当前位置: 首页>>代码示例>>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;未经允许,请勿转载。