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


Python Node.newString方法代码示例

本文整理汇总了Python中Node.Node.newString方法的典型用法代码示例。如果您正苦于以下问题:Python Node.newString方法的具体用法?Python Node.newString怎么用?Python Node.newString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Node.Node的用法示例。


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

示例1: initFunction

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import newString [as 别名]
    def initFunction(self, fnNode, functionIndex, statements, functionType):
        fnNode.itsFunctionType = functionType
        fnNode.addChildToBack(statements)
        functionCount = fnNode.getFunctionCount()
        if (functionCount != 0):
            fnNode.itsNeedsActivation = True
            ## for-while
            i = 0
            while (i != functionCount):
                fn = fnNode.getFunctionNode(i)
                if (fn.getFunctionType() == FunctionNode.FUNCTION_EXPRESSION_STATEMENT):
                    name = fn.getFunctionName()
                    if name is not None and (len(name) != 0):
                        fnNode.removeParamOrVar(name)
                i += 1
        if (functionType == FunctionNode.FUNCTION_EXPRESSION):
            name = fnNode.getFunctionName()
            if (name is not None) and \
                            len(name) != 0 \
                            and (not fnNode.hasParamOrVar(name)):

                if (fnNode.addVar(name) == ScriptOrFnNode.DUPLICATE_CONST):
                    self.parser.addError("msg.const.redecl", name)
                setFn = Node(Token.EXPR_VOID, Node(Token.SETNAME, Node.newString(Token.BINDNAME, name), Node(Token.THISFN)))
                statements.addChildrenToFront(setFn)
        lastStmt = statements.getLastChild()
        if lastStmt is None or (lastStmt.getType() != Token.RETURN):
            statements.addChildToBack(Node(Token.RETURN))
        result = Node.newString(Token.FUNCTION, fnNode.getFunctionName())
        result.putIntProp(Node.FUNCTION_PROP, functionIndex)
        return result
开发者ID:Mitame,项目名称:pynoceros,代码行数:33,代码来源:IRFactory.py

示例2: createAssignment

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import newString [as 别名]
 def createAssignment(self, assignType, left, right):
     left = self.makeReference(left)
     if left is None:
         self.parser.reportError("msg.bad.assign.left")
         return right
     assignOp = 0
     if assignType == Token.ASSIGN:
         return self.simpleAssignment(left, right)
     elif assignType == Token.ASSIGN_BITOR:
         assignOp = Token.BITOR
     elif assignType == Token.ASSIGN_BITXOR:
         assignOp = Token.BITXOR
     elif assignType == Token.ASSIGN_BITAND:
         assignOp = Token.BITAND
     elif assignType == Token.ASSIGN_LSH:
         assignOp = Token.LSH
     elif assignType == Token.ASSIGN_RSH:
         assignOp = Token.RSH
     elif assignType == Token.ASSIGN_URSH:
         assignOp = Token.URSH
     elif assignType == Token.ASSIGN_ADD:
         assignOp = Token.ADD
     elif assignType == Token.ASSIGN_SUB:
         assignOp = Token.SUB
     elif assignType == Token.ASSIGN_MUL:
         assignOp = Token.MUL
     elif assignType == Token.ASSIGN_DIV:
         assignOp = Token.DIV
     elif assignType == Token.ASSIGN_MOD:
         assignOp = Token.MOD
     else:
         raise Kit.codeBug()
     nodeType = left.getType()
     if nodeType == Token.NAME:
         s = left.getString()
         opLeft = Node.newString(Token.NAME, s)
         op = Node(assignOp, opLeft, right)
         lvalueLeft = Node.newString(Token.BINDNAME, s)
         return Node(Token.SETNAME, lvalueLeft, op)
     elif nodeType in (Token.GETPROP,
                       Token.GETELEM):
         obj = left.getFirstChild()
         id = left.getLastChild()
         type = Token.SETPROP_OP if (nodeType == Token.GETPROP) else Token.SETELEM_OP
         opLeft = Node(Token.USE_STACK)
         op = Node(assignOp, opLeft, right)
         return Node(type, obj, id, op)
     elif nodeType == Token.GET_REF:
         ref = left.getFirstChild()
         self.checkMutableReference(ref)
         opLeft = Node(Token.USE_STACK)
         op = Node(assignOp, opLeft, right)
         return Node(Token.SET_REF_OP, ref, op)
     raise Kit.codeBug()
