From 5fcf92e153806e8fb3f195104f3d057580236132 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Wed, 3 Jul 2019 01:26:38 +0000 Subject: [PATCH] [analyzer] exploded-graph-rewriter: NFC: Add more comments. llvm-svn: 364991 --- clang/utils/analyzer/exploded-graph-rewriter.py | 28 ++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/clang/utils/analyzer/exploded-graph-rewriter.py b/clang/utils/analyzer/exploded-graph-rewriter.py index cb8af92..463ae02 100755 --- a/clang/utils/analyzer/exploded-graph-rewriter.py +++ b/clang/utils/analyzer/exploded-graph-rewriter.py @@ -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) -- 2.7.4