wip: working on analyzer
- Feat: add binary math analysis - Fix: check for function context in block analysis - Feat: add 'break' analysis - Fix: few fixes in call analysis - Feat: add class analysis - Feat: add construct analysis - Feat: add declaration analysis - Feat: add field analysis - Feat: add function analysis - Feat: add loop analysis - Ref: updated utilities and context functions
This commit is contained in:
@@ -1,8 +1,73 @@
|
||||
// TODO:
|
||||
// 1. check for manual `this` declaration
|
||||
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char class_problem[256];
|
||||
|
||||
// Analyze class declaration
|
||||
fzl_an_res_t analyze_class(fzl_node_t *class_node) {}
|
||||
fzl_an_res_t analyze_class(fzl_analyzer_t *analyzer, fzl_node_t *class_node)
|
||||
{
|
||||
if (!analyzer)
|
||||
return (fzl_an_res_t){.error = true};
|
||||
|
||||
if (!class_node || class_node->type != FZL_NODETYPE_CLASS)
|
||||
{
|
||||
an_push_error(analyzer, NULL, "node is not typeof CLASS");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
char *classname = (char *)class_node->class.name->value;
|
||||
fzl_an_ctx_t *ctx = an_nest_ctx(analyzer, FZL_AN_CTX_TYPE_CLASS);
|
||||
ctx->classname = classname;
|
||||
|
||||
fzl_sym_t sym;
|
||||
bool sym_found = false;
|
||||
for (ssize_t i = analyzer->symbols_top - 1; i >= 0; i--)
|
||||
{
|
||||
if ((sym_found = fzl_symt_get(analyzer->symbols[i], classname, &sym)))
|
||||
break;
|
||||
}
|
||||
|
||||
fzl_symtable_res_t res =
|
||||
fzl_symt_put(analyzer->symbols[analyzer->symbols_top - 2], class_node,
|
||||
classname, FZL_TYPE_NULL, 0);
|
||||
|
||||
if (res != FZL_SYMTABLE_RESULT_OK)
|
||||
{
|
||||
if (res == FZL_SYMTABLE_RESULT_EXISTS)
|
||||
{
|
||||
snprintf(class_problem, sizeof(class_problem),
|
||||
"name '%s' already has been declared", classname);
|
||||
an_push_error(analyzer, class_node->token, class_problem);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(class_problem, sizeof(class_problem), "cannot store name '%s'",
|
||||
classname);
|
||||
an_push_error(analyzer, class_node->token, class_problem);
|
||||
}
|
||||
|
||||
an_fin_ctx(analyzer);
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
bool error = false;
|
||||
for (size_t i = 0; i < class_node->class.fields_count; i++)
|
||||
{
|
||||
fzl_an_res_t res = analyze_common(analyzer, class_node->class.fields[i]);
|
||||
if (res.error)
|
||||
error = true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < class_node->class.methods_count; i++)
|
||||
{
|
||||
fzl_an_res_t res = analyze_common(analyzer, class_node->class.methods[i]);
|
||||
if (res.error)
|
||||
error = true;
|
||||
}
|
||||
|
||||
an_fin_ctx(analyzer);
|
||||
return (fzl_an_res_t){.error = error, .type = FZL_TYPE_NULL};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user