Files
fz-lang/src/compiler/analyzer/an_unarycond.c
T
2026-10-27 15:40:25 +03:00

31 lines
944 B
C

#include <common/fzl_types.h>
#include <compiler/fzl_analyzer.h>
#include <compiler/fzl_parser.h>
// Analyze unary condition
fzl_an_res_t analyze_unarycond(fzl_analyzer_t *analyzer, fzl_node_t *unary)
{
if (!analyzer)
return (fzl_an_res_t){.error = true};
if (!unary || unary->type != FZL_NODETYPE_NOT)
{
an_push_error(analyzer, NULL, "node is not an unary condition 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_BOOL && operand_res.type < FZL_TYPE_INT8)
{
an_push_error(analyzer, unary->unary_op.operand->token,
"unary condition only support bool and integer types");
return (fzl_an_res_t){.error = true};
}
return (fzl_an_res_t){
.error = false, .type = FZL_TYPE_BOOL, .classname = NULL};
}