本文整理汇总了Python中State.State.env_set方法的典型用法代码示例。如果您正苦于以下问题:Python State.env_set方法的具体用法?Python State.env_set怎么用?Python State.env_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State.State
的用法示例。
在下文中一共展示了State.env_set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _analyseStatement
# 需要导入模块: from State import State [as 别名]
# 或者: from State.State import env_set [as 别名]
def _analyseStatement(self, astNumber, nodeNumber, state, recursionDepth):
''' Analyses a single statment
Executes a statement returning its history. A return value is not provided.
Handling "return" is done by observing the special return-Element in the
env after a function has run through.
There is no return value -> This is handled differently: There is a special return value in "env"
this can be then be read when the function call returns!
To handle the histories: A certain history is NOT extended if its last event
is ret with the function beeing the same element the special "context.functionName" points
to in the current context -> Handle recursive calls later!
In Statements (despite for the return statement), merging the HistorieCollections
returned by the Expressions is the only thing, that is done concerning histories.
Input:
astNumber: The ast the statement belongs to
nodeNumber: The node in the AST to analyse
state: The state with the current environment, the objects and the heap.
Return:
hist: The HistoryCollection for this node
'''
### Get Statement and type
ast = self.asts[astNumber]
curNode = ast[nodeNumber]
t = curNode["type"]
### Analyse the Statements based on type
if t == "ExpressionStatement":
tmpHis, ret = self._analyseExpression(astNumber, curNode["children"][0], state, recursionDepth)
return tmpHis
elif t in ["Program","BlockStatement","WithStatement"]:
hist = HistoryCollection()
if "children" in curNode:
for i in curNode["children"]:
tmpHist = self._analyseStatement(astNumber, i, state, recursionDepth)
hist.addHistoryCollection(tmpHist)
return hist
if t in ["EmptyStatement", "DebuggerStatement"]:
return HistoryCollection()
# Control Flow (ignore completly, TODO)
if t in ["BreakStatement", "ContinueStatement"]:
return HistoryCollection()
elif t == "ReturnStatement":
# Do nothing for returns without return value
if not "children" in curNode:
return HistoryCollection()
# Extend the the "__return__" variable and add the "return" statement to the history.
hist, ret = self._analyseExpression(astNumber, curNode["children"][0],state, recursionDepth)
if ret:
returnObject = state.getTarget(ret)
state.env_set("__return__", returnObject)# Merging is done automatically
if returnObject != None:
hist.addEventToHistory(returnObject, state.functionName,"ret", state.functionName)
return hist
# Choice
elif t == "IfStatement":
hist, ret = self._analyseExpression(astNumber, curNode["children"][0], state, recursionDepth)
hist.tagAsSpecialNode("ic")
thenState = state.copy()
hist_then = self._analyseStatement(astNumber, curNode["children"][1], thenState, recursionDepth)
# Check whether else is given
if len(curNode["children"]) == 3:
elseState = state.copy()
hist_else = self._analyseStatement(astNumber, curNode["children"][2], elseState, recursionDepth)
state.mergeIn([thenState,elseState])
hist.addHistoriesConditional([hist_then,hist_else])
else:
hist.addHistoriesConditional([hist_then,HistoryCollection()])
state.mergeIn([thenState])
return hist
elif t == "SwitchStatement":
hist, ret = self._analyseExpression(astNumber, curNode["children"][0], state, recursionDepth)
hist.tagAsSpecialNode("sc")
condHistories = []
condStates = []
preceedingCaseConditions = []
for case in curNode["children"][1:]:
condStates.append(state.copy())
case = ast[case]
innerHist = HistoryCollection()
# Handle previous case conditions
for precCaseCond in preceedingCaseConditions:
tmpHist, ret = self._analyseExpression(astNumber, precCaseCond, condStates[-1], recursionDepth)
innerHist.addHistoryCollection(tmpHist)
# Handle current case
isDefault = len(case["children"]) == 1
if not isDefault:
preceedingCaseConditions.append(case["children"][0]);
tmpHist, ret = self._analyseExpression(astNumber, case["children"][0], condStates[-1], recursionDepth)
tmpHist.tagAsSpecialNode("cc")
innerHist.addHistoryCollection(tmpHist)
tmpHist = self._analyseStatement(astNumber, case["children"][1], condStates[-1], recursionDepth)
#.........这里部分代码省略.........