當前位置: 首頁>>代碼示例>>Python>>正文


Python incast.L類代碼示例

本文整理匯總了Python中incoq.compiler.incast.L的典型用法代碼示例。如果您正苦於以下問題:Python L類的具體用法?Python L怎麽用?Python L使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了L類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_priority

 def get_priority(self, cl, bindenv):
     mask = L.mask_from_bounds(self.lhs_vars(cl), bindenv)
     
     if mask == L.mask('bu'):
         return Priority.Constant
     else:
         return super().get_priority(cl, bindenv)
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:7,代碼來源:clause.py

示例2: functionally_determines

 def functionally_determines(self, cl, bindenv):
     mask = L.mask_from_bounds(self.lhs_vars(cl), bindenv)
     
     if mask == L.mask('bu'):
         return True
     else:
         return super().functionally_determines(cl, bindenv)
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:7,代碼來源:clause.py

示例3: visit_DictLookup

 def visit_DictLookup(self, node):
     node = self.generic_visit(node)
     
     # Only simple map lookups are allowed.
     assert isinstance(node.value, L.Name)
     assert L.is_tuple_of_names(node.key)
     assert node.default is None
     map = node.value.id
     keyvars = L.detuplify(node.key)
     
     var = self.repls.get(node, None)
     if var is None:
         mask = L.mapmask_from_len(len(keyvars))
         rel = N.SA_name(map, mask)
         
         # Create a fresh variable.
         self.repls[node] = var = next(self.fresh_names)
         
         # Construct a clause to bind it.
         vars = list(keyvars) + [var]
         new_clause = L.SetFromMapMember(vars, rel, map, mask)
         self.new_clauses.append(new_clause)
         
         # Construct a corresponding SetFromMap invariant.
         sfm = SetFromMapInvariant(rel, map, mask)
         self.sfm_invs.add(sfm)
     
     return L.Name(var)
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:28,代碼來源:comp.py

示例4: get_code

 def get_code(self, cl, bindenv, body):
     assert_unique(cl.vars)
     mask = L.mask_from_bounds(cl.vars, bindenv)
     keyvars, valvar = L.split_by_mask(cl.mask, cl.vars)
     valvar = valvar[0]
     
     # Can also handle all-unbound case by iterating over dict.items(),
     # but requires fresh var for decomposing key tuple.
     
     if L.mask_is_allbound(mask):
         comparison = L.Parser.pe('_KEY in _MAP and _MAP[_KEY] == _VALUE',
                                  subst={'_MAP': cl.map,
                                         '_KEY': L.tuplify(keyvars),
                                         '_VALUE': valvar})
         code = (L.If(comparison, body, ()),)
     
     elif mask == cl.mask:
         code = L.Parser.pc('''
             if _KEY in _MAP:
                 _VALUE = _MAP[_KEY]
                 _BODY
             ''', subst={'_MAP': cl.map,
                         '_KEY': L.tuplify(keyvars),
                         '_VALUE': valvar,
                         '<c>_BODY': body})
     
     else:
         code = super().get_code(cl, bindenv, body)
     
     return code
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:30,代碼來源:clause.py

示例5: convert_subquery_clause

def convert_subquery_clause(clause):
    """Given a clause, if it is a VarsMember clause for an
    incrementalized subquery, return an equivalent RelMember clause.
    For any other clause return the clause unchanged.
    
    The two forms recognized are:
    
        - right-hand side is a Name node
        
        - right-hand side is an ImgLookup node on a Name, with a keymask
    """
    if not isinstance(clause, L.VarsMember):
        return clause
    
    if isinstance(clause.iter, L.Name):
        return L.RelMember(clause.vars, clause.iter.id)
    elif (isinstance(clause.iter, L.ImgLookup) and
          isinstance(clause.iter.set, L.Name) and
          L.is_keymask(clause.iter.mask)):
        nb, nu = L.break_keymask(clause.iter.mask)
        assert nb == len(clause.iter.bounds)
        assert nu == len(clause.vars)
        return L.RelMember(clause.iter.bounds + clause.vars,
                           clause.iter.set.id)
    
    return clause
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:26,代碼來源:trans.py

示例6: visit_Member

 def visit_Member(self, node):
     # For clauses that wrap around another clause, like
     # WithoutMember, reorient the target and iter before recursing.
     handled = False
     
     # <target> in <expr> - {<elem>}
     if (isinstance(node.iter, L.BinOp) and
         isinstance(node.iter.op, L.Sub) and
         isinstance(node.iter.right, L.Set) and
         len(node.iter.right.elts) == 1):
         inner_clause = L.Member(node.target, node.iter.left)
         node = L.WithoutMember(inner_clause, node.iter.right.elts[0])
         handled = True
     
     node = self.generic_visit(node)
     if handled:
         return node
     
     # <vars> in {<elem>}
     if (L.is_tuple_of_names(node.target) and
         isinstance(node.iter, L.Set) and
         len(node.iter.elts) == 1):
         return L.SingMember(L.detuplify(node.target),
                             node.iter.elts[0])
     
     return node
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:26,代碼來源:incast_rewritings.py

示例7: py_preprocess

