diff options
author | Stephen Kelly <steveire@gmail.com> | 2019-01-11 19:11:17 +0000 |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2019-01-11 19:11:17 +0000 |
commit | 0df805db731fa1384c36f18a50b4ec35cbf368f4 (patch) | |
tree | ab903a3323209fd202018a1913f0f0c47f54334d /clang/include | |
parent | 27ba55914addfd55c9b6e5fa73aae51246424ef2 (diff) |
[ASTDump] Add utility for dumping a label with child nodes
Summary:
Use it to add optional label nodes to Stmt dumps. This preserves
behavior of InitExprList dump:
// CHECK-NEXT: `-InitListExpr {{.+}} <col:13, col:15> 'U [3]'
// CHECK-NEXT: |-array_filler: InitListExpr {{.+}} <col:15> 'U' field Field {{.+}} 'i' 'int'
// CHECK-NEXT: `-InitListExpr {{.+}} <col:14> 'U' field Field {{.+}} 'i' 'int'
// CHECK-NEXT: `-IntegerLiteral {{.+}} <col:14> 'int' 1
Reviewers: aaron.ballman
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D55488
llvm-svn: 350957
Diffstat (limited to 'clang/include')
-rw-r--r-- | clang/include/clang/AST/TextNodeDumper.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/include/clang/AST/TextNodeDumper.h b/clang/include/clang/AST/TextNodeDumper.h index 8b6fde938d2e..7948fdc696ea 100644 --- a/clang/include/clang/AST/TextNodeDumper.h +++ b/clang/include/clang/AST/TextNodeDumper.h @@ -41,6 +41,12 @@ class TextTreeStructure { public: /// Add a child of the current node. Calls DoAddChild without arguments template <typename Fn> void AddChild(Fn DoAddChild) { + return AddChild("", DoAddChild); + } + + /// Add a child of the current node with an optional label. + /// Calls DoAddChild without arguments. + template <typename Fn> void AddChild(StringRef Label, Fn DoAddChild) { // If we're at the top level, there's nothing interesting to do; just // run the dumper. if (TopLevel) { @@ -56,7 +62,10 @@ public: return; } - auto DumpWithIndent = [this, DoAddChild](bool IsLastChild) { + // We need to capture an owning-string in the lambda because the lambda + // is invoked in a deferred manner. + std::string LabelStr = Label; + auto DumpWithIndent = [this, DoAddChild, LabelStr](bool IsLastChild) { // Print out the appropriate tree structure and work out the prefix for // children of this node. For instance: // @@ -73,6 +82,9 @@ public: OS << '\n'; ColorScope Color(OS, ShowColors, IndentColor); OS << Prefix << (IsLastChild ? '`' : '|') << '-'; + if (!LabelStr.empty()) + OS << LabelStr << ": "; + this->Prefix.push_back(IsLastChild ? ' ' : '|'); this->Prefix.push_back(' '); } |