当前位置: 首页>>代码示例>>Python>>正文


Python ExprNodes类代码示例

本文整理汇总了Python中ExprNodes的典型用法代码示例。如果您正苦于以下问题:Python ExprNodes类的具体用法?Python ExprNodes怎么用?Python ExprNodes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ExprNodes类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visit_ForInStatNode

 def visit_ForInStatNode(self, node):
     # TODO: Remove redundancy with range optimization...
     is_special = False
     sequence = node.iterator.sequence
     if isinstance(sequence, ExprNodes.SimpleCallNode):
         function = sequence.function
         if sequence.self is None and function.is_name:
             if function.name in ('range', 'xrange'):
                 is_special = True
                 for arg in sequence.args[:2]:
                     self.mark_assignment(node.target, arg)
                 if len(sequence.args) > 2:
                     self.mark_assignment(
                         node.target,
                         ExprNodes.binop_node(node.pos,
                                              '+',
                                              sequence.args[0],
                                              sequence.args[2]))
     if not is_special:
         # A for-loop basically translates to subsequent calls to
         # __getitem__(), so using an IndexNode here allows us to
         # naturally infer the base type of pointers, C arrays,
         # Python strings, etc., while correctly falling back to an
         # object type when the base type cannot be handled.
         self.mark_assignment(node.target, ExprNodes.IndexNode(
             node.pos,
             base = sequence,
             index = ExprNodes.IntNode(node.pos, value = '0')))
     self.visitchildren(node)
     return node
开发者ID:Mistobaan,项目名称:cython,代码行数:30,代码来源:TypeInference.py

示例2: visit_ForFromStatNode

    def visit_ForFromStatNode(self, node):
        condition_block = self.flow.nextblock()
        next_block = self.flow.newblock()
        # Condition with iterator
        self.flow.loops.append(LoopDescr(next_block, condition_block))
        self.visit(node.bound1)
        self.visit(node.bound2)
        if node.step is not None:
            self.visit(node.step)
        # Target assignment
        self.flow.nextblock()
        self.mark_assignment(node.target, node.bound1)
        if node.step is not None:
            self.mark_assignment(node.target, ExprNodes.binop_node(node.pos, "+", node.bound1, node.step))
        # Body block
        self.flow.nextblock()
        self.visit(node.body)
        self.flow.loops.pop()
        # Loop it
        if self.flow.block:
            self.flow.block.add_child(condition_block)
        # Else clause
        if node.else_clause:
            self.flow.nextblock(parent=condition_block)
            self.visit(node.else_clause)
            if self.flow.block:
                self.flow.block.add_child(next_block)
        else:
            condition_block.add_child(next_block)

        if next_block.parents:
            self.flow.block = next_block
        else:
            self.flow.block = None
        return node
开发者ID:fatihmert,项目名称:how-to-cython-mt2,代码行数:35,代码来源:FlowControl.py

示例3: visit_ForInStatNode

    def visit_ForInStatNode(self, node):
        # TODO: Remove redundancy with range optimization...
        is_special = False
        sequence = node.iterator.sequence
        target = node.target
        if isinstance(sequence, ExprNodes.SimpleCallNode):
            function = sequence.function
            if sequence.self is None and function.is_name:
                entry = self.current_env().lookup(function.name)
                if not entry or entry.is_builtin:
                    if function.name == "reversed" and len(sequence.args) == 1:
                        sequence = sequence.args[0]
                    elif function.name == "enumerate" and len(sequence.args) == 1:
                        if target.is_sequence_constructor and len(target.args) == 2:
                            iterator = sequence.args[0]
                            if iterator.is_name:
                                iterator_type = iterator.infer_type(self.current_env())
                                if iterator_type.is_builtin_type:
                                    # assume that builtin types have a length within Py_ssize_t
                                    self.mark_assignment(
                                        target.args[0],
                                        ExprNodes.IntNode(
                                            target.pos, value="PY_SSIZE_T_MAX", type=PyrexTypes.c_py_ssize_t_type
                                        ),
                                    )
                                    target = target.args[1]
                                    sequence = sequence.args[0]
        if isinstance(sequence, ExprNodes.SimpleCallNode):
            function = sequence.function
            if sequence.self is None and function.is_name:
                entry = self.current_env().lookup(function.name)
                if not entry or entry.is_builtin:
                    if function.name in ("range", "xrange"):
                        is_special = True
                        for arg in sequence.args[:2]:
                            self.mark_assignment(target, arg)
                        if len(sequence.args) > 2:
                            self.mark_assignment(
                                target, ExprNodes.binop_node(node.pos, "+", sequence.args[0], sequence.args[2])
                            )

        if not is_special:
            # A for-loop basically translates to subsequent calls to
            # __getitem__(), so using an IndexNode here allows us to
            # naturally infer the base type of pointers, C arrays,
            # Python strings, etc., while correctly falling back to an
            # object type when the base type cannot be handled.
            self.mark_assignment(
                target,
                ExprNodes.IndexNode(
                    node.pos,
                    base=sequence,
                    index=ExprNodes.IntNode(target.pos, value="PY_SSIZE_T_MAX", type=PyrexTypes.c_py_ssize_t_type),
                ),
            )

        self.visitchildren(node)
        return node
开发者ID:B-Rich,项目名称:cython,代码行数:58,代码来源:TypeInference.py

示例4: visit_ForFromStatNode

 def visit_ForFromStatNode(self, node):
     self.mark_assignment(node.target, node.bound1)
     if node.step is not None:
         self.mark_assignment(node.target,
                 ExprNodes.binop_node(node.pos,
                                      '+',
                                      node.bound1,
                                      node.step))
     self.visitchildren(node)
     return node
开发者ID:minisin,项目名称:cython,代码行数:10,代码来源:TypeInference.py

示例5: visit_ForInStatNode

 def visit_ForInStatNode(self, node):
     # TODO: Remove redundancy with range optimization...
     is_special = False
     sequence = node.iterator.sequence
     if isinstance(sequence, ExprNodes.SimpleCallNode):
         function = sequence.function
         if sequence.self is None and function.is_name:
             if function.name in ('range', 'xrange'):
                 is_special = True
                 for arg in sequence.args[:2]:
                     self.mark_assignment(node.target, arg)
                 if len(sequence.args) > 2:
                     self.mark_assignment(
                         node.target, 
                         ExprNodes.binop_node(node.pos,
                                              '+',
                                              sequence.args[0],
                                              sequence.args[2]))
     if not is_special:
         self.mark_assignment(node.target, object_expr)
     self.visitchildren(node)
     return node
开发者ID:anandu,项目名称:pylibs,代码行数:22,代码来源:TypeInference.py


注:本文中的ExprNodes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。