Files
fz-lang/src/compiler/analyzer/an_unarymath.c
T

34 lines
1.0 KiB
C

#include <common/fzl_types.h>
#include <compiler/fzl_analyzer.h>
#include <compiler/fzl_parser.h>
#include <compiler/internals/analyzer.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 an unary math operator");
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};
}