diff options
author | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
commit | 056abd2059c65a3e908193aeae16fad98017437c (patch) | |
tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /lib/AST/StmtDumper.cpp | |
parent | cc73504950eb7b5dff2dded9bedd67bc36d64641 (diff) | |
download | FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.zip FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.tar.gz |
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):
http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974
Diffstat (limited to 'lib/AST/StmtDumper.cpp')
-rw-r--r-- | lib/AST/StmtDumper.cpp | 115 |
1 files changed, 57 insertions, 58 deletions
diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp index 962e352..fbc990f 100644 --- a/lib/AST/StmtDumper.cpp +++ b/lib/AST/StmtDumper.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file implements the Stmt::dump/Stmt::print methods, which dump out the +// This file implements the Stmt::dump method, which dumps out the // AST in a form that exposes type details and other fields. // //===----------------------------------------------------------------------===// @@ -30,6 +30,7 @@ namespace { SourceManager *SM; raw_ostream &OS; unsigned IndentLevel; + bool IsFirstLine; /// MaxDepth - When doing a normal dump (not dumpAll) we only want to dump /// the first few levels of an AST. This keeps track of how many ast levels @@ -41,46 +42,64 @@ namespace { const char *LastLocFilename; unsigned LastLocLine; + class IndentScope { + StmtDumper &Dumper; + public: + IndentScope(StmtDumper &Dumper) : Dumper(Dumper) { + Dumper.indent(); + } + ~IndentScope() { + Dumper.unindent(); + } + }; + public: StmtDumper(SourceManager *sm, raw_ostream &os, unsigned maxDepth) - : SM(sm), OS(os), IndentLevel(0-1), MaxDepth(maxDepth) { + : SM(sm), OS(os), IndentLevel(0), IsFirstLine(true), MaxDepth(maxDepth) { LastLocFilename = ""; LastLocLine = ~0U; } + ~StmtDumper() { + OS << "\n"; + } + void DumpSubTree(Stmt *S) { // Prune the recursion if not using dump all. if (MaxDepth == 0) return; - ++IndentLevel; - if (S) { - if (DeclStmt* DS = dyn_cast<DeclStmt>(S)) - VisitDeclStmt(DS); - else { - Visit(S); - - // Print out children. - Stmt::child_range CI = S->children(); - if (CI) { - while (CI) { - OS << '\n'; - DumpSubTree(*CI++); - } - } - } - OS << ')'; - } else { - Indent(); + IndentScope Indent(*this); + + if (!S) { OS << "<<<NULL>>>"; + return; + } + + if (DeclStmt* DS = dyn_cast<DeclStmt>(S)) { + VisitDeclStmt(DS); + return; } - --IndentLevel; + + Visit(S); + for (Stmt::child_range CI = S->children(); CI; CI++) + DumpSubTree(*CI); } void DumpDeclarator(Decl *D); - void Indent() const { - for (int i = 0, e = IndentLevel; i < e; ++i) - OS << " "; + void indent() { + if (IsFirstLine) + IsFirstLine = false; + else + OS << "\n"; + OS.indent(IndentLevel * 2); + OS << "("; + IndentLevel++; + } + + void unindent() { + OS << ")"; + IndentLevel--; } void DumpType(QualType T) { @@ -96,9 +115,8 @@ namespace { } void DumpDeclRef(Decl *node); void DumpStmt(const Stmt *Node) { - Indent(); - OS << "(" << Node->getStmtClassName() - << " " << (void*)Node; + OS << Node->getStmtClassName() + << " " << (const void*)Node; DumpSourceRange(Node); } void DumpValueKind(ExprValueKind K) { @@ -262,7 +280,7 @@ void StmtDumper::DumpDeclarator(Decl *D) { // If this is a vardecl with an initializer, emit it. if (VarDecl *V = dyn_cast<VarDecl>(VD)) { if (V->getInit()) { - OS << " =\n"; + OS << " ="; DumpSubTree(V->getInit()); } } @@ -294,9 +312,9 @@ void StmtDumper::DumpDeclarator(Decl *D) { } else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) { OS << "label " << *LD; } else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) { - OS << "\"static_assert(\n"; + OS << "\"static_assert("; DumpSubTree(SAD->getAssertExpr()); - OS << ",\n"; + OS << ","; DumpSubTree(SAD->getMessage()); OS << ");\""; } else { @@ -306,17 +324,12 @@ void StmtDumper::DumpDeclarator(Decl *D) { void StmtDumper::VisitDeclStmt(DeclStmt *Node) { DumpStmt(Node); - OS << "\n"; for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end(); DI != DE; ++DI) { + IndentScope Indent(*this); Decl* D = *DI; - ++IndentLevel; - Indent(); OS << (void*) D << " "; DumpDeclarator(D); - if (DI+1 != DE) - OS << "\n"; - --IndentLevel; } } @@ -503,35 +516,29 @@ void StmtDumper::VisitBlockExpr(BlockExpr *Node) { BlockDecl *block = Node->getBlockDecl(); OS << " decl=" << block; - IndentLevel++; if (block->capturesCXXThis()) { - OS << '\n'; Indent(); OS << "(capture this)"; + IndentScope Indent(*this); + OS << "capture this"; } for (BlockDecl::capture_iterator i = block->capture_begin(), e = block->capture_end(); i != e; ++i) { - OS << '\n'; - Indent(); - OS << "(capture "; + IndentScope Indent(*this); + OS << "capture "; if (i->isByRef()) OS << "byref "; if (i->isNested()) OS << "nested "; if (i->getVariable()) DumpDeclRef(i->getVariable()); if (i->hasCopyExpr()) DumpSubTree(i->getCopyExpr()); - OS << ")"; } - IndentLevel--; - OS << '\n'; DumpSubTree(block->getBody()); } void StmtDumper::VisitOpaqueValueExpr(OpaqueValueExpr *Node) { DumpExpr(Node); - if (Expr *Source = Node->getSourceExpr()) { - OS << '\n'; + if (Expr *Source = Node->getSourceExpr()) DumpSubTree(Source); - } } // GNU extensions. @@ -589,15 +596,11 @@ void StmtDumper::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) { void StmtDumper::VisitExprWithCleanups(ExprWithCleanups *Node) { DumpExpr(Node); - ++IndentLevel; for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) { - OS << "\n"; - Indent(); - OS << "(cleanup "; + IndentScope Indent(*this); + OS << "cleanup "; DumpDeclRef(Node->getObject(i)); - OS << ")"; } - --IndentLevel; } void StmtDumper::DumpCXXTemporary(CXXTemporary *Temporary) { @@ -734,7 +737,6 @@ void Stmt::dump(SourceManager &SM) const { void Stmt::dump(raw_ostream &OS, SourceManager &SM) const { StmtDumper P(&SM, OS, 4); P.DumpSubTree(const_cast<Stmt*>(this)); - OS << "\n"; } /// dump - This does a local dump of the specified AST fragment. It dumps the @@ -743,19 +745,16 @@ void Stmt::dump(raw_ostream &OS, SourceManager &SM) const { void Stmt::dump() const { StmtDumper P(0, llvm::errs(), 4); P.DumpSubTree(const_cast<Stmt*>(this)); - llvm::errs() << "\n"; } /// dumpAll - This does a dump of the specified AST fragment and all subtrees. void Stmt::dumpAll(SourceManager &SM) const { StmtDumper P(&SM, llvm::errs(), ~0U); P.DumpSubTree(const_cast<Stmt*>(this)); - llvm::errs() << "\n"; } /// dumpAll - This does a dump of the specified AST fragment and all subtrees. void Stmt::dumpAll() const { StmtDumper P(0, llvm::errs(), ~0U); P.DumpSubTree(const_cast<Stmt*>(this)); - llvm::errs() << "\n"; } |