Some simple information syncing
This commit is contained in:
@@ -112,20 +112,26 @@ class ImportHandle(BaseHandle):
|
||||
# For 'from X import Y' (no asname), register CDefine constants
|
||||
# into _define_constants so they can be found by _HandleNameLlvm
|
||||
if not asname or asname == name:
|
||||
define_constants = vars(Gen).setdefault('_define_constants', {})
|
||||
# Check if this name is a CDefine constant in SymbolTable
|
||||
sym_info = self.Trans.SymbolTable.lookup(name)
|
||||
if sym_info and sym_info.IsDefine and sym_info.DefineValue is not None:
|
||||
define_constants = vars(Gen).setdefault('_define_constants', {})
|
||||
if name not in define_constants:
|
||||
define_constants[name] = sym_info.DefineValue
|
||||
# Also check with module prefix
|
||||
for prefix_key in [f"{module}.{name}", name]:
|
||||
sym_info2 = self.Trans.SymbolTable.lookup(prefix_key)
|
||||
if sym_info2 and sym_info2.IsDefine and sym_info2.DefineValue is not None:
|
||||
define_constants = vars(Gen).setdefault('_define_constants', {})
|
||||
if name not in define_constants:
|
||||
define_constants[name] = sym_info2.DefineValue
|
||||
break
|
||||
# 治本修复:如果符号表中没有,回退查询 _all_define_constants
|
||||
# _all_define_constants 由 Phase2Translator 从所有 .pyi 文件预提取,
|
||||
# 包含跨模块导入的 CDefine 常量(如 FOREGROUND_GREEN、STD_OUTPUT_HANDLE)
|
||||
if name not in define_constants:
|
||||
all_dc: dict = getattr(Gen, '_all_define_constants', None) or getattr(self.Trans, '_all_define_constants', None) or {}
|
||||
if name in all_dc:
|
||||
define_constants[name] = all_dc[name]
|
||||
continue
|
||||
if not hasattr(self.Trans, '_t_c_imported_names'):
|
||||
self.Trans._t_c_imported_names = {}
|
||||
|
||||
Reference in New Issue
Block a user