19
19
import re
20
20
21
21
22
+ #===-----------------------------------------------------------------------===#
23
+ # These data structures represent a deserialized ExplodedGraph.
24
+ #===-----------------------------------------------------------------------===#
25
+
26
+
22
27
# A helper function for finding the difference between two dictionaries.
23
28
def diff_dicts (curr , prev ):
24
29
removed = [k for k in prev if k not in curr or curr [k ] != prev [k ]]
@@ -368,6 +373,12 @@ def add_raw_line(self, raw_line):
368
373
logging .debug ('Skipping.' )
369
374
370
375
376
+ #===-----------------------------------------------------------------------===#
377
+ # Visitors traverse a deserialized ExplodedGraph and do different things
378
+ # with every node and edge.
379
+ #===-----------------------------------------------------------------------===#
380
+
381
+
371
382
# A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
372
383
# syntax highlighing.
373
384
class DotDumpVisitor (object ):
@@ -775,11 +786,17 @@ def visit_end_of_graph(self):
775
786
self ._dump_raw ('}\n ' )
776
787
777
788
789
+ #===-----------------------------------------------------------------------===#
790
+ # Explorers know how to traverse the ExplodedGraph in a certain order.
791
+ # They would invoke a Visitor on every node or edge they encounter.
792
+ #===-----------------------------------------------------------------------===#
793
+
794
+
778
795
# A class that encapsulates traversal of the ExplodedGraph. Different explorer
779
796
# kinds could potentially traverse specific sub-graphs.
780
- class Explorer (object ):
797
+ class BasicExplorer (object ):
781
798
def __init__ (self ):
782
- super (Explorer , self ).__init__ ()
799
+ super (BasicExplorer , self ).__init__ ()
783
800
784
801
def explore (self , graph , visitor ):
785
802
visitor .visit_begin_graph (graph )
@@ -792,6 +809,11 @@ def explore(self, graph, visitor):
792
809
visitor .visit_end_of_graph ()
793
810
794
811
812
+ #===-----------------------------------------------------------------------===#
813
+ # The entry point to the script.
814
+ #===-----------------------------------------------------------------------===#
815
+
816
+
795
817
def main ():
796
818
parser = argparse .ArgumentParser ()
797
819
parser .add_argument ('filename' , type = str )
@@ -814,7 +836,7 @@ def main():
814
836
raw_line = raw_line .strip ()
815
837
graph .add_raw_line (raw_line )
816
838
817
- explorer = Explorer ()
839
+ explorer = BasicExplorer ()
818
840
visitor = DotDumpVisitor (args .diff , args .dark )
819
841
explorer .explore (graph , visitor )
820
842
0 commit comments