fix: vpi 注入错误上下文帧携带触发 import 的真实行号与行内容
This commit is contained in:
1 parent
6dbcbe247e
commit
95a52bb9f6
2 files changed
+8
-5
No files matched your search
@@ -330,6 +330,8 @@ class Translator:
|
|||||||
if self._declare_only == 0:
|
if self._declare_only == 0:
|
||||||
# 预处理导入语句,确保 _imported_modules 和 _from_imports 已填充
|
# 预处理导入语句,确保 _imported_modules 和 _from_imports 已填充
|
||||||
# (前向声明需要解析类型注解,如 t.CArray[str] 依赖 t 模块已导入)
|
# (前向声明需要解析类型注解,如 t.CArray[str] 依赖 t 模块已导入)
|
||||||
|
# 记录最后处理的 import 行号,供 vpi 注入错误上下文帧定位
|
||||||
|
cur_imp_lineno: int = 0
|
||||||
ch: list[ast.AST | t.CPtr] | t.CPtr = tree.children
|
ch: list[ast.AST | t.CPtr] | t.CPtr = tree.children
|
||||||
if ch is not None:
|
if ch is not None:
|
||||||
cn_count: t.CSizeT = ch.__len__()
|
cn_count: t.CSizeT = ch.__len__()
|
||||||
@@ -339,8 +341,10 @@ class Translator:
|
|||||||
continue
|
continue
|
||||||
kd: int = child.kind()
|
kd: int = child.kind()
|
||||||
if kd == ast.ASTKind.Import:
|
if kd == ast.ASTKind.Import:
|
||||||
|
cur_imp_lineno = child.lineno
|
||||||
self.ImportsH.HandleImport(child)
|
self.ImportsH.HandleImport(child)
|
||||||
elif kd == ast.ASTKind.ImportFrom:
|
elif kd == ast.ASTKind.ImportFrom:
|
||||||
|
cur_imp_lineno = child.lineno
|
||||||
self.ImportsH.HandleImportFromModule(child)
|
self.ImportsH.HandleImportFromModule(child)
|
||||||
self.ImportsH.HandleImportFromNames(child)
|
self.ImportsH.HandleImportFromNames(child)
|
||||||
# 扫描当前模块的 CTypedef 声明(NAME: t.CTypedef = Type),
|
# 扫描当前模块的 CTypedef 声明(NAME: t.CTypedef = Type),
|
||||||
@@ -351,9 +355,12 @@ class Translator:
|
|||||||
# 严格保证 declare_only == 0 时才注入(避免 Phase A-pre-inc 死锁)
|
# 严格保证 declare_only == 0 时才注入(避免 Phase A-pre-inc 死锁)
|
||||||
if self._imported_modules is not None:
|
if self._imported_modules is not None:
|
||||||
import lib.core.StubMerger as StubMerger
|
import lib.core.StubMerger as StubMerger
|
||||||
|
# 错误上下文帧:当前模块触发依赖 stub 加载的 import 位置
|
||||||
|
HandlesType.push_trace(HandlesType.get_current_file(), cur_imp_lineno)
|
||||||
StubMerger.LoadDepVpiIntoModule(
|
StubMerger.LoadDepVpiIntoModule(
|
||||||
pool, mod, self._imported_modules, self._from_imports,
|
pool, mod, self._imported_modules, self._from_imports,
|
||||||
HandlesExprCall._g_temp_dir, self)
|
HandlesExprCall._g_temp_dir, self)
|
||||||
|
HandlesType.pop_trace()
|
||||||
# 预注册模块级变量(AnnAssign/Assign)到 SymTab
|
# 预注册模块级变量(AnnAssign/Assign)到 SymTab
|
||||||
# 解决时序问题:class Logger 的 __init__ 引用 _mbuddy 时,
|
# 解决时序问题:class Logger 的 __init__ 引用 _mbuddy 时,
|
||||||
# _mbuddy 的 AnnAssign 在 AST 中位于 class Logger 之后,
|
# _mbuddy 的 AnnAssign 在 AST 中位于 class Logger 之后,
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import lib.core.IncludesScanner as IncludesScanner
|
|||||||
import lib.core.Handles.HandlesStruct as HandlesStruct
|
import lib.core.Handles.HandlesStruct as HandlesStruct
|
||||||
import lib.core.Handles.HandlesImports as HandlesImports
|
import lib.core.Handles.HandlesImports as HandlesImports
|
||||||
import lib.core.Handles.HandlesTranslator as HandlesTranslator
|
import lib.core.Handles.HandlesTranslator as HandlesTranslator
|
||||||
import lib.core.Handles.HandlesType as HandlesType
|
|
||||||
import lib.core.BuildPipeline as BuildPipeline
|
import lib.core.BuildPipeline as BuildPipeline
|
||||||
import lib.StubGen.VpiReader as VpiReader
|
import lib.StubGen.VpiReader as VpiReader
|
||||||
import lib.Projectrans.Utils as Utils
|
import lib.Projectrans.Utils as Utils
|
||||||
@@ -2085,11 +2084,8 @@ def LoadDepVpiIntoModule(pool: memhub.MemBuddy | t.CPtr,
|
|||||||
if not vf.closed:
|
if not vf.closed:
|
||||||
vf.close()
|
vf.close()
|
||||||
# 调用 VpiReader 解析 .vpi 并注入 declare
|
# 调用 VpiReader 解析 .vpi 并注入 declare
|
||||||
# 错误归因:push 当前编译模块帧,stub 解析期间若 fatal_error,
|
# (错误上下文帧由调用方 HandlesTranslator 维护)
|
||||||
# 多级堆栈显示 当前模块 → 被读 stub 文件(真实出错位置)
|
|
||||||
HandlesType.push_trace(HandlesType.get_current_file(), 0)
|
|
||||||
ret: int = VpiReader.ParseVpiIntoModule(pool, mod, vpi_path, trans)
|
ret: int = VpiReader.ParseVpiIntoModule(pool, mod, vpi_path, trans)
|
||||||
HandlesType.pop_trace()
|
|
||||||
if ret == 1:
|
if ret == 1:
|
||||||
success_count += 1
|
success_count += 1
|
||||||
stdlib.free(vpi_path)
|
stdlib.free(vpi_path)
|
||||||
|
|||||||
Reference in new issue
Block a user