可用的回归测试通过的标准版本
This commit is contained in:
@@ -23,13 +23,16 @@ class FunctionHandle(BaseHandle):
|
||||
elif d.id == 'classmethod':
|
||||
meta |= FuncMeta.CLASS_METHOD
|
||||
elif isinstance(d, ast.Attribute):
|
||||
if isinstance(d.value, ast.Name) and d.value.id == 'property':
|
||||
if d.attr == 'setter':
|
||||
meta |= FuncMeta.PROPERTY_SETTER
|
||||
elif d.attr == 'getter':
|
||||
meta |= FuncMeta.PROPERTY_GETTER
|
||||
elif d.attr == 'deleter':
|
||||
meta |= FuncMeta.PROPERTY_DELETER
|
||||
if isinstance(d.value, ast.Name):
|
||||
# 支持 @property.setter 和 @propname.setter 两种形式
|
||||
# @propname.setter 中 propname 是之前用 @property 定义的同名属性
|
||||
if d.value.id == 'property' or d.attr in ('setter', 'getter', 'deleter'):
|
||||
if d.attr == 'setter':
|
||||
meta |= FuncMeta.PROPERTY_SETTER
|
||||
elif d.attr == 'getter':
|
||||
meta |= FuncMeta.PROPERTY_GETTER
|
||||
elif d.attr == 'deleter':
|
||||
meta |= FuncMeta.PROPERTY_DELETER
|
||||
return meta
|
||||
|
||||
def _body_contains_raise(self, body):
|
||||
@@ -189,8 +192,8 @@ class FunctionHandle(BaseHandle):
|
||||
if sym and isinstance(sym, dict):
|
||||
ret_type_str = sym.get('return_type', '')
|
||||
if ret_type_str and ret_type_str != 'int':
|
||||
is_ptr = sym.get('is_ptr', False)
|
||||
return (ret_type_str, is_ptr)
|
||||
IsPtr = sym.get('IsPtr', False)
|
||||
return (ret_type_str, IsPtr)
|
||||
elif isinstance(val, ast.Constant):
|
||||
if val.value is None:
|
||||
return ('char', True)
|
||||
@@ -204,8 +207,8 @@ class FunctionHandle(BaseHandle):
|
||||
if var_info and isinstance(var_info, dict):
|
||||
var_type = var_info.get('type', '')
|
||||
if var_type and var_type != 'int':
|
||||
is_ptr = var_info.get('is_ptr', False)
|
||||
return (var_type, is_ptr)
|
||||
IsPtr = var_info.get('IsPtr', False)
|
||||
return (var_type, IsPtr)
|
||||
elif isinstance(val, ast.Subscript):
|
||||
if (isinstance(val.value, ast.Attribute)
|
||||
and isinstance(val.value.value, ast.Name)
|
||||
@@ -264,8 +267,8 @@ class FunctionHandle(BaseHandle):
|
||||
parts = inner.split(',')
|
||||
elem_type_str = parts[0].strip()
|
||||
if elem_type_str and elem_type_str != 'int':
|
||||
is_ptr = var_info.get('is_ptr', False)
|
||||
return (elem_type_str, is_ptr)
|
||||
IsPtr = var_info.get('IsPtr', False)
|
||||
return (elem_type_str, IsPtr)
|
||||
return None
|
||||
|
||||
def _GetFunctionSignatureLlvm(self, Node, Gen, ClassName=None, extra_params=None):
|
||||
@@ -368,7 +371,7 @@ class FunctionHandle(BaseHandle):
|
||||
ReturnTypeInfo = CTypeInfo()
|
||||
ReturnTypeInfo.BaseType = t.CChar()
|
||||
ReturnTypeInfo.PtrCount = 1
|
||||
if ReturnTypeInfo.IsVoid and not ReturnTypeInfo.IsState:
|
||||
if ReturnTypeInfo.IsVoid and ReturnTypeInfo.PtrCount == 0 and not ReturnTypeInfo.IsState:
|
||||
ReturnTypeInfo = CTypeInfo()
|
||||
ReturnTypeInfo.BaseType = t.CInt()
|
||||
except Exception: # 回退:设置默认返回类型为 CInt
|
||||
@@ -762,8 +765,12 @@ class FunctionHandle(BaseHandle):
|
||||
for attr_name in self._pending_llvm_attrs[FuncName]:
|
||||
try:
|
||||
func.attributes.add(attr_name)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as _e:
|
||||
from lib.core.VLogger import get_logger as _vlog
|
||||
from lib.constants.config import mode as _config_mode
|
||||
if _config_mode == "strict":
|
||||
raise
|
||||
_vlog().warning(f"添加函数属性失败: {_e}", "Exception")
|
||||
Gen.functions[MangledName] = func
|
||||
Gen.functions[FuncName] = func
|
||||
except Exception as _e:
|
||||
@@ -820,6 +827,12 @@ class FunctionHandle(BaseHandle):
|
||||
FuncName = f"{ClassName}.{RawFuncName}"
|
||||
else:
|
||||
FuncName = RawFuncName
|
||||
# property setter/deleter 使用不同的函数名后缀,避免与 getter 冲突
|
||||
func_meta = self._ExtractFuncMeta(Node.decorator_list)
|
||||
if FuncMeta.PROPERTY_SETTER in func_meta:
|
||||
FuncName = FuncName + '$set'
|
||||
elif FuncMeta.PROPERTY_DELETER in func_meta:
|
||||
FuncName = FuncName + '$del'
|
||||
CReturnTypes = []
|
||||
IsPtr = False
|
||||
fn_attrs = {}
|
||||
@@ -971,7 +984,7 @@ class FunctionHandle(BaseHandle):
|
||||
ReturnTypeInfo = CTypeInfo()
|
||||
ReturnTypeInfo.BaseType = t.CChar()
|
||||
ReturnTypeInfo.PtrCount = 1
|
||||
if ReturnTypeInfo.IsVoid and not ReturnTypeInfo.IsState:
|
||||
if ReturnTypeInfo.IsVoid and ReturnTypeInfo.PtrCount == 0 and not ReturnTypeInfo.IsState:
|
||||
ReturnTypeInfo = CTypeInfo()
|
||||
ReturnTypeInfo.BaseType = t.CInt()
|
||||
except Exception: # 回退:设置默认返回类型为 CInt
|
||||
@@ -992,7 +1005,7 @@ class FunctionHandle(BaseHandle):
|
||||
IsMethod = False
|
||||
IsClassMethod = False
|
||||
ResolvedClassName = ClassName
|
||||
func_meta = self._ExtractFuncMeta(Node.decorator_list)
|
||||
# func_meta 已在函数开头提取(用于 setter/deleter 函数名后缀)
|
||||
if not ResolvedClassName:
|
||||
for potential_class in Gen.class_methods:
|
||||
if FuncName.startswith(f"{potential_class}."):
|
||||
@@ -1196,21 +1209,33 @@ class FunctionHandle(BaseHandle):
|
||||
if fn_attrs.get(attr_name):
|
||||
try:
|
||||
func.attributes.add(llvm_name)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as _e:
|
||||
from lib.core.VLogger import get_logger as _vlog
|
||||
from lib.constants.config import mode as _config_mode
|
||||
if _config_mode == "strict":
|
||||
raise
|
||||
_vlog().warning(f"添加函数属性失败: {_e}", "Exception")
|
||||
for key in fn_attrs:
|
||||
if key.startswith('llvm.'):
|
||||
llvm_attr_name = key[5:]
|
||||
try:
|
||||
func.attributes.add(llvm_attr_name)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as _e:
|
||||
from lib.core.VLogger import get_logger as _vlog
|
||||
from lib.constants.config import mode as _config_mode
|
||||
if _config_mode == "strict":
|
||||
raise
|
||||
_vlog().warning(f"添加函数属性失败: {_e}", "Exception")
|
||||
if hasattr(self, '_pending_llvm_attrs') and FuncName in self._pending_llvm_attrs:
|
||||
for attr_name in self._pending_llvm_attrs.pop(FuncName):
|
||||
try:
|
||||
func.attributes.add(attr_name)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as _e:
|
||||
from lib.core.VLogger import get_logger as _vlog
|
||||
from lib.constants.config import mode as _config_mode
|
||||
if _config_mode == "strict":
|
||||
raise
|
||||
_vlog().warning(f"添加函数属性失败: {_e}", "Exception")
|
||||
# 记录自定义行为装饰器信息,供 DecoratorPass 使用
|
||||
if behavior_decorators:
|
||||
if not hasattr(Gen, '_decorated_funcs'):
|
||||
@@ -1272,7 +1297,7 @@ class FunctionHandle(BaseHandle):
|
||||
break
|
||||
else:
|
||||
# 所有参数都存入 alloca,确保循环体中对参数的修改能正确反映
|
||||
var = Gen._alloca_entry(param.type, name=param_name)
|
||||
var = Gen._allocaEntry(param.type, name=param_name)
|
||||
Gen._store(param, var)
|
||||
Gen.variables[param_name] = var
|
||||
if ResolvedClassName and (IsMethod or RawFuncName == '__init__'):
|
||||
@@ -1298,7 +1323,7 @@ class FunctionHandle(BaseHandle):
|
||||
va_list_size = 8 if is_windows else 24
|
||||
va_list_align = 8 if is_windows else 16
|
||||
va_list_type = ir.ArrayType(ir.IntType(8), va_list_size)
|
||||
va_list_alloc = Gen._alloca_entry(va_list_type, name=f"{vararg_name}_va_list", align=va_list_align)
|
||||
va_list_alloc = Gen._allocaEntry(va_list_type, name=f"{vararg_name}_va_list", align=va_list_align)
|
||||
va_list_ptr = Gen.builder.bitcast(va_list_alloc, ir.IntType(8).as_pointer(), name=f"{vararg_name}_va_list_i8ptr")
|
||||
Gen._variadic_info = {
|
||||
'vararg_name': vararg_name,
|
||||
@@ -1307,7 +1332,7 @@ class FunctionHandle(BaseHandle):
|
||||
'va_start_called': False,
|
||||
}
|
||||
if last_param_ptr:
|
||||
last_param_alloc = Gen._alloca_entry(last_param_ptr.type, name="last_param_copy")
|
||||
last_param_alloc = Gen._allocaEntry(last_param_ptr.type, name="last_param_copy")
|
||||
Gen.builder.store(last_param_ptr, last_param_alloc)
|
||||
Gen.emit_va_start(va_list_ptr)
|
||||
Gen._variadic_info['va_start_called'] = True
|
||||
@@ -1379,4 +1404,17 @@ class FunctionHandle(BaseHandle):
|
||||
existing.IsInline = True
|
||||
existing.InlineBody = Node.body
|
||||
existing.InlineParams = [arg.arg for arg in Node.args.args]
|
||||
# property setter/deleter: 在原始 PropKey(不带后缀)下注册 MetaList
|
||||
if FuncMeta.PROPERTY_SETTER in func_meta or FuncMeta.PROPERTY_DELETER in func_meta:
|
||||
BasePropKey = f"{ClassName}.{RawFuncName}" if ClassName else RawFuncName
|
||||
if BasePropKey in self.Trans.SymbolTable:
|
||||
base_existing = self.Trans.SymbolTable[BasePropKey]
|
||||
if func_meta != FuncMeta.NONE:
|
||||
base_existing.MetaList = base_existing.MetaList | func_meta
|
||||
else:
|
||||
PropInfo = CTypeInfo()
|
||||
PropInfo.Name = BasePropKey
|
||||
PropInfo.IsFunction = True
|
||||
PropInfo.MetaList = func_meta
|
||||
self.Trans.SymbolTable[BasePropKey] = PropInfo
|
||||
return func
|
||||
|
||||
Reference in New Issue
Block a user