40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
#include <common/fzl_types.h>
|
|
#include <compiler/fzl_analyzer.h>
|
|
#include <compiler/fzl_parser.h>
|
|
#include <compiler/internals/analyzer.h>
|
|
#include <compiler/utils/fzl_symtable.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
|
|
// Analyze class construct
|
|
fzl_an_res_t analyze_construct(fzl_analyzer_t *analyzer, fzl_node_t *construct)
|
|
{
|
|
if (!analyzer)
|
|
return (fzl_an_res_t){.error = true};
|
|
|
|
if (!construct || construct->type != FZL_NODETYPE_CONSTRUCT)
|
|
{
|
|
an_push_error(analyzer, NULL, "node is not a construct");
|
|
return (fzl_an_res_t){.error = true};
|
|
}
|
|
|
|
char *classname = (char *)construct->construct.name->token->value;
|
|
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;
|
|
}
|
|
|
|
if (!sym_found)
|
|
{
|
|
snprintf(an_problem, sizeof(an_problem), "class '%s' not found", classname);
|
|
an_push_error(analyzer, construct->token, an_problem);
|
|
return (fzl_an_res_t){.error = true};
|
|
}
|
|
|
|
return (fzl_an_res_t){
|
|
.error = false, .type = FZL_TYPE_OBJECT, .classname = classname};
|
|
}
|