def py_preprocess(tree):
    """Take in a Python AST tree, partially preprocess it, and return
    the corresponding IncAST tree along with parsed information.
    """
    # Rewrite QUERY directives to replace their source strings with
    # the corresponding parsed Python ASTs. Provided that the other
    # preprocessing steps are functional (i.e., apply equally to
    # multiple occurrences of the same AST), this ensures that any
    # subsequent steps that modify occurrences of a query will also
    # modify its occurrence in the QUERY directive.
    tree = preprocess_query_directives(tree)

    # Admit some constructs as syntactic sugar that would otherwise
    # be excluded from IncAST.
    tree = preprocess_constructs(tree)

    # Get rid of import statement and qualifiers for the runtime
    # library.
    tree = preprocess_runtime_import(tree)

    # Get rid of main boilerplate.
    tree = preprocess_main_call(tree)

    # Get relation declarations.
    tree, decls = preprocess_var_decls(tree)

    # Get symbol info.
    tree, info = preprocess_directives(tree)

    # Convert the tree and parsed query info to IncAST.
    tree = L.import_incast(tree)
    info.query_info = [(L.import_incast(query), value) for query, value in info.query_info]

    return tree, decls, info
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:34,代碼來源:py_rewritings.py

示例8: visit_Member

 def visit_Member(self, node):
     node = self.generic_visit(node)
     
     if (L.is_tuple_of_names(node.target) and
         isinstance(node.iter, L.Query)):
         node = L.VarsMember(L.detuplify(node.target), node.iter)
     
     return node
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:8,代碼來源:misc_rewritings.py

示例9: Tuple_helper

 def Tuple_helper(self, node):
     if not L.is_tuple_of_names(node):
         raise L.ProgramError('Non-simple tuple expression: {}'
                              .format(node))
     elts = L.detuplify(node)
     
     name = self.tuple_namer(elts)
     clause = L.TUPMember(name, elts)
     self.objrels.TUPs.append(len(elts))
     self.after_clauses.insert(0, clause)
     return name
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:11,代碼來源:comp.py

示例10: visit_RelUpdate

 def visit_RelUpdate(self, node):
     if not isinstance(node.op, (L.SetAdd, L.SetRemove)):
         return node
     if node.rel not in self.rels:
         return node
     
     op_name = L.set_update_name(node.op)
     func_name = N.get_maint_func_name(self.result_var, node.rel, op_name)
     
     code = (node,)
     call_code = (L.Expr(L.Call(func_name, [L.Name(node.elem)])),)
     code = L.insert_rel_maint(code, call_code, node.op)
     return code
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:13,代碼來源:trans.py

示例11: visit_RelClear

 def visit_RelClear(self, node):
     code = (node,)
     
     auxmaps = self.auxmaps_by_rel.get(node.rel, set())
     for auxmap in auxmaps:
         clear_code = (L.MapClear(auxmap.map),)
         code = L.insert_rel_maint(code, clear_code, L.SetRemove())
     
     wraps = self.wraps_by_rel.get(node.rel, set())
     for wrap in wraps:
         clear_code = (L.RelClear(wrap.rel),)
         code = L.insert_rel_maint(code, clear_code, L.SetRemove())
     
     return code
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:14,代碼來源:trans.py

示例12: transform_source

def transform_source(input_source, *, options=None, query_options=None):
    """Take in the Python source code to a module and return the
    transformed source code and the symbol table.
    """
    tree = P.Parser.p(input_source)
    
    t1 = process_time()
    tree, symtab = transform_ast(tree, options=options,
                                 query_options=query_options)
    t2 = process_time()
    
    source = P.Parser.ts(tree)
    # All good human beings have trailing newlines in their
    # text files.
    source = source + '\n'
    
    symtab.stats['lines'] = get_loc_source(source)
    # L.tree_size() is for IncASTs, but it should also work for
    # Python ASTs. We have to re-parse the source to get rid of
    # our Comment pseudo-nodes.
    tree = P.Parser.p(source)
    symtab.stats['ast_nodes'] = L.tree_size(tree)
    symtab.stats['time'] = t2 - t1
    
    return source, symtab
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:25,代碼來源:apply.py

示例13: flatten_memberships

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
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:32,代碼來源:comp.py

示例14: is_duplicate_safe

def is_duplicate_safe(clausetools, comp):
    """Return whether we can rule out duplicates analytically."""
    if not L.is_injective(comp.resexp):
        return False
    vars = L.IdentFinder.find_vars(comp.resexp)
    determined = clausetools.all_vars_determined(comp.clauses, vars)
    return determined
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:7,代碼來源:trans.py

示例15: make_setfrommap_type

def make_setfrommap_type(mask, maptype):
    """Given a mask and a map type, determine the corresponding relation
    type.
    
    We obtain by lattice join the smallest map type that is at least as
    big as the given map type and that has the correct key tuple arity.
    This should have the form {(K1, ..., Kn): V}. The relation type is
    then a set of tuples of these types interleaved according to the
    mask.
    
    If no such type exists, e.g. if the given relation type is {Top: Top}
    or the key is not a tuple of correct arity, we instead give the
    relation type {Top}.
    """
    nb = mask.m.count('b')
    assert mask.m.count('u') == 1
    bottom_maptype = T.Map(T.Tuple([T.Bottom] * nb), T.Bottom)
    top_maptype = T.Map(T.Tuple([T.Top] * nb), T.Top)
    
    norm_type = maptype.join(bottom_maptype)
    well_typed = norm_type.issmaller(top_maptype)
    
    if well_typed:
        assert (isinstance(norm_type, T.Map) and
                isinstance(norm_type.key, T.Tuple) and
                len(norm_type.key.elts) == nb)
        t_elts = L.combine_by_mask(mask, norm_type.key.elts,
                                   [norm_type.value])
        rel_type = T.Set(T.Tuple(t_elts))
    else:
        rel_type = T.Set(T.Top)
    
    return rel_type
開發者ID:jieaozhu,項目名稱:dist_lang_reviews,代碼行數:33,代碼來源:trans.py


注:本文中的incoq.compiler.incast.L類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。