Skip to content

Commit a2c1c63

Browse files
marcomarquesdcBeyondMagic
authored andcommitted
Update semantic.c
A lógica principal. Marcar uso e conectar declaração.
1 parent ad1c76a commit a2c1c63

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/semantic.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int analyze_function(SemanticInfo *info, AstFunction *fn)
8888
symbol_table_free(&symbols);
8989
return 0;
9090
}
91-
if (!symbol_table_add(&symbols, param->name, param->type, 0, 0, TYPE_UNKNOWN))
91+
if (!symbol_table_add(&symbols, param->name, param->type, 0, 0, TYPE_UNKNOWN, NULL))
9292
{
9393
semantic_error("duplicate parameter '%s' in function '%s'", param->name, fn->name);
9494
symbol_table_free(&symbols);
@@ -222,7 +222,7 @@ static int analyze_statement(SemanticInfo *info, AstFunction *fn, SymbolTable *s
222222
}
223223
else
224224
{
225-
if (!symbol_table_add(symbols, stmt->data.decl.name, stmt->data.decl.type, 0, 0, TYPE_UNKNOWN))
225+
if (!symbol_table_add(symbols, stmt->data.decl.name, stmt->data.decl.type, 0, 0, TYPE_UNKNOWN, stmt))
226226
{
227227
semantic_error("duplicate declaration of '%s' in function '%s'", stmt->data.decl.name, fn->name);
228228
return 0;
@@ -451,6 +451,15 @@ static TypeKind analyze_expression(SemanticInfo *info, SymbolTable *symbols, Ast
451451
expr->type = symbol->type;
452452
return expr->type;
453453
}
454+
if (symbol->stmt_ref)
455+
{
456+
symbol->stmt_ref->data.decl.is_used = 1;
457+
}
458+
// ---------------------------
459+
460+
expr->type = symbol->type;
461+
return expr->type;
462+
}
454463
case EXPR_SUBSCRIPT:
455464
{
456465
AstExpr *array_expr = expr->data.subscript.array;

0 commit comments

Comments
 (0)