fix: review problems
This commit is contained in:
@@ -3,12 +3,6 @@
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char asn_problem[256];
|
||||
|
||||
// defined in `compiler/analyzer/utility.c`
|
||||
extern bool an_is_compatible(fzl_type_t a, fzl_type_t b, char *ac, char *bc);
|
||||
extern char *an_typetostr(fzl_type_t type, char *classname);
|
||||
|
||||
// Analyze assigns
|
||||
fzl_an_res_t analyze_assign(fzl_analyzer_t *analyzer, fzl_node_t *assign_node)
|
||||
{
|
||||
@@ -17,7 +11,7 @@ fzl_an_res_t analyze_assign(fzl_analyzer_t *analyzer, fzl_node_t *assign_node)
|
||||
|
||||
if (!assign_node || assign_node->type != FZL_NODETYPE_ASSIGN)
|
||||
{
|
||||
an_push_error(analyzer, NULL, "node is not typeof ASSIGN");
|
||||
an_push_error(analyzer, NULL, "node is not assignment");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
@@ -35,17 +29,19 @@ fzl_an_res_t analyze_assign(fzl_analyzer_t *analyzer, fzl_node_t *assign_node)
|
||||
left->type != FZL_NODETYPE_IDENTIFIER && left->type != FZL_NODETYPE_FIELD)
|
||||
{
|
||||
an_push_error(analyzer, left->token,
|
||||
"this type of assignment left is not supported");
|
||||
"left side must be one of these: declaration, identifier or "
|
||||
"field access");
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
if (!an_is_compatible(leftside.type, rightside.type, leftside.classname,
|
||||
rightside.classname))
|
||||
{
|
||||
snprintf(asn_problem, sizeof(asn_problem), "cannot assign %s to %s",
|
||||
an_typetostr(rightside.type, rightside.classname),
|
||||
an_typetostr(leftside.type, leftside.classname));
|
||||
an_push_error(analyzer, assign_node->binary_op.right->token, asn_problem);
|
||||
snprintf(an_problem, sizeof(an_problem),
|
||||
"incompatible types - '%s' is expected, got '%s'",
|
||||
an_typetostr(leftside.type, leftside.classname),
|
||||
an_typetostr(rightside.type, rightside.classname));
|
||||
an_push_error(analyzer, assign_node->binary_op.right->token, an_problem);
|
||||
return (fzl_an_res_t){.error = true};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user