本文整理汇总了Python中Node.Node.addChildToBack方法的典型用法代码示例。如果您正苦于以下问题:Python Node.addChildToBack方法的具体用法?Python Node.addChildToBack怎么用?Python Node.addChildToBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node.Node
的用法示例。
在下文中一共展示了Node.addChildToBack方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createWith
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import addChildToBack [as 别名]
def createWith(self, obj, body, lineno):
self.setRequiresActivation()
result = Node(Token.BLOCK, lineno)
result.addChildToBack(Node(Token.ENTERWITH, obj))
bodyNode = Node(Token.WITH, body, lineno)
result.addChildrenToBack(bodyNode)
result.addChildToBack(Node(Token.LEAVEWITH))
return result
示例2: createObjectLiteral
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import addChildToBack [as 别名]
def createObjectLiteral(self, elems):
size = len(elems) / 2
ob = Node(Token.OBJECTLIT)
if (size == 0):
properties = ScriptRuntime.emptyArgs
else:
properties = [object() for __idx0 in range(size)]
## for-while
i = 0
while (i != size):
properties[i] = elems[2 * i]
value = elems[2 * i + 1]
ob.addChildToBack(value)
i += 1
ob.putProp(Node.OBJECT_IDS_PROP, properties)
return ob
示例3: createArrayLiteral
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import addChildToBack [as 别名]
def createArrayLiteral(self, elems, skipCount):
length = len(elems)
skipIndexes = None
if (skipCount != 0):
skipIndexes = [int() for __idx0 in range(skipCount)]
array = Node(Token.ARRAYLIT)
## for-while
i = 0
j = 0
while (i != length):
elem = elems[i]
if elem is not None:
array.addChildToBack(elem)
else:
skipIndexes[j] = i
j += 1
i += 1
if (skipCount != 0):
array.putProp(Node.SKIP_INDEXES_PROP, skipIndexes)
return array
示例4: createForIn
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import addChildToBack [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
示例5: createIf
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import addChildToBack [as 别名]
def createIf(self, cond, ifTrue, ifFalse, lineno):
condStatus = self.isAlwaysDefinedBoolean(cond)
if (condStatus == self.ALWAYS_TRUE_BOOLEAN):
return ifTrue
else:
if (condStatus == self.ALWAYS_FALSE_BOOLEAN):
if ifFalse is not None:
return ifFalse
return Node(Token.BLOCK, lineno)
result = Node(Token.BLOCK, lineno)
ifNotTarget = Node.newTarget()
IFNE = Jump(Token.IFNE, cond)
IFNE.target = ifNotTarget
result.addChildToBack(IFNE)
result.addChildrenToBack(ifTrue)
if ifFalse is not None:
endTarget = Node.newTarget()
result.addChildToBack(self.makeJump(Token.GOTO, endTarget))
result.addChildToBack(ifNotTarget)
result.addChildrenToBack(ifFalse)
result.addChildToBack(endTarget)
else:
result.addChildToBack(ifNotTarget)
return result
示例6: createTryCatchFinally
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import addChildToBack [as 别名]
def createTryCatchFinally(self, tryBlock, catchBlocks, finallyBlock, lineno):
hasFinally = finallyBlock is not None and ( (finallyBlock.getType() != Token.BLOCK) or finallyBlock.hasChildren())
if (tryBlock.getType() == Token.BLOCK) and not tryBlock.hasChildren() and not hasFinally:
return tryBlock
hasCatch = catchBlocks.hasChildren()
if not hasFinally and not hasCatch:
return tryBlock
handlerBlock = Node(Token.LOCAL_BLOCK)
pn = Jump(Token.TRY, tryBlock, lineno)
pn.putProp(Node.LOCAL_BLOCK_PROP, handlerBlock)
if hasCatch:
endCatch = Node.newTarget()
pn.addChildToBack(self.makeJump(Token.GOTO, endCatch))
catchTarget = Node.newTarget()
pn.target = catchTarget
pn.addChildToBack(catchTarget)
catchScopeBlock = Node(Token.LOCAL_BLOCK)
cb = catchBlocks.getFirstChild()
hasDefault = False
scopeIndex = 0
while cb is not None:
catchLineNo = cb.getLineno()
name = cb.getFirstChild()
cond = name.getNext()
catchStatement = cond.getNext()
cb.removeChild(name)
cb.removeChild(cond)
cb.removeChild(catchStatement)
catchStatement.addChildToBack(Node(Token.LEAVEWITH))
catchStatement.addChildToBack(self.makeJump(Token.GOTO, endCatch))
condStmt = None#Node()
if (cond.getType() == Token.EMPTY):
condStmt = catchStatement
hasDefault = True
else:
condStmt = self.createIf(cond, catchStatement, None, catchLineNo)
catchScope = Node(Token.CATCH_SCOPE, name, self.createUseLocal(handlerBlock))
catchScope.putProp(Node.LOCAL_BLOCK_PROP, catchScopeBlock)
catchScope.putIntProp(Node.CATCH_SCOPE_PROP, scopeIndex)
catchScopeBlock.addChildToBack(catchScope)
catchScopeBlock.addChildToBack(self.createWith(self.createUseLocal(catchScopeBlock), condStmt, catchLineNo))
cb = cb.getNext()
scopeIndex += 1
pn.addChildToBack(catchScopeBlock)
if not hasDefault:
rethrow = Node(Token.RETHROW)
rethrow.putProp(Node.LOCAL_BLOCK_PROP, handlerBlock)
pn.addChildToBack(rethrow)
pn.addChildToBack(endCatch)
if hasFinally:
finallyTarget = Node.newTarget()
pn.setFinally(finallyTarget)
pn.addChildToBack(self.makeJump(Token.JSR, finallyTarget))
finallyEnd = Node.newTarget()
pn.addChildToBack(self.makeJump(Token.GOTO, finallyEnd))
pn.addChildToBack(finallyTarget)
fBlock = Node(Token.FINALLY, finallyBlock)
fBlock.putProp(Node.LOCAL_BLOCK_PROP, handlerBlock)
pn.addChildToBack(fBlock)
pn.addChildToBack(finallyEnd)
handlerBlock.addChildToBack(pn)
return handlerBlock