diff --git a/lib/core/Handles/HandlesImports.py b/lib/core/Handles/HandlesImports.py index 74fd7bb..64678b4 100644 --- a/lib/core/Handles/HandlesImports.py +++ b/lib/core/Handles/HandlesImports.py @@ -1365,16 +1365,24 @@ class ImportHandle(BaseHandle): var_type = Gen._ctype_to_llvm(ElemTypeInfo) IsPtr = False else: - TypeInfo = CTypeInfo.FromNode(Node.annotation, self.Trans.SymbolTable) - if TypeInfo: - var_type = Gen._ctype_to_llvm(TypeInfo) - if isinstance(var_type, ir.VoidType): - raise TypeError( - f"[TPC] 全局变量 '{VarName}' 的类型注解 " - f"'{getattr(Node.annotation, 'id', type(Node.annotation).__name__)}' " - f"解析为 void(第 {getattr(Node, 'lineno', 0)} 行);" - f"请检查该类型是否已定义或声明顺序是否正确。") - IsPtr = TypeInfo.IsPtr + _AnnMarkers: tuple[str, ...] = (tuple(getattr(Node, 'Markers', None) or ()) + + tuple(getattr(Node.annotation, 'Markers', None) or ())) + if 'typedef' in _AnnMarkers or 'define' in _AnnMarkers: + # typedef / define 走下面的注册分支,不发射全局变量 + TypeInfo = None + var_type = ir.IntType(32) + IsPtr = False + else: + TypeInfo = CTypeInfo.FromNode(Node.annotation, self.Trans.SymbolTable) + if TypeInfo: + var_type = Gen._ctype_to_llvm(TypeInfo) + if isinstance(var_type, ir.VoidType): + raise TypeError( + f"[TPC] 全局变量 '{VarName}' 的类型注解 " + f"'{getattr(Node.annotation, 'id', type(Node.annotation).__name__)}' " + f"解析为 void(第 {getattr(Node, 'lineno', 0)} 行);" + f"请检查该类型是否已定义或声明顺序是否正确。") + IsPtr = TypeInfo.IsPtr if isinstance(var_type, ir.IdentifiedStructType) and (var_type.elements is None or len(var_type.elements) == 0): var_type = ir.IntType(32) if Node.value and ModulePath and IsPtr and isinstance(Node.value, ast.Constant) and isinstance(Node.value.value, str):