Implement resolving basetypes.
This commit is contained in:
parent
3ada78a557
commit
576f805bd7
|
@ -4,6 +4,8 @@
|
|||
#include "libds.h"
|
||||
#include "liblex.h"
|
||||
#include "result.h"
|
||||
#include "parsetype.h"
|
||||
#include "table.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
|
@ -44,5 +46,12 @@ libab_result libab_copy_string_size(char** destination, const char* source, size
|
|||
* @return the result of the operation.
|
||||
*/
|
||||
libab_result libab_copy_string(char** destination, const char* source);
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
libab_result libab_resolve_parsetype(libab_parsetype* to_resolve, libab_table* scope);
|
||||
|
||||
#endif
|
||||
|
|
38
src/util.c
38
src/util.c
|
@ -36,3 +36,41 @@ libab_result libab_copy_string_size(char** destination, const char* source, size
|
|||
libab_result libab_copy_string(char** destination, const char* source) {
|
||||
return libab_copy_string_range(destination, source, 0, strlen(source));
|
||||
}
|
||||
libab_result _libab_check_parsetype(libab_parsetype* to_check) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
return result;
|
||||
}
|
||||
libab_result libab_resolve_parsetype(libab_parsetype* to_resolve, libab_table* scope) {
|
||||
libab_result result = LIBAB_SUCCESS;
|
||||
int resolve_name, check_parents;
|
||||
size_t index = 0;
|
||||
resolve_name = !(to_resolve->variant & (LIBABACUS_TYPE_F_RESOLVED | LIBABACUS_TYPE_F_PLACE));
|
||||
check_parents = !(to_resolve->variant & LIBABACUS_TYPE_F_PLACE);
|
||||
if(resolve_name) {
|
||||
libab_basetype* basetype = libab_table_search_basetype(scope, to_resolve->data_u.name);
|
||||
if(basetype) {
|
||||
free(to_resolve->data_u.name);
|
||||
to_resolve->data_u.base = basetype;
|
||||
to_resolve->variant |= LIBABACUS_TYPE_F_RESOLVED;
|
||||
} else {
|
||||
result = LIBAB_BAD_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
if(check_parents && result == LIBAB_SUCCESS) {
|
||||
if(to_resolve->variant & LIBABACUS_TYPE_F_PARENT) {
|
||||
result = _libab_check_parsetype(to_resolve);
|
||||
} else if(to_resolve->data_u.base->count) {
|
||||
result = LIBAB_BAD_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
if(to_resolve->variant & LIBABACUS_TYPE_F_PARENT) {
|
||||
while(result == LIBAB_SUCCESS && index < to_resolve->children.size) {
|
||||
result = libab_resolve_parsetype(libab_ref_get(&to_resolve->children.data[index]), scope);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user