本文整理匯總了Python中pykit.ir.Builder.getfield方法的典型用法代碼示例。如果您正苦於以下問題:Python Builder.getfield方法的具體用法?Python Builder.getfield怎麽用?Python Builder.getfield使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pykit.ir.Builder
的用法示例。
在下文中一共展示了Builder.getfield方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rewrite_setattr
# 需要導入模塊: from pykit.ir import Builder [as 別名]
# 或者: from pykit.ir.Builder import getfield [as 別名]
def rewrite_setattr(func, env):
"""
Resolve missing attributes through __setattr__
"""
context = env['flypy.typing.context']
b = Builder(func)
for op in func.ops:
if op.opcode == 'setfield':
obj, attr, value = op.args
obj_type = context[obj]
attr_type = types.String[()]
if attr not in obj_type.fields and attr not in obj_type.layout:
assert SETATTR in obj_type.fields, attr
b.position_after(op)
# Construct attribute string
attr_string = OConst(attr)
# call(getfield(obj, '__setattr__'), ['attr', value])
method_type = make_method(obj_type, SETATTR)
method = b.getfield(ptypes.Opaque, obj, SETATTR)
call = b.call(ptypes.Opaque, method, [attr_string, value])
op.delete()
# Update context
del context[op]
context[method] = method_type
context[call] = types.Void[()]
context[attr_string] = attr_type