feat(parser): 实现赋值表达式和常量表达式解析功能
- 添加 scc_parse_assignment_expression 函数用于解析赋值表达式 - 添加 scc_parser_constant_expression 函数用于解析常量表达式 - 修改 cast 表达式解析逻辑,修复类型转换解析问题 - 改进错误处理机制,使用 SCC_ERROR 替代 LOG_ERROR 并提供准确位置信息 - 移除未使用的变量声明,优化代码结构 refactor(ast): 调整类型定义中的 typedef 类型存储结构 - 将 scc_ast_type 中的 underlying 字段改为 decl 字段 - 更新相关初始化函数以适配新的字段名称 - 修复枚举类型初始化时缺失的 decl 字段设置 feat(ast): 添加类型转换、sizeof 和 alignof 表达式的初始化函数 - 实现 scc_ast_expr_cast_init 用于初始化类型转换表达式 - 实现 scc_ast_expr_sizeof_init 用于初始化 sizeof 表达式 - 实现 scc_ast_expr_alignof_init 用于初始化 alignof 表达式 - 完善表达式类型的支持 chore(parser): 增加语义分析回调接口和位置获取工具函数 - 添加 scc_parse_decl_sema、scc_parse_type_sema 等语义分析辅助函数 - 提供 scc_parser_got_current_pos 函数获取当前解析位置 - 增强错误报告的准确性 refactor(dump): 完善 AST 转储功能,支持 break 和 continue 语句 - 为 SCC_AST_STMT_BREAK 和 SCC_AST_STMT_CONTINUE 添加转储支持 - 优化转储函数的分支处理结构
This commit is contained in:
@@ -341,10 +341,33 @@ static inline void scc_ast_expr_ptr_member_init(scc_ast_expr_t *expr,
|
||||
_scc_ast_expr_member_init(expr, SCC_AST_EXPR_PTR_MEMBER, object, member);
|
||||
}
|
||||
|
||||
// TODO
|
||||
// SCC_AST_EXPR_CAST, // 类型转换
|
||||
// SCC_AST_EXPR_SIZE_OF, // sizeof
|
||||
// SCC_AST_EXPR_ALIGN_OF, // _Alignof
|
||||
static inline void scc_ast_expr_cast_init(scc_ast_expr_t *expr,
|
||||
scc_ast_type_t *type,
|
||||
scc_ast_expr_t *operand) {
|
||||
Assert(expr != null && type != null && operand != null);
|
||||
expr->base.loc = scc_pos_create();
|
||||
expr->base.type = SCC_AST_EXPR_CAST;
|
||||
expr->cast.type = type;
|
||||
expr->cast.expr = operand;
|
||||
}
|
||||
|
||||
static inline void scc_ast_expr_sizeof_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_SIZE_OF;
|
||||
expr->attr_of.type = type;
|
||||
expr->attr_of.expr = null;
|
||||
}
|
||||
|
||||
static inline void scc_ast_expr_alignof_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_SIZE_OF;
|
||||
expr->attr_of.type = type;
|
||||
expr->attr_of.expr = null;
|
||||
}
|
||||
|
||||
// init can be null
|
||||
static inline void
|
||||
@@ -486,18 +509,18 @@ static inline void scc_ast_type_enum_init(scc_ast_type_t *type,
|
||||
type->base.type = SCC_AST_TYPE_ENUM;
|
||||
type->quals = (scc_ast_decl_specifier_t){0}; // FIXME
|
||||
type->enumeration.name = name;
|
||||
type->enumeration.decl = null;
|
||||
type->enumeration.decl = decl;
|
||||
}
|
||||
|
||||
static inline void scc_ast_type_typedef_init(scc_ast_type_t *type,
|
||||
const char *name,
|
||||
scc_ast_type_t *target) {
|
||||
scc_ast_decl_t *target) {
|
||||
Assert(type != null && target != null);
|
||||
type->base.loc = scc_pos_create();
|
||||
type->base.type = SCC_AST_TYPE_TYPEDEF;
|
||||
type->quals = (scc_ast_decl_specifier_t){0}; // FIXME
|
||||
type->typedef_type.name = name;
|
||||
type->typedef_type.underlying = target;
|
||||
type->typedef_type.decl = target;
|
||||
}
|
||||
|
||||
#endif /* __SCC_AST_H__ */
|
||||
|
||||
Reference in New Issue
Block a user