diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-09-14 01:18:16 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-09-14 01:20:01 +0900 |
| commit | 6a45ad108293f9fa4f90eed55fc1101711bcc0ee (patch) | |
| tree | bf3c39cb721bb86085e9555224651dd2c72ef069 | |
| parent | 90246b99595e86e5e6fe41973db1a00171cf0462 (diff) | |
| download | ducc-6a45ad108293f9fa4f90eed55fc1101711bcc0ee.tar.gz ducc-6a45ad108293f9fa4f90eed55fc1101711bcc0ee.tar.zst ducc-6a45ad108293f9fa4f90eed55fc1101711bcc0ee.zip | |
fix: work-around for issue where storage class is changed somewhere
| -rw-r--r-- | src/ast.c | 21 | ||||
| -rw-r--r-- | src/ast.h | 2 | ||||
| -rw-r--r-- | src/codegen.c | 2 | ||||
| -rw-r--r-- | src/parse.c | 7 |
4 files changed, 31 insertions, 1 deletions
@@ -4,6 +4,27 @@ #include "common.h" #include "preprocess.h" +const char* storageclass_stringify(StorageClass s) { + if (s == StorageClass_unspecified) + return ""; + if (s == StorageClass_auto) + return "auto"; + if (s == StorageClass_constexpr) + return "constexpr"; + if (s == StorageClass_extern) + return "extern"; + if (s == StorageClass_register) + return "register"; + if (s == StorageClass_static) + return "static"; + if (s == StorageClass_thread_local) + return "thread_local"; + if (s == StorageClass_typedef) + return "typedef"; + else + unreachable(); +} + const char* type_kind_stringify(TypeKind k) { if (k == TypeKind_unknown) return "<unknown>"; @@ -14,6 +14,8 @@ typedef enum { StorageClass_typedef, } StorageClass; +const char* storageclass_stringify(StorageClass s); + typedef enum { TypeKind_unknown, diff --git a/src/codegen.c b/src/codegen.c index db6514d..716660d 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -597,7 +597,7 @@ static void codegen_stmt(CodeGen* g, AstNode* ast) { static void codegen_func(CodeGen* g, AstNode* ast) { g->current_func = ast; - if (ast->ty->result->storage_class != StorageClass_static) { + if (ast->ty->storage_class != StorageClass_static) { fprintf(g->out, ".globl %s\n", ast->name); } fprintf(g->out, "%s:\n", ast->name); diff --git a/src/parse.c b/src/parse.c index 911a59e..0a23aaa 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1039,12 +1039,16 @@ static Type* parse_array_declarator_suffix(Parser* p, Type* ty) { 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); } @@ -1353,7 +1357,10 @@ static AstNode* parse_func_def(Parser* p, AstNode* decls) { if (decls->node_len != 1) { fatal_error("parse_func_def: invalid syntax"); } + Type* ty = decls->node_items[0].ty; + ty->storage_class = ty->result->storage_class; + ty->result->storage_class = StorageClass_unspecified; const char* name = decls->node_items[0].name; AstNode* params = ty->params; |
