2018-02-11 22:32:42 -08:00
|
|
|
#include "util.h"
|
2018-04-24 15:22:17 -07:00
|
|
|
#include "value.h"
|
2018-04-22 20:44:30 -07:00
|
|
|
#include <stdarg.h>
|
2018-05-17 14:53:48 -07:00
|
|
|
#include <stdlib.h>
|
2018-06-15 20:38:19 -07:00
|
|
|
#include "free_functions.h"
|
2018-02-10 16:01:01 -08:00
|
|
|
|
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
|
|
|
libab_result result = LIBAB_SUCCESS;
|
2018-04-21 14:09:01 -07:00
|
|
|
if (to_convert == LIBLEX_MALLOC) {
|
2018-02-10 16:01:01 -08:00
|
|
|
result = LIBAB_MALLOC;
|
2018-04-21 14:09:01 -07:00
|
|
|
} else if (to_convert == LIBLEX_INVALID) {
|
2018-02-10 16:01:01 -08:00
|
|
|
result = LIBAB_BAD_PATTERN;
|
2018-04-21 14:09:01 -07:00
|
|
|
} else if (to_convert == LIBLEX_UNRECOGNIZED) {
|
2018-02-10 16:01:01 -08:00
|
|
|
result = LIBAB_FAILED_MATCH;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2018-02-11 21:09:41 -08:00
|
|
|
libab_result libab_convert_ds_result(libds_result to_convert) {
|
2018-02-10 16:01:01 -08:00
|
|
|
libab_result result = LIBAB_SUCCESS;
|
2018-04-21 14:09:01 -07:00
|
|
|
if (to_convert == LIBDS_MALLOC) {
|
2018-02-10 16:01:01 -08:00
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
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
|
|
|
libab_result result = LIBAB_SUCCESS;
|
|
|
|
size_t string_length = to - from;
|
2018-04-21 14:09:01 -07:00
|
|
|
if ((*destination = malloc(string_length + 1)) == NULL) {
|
2018-03-06 16:45:55 -08:00
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
} else {
|
|
|
|
strncpy(*destination, source + from, string_length);
|
|
|
|
(*destination)[string_length] = '\0';
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
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
|
|
|
return libab_copy_string_range(destination, source, 0, length);
|
|
|
|
}
|
|
|
|
libab_result libab_copy_string(char** destination, const char* source) {
|
|
|
|
return libab_copy_string_range(destination, source, 0, strlen(source));
|
|
|
|
}
|
2018-04-19 23:17:54 -07:00
|
|
|
libab_result _libab_check_parsetype(libab_parsetype* to_check) {
|
|
|
|
libab_result result = LIBAB_SUCCESS;
|
|
|
|
return result;
|
|
|
|
}
|
2018-06-17 19:01:15 -07:00
|
|
|
libab_result libab_resolve_parsetype_inplace(libab_parsetype* to_resolve,
|
2018-04-21 14:09:01 -07:00
|
|
|
libab_table* scope) {
|
2018-04-19 23:17:54 -07:00
|
|
|
libab_result result = LIBAB_SUCCESS;
|
|
|
|
int resolve_name, check_parents;
|
|
|
|
size_t index = 0;
|
2018-04-21 14:09:01 -07:00
|
|
|
resolve_name = !(to_resolve->variant &
|
|
|
|
(LIBABACUS_TYPE_F_RESOLVED | LIBABACUS_TYPE_F_PLACE));
|
2018-04-19 23:17:54 -07:00
|
|
|
check_parents = !(to_resolve->variant & LIBABACUS_TYPE_F_PLACE);
|
2018-05-19 13:04:41 -07:00
|
|
|
|
2018-05-26 21:55:30 -07:00
|
|
|
if ((to_resolve->variant & LIBABACUS_TYPE_F_PLACE) &&
|
|
|
|
(to_resolve->variant & LIBABACUS_TYPE_F_PARENT)) {
|
2018-05-19 13:04:41 -07:00
|
|
|
result = LIBAB_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resolve_name && result == LIBAB_SUCCESS) {
|
2018-04-21 14:09:01 -07:00
|
|
|
libab_basetype* basetype =
|
2018-06-17 19:01:15 -07:00
|
|
|
libab_get_basetype(to_resolve, scope);
|
2018-04-21 14:09:01 -07:00
|
|
|
if (basetype) {
|
2018-04-19 23:17:54 -07:00
|
|
|
free(to_resolve->data_u.name);
|
|
|
|
to_resolve->data_u.base = basetype;
|
|
|
|
to_resolve->variant |= LIBABACUS_TYPE_F_RESOLVED;
|
|
|
|
} else {
|
2018-05-22 13:03:14 -07:00
|
|
|
result = LIBAB_UNKNOWN_TYPE;
|
2018-04-19 23:17:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-21 14:09:01 -07:00
|
|
|
if (check_parents && result == LIBAB_SUCCESS) {
|
|
|
|
if (to_resolve->variant & LIBABACUS_TYPE_F_PARENT) {
|
2018-04-19 23:17:54 -07:00
|
|
|
result = _libab_check_parsetype(to_resolve);
|
2018-04-21 14:09:01 -07:00
|
|
|
} else if (to_resolve->data_u.base->count) {
|
2018-04-19 23:17:54 -07:00
|
|
|
result = LIBAB_BAD_TYPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-21 14:09:01 -07:00
|
|
|
if (to_resolve->variant & LIBABACUS_TYPE_F_PARENT) {
|
|
|
|
while (result == LIBAB_SUCCESS && index < to_resolve->children.size) {
|
2018-06-17 19:01:15 -07:00
|
|
|
result = libab_resolve_parsetype_inplace(
|
2018-04-21 14:09:01 -07:00
|
|
|
libab_ref_get(&to_resolve->children.data[index]), scope);
|
2018-04-19 23:17:54 -07:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2018-04-22 20:44:30 -07:00
|
|
|
|
2018-06-17 19:01:15 -07:00
|
|
|
libab_result libab_resolve_parsetype_copy(libab_parsetype* to_resolve,
|
|
|
|
libab_table* scope,
|
|
|
|
libab_ref* into) {
|
|
|
|
libab_result result = LIBAB_SUCCESS;
|
|
|
|
libab_parsetype* parsetype;
|
2018-06-17 20:21:40 -07:00
|
|
|
int is_placeholer = to_resolve->variant & LIBABACUS_TYPE_F_PLACE;
|
2018-06-17 19:01:15 -07:00
|
|
|
if((parsetype = malloc(sizeof(*parsetype)))) {
|
2018-06-17 20:21:40 -07:00
|
|
|
parsetype->variant = to_resolve->variant;
|
|
|
|
if(!is_placeholer) {
|
|
|
|
parsetype->variant |= LIBABACUS_TYPE_F_RESOLVED;
|
|
|
|
}
|
2018-06-17 19:01:15 -07:00
|
|
|
} else {
|
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result == LIBAB_SUCCESS) {
|
2018-06-17 20:21:40 -07:00
|
|
|
if(!is_placeholer) {
|
|
|
|
libab_basetype* parent_basetype = libab_get_basetype(to_resolve, scope);
|
|
|
|
if(parent_basetype) {
|
|
|
|
parsetype->data_u.base = parent_basetype;
|
|
|
|
} else {
|
|
|
|
result = LIBAB_UNKNOWN_TYPE;
|
|
|
|
}
|
2018-06-17 19:01:15 -07:00
|
|
|
} else {
|
2018-06-17 20:21:40 -07:00
|
|
|
result = libab_copy_string(&parsetype->data_u.name, to_resolve->data_u.name);
|
2018-06-17 19:01:15 -07:00
|
|
|
}
|
|
|
|
}
|
2018-04-22 20:44:30 -07:00
|
|
|
|
2018-06-17 19:01:15 -07:00
|
|
|
|
|
|
|
if(result == LIBAB_SUCCESS && (to_resolve->variant & LIBABACUS_TYPE_F_PARENT)) {
|
|
|
|
result = libab_ref_vec_init(&parsetype->children);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result == LIBAB_SUCCESS && (to_resolve->variant & LIBABACUS_TYPE_F_PARENT)) {
|
|
|
|
size_t i;
|
|
|
|
libab_ref temp;
|
|
|
|
libab_ref new_type;
|
|
|
|
for(i = 0; i < to_resolve->children.size && result == LIBAB_SUCCESS; i++) {
|
|
|
|
libab_ref_vec_index(&to_resolve->children, i, &temp);
|
|
|
|
result = libab_resolve_parsetype_copy(libab_ref_get(&temp), scope, &new_type);
|
|
|
|
if(result == LIBAB_SUCCESS) {
|
|
|
|
libab_ref_vec_insert(&parsetype->children, &new_type);
|
|
|
|
}
|
|
|
|
libab_ref_free(&new_type);
|
|
|
|
libab_ref_free(&temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result != LIBAB_SUCCESS) {
|
|
|
|
libab_ref_vec_free(&parsetype->children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result == LIBAB_SUCCESS) {
|
2018-06-17 19:43:18 -07:00
|
|
|
result = libab_ref_new(into, parsetype, libab_free_parsetype);
|
2018-06-17 19:01:15 -07:00
|
|
|
if(result != LIBAB_SUCCESS) libab_parsetype_free(parsetype);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result != LIBAB_SUCCESS) {
|
|
|
|
free(parsetype);
|
|
|
|
libab_ref_null(into);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2018-04-22 20:44:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
libab_result libab_instantiate_basetype(libab_basetype* to_instantiate,
|
2018-05-17 14:53:48 -07:00
|
|
|
libab_ref* into, size_t n, ...) {
|
2018-04-22 20:44:30 -07:00
|
|
|
libab_result result = LIBAB_SUCCESS;
|
|
|
|
libab_parsetype* parsetype;
|
|
|
|
va_list params;
|
|
|
|
|
|
|
|
va_start(params, n);
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if ((parsetype = malloc(sizeof(*parsetype)))) {
|
2018-04-22 20:44:30 -07:00
|
|
|
result = libab_parsetype_init_va(parsetype, to_instantiate, n, params);
|
|
|
|
} else {
|
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result == LIBAB_SUCCESS) {
|
2018-06-17 19:43:18 -07:00
|
|
|
result = libab_ref_new(into, parsetype, libab_free_parsetype);
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-04-22 20:44:30 -07:00
|
|
|
libab_parsetype_free(parsetype);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-04-22 21:24:43 -07:00
|
|
|
libab_ref_null(into);
|
2018-04-22 20:44:30 -07:00
|
|
|
free(parsetype);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(params);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2018-04-24 11:32:57 -07:00
|
|
|
|
|
|
|
libab_result libab_create_table(libab_ref* into, libab_ref* parent) {
|
|
|
|
libab_table* table;
|
|
|
|
libab_result result = LIBAB_SUCCESS;
|
2018-05-17 14:53:48 -07:00
|
|
|
if ((table = malloc(sizeof(*table)))) {
|
2018-04-24 11:32:57 -07:00
|
|
|
libab_table_init(table);
|
|
|
|
libab_table_set_parent(table, parent);
|
2018-06-17 19:43:18 -07:00
|
|
|
result = libab_ref_new(into, table, libab_free_table);
|
2018-04-24 11:32:57 -07:00
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-06-17 19:43:18 -07:00
|
|
|
libab_free_table(table);
|
2018-04-24 11:32:57 -07:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-17 14:53:48 -07:00
|
|
|
result = LIBAB_MALLOC;
|
2018-04-24 11:32:57 -07:00
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-04-24 11:32:57 -07:00
|
|
|
libab_ref_null(into);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2018-04-24 15:22:17 -07:00
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
libab_result libab_create_value_ref(libab_ref* into, libab_ref* data,
|
|
|
|
libab_ref* type) {
|
2018-04-24 15:22:17 -07:00
|
|
|
libab_value* value;
|
|
|
|
libab_result result = LIBAB_SUCCESS;
|
2018-05-17 14:53:48 -07:00
|
|
|
if ((value = malloc(sizeof(*value)))) {
|
2018-05-14 17:41:41 -07:00
|
|
|
libab_value_init_ref(value, data, type);
|
2018-06-17 19:43:18 -07:00
|
|
|
result = libab_ref_new(into, value, libab_free_value);
|
2018-04-24 15:22:17 -07:00
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-06-17 19:43:18 -07:00
|
|
|
libab_free_value(value);
|
2018-04-24 15:22:17 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-04-24 15:22:17 -07:00
|
|
|
libab_ref_null(into);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2018-04-26 19:16:20 -07:00
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
libab_result libab_create_value_raw(libab_ref* into, void* data,
|
|
|
|
libab_ref* type) {
|
2018-05-14 17:41:41 -07:00
|
|
|
libab_value* value;
|
|
|
|
libab_result result = LIBAB_SUCCESS;
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if ((value = malloc(sizeof(*value)))) {
|
2018-05-14 17:41:41 -07:00
|
|
|
result = libab_value_init_raw(value, data, type);
|
|
|
|
} else {
|
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result == LIBAB_SUCCESS) {
|
2018-06-17 19:43:18 -07:00
|
|
|
result = libab_ref_new(into, value, libab_free_value);
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-05-14 17:41:41 -07:00
|
|
|
libab_value_free(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-05-14 17:41:41 -07:00
|
|
|
libab_ref_null(into);
|
|
|
|
free(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
libab_result libab_create_function_internal(libab_ref* into,
|
|
|
|
void (*free_function)(void*),
|
2018-05-28 01:18:06 -07:00
|
|
|
libab_function_ptr fun,
|
|
|
|
libab_ref* scope) {
|
2018-05-14 19:17:03 -07:00
|
|
|
libab_function* new_function;
|
|
|
|
libab_result result = LIBAB_SUCCESS;
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if ((new_function = malloc(sizeof(*new_function)))) {
|
2018-05-28 01:18:06 -07:00
|
|
|
result = libab_function_init_internal(new_function, fun, scope);
|
2018-05-14 19:17:03 -07:00
|
|
|
} else {
|
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result == LIBAB_SUCCESS) {
|
2018-05-16 15:26:03 -07:00
|
|
|
result = libab_ref_new(into, new_function, free_function);
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-05-14 19:17:03 -07:00
|
|
|
libab_function_free(new_function);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-05-14 19:17:03 -07:00
|
|
|
libab_ref_null(into);
|
|
|
|
free(new_function);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
libab_result libab_create_function_tree(libab_ref* into,
|
|
|
|
void (*free_function)(void*),
|
2018-05-28 01:18:06 -07:00
|
|
|
libab_tree* tree,
|
|
|
|
libab_ref* scope) {
|
2018-05-14 19:17:03 -07:00
|
|
|
libab_function* new_function;
|
|
|
|
libab_result result = LIBAB_SUCCESS;
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if ((new_function = malloc(sizeof(*new_function)))) {
|
2018-05-28 01:18:06 -07:00
|
|
|
result = libab_function_init_tree(new_function, tree, scope);
|
2018-05-14 19:17:03 -07:00
|
|
|
} else {
|
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result == LIBAB_SUCCESS) {
|
2018-05-16 15:26:03 -07:00
|
|
|
result = libab_ref_new(into, new_function, free_function);
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-05-14 19:17:03 -07:00
|
|
|
libab_function_free(new_function);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-05-14 19:17:03 -07:00
|
|
|
libab_ref_null(into);
|
|
|
|
free(new_function);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-06-02 20:56:30 -07:00
|
|
|
libab_result libab_create_function_behavior(libab_ref* into,
|
|
|
|
void (*free_function)(void*),
|
|
|
|
libab_behavior* behavior,
|
|
|
|
libab_ref* scope) {
|
|
|
|
libab_function* new_function;
|
|
|
|
libab_result result = LIBAB_SUCCESS;
|
|
|
|
|
|
|
|
if((new_function = malloc(sizeof(*new_function)))) {
|
|
|
|
result = libab_function_init_behavior(new_function, behavior, scope);
|
|
|
|
} else {
|
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result == LIBAB_SUCCESS) {
|
|
|
|
result = libab_ref_new(into, new_function, free_function);
|
|
|
|
if(result != LIBAB_SUCCESS) {
|
|
|
|
libab_function_free(new_function);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result != LIBAB_SUCCESS) {
|
|
|
|
libab_ref_null(into);
|
|
|
|
free(new_function);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-04-26 19:16:20 -07:00
|
|
|
libab_result libab_create_function_list(libab_ref* into, libab_ref* type) {
|
|
|
|
libab_function_list* list;
|
|
|
|
libab_result result = LIBAB_SUCCESS;
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if ((list = malloc(sizeof(*list)))) {
|
2018-04-26 19:16:20 -07:00
|
|
|
result = libab_function_list_init(list);
|
|
|
|
} else {
|
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result == LIBAB_SUCCESS) {
|
|
|
|
result = libab_ref_new(into, list,
|
|
|
|
((libab_parsetype*)libab_ref_get(type))
|
|
|
|
->data_u.base->free_function);
|
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-04-26 19:16:20 -07:00
|
|
|
libab_function_list_free(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-04-26 19:16:20 -07:00
|
|
|
libab_ref_null(into);
|
2018-05-14 20:15:03 -07:00
|
|
|
free(list);
|
2018-04-26 19:16:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2018-04-26 20:59:12 -07:00
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
libab_result libab_put_table_value(libab_table* table, const char* key,
|
|
|
|
libab_ref* value) {
|
2018-04-26 20:59:12 -07:00
|
|
|
libab_table_entry* entry;
|
|
|
|
libab_result result = LIBAB_SUCCESS;
|
2018-05-17 14:53:48 -07:00
|
|
|
if ((entry = malloc(sizeof(*entry)))) {
|
2018-04-26 20:59:12 -07:00
|
|
|
entry->variant = ENTRY_VALUE;
|
|
|
|
libab_ref_copy(value, &entry->data_u.value);
|
|
|
|
} else {
|
|
|
|
result = LIBAB_MALLOC;
|
|
|
|
}
|
|
|
|
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result == LIBAB_SUCCESS) {
|
2018-04-26 20:59:12 -07:00
|
|
|
result = libab_table_put(table, key, entry);
|
2018-05-17 14:53:48 -07:00
|
|
|
if (result != LIBAB_SUCCESS) {
|
2018-04-26 20:59:12 -07:00
|
|
|
libab_ref_free(&entry->data_u.value);
|
|
|
|
free(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2018-05-26 15:04:07 -07:00
|
|
|
|
2018-06-17 19:01:15 -07:00
|
|
|
libab_basetype* libab_get_basetype(libab_parsetype* type, libab_table* scope) {
|
|
|
|
libab_ref type_param;
|
|
|
|
libab_basetype* to_return;
|
|
|
|
if(type->variant & LIBABACUS_TYPE_F_RESOLVED) {
|
|
|
|
to_return = type->data_u.base;
|
|
|
|
} else {
|
|
|
|
to_return = libab_table_search_basetype(scope, type->data_u.name);
|
|
|
|
if(to_return == NULL) {
|
|
|
|
libab_table_search_type_param(scope, type->data_u.name, &type_param);
|
2018-06-17 20:21:40 -07:00
|
|
|
to_return = ((libab_parsetype*)libab_ref_get(&type_param))->data_u.base;
|
2018-06-17 19:01:15 -07:00
|
|
|
libab_ref_free(&type_param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return to_return;
|
|
|
|
}
|
|
|
|
|
2018-05-26 15:04:07 -07:00
|
|
|
void* libab_unwrap_value(libab_ref* ref) {
|
|
|
|
libab_value* value = libab_ref_get(ref);
|
|
|
|
return libab_ref_get(&value->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* libab_unwrap_param(libab_ref_vec* vec, size_t index) {
|
|
|
|
libab_ref temp;
|
|
|
|
void* data;
|
|
|
|
libab_ref_vec_index(vec, index, &temp);
|
|
|
|
data = libab_unwrap_value(&temp);
|
|
|
|
libab_ref_free(&temp);
|
|
|
|
return data;
|
|
|
|
}
|
2018-08-10 18:39:26 -07:00
|
|
|
|
|
|
|
void libab_sanitize(char* to, const char* from, size_t buffer_size) {
|
|
|
|
size_t index = 0;
|
|
|
|
while (*from && index < (buffer_size - 2)) {
|
|
|
|
if (*from == '+' || *from == '*' || *from == '\\' ||
|
|
|
|
*from == '|' || *from == '[' || *from == ']' || *from == '(' ||
|
|
|
|
*from == ')')
|
|
|
|
to[index++] = '\\';
|
|
|
|
to[index++] = *(from++);
|
|
|
|
}
|
|
|
|
to[index] = '\0';
|
|
|
|
}
|