fix: P1审查修复 — error.c arena化 + Self类型解析 + trait查找加固 + 缓冲区安全
P1-①: error_init/add 从 malloc/realloc/strdup 改为 arena_alloc/arena_strdup P1-②: impl 方法中 Self 类型在 sema 解析为实际结构体名 P1-③: trait 方法 fallback 增加前缀校验(strncmp),method_name 统一更新 P1-④: codegen args[16] 增加溢出检查,移除 parser 未使用的 mods/uses 数组 新增: 36_self_type.l 集成测试(Self 类型 + trait 方法) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+4
-14
@@ -1031,8 +1031,6 @@ AstNode* parse(Arena* a, const Token* tokens, size_t count,
|
||||
AstNode* aliases[64]; int alias_count = 0;
|
||||
AstNode* enums[64]; int enum_count = 0;
|
||||
AstNode* impls[64]; int impl_count = 0;
|
||||
AstNode* mods[64]; int mod_count = 0;
|
||||
AstNode* uses[64]; int use_count = 0;
|
||||
while (peek(&p)->kind != TOK_EOF && !error->message) {
|
||||
// pub 前缀
|
||||
bool is_pub = false;
|
||||
@@ -1179,20 +1177,12 @@ AstNode* parse(Arena* a, const Token* tokens, size_t count,
|
||||
if (enum_count >= 64) break;
|
||||
enums[enum_count++] = sub->as.program.enums[i];
|
||||
}
|
||||
if (mod_count < 64) mods[mod_count++] = ast_make_mod_decl(a, mod_name, sub, tok_loc(mn));
|
||||
/* mod 内容已内联合并到当前文件 */ ;
|
||||
} else if (peek(&p)->kind == TOK_USE) {
|
||||
/* TODO: use 语句待实现符号导入 */ ;
|
||||
advance(&p);
|
||||
const Token* path_tok = expect(&p, TOK_IDENT, error, "use 后应为模块名");
|
||||
if (!path_tok) return NULL;
|
||||
if (!expect(&p, TOK_COLON_COLON, error, "缺少 '::'")) return NULL;
|
||||
const Token* item_tok = expect(&p, TOK_IDENT, error, "use 后应为项目名");
|
||||
if (!item_tok) return NULL;
|
||||
if (!expect(&p, TOK_SEMICOLON, error, "缺少 ';'")) return NULL;
|
||||
if (use_count >= 64) { error->message = "use 过多 (最多64)"; error->filename = p.filename; error->line = peek(&p)->line; error->col = peek(&p)->col; return NULL; }
|
||||
uses[use_count++] = ast_make_use_decl(a,
|
||||
arena_strdup_impl(p.arena, path_tok->start, path_tok->length),
|
||||
arena_strdup_impl(p.arena, item_tok->start, item_tok->length),
|
||||
tok_loc(path_tok));
|
||||
while (peek(&p)->kind != TOK_SEMICOLON && peek(&p)->kind != TOK_EOF) advance(&p);
|
||||
if (peek(&p)->kind == TOK_SEMICOLON) advance(&p);
|
||||
} else if (peek(&p)->kind == TOK_FN) {
|
||||
if (fn_count >= 256) { error->message = "函数过多 (最多256)"; error->filename = p.filename; error->line = peek(&p)->line; error->col = peek(&p)->col; return NULL; }
|
||||
functions[fn_count++] = parse_function(&p, is_pub, error);
|
||||
|
||||
Reference in New Issue
Block a user