refactor(c): 删除 c.* 及对应的裸名语法糖处理分支
移除 c.CIf 判断、Addr/Load/Deref/DerefAs/PtrToInt 裸名分支及 _HandleC* 处理函数;c. 前缀退役后不再保留任何处理路径。
This commit is contained in:
1 parent
f32235274b
commit
c94cdd7174
3 files changed
-228
No files matched your search
@@ -536,16 +536,6 @@ class ExprCallHandle(BaseHandle):
|
||||
# CPragma / CUndef 不是普通函数,优先于符号查找。
|
||||
if FuncName == 'Asm':
|
||||
return self.Trans.ExprAsmHandle._HandleAsmLlvm(Node)
|
||||
if FuncName == 'Addr':
|
||||
return self.Trans.CSpecialCallHandle._HandleCAddrLlvm(Node)
|
||||
if FuncName == 'Load':
|
||||
return self.Trans.CSpecialCallHandle._HandleCLoadLlvm(Node)
|
||||
if FuncName == 'Deref':
|
||||
return self.Trans.CSpecialCallHandle._HandleCDerefLlvm(Node)
|
||||
if FuncName == 'DerefAs':
|
||||
return self._HandleCDerefAsLlvm(Node)
|
||||
if FuncName == 'PtrToInt':
|
||||
return self.Trans.CSpecialCallHandle._HandleCPtrToIntLlvm(Node)
|
||||
if FuncName in ('AsmInp', 'AsmOut', 'LInp', 'LOut'):
|
||||
return ir.Constant(ir.IntType(32), 0)
|
||||
if FuncName == 'LLVMIR':
|
||||
@@ -4850,47 +4840,6 @@ class ExprCallHandle(BaseHandle):
|
||||
Gen: LlvmGeneratorMixin = self.Trans.LlvmGen
|
||||
return ir.Constant(ir.IntType(32), 0)
|
||||
|
||||
def _HandleCDerefAsLlvm(self, Node: ast.Call) -> ir.Value | None:
|
||||
"""DerefAs(p, v):bitcast **指针** p 到 typeof(v)* 后按值存 v(`*(T*(p)) = v`)。
|
||||
|
||||
与 ViperC CallGenCBuiltin.translate_c_derefas 逐字同口径:
|
||||
- 单参形式(len<2)是**解引用读取**(等同 Deref(p));
|
||||
- 双参:p、v 均为指针且 p 的 pointee 是结构体且与 v 的 pointee **同一**时,
|
||||
按整对象拷贝(load v 指向的对象 + bitcast p + store);否则 bitcast p 到
|
||||
typeof(v)* 后按值 store v。
|
||||
此前实现把**值** bitcast 成指针大小整数再写(`*(intptr_t*(p)) = (intptr_t)v`),
|
||||
与语义不符(R5 混淆了"bitcast 指针"与"bitcast 值")。
|
||||
"""
|
||||
Gen: LlvmGeneratorMixin = self.Trans.LlvmGen
|
||||
if Node.args is None or len(Node.args) < 1:
|
||||
return ir.Constant(ir.IntType(32), 0)
|
||||
if len(Node.args) < 2:
|
||||
# 单参:解引用读取(与 VPC translate_c_derefas 的转发口径一致)
|
||||
return self.Trans.CSpecialCallHandle._HandleCDerefLlvm(Node)
|
||||
ptr_val: ir.Value | None = self.HandleExprLlvm(Node.args[0])
|
||||
val_val: ir.Value | None = self.HandleExprLlvm(Node.args[1])
|
||||
if ptr_val is None or val_val is None:
|
||||
return ir.Constant(ir.IntType(32), 0)
|
||||
if not isinstance(ptr_val.type, ir.PointerType):
|
||||
return val_val
|
||||
# 整对象拷贝:p 的 pointee 是结构体且与 v 的 pointee 同一(REnum 变体 tag 才不会丢)
|
||||
if isinstance(val_val.type, ir.PointerType):
|
||||
p_pointee: ir.Type = ptr_val.type.pointee
|
||||
v_pointee: ir.Type = val_val.type.pointee
|
||||
if (isinstance(p_pointee, (ir.IdentifiedStructType, ir.LiteralStructType))
|
||||
and p_pointee == v_pointee):
|
||||
loaded_s: ir.Value = Gen._load(val_val, name="deref_as_struct_load")
|
||||
store_ptr: ir.Value = ptr_val
|
||||
if store_ptr.type != val_val.type:
|
||||
store_ptr = Gen.builder.bitcast(ptr_val, val_val.type, name="deref_as_ptr_align")
|
||||
Gen._store(loaded_s, store_ptr)
|
||||
return val_val
|
||||
# 常规:bitcast p 到 typeof(v)* 后按值存 v(`*(T*(p)) = v`)
|
||||
if ptr_val.type.pointee != val_val.type:
|
||||
ptr_val = Gen.builder.bitcast(ptr_val, ir.PointerType(val_val.type), name="deref_as_cast")
|
||||
Gen._store(val_val, ptr_val)
|
||||
return val_val
|
||||
|
||||
def _InjectRequiresFields(self, result: ir.Value, ClassName: str, Gen: LlvmGeneratorMixin) -> None:
|
||||
"""在 __new__ 后、__init__ 前自动注入 __requires__/__require_must__ 字段。
|
||||
|
||||
|
||||
Reference in new issue
Block a user