From 6488032643944c0ca09a1d33689ccd93ea37f7af Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 30 Aug 2025 11:34:50 +0900 Subject: refactor: define enum StorageClass --- src/ast.h | 14 +++++++++++++- src/parse.c | 6 ++++-- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ast.h b/src/ast.h index 108d436..8e70260 100644 --- a/src/ast.h +++ b/src/ast.h @@ -3,6 +3,18 @@ #include "std.h" +enum StorageClass { + StorageClass_unspecified, + StorageClass_auto, + StorageClass_constexpr, + StorageClass_extern, + StorageClass_register, + StorageClass_static, + StorageClass_thread_local, + StorageClass_typedef, +}; +typedef enum StorageClass StorageClass; + enum TypeKind { TypeKind_unknown, @@ -32,11 +44,11 @@ typedef struct TypeRef TypeRef; struct Type { TypeKind kind; + StorageClass storage_class; // Check `base` instead of `kind` to test if the type is an array or a pointer. struct Type* base; int array_size; TypeRef ref; - BOOL is_static; }; typedef struct Type Type; diff --git a/src/parse.c b/src/parse.c index fe623a5..bafb156 100644 --- a/src/parse.c +++ b/src/parse.c @@ -589,7 +589,9 @@ static Type* parse_type(Parser* p) { } ty = type_new_ptr(ty); } - ty->is_static = has_static; + if (has_static) { + ty->storage_class = StorageClass_static; + } return ty; } @@ -1265,7 +1267,7 @@ static AstNode* parse_func_decl_or_def(Parser* p) { func->node_stack_size = p->lvars.data[p->lvars.len - 1].stack_offset + type_sizeof(p->lvars.data[p->lvars.len - 1].ty); } - func->node_function_is_static = ty->is_static; + func->node_function_is_static = ty->storage_class == StorageClass_static; return func; } -- cgit v1.2.3-70-g09d2