refactor(ast): 移除内置类型头文件并优化类型初始化

移除了独立的ast_builtin.h头文件,将内置类型定义整合到现有结构中,
同时修复了类型初始化函数命名不一致的问题。

BREAKING CHANGE: 原有的ast_builtin.h头文件已被移除,
相关内置类型声明已重构为新的接口形式。

fix(parser): 修复表达式解析中的位置信息处理

确保条件表达式和逗号表达式的解析正确获取并传递位置信息,
避免在语法树构建过程中丢失源码位置。

refactor(ir): 修复IR转储中的类型转换问题

添加必要的类型转换以防止整数溢出,并优化代码格式以提高可读性。

feat(parser): 添加表达式解析测试套件

引入全面的表达式解析测试框架,覆盖从基本表达式到复杂嵌套表达式
的各种场景,确保解析器功能的正确性和稳定性。
This commit is contained in:
zzy
2026-03-18 12:18:56 +08:00
parent 2e5e98868d
commit 5f915ba8d3
12 changed files with 1376 additions and 1370 deletions

View File

@@ -21,7 +21,7 @@ static const char *get_node_type_str(scc_ir_node_tag_t tag) {
[SCC_IR_NODE_RET] = "Return",
};
if (tag >= 0 && tag < sizeof(node_types) / sizeof(node_types[0]) &&
if (tag >= 0 && (usize)tag < sizeof(node_types) / sizeof(node_types[0]) &&
node_types[tag] != NULL) {
return node_types[tag];
}
@@ -39,11 +39,12 @@ static const char *get_op_str(scc_ir_op_type_t op) {
[SCC_IR_OP_DIV] = "/", [SCC_IR_OP_MOD] = "%",
[SCC_IR_OP_AND] = "&", [SCC_IR_OP_OR] = "|",
[SCC_IR_OP_XOR] = "^", [SCC_IR_OP_NOT] = "~",
[SCC_IR_OP_SHL] = "<<", [SCC_IR_OP_SHR] = ">>",
[SCC_IR_OP_SHL] = "<<", [SCC_IR_OP_SHR] = ">>",
[SCC_IR_OP_SAR] = ">>a", // Arithmetic shift right
};
if (op >= 0 && op < sizeof(ops) / sizeof(ops[0]) && ops[op] != NULL) {
if (op >= 0 && (usize)op < sizeof(ops) / sizeof(ops[0]) &&
ops[op] != NULL) {
return ops[op];
}
return "<unknown_op>";
@@ -64,7 +65,7 @@ static const char *get_type_tag_str(scc_ir_type_tag_t tag) {
[SCC_IR_TYPE_STRUCT] = "struct", [SCC_IR_TYPE_VECTOR] = "vector",
};
if (tag >= 0 && tag < sizeof(type_tags) / sizeof(type_tags[0]) &&
if (tag >= 0 && (usize)tag < sizeof(type_tags) / sizeof(type_tags[0]) &&
type_tags[tag] != NULL) {
return type_tags[tag];
}