aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parse.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-09-02 00:17:51 +0900
committernsfisis <nsfisis@gmail.com>2025-09-02 00:17:51 +0900
commit16aa2c081db71181ba33aa205d2b0699efa29a99 (patch)
tree56a16139f384c317bcd82c43bea6f7c79e80375b /src/parse.c
parent09a245679c8d01eaec71b22985a9895667280cad (diff)
downloadducc-16aa2c081db71181ba33aa205d2b0699efa29a99.tar.gz
ducc-16aa2c081db71181ba33aa205d2b0699efa29a99.tar.zst
ducc-16aa2c081db71181ba33aa205d2b0699efa29a99.zip
feat: support constant expression in array size
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/parse.c b/src/parse.c
index 57dd316..ecd8e65 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -870,6 +870,8 @@ static Type* parse_pointer_opt(Parser* p, Type* ty) {
return ty;
}
+static int eval(AstNode* e);
+
// array-declarator:
// direct-declarator '[' TODO type-qualifier-list? TODO assignment-expression? ']'
// TODO direct-declarator '[' 'static' type-qualifier-list? assignment-expression? ']'
@@ -878,11 +880,8 @@ static Type* parse_pointer_opt(Parser* p, Type* ty) {
static Type* parse_array_declarator_suffix(Parser* p, Type* ty) {
next_token(p); // skip '['
- AstNode* size_expr = parse_expr(p);
- if (size_expr->kind != AstNodeKind_int_expr) {
- fatal_error("parse_var_decl: invalid array size");
- }
- int size = size_expr->node_int_value;
+ AstNode* size_expr = parse_assignment_expr(p);
+ int size = eval(size_expr);
expect(p, TokenKind_bracket_r);
return type_new_array(ty, size);