示例#1
0
 def helper(self, target, id):
     syms = st.gatherSymbols(target)
     
     newtarget = du.genDPatTuple([dha.PatVar(s, dha.P_UNKNOWN) for s in syms])
     
     # Generate wildcard comprehension.
     elt = du.genDTuple([dha.Name(s) for s in syms])
     enumtarget = dka.copy(target)
     st.cleanPatterns(enumtarget)
     WildcardFiller().run(enumtarget)
     enum = dha.RelEnum(enumtarget, id)
     comp = dha.RelSetComp(elt, [enum], [], dka.Symtab())
     
     num = next(wildcard_uid)
     
     repldict = {s: dha.VSymbol(s.name + '_W' + num)
                 for s in syms}
     st.replaceSymbols(comp, repldict)
     
     newid = dha.VSymbol(id.name + '_W' + num)
     
     invdef = dha.InvDef(newid, comp)
     
     ### Need a more robust way to do this part.
     oldccb = self.code_callback
     newccb = \
         (lambda ccb: oldccb(ccb) + [invdef]
             if ccb is self.CCB_NORMAL or
                ccb is self.CCB_LOOP_ENTRY
             else [])
     
     return newtarget, newid, newccb
示例#2
0
文件: inc.py 项目: sadboy/AsdlPy
 def genDSetBlock(self, enumnum, upvalexpr):
     compnode = self.compnode
     enumvars = self.info.enumvars
     
     enums = dka.copy(compnode.enums)
     conds = dka.copy(compnode.conds)
     st.cleanPatterns(enums)
     
     suffix = '_up' + str(enumnum)
     
     wittarget = dka.copy(enums[enumnum].target)
     upval = dka.copy(upvalexpr)
     upvalassign = dha.Assign(wittarget, upval)
     elt = du.genDTuple([s for s in enumvars])
     
     if len(enums) > 1:
         maintenums = enums[:enumnum] + enums[enumnum+1:]
         maintcomp = dha.RelSetComp(elt, maintenums, conds, dka.Symtab())
         maintupdate = dha.SetUpdate(self.diffsym, dha.UpUnionNS(), maintcomp)
     else:
         maintupdate = dha.SetUpdate(self.diffsym, dha.UpAddNS(), elt)
     
     code = [upvalassign, maintupdate]
     
     repldict = {s: dha.VSymbol(s.name + suffix)
                 for s in enumvars}
     st.replaceSymbols(code, repldict)
     
     return code
示例#3
0
 def visit_InvDef(self, node):
     dka.assertnodetype(node.value, dha.RelSetComp)
     
     self.generic_visit(node)
     
     compnode = node.value
     info = node.id.info
     params = info.enumparams
     repldict = {sym: dha.VSymbol(sym.name + '_local')
                 for sym in params}
     
     if len(params) > 0:
         paramtup = du.genDTuple([dha.Name(sym) for sym in params])
         newelt = dha.Tuple([paramtup, dka.copy(compnode.elt)])
         compnode.elt = newelt
     else:
         pass
     
     st.cleanPatterns(compnode)
     st.replaceSymbols(compnode, repldict)