将 EnumName/value/IsSigned 加入 FIELD_ROUTES,消除所有冗余 hasattr/getattr
This commit is contained in:
@@ -328,9 +328,9 @@ class AnnotationLoaderMixin:
|
||||
orig_type_str = orig_entry.get('OriginalType', f'struct {original_name}')
|
||||
elif orig_entry.get('type') == 'enum':
|
||||
orig_type_str = f'enum {original_name}'
|
||||
elif hasattr(orig_entry, 'IsTypedef') and orig_entry.IsTypedef:
|
||||
orig_type_str = getattr(orig_entry, 'OriginalType', f'struct {original_name}')
|
||||
elif hasattr(orig_entry, 'IsEnum') and orig_entry.IsEnum:
|
||||
elif orig_entry.IsTypedef:
|
||||
orig_type_str = orig_entry.OriginalType or f'struct {original_name}'
|
||||
elif orig_entry.IsEnum:
|
||||
orig_type_str = f'enum {original_name}'
|
||||
TypedefNode.OriginalType = orig_type_str
|
||||
TypedefNode.set('source', 'annotation_module')
|
||||
|
||||
@@ -112,42 +112,8 @@ class ConstEvalMixin:
|
||||
return self._try_eval_const_expr(node, Gen)
|
||||
|
||||
def _try_eval_const_expr(self, node, Gen):
|
||||
import ast
|
||||
if isinstance(node, ast.Constant):
|
||||
return node.value
|
||||
elif isinstance(node, ast.BinOp):
|
||||
left = self._try_eval_const_expr(node.left, Gen)
|
||||
right = self._try_eval_const_expr(node.right, Gen)
|
||||
if left is None or right is None:
|
||||
return None
|
||||
if isinstance(node.op, ast.Add):
|
||||
return left + right
|
||||
elif isinstance(node.op, ast.Sub):
|
||||
return left - right
|
||||
elif isinstance(node.op, ast.Mult):
|
||||
return left * right
|
||||
elif isinstance(node.op, ast.LShift):
|
||||
return left << right
|
||||
elif isinstance(node.op, ast.RShift):
|
||||
return left >> right
|
||||
elif isinstance(node.op, ast.BitOr):
|
||||
return left | right
|
||||
elif isinstance(node.op, ast.BitAnd):
|
||||
return left & right
|
||||
elif isinstance(node.op, ast.BitXor):
|
||||
return left ^ right
|
||||
elif isinstance(node, ast.UnaryOp):
|
||||
operand = self._try_eval_const_expr(node.operand, Gen)
|
||||
if operand is None:
|
||||
return None
|
||||
if isinstance(node.op, ast.USub):
|
||||
return -operand
|
||||
elif isinstance(node.op, ast.Invert):
|
||||
return ~operand
|
||||
elif isinstance(node, ast.Name):
|
||||
if node.id in getattr(Gen, '_DefineConstants', {}):
|
||||
return Gen._DefineConstants[node.id]
|
||||
return None
|
||||
from lib.core.ConstEvaluator import ConstEvaluator
|
||||
return ConstEvaluator.eval_with_symtab(node, self.SymbolTable)
|
||||
|
||||
def _BuildMultiDimArrayInitConstants(self, value_node, ArrayType, Gen):
|
||||
from lib.core.Handles.HandlesAssign import AssignHandle
|
||||
|
||||
Reference in New Issue
Block a user