diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-14 23:30:18 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-14 23:30:18 +0900 |
| commit | ef0cb4dbdc1c036f70f94a905cbacae9be5abf5e (patch) | |
| tree | 39e612997349dd66050fe5820fefc4da65457821 | |
| parent | 5a1789c2de30ec503e488ca77d664199a545a04a (diff) | |
| download | ducc-ef0cb4dbdc1c036f70f94a905cbacae9be5abf5e.tar.gz ducc-ef0cb4dbdc1c036f70f94a905cbacae9be5abf5e.tar.zst ducc-ef0cb4dbdc1c036f70f94a905cbacae9be5abf5e.zip | |
refactor: shallow copy typedef-ed types to remove work-around
| -rw-r--r-- | src/ast.c | 6 | ||||
| -rw-r--r-- | src/ast.h | 1 | ||||
| -rw-r--r-- | src/parse.c | 8 |
3 files changed, 10 insertions, 5 deletions
@@ -88,6 +88,12 @@ Type* type_new(TypeKind kind) { return ty; } +Type* type_dup(Type* src) { + Type* ty = malloc(sizeof(Type)); + memcpy(ty, src, sizeof(Type)); + return ty; +} + Type* type_new_ptr(Type* base) { Type* ty = type_new(TypeKind_ptr); ty->base = base; @@ -65,6 +65,7 @@ typedef struct Type { } Type; Type* type_new(TypeKind kind); +Type* type_dup(Type* src); Type* type_new_ptr(Type* base); Type* type_new_array(Type* elem, int size); Type* type_new_static_string(int len); diff --git a/src/parse.c b/src/parse.c index aeafabd..494e4a2 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1209,15 +1209,12 @@ static Type* parse_function_declarator_suffix(Parser* p, Type* ty) { next_token(p); // skip '(' AstNode* params; - // FIXME: save and restore ty->storage_class because it will be modified somewhere for some reason. - StorageClass FIXME_storage_class = ty->storage_class; if (consume_token_if(p, TokenKind_paren_r)) { params = ast_new_list(1); } else { params = parse_parameter_type_list(p); expect(p, TokenKind_paren_r); } - ty->storage_class = FIXME_storage_class; return type_new_func(ty, params); } @@ -1693,7 +1690,7 @@ static Type* parse_declaration_specifiers(Parser* p) { } next_token(p); int typedef_idx = find_typedef(p, tok->value.string); - ty = p->typedefs->as.list->items[typedef_idx].ty; + ty = type_dup(p->typedefs->as.list->items[typedef_idx].ty); type_specifiers += TypeSpecifierMask_typedef_name; } // type-specifier-qualifier > type-qualifier @@ -2047,7 +2044,7 @@ static Type* parse_specifier_qualifier_list(Parser* p) { } next_token(p); int typedef_idx = find_typedef(p, tok->value.string); - ty = p->typedefs->as.list->items[typedef_idx].ty; + ty = type_dup(p->typedefs->as.list->items[typedef_idx].ty); type_specifiers += TypeSpecifierMask_typedef_name; } // type-specifier-qualifier > type-qualifier @@ -2075,6 +2072,7 @@ static Type* parse_specifier_qualifier_list(Parser* p) { ty = ty_; } + ty->storage_class = StorageClass_unspecified; return ty; } |
