- 将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 <copilot@github.com>
49 lines
1.7 KiB
C
49 lines
1.7 KiB
C
#ifndef __SCC_AST_H__
|
|
#define __SCC_AST_H__
|
|
|
|
#include "scc_ast_def.h"
|
|
|
|
typedef struct scc_ast_ctx {
|
|
scc_ast_canon_type_vec_t canonical_type_pool;
|
|
scc_ast_canon_type_t *builtin_types[SCC_AST_BUILTIN_TYPE_COUNT];
|
|
scc_ast_node_vec_t all_nodes;
|
|
} scc_ast_ctx_t;
|
|
|
|
void scc_ast_ctx_init(scc_ast_ctx_t *ctx);
|
|
void scc_ast_ctx_drop(scc_ast_ctx_t *ctx);
|
|
|
|
scc_ast_canon_type_t *scc_ast_ctx_get_builtin_type(scc_ast_ctx_t *ctx,
|
|
scc_ast_builtin_type_t kind);
|
|
|
|
scc_ast_canon_type_t *scc_ast_ctx_alloc_type(scc_ast_ctx_t *ctx);
|
|
|
|
static inline void *scc_ast_ctx_alloc_node(scc_ast_ctx_t *ctx, usize size) {
|
|
void *ptr = scc_malloc(size);
|
|
if (ptr == nullptr) {
|
|
Panic("Out of memory");
|
|
}
|
|
scc_memset(ptr, 0, size);
|
|
scc_vec_push(ctx->all_nodes, (scc_ast_node_t *)ptr);
|
|
return ptr;
|
|
}
|
|
|
|
#define SCC_AST_ALLOC(ctx, type) \
|
|
((type *)scc_ast_ctx_alloc_node(ctx, sizeof(type)))
|
|
#define SCC_AST_ALLOC_QUAL_TYPE(ctx) SCC_AST_ALLOC(ctx, scc_ast_qual_type_t)
|
|
#define SCC_AST_ALLOC_DECL(ctx) SCC_AST_ALLOC(ctx, scc_ast_decl_t)
|
|
#define SCC_AST_ALLOC_EXPR(ctx) SCC_AST_ALLOC(ctx, scc_ast_expr_t)
|
|
#define SCC_AST_ALLOC_STMT(ctx) SCC_AST_ALLOC(ctx, scc_ast_stmt_t)
|
|
|
|
// have defined cannoical_type type
|
|
static inline void
|
|
scc_ast_type_builtin_init(scc_ast_qual_type_t *type, scc_ast_ctx_t *ctx,
|
|
scc_ast_builtin_type_t builtin_type, scc_pos_t loc) {
|
|
Assert(type != nullptr);
|
|
type->base.loc = loc;
|
|
type->base.type = SCC_AST_TYPE_BUILTIN;
|
|
type->type = scc_ast_ctx_get_builtin_type(ctx, builtin_type);
|
|
type->quals = (scc_ast_decl_specifier_t){0}; // FIXME
|
|
}
|
|
|
|
#endif /* __SCC_AST_H__*/
|