开发者ID:Mitame,项目名称:pynoceros,代码行数:56,代码来源:IRFactory.py

示例3: createForIn

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import newString [as 别名]
 def createForIn(self, loop,
                       lhs,
                       obj,
                       body,
                       isForEach):
     type = lhs.getType()
     lvalue = None#Node()
     if (type == Token.VAR):
         lastChild = lhs.getLastChild()
         if (lhs.getFirstChild() != lastChild):
             self.parser.reportError("msg.mult.index")
         lvalue = Node.newString(Token.NAME, lastChild.getString())
     else:
         lvalue = self.makeReference(lhs)
         if lvalue is None:
             self.parser.reportError("msg.bad.for.in.lhs")
             return obj
     localBlock = Node(Token.LOCAL_BLOCK)
     initType = Token.ENUM_INIT_VALUES if isForEach else Token.ENUM_INIT_KEYS
     init = Node(initType, obj)
     init.putProp(Node.LOCAL_BLOCK_PROP, localBlock)
     cond = Node(Token.ENUM_NEXT)
     cond.putProp(Node.LOCAL_BLOCK_PROP, localBlock)
     id = Node(Token.ENUM_ID)
     id.putProp(Node.LOCAL_BLOCK_PROP, localBlock)
     newBody = Node(Token.BLOCK)
     assign = self.simpleAssignment(lvalue, id)
     newBody.addChildToBack(Node(Token.EXPR_VOID, assign))
     newBody.addChildToBack(body)
     loop = self.createWhile(loop, cond, newBody)
     loop.addChildToFront(init)
     if (type == Token.VAR):
         loop.addChildToFront(lhs)
     localBlock.addChildToBack(loop)
     return localBlock
开发者ID:Mitame,项目名称:pynoceros,代码行数:37,代码来源:IRFactory.py

示例4: createUnary

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import newString [as 别名]
 def createUnary(self, nodeType, child):
     childType = child.getType()
     if nodeType == Token.DELPROP:
         n = None#Node()
         if (childType == Token.NAME):
             child.setType(Token.BINDNAME)
             left = child
             right = Node.newString(child.getString())
             n = Node(nodeType, left, right)
         else:
             if (childType == Token.GETPROP) or (childType == Token.GETELEM):
                 left = child.getFirstChild()
                 right = child.getLastChild()
                 child.removeChild(left)
                 child.removeChild(right)
                 n = Node(nodeType, left, right)
             else:
                 if (childType == Token.GET_REF):
                     ref = child.getFirstChild()
                     child.removeChild(ref)
                     n = Node(Token.DEL_REF, ref)
                 else:
                     n = Node(Token.TRUE)
         return n
     elif nodeType == Token.TYPEOF:
         if (childType == Token.NAME):
             child.setType(Token.TYPEOFNAME)
             return child
     elif nodeType == Token.BITNOT:
         if (childType == Token.NUMBER):
             value = ScriptRuntime.toInt32(child.getDouble())
             child.setDouble(~value)
             return child
     elif nodeType == Token.NEG:
         if (childType == Token.NUMBER):
             child.setDouble(-child.getDouble())
             return child
     elif nodeType == Token.NOT:
         status = self.isAlwaysDefinedBoolean(child)
         if (status != 0):
             type = 0
             if (status == self.ALWAYS_TRUE_BOOLEAN):
                 type = Token.FALSE
             else:
                 type = Token.TRUE
             if (childType == Token.TRUE) or (childType == Token.FALSE):
                 child.setType(type)
                 return child
             return Node(type)
     return Node(nodeType, child)
开发者ID:Mitame,项目名称:pynoceros,代码行数:52,代码来源:IRFactory.py

示例5: createString

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import newString [as 别名]
 def createString(self, string):
     return Node.newString(string)
开发者ID:Mitame,项目名称:pynoceros,代码行数:4,代码来源:IRFactory.py

示例6: createName

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import newString [as 别名]
 def createName(self, name):
     self.checkActivationName(name, Token.NAME)
     return Node.newString(Token.NAME, name)
开发者ID:Mitame,项目名称:pynoceros,代码行数:5,代码来源:IRFactory.py


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