本文整理汇总了Python中Node.Node.putProp方法的典型用法代码示例。如果您正苦于以下问题:Python Node.putProp方法的具体用法?Python Node.putProp怎么用?Python Node.putProp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node.Node
的用法示例。
在下文中一共展示了Node.putProp方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createPropertyGet
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import putProp [as 别名]
def createPropertyGet(self, target, namespace, name, memberTypeFlags):
if namespace is None and (memberTypeFlags == 0):
if target is None:
return self.createName(name)
self.checkActivationName(name, Token.GETPROP)
if ScriptRuntime.isSpecialProperty(name):
ref = Node(Token.REF_SPECIAL, target)
ref.putProp(Node.NAME_PROP, name)
return Node(Token.GET_REF, ref)
return Node(Token.GETPROP, target, self.createString(name))
elem = self.createString(name)
memberTypeFlags |= Node.PROPERTY_FLAG
return self.createMemberRefGet(target, namespace, elem, memberTypeFlags)
示例2: createObjectLiteral
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import putProp [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 putProp [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 putProp [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: createUseLocal
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import putProp [as 别名]
def createUseLocal(self, localBlock):
if (Token.LOCAL_BLOCK != localBlock.getType()):
raise Kit.codeBug()
result = Node(Token.LOCAL_LOAD)
result.putProp(Node.LOCAL_BLOCK_PROP, localBlock)
return result
示例6: createTryCatchFinally
# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import putProp [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