refactor(ast): 将AST类型系统重构为规范类型系统
- 将scc_ast_type_t替换为scc_ast_qual_type_t,引入规范类型概念 - 添加scc_ast_canonical_type_t联合体用于表示规范类型 - 修改头文件结构,移除大量内联初始化函数,改为使用AST上下文分配器 - 添加SCC_AST_ALLOC宏用于统一节点分配管理 - 更新builtin类型枚举定义,添加类型计数常量 feat(ast): 引入AST上下文管理器 - 创建scc_ast_ctx_t结构体用于管理AST节点生命周期 - 实现类型池化机制,支持内置类型的统一管理 - 添加canonical类型获取和分配接口 refactor(abi): 适配新的AST类型系统 - 更新头文件包含,从<scc_ir.h>改为<scc_hir.h> - 适配函数参数类型,使用qual_type替代原始type - 使用scc_ast_canon_type()函数获取规范类型进行处理 Co-authored-by: Copilot <[email protected]>
This commit is contained in:
1 parent
d7ac5fd30b
commit
f6bc40ae4a
20 files changed
+1302
-1045
No files matched your search
@@ -0,0 +1,42 @@
|
||||
#include <scc_ast.h>
|
||||
|
||||
static scc_ast_canon_type_t *alloc_canonical_type(scc_ast_ctx_t *ctx) {
|
||||
scc_ast_canon_type_t *type = scc_malloc(sizeof(scc_ast_canon_type_t));
|
||||
if (type == nullptr) {
|
||||
Panic("alloc_canonical_type: malloc failed");
|
||||
}
|
||||
scc_vec_push(ctx->canonical_type_pool, type);
|
||||
return type;
|
||||
}
|
||||
|
||||
void scc_ast_ctx_init(scc_ast_ctx_t *ctx) {
|
||||
scc_vec_init(ctx->canonical_type_pool);
|
||||
scc_vec_init(ctx->all_nodes);
|
||||
|
||||
// 创建全部内置类型
|
||||
for (int i = 0; i < SCC_AST_BUILTIN_TYPE_COUNT; i += 1) {
|
||||
scc_ast_canon_type_t *t = alloc_canonical_type(ctx);
|
||||
t->builtin.type = (scc_ast_builtin_type_t)i; // 直接按顺序对应
|
||||
ctx->builtin_types[i] = t;
|
||||
}
|
||||
}
|
||||
|
||||
void scc_ast_ctx_drop(scc_ast_ctx_t *ctx) {
|
||||
// 释放所有规范类型
|
||||
scc_vec_foreach(ctx->canonical_type_pool, i) {
|
||||
scc_free(ctx->canonical_type_pool.data[i]);
|
||||
}
|
||||
scc_vec_foreach(ctx->all_nodes, i) { scc_free(ctx->all_nodes.data[i]); }
|
||||
scc_vec_free(ctx->canonical_type_pool);
|
||||
}
|
||||
|
||||
scc_ast_canon_type_t *
|
||||
scc_ast_ctx_get_builtin_type(scc_ast_ctx_t *ctx, scc_ast_builtin_type_t kind) {
|
||||
assert(kind < SCC_AST_BUILTIN_TYPE_COUNT &&
|
||||
kind > SCC_AST_BUILTIN_TYPE_UNKNOWN);
|
||||
return ctx->builtin_types[kind];
|
||||
}
|
||||
|
||||
scc_ast_canon_type_t *scc_ast_ctx_alloc_type(scc_ast_ctx_t *ctx) {
|
||||
return alloc_canonical_type(ctx);
|
||||
}
|
||||
Reference in new issue
Block a user