#include #include #include #include // 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 binary math operator"); 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) { snprintf(an_problem, sizeof(an_problem), "integer type is expected, got '%s'", an_typetostr(left.type, left.classname)); an_push_error(analyzer, bin_node->binary_op.left->token, an_problem); return (fzl_an_res_t){.error = true}; } if (right.type < FZL_TYPE_INT8) { snprintf(an_problem, sizeof(an_problem), "integer type is expected, got '%s'", an_typetostr(right.type, right.classname)); an_push_error(analyzer, bin_node->binary_op.right->token, an_problem); return (fzl_an_res_t){.error = true}; } return (fzl_an_res_t){.error = false, .type = left.type, .classname = NULL}; }