aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-06-25 18:06:18 +0200
committerBad Diode <bd@badd10de.dev>2024-06-25 18:06:18 +0200
commit90507290b8b6f9d15605c53480225f5a10a36ca7 (patch)
tree09e87f7e8d2ed5dc2897b1f7c67aaa8bdc3ee41d /src/main.c
parentbc9aa6e8ad03cd739cd54a9b97f78a14287b9fbd (diff)
downloadbdl-90507290b8b6f9d15605c53480225f5a10a36ca7.tar.gz
bdl-90507290b8b6f9d15605c53480225f5a10a36ca7.zip
Update inner struct symbol resolution
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index d3c171c..c8584e4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -598,7 +598,11 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) {
598 Str symbol = node->value.str; 598 Str symbol = node->value.str;
599 // TODO: make sure it didn't exist before. 599 // TODO: make sure it didn't exist before.
600 EnumMap *e = enummap_insert(&scope->enums, symbol, 600 EnumMap *e = enummap_insert(&scope->enums, symbol,
601 (Enum){.name = symbol}, a->storage); 601 (Enum){
602 .name = symbol,
603 .val = node->field_val,
604 },
605 a->storage);
602 for (sz i = 0; i < array_size(node->struct_field); i++) { 606 for (sz i = 0; i < array_size(node->struct_field); i++) {
603 Node *field = node->struct_field[i]; 607 Node *field = node->struct_field[i];
604 Str field_name = str_concat(symbol, cstr("."), a->storage); 608 Str field_name = str_concat(symbol, cstr("."), a->storage);
@@ -867,18 +871,21 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) {
867 StructMap *s = find_struct(scope, type->val); 871 StructMap *s = find_struct(scope, type->val);
868 if (s && !str_eq(symbol, type->val)) { 872 if (s && !str_eq(symbol, type->val)) {
869 if (node->next) { 873 if (node->next) {
870 FieldMap *field = 874 Str chain = type->val;
871 fieldmap_lookup(&s->val.fields, node->next->value.str); 875 Node *next = node;
876 while (next->next) {
877 next = next->next;
878 chain = str_concat(chain, cstr("."), a->storage);
879 chain = str_concat(chain, next->value.str, a->storage);
880 }
881 StructMap *field = find_struct(scope, chain);
872 if (!field) { 882 if (!field) {
873 eprintln( 883 eprintln("%s:%d:%d: error: unknown struct field '%s'",
874 "%s:%d:%d: error: unknown struct field for symbol " 884 a->file_name, node->line, node->col, chain);
875 "'%s'",
876 a->file_name, node->line, node->col, symbol);
877 return cstr(""); 885 return cstr("");
878 } 886 }
879 node->next->type = field->val.type; 887 node->type = field->val.type;
880 node->type = type->val; 888 return node->type;
881 return node->next->type;
882 } 889 }
883 } 890 }
884 node->type = type->val; 891 node->type = type->val;