wip: working on analyzer
- Feat: add assigns analysis - Fix: change node check condition in binary math analysis - Feat: add unary and binary conditions analysis - Fix: add type passtrough in declaration analysis - Feat: add unary math analysis
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Analyze unary arithmetic
|
||||
fzl_an_res_t analyze_unarymath(fzl_analyzer_t *analyzer, fzl_node_t *unary)
|
||||
{
|
||||
if (!analyzer)
|
||||
return (fzl_an_res_t){.error = true};
|
||||
|
||||
if (!unary || (unary->type != FZL_NODETYPE_UNARY_MINUS &&
|
||||
unary->type != FZL_NODETYPE_UNARY_PLUS))
|
||||
{
|
||||
an_push_error(analyzer, NULL, "node is not typeof unary math");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
fzl_an_res_t operand_res = analyze_common(analyzer, unary->unary_op.operand);
|
||||
if (operand_res.error)
|
||||
return (fzl_an_res_t){.error = true};
|
||||
|
||||
if (operand_res.type < FZL_TYPE_INT8)
|
||||
{
|
||||
an_push_error(analyzer, unary->unary_op.operand->token,
|
||||
"unary operator only support integer types");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
return (fzl_an_res_t){
|
||||
.error = false, .type = operand_res.type, .classname = NULL};
|
||||
}
|
||||
Reference in New Issue
Block a user