本文整理汇总了Python中incoq.compiler.incast.L.rewrite_comp方法的典型用法代码示例。如果您正苦于以下问题:Python L.rewrite_comp方法的具体用法?Python L.rewrite_comp怎么用?Python L.rewrite_comp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类incoq.compiler.incast.L
的用法示例。
在下文中一共展示了L.rewrite_comp方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: flatten_memberships
# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import rewrite_comp [as 别名]
def flatten_memberships(comp):
"""Transform the comprehension to rewrite set memberships (Member
nodes) as MMember clauses. Return an ObjRelations indicating whether
an M set is needed.
"""
M = False
def process(clause):
nonlocal M
if isinstance(clause, L.Member):
# MMember.
if (isinstance(clause.target, L.Name) and
isinstance(clause.iter, L.Name)):
set_ = clause.iter.id
elem = clause.target.id
M = True
clause = L.MMember(set_, elem)
# Subquery clause, leave as Member for now.
elif (isinstance(clause.target, L.Name) and
isinstance(clause.iter, L.Unwrap)):
pass
else:
raise L.ProgramError('Cannot flatten Member clause: {}'
.format(clause))
return clause, [], []
tree = L.rewrite_comp(comp, process)
objrels = ObjRelations(M, [], False, [])
return tree, objrels
示例2: flatten_replaceables
# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import rewrite_comp [as 别名]
def flatten_replaceables(comp):
"""Transform the comprehension to rewrite replaceables and add new
clauses for them. Also return an ObjRelations indicating what object
relations are needed.
"""
field_namer = lambda obj, attr: obj + '_' + attr
map_namer = lambda map, key: map + '_' + key
tuple_namer = lambda elts: 't_' + '_'.join(elts)
rewriter = ReplaceableRewriter(field_namer, map_namer, tuple_namer)
tree = L.rewrite_comp(comp, rewriter.process)
# Go from MutableObjRelations to an immutable one.
objrels = ObjRelations(*rewriter.objrels)
return tree, objrels
示例3: rewrite_comp
# 需要导入模块: from incoq.compiler.incast import L [as 别名]
# 或者: from incoq.compiler.incast.L import rewrite_comp [as 别名]
def rewrite_comp(self, symbol, name, comp):
rewriter = AggrMapReplacer(self.symtab.fresh_names.vars)
comp = L.rewrite_comp(comp, rewriter.process)
self.sfm_invs.update(rewriter.sfm_invs)
return comp