aboutsummaryrefslogtreecommitdiffstats
path: root/src/semantic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/semantic.c')
-rw-r--r--src/semantic.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/semantic.c b/src/semantic.c
index 1b40723..d782cac 100644
--- a/src/semantic.c
+++ b/src/semantic.c
@@ -146,6 +146,23 @@ find_struct(Scope *scope, Str type) {
146 return (FindStructResult){0}; 146 return (FindStructResult){0};
147} 147}
148 148
149typedef struct FindSymbolResult {
150 SymbolMap *map;
151 Scope *scope;
152} FindSymbolResult;
153
154FindSymbolResult
155find_symbol(Scope *scope, Str type) {
156 while (scope != NULL) {
157 SymbolMap *val = symmap_lookup(&scope->symbols, type);
158 if (val != NULL) {
159 return (FindSymbolResult){.map = val, .scope = scope};
160 }
161 scope = scope->parent;
162 }
163 return (FindSymbolResult){0};
164}
165
149void 166void
150graph_typescope(Scope *scope, Arena a) { 167graph_typescope(Scope *scope, Arena a) {
151 if (!scope->symbols) { 168 if (!scope->symbols) {
@@ -868,6 +885,13 @@ type_inference(Analyzer *a, Node *node, Scope *scope) {
868 a->err = true; 885 a->err = true;
869 return cstr(""); 886 return cstr("");
870 } 887 }
888
889 FindSymbolResult sym = find_symbol(scope, symbol);
890 node->unique_name = str_concat(cstr("."), symbol, a->storage);
891 node->unique_name =
892 str_concat(node->unique_name,
893 str_from_int(sym.scope->id, a->storage), a->storage);
894
871 Str type_name = type->val.name; 895 Str type_name = type->val.name;
872 if (node->kind == NODE_SYMBOL_IDX) { 896 if (node->kind == NODE_SYMBOL_IDX) {
873 Str idx_type = type_inference(a, node->arr_size, scope); 897 Str idx_type = type_inference(a, node->arr_size, scope);
@@ -904,6 +928,7 @@ type_inference(Analyzer *a, Node *node, Scope *scope) {
904 a->err = true; 928 a->err = true;
905 return cstr(""); 929 return cstr("");
906 } 930 }
931
907 node->next->type = type_name; 932 node->next->type = type_name;
908 node->type = type_name; 933 node->type = type_name;
909 return node->next->type; 934 return node->next->type;