feat: 类型别名 type alias (P1 #10)

- lexer: TOK_TYPE 关键字
- ast: AST_TYPE_ALIAS + AST_PROGRAM aliases数组
- parser: parse_type_expr() 抽取, type Name = Type; 解析
- sema: 别名注册+解析, 类型标注/struct字段/函数参数均支持
- 新增测试: 15_type_alias.l, 16_type_alias_struct.l

测试: 112 通过 (41+15+41+15)
This commit is contained in:
2026-06-05 13:54:58 +08:00
parent da9a7065dd
commit ab88ea2753
13 changed files with 235 additions and 79 deletions
+6 -6
View File
@@ -13,7 +13,7 @@ void test_codegen_simple_function() {
AstNode* body = ast_make_block(&a, stmts, 1, loc_at(1, 1));
AstNode* fn = ast_make_function(&a, "main", NULL, 0, TYPE_I64, NULL, body, loc_at(1, 1));
AstNode* fns[] = { fn };
AstNode* prog = ast_make_program(&a, fns, 1, NULL, 0, loc_at(1, 1));
AstNode* prog = ast_make_program(&a, fns, 1, NULL, 0, NULL, 0, loc_at(1, 1));
const char* err = NULL;
LLVMContextRef ctx = NULL;
@@ -47,7 +47,7 @@ void test_codegen_if_else() {
AstNode* body = ast_make_block(&a, stmts, 1, loc_at(1, 1));
AstNode* fn = ast_make_function(&a, "main", NULL, 0, TYPE_I64, NULL, body, loc_at(1, 1));
AstNode* fns[] = { fn };
AstNode* prog = ast_make_program(&a, fns, 1, NULL, 0, loc_at(1, 1));
AstNode* prog = ast_make_program(&a, fns, 1, NULL, 0, NULL, 0, loc_at(1, 1));
const char* err = NULL;
LLVMContextRef ctx2 = NULL;
@@ -78,7 +78,7 @@ void test_codegen_binary_ops() {
AstNode* body = ast_make_block(&a, stmts, 1, loc_at(1, 1));
AstNode* fn = ast_make_function(&a, "main", NULL, 0, TYPE_I64, NULL, body, loc_at(1, 1));
AstNode* fns[] = { fn };
AstNode* prog = ast_make_program(&a, fns, 1, NULL, 0, loc_at(1, 1));
AstNode* prog = ast_make_program(&a, fns, 1, NULL, 0, NULL, 0, loc_at(1, 1));
const char* err = NULL;
LLVMContextRef ctx3 = NULL;
@@ -108,7 +108,7 @@ void test_codegen_while_loop() {
AstNode* fn_body = ast_make_block(&a, stmts, 2, loc_at(1, 1));
AstNode* fn = ast_make_function(&a, "main", NULL, 0, TYPE_I64, NULL, fn_body, loc_at(1, 1));
AstNode* fns[] = { fn };
AstNode* prog = ast_make_program(&a, fns, 1, NULL, 0, loc_at(1, 1));
AstNode* prog = ast_make_program(&a, fns, 1, NULL, 0, NULL, 0, loc_at(1, 1));
const char* err = NULL;
LLVMContextRef ctx4 = NULL;
@@ -162,7 +162,7 @@ void test_codegen_struct_decl() {
AstNode* fn = ast_make_function(&a, "main", NULL, 0, TYPE_I64, NULL, body, loc_at(1, 1));
AstNode* fns[] = { fn };
AstNode* prog = ast_make_program(&a, fns, 1, structs, 1, loc_at(1, 1));
AstNode* prog = ast_make_program(&a, fns, 1, structs, 1, NULL, 0, loc_at(1, 1));
const char* err = NULL;
LLVMContextRef ctx = NULL;
@@ -217,7 +217,7 @@ void test_codegen_struct_field_access() {
AstNode* fn = ast_make_function(&a, "main", NULL, 0, TYPE_I64, NULL, body, loc_at(1, 1));
AstNode* fns[] = { fn };
AstNode* prog = ast_make_program(&a, fns, 1, structs, 1, loc_at(1, 1));
AstNode* prog = ast_make_program(&a, fns, 1, structs, 1, NULL, 0, loc_at(1, 1));
const char* err = NULL;
LLVMContextRef ctx = NULL;