wip: working on dynamic linking
- Feat: add analyzers for: - external functions - reference - structures - type definitions - Feat: add new nodes to debug print (ast)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/analyzer.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Analyze structure definition
|
||||
fzl_an_res_t analyze_struct(fzl_analyzer_t *analyzer, fzl_node_t *struct_node)
|
||||
{
|
||||
if (!analyzer)
|
||||
return (fzl_an_res_t){.error = true};
|
||||
|
||||
if (!struct_node || struct_node->type != FZL_NODETYPE_STRUCT)
|
||||
{
|
||||
an_push_error(analyzer, NULL, "node is not a structure");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
if (struct_node->structure.entries_count < 1)
|
||||
{
|
||||
an_push_warning(analyzer, struct_node->token, "empty structure");
|
||||
return (fzl_an_res_t){.error = false};
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < struct_node->structure.entries_count; i++)
|
||||
{
|
||||
fzl_node_t *entry = struct_node->structure.entries[i];
|
||||
if (entry->type != FZL_NODETYPE_DECLARATION &&
|
||||
entry->type != FZL_NODETYPE_IDENTIFIER)
|
||||
{
|
||||
an_push_error(
|
||||
analyzer, entry->token,
|
||||
"structure can contain only declarations and another structures");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
fzl_an_res_t res = analyze_common(analyzer, entry);
|
||||
if (res.error)
|
||||
return (fzl_an_res_t){.error = true};
|
||||
|
||||
if (res.type == FZL_TYPE_OBJECT)
|
||||
{
|
||||
an_push_error(analyzer, entry->token,
|
||||
"cannot store object inside struct");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
}
|
||||
|
||||
return (fzl_an_res_t){
|
||||
.error = false, .type = FZL_TYPE_STRUCT, .classname = NULL};
|
||||
}
|
||||
Reference in New Issue
Block a user