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 <copilot@github.com>
This commit is contained in:
@@ -152,6 +152,7 @@ A.2.4 External definitions
|
||||
*/
|
||||
|
||||
#include <parser_utils.h>
|
||||
#include <scc_ast_utils.h>
|
||||
#include <scc_parser.h>
|
||||
|
||||
scc_ast_expr_t *scc_parse_initializer(scc_parser_t *parser,
|
||||
@@ -186,7 +187,7 @@ scc_ast_expr_t *scc_parse_initializer(scc_parser_t *parser,
|
||||
scc_pos_t pos = tok.loc;
|
||||
scc_lexer_tok_drop(&tok);
|
||||
|
||||
init = scc_malloc(sizeof(scc_ast_expr_t));
|
||||
init = SCC_AST_ALLOC_EXPR(parser->ast_ctx);
|
||||
Assert(init != nullptr);
|
||||
scc_ast_expr_vec_t lhs_exprs;
|
||||
scc_vec_init(lhs_exprs);
|
||||
@@ -202,7 +203,7 @@ scc_ast_expr_t *scc_parse_initializer(scc_parser_t *parser,
|
||||
tok_ptr = scc_parser_peek(parser);
|
||||
if (tok_ptr && tok_ptr->type == SCC_TOK_IDENT) {
|
||||
scc_parser_next_consume(parser, &tok);
|
||||
lhs = scc_malloc(sizeof(scc_ast_expr_t));
|
||||
lhs = SCC_AST_ALLOC_EXPR(parser->ast_ctx);
|
||||
Assert(lhs != nullptr);
|
||||
scc_ast_expr_member_init(lhs, ptr, scc_str_as_cstr(&tok.lexeme),
|
||||
tok.loc);
|
||||
@@ -230,7 +231,7 @@ scc_ast_expr_t *scc_parse_initializer(scc_parser_t *parser,
|
||||
if (!scc_parser_consume_if(parser, SCC_TOK_R_BRACKET)) {
|
||||
SCC_ERROR(scc_parser_got_current_pos(parser), "Expected ']'");
|
||||
}
|
||||
lhs = scc_malloc(sizeof(scc_ast_expr_t));
|
||||
lhs = SCC_AST_ALLOC_EXPR(parser->ast_ctx);
|
||||
Assert(lhs != nullptr);
|
||||
scc_ast_expr_array_subscript_init(lhs, ptr, idx, tok_ptr->loc);
|
||||
if (!scc_parser_consume_if(parser, SCC_TOK_ASSIGN)) {
|
||||
@@ -266,7 +267,7 @@ scc_ast_decl_t *scc_parse_declaration(scc_parser_t *parser) {
|
||||
scc_ast_decl_vec_t decl_list_vec;
|
||||
scc_vec_init(decl_list_vec);
|
||||
|
||||
scc_ast_type_t *type = scc_parse_declaration_specifiers(parser);
|
||||
scc_ast_qual_type_t *type = scc_parse_declaration_specifiers(parser);
|
||||
if (type == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -284,16 +285,17 @@ CONTINUE:
|
||||
if (tok_ptr->type == SCC_TOK_ASSIGN) {
|
||||
scc_parser_next_consume(parser, nullptr);
|
||||
// TODO maybe memory leak
|
||||
scc_ast_expr_t *lvalue = scc_malloc(sizeof(scc_ast_expr_t));
|
||||
scc_ast_expr_t *lvalue = SCC_AST_ALLOC_EXPR(parser->ast_ctx);
|
||||
scc_ast_expr_lvalue_init(lvalue, decl->var.type, decl->base.loc);
|
||||
decl->var.init = scc_parse_initializer(parser, lvalue);
|
||||
} else if (tok_ptr->type == SCC_TOK_L_BRACE) {
|
||||
scc_parse_decl_sema(parser, decl);
|
||||
parser->sema_callbacks.on_decl(parser->sema_callbacks.context,
|
||||
scc_ast_decl_t_BEGIN, nullptr);
|
||||
scc_vec_foreach(decl->func.type->function.params, i) {
|
||||
// FIXME hack struct
|
||||
scc_vec_foreach(decl->func.type->type->function.params, i) {
|
||||
scc_ast_decl_t *param =
|
||||
scc_vec_at(decl->func.type->function.params, i);
|
||||
scc_vec_at(decl->func.type->type->function.params, i);
|
||||
// Add params to decl
|
||||
scc_parse_decl_sema(parser, param);
|
||||
}
|
||||
@@ -342,7 +344,7 @@ CONTINUE:
|
||||
} else if (tok_ptr->type == SCC_TOK_COMMA) {
|
||||
scc_parser_next_consume(parser, nullptr);
|
||||
if (decl_list == nullptr) {
|
||||
decl_list = scc_malloc(sizeof(scc_ast_decl_t));
|
||||
decl_list = SCC_AST_ALLOC_DECL(parser->ast_ctx);
|
||||
Assert(decl_list != nullptr);
|
||||
scc_vec_push(decl_list_vec, decl);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user