diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-25 18:06:18 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-25 18:06:18 +0200 |
commit | 90507290b8b6f9d15605c53480225f5a10a36ca7 (patch) | |
tree | 09e87f7e8d2ed5dc2897b1f7c67aaa8bdc3ee41d /src | |
parent | bc9aa6e8ad03cd739cd54a9b97f78a14287b9fbd (diff) | |
download | bdl-90507290b8b6f9d15605c53480225f5a10a36ca7.tar.gz bdl-90507290b8b6f9d15605c53480225f5a10a36ca7.zip |
Update inner struct symbol resolution
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 27 | ||||
-rw-r--r-- | src/parser.c | 3 |
2 files changed, 18 insertions, 12 deletions
@@ -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; |
diff --git a/src/parser.c b/src/parser.c index 1e54776..e38f2ca 100644 --- a/src/parser.c +++ b/src/parser.c | |||
@@ -488,10 +488,9 @@ parse_type(Parser *parser) { | |||
488 | void | 488 | void |
489 | parse_struct_field(Parser *parser) { | 489 | parse_struct_field(Parser *parser) { |
490 | if (parser->panic) return; | 490 | if (parser->panic) return; |
491 | Token prev = parser->previous; | ||
492 | #if DEBUG == 1 | 491 | #if DEBUG == 1 |
493 | print("parsing struct field "); | 492 | print("parsing struct field "); |
494 | print_token(prev); | 493 | print_token(parser->previous); |
495 | #endif | 494 | #endif |
496 | Node *field = node_alloc(parser, NODE_FIELD, parser->current); | 495 | Node *field = node_alloc(parser, NODE_FIELD, parser->current); |
497 | if (!field) return; | 496 | if (!field) return; |