可用的回归测试通过的标准版本
This commit is contained in:
@@ -56,9 +56,9 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
if isinstance(Val.type, ir.IntType):
|
||||
if Val.type.width == 1:
|
||||
return Val
|
||||
return Gen.builder.icmp_signed('!=', Val, Gen._zero_const(Val.type), name="bool_result")
|
||||
return Gen.builder.icmp_signed('!=', Val, Gen._ZeroConst(Val.type), name="bool_result")
|
||||
elif isinstance(Val.type, ir.PointerType):
|
||||
return Gen.builder.icmp_signed('!=', Val, Gen._zero_const(Val.type), name="bool_result")
|
||||
return Gen.builder.icmp_signed('!=', Val, Gen._ZeroConst(Val.type), name="bool_result")
|
||||
return Val
|
||||
return ir.Constant(ir.IntType(1), 0)
|
||||
elif FuncName == 'int':
|
||||
@@ -254,7 +254,7 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
val = Gen.builder.zext(val, ir.IntType(32), name="zext_bool_print")
|
||||
elif val.type.width == 8:
|
||||
if self._is_char_type(arg):
|
||||
char_var = Gen._alloca_entry(ir.IntType(8), name="print_char_buf")
|
||||
char_var = Gen._allocaEntry(ir.IntType(8), name="print_char_buf")
|
||||
Gen.builder.store(val, char_var)
|
||||
fmt_parts.append('%c')
|
||||
fmt_args.append(char_var)
|
||||
@@ -316,7 +316,7 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
if ClassName in Gen.structs:
|
||||
obj_val = Gen.builder.bitcast(obj_val, ir.PointerType(Gen.structs[ClassName]), name=f"cast_{ClassName}")
|
||||
str_val = Gen.builder.call(Gen._get_function(f'{ClassName}.__str__'), [obj_val], name=f"call_{ClassName}.__str__")
|
||||
Gen._register_temp_ptr(str_val)
|
||||
Gen._RegisterTempPtr(str_val)
|
||||
Gen._emit_printf([str_val], unsigned_flags=[False], sep=None, end=None)
|
||||
else:
|
||||
val = self.HandleExprLlvm(arg)
|
||||
@@ -325,7 +325,7 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
pointee = val.type.pointee
|
||||
if not (isinstance(pointee, ir.IntType) and pointee.width == 8):
|
||||
try:
|
||||
val = Gen._load(val, name="print_load")
|
||||
val = Gen._load(val, name="print_Load")
|
||||
except Exception as _e:
|
||||
if __import__('lib.constants.config', fromlist=['mode']).mode == "strict":
|
||||
self.Trans.LogWarning(f"异常被忽略: {_e}")
|
||||
@@ -394,7 +394,7 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
if isinstance(pointee, (ir.IdentifiedStructType, ir.LiteralStructType)):
|
||||
for CN, ST in Gen.structs.items():
|
||||
if pointee == ST:
|
||||
result = self.Trans.ExprUtils._try_operator_overload(CN, '__len__', val, Gen)
|
||||
result = self.Trans.ExprUtils._try_operator_overLoad(CN, '__len__', val, Gen)
|
||||
if result is not None:
|
||||
return result
|
||||
break
|
||||
@@ -442,8 +442,12 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
size_bits = getattr(ctype_inst, 'Size', 0) or 0
|
||||
size_bytes = size_bits // 8
|
||||
return ir.Constant(ir.IntType(64), size_bytes)
|
||||
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")
|
||||
resolved = CTypeRegistry.ResolveName(type_name)
|
||||
if resolved:
|
||||
ctype_cls, ptr_level = resolved
|
||||
@@ -454,8 +458,12 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
if ptr_level > 0:
|
||||
size_bytes = 8
|
||||
return ir.Constant(ir.IntType(64), size_bytes)
|
||||
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")
|
||||
return ir.Constant(ir.IntType(64), 0)
|
||||
|
||||
struct_type = Gen.structs[type_name]
|
||||
@@ -479,7 +487,7 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
if isinstance(pointee, (ir.IdentifiedStructType, ir.LiteralStructType)):
|
||||
for CN, ST in Gen.structs.items():
|
||||
if pointee == ST:
|
||||
result = self.Trans.ExprUtils._try_operator_overload(CN, '__abs__', val, Gen)
|
||||
result = self.Trans.ExprUtils._try_operator_overLoad(CN, '__abs__', val, Gen)
|
||||
if result is not None:
|
||||
return result
|
||||
break
|
||||
@@ -525,12 +533,12 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
if TypeInfo.IsEnum:
|
||||
enum_type_name = arg_name
|
||||
elif isinstance(arg, ast.Attribute):
|
||||
last_part = None
|
||||
LastPart = None
|
||||
enum_class_name = None
|
||||
if isinstance(arg.value, ast.Name):
|
||||
last_part = arg.attr
|
||||
if last_part in self.Trans.SymbolTable:
|
||||
AttrInfo = self.Trans.SymbolTable[last_part]
|
||||
LastPart = arg.attr
|
||||
if LastPart in self.Trans.SymbolTable:
|
||||
AttrInfo = self.Trans.SymbolTable[LastPart]
|
||||
if getattr(AttrInfo, 'IsEnumMember', None) and getattr(AttrInfo, 'EnumName', None):
|
||||
enum_type_name = AttrInfo.EnumName
|
||||
elif isinstance(arg.value, ast.Attribute):
|
||||
@@ -539,9 +547,9 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
parts = attr_path.split('.')
|
||||
if len(parts) >= 2:
|
||||
enum_class_name = parts[-2]
|
||||
last_part = parts[-1]
|
||||
qualified_name_dot = f"{enum_class_name}.{last_part}"
|
||||
qualified_name_under = f"{enum_class_name}_{last_part}"
|
||||
LastPart = parts[-1]
|
||||
qualified_name_dot = f"{enum_class_name}.{LastPart}"
|
||||
qualified_name_under = f"{enum_class_name}_{LastPart}"
|
||||
enum_member_found = None
|
||||
for qname in (qualified_name_dot, qualified_name_under):
|
||||
if qname in self.Trans.SymbolTable:
|
||||
@@ -551,7 +559,7 @@ class ExprBuiltinHandle(BaseHandle):
|
||||
break
|
||||
if not enum_member_found:
|
||||
for key in self.Trans.SymbolTable:
|
||||
if key == last_part:
|
||||
if key == LastPart:
|
||||
info = self.Trans.SymbolTable[key]
|
||||
if getattr(info, 'IsEnumMember', None) and getattr(info, 'EnumName', None) == enum_class_name:
|
||||
enum_member_found = info
|
||||
|
||||
Reference in New Issue
Block a user