diff --git a/App/lib/core/Diag.vp b/App/lib/core/Diag.vp index fe76b2b..9e0e307 100644 --- a/App/lib/core/Diag.vp +++ b/App/lib/core/Diag.vp @@ -39,7 +39,12 @@ define DIAG_MAX_FRAMES = 32 # 调用链上限(与 TypeGenMixin.TRACE_MAX 对 # 用于"从错误发生点向外展示触发过程"。 # 所有字符串都用 stdlib 深拷贝:编译期池会回绕,不能借用池内指针。 class DiagEntry: - File: str # 当前帧(错误点)文件 + # 字段名不要与"本模块 import 的类名"重名:TPC 的类型/符号表按**非限定名**索引 + # (Gen.structs / SymbolTable / _mangle_func_name),曾把本字段的 `File` 与 + # `w32.fileio.File` 撞在一起,导致同模块 `fileio.File(...)` 的构造调用把 + # `File.__before_init__` 的 self 形参解析成 `i8**`(llvmlite: "Type of #1 arg + # mismatch: i8** != %"...fileio.File"*")。故此处用 FileName 而非 File。 + FileName: str # 当前帧(错误点)文件 Line: int # 当前帧行号 ColStart: int # caret 起始列(1-based;0 = 不画) ColEnd: int # caret 结束列 @@ -68,7 +73,7 @@ def new_entry(max_frames: int) -> DiagEntry*: ent: DiagEntry* = (DiagEntry*)(stdlib.malloc(DiagEntry.__sizeof__())) if ent is None: return None if max_frames <= 0: max_frames = 1 - ent.File = None + ent.FileName = None ent.Line = 0 ent.ColStart = 0 ent.ColEnd = 0 @@ -88,7 +93,7 @@ def begin(ent: DiagEntry*, category: str, msg: str, hint: str = None) -> int: ent.Category = dup_str(category) ent.Msg = dup_str(msg) ent.Hint = dup_str(hint) - ent.File = None + ent.FileName = None ent.Line = 0 ent.ColStart = 0 ent.ColEnd = 0 @@ -99,7 +104,7 @@ def begin(ent: DiagEntry*, category: str, msg: str, hint: str = None) -> int: # set_current - 设置当前帧(错误点)位置 def set_current(ent: DiagEntry*, file_name: str, lineno: int, col_start: int, col_end: int) -> int: if ent is None: return 0 - ent.File = dup_str(file_name) + ent.FileName = dup_str(file_name) ent.Line = lineno ent.ColStart = col_start ent.ColEnd = col_end @@ -131,7 +136,7 @@ def emit(ent: DiagEntry*, direction: int) -> int: while i_u < ent.FrameCount: emit_frame(str(ent.FrameFiles[i_u]), int(ent.FrameLines[i_u])) i_u += 1 - emit_current(ent.File, ent.Line, ent.ColStart, ent.ColEnd) + emit_current(ent.FileName, ent.Line, ent.ColStart, ent.ColEnd) emit_category(ent.Category, ent.Msg) return 0 @@ -139,7 +144,7 @@ def emit(ent: DiagEntry*, direction: int) -> int: # free_entry - 释放一条诊断(含深拷贝的字符串) def free_entry(ent: DiagEntry*) -> int: if ent is None: return 0 - if ent.File is not None: stdlib.free(ent.File) + if ent.FileName is not None: stdlib.free(ent.FileName) if ent.Category is not None: stdlib.free(ent.Category) if ent.Msg is not None: stdlib.free(ent.Msg) if ent.Hint is not None: stdlib.free(ent.Hint)