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.
|
2011-02-20 13:06:31 +00:00
|
|
|
Stmt::child_range CI = S->children();
|
|
|
|
if (CI) {
|
|
|
|
while (CI) {
|
2009-12-15 18:49:47 +00:00
|
|
|
OS << '\n';
|
2009-06-02 17:58:47 +00:00
|
|
|
DumpSubTree(*CI++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-27 15:17:06 +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) {
|
2011-02-20 13:06:31 +00:00
|
|
|
SplitQualType T_split = T.split();
|
|
|
|
OS << "'" << QualType::getAsString(T_split) << "'";
|
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.
|
2011-02-20 13:06:31 +00:00
|
|
|
SplitQualType D_split = T.getSplitDesugaredType();
|
|
|
|
if (T_split != D_split)
|
|
|
|
OS << ":'" << QualType::getAsString(D_split) << "'";
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-20 13:06:31 +00:00
|
|
|
void DumpDeclRef(Decl *node);
|
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);
|
|
|
|
}
|
2011-02-20 13:06:31 +00:00
|
|
|
void DumpValueKind(ExprValueKind K) {
|
|
|
|
switch (K) {
|
|
|
|
case VK_RValue: break;
|
|
|
|
case VK_LValue: OS << " lvalue"; break;
|
|
|
|
case VK_XValue: OS << " xvalue"; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void DumpObjectKind(ExprObjectKind K) {
|
|
|
|
switch (K) {
|
|
|
|
case OK_Ordinary: break;
|
|
|
|
case OK_BitField: OS << " bitfield"; break;
|
|
|
|
case OK_ObjCProperty: OS << " objcproperty"; break;
|
|
|
|
case OK_VectorComponent: OS << " vectorcomponent"; break;
|
|
|
|
}
|
|
|
|
}
|
2009-06-02 17:58:47 +00:00
|
|
|
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());
|
2011-02-20 13:06:31 +00:00
|
|
|
DumpValueKind(Node->getValueKind());
|
|
|
|
DumpObjectKind(Node->getObjectKind());
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
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-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);
|
2011-05-02 19:39:53 +00:00
|
|
|
void VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node);
|
2009-06-02 17:58:47 +00:00
|
|
|
void VisitMemberExpr(MemberExpr *Node);
|
|
|
|
void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
|
|
|
|
void VisitBinaryOperator(BinaryOperator *Node);
|
|
|
|
void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
|
|
|
|
void VisitAddrLabelExpr(AddrLabelExpr *Node);
|
2011-02-20 13:06:31 +00:00
|
|
|
void VisitBlockExpr(BlockExpr *Node);
|
2009-06-02 17:58:47 +00:00
|
|
|
|
|
|
|
// 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);
|
2011-02-20 13:06:31 +00:00
|
|
|
void VisitExprWithCleanups(ExprWithCleanups *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
|
2010-05-04 16:12:48 +00:00
|
|
|
void VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node);
|
2009-06-02 17:58:47 +00:00
|
|
|
void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
|
|
|
|
void VisitObjCMessageExpr(ObjCMessageExpr* Node);
|
|
|
|
void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
|
|
|
|
void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
|
|
|
|
void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
|
|
|
|
void VisitObjCIvarRefExpr(ObjCIvarRefExpr *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
|
|
|
// 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);
|
|
|
|
|
2011-02-20 13:06:31 +00:00
|
|
|
if (PLoc.isInvalid()) {
|
|
|
|
OS << "<invalid sloc>";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
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()
|
2010-05-04 16:12:48 +00:00
|
|
|
<< ' ' << localType << '"';
|
2011-05-02 19:39:53 +00:00
|
|
|
} else if (TypeAliasDecl *localType = dyn_cast<TypeAliasDecl>(D)) {
|
|
|
|
OS << "\"using " << localType << " = "
|
|
|
|
<< localType->getUnderlyingType().getAsString() << '"';
|
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)) {
|
2010-09-17 15:54:40 +00:00
|
|
|
if (V->getStorageClass() != SC_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 << ";\"";
|
2010-05-04 20:51:19 +00:00
|
|
|
} else if (UsingDecl *UD = dyn_cast<UsingDecl>(D)) {
|
|
|
|
// print using decl (e.g. "using std::string;")
|
|
|
|
const char *tn = UD->isTypeName() ? "typename " : "";
|
|
|
|
OS << '"' << UD->getDeclKindName() << tn;
|
2011-02-26 22:09:03 +00:00
|
|
|
UD->getQualifier()->print(OS,
|
|
|
|
PrintingPolicy(UD->getASTContext().getLangOptions()));
|
2010-05-04 20:51:19 +00:00
|
|
|
OS << ";\"";
|
2011-02-20 13:06:31 +00:00
|
|
|
} else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) {
|
|
|
|
OS << "label " << LD->getNameAsString();
|
2011-05-02 19:39:53 +00:00
|
|
|
} else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) {
|
|
|
|
OS << "\"static_assert(\n";
|
|
|
|
DumpSubTree(SAD->getAssertExpr());
|
|
|
|
OS << ",\n";
|
|
|
|
DumpSubTree(SAD->getMessage());
|
|
|
|
OS << ");\"";
|
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);
|
|
|
|
}
|
|
|
|
|
2010-05-04 16:12:48 +00:00
|
|
|
static void DumpBasePath(llvm::raw_ostream &OS, CastExpr *Node) {
|
2010-09-17 15:54:40 +00:00
|
|
|
if (Node->path_empty())
|
2010-05-04 16:12:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
OS << " (";
|
|
|
|
bool First = true;
|
2010-09-17 15:54:40 +00:00
|
|
|
for (CastExpr::path_iterator
|
|
|
|
I = Node->path_begin(), E = Node->path_end(); I != E; ++I) {
|
2010-05-04 16:12:48 +00:00
|
|
|
const CXXBaseSpecifier *Base = *I;
|
|
|
|
if (!First)
|
|
|
|
OS << " -> ";
|
|
|
|
|
|
|
|
const CXXRecordDecl *RD =
|
|
|
|
cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
|
|
|
|
|
|
|
|
if (Base->isVirtual())
|
|
|
|
OS << "virtual ";
|
|
|
|
OS << RD->getName();
|
|
|
|
First = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << ')';
|
|
|
|
}
|
|
|
|
|
2009-10-14 18:03:49 +00:00
|
|
|
void StmtDumper::VisitCastExpr(CastExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
2010-05-04 16:12:48 +00:00
|
|
|
OS << " <" << Node->getCastKindName();
|
|
|
|
DumpBasePath(OS, Node);
|
|
|
|
OS << ">";
|
2009-10-14 18:03:49 +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 << " ";
|
2011-02-20 13:06:31 +00:00
|
|
|
DumpDeclRef(Node->getDecl());
|
2011-05-02 19:39:53 +00:00
|
|
|
if (Node->getDecl() != Node->getFoundDecl()) {
|
|
|
|
OS << " (";
|
|
|
|
DumpDeclRef(Node->getFoundDecl());
|
|
|
|
OS << ")";
|
|
|
|
}
|
2011-02-20 13:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::DumpDeclRef(Decl *d) {
|
|
|
|
OS << d->getDeclKindName() << ' ' << (void*) d;
|
|
|
|
|
|
|
|
if (NamedDecl *nd = dyn_cast<NamedDecl>(d)) {
|
|
|
|
OS << " '";
|
|
|
|
nd->getDeclName().printName(OS);
|
|
|
|
OS << "'";
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
2009-10-14 18:03:49 +00:00
|
|
|
|
2011-02-20 13:06:31 +00:00
|
|
|
if (ValueDecl *vd = dyn_cast<ValueDecl>(d)) {
|
|
|
|
OS << ' '; DumpType(vd->getType());
|
|
|
|
}
|
2009-12-15 18:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
OS << " (";
|
|
|
|
if (!Node->requiresADL()) OS << "no ";
|
2010-05-04 16:12:48 +00:00
|
|
|
OS << "ADL) = '" << Node->getName() << '\'';
|
2009-12-15 18:49:47 +00:00
|
|
|
|
|
|
|
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()
|
2010-05-04 16:12:48 +00:00
|
|
|
<< "Decl='" << Node->getDecl()
|
2009-12-15 18:49:47 +00:00
|
|
|
<< "' " << (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 << '"';
|
2010-09-17 15:54:40 +00:00
|
|
|
OS.write_escaped(Str->getString());
|
2009-12-15 18:49:47 +00:00
|
|
|
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
|
|
|
}
|
2011-05-02 19:39:53 +00:00
|
|
|
void StmtDumper::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *Node) {
|
2009-06-02 17:58:47 +00:00
|
|
|
DumpExpr(Node);
|
2011-05-02 19:39:53 +00:00
|
|
|
switch(Node->getKind()) {
|
|
|
|
case UETT_SizeOf:
|
|
|
|
OS << " sizeof ";
|
|
|
|
break;
|
|
|
|
case UETT_AlignOf:
|
|
|
|
OS << " __alignof ";
|
|
|
|
break;
|
|
|
|
case UETT_VecStep:
|
|
|
|
OS << " vec_step ";
|
|
|
|
break;
|
|
|
|
}
|
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() ? "->" : ".")
|
2010-05-04 16:12:48 +00:00
|
|
|
<< Node->getMemberDecl() << ' '
|
2009-12-15 18:49:47 +00:00
|
|
|
<< (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());
|
|
|
|
}
|
|
|
|
|
2011-02-20 13:06:31 +00:00
|
|
|
void StmtDumper::VisitBlockExpr(BlockExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
|
|
|
|
IndentLevel++;
|
|
|
|
BlockDecl *block = Node->getBlockDecl();
|
|
|
|
if (block->capturesCXXThis()) {
|
|
|
|
OS << '\n'; Indent(); OS << "(capture this)";
|
|
|
|
}
|
|
|
|
for (BlockDecl::capture_iterator
|
|
|
|
i = block->capture_begin(), e = block->capture_end(); i != e; ++i) {
|
|
|
|
OS << '\n';
|
|
|
|
Indent();
|
|
|
|
OS << "(capture ";
|
|
|
|
if (i->isByRef()) OS << "byref ";
|
|
|
|
if (i->isNested()) OS << "nested ";
|
|
|
|
DumpDeclRef(i->getVariable());
|
|
|
|
if (i->hasCopyExpr()) DumpSubTree(i->getCopyExpr());
|
|
|
|
OS << ")";
|
|
|
|
}
|
|
|
|
IndentLevel--;
|
|
|
|
|
|
|
|
DumpSubTree(block->getBody());
|
|
|
|
}
|
|
|
|
|
2009-06-02 17:58:47 +00:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// C++ Expressions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
2009-12-15 18:49:47 +00:00
|
|
|
OS << " " << Node->getCastName()
|
|
|
|
<< "<" << Node->getTypeAsWritten().getAsString() << ">"
|
2010-05-04 16:12:48 +00:00
|
|
|
<< " <" << Node->getCastKindName();
|
|
|
|
DumpBasePath(OS, Node);
|
|
|
|
OS << ">";
|
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";
|
2010-09-17 15:54:40 +00:00
|
|
|
if (Node->requiresZeroInitialization())
|
|
|
|
OS << " zeroing";
|
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());
|
|
|
|
}
|
|
|
|
|
2011-02-20 13:06:31 +00:00
|
|
|
void StmtDumper::VisitExprWithCleanups(ExprWithCleanups *Node) {
|
2009-10-14 18:03:49 +00:00
|
|
|
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();
|
2010-05-04 16:12:48 +00:00
|
|
|
switch (Node->getReceiverKind()) {
|
|
|
|
case ObjCMessageExpr::Instance:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ObjCMessageExpr::Class:
|
|
|
|
OS << " class=";
|
|
|
|
DumpType(Node->getClassReceiver());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ObjCMessageExpr::SuperInstance:
|
|
|
|
OS << " super (instance)";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ObjCMessageExpr::SuperClass:
|
|
|
|
OS << " super (class)";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::VisitObjCAtCatchStmt(ObjCAtCatchStmt *Node) {
|
|
|
|
DumpStmt(Node);
|
|
|
|
if (VarDecl *CatchParam = Node->getCatchParamDecl()) {
|
|
|
|
OS << " catch parm = ";
|
|
|
|
DumpDeclarator(CatchParam);
|
|
|
|
} else {
|
|
|
|
OS << " catch all";
|
|
|
|
}
|
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
|
|
|
|
2010-05-04 16:12:48 +00:00
|
|
|
OS << ' ' << Node->getProtocol();
|
2009-06-02 17:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
2011-02-20 13:06:31 +00:00
|
|
|
if (Node->isImplicitProperty()) {
|
|
|
|
OS << " Kind=MethodRef Getter=\"";
|
|
|
|
if (Node->getImplicitPropertyGetter())
|
|
|
|
OS << Node->getImplicitPropertyGetter()->getSelector().getAsString();
|
|
|
|
else
|
|
|
|
OS << "(null)";
|
2009-06-02 17:58:47 +00:00
|
|
|
|
2011-02-20 13:06:31 +00:00
|
|
|
OS << "\" Setter=\"";
|
|
|
|
if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter())
|
|
|
|
OS << Setter->getSelector().getAsString();
|
|
|
|
else
|
|
|
|
OS << "(null)";
|
|
|
|
OS << "\"";
|
|
|
|
} else {
|
|
|
|
OS << " Kind=PropertyRef Property=\"" << Node->getExplicitProperty() << '"';
|
|
|
|
}
|
2009-06-02 17:58:47 +00:00
|
|
|
|
2011-02-20 13:06:31 +00:00
|
|
|
if (Node->isSuperReceiver())
|
|
|
|
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 {
|
2010-09-17 15:54:40 +00:00
|
|
|
dump(llvm::errs(), SM);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stmt::dump(llvm::raw_ostream &OS, SourceManager &SM) const {
|
|
|
|
StmtDumper P(&SM, OS, 4);
|
2009-06-02 17:58:47 +00:00
|
|
|
P.DumpSubTree(const_cast<Stmt*>(this));
|
2010-09-17 15:54:40 +00:00
|
|
|
OS << "\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
|
|
|
}
|