r364991 - [analyzer] exploded-graph-rewriter: NFC: Add more comments.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 2 18:26:39 PDT 2019
Author: dergachev
Date: Tue Jul 2 18:26:38 2019
New Revision: 364991
URL: http://llvm.org/viewvc/llvm-project?rev=364991&view=rev
Log:
[analyzer] exploded-graph-rewriter: NFC: Add more comments.
Modified:
cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
Modified: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/exploded-graph-rewriter.py?rev=364991&r1=364990&r2=364991&view=diff
==============================================================================
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py (original)
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py Tue Jul 2 18:26:38 2019
@@ -19,6 +19,11 @@ import logging
import re
+#===-----------------------------------------------------------------------===#
+# These data structures represent a deserialized ExplodedGraph.
+#===-----------------------------------------------------------------------===#
+
+
# A helper function for finding the difference between two dictionaries.
def diff_dicts(curr, prev):
removed = [k for k in prev if k not in curr or curr[k] != prev[k]]
@@ -368,6 +373,12 @@ class ExplodedGraph(object):
logging.debug('Skipping.')
+#===-----------------------------------------------------------------------===#
+# Visitors traverse a deserialized ExplodedGraph and do different things
+# with every node and edge.
+#===-----------------------------------------------------------------------===#
+
+
# A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
# syntax highlighing.
class DotDumpVisitor(object):
@@ -775,11 +786,17 @@ class DotDumpVisitor(object):
self._dump_raw('}\n')
+#===-----------------------------------------------------------------------===#
+# Explorers know how to traverse the ExplodedGraph in a certain order.
+# They would invoke a Visitor on every node or edge they encounter.
+#===-----------------------------------------------------------------------===#
+
+
# A class that encapsulates traversal of the ExplodedGraph. Different explorer
# kinds could potentially traverse specific sub-graphs.
-class Explorer(object):
+class BasicExplorer(object):
def __init__(self):
- super(Explorer, self).__init__()
+ super(BasicExplorer, self).__init__()
def explore(self, graph, visitor):
visitor.visit_begin_graph(graph)
@@ -792,6 +809,11 @@ class Explorer(object):
visitor.visit_end_of_graph()
+#===-----------------------------------------------------------------------===#
+# The entry point to the script.
+#===-----------------------------------------------------------------------===#
+
+
def main():
parser = argparse.ArgumentParser()
parser.add_argument('filename', type=str)
@@ -814,7 +836,7 @@ def main():
raw_line = raw_line.strip()
graph.add_raw_line(raw_line)
- explorer = Explorer()
+ explorer = BasicExplorer()
visitor = DotDumpVisitor(args.diff, args.dark)
explorer.explore(graph, visitor)
More information about the cfe-commits
mailing list