将 EnumName/value/IsSigned 加入 FIELD_ROUTES,消除所有冗余 hasattr/getattr

This commit is contained in:
2026-06-18 19:09:50 +08:00
parent f99666420b
commit d7b98cc9c5
33 changed files with 1722 additions and 1200 deletions

View File

@@ -173,28 +173,28 @@ class BaseGenMixin:
return ir.IntType(8)
if hasattr(self, 'SymbolTable') and self.SymbolTable and clean_name in self.SymbolTable:
Entry = self.SymbolTable[clean_name]
if hasattr(Entry, 'IsTypedef') and Entry.IsTypedef:
if Entry.IsTypedef:
resolved_str = self._resolve_typedef(clean_name)
if resolved_str != clean_name:
return self._type_str_to_llvm(resolved_str)
if hasattr(Entry, 'BaseType') and Entry.BaseType:
if Entry.BaseType:
from lib.includes import t as _t
if not isinstance(Entry.BaseType, (_t._CTypedef,)) or getattr(Entry, 'PtrCount', 0) > 0:
if not isinstance(Entry.BaseType, (_t._CTypedef,)) or Entry.PtrCount > 0:
resolved = self._resolve_ctype_to_str(Entry)
if resolved:
return self._type_str_to_llvm(resolved)
if hasattr(Entry, 'IsRenum') and Entry.IsRenum:
if Entry.IsRenum:
if clean_name in self.structs:
return self.structs[clean_name]
if hasattr(Entry, 'IsEnum') and Entry.IsEnum:
if Entry.IsEnum:
return ir.IntType(32)
if hasattr(Entry, 'IsExceptionClass') and Entry.IsExceptionClass:
if Entry.IsExceptionClass:
return ir.IntType(32)
if hasattr(Entry, 'IsFunction') and Entry.IsFunction:
if Entry.IsFunction:
return ir.PointerType(ir.IntType(8))
if hasattr(Entry, 'IsVariable') and Entry.IsVariable:
if Entry.IsVariable:
return ir.PointerType(ir.IntType(8))
if hasattr(Entry, 'BaseType'):
if Entry.BaseType:
from lib.includes import t as _t
if isinstance(Entry.BaseType, type) and issubclass(Entry.BaseType, _t.CEnum):
return ir.IntType(32)
@@ -237,17 +237,17 @@ class BaseGenMixin:
# 2. 再查 SymbolTable用户定义的 typedef
if hasattr(self, 'SymbolTable') and self.SymbolTable and name in self.SymbolTable:
Entry = self.SymbolTable[name]
if hasattr(Entry, 'IsTypedef') and Entry.IsTypedef:
if hasattr(Entry, 'BaseType') and Entry.BaseType:
if Entry.IsTypedef:
if Entry.BaseType:
from lib.includes import t as _t
if not isinstance(Entry.BaseType, (_t._CTypedef,)) and getattr(Entry, 'PtrCount', 0) == 0:
if not isinstance(Entry.BaseType, (_t._CTypedef,)) and Entry.PtrCount == 0:
llvm_str = CTypeRegistry.CTypeToLLVM(type(Entry.BaseType) if isinstance(Entry.BaseType, _t.CType) else Entry.BaseType)
if llvm_str and llvm_str.startswith('i') and llvm_str[1:].isdigit():
return int(llvm_str[1:])
if hasattr(Entry, 'OriginalType') and Entry.OriginalType:
if Entry.OriginalType:
from lib.core.Handles.HandlesBase import CTypeInfo as _CTypeInfo
if isinstance(Entry.OriginalType, _CTypeInfo) and Entry.OriginalType.BaseType:
if not isinstance(Entry.OriginalType.BaseType, (_t._CTypedef,)) and getattr(Entry.OriginalType, 'PtrCount', 0) == 0:
if not isinstance(Entry.OriginalType.BaseType, (_t._CTypedef,)) and Entry.OriginalType.PtrCount == 0:
llvm_str = CTypeRegistry.CTypeToLLVM(type(Entry.OriginalType.BaseType) if isinstance(Entry.OriginalType.BaseType, _t.CType) else Entry.OriginalType.BaseType)
if llvm_str and llvm_str.startswith('i') and llvm_str[1:].isdigit():
return int(llvm_str[1:])

View File

@@ -207,13 +207,13 @@ class StructGenMixin:
is_packed = ClassName in self.class_packed
if hasattr(self, 'SymbolTable') and self.SymbolTable and ClassName in self.SymbolTable:
Entry = self.SymbolTable[ClassName]
if hasattr(Entry, 'IsExceptionClass') and Entry.IsExceptionClass:
if Entry.IsExceptionClass:
continue
if hasattr(Entry, 'IsEnum') and Entry.IsEnum:
if not getattr(Entry, 'IsRenum', False):
if Entry.IsEnum:
if not Entry.IsRenum:
continue
if hasattr(Entry, 'IsTypedef') and Entry.IsTypedef:
if hasattr(Entry, 'BaseType') and Entry.BaseType and not isinstance(Entry.BaseType, (type(None),)):
if Entry.IsTypedef:
if Entry.BaseType and not isinstance(Entry.BaseType, (type(None),)):
import lib.includes.t as _t
if not isinstance(Entry.BaseType, (_t._CTypedef,)):
continue
@@ -304,10 +304,10 @@ class StructGenMixin:
for ClassName in all_classes:
if hasattr(self, 'SymbolTable') and self.SymbolTable and ClassName in self.SymbolTable:
Entry = self.SymbolTable[ClassName]
if hasattr(Entry, 'IsExceptionClass') and Entry.IsExceptionClass:
if Entry.IsExceptionClass:
continue
if hasattr(Entry, 'IsEnum') and Entry.IsEnum:
if not getattr(Entry, 'IsRenum', False):
if Entry.IsEnum:
if not Entry.IsRenum:
continue
existing_st = self.structs.get(ClassName)
if isinstance(existing_st, ir.IdentifiedStructType) and existing_st.elements is not None and len(existing_st.elements) > 0:

View File

@@ -137,7 +137,7 @@ class TypeConvertMixin:
if isinstance(BaseType, _t.CDefine):
# Use 64-bit type if the define value exceeds 32-bit range
if type_info and hasattr(type_info, 'DefineValue') and isinstance(type_info.DefineValue, int):
if type_info and isinstance(type_info.DefineValue, int):
if type_info.DefineValue < 0 or type_info.DefineValue > 0xFFFFFFFF:
return ir.IntType(64)
return ir.IntType(32)
@@ -180,8 +180,8 @@ class TypeConvertMixin:
if OriginalType:
current = OriginalType
continue
elif hasattr(Entry, 'IsTypedef') and Entry.IsTypedef:
if hasattr(Entry, 'OriginalType') and Entry.OriginalType:
elif Entry.IsTypedef:
if Entry.OriginalType:
if isinstance(Entry.OriginalType, _CTypeInfo):
if Entry.OriginalType.IsFuncPtr:
return 'Callable'
@@ -189,9 +189,9 @@ class TypeConvertMixin:
elif isinstance(Entry.OriginalType, str):
current = Entry.OriginalType
continue
if hasattr(Entry, 'BaseType') and Entry.BaseType:
if Entry.BaseType:
from lib.includes import t as _t
if not isinstance(Entry.BaseType, (_t._CTypedef,)) or getattr(Entry, 'PtrCount', 0) > 0:
if not isinstance(Entry.BaseType, (_t._CTypedef,)) or Entry.PtrCount > 0:
resolved = self._resolve_ctype_to_str(Entry)
if resolved and resolved != current:
current = resolved
@@ -396,24 +396,24 @@ class TypeConvertMixin:
return basic_stripped
if hasattr(self, 'SymbolTable') and self.SymbolTable and type_str in self.SymbolTable:
_Entry = self.SymbolTable[type_str]
if hasattr(_Entry, 'IsTypedef') and _Entry.IsTypedef:
if _Entry.IsTypedef:
resolved_str = self._resolve_typedef(type_str)
if resolved_str != type_str:
return self._type_str_to_llvm(resolved_str, IsPtr)
if hasattr(_Entry, 'BaseType') and _Entry.BaseType:
if _Entry.BaseType:
from lib.includes import t as _t
if not isinstance(_Entry.BaseType, (_t._CTypedef,)) or getattr(_Entry, 'PtrCount', 0) > 0:
if not isinstance(_Entry.BaseType, (_t._CTypedef,)) or _Entry.PtrCount > 0:
resolved = self._resolve_ctype_to_str(_Entry)
if resolved:
return self._type_str_to_llvm(resolved, IsPtr)
if hasattr(_Entry, 'IsRenum') and _Entry.IsRenum:
if _Entry.IsRenum:
if type_str in self.structs:
return self.structs[type_str]
if hasattr(_Entry, 'IsEnum') and _Entry.IsEnum:
if _Entry.IsEnum:
return ir.IntType(32) if not IsPtr else ir.PointerType(ir.IntType(32))
if hasattr(_Entry, 'IsExceptionClass') and _Entry.IsExceptionClass:
if _Entry.IsExceptionClass:
return ir.IntType(32) if not IsPtr else ir.PointerType(ir.IntType(32))
if hasattr(_Entry, 'BaseType'):
if _Entry.BaseType:
from lib.includes import t as _t
if (isinstance(_Entry.BaseType, type) and issubclass(_Entry.BaseType, _t.CEnum)) or _Entry.BaseType is _t.CEnum:
return ir.IntType(32) if not IsPtr else ir.PointerType(ir.IntType(32))
@@ -431,24 +431,24 @@ class TypeConvertMixin:
return basic_last
if hasattr(self, 'SymbolTable') and self.SymbolTable and LastPart in self.SymbolTable:
_Entry = self.SymbolTable[LastPart]
if hasattr(_Entry, 'IsTypedef') and _Entry.IsTypedef:
if _Entry.IsTypedef:
resolved_str = self._resolve_typedef(LastPart)
if resolved_str != LastPart:
return self._type_str_to_llvm(resolved_str, IsPtr)
if hasattr(_Entry, 'BaseType') and _Entry.BaseType:
if _Entry.BaseType:
from lib.includes import t as _t
if not isinstance(_Entry.BaseType, (_t._CTypedef,)) or getattr(_Entry, 'PtrCount', 0) > 0:
if not isinstance(_Entry.BaseType, (_t._CTypedef,)) or _Entry.PtrCount > 0:
resolved = self._resolve_ctype_to_str(_Entry)
if resolved:
return self._type_str_to_llvm(resolved, IsPtr)
if hasattr(_Entry, 'IsRenum') and _Entry.IsRenum:
if _Entry.IsRenum:
if LastPart in self.structs:
return self.structs[LastPart]
if hasattr(_Entry, 'IsEnum') and _Entry.IsEnum:
if _Entry.IsEnum:
return ir.IntType(32) if not IsPtr else ir.PointerType(ir.IntType(32))
if hasattr(_Entry, 'IsExceptionClass') and _Entry.IsExceptionClass:
if _Entry.IsExceptionClass:
return ir.IntType(32) if not IsPtr else ir.PointerType(ir.IntType(32))
if hasattr(_Entry, 'BaseType'):
if _Entry.BaseType:
from lib.includes import t as _t
if (isinstance(_Entry.BaseType, type) and issubclass(_Entry.BaseType, _t.CEnum)) or _Entry.BaseType is _t.CEnum:
return ir.IntType(32) if not IsPtr else ir.PointerType(ir.IntType(32))