r364990 - [analyzer] exploded-graph-rewriter: Collapse very long statement pretty-prints.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 2 18:26:35 PDT 2019


Author: dergachev
Date: Tue Jul  2 18:26:35 2019
New Revision: 364990

URL: http://llvm.org/viewvc/llvm-project?rev=364990&view=rev
Log:
[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

Modified:
    cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot
    cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot?rev=364990&r1=364989&r2=364990&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot Tue Jul  2 18:26:35 2019
@@ -90,3 +90,27 @@ Node0x2 [shape=record,label=
       }
     ]}
 \l}"];
+
+// Test collapsing large pretty prints with braces.
+
+// CHECK-NEXT: <b>Program point:</b>
+// CHECK-SAME: <td>\{ ... \}</td>
+Node0x3 [shape=record,label=
+ "{
+    { "node_id": 3, "pointer": "0x3",
+      "program_state": null, "program_points": [
+      {
+        "kind": "Statement",
+        "stmt_kind": "CompoundStmt",
+        "stmt_point_kind": "PostStmt",
+        "stmd_id": 6,
+        "pointer": "0x6",
+        "pretty": "{ very very very very very very long pretty print }",
+        "location": {
+          "line": 7,
+          "column": 8
+        },
+        "tag": "ExprEngine : Clean Node"
+      }
+    ]}
+\l}"];

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=364990&r1=364989&r2=364990&view=diff
==============================================================================
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py (original)
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py Tue Jul  2 18:26:35 2019
@@ -398,6 +398,21 @@ class DotDumpVisitor(object):
             return '<font color="forestgreen">+</font>'
         return '<font color="red">-</font>'
 
+    @staticmethod
+    def _short_pretty(s):
+        if s is None:
+            return None
+        if len(s) < 20:
+            return s
+        left = s.find('{')
+        right = s.rfind('}')
+        if left == -1 or right == -1 or left >= right:
+            return s
+        candidate = s[0:left + 1] + ' ... ' + s[right:]
+        if len(candidate) >= len(s):
+            return s
+        return candidate
+
     def visit_begin_graph(self, graph):
         self._graph = graph
         self._dump_raw('digraph "ExplodedGraph" {\n')
@@ -433,7 +448,8 @@ class DotDumpVisitor(object):
                            % (p.loc.filename, p.loc.line,
                               p.loc.col, color, p.stmt_kind,
                               stmt_color, p.stmt_point_kind,
-                              p.pretty if not skip_pretty else ''))
+                              self._short_pretty(p.pretty)
+                              if not skip_pretty else ''))
             else:
                 self._dump('<tr><td align="left" width="0">'
                            '<i>Invalid Source Location</i>:</td>'
@@ -443,7 +459,8 @@ class DotDumpVisitor(object):
                            '<td>%s</td></tr>'
                            % (color, p.stmt_kind,
                               stmt_color, p.stmt_point_kind,
-                              p.pretty if not skip_pretty else ''))
+                              self._short_pretty(p.pretty)
+                              if not skip_pretty else ''))
         elif p.kind == 'Edge':
             self._dump('<tr><td width="0"></td>'
                        '<td align="left" width="0">'
@@ -496,7 +513,7 @@ class DotDumpVisitor(object):
                               'lavender' if self._dark_mode else 'darkgreen',
                               ('(%s)' % b.kind) if b.kind is not None else ' '
                           ),
-                          b.pretty, f.bindings[b]))
+                          self._short_pretty(b.pretty), f.bindings[b]))
 
         frames_updated = e.diff_frames(prev_e) if prev_e is not None else None
         if frames_updated:




More information about the cfe-commits mailing list