feat(ast): 添加复合表达式和初始化器解析支持

重构AST表达式枚举,将COMPOUND_LITERAL重命名为COMPOUND,
更新相关结构体定义以支持复合字面量的左右表达式向量表示。

添加lvalue表达式类型用于左值处理,实现完整的初始化器解析功能,
包括大括号初始化列表、成员访问和数组下标的处理逻辑。

更新表达式解析器为基于优先级的递归下降解析,修复变量声明中
初始化表达式的内存泄漏问题。

完善类型限定符和存储类说明符的重复检查机制,增强语法分析的准确性。
This commit is contained in:
zzy
2026-03-12 21:14:08 +08:00
parent b00a42a539
commit c46578736a
15 changed files with 495 additions and 225 deletions

View File

@@ -369,19 +369,28 @@ static inline void scc_ast_expr_alignof_init(scc_ast_expr_t *expr,
expr->attr_of.expr = null;
}
// init can be null
static inline void
scc_ast_expr_compound_literal_init(scc_ast_expr_t *expr, scc_ast_type_t *type,
scc_ast_expr_vec_t *init) {
Assert(expr != null && type != null);
// lhs_exprs and rhs_exprs can be null
static inline void scc_ast_expr_compound_init(scc_ast_expr_t *expr,
scc_ast_expr_t *base,
scc_ast_expr_vec_t *lhs_exprs,
scc_ast_expr_vec_t *rhs_exprs) {
Assert(expr != null && base != null);
expr->base.loc = scc_pos_create();
expr->base.type = SCC_AST_EXPR_COMPOUND_LITERAL;
expr->compound_literal.type = type;
if (init == null) {
scc_vec_init(expr->compound_literal.init_list);
expr->base.type = SCC_AST_EXPR_COMPOUND;
expr->compound.base = base;
if (lhs_exprs == null) {
scc_vec_init(expr->compound.lhs_exprs);
} else {
expr->compound_literal.init_list = *init;
scc_vec_init(*init);
expr->compound.lhs_exprs = *lhs_exprs;
scc_vec_init(*lhs_exprs);
}
if (rhs_exprs == null) {
scc_vec_init(expr->compound.rhs_exprs);
} else {
expr->compound.rhs_exprs = *rhs_exprs;
scc_vec_init(*rhs_exprs);
}
}
@@ -426,6 +435,14 @@ static inline void scc_ast_expr_identifier_init(scc_ast_expr_t *expr,
expr->identifier._target = null;
}
static inline void scc_ast_expr_lvalue_init(scc_ast_expr_t *expr,
scc_ast_type_t *type) {
Assert(expr != null && type != null);
expr->base.loc = scc_pos_create();
expr->base.type = SCC_AST_EXPR_IDENTIFIER;
expr->lvalue.type = type;
}
// have defined builtin type
static inline void _scc_ast_type_builtin_init(scc_ast_type_t *type,
scc_ast_builtin_type_t builtin) {