def main(treeFile): import sourceutils.pythonCFGs.CFG as CFG #@UnusedImport tree = pickle.load(open(treeFile)) drawer = DotDrawer() drawer.beginDraw() drawer.drawHeader() for node in tree.nodes: nodeText = "\\n".join([str(r) for r in node.rows]) drawer.drawNode(nodeText, '', 'white') for (src, dst, predicate) in tree.edges: src = 'node%d' % (src) dst = 'node%d' % (dst) drawer.drawLink(src, dst, predicate) drawer.drawFooter() drawer.endDraw()
def __init__(self): PythonASTProcessor.__init__(self) self.drawer = DotDrawer()
class ASTPlotter(PythonASTProcessor): def __init__(self): PythonASTProcessor.__init__(self) self.drawer = DotDrawer() def process(self, treeFilename): self.loadTreeFromFile(treeFilename) self.handlePrunedTree() def handlePrunedTree(self): prunedTree = self.tree.parent self.drawer.beginDraw() self.drawer.drawHeader() self._traverseFunction(prunedTree) self.drawer.drawFooter() self.drawer.endDraw() def _traverseFunction(self, node): if len(node.row) > 0 and node.row[0] == 'LEAF_NODE': return -1 # if len(node.children) >0 and len(node.row) > 2: # node.row = node.row[:1] if len(node.row) > 2: node.row = [node.row[0], node.row[4]] rootNodeLabel = str(node.row) # if rootNodeLabel.find('[\'water') == 0: # style = 'dashed' # fontColor = 'grey' # else: style='' fontColor = 'black' rootNodeId = self.drawer.drawNode(rootNodeLabel, 'http://foo', 'white', style, fontColor) for child in node.children: childNodeId = self._traverseFunction(child) if childNodeId == -1: continue self.drawer.drawLink(rootNodeId, childNodeId) return rootNodeId
def main(treeFile): import sourceutils.pythonCFGs.CFG as CFG #@UnusedImport tree = pickle.load(open(treeFile)) drawer = DotDrawer() drawer.beginDraw() drawer.drawHeader() for node in tree.nodes: nodeText = "\\n".join([str(r) for r in node.rows]) drawer.drawNode(nodeText, '', 'white') for (src, dst, predicate) in tree.edges: src = 'node%d' % (src) dst = 'node%d' %(dst) drawer.drawLink(src, dst, predicate) drawer.drawFooter() drawer.endDraw()
class ASTPlotter(PythonPrunedASTProcessor): def __init__(self): PythonPrunedASTProcessor.__init__(self) self.drawer = DotDrawer() def handlePrunedTree(self): prunedTree = self.tree self.drawer.beginDraw() self.drawer.drawHeader() self._traverseFunction(prunedTree) self.drawer.drawFooter() self.drawer.endDraw() def _traverseFunction(self, node): rootNodeLabel = str(node.row) if rootNodeLabel.find('[\'water') == 0: style = 'dashed' fontColor = 'grey' else: style = '' fontColor = 'black' rootNodeId = self.drawer.drawNode(rootNodeLabel, 'http://foo', 'white', style, fontColor) for child in node.children: childNodeId = self._traverseFunction(child) self.drawer.drawLink(rootNodeId, childNodeId) return rootNodeId
class ASTPlotter(PythonPrunedASTProcessor): def __init__(self): PythonPrunedASTProcessor.__init__(self) self.drawer = DotDrawer() def handlePrunedTree(self): prunedTree = self.tree self.drawer.beginDraw() self.drawer.drawHeader() self._traverseFunction(prunedTree) self.drawer.drawFooter() self.drawer.endDraw() def _traverseFunction(self, node): rootNodeLabel = str(node.row) if rootNodeLabel.find('[\'water') == 0: style = 'dashed' fontColor = 'grey' else: style='' fontColor = 'black' rootNodeId = self.drawer.drawNode(rootNodeLabel, 'http://foo', 'white', style, fontColor) for child in node.children: childNodeId = self._traverseFunction(child) self.drawer.drawLink(rootNodeId, childNodeId) return rootNodeId