feat(ast): 添加内置类型定义和AST节点初始化函数

添加了完整的内置类型支持,包括整数、浮点数、字符、布尔等基本类型,
以及它们的有符号/无符号变体。同时添加了大量的AST节点初始化函数,
简化了AST节点的创建过程。

BREAKING CHANGE: 重构了AST表达式和声明结构,移除了冗余字段,
统一了命名规范,并修改了函数调用和成员访问的表示方式。
This commit is contained in:
zzy
2026-03-10 13:56:32 +08:00
parent 80714fe7e5
commit 2e331ee016
17 changed files with 981 additions and 581 deletions

View File

@@ -188,7 +188,6 @@ scc_ast_decl_t *scc_parse_declaration(scc_parser_t *parser) {
}
scc_ast_decl_t *decl = scc_malloc(sizeof(scc_ast_decl_t));
/*
(6.7.5) declarator:
pointeropt direct-declarator
@@ -203,18 +202,14 @@ scc_ast_decl_t *scc_parse_declaration(scc_parser_t *parser) {
direct-declarator ( identifier-listopt )
*/
if (!scc_parser_consume_if(parser, SCC_TOK_L_PAREN)) {
// TODO
if (scc_parser_consume_if(parser, SCC_TOK_SEMICOLON)) {
decl->base.type = SCC_AST_DECL_VAR;
decl->var.type = type;
decl->var.name = scc_cstring_as_cstr(&tok.lexeme);
decl->var.init = null;
scc_ast_decl_val_init(decl, type, scc_cstring_as_cstr(&tok.lexeme),
null);
goto RETURN;
} else if (scc_parser_consume_if(parser, SCC_TOK_ASSIGN)) {
decl->base.type = SCC_AST_DECL_VAR;
decl->var.type = type;
decl->var.name = scc_cstring_as_cstr(&tok.lexeme);
decl->var.init = scc_parse_expression(parser);
scc_ast_expr_t *init = scc_parse_expression(parser);
scc_ast_decl_val_init(decl, type, scc_cstring_as_cstr(&tok.lexeme),
init);
goto RETURN;
}
// TODO
@@ -223,13 +218,11 @@ scc_ast_decl_t *scc_parse_declaration(scc_parser_t *parser) {
// function decl
decl->base.type = SCC_AST_DECL_FUNC;
decl->func.name = scc_cstring_as_cstr(&tok.lexeme);
decl->name = scc_cstring_as_cstr(&tok.lexeme);
decl->func.type = scc_malloc(sizeof(scc_ast_type_t));
decl->func.type->base.type = SCC_AST_TYPE_FUNCTION;
scc_vec_init(decl->func.type->function.param_types);
decl->func.type->function.return_type = type;
// TODO
decl->func.type->function.is_variadic = false;
// TODO param type
scc_parser_consume_if(parser, SCC_TOK_VOID);