feat: struct参数/返回值 + SourceLoc + 测试补全
- struct 可作函数参数和返回值 (fn make_point -> Point) - SourceLoc 抽象: 所有 ast_make_* 参数 + AstNode 迁移完毕 - sema: +4 struct 类型检查测试 (字段类型/未定义/数量/嵌套) - codegen: +2 struct IR 生成测试 (decl + field_access) - 新增集成测试 14_struct_fn.l 测试: 104 单元 + 14 集成 = 全部通过
This commit is contained in:
+24
-24
@@ -42,8 +42,7 @@ typedef struct {
|
||||
struct AstNode {
|
||||
AstKind kind;
|
||||
TypeInfo type; // 语义分析后填充,默认为 TYPE_UNKNOWN
|
||||
int line; // 源文件行号
|
||||
int col; // 源文件列号
|
||||
SourceLoc loc; // 源码位置
|
||||
|
||||
// 节点特有数据(按 kind 解释)
|
||||
union {
|
||||
@@ -52,7 +51,8 @@ struct AstNode {
|
||||
struct AstNode** structs; size_t struct_count; } program;
|
||||
// AST_FUNCTION
|
||||
struct { const char* name; struct AstNode** params; size_t param_count;
|
||||
TypeKind return_type; struct AstNode* body; } function;
|
||||
TypeKind return_type; const char* return_struct_type_name;
|
||||
struct AstNode* body; } function;
|
||||
// AST_PARAMETER (也用作结构体字段: name + type)
|
||||
struct { const char* name; TypeKind type; const char* struct_type_name; } parameter;
|
||||
// AST_BLOCK
|
||||
@@ -92,28 +92,28 @@ struct AstNode {
|
||||
|
||||
// 创建节点的辅助函数(内存来自 arena,通过 void* 传递避免循环依赖)
|
||||
AstNode* ast_make_program(void* alloc, AstNode** fns, size_t fn_count,
|
||||
AstNode** structs, size_t struct_count, int line, int col);
|
||||
AstNode** structs, size_t struct_count, SourceLoc loc);
|
||||
AstNode* ast_make_function(void* alloc, const char* name, AstNode** params, size_t pcount,
|
||||
TypeKind ret, AstNode* body, int line, int col);
|
||||
AstNode* ast_make_parameter(void* alloc, const char* name, TypeKind type, const char* struct_type_name, int line, int col);
|
||||
AstNode* ast_make_block(void* alloc, AstNode** stmts, size_t count, int line, int col);
|
||||
TypeKind ret, const char* ret_struct_name, AstNode* body, SourceLoc loc);
|
||||
AstNode* ast_make_parameter(void* alloc, const char* name, TypeKind type, const char* struct_type_name, SourceLoc loc);
|
||||
AstNode* ast_make_block(void* alloc, AstNode** stmts, size_t count, SourceLoc loc);
|
||||
AstNode* ast_make_let(void* alloc, const char* name, TypeKind annot_type, bool has_type_annot,
|
||||
bool is_mut, AstNode* init, const char* struct_type_name, int line, int col);
|
||||
AstNode* ast_make_assign(void* alloc, const char* name, AstNode* value, int line, int col);
|
||||
AstNode* ast_make_if(void* alloc, AstNode* cond, AstNode* then_b, AstNode* else_b, int line, int col);
|
||||
AstNode* ast_make_while(void* alloc, AstNode* cond, AstNode* body, int line, int col);
|
||||
AstNode* ast_make_return(void* alloc, AstNode* expr, int line, int col);
|
||||
AstNode* ast_make_expr_stmt(void* alloc, AstNode* expr, int line, int col);
|
||||
AstNode* ast_make_binary(void* alloc, BinaryOp op, AstNode* left, AstNode* right, int line, int col);
|
||||
AstNode* ast_make_unary(void* alloc, BinaryOp op, AstNode* operand, int line, int col);
|
||||
AstNode* ast_make_call(void* alloc, const char* name, AstNode** args, size_t count, int line, int col);
|
||||
AstNode* ast_make_literal_i64(void* alloc, int64_t val, int line, int col);
|
||||
AstNode* ast_make_literal_f64(void* alloc, double val, int line, int col);
|
||||
AstNode* ast_make_literal_bool(void* alloc, bool val, int line, int col);
|
||||
AstNode* ast_make_literal_str(void* alloc, const char* val, int line, int col);
|
||||
AstNode* ast_make_ident(void* alloc, const char* name, int line, int col);
|
||||
AstNode* ast_make_struct_decl(void* alloc, const char* name, AstNode** fields, size_t count, int line, int col);
|
||||
AstNode* ast_make_struct_init(void* alloc, const char* type_name, const char** fnames, AstNode** fvals, size_t count, int line, int col);
|
||||
AstNode* ast_make_field_access(void* alloc, AstNode* object, const char* field, int line, int col);
|
||||
bool is_mut, AstNode* init, const char* struct_type_name, SourceLoc loc);
|
||||
AstNode* ast_make_assign(void* alloc, const char* name, AstNode* value, SourceLoc loc);
|
||||
AstNode* ast_make_if(void* alloc, AstNode* cond, AstNode* then_b, AstNode* else_b, SourceLoc loc);
|
||||
AstNode* ast_make_while(void* alloc, AstNode* cond, AstNode* body, SourceLoc loc);
|
||||
AstNode* ast_make_return(void* alloc, AstNode* expr, SourceLoc loc);
|
||||
AstNode* ast_make_expr_stmt(void* alloc, AstNode* expr, SourceLoc loc);
|
||||
AstNode* ast_make_binary(void* alloc, BinaryOp op, AstNode* left, AstNode* right, SourceLoc loc);
|
||||
AstNode* ast_make_unary(void* alloc, BinaryOp op, AstNode* operand, SourceLoc loc);
|
||||
AstNode* ast_make_call(void* alloc, const char* name, AstNode** args, size_t count, SourceLoc loc);
|
||||
AstNode* ast_make_literal_i64(void* alloc, int64_t val, SourceLoc loc);
|
||||
AstNode* ast_make_literal_f64(void* alloc, double val, SourceLoc loc);
|
||||
AstNode* ast_make_literal_bool(void* alloc, bool val, SourceLoc loc);
|
||||
AstNode* ast_make_literal_str(void* alloc, const char* val, SourceLoc loc);
|
||||
AstNode* ast_make_ident(void* alloc, const char* name, SourceLoc loc);
|
||||
AstNode* ast_make_struct_decl(void* alloc, const char* name, AstNode** fields, size_t count, SourceLoc loc);
|
||||
AstNode* ast_make_struct_init(void* alloc, const char* type_name, const char** fnames, AstNode** fvals, size_t count, SourceLoc loc);
|
||||
AstNode* ast_make_field_access(void* alloc, AstNode* object, const char* field, SourceLoc loc);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user