2007-08-09 06:51:59 +08:00
|
|
|
//===--- StmtDumper.cpp - Dumping implementation for Stmt ASTs ------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-08-09 06:51:59 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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"
|
2007-10-18 02:36:42 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2009-02-04 03:21:40 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2007-08-30 14:17:34 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2007-08-09 06:51:59 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include <cstdio>
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// StmtDumper Visitor
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
2007-08-21 12:04:25 +08:00
|
|
|
class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor<StmtDumper> {
|
2007-08-30 14:17:34 +08:00
|
|
|
SourceManager *SM;
|
2007-08-09 06:51:59 +08:00
|
|
|
FILE *F;
|
|
|
|
unsigned IndentLevel;
|
|
|
|
|
|
|
|
/// 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;
|
2007-08-30 14:17:34 +08: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;
|
2007-08-09 06:51:59 +08:00
|
|
|
public:
|
2007-08-30 14:17:34 +08:00
|
|
|
StmtDumper(SourceManager *sm, FILE *f, unsigned maxDepth)
|
|
|
|
: SM(sm), F(f), IndentLevel(0-1), MaxDepth(maxDepth) {
|
|
|
|
LastLocFilename = "";
|
|
|
|
LastLocLine = ~0U;
|
|
|
|
}
|
2007-08-09 06:51:59 +08:00
|
|
|
|
2007-08-10 02:03:18 +08:00
|
|
|
void DumpSubTree(Stmt *S) {
|
2007-08-09 06:51:59 +08:00
|
|
|
// Prune the recursion if not using dump all.
|
|
|
|
if (MaxDepth == 0) return;
|
|
|
|
|
2007-08-10 02:03:18 +08:00
|
|
|
++IndentLevel;
|
2007-08-09 06:51:59 +08:00
|
|
|
if (S) {
|
2007-12-12 14:59:42 +08:00
|
|
|
if (DeclStmt* DS = dyn_cast<DeclStmt>(S))
|
|
|
|
VisitDeclStmt(DS);
|
|
|
|
else {
|
|
|
|
Visit(S);
|
|
|
|
|
|
|
|
// Print out children.
|
|
|
|
Stmt::child_iterator CI = S->child_begin(), CE = S->child_end();
|
|
|
|
if (CI != CE) {
|
|
|
|
while (CI != CE) {
|
|
|
|
fprintf(F, "\n");
|
|
|
|
DumpSubTree(*CI++);
|
|
|
|
}
|
2007-08-30 08:53:54 +08:00
|
|
|
}
|
2007-12-12 14:59:42 +08:00
|
|
|
fprintf(F, ")");
|
2007-08-30 08:53:54 +08:00
|
|
|
}
|
2007-08-09 06:51:59 +08:00
|
|
|
} else {
|
|
|
|
Indent();
|
2007-08-26 11:53:29 +08:00
|
|
|
fprintf(F, "<<<NULL>>>");
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
2007-08-10 02:03:18 +08:00
|
|
|
--IndentLevel;
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
2007-08-10 02:03:18 +08:00
|
|
|
void DumpDeclarator(Decl *D);
|
2007-08-09 06:51:59 +08:00
|
|
|
|
|
|
|
void Indent() const {
|
|
|
|
for (int i = 0, e = IndentLevel; i < e; ++i)
|
|
|
|
fprintf(F, " ");
|
|
|
|
}
|
|
|
|
|
2007-09-02 05:08:38 +08:00
|
|
|
void DumpType(QualType T) {
|
2007-08-09 08:36:22 +08:00
|
|
|
fprintf(F, "'%s'", T.getAsString().c_str());
|
|
|
|
|
2008-12-24 08:01:03 +08:00
|
|
|
if (!T.isNull()) {
|
|
|
|
// If the type is directly a typedef, strip off typedefness to give at
|
|
|
|
// least one level of concreteness.
|
|
|
|
if (TypedefType *TDT = dyn_cast<TypedefType>(T)) {
|
|
|
|
QualType Simplified =
|
|
|
|
TDT->LookThroughTypedefs().getQualifiedType(T.getCVRQualifiers());
|
|
|
|
fprintf(F, ":'%s'", Simplified.getAsString().c_str());
|
|
|
|
}
|
2008-04-02 13:06:23 +08:00
|
|
|
}
|
2007-08-09 08:36:22 +08:00
|
|
|
}
|
2007-09-02 05:08:38 +08:00
|
|
|
void DumpStmt(const Stmt *Node) {
|
2007-08-09 06:51:59 +08:00
|
|
|
Indent();
|
|
|
|
fprintf(F, "(%s %p", Node->getStmtClassName(), (void*)Node);
|
2007-09-02 05:08:38 +08:00
|
|
|
DumpSourceRange(Node);
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
2007-09-02 05:08:38 +08:00
|
|
|
void DumpExpr(const Expr *Node) {
|
2007-08-09 06:51:59 +08:00
|
|
|
DumpStmt(Node);
|
2007-08-09 08:36:22 +08:00
|
|
|
fprintf(F, " ");
|
|
|
|
DumpType(Node->getType());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
2007-09-02 05:08:38 +08:00
|
|
|
void DumpSourceRange(const Stmt *Node);
|
2007-08-30 14:17:34 +08:00
|
|
|
void DumpLocation(SourceLocation Loc);
|
|
|
|
|
2007-08-30 09:00:35 +08:00
|
|
|
// Stmts.
|
2007-08-21 12:04:25 +08:00
|
|
|
void VisitStmt(Stmt *Node);
|
2007-12-12 14:59:42 +08:00
|
|
|
void VisitDeclStmt(DeclStmt *Node);
|
2007-08-30 09:00:35 +08:00
|
|
|
void VisitLabelStmt(LabelStmt *Node);
|
|
|
|
void VisitGotoStmt(GotoStmt *Node);
|
|
|
|
|
|
|
|
// Exprs
|
|
|
|
void VisitExpr(Expr *Node);
|
|
|
|
void VisitDeclRefExpr(DeclRefExpr *Node);
|
2008-08-10 09:53:14 +08:00
|
|
|
void VisitPredefinedExpr(PredefinedExpr *Node);
|
2007-08-30 09:00:35 +08:00
|
|
|
void VisitCharacterLiteral(CharacterLiteral *Node);
|
|
|
|
void VisitIntegerLiteral(IntegerLiteral *Node);
|
|
|
|
void VisitFloatingLiteral(FloatingLiteral *Node);
|
|
|
|
void VisitStringLiteral(StringLiteral *Str);
|
|
|
|
void VisitUnaryOperator(UnaryOperator *Node);
|
2008-11-12 01:56:53 +08:00
|
|
|
void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node);
|
2007-08-30 09:00:35 +08:00
|
|
|
void VisitMemberExpr(MemberExpr *Node);
|
2008-04-19 07:10:10 +08:00
|
|
|
void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
|
2007-08-30 09:00:35 +08:00
|
|
|
void VisitBinaryOperator(BinaryOperator *Node);
|
|
|
|
void VisitCompoundAssignOperator(CompoundAssignOperator *Node);
|
|
|
|
void VisitAddrLabelExpr(AddrLabelExpr *Node);
|
|
|
|
void VisitTypesCompatibleExpr(TypesCompatibleExpr *Node);
|
|
|
|
|
|
|
|
// C++
|
2008-10-28 03:41:14 +08:00
|
|
|
void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node);
|
2007-08-30 09:00:35 +08:00
|
|
|
void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node);
|
2008-11-04 22:56:14 +08:00
|
|
|
void VisitCXXThisExpr(CXXThisExpr *Node);
|
2008-10-28 03:41:14 +08:00
|
|
|
void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node);
|
2008-11-04 22:56:14 +08:00
|
|
|
|
2007-08-30 09:00:35 +08:00
|
|
|
// ObjC
|
|
|
|
void VisitObjCEncodeExpr(ObjCEncodeExpr *Node);
|
2008-03-01 06:04:05 +08:00
|
|
|
void VisitObjCMessageExpr(ObjCMessageExpr* Node);
|
2007-10-17 04:40:23 +08:00
|
|
|
void VisitObjCSelectorExpr(ObjCSelectorExpr *Node);
|
2007-10-18 00:58:11 +08:00
|
|
|
void VisitObjCProtocolExpr(ObjCProtocolExpr *Node);
|
2008-08-30 13:35:15 +08:00
|
|
|
void VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node);
|
2008-11-23 02:39:36 +08:00
|
|
|
void VisitObjCKVCRefExpr(ObjCKVCRefExpr *Node);
|
2008-03-12 21:19:12 +08:00
|
|
|
void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
|
2008-11-04 22:56:14 +08:00
|
|
|
void VisitObjCSuperExpr(ObjCSuperExpr *Node);
|
2007-08-09 06:51:59 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2007-08-30 14:17:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utilities
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void StmtDumper::DumpLocation(SourceLocation Loc) {
|
2009-01-16 15:00:02 +08:00
|
|
|
SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
|
2009-01-27 15:57:44 +08:00
|
|
|
|
|
|
|
if (SpellingLoc.isInvalid()) {
|
|
|
|
fprintf(stderr, "<invalid sloc>");
|
|
|
|
return;
|
|
|
|
}
|
2007-08-30 14:17:34 +08:00
|
|
|
|
|
|
|
// The general format we print out is filename:line:col, but we drop pieces
|
|
|
|
// that haven't changed since the last loc printed.
|
2009-01-27 15:57:44 +08:00
|
|
|
PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc);
|
|
|
|
|
|
|
|
if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
|
|
|
|
fprintf(stderr, "%s:%u:%u", PLoc.getFilename(), PLoc.getLine(),
|
|
|
|
PLoc.getColumn());
|
|
|
|
LastLocFilename = PLoc.getFilename();
|
|
|
|
LastLocLine = PLoc.getLine();
|
|
|
|
} else if (PLoc.getLine() != LastLocLine) {
|
|
|
|
fprintf(stderr, "line:%u:%u", PLoc.getLine(), PLoc.getColumn());
|
|
|
|
LastLocLine = PLoc.getLine();
|
2007-08-30 14:17:34 +08:00
|
|
|
} else {
|
2009-01-27 15:57:44 +08:00
|
|
|
fprintf(stderr, "col:%u", PLoc.getColumn());
|
2007-08-30 14:17:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-02 05:08:38 +08:00
|
|
|
void StmtDumper::DumpSourceRange(const Stmt *Node) {
|
2007-08-30 14:17:34 +08:00
|
|
|
// Can't translate locations if a SourceManager isn't available.
|
|
|
|
if (SM == 0) return;
|
|
|
|
|
|
|
|
// TODO: If the parent expression is available, we can print a delta vs its
|
|
|
|
// location.
|
|
|
|
SourceRange R = Node->getSourceRange();
|
|
|
|
|
|
|
|
fprintf(stderr, " <");
|
2007-10-17 06:36:42 +08:00
|
|
|
DumpLocation(R.getBegin());
|
|
|
|
if (R.getBegin() != R.getEnd()) {
|
2007-08-30 14:17:34 +08:00
|
|
|
fprintf(stderr, ", ");
|
2007-10-17 06:36:42 +08:00
|
|
|
DumpLocation(R.getEnd());
|
2007-08-30 14:17:34 +08:00
|
|
|
}
|
|
|
|
fprintf(stderr, ">");
|
|
|
|
|
|
|
|
// <t2.c:123:421[blah], t2.c:412:321>
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-09 06:51:59 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Stmt printing methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void StmtDumper::VisitStmt(Stmt *Node) {
|
2007-08-30 09:00:35 +08:00
|
|
|
DumpStmt(Node);
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
2007-08-10 02:03:18 +08:00
|
|
|
void StmtDumper::DumpDeclarator(Decl *D) {
|
2007-08-09 06:51:59 +08:00
|
|
|
// 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)) {
|
2007-08-10 02:03:18 +08:00
|
|
|
fprintf(F, "\"typedef %s %s\"",
|
|
|
|
localType->getUnderlyingType().getAsString().c_str(),
|
2008-11-24 11:54:41 +08:00
|
|
|
localType->getNameAsString().c_str());
|
2007-08-09 06:51:59 +08:00
|
|
|
} else if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
|
2007-08-10 02:03:18 +08:00
|
|
|
fprintf(F, "\"");
|
2007-08-09 06:51:59 +08:00
|
|
|
// Emit storage class for vardecls.
|
|
|
|
if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
|
|
|
|
switch (V->getStorageClass()) {
|
2007-08-10 02:03:18 +08:00
|
|
|
default: assert(0 && "Unknown storage class!");
|
|
|
|
case VarDecl::None: break;
|
|
|
|
case VarDecl::Extern: fprintf(F, "extern "); break;
|
|
|
|
case VarDecl::Static: fprintf(F, "static "); break;
|
|
|
|
case VarDecl::Auto: fprintf(F, "auto "); break;
|
|
|
|
case VarDecl::Register: fprintf(F, "register "); break;
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-24 12:00:27 +08:00
|
|
|
std::string Name = VD->getNameAsString();
|
2007-08-09 06:51:59 +08:00
|
|
|
VD->getType().getAsStringInternal(Name);
|
2007-08-10 02:03:18 +08:00
|
|
|
fprintf(F, "%s", Name.c_str());
|
2007-08-09 06:51:59 +08:00
|
|
|
|
|
|
|
// If this is a vardecl with an initializer, emit it.
|
|
|
|
if (VarDecl *V = dyn_cast<VarDecl>(VD)) {
|
|
|
|
if (V->getInit()) {
|
2007-08-10 02:03:18 +08:00
|
|
|
fprintf(F, " =\n");
|
|
|
|
DumpSubTree(V->getInit());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
}
|
2007-08-10 02:03:18 +08:00
|
|
|
fprintf(F, "\"");
|
2007-11-18 05:37:36 +08: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())
|
|
|
|
tagname = II->getName();
|
|
|
|
else
|
|
|
|
tagname = "<anonymous>";
|
|
|
|
fprintf(F, "\"%s %s;\"", TD->getKindName(), tagname);
|
|
|
|
// FIXME: print tag bodies.
|
2009-02-04 03:21:40 +08:00
|
|
|
} 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())
|
|
|
|
ns = II->getName();
|
|
|
|
else
|
|
|
|
ns = "<anonymous>";
|
|
|
|
fprintf(F, "\"%s %s;\"",UD->getDeclKindName(), ns);
|
2007-08-09 06:51:59 +08:00
|
|
|
} else {
|
|
|
|
assert(0 && "Unexpected decl");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-12 14:59:42 +08:00
|
|
|
void StmtDumper::VisitDeclStmt(DeclStmt *Node) {
|
|
|
|
DumpStmt(Node);
|
|
|
|
fprintf(F,"\n");
|
2008-10-07 02:38:35 +08:00
|
|
|
for (DeclStmt::decl_iterator DI = Node->decl_begin(), DE = Node->decl_end();
|
|
|
|
DI != DE; ++DI) {
|
2009-01-20 09:17:11 +08:00
|
|
|
Decl* D = *DI;
|
2007-12-12 14:59:42 +08:00
|
|
|
++IndentLevel;
|
|
|
|
Indent();
|
|
|
|
fprintf(F, "%p ", (void*) D);
|
|
|
|
DumpDeclarator(D);
|
|
|
|
if (D->getNextDeclarator())
|
|
|
|
fprintf(F,"\n");
|
|
|
|
--IndentLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-09 06:51:59 +08:00
|
|
|
void StmtDumper::VisitLabelStmt(LabelStmt *Node) {
|
|
|
|
DumpStmt(Node);
|
2008-07-27 03:24:43 +08:00
|
|
|
fprintf(F, " '%s'", Node->getName());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::VisitGotoStmt(GotoStmt *Node) {
|
|
|
|
DumpStmt(Node);
|
2007-08-30 08:53:54 +08:00
|
|
|
fprintf(F, " '%s':%p", Node->getLabel()->getName(), (void*)Node->getLabel());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Expr printing methods.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void StmtDumper::VisitExpr(Expr *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
2007-09-11 01:32:55 +08:00
|
|
|
|
|
|
|
fprintf(F, " ");
|
|
|
|
switch (Node->getDecl()->getKind()) {
|
|
|
|
case Decl::Function: fprintf(F,"FunctionDecl"); break;
|
2008-04-16 06:42:06 +08:00
|
|
|
case Decl::Var: fprintf(F,"Var"); break;
|
2007-10-09 05:37:32 +08:00
|
|
|
case Decl::ParmVar: fprintf(F,"ParmVar"); break;
|
2007-09-11 01:32:55 +08:00
|
|
|
case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
|
|
|
|
case Decl::Typedef: fprintf(F,"Typedef"); break;
|
2008-10-15 08:42:39 +08:00
|
|
|
case Decl::Record: fprintf(F,"Record"); break;
|
2007-09-11 01:32:55 +08:00
|
|
|
case Decl::Enum: fprintf(F,"Enum"); break;
|
2008-10-15 08:42:39 +08:00
|
|
|
case Decl::CXXRecord: fprintf(F,"CXXRecord"); break;
|
2008-01-08 03:49:32 +08:00
|
|
|
case Decl::ObjCInterface: fprintf(F,"ObjCInterface"); break;
|
|
|
|
case Decl::ObjCClass: fprintf(F,"ObjCClass"); break;
|
2007-09-11 01:32:55 +08:00
|
|
|
default: fprintf(F,"Decl"); break;
|
|
|
|
}
|
|
|
|
|
2008-11-24 12:00:27 +08:00
|
|
|
fprintf(F, "='%s' %p", Node->getDecl()->getNameAsString().c_str(),
|
2008-11-17 22:58:09 +08:00
|
|
|
(void*)Node->getDecl());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
2008-03-12 21:19:12 +08:00
|
|
|
void StmtDumper::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) {
|
2008-05-23 08:59:14 +08:00
|
|
|
DumpExpr(Node);
|
2008-03-12 21:19:12 +08:00
|
|
|
|
2008-05-23 08:59:14 +08:00
|
|
|
fprintf(F, " %sDecl='%s' %p", Node->getDecl()->getDeclKindName(),
|
2008-11-24 11:54:41 +08:00
|
|
|
Node->getDecl()->getNameAsString().c_str(), (void*)Node->getDecl());
|
2008-05-24 06:01:24 +08:00
|
|
|
if (Node->isFreeIvar())
|
|
|
|
fprintf(F, " isFreeIvar");
|
2008-03-12 21:19:12 +08:00
|
|
|
}
|
|
|
|
|
2008-08-10 09:53:14 +08:00
|
|
|
void StmtDumper::VisitPredefinedExpr(PredefinedExpr *Node) {
|
2007-08-09 06:51:59 +08:00
|
|
|
DumpExpr(Node);
|
|
|
|
switch (Node->getIdentType()) {
|
2008-06-22 02:04:54 +08:00
|
|
|
default: assert(0 && "unknown case");
|
2008-08-10 09:53:14 +08:00
|
|
|
case PredefinedExpr::Func: fprintf(F, " __func__"); break;
|
|
|
|
case PredefinedExpr::Function: fprintf(F, " __FUNCTION__"); break;
|
|
|
|
case PredefinedExpr::PrettyFunction: fprintf(F, " __PRETTY_FUNCTION__");break;
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::VisitCharacterLiteral(CharacterLiteral *Node) {
|
2007-08-09 09:04:32 +08:00
|
|
|
DumpExpr(Node);
|
2007-08-30 08:53:54 +08:00
|
|
|
fprintf(F, " %d", Node->getValue());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::VisitIntegerLiteral(IntegerLiteral *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
|
|
|
|
bool isSigned = Node->getType()->isSignedIntegerType();
|
2007-08-30 08:53:54 +08:00
|
|
|
fprintf(F, " %s", Node->getValue().toString(10, isSigned).c_str());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
void StmtDumper::VisitFloatingLiteral(FloatingLiteral *Node) {
|
|
|
|
DumpExpr(Node);
|
2008-06-08 06:13:43 +08:00
|
|
|
fprintf(F, " %f", Node->getValueAsApproximateDouble());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
2007-08-26 11:42:43 +08:00
|
|
|
|
2007-08-09 06:51:59 +08:00
|
|
|
void StmtDumper::VisitStringLiteral(StringLiteral *Str) {
|
2007-08-09 09:04:32 +08:00
|
|
|
DumpExpr(Str);
|
|
|
|
// FIXME: this doesn't print wstrings right.
|
2007-08-10 01:14:24 +08:00
|
|
|
fprintf(F, " %s\"", Str->isWide() ? "L" : "");
|
2007-08-09 09:04:32 +08:00
|
|
|
|
2007-08-09 06:51:59 +08:00
|
|
|
for (unsigned i = 0, e = Str->getByteLength(); i != e; ++i) {
|
2007-08-10 01:14:24 +08:00
|
|
|
switch (char C = Str->getStrData()[i]) {
|
|
|
|
default:
|
|
|
|
if (isprint(C))
|
|
|
|
fputc(C, F);
|
|
|
|
else
|
|
|
|
fprintf(F, "\\%03o", C);
|
|
|
|
break;
|
2007-08-09 06:51:59 +08:00
|
|
|
// Handle some common ones to make dumps prettier.
|
2007-08-10 01:14:24 +08:00
|
|
|
case '\\': fprintf(F, "\\\\"); break;
|
|
|
|
case '"': fprintf(F, "\\\""); break;
|
|
|
|
case '\n': fprintf(F, "\\n"); break;
|
|
|
|
case '\t': fprintf(F, "\\t"); break;
|
|
|
|
case '\a': fprintf(F, "\\a"); break;
|
|
|
|
case '\b': fprintf(F, "\\b"); break;
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
}
|
2007-08-30 08:53:54 +08:00
|
|
|
fprintf(F, "\"");
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
2007-08-30 09:00:35 +08:00
|
|
|
|
2007-08-09 06:51:59 +08:00
|
|
|
void StmtDumper::VisitUnaryOperator(UnaryOperator *Node) {
|
2007-08-10 01:35:30 +08:00
|
|
|
DumpExpr(Node);
|
2007-08-30 08:53:54 +08:00
|
|
|
fprintf(F, " %s '%s'", Node->isPostfix() ? "postfix" : "prefix",
|
2007-08-10 01:35:30 +08:00
|
|
|
UnaryOperator::getOpcodeStr(Node->getOpcode()));
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
2008-11-12 01:56:53 +08:00
|
|
|
void StmtDumper::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node) {
|
2007-08-10 01:35:30 +08:00
|
|
|
DumpExpr(Node);
|
|
|
|
fprintf(F, " %s ", Node->isSizeOf() ? "sizeof" : "alignof");
|
2008-11-12 01:56:53 +08:00
|
|
|
if (Node->isArgumentType())
|
|
|
|
DumpType(Node->getArgumentType());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
2007-08-10 01:35:30 +08:00
|
|
|
|
2007-08-09 06:51:59 +08:00
|
|
|
void StmtDumper::VisitMemberExpr(MemberExpr *Node) {
|
2007-08-10 01:35:30 +08:00
|
|
|
DumpExpr(Node);
|
2007-08-30 08:53:54 +08:00
|
|
|
fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".",
|
2008-11-24 11:33:13 +08:00
|
|
|
Node->getMemberDecl()->getNameAsString().c_str(),
|
2008-11-17 22:58:09 +08:00
|
|
|
(void*)Node->getMemberDecl());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
2008-04-19 07:10:10 +08:00
|
|
|
void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) {
|
2007-08-10 01:35:30 +08:00
|
|
|
DumpExpr(Node);
|
2007-08-30 08:53:54 +08:00
|
|
|
fprintf(F, " %s", Node->getAccessor().getName());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
void StmtDumper::VisitBinaryOperator(BinaryOperator *Node) {
|
|
|
|
DumpExpr(Node);
|
2007-08-30 08:53:54 +08:00
|
|
|
fprintf(F, " '%s'", BinaryOperator::getOpcodeStr(Node->getOpcode()));
|
2007-08-25 10:00:02 +08:00
|
|
|
}
|
|
|
|
void StmtDumper::VisitCompoundAssignOperator(CompoundAssignOperator *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
fprintf(F, " '%s' ComputeTy=",
|
|
|
|
BinaryOperator::getOpcodeStr(Node->getOpcode()));
|
|
|
|
DumpType(Node->getComputationType());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GNU extensions.
|
|
|
|
|
|
|
|
void StmtDumper::VisitAddrLabelExpr(AddrLabelExpr *Node) {
|
2007-08-10 01:35:30 +08:00
|
|
|
DumpExpr(Node);
|
2007-08-30 08:53:54 +08:00
|
|
|
fprintf(F, " %s %p", Node->getLabel()->getName(), (void*)Node->getLabel());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
|
2007-08-10 01:35:30 +08:00
|
|
|
DumpExpr(Node);
|
|
|
|
fprintf(F, " ");
|
|
|
|
DumpType(Node->getArgType1());
|
|
|
|
fprintf(F, " ");
|
|
|
|
DumpType(Node->getArgType2());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
2007-08-10 02:03:18 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// C++ Expressions
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-08-09 06:51:59 +08:00
|
|
|
|
2008-10-28 03:41:14 +08:00
|
|
|
void StmtDumper::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) {
|
2007-08-10 01:35:30 +08:00
|
|
|
DumpExpr(Node);
|
2008-10-28 03:41:14 +08:00
|
|
|
fprintf(F, " %s<%s>", Node->getCastName(),
|
|
|
|
Node->getTypeAsWritten().getAsString().c_str());
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) {
|
2007-08-10 01:35:30 +08:00
|
|
|
DumpExpr(Node);
|
2007-08-30 08:53:54 +08:00
|
|
|
fprintf(F, " %s", Node->getValue() ? "true" : "false");
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
2008-11-04 22:56:14 +08:00
|
|
|
void StmtDumper::VisitCXXThisExpr(CXXThisExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
fprintf(F, " this");
|
|
|
|
}
|
|
|
|
|
2008-10-28 03:41:14 +08:00
|
|
|
void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
fprintf(F, " functional cast to %s",
|
|
|
|
Node->getTypeAsWritten().getAsString().c_str());
|
|
|
|
}
|
|
|
|
|
2007-08-22 01:43:55 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Obj-C Expressions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-03-01 06:04:05 +08:00
|
|
|
void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) {
|
|
|
|
DumpExpr(Node);
|
2008-11-24 11:33:13 +08:00
|
|
|
fprintf(F, " selector=%s", Node->getSelector().getAsString().c_str());
|
2008-05-02 01:26:20 +08:00
|
|
|
IdentifierInfo* clsName = Node->getClassName();
|
|
|
|
if (clsName) fprintf(F, " class=%s", clsName->getName());
|
2008-03-01 06:04:05 +08:00
|
|
|
}
|
|
|
|
|
2007-08-22 23:14:15 +08:00
|
|
|
void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
|
|
|
|
fprintf(F, " ");
|
|
|
|
DumpType(Node->getEncodedType());
|
|
|
|
}
|
|
|
|
|
2007-10-17 04:40:23 +08:00
|
|
|
void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
|
|
|
|
fprintf(F, " ");
|
2008-11-24 11:33:13 +08:00
|
|
|
fprintf(F, "%s", Node->getSelector().getAsString().c_str());
|
2007-10-17 04:40:23 +08:00
|
|
|
}
|
|
|
|
|
2007-10-18 00:58:11 +08:00
|
|
|
void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
|
|
|
|
fprintf(F, " ");
|
2008-11-24 11:54:41 +08:00
|
|
|
fprintf(F, "%s", Node->getProtocol()->getNameAsString().c_str());
|
2007-10-18 00:58:11 +08:00
|
|
|
}
|
2008-08-30 13:35:15 +08:00
|
|
|
|
|
|
|
void StmtDumper::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
2008-09-03 08:27:26 +08:00
|
|
|
|
2008-11-23 02:39:36 +08:00
|
|
|
fprintf(F, " Kind=PropertyRef Property=\"%s\"",
|
2008-11-24 11:54:41 +08:00
|
|
|
Node->getProperty()->getNameAsString().c_str());
|
2008-11-23 02:39:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StmtDumper::VisitObjCKVCRefExpr(ObjCKVCRefExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
|
|
|
|
ObjCMethodDecl *Getter = Node->getGetterMethod();
|
|
|
|
ObjCMethodDecl *Setter = Node->getSetterMethod();
|
|
|
|
fprintf(F, " Kind=MethodRef Getter=\"%s\" Setter=\"%s\"",
|
2008-11-24 11:33:13 +08:00
|
|
|
Getter->getSelector().getAsString().c_str(),
|
|
|
|
Setter ? Setter->getSelector().getAsString().c_str() : "(null)");
|
2008-08-30 13:35:15 +08:00
|
|
|
}
|
|
|
|
|
2008-11-04 22:56:14 +08:00
|
|
|
void StmtDumper::VisitObjCSuperExpr(ObjCSuperExpr *Node) {
|
|
|
|
DumpExpr(Node);
|
|
|
|
fprintf(F, " super");
|
|
|
|
}
|
|
|
|
|
2007-08-09 06:51:59 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Stmt method implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-08-30 08:40:08 +08: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.
|
2007-08-30 14:17:34 +08:00
|
|
|
void Stmt::dump(SourceManager &SM) const {
|
2007-08-30 08:40:08 +08:00
|
|
|
StmtDumper P(&SM, stderr, 4);
|
2007-08-30 08:53:54 +08:00
|
|
|
P.DumpSubTree(const_cast<Stmt*>(this));
|
2007-08-30 08:40:08 +08:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2007-08-09 06:51:59 +08: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 {
|
2007-08-30 08:40:08 +08:00
|
|
|
StmtDumper P(0, stderr, 4);
|
2007-08-30 08:53:54 +08:00
|
|
|
P.DumpSubTree(const_cast<Stmt*>(this));
|
2007-08-30 08:40:08 +08:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
|
2007-08-30 14:17:34 +08:00
|
|
|
void Stmt::dumpAll(SourceManager &SM) const {
|
2007-08-30 08:40:08 +08:00
|
|
|
StmtDumper P(&SM, stderr, ~0U);
|
2007-08-30 08:53:54 +08:00
|
|
|
P.DumpSubTree(const_cast<Stmt*>(this));
|
2007-08-11 05:51:12 +08:00
|
|
|
fprintf(stderr, "\n");
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
|
|
|
|
void Stmt::dumpAll() const {
|
2007-08-30 08:40:08 +08:00
|
|
|
StmtDumper P(0, stderr, ~0U);
|
2007-08-30 08:53:54 +08:00
|
|
|
P.DumpSubTree(const_cast<Stmt*>(this));
|
2007-08-11 05:51:12 +08:00
|
|
|
fprintf(stderr, "\n");
|
2007-08-09 06:51:59 +08:00
|
|
|
}
|