#include "clang/Lex/IdentifierTable.h"
using namespace clang;
-// Implement all the AST node visit methods using the StmtNodes.def database.
-#define STMT(N, CLASS, PARENT) \
-void CLASS::visit(StmtVisitor &V) { return V.Visit##CLASS(this); }
-
-STMT(0, Stmt, )
-#include "clang/AST/StmtNodes.def"
-
static struct StmtClassNameTable {
int enumValue;
const char *className;
//===----------------------------------------------------------------------===//
namespace {
- class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor {
+ class VISIBILITY_HIDDEN StmtDumper : public StmtVisitor<StmtDumper> {
FILE *F;
unsigned IndentLevel;
++IndentLevel;
if (S) {
- S->visit(*this);
+ Visit(S);
} else {
Indent();
fprintf(F, "<<<NULL>>>\n");
DumpType(Node->getType());
}
- virtual void VisitStmt(Stmt *Node);
+ void VisitStmt(Stmt *Node);
#define STMT(N, CLASS, PARENT) \
- virtual void Visit##CLASS(CLASS *Node);
+ void Visit##CLASS(CLASS *Node);
#include "clang/AST/StmtNodes.def"
};
}
/// This is useful in a debugger.
void Stmt::dump() const {
StmtDumper P(stderr, 4);
- const_cast<Stmt*>(this)->visit(P);
+ P.Visit(const_cast<Stmt*>(this));
fprintf(stderr, "\n");
}
/// dumpAll - This does a dump of the specified AST fragment and all subtrees.
void Stmt::dumpAll() const {
StmtDumper P(stderr, ~0U);
- const_cast<Stmt*>(this)->visit(P);
+ P.Visit(const_cast<Stmt*>(this));
fprintf(stderr, "\n");
}
//===----------------------------------------------------------------------===//
namespace {
- class VISIBILITY_HIDDEN StmtPrinter : public StmtVisitor {
+ class VISIBILITY_HIDDEN StmtPrinter : public StmtVisitor<StmtPrinter> {
std::ostream &OS;
unsigned IndentLevel;
public:
if (S && isa<Expr>(S)) {
// If this is an expr used in a stmt context, indent and newline it.
Indent();
- S->visit(*this);
+ Visit(S);
OS << ";\n";
} else if (S) {
- S->visit(*this);
+ Visit(S);
} else {
Indent() << "<<<NULL STATEMENT>>>\n";
}
void PrintExpr(Expr *E) {
if (E)
- E->visit(*this);
+ Visit(E);
else
OS << "<null expr>";
}
return OS;
}
- virtual void VisitStmt(Stmt *Node);
+ void VisitStmt(Stmt *Node);
#define STMT(N, CLASS, PARENT) \
- virtual void Visit##CLASS(CLASS *Node);
+ void Visit##CLASS(CLASS *Node);
#include "clang/AST/StmtNodes.def"
};
}
}
StmtPrinter P(OS);
- const_cast<Stmt*>(this)->visit(P);
+ P.Visit(const_cast<Stmt*>(this));
}
+++ /dev/null
-//===--- StmtVisitor.cpp - Visitor for Stmt subclasses --------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the StmtVisitor class.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/AST/StmtVisitor.h"
-#include "clang/AST/ExprCXX.h"
-using namespace clang;
-
-StmtVisitor::~StmtVisitor() {
- // Out-of-line virtual dtor.
-}
-
-// Implement all of the delegation visitor methods.
-#define STMT(N, FROM, TO) \
- void StmtVisitor::Visit##FROM(FROM *Node) { Visit##TO(Node); }
-#include "clang/AST/StmtNodes.def"
-
DE3452410AEF1A2D00DBC861 /* Stmt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE3452400AEF1A2D00DBC861 /* Stmt.cpp */; };
DE3452810AEF1B1800DBC861 /* Stmt.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3452800AEF1B1800DBC861 /* Stmt.h */; };
DE345C1A0AFC658B00DBC861 /* StmtVisitor.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE345C190AFC658B00DBC861 /* StmtVisitor.h */; };
- DE345C570AFC69E800DBC861 /* StmtVisitor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE345C560AFC69E800DBC861 /* StmtVisitor.cpp */; };
DE345F220AFD347900DBC861 /* StmtNodes.def in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE345F210AFD347900DBC861 /* StmtNodes.def */; };
DE3460000AFDCC1900DBC861 /* ParseObjc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE345FFF0AFDCC1900DBC861 /* ParseObjc.cpp */; };
DE3460050AFDCC6500DBC861 /* ParseInit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE3460040AFDCC6500DBC861 /* ParseInit.cpp */; };
DE3452400AEF1A2D00DBC861 /* Stmt.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Stmt.cpp; path = AST/Stmt.cpp; sourceTree = "<group>"; };
DE3452800AEF1B1800DBC861 /* Stmt.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Stmt.h; path = clang/AST/Stmt.h; sourceTree = "<group>"; };
DE345C190AFC658B00DBC861 /* StmtVisitor.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = StmtVisitor.h; path = clang/AST/StmtVisitor.h; sourceTree = "<group>"; };
- DE345C560AFC69E800DBC861 /* StmtVisitor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = StmtVisitor.cpp; path = AST/StmtVisitor.cpp; sourceTree = "<group>"; };
DE345F210AFD347900DBC861 /* StmtNodes.def */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; name = StmtNodes.def; path = clang/AST/StmtNodes.def; sourceTree = "<group>"; };
DE345FFF0AFDCC1900DBC861 /* ParseObjc.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseObjc.cpp; path = Parse/ParseObjc.cpp; sourceTree = "<group>"; };
DE3460040AFDCC6500DBC861 /* ParseInit.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseInit.cpp; path = Parse/ParseInit.cpp; sourceTree = "<group>"; };
DE75EDF00B06880E0020CF81 /* Type.cpp */,
DEF2EDA60C6A4252000C4259 /* StmtDumper.cpp */,
DE34621C0AFEB19B00DBC861 /* StmtPrinter.cpp */,
- DE345C560AFC69E800DBC861 /* StmtVisitor.cpp */,
);
name = AST;
sourceTree = "<group>";
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
DE344B540AE5E46C00DBC861 /* HeaderSearch.cpp in Sources */,
DE3451580AEC176100DBC861 /* MacroExpander.cpp in Sources */,
DE3452410AEF1A2D00DBC861 /* Stmt.cpp in Sources */,
- DE345C570AFC69E800DBC861 /* StmtVisitor.cpp in Sources */,
DE3460000AFDCC1900DBC861 /* ParseObjc.cpp in Sources */,
DE3460050AFDCC6500DBC861 /* ParseInit.cpp in Sources */,
DE34600B0AFDCCBF00DBC861 /* ParseStmt.cpp in Sources */,
return isIntegerConstantExpr(X, Ctx, Loc);
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() >= firstExprConstant &&
T->getStmtClass() <= lastExprConstant;
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == DeclRefExprClass;
}
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == PreDefinedExprClass;
}
const llvm::APInt &getValue() const { return Value; }
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == IntegerLiteralClass;
}
unsigned getValue() const { return Value; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == CharacterLiteralClass;
}
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == FloatingLiteralClass;
}
virtual SourceRange getSourceRange() const {
return SourceRange(firstTokLoc,lastTokLoc);
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == StringLiteralClass;
}
Expr *getSubExpr() { return Val; }
SourceRange getSourceRange() const { return SourceRange(L, R); }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == ParenExprClass;
}
}
virtual SourceLocation getExprLoc() const { return Loc; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == UnaryOperatorClass;
}
SourceLocation getOperatorLoc() const { return OpLoc; }
SourceRange getSourceRange() const { return SourceRange(OpLoc, RParenLoc); }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == SizeOfAlignOfTypeExprClass;
}
}
virtual SourceLocation getExprLoc() const { return RBracketLoc; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == ArraySubscriptExprClass;
}
return SourceRange(Fn->getLocStart(), RParenLoc);
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == CallExprClass;
}
}
virtual SourceLocation getExprLoc() const { return MemberLoc; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == MemberExprClass;
}
virtual SourceRange getSourceRange() const {
return SourceRange(getBase()->getLocStart(), AccessorLoc);
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == OCUVectorElementExprClass;
}
virtual SourceRange getSourceRange() const { return Init->getSourceRange(); }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == CompoundLiteralExprClass;
}
virtual SourceRange getSourceRange() const { return Op->getSourceRange(); }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == ImplicitCastExprClass;
}
virtual SourceRange getSourceRange() const {
return SourceRange(Loc, getSubExpr()->getSourceRange().End());
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == CastExprClass;
}
bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == BinaryOperatorClass;
}
virtual SourceRange getSourceRange() const {
return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == ConditionalOperatorClass;
}
LabelStmt *getLabel() const { return Label; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == AddrLabelExprClass;
}
return SourceRange(LParenLoc, RParenLoc);
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == StmtExprClass;
}
virtual SourceRange getSourceRange() const {
return SourceRange(BuiltinLoc, RParenLoc);
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == TypesCompatibleExprClass;
}
virtual SourceRange getSourceRange() const {
return SourceRange(BuiltinLoc, RParenLoc);
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == ChooseExprClass;
}
virtual SourceRange getSourceRange() const {
return SourceRange(Loc, getSubExpr()->getSourceRange().End());
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXCastExprClass;
}
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == CXXBoolLiteralExprClass;
}
class Expr;
class Decl;
class IdentifierInfo;
- class StmtVisitor;
class SwitchStmt;
/// Stmt - This represents one statement.
void dumpPretty() const;
void printPretty(std::ostream &OS) const;
- // Implement visitor support.
- virtual void visit(StmtVisitor &Visitor);
-
// Implement isa<T> support.
static bool classof(const Stmt *) { return true; }
};
const Decl *getDecl() const { return TheDecl; }
Decl *getDecl() { return TheDecl; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == DeclStmtClass;
}
SourceLocation getSemiLoc() const { return SemiLoc; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == NullStmtClass;
}
void push_back(Stmt *S) { Body.push_back(S); }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == CompoundStmtClass;
}
T->getStmtClass() == DefaultStmtClass;
}
static bool classof(const SwitchCase *) { return true; }
-
- virtual void visit(StmtVisitor &Visitor) = 0;
};
class CaseStmt : public SwitchCase {
Expr *getRHS() { return RHSVal; }
Stmt *getSubStmt() { return SubStmt; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == CaseStmtClass;
}
SourceLocation getDefaultLoc() const { return DefaultLoc; }
Stmt *getSubStmt() { return SubStmt; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == DefaultStmtClass;
}
void setIdentLoc(SourceLocation L) { IdentLoc = L; }
void setSubStmt(Stmt *SS) { SubStmt = SS; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == LabelStmtClass;
}
Stmt *getThen() { return Then; }
Stmt *getElse() { return Else; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == IfStmtClass;
}
FirstCase = SC;
}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == SwitchStmtClass;
}
Stmt *getBody() { return Body; }
const Stmt *getBody() const { return Body; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == WhileStmtClass;
}
Expr *getCond() { return Cond; }
const Expr *getCond() const { return Cond; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == DoStmtClass;
}
const Expr *getInc() const { return Inc; }
const Stmt *getBody() const { return Body; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == ForStmtClass;
}
LabelStmt *getLabel() const { return Label; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == GotoStmtClass;
}
Expr *getTarget() { return Target; }
const Expr *getTarget() const { return Target; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == IndirectGotoStmtClass;
}
class ContinueStmt : public Stmt {
public:
ContinueStmt() : Stmt(ContinueStmtClass) {}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == ContinueStmtClass;
}
class BreakStmt : public Stmt {
public:
BreakStmt() : Stmt(BreakStmtClass) {}
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == BreakStmtClass;
}
const Expr *getRetValue() const { return RetExpr; }
Expr *getRetValue() { return RetExpr; }
- virtual void visit(StmtVisitor &Visitor);
static bool classof(const Stmt *T) {
return T->getStmtClass() == ReturnStmtClass;
}
#ifndef LLVM_CLANG_AST_STMTVISITOR_H
#define LLVM_CLANG_AST_STMTVISITOR_H
+#include "clang/AST/ExprCXX.h"
+
namespace clang {
- class Stmt;
- // Add prototypes for all AST node classes.
-#define STMT(N, CLASS, PARENT) \
- class CLASS;
-#include "clang/AST/StmtNodes.def"
/// StmtVisitor - This class implements a simple visitor for Stmt subclasses.
/// Since Expr derives from Stmt, this also includes support for visiting Exprs.
+template<typename ImplClass>
class StmtVisitor {
public:
- virtual ~StmtVisitor();
-
- virtual void VisitStmt(Stmt *Node) {}
+ void Visit(Stmt *S) {
+ // Top switch stmt: dispatch to VisitFooStmt for each FooStmt.
+ switch (S->getStmtClass()) {
+ default: assert(0 && "Unknown stmt kind!");
+#define STMT(N, CLASS, PARENT) \
+ case Stmt::CLASS ## Class: \
+ return static_cast<ImplClass*>(this)->Visit ## CLASS( \
+ static_cast<CLASS*>(S));
+#include "clang/AST/StmtNodes.def"
+ }
+ }
- // Implement all the methods with the StmtNodes.def file.
-#define STMT(N, CLASS, PARENT) \
- virtual void Visit##CLASS(CLASS *Node);
+ // If the implementation chooses not to implement a certain visit method, fall
+ // back on VisitExpr or whatever else is the superclass.
+#define STMT(N, CLASS, PARENT) \
+ void Visit ## CLASS(CLASS *Node) { \
+ return static_cast<ImplClass*>(this)->Visit ## PARENT(Node); \
+ }
#include "clang/AST/StmtNodes.def"
+
+ // Base case, ignore it. :)
+ void VisitStmt(Stmt *Node) {}
};
}