Example #1
0
 def handleNodeInFunction(self, row):
     level = int(getCSVRowLevel(row))
     
     if self.isInScope(level):
         self.handleNodeInScope(row, level)
     else:
         self.leaveScope(row, level)
Example #2
0
    def handleNodeInFunction(self, row):
        level = int(getCSVRowLevel(row))

        if self.isInScope(level):
            self.handleNodeInScope(row, level)
        else:
            self.leaveScope(row, level)
Example #3
0
 def enterScope(self, row):
     # TODO: simplify: just push nodeId and row
     currentNodeId = self.currentCFG.getCurrentNodeId()
     level = int(getCSVRowLevel(row))
     nodeType = getCSVRowType(row)
     self.scopeStack.append((currentNodeId, nodeType, level))
     self.currentLevel = level + 1
Example #4
0
 def enterScope(self, row):
     # TODO: simplify: just push nodeId and row
     currentNodeId = self.currentCFG.getCurrentNodeId()
     level = int(getCSVRowLevel(row))
     nodeType = getCSVRowType(row)
     self.scopeStack.append((currentNodeId, nodeType, level))
     self.currentLevel = level + 1
Example #5
0
 def _initCFG(self, row):
     self.currentCFG = CFG()
     self.currentCFG.addNode(BasicBlock(row))
     self.currentLevel = int(getCSVRowLevel(row)) + 1
     self.functionLevel = self.currentLevel - 1
     self.functionName = row[5]
     self.functionPos = row[1]
     self.resetStacks()    
Example #6
0
 def _initCFG(self, row):
     self.currentCFG = CFG()
     self.currentCFG.addNode(BasicBlock(row))
     self.currentLevel = int(getCSVRowLevel(row)) + 1
     self.functionLevel = self.currentLevel - 1
     self.functionName = row[5]
     self.functionPos = row[1]
     self.resetStacks()
Example #7
0
 def leaveSwitchScope(self, predicateNodeId):
     self.createAndConnectNode()
            
     labeledNodesCopy = self.currentCFG.labeledNodes[:]
     
     while labeledNodesCopy != []:
         (labelNodeId, labelRow) = labeledNodesCopy.pop()
         labelLevel = int(getCSVRowLevel(labelRow))
         if labelLevel <= self.getCurrentLevel():
             break
         conditionStr = self.getCondition(predicateNodeId)
         conditionStr += ' == ' + labelRow[4]
         self.currentCFG.addEdge(predicateNodeId, labelNodeId, conditionStr)
Example #8
0
    def leaveSwitchScope(self, predicateNodeId):
        self.createAndConnectNode()

        labeledNodesCopy = self.currentCFG.labeledNodes[:]

        while labeledNodesCopy != []:
            (labelNodeId, labelRow) = labeledNodesCopy.pop()
            labelLevel = int(getCSVRowLevel(labelRow))
            if labelLevel <= self.getCurrentLevel():
                break
            conditionStr = self.getCondition(predicateNodeId)
            conditionStr += " == " + labelRow[4]
            self.currentCFG.addEdge(predicateNodeId, labelNodeId, conditionStr)
Example #9
0
    def handleNode(self, row):

        newNode = PythonASTTreeNode(row)

        # code below fails if level ever
        # increases by more than one at once
        level = int(getCSVRowLevel(row))
        if level > len(self.parentStack) - 1:
            # moved down one level, push previous node
            self.parentStack.append(self.previousNode)
        elif level < len(self.parentStack) - 1:
            while (level < len(self.parentStack) - 1):
                self.parentStack.pop()
        else:
            # stayed on a level, no need to adjust parentStack
            pass

        parentNode = self.parentStack[-1]
        parentNode.appendChild(newNode)

        self.previousNode = newNode
Example #10
0
 def handleNode(self, row):
     
     newNode = PythonASTTreeNode(row)
     
     # code below fails if level ever
     # increases by more than one at once
     level = int(getCSVRowLevel(row))
     if level > len(self.parentStack) - 1:
         # moved down one level, push previous node
         self.parentStack.append(self.previousNode)
     elif level < len(self.parentStack) -1:
         while(level < len(self.parentStack) - 1):
             self.parentStack.pop()
     else:
         # stayed on a level, no need to adjust parentStack
         pass
             
     parentNode = self.parentStack[-1]
     parentNode.appendChild(newNode)
     
     self.previousNode = newNode