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:
@@ -0,0 +1,47 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
|
||||
// defined in `compiler/analyzer/utility.c`
|
||||
extern bool an_is_compatible(fzl_type_t a, fzl_type_t b, char *ac, char *bc);
|
||||
|
||||
// Analyze binary arithmetics
|
||||
fzl_an_res_t analyze_binmath(fzl_analyzer_t *analyzer, fzl_node_t *bin_node)
|
||||
{
|
||||
if (!analyzer)
|
||||
return (fzl_an_res_t){.error = true};
|
||||
|
||||
if (!bin_node || bin_node->type != FZL_NODETYPE_ADD ||
|
||||
bin_node->type != FZL_NODETYPE_SUB ||
|
||||
bin_node->type != FZL_NODETYPE_MUL ||
|
||||
bin_node->type != FZL_NODETYPE_DIV ||
|
||||
bin_node->type != FZL_NODETYPE_POW || bin_node->type != FZL_NODETYPE_MOD)
|
||||
{
|
||||
an_push_error(analyzer, NULL, "node is not typeof binary math");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
fzl_an_res_t left = analyze_common(analyzer, bin_node->binary_op.left);
|
||||
if (left.error)
|
||||
return (fzl_an_res_t){.error = true};
|
||||
|
||||
fzl_an_res_t right = analyze_common(analyzer, bin_node->binary_op.right);
|
||||
if (right.error)
|
||||
return (fzl_an_res_t){.error = true};
|
||||
|
||||
if (left.type < FZL_TYPE_INT8)
|
||||
{
|
||||
an_push_error(analyzer, bin_node->binary_op.left->token,
|
||||
"left side is not an integer type");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
if (right.type < FZL_TYPE_INT8)
|
||||
{
|
||||
an_push_error(analyzer, bin_node->binary_op.right->token,
|
||||
"right side is not an integer type");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
return (fzl_an_res_t){.error = false, .type = left.type, .classname = NULL};
|
||||
}
|
||||
Reference in New Issue
Block a user