2018-02-10 16:01:01 -08:00
|
|
|
#ifndef LIBABACUS_UTIL_H
|
|
|
|
#define LIBABACUS_UTIL_H
|
|
|
|
|
|
|
|
#include "libds.h"
|
|
|
|
#include "liblex.h"
|
2018-04-19 23:17:54 -07:00
|
|
|
#include "parsetype.h"
|
2018-04-21 14:09:01 -07:00
|
|
|
#include "result.h"
|
2018-04-19 23:17:54 -07:00
|
|
|
#include "table.h"
|
2018-03-06 16:45:55 -08:00
|
|
|
#include <string.h>
|
2018-02-10 16:01:01 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a result code from liblex to libabacus.
|
|
|
|
* @param to_convert the code to convert.
|
|
|
|
* @return the libabacus equivalent of the error code.
|
|
|
|
*/
|
2018-02-11 21:09:41 -08:00
|
|
|
libab_result libab_convert_lex_result(liblex_result to_convert);
|
2018-02-10 16:01:01 -08:00
|
|
|
/**
|
|
|
|
* Converts a result code from libds to libabacus.
|
|
|
|
* @param to_convert the code to convert.
|
|
|
|
* @return the libabacus equivalent of the error code.
|
|
|
|
*/
|
2018-02-11 21:09:41 -08:00
|
|
|
libab_result libab_convert_ds_result(libds_result to_convert);
|
2018-03-06 16:45:55 -08:00
|
|
|
/**
|
2018-04-21 14:09:01 -07:00
|
|
|
* Copies a range of the given string into a new, null-terminated string
|
|
|
|
* allocated on the heap.
|
2018-03-06 16:45:55 -08:00
|
|
|
* @param destination the pointer to populate with the newly created string.
|
|
|
|
* @param source the source from which to pull character information from.
|
|
|
|
* @param from the index (inclusive) at which to begin copying.
|
|
|
|
* @param to the index (exclusive) at which to end copying.
|
|
|
|
* @return the result of the operation.
|
|
|
|
*/
|
2018-04-21 14:09:01 -07:00
|
|
|
libab_result libab_copy_string_range(char** destination, const char* source,
|
|
|
|
size_t from, size_t to);
|
2018-03-06 16:45:55 -08:00
|
|
|
/**
|
|
|
|
* Copies the given string, starting at 0 and copying length bytes.
|
|
|
|
* @param destination the pointer to populate with the newly created string.
|
|
|
|
* @param source to source string to copy.
|
|
|
|
* @param length the number of bytes to copy.
|
|
|
|
* @return the result of the operation.
|
|
|
|
*/
|
2018-04-21 14:09:01 -07:00
|
|
|
libab_result libab_copy_string_size(char** destination, const char* source,
|
|
|
|
size_t length);
|
2018-03-06 16:45:55 -08:00
|
|
|
/**
|
|
|
|
* Copies the entire string into a null-terminated string allocated
|
|
|
|
* on the heap.
|
|
|
|
* @param destination the pointer to populate with the newly allocated string.
|
|
|
|
* @param source the source string to copy.
|
|
|
|
* @return the result of the operation.
|
|
|
|
*/
|
|
|
|
libab_result libab_copy_string(char** destination, const char* source);
|
2018-04-19 23:17:54 -07:00
|
|
|
/**
|
|
|
|
* Resolves the given parsetype, looking through the scope to find all the
|
|
|
|
* referenced base types, if applicable.
|
|
|
|
* @param to_resolve the parsetype to resolve.
|
|
|
|
* @param scope the scope to use for resolving the type info.
|
|
|
|
*/
|
2018-04-21 14:09:01 -07:00
|
|
|
libab_result libab_resolve_parsetype(libab_parsetype* to_resolve,
|
|
|
|
libab_table* scope);
|
2018-02-10 16:01:01 -08:00
|
|
|
|
|
|
|
#endif
|