Skip to content

Commit 48a5c83

Browse files
committed
[analyzer] exploded-graph-rewriter: Collapse very long statement pretty-prints.
When printing various statements that include braces (compound statements, lambda expressions, statement-expressions, etc.), replace the code between braces with '...'. Differential Revision: https://reviews.llvm.org/D64104 llvm-svn: 364990
1 parent deb7acc commit 48a5c83

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,27 @@ Node0x2 [shape=record,label=
9090
}
9191
]}
9292
\l}"];
93+
94+
// Test collapsing large pretty prints with braces.
95+
96+
// CHECK-NEXT: <b>Program point:</b>
97+
// CHECK-SAME: <td>\{ ... \}</td>
98+
Node0x3 [shape=record,label=
99+
"{
100+
{ "node_id": 3, "pointer": "0x3",
101+
"program_state": null, "program_points": [
102+
{
103+
"kind": "Statement",
104+
"stmt_kind": "CompoundStmt",
105+
"stmt_point_kind": "PostStmt",
106+
"stmd_id": 6,
107+
"pointer": "0x6",
108+
"pretty": "{ very very very very very very long pretty print }",
109+
"location": {
110+
"line": 7,
111+
"column": 8
112+
},
113+
"tag": "ExprEngine : Clean Node"
114+
}
115+
]}
116+
\l}"];

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,21 @@ def _diff_plus_minus(is_added):
398398
return '<font color="forestgreen">+</font>'
399399
return '<font color="red">-</font>'
400400

401+
@staticmethod
402+
def _short_pretty(s):
403+
if s is None:
404+
return None
405+
if len(s) < 20:
406+
return s
407+
left = s.find('{')
408+
right = s.rfind('}')
409+
if left == -1 or right == -1 or left >= right:
410+
return s
411+
candidate = s[0:left + 1] + ' ... ' + s[right:]
412+
if len(candidate) >= len(s):
413+
return s
414+
return candidate
415+
401416
def visit_begin_graph(self, graph):
402417
self._graph = graph
403418
self._dump_raw('digraph "ExplodedGraph" {\n')
@@ -433,7 +448,8 @@ def visit_program_point(self, p):
433448
% (p.loc.filename, p.loc.line,
434449
p.loc.col, color, p.stmt_kind,
435450
stmt_color, p.stmt_point_kind,
436-
p.pretty if not skip_pretty else ''))
451+
self._short_pretty(p.pretty)
452+
if not skip_pretty else ''))
437453
else:
438454
self._dump('<tr><td align="left" width="0">'
439455
'<i>Invalid Source Location</i>:</td>'
@@ -443,7 +459,8 @@ def visit_program_point(self, p):
443459
'<td>%s</td></tr>'
444460
% (color, p.stmt_kind,
445461
stmt_color, p.stmt_point_kind,
446-
p.pretty if not skip_pretty else ''))
462+
self._short_pretty(p.pretty)
463+
if not skip_pretty else ''))
447464
elif p.kind == 'Edge':
448465
self._dump('<tr><td width="0"></td>'
449466
'<td align="left" width="0">'
@@ -496,7 +513,7 @@ def dump_binding(f, b, is_added=None):
496513
'lavender' if self._dark_mode else 'darkgreen',
497514
('(%s)' % b.kind) if b.kind is not None else ' '
498515
),
499-
b.pretty, f.bindings[b]))
516+
self._short_pretty(b.pretty), f.bindings[b]))
500517

501518
frames_updated = e.diff_frames(prev_e) if prev_e is not None else None
502519
if frames_updated:

0 commit comments

Comments
 (0)