freebsd-skq/lib/AST/StmtDumper.cpp

594 lines
18 KiB
C++
Raw Normal View History

2009-06-02 17:58:47 +00:00
//===--- StmtDumper.cpp - Dumping implementation for Stmt ASTs ------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the Stmt::dump/Stmt::print methods, which dump out the
// AST in a form that exposes type details and other fields.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/Basic/SourceManager.h"
2009-12-15 18:49:47 +00:00
#include "llvm/Support/raw_ostream.h"
2009-06-02 17:58:47 +00:00
using namespace clang;
//===----------------------------------------------------------------------===//
// StmtDumper Visitor
//===----------------------------------------------------------------------===//
namespace {
2009-12-01 11:08:04 +00:00
class StmtDumper : public StmtVisitor<StmtDumper> {
2009-06-02 17:58:47 +00:00
SourceManager *SM;
2009-12-15 18:49:47 +00:00
llvm::raw_ostream &OS;
2009-06-02 17:58:47 +00:00
unsigned IndentLevel;
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
/// 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
/// are left.
unsigned MaxDepth;
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
/// LastLocFilename/LastLocLine - Keep track of the last location we print
/// out so that we can print out deltas from then on out.
const char *LastLocFilename;
unsigned LastLocLine;
public:
2009-12-15 18:49:47 +00:00
StmtDumper(SourceManager *sm, llvm::raw_ostream &os, unsigned maxDepth)
: SM(sm), OS(os), IndentLevel(0-1), MaxDepth(maxDepth) {
2009-06-02 17:58:47 +00:00
LastLocFilename = "";
LastLocLine = ~0U;
}
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
void DumpSubTree(Stmt *S) {
// Prune the recursion if not using dump all.
if (MaxDepth == 0) return;
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
++IndentLevel;
if (S) {
if (DeclStmt* DS = dyn_cast<DeclStmt>(S))
VisitDeclStmt(DS);
2009-10-14 18:03:49 +00:00
else {
2009-06-02 17:58:47 +00:00
Visit(S);
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
// Print out children.
Stmt::child_iterator CI = S->child_begin(), CE = S->child_end();
if (CI != CE) {
while (CI != CE) {
2009-12-15 18:49:47 +00:00
OS << '\n';
2009-06-02 17:58:47 +00:00
DumpSubTree(*CI++);
}
}
2009-12-15 18:49:47 +00:00
OS << ')';
2009-06-02 17:58:47 +00:00
}
} else {
Indent();
2009-12-15 18:49:47 +00:00
OS << "<<<NULL>>>";
2009-06-02 17:58:47 +00:00
}
--IndentLevel;
}
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
void DumpDeclarator(Decl *D);
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
void Indent() const {
for (int i = 0, e = IndentLevel; i < e; ++i)
2009-12-15 18:49:47 +00:00
OS << " ";
2009-06-02 17:58:47 +00:00
}
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
void DumpType(QualType T) {
2009-12-15 18:49:47 +00:00
OS << "'" << T.getAsString() << "'";
2009-06-02 17:58:47 +00:00
if (!T.isNull()) {
2009-10-14 18:03:49 +00:00
// If the type is sugared, also dump a (shallow) desugared type.
QualType Simplified = T.getDesugaredType();
if (Simplified != T)
2009-12-15 18:49:47 +00:00
OS << ":'" << Simplified.getAsString() << "'";
2009-06-02 17:58:47 +00:00
}
}
void DumpStmt(const Stmt *Node) {
Indent();
2009-12-15 18:49:47 +00:00
OS << "(" << Node->getStmtClassName()
<< " " << (void*)Node;
2009-06-02 17:58:47 +00:00
DumpSourceRange(Node);
}
void DumpExpr(const Expr *Node) {
DumpStmt(Node);
2009-12-15 18:49:47 +00:00
OS << ' ';
2009-06-02 17:58:47 +00:00
DumpType(Node->getType());
}
void DumpSourceRange(const Stmt *Node);
void DumpLocation(SourceLocation Loc);
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
// Stmts.
void VisitStmt(Stmt *Node);
void VisitDeclStmt(DeclStmt *Node);
void VisitLabelStmt(LabelStmt *Node);
void VisitGotoStmt(GotoStmt *Node);
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
// Exprs
void VisitExpr(Expr *Node);
2009-10-14 18:03:49 +00:00
void VisitCastExpr(CastExpr *Node);
2009-11-18 14:59:57 +00:00
void VisitImplicitCastExpr(ImplicitCastExpr *Node);
2009-06-02 17:58:47 +00:00
void VisitDeclRefExpr(DeclRefExpr *Node);
void VisitPredefinedExpr(PredefinedExpr *Node);
void VisitCharacterLiteral(CharacterLiteral *Node);
void VisitIntegerLiteral(IntegerLiteral *Node);
void VisitFloatingLiteral(FloatingLiteral *Node);
void VisitStringLiteral(StringLiteral *Str);
void VisitUnaryOperator(UnaryOperator *Node);
void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node);
void VisitMemberExpr(MemberExpr *Node);
void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
void VisitBinaryOperator(BinaryOperator *Node);
void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
void VisitAddrLabelExpr(AddrLabelExpr *Node);
void VisitTypesCompatibleExpr(TypesCompatibleExpr *Node);
// C++
void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
void VisitCXXThisExpr(CXXThisExpr *Node);
void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
2009-10-14 18:03:49 +00:00
void VisitCXXConstructExpr(CXXConstructExpr *Node);
void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node);
void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *Node);
2009-12-15 18:49:47 +00:00
void VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node);
2009-10-14 18:03:49 +00:00
void DumpCXXTemporary(CXXTemporary *Temporary);
2009-06-02 17:58:47 +00:00
// ObjC
void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
void VisitObjCMessageExpr(ObjCMessageExpr* Node);
void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
2009-10-14 18:03:49 +00:00
void VisitObjCImplicitSetterGetterRefExpr(
ObjCImplicitSetterGetterRefExpr *Node);
2009-06-02 17:58:47 +00:00
void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
void VisitObjCSuperExpr(ObjCSuperExpr *Node);
};
}
//===----------------------------------------------------------------------===//
// Utilities
//===----------------------------------------------------------------------===//
void StmtDumper::DumpLocation(SourceLocation Loc) {
SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
if (SpellingLoc.isInvalid()) {
2009-12-15 18:49:47 +00:00
OS << "<invalid sloc>";
2009-06-02 17:58:47 +00:00
return;
}
// The general format we print out is filename:line:col, but we drop pieces
// that haven't changed since the last loc printed.
PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
2009-12-15 18:49:47 +00:00
OS << PLoc.getFilename() << ':' << PLoc.getLine()
<< ':' << PLoc.getColumn();
2009-06-02 17:58:47 +00:00
LastLocFilename = PLoc.getFilename();
LastLocLine = PLoc.getLine();
} else if (PLoc.getLine() != LastLocLine) {
2009-12-15 18:49:47 +00:00
OS << "line" << ':' << PLoc.getLine()
<< ':' << PLoc.getColumn();
2009-06-02 17:58:47 +00:00
LastLocLine = PLoc.getLine();
} else {
2009-12-15 18:49:47 +00:00
OS << "col" << ':' << PLoc.getColumn();
2009-06-02 17:58:47 +00:00
}
}
void StmtDumper::DumpSourceRange(const Stmt *Node) {
// Can't translate locations if a SourceManager isn't available.
if (SM == 0) return;
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
// TODO: If the parent expression is available, we can print a delta vs its
// location.
SourceRange R = Node->getSourceRange();
2009-10-14 18:03:49 +00:00
2009-12-15 18:49:47 +00:00
OS << " <";
2009-06-02 17:58:47 +00:00
DumpLocation(R.getBegin());
if (R.getBegin() != R.getEnd()) {
2009-12-15 18:49:47 +00:00
OS << ", ";
2009-06-02 17:58:47 +00:00
DumpLocation(R.getEnd());
}
2009-12-15 18:49:47 +00:00
OS << ">";
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
// <t2.c:123:421[blah], t2.c:412:321>
}
//===----------------------------------------------------------------------===//
// Stmt printing methods.
//===----------------------------------------------------------------------===//
void StmtDumper::VisitStmt(Stmt *Node) {
DumpStmt(Node);
}
void StmtDumper::DumpDeclarator(Decl *D) {
// FIXME: Need to complete/beautify this... this code simply shows the
// nodes are where they need to be.
if (TypedefDecl *localType = dyn_cast<TypedefDecl>(D)) {
2009-12-15 18:49:47 +00:00
OS << "\"typedef " << localType->getUnderlyingType().getAsString()
<< " " << localType->getNameAsString() << "\"";
2009-06-02 17:58:47 +00:00
} else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
2009-12-15 18:49:47 +00:00
OS << "\"";
2009-06-02 17:58:47 +00:00
// Emit storage class for vardecls.
if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
if (V->getStorageClass() != VarDecl::None)
2009-12-15 18:49:47 +00:00
OS << VarDecl::getStorageClassSpecifierString(V->getStorageClass())
<< " ";
2009-06-02 17:58:47 +00:00
}
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
std::string Name = VD->getNameAsString();
2009-10-14 18:03:49 +00:00
VD->getType().getAsStringInternal(Name,
2009-07-04 13:58:54 +00:00
PrintingPolicy(VD->getASTContext().getLangOptions()));
2009-12-15 18:49:47 +00:00
OS << Name;
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
// If this is a vardecl with an initializer, emit it.
if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
if (V->getInit()) {
2009-12-15 18:49:47 +00:00
OS << " =\n";
2009-06-02 17:58:47 +00:00
DumpSubTree(V->getInit());
}
}
2009-12-15 18:49:47 +00:00
OS << '"';
2009-06-02 17:58:47 +00:00
} else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
// print a free standing tag decl (e.g. "struct x;").
const char *tagname;
if (const IdentifierInfo *II = TD->getIdentifier())
2009-10-23 14:22:18 +00:00
tagname = II->getNameStart();
2009-06-02 17:58:47 +00:00
else
tagname = "<anonymous>";
2009-12-15 18:49:47 +00:00
OS << '"' << TD->getKindName() << ' ' << tagname << ";\"";
2009-06-02 17:58:47 +00:00
// FIXME: print tag bodies.
} else if (UsingDirectiveDecl *UD = dyn_cast<UsingDirectiveDecl>(D)) {
// print using-directive decl (e.g. "using namespace x;")
const char *ns;
if (const IdentifierInfo *II = UD->getNominatedNamespace()->getIdentifier())
2009-10-23 14:22:18 +00:00
ns = II->getNameStart();
2009-06-02 17:58:47 +00:00
else
ns = "<anonymous>";
2009-12-15 18:49:47 +00:00
OS << '"' << UD->getDeclKindName() << ns << ";\"";
2009-06-02 17:58:47 +00:00
} else {
assert(0 && "Unexpected decl");
}
}
void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
DumpStmt(Node);
2009-12-15 18:49:47 +00:00
OS << "\n";
2009-06-02 17:58:47 +00:00
for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end();
DI != DE; ++DI) {
Decl* D = *DI;
++IndentLevel;
Indent();
2009-12-15 18:49:47 +00:00
OS << (void*) D << " ";
2009-06-02 17:58:47 +00:00
DumpDeclarator(D);
if (DI+1 != DE)
2009-12-15 18:49:47 +00:00
OS << "\n";
2009-06-02 17:58:47 +00:00
--IndentLevel;
}
}
void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
DumpStmt(Node);
2009-12-15 18:49:47 +00:00
OS << " '" << Node->getName() << "'";
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
DumpStmt(Node);
2009-12-15 18:49:47 +00:00
OS << " '" << Node->getLabel()->getName()
<< "':" << (void*)Node->getLabel();
2009-06-02 17:58:47 +00:00
}
//===----------------------------------------------------------------------===//
// Expr printing methods.
//===----------------------------------------------------------------------===//
void StmtDumper::VisitExpr(Expr *Node) {
DumpExpr(Node);
}
2009-10-14 18:03:49 +00:00
void StmtDumper::VisitCastExpr(CastExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " <" << Node->getCastKindName() << ">";
2009-10-14 18:03:49 +00:00
}
2009-11-18 14:59:57 +00:00
void StmtDumper::VisitImplicitCastExpr(ImplicitCastExpr *Node) {
VisitCastExpr(Node);
if (Node->isLvalueCast())
2009-12-15 18:49:47 +00:00
OS << " lvalue";
2009-11-18 14:59:57 +00:00
}
2009-06-02 17:58:47 +00:00
void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " ";
2009-06-02 17:58:47 +00:00
switch (Node->getDecl()->getKind()) {
2009-12-15 18:49:47 +00:00
default: OS << "Decl"; break;
case Decl::Function: OS << "FunctionDecl"; break;
case Decl::Var: OS << "Var"; break;
case Decl::ParmVar: OS << "ParmVar"; break;
case Decl::EnumConstant: OS << "EnumConstant"; break;
case Decl::Typedef: OS << "Typedef"; break;
case Decl::Record: OS << "Record"; break;
case Decl::Enum: OS << "Enum"; break;
case Decl::CXXRecord: OS << "CXXRecord"; break;
case Decl::ObjCInterface: OS << "ObjCInterface"; break;
case Decl::ObjCClass: OS << "ObjCClass"; break;
2009-06-02 17:58:47 +00:00
}
2009-10-14 18:03:49 +00:00
2009-12-15 18:49:47 +00:00
OS << "='" << Node->getDecl()->getNameAsString()
<< "' " << (void*)Node->getDecl();
}
void StmtDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
DumpExpr(Node);
OS << " (";
if (!Node->requiresADL()) OS << "no ";
OS << "ADL) = '" << Node->getName().getAsString() << "'";
UnresolvedLookupExpr::decls_iterator
I = Node->decls_begin(), E = Node->decls_end();
if (I == E) OS << " empty";
for (; I != E; ++I)
OS << " " << (void*) *I;
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " " << Node->getDecl()->getDeclKindName()
<< "Decl='" << Node->getDecl()->getNameAsString()
<< "' " << (void*)Node->getDecl();
2009-06-02 17:58:47 +00:00
if (Node->isFreeIvar())
2009-12-15 18:49:47 +00:00
OS << " isFreeIvar";
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) {
DumpExpr(Node);
switch (Node->getIdentType()) {
default: assert(0 && "unknown case");
2009-12-15 18:49:47 +00:00
case PredefinedExpr::Func: OS << " __func__"; break;
case PredefinedExpr::Function: OS << " __FUNCTION__"; break;
case PredefinedExpr::PrettyFunction: OS << " __PRETTY_FUNCTION__";break;
2009-06-02 17:58:47 +00:00
}
}
void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << Node->getValue();
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
DumpExpr(Node);
bool isSigned = Node->getType()->isSignedIntegerType();
2009-12-15 18:49:47 +00:00
OS << " " << Node->getValue().toString(10, isSigned);
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " " << Node->getValueAsApproximateDouble();
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
DumpExpr(Str);
// FIXME: this doesn't print wstrings right.
2009-12-15 18:49:47 +00:00
OS << " ";
if (Str->isWide())
OS << "L";
OS << '"';
OS.write_escaped(llvm::StringRef(Str->getStrData(),
Str->getByteLength()));
OS << '"';
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
<< " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " " << (Node->isSizeOf() ? "sizeof" : "alignof") << " ";
2009-06-02 17:58:47 +00:00
if (Node->isArgumentType())
DumpType(Node->getArgumentType());
}
void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " " << (Node->isArrow() ? "->" : ".")
<< Node->getMemberDecl()->getNameAsString() << " "
<< (void*)Node->getMemberDecl();
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " " << Node->getAccessor().getNameStart();
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode())
<< "' ComputeLHSTy=";
2009-06-02 17:58:47 +00:00
DumpType(Node->getComputationLHSType());
2009-12-15 18:49:47 +00:00
OS << " ComputeResultTy=";
2009-06-02 17:58:47 +00:00
DumpType(Node->getComputationResultType());
}
// GNU extensions.
void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " " << Node->getLabel()->getName()
<< " " << (void*)Node->getLabel();
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " ";
2009-06-02 17:58:47 +00:00
DumpType(Node->getArgType1());
2009-12-15 18:49:47 +00:00
OS << " ";
2009-06-02 17:58:47 +00:00
DumpType(Node->getArgType2());
}
//===----------------------------------------------------------------------===//
// C++ Expressions
//===----------------------------------------------------------------------===//
void StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " " << Node->getCastName()
<< "<" << Node->getTypeAsWritten().getAsString() << ">"
<< " <" << Node->getCastKindName() << ">";
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " " << (Node->getValue() ? "true" : "false");
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " this";
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " functional cast to " << Node->getTypeAsWritten().getAsString();
2009-06-02 17:58:47 +00:00
}
2009-10-14 18:03:49 +00:00
void StmtDumper::VisitCXXConstructExpr(CXXConstructExpr *Node) {
DumpExpr(Node);
2010-02-16 09:31:36 +00:00
CXXConstructorDecl *Ctor = Node->getConstructor();
DumpType(Ctor->getType());
2009-10-14 18:03:49 +00:00
if (Node->isElidable())
2009-12-15 18:49:47 +00:00
OS << " elidable";
2009-10-14 18:03:49 +00:00
}
void StmtDumper::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " ";
2009-10-14 18:03:49 +00:00
DumpCXXTemporary(Node->getTemporary());
}
void StmtDumper::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *Node) {
DumpExpr(Node);
++IndentLevel;
for (unsigned i = 0, e = Node->getNumTemporaries(); i != e; ++i) {
2009-12-15 18:49:47 +00:00
OS << "\n";
2009-10-14 18:03:49 +00:00
Indent();
DumpCXXTemporary(Node->getTemporary(i));
}
--IndentLevel;
}
void StmtDumper::DumpCXXTemporary(CXXTemporary *Temporary) {
2009-12-15 18:49:47 +00:00
OS << "(CXXTemporary " << (void *)Temporary << ")";
2009-10-14 18:03:49 +00:00
}
2009-06-02 17:58:47 +00:00
//===----------------------------------------------------------------------===//
// Obj-C Expressions
//===----------------------------------------------------------------------===//
void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " selector=" << Node->getSelector().getAsString();
if (IdentifierInfo *clsName = Node->getClassName())
OS << " class=" << clsName->getNameStart();
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " ";
2009-06-02 17:58:47 +00:00
DumpType(Node->getEncodedType());
}
void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
DumpExpr(Node);
2009-10-14 18:03:49 +00:00
2009-12-15 18:49:47 +00:00
OS << " " << Node->getSelector().getAsString();
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
DumpExpr(Node);
2009-10-14 18:03:49 +00:00
2009-12-15 18:49:47 +00:00
OS << " " << Node->getProtocol()->getNameAsString();
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " Kind=PropertyRef Property=\""
<< Node->getProperty()->getNameAsString() << "\"";
2009-06-02 17:58:47 +00:00
}
2009-10-14 18:03:49 +00:00
void StmtDumper::VisitObjCImplicitSetterGetterRefExpr(
ObjCImplicitSetterGetterRefExpr *Node) {
2009-06-02 17:58:47 +00:00
DumpExpr(Node);
2009-10-14 18:03:49 +00:00
2009-06-02 17:58:47 +00:00
ObjCMethodDecl *Getter = Node->getGetterMethod();
ObjCMethodDecl *Setter = Node->getSetterMethod();
2009-12-15 18:49:47 +00:00
OS << " Kind=MethodRef Getter=\""
<< Getter->getSelector().getAsString()
<< "\" Setter=\"";
if (Setter)
OS << Setter->getSelector().getAsString();
else
OS << "(null)";
OS << "\"";
2009-06-02 17:58:47 +00:00
}
void StmtDumper::VisitObjCSuperExpr(ObjCSuperExpr *Node) {
DumpExpr(Node);
2009-12-15 18:49:47 +00:00
OS << " super";
2009-06-02 17:58:47 +00:00
}
//===----------------------------------------------------------------------===//
// Stmt method implementations
//===----------------------------------------------------------------------===//
/// dump - This does a local dump of the specified AST fragment. It dumps the
/// specified node and a few nodes underneath it, but not the whole subtree.
/// This is useful in a debugger.
void Stmt::dump(SourceManager &SM) const {
2009-12-15 18:49:47 +00:00
StmtDumper P(&SM, llvm::errs(), 4);
2009-06-02 17:58:47 +00:00
P.DumpSubTree(const_cast<Stmt*>(this));
2009-12-15 18:49:47 +00:00
llvm::errs() << "\n";
2009-06-02 17:58:47 +00:00
}
/// dump - This does a local dump of the specified AST fragment. It dumps the
/// specified node and a few nodes underneath it, but not the whole subtree.
/// This is useful in a debugger.
void Stmt::dump() const {
2009-12-15 18:49:47 +00:00
StmtDumper P(0, llvm::errs(), 4);
2009-06-02 17:58:47 +00:00
P.DumpSubTree(const_cast<Stmt*>(this));
2009-12-15 18:49:47 +00:00
llvm::errs() << "\n";
2009-06-02 17:58:47 +00:00
}
/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
void Stmt::dumpAll(SourceManager &SM) const {
2009-12-15 18:49:47 +00:00
StmtDumper P(&SM, llvm::errs(), ~0U);
2009-06-02 17:58:47 +00:00
P.DumpSubTree(const_cast<Stmt*>(this));
2009-12-15 18:49:47 +00:00
llvm::errs() << "\n";
2009-06-02 17:58:47 +00:00
}
/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
void Stmt::dumpAll() const {
2009-12-15 18:49:47 +00:00
StmtDumper P(0, llvm::errs(), ~0U);
2009-06-02 17:58:47 +00:00
P.DumpSubTree(const_cast<Stmt*>(this));
2009-12-15 18:49:47 +00:00
llvm::errs() << "\n";
2009-06-02 17:58:47 +00:00
}