Skip to content

Commit ad38e58

Browse files
committed
[analyzer] exploded-graph-rewriter: Implement a dark color scheme.
Addresses a popular request. Activated via --dark. Differential Revision: https://reviews.llvm.org/D64056 llvm-svn: 364882
1 parent 2ca5355 commit ad38e58

File tree

6 files changed

+57
-15
lines changed

6 files changed

+57
-15
lines changed

clang/test/Analysis/exploded-graph-rewriter/edge.dot

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %exploded_graph_rewriter %s | FileCheck %s
1+
// RUN: %exploded_graph_rewriter %s | FileCheck %s -check-prefix=LIGHT
2+
// RUN: %exploded_graph_rewriter --dark %s | FileCheck %s -check-prefixes=DARK
23

34
// FIXME: Substitution doesn't seem to work on Windows.
45
// UNSUPPORTED: system-windows
@@ -7,7 +8,8 @@ Node0x1 [shape=record,label=
78
"{{ "node_id": 1, "pointer": "0x1",
89
"program_state": null, "program_points": []}\l}"];
910

10-
// CHECK: Node0x1 -> Node0x2;
11+
// LIGHT: Node0x1 -> Node0x2;
12+
// DARK: Node0x1 -> Node0x2 [color="white"];
1113
Node0x1 -> Node0x2;
1214

1315
Node0x2 [shape=record,label=

clang/test/Analysis/exploded-graph-rewriter/empty.dot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: %exploded_graph_rewriter %s | FileCheck %s
2+
// RUN: %exploded_graph_rewriter --dark %s | FileCheck %s \
3+
// RUN: -check-prefixes=CHECK,DARK
24

35
// FIXME: Substitution doesn't seem to work on Windows.
46
// UNSUPPORTED: system-windows
@@ -8,5 +10,6 @@ digraph "Exploded Graph" {
810
}
911

1012
// CHECK: digraph "ExplodedGraph" {
13+
// DARK-NEXT: bgcolor="gray10";
1114
// CHECK-NEXT: label="";
1215
// CHECK-NEXT: }

clang/test/Analysis/exploded-graph-rewriter/environment.dot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// CHECK-SAME: <b>#0 Call</b>
1111
// CHECK-SAME: </td>
1212
// CHECK-SAME: <td align="left" colspan="2">
13-
// CHECK-SAME: <font color="grey60">foo </font>(line 4)
13+
// CHECK-SAME: <font color="gray60">foo </font>(line 4)
1414
// CHECK-SAME: </td>
1515
// CHECK-SAME: </tr>
1616
// CHECK-SAME: <tr>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %exploded_graph_rewriter %s | FileCheck %s -check-prefixes=CHECK,LIGHT
2+
// RUN: %exploded_graph_rewriter %s --dark | FileCheck %s \
3+
// RUN: -check-prefixes CHECK,DARK
4+
5+
// FIXME: Substitution doesn't seem to work on Windows.
6+
// UNSUPPORTED: system-windows
7+
8+
// LIGHT: Node0x1 [shape=record,label=<
9+
// DARK: Node0x1 [shape=record,color="white",fontcolor="gray80",label=<
10+
// CHECK-SAME: <tr>
11+
// LIGHT-SAME: <td bgcolor="gray">
12+
// DARK-SAME: <td bgcolor="gray20">
13+
// CHECK-SAME: <b>Node 1 (0x1) - State Unspecified</b>
14+
// CHECK-SAME: </td>
15+
// CHECK-SAME: </tr>
16+
Node0x1 [shape=record,label=
17+
"{
18+
{ "node_id": 1, "pointer": "0x1",
19+
"program_state": null,
20+
"program_points": []
21+
}
22+
\l}"];

clang/test/Analysis/exploded-graph-rewriter/objects_under_construction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void test() {
1717
// CHECK-SAME: <tr>
1818
// CHECK-SAME: <td align="left"><b>#0 Call</b></td>
1919
// CHECK-SAME: <td align="left" colspan="2">
20-
// CHECK-SAME: <font color="grey60">test </font>
20+
// CHECK-SAME: <font color="gray60">test </font>
2121
// CHECK-SAME: </td>
2222
// CHECK-SAME: </tr>
2323
// CHECK-SAME: <tr>

clang/utils/analyzer/exploded-graph-rewriter.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,10 @@ def add_raw_line(self, raw_line):
334334
# A visitor that dumps the ExplodedGraph into a DOT file with fancy HTML-based
335335
# syntax highlighing.
336336
class DotDumpVisitor(object):
337-
def __init__(self, do_diffs):
337+
def __init__(self, do_diffs, dark_mode):
338338
super(DotDumpVisitor, self).__init__()
339339
self._do_diffs = do_diffs
340+
self._dark_mode = dark_mode
340341

341342
@staticmethod
342343
def _dump_raw(s):
@@ -363,6 +364,8 @@ def _diff_plus_minus(is_added):
363364
def visit_begin_graph(self, graph):
364365
self._graph = graph
365366
self._dump_raw('digraph "ExplodedGraph" {\n')
367+
if self._dark_mode:
368+
self._dump_raw('bgcolor="gray10";\n')
366369
self._dump_raw('label="";\n')
367370

368371
def visit_program_point(self, p):
@@ -372,7 +375,7 @@ def visit_program_point(self, p):
372375
'PostStmtPurgeDeadSymbols']:
373376
color = 'red'
374377
elif p.kind in ['CallEnter', 'CallExitBegin', 'CallExitEnd']:
375-
color = 'blue'
378+
color = 'dodgerblue' if self._dark_mode else 'blue'
376379
elif p.kind in ['Statement']:
377380
color = 'cyan4'
378381
else:
@@ -436,7 +439,7 @@ def dump_location_context(lc, is_added=None):
436439
self._dump('<tr><td>%s</td>'
437440
'<td align="left"><b>%s</b></td>'
438441
'<td align="left" colspan="2">'
439-
'<font color="grey60">%s </font>'
442+
'<font color="gray60">%s </font>'
440443
'%s</td></tr>'
441444
% (self._diff_plus_minus(is_added),
442445
lc.caption, lc.decl,
@@ -451,9 +454,11 @@ def dump_binding(f, b, is_added=None):
451454
'<td align="left">%s</td></tr>'
452455
% (self._diff_plus_minus(is_added),
453456
b.stmt_id,
454-
'<td align="left"><font color="darkgreen"><i>'
455-
'(%s)</i></font></td>' % b.kind
456-
if b.kind is not None else '',
457+
'<td align="left"><font color="%s"><i>'
458+
'%s</i></font></td>' % (
459+
'lavender' if self._dark_mode else 'darkgreen',
460+
('(%s)' % b.kind) if b.kind is not None else ' '
461+
),
457462
b.pretty, f.bindings[b]))
458463

459464
frames_updated = e.diff_frames(prev_e) if prev_e is not None else None
@@ -615,12 +620,16 @@ def visit_state(self, s, prev_s):
615620
s, prev_s)
616621

617622
def visit_node(self, node):
618-
self._dump('%s [shape=record,label=<<table border="0">'
623+
self._dump('%s [shape=record,'
619624
% (node.node_name()))
625+
if self._dark_mode:
626+
self._dump('color="white",fontcolor="gray80",')
627+
self._dump('label=<<table border="0">')
620628

621-
self._dump('<tr><td bgcolor="grey"><b>Node %d (%s) - '
629+
self._dump('<tr><td bgcolor="%s"><b>Node %d (%s) - '
622630
'State %s</b></td></tr>'
623-
% (node.node_id, node.ptr, node.state.state_id
631+
% ("gray20" if self._dark_mode else "gray",
632+
node.node_id, node.ptr, node.state.state_id
624633
if node.state is not None else 'Unspecified'))
625634
self._dump('<tr><td align="left" width="0">')
626635
if len(node.points) > 1:
@@ -645,7 +654,10 @@ def visit_node(self, node):
645654
self._dump_raw('</table>>];\n')
646655

647656
def visit_edge(self, pred, succ):
648-
self._dump_raw('%s -> %s;\n' % (pred.node_name(), succ.node_name()))
657+
self._dump_raw('%s -> %s%s;\n' % (
658+
pred.node_name(), succ.node_name(),
659+
' [color="white"]' if self._dark_mode else ''
660+
))
649661

650662
def visit_end_of_graph(self):
651663
self._dump_raw('}\n')
@@ -678,6 +690,9 @@ def main():
678690
parser.add_argument('-d', '--diff', action='store_const', dest='diff',
679691
const=True, default=False,
680692
help='display differences between states')
693+
parser.add_argument('--dark', action='store_const', dest='dark',
694+
const=True, default=False,
695+
help='dark mode')
681696
args = parser.parse_args()
682697
logging.basicConfig(level=args.loglevel)
683698

@@ -688,7 +703,7 @@ def main():
688703
graph.add_raw_line(raw_line)
689704

690705
explorer = Explorer()
691-
visitor = DotDumpVisitor(args.diff)
706+
visitor = DotDumpVisitor(args.diff, args.dark)
692707
explorer.explore(graph, visitor)
693708

694709

0 commit comments

Comments
 (0)