[PATCH] D55488: Add utility for dumping a label with child nodes
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 9 05:29:27 PST 2018
steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added a subscriber: cfe-commits.
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
// CHECK-NEXT: | `-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
Repository:
rC Clang
https://reviews.llvm.org/D55488
Files:
include/clang/AST/ASTDumperUtils.h
lib/AST/ASTDumper.cpp
Index: lib/AST/ASTDumper.cpp
===================================================================
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -63,6 +63,9 @@
template<typename Fn> void dumpChild(Fn doDumpChild) {
TreeStructure.addChild(doDumpChild);
}
+ template <typename Fn> void dumpChild(const char *label, Fn doDumpChild) {
+ TreeStructure.addChild(label, doDumpChild);
+ }
public:
ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
@@ -83,7 +86,7 @@
void setDeserialize(bool D) { Deserialize = D; }
void dumpDecl(const Decl *D);
- void dumpStmt(const Stmt *S);
+ void dumpStmt(const Stmt *S, const char *label = nullptr);
// Utilities
void dumpType(QualType T) { NodeDumper.dumpType(T); }
@@ -1711,8 +1714,8 @@
// Stmt dumping methods.
//===----------------------------------------------------------------------===//
-void ASTDumper::dumpStmt(const Stmt *S) {
- dumpChild([=] {
+void ASTDumper::dumpStmt(const Stmt *S, const char *label) {
+ dumpChild(label, [=] {
if (!S) {
ColorScope Color(OS, ShowColors, NullColor);
OS << "<<<NULL>>>";
@@ -1978,10 +1981,7 @@
NodeDumper.dumpBareDeclRef(Field);
}
if (auto *Filler = ILE->getArrayFiller()) {
- dumpChild([=] {
- OS << "array filler";
- dumpStmt(Filler);
- });
+ dumpStmt(Filler, "array filler");
}
}
Index: include/clang/AST/ASTDumperUtils.h
===================================================================
--- include/clang/AST/ASTDumperUtils.h
+++ include/clang/AST/ASTDumperUtils.h
@@ -109,6 +109,16 @@
std::string Prefix;
public:
+ /// Add a child of the current node with a label.
+ /// Calls doAddChild without arguments
+ template <typename Fn> void addChild(const char *label, Fn doAddChild) {
+ if (!label)
+ return addChild(doAddChild);
+ addChild([=] {
+ OS << label;
+ addChild(doAddChild);
+ });
+ }
/// Add a child of the current node. Calls doAddChild without arguments
template <typename Fn> void addChild(Fn doAddChild) {
// If we're at the top level, there's nothing interesting to do; just
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55488.177413.patch
Type: text/x-patch
Size: 2160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181209/6cea8d57/attachment.bin>
More information about the cfe-commits
mailing list