forked from OSchip/llvm-project
make visit methods take a reference to a visitor instead of a pointer.
Remove all dump_impl methods from Stmt subclasses llvm-svn: 39108
This commit is contained in:
parent
72b7d39d78
commit
9ea960a220
|
@ -14,7 +14,6 @@
|
|||
#include "clang/AST/Expr.h"
|
||||
#include "clang/AST/StmtVisitor.h"
|
||||
#include "clang/Lex/IdentifierTable.h"
|
||||
#include <iostream>
|
||||
using namespace llvm;
|
||||
using namespace clang;
|
||||
|
||||
|
@ -23,7 +22,7 @@ using namespace clang;
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define MAKE_VISITOR(CLASS) \
|
||||
void CLASS::visit(StmtVisitor *V) { return V->Visit ## CLASS(this); }
|
||||
void CLASS::visit(StmtVisitor &V) { return V.Visit##CLASS(this); }
|
||||
|
||||
MAKE_VISITOR(Expr)
|
||||
MAKE_VISITOR(DeclRefExpr)
|
||||
|
@ -46,19 +45,6 @@ MAKE_VISITOR(ConditionalOperator)
|
|||
// Primary Expressions.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void DeclRefExpr::dump_impl() const {
|
||||
std::cerr << "x";
|
||||
}
|
||||
|
||||
void IntegerConstant::dump_impl() const {
|
||||
std::cerr << "1";
|
||||
}
|
||||
|
||||
void FloatingConstant::dump_impl() const {
|
||||
std::cerr << "1.0";
|
||||
}
|
||||
|
||||
|
||||
|
||||
StringExpr::StringExpr(const char *strData, unsigned byteLength, bool Wide) {
|
||||
// OPTIMIZE: could allocate this appended to the StringExpr.
|
||||
|
@ -73,19 +59,6 @@ StringExpr::~StringExpr() {
|
|||
delete[] StrData;
|
||||
}
|
||||
|
||||
void StringExpr::dump_impl() const {
|
||||
if (isWide) std::cerr << 'L';
|
||||
std::cerr << '"' << StrData << '"';
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ParenExpr::dump_impl() const {
|
||||
std::cerr << "'('";
|
||||
Val->dump();
|
||||
std::cerr << "')'";
|
||||
}
|
||||
|
||||
/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
|
||||
/// corresponds to, e.g. "sizeof" or "[pre]++".
|
||||
const char *UnaryOperator::getOpcodeStr(Opcode Op) {
|
||||
|
@ -109,28 +82,10 @@ const char *UnaryOperator::getOpcodeStr(Opcode Op) {
|
|||
}
|
||||
}
|
||||
|
||||
void UnaryOperator::dump_impl() const {
|
||||
std::cerr << getOpcodeStr(Opc);
|
||||
Input->dump();
|
||||
}
|
||||
|
||||
void SizeOfAlignOfTypeExpr::dump_impl() const {
|
||||
std::cerr << (isSizeof ? "sizeof(" : "alignof(");
|
||||
// FIXME: print type.
|
||||
std::cerr << "ty)";
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Postfix Operators.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void ArraySubscriptExpr::dump_impl() const {
|
||||
Base->dump();
|
||||
std::cerr << "[";
|
||||
Idx->dump();
|
||||
std::cerr << "]";
|
||||
}
|
||||
|
||||
CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs)
|
||||
: Fn(fn), NumArgs(numargs) {
|
||||
Args = new Expr*[numargs];
|
||||
|
@ -138,35 +93,6 @@ CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs)
|
|||
Args[i] = args[i];
|
||||
}
|
||||
|
||||
void CallExpr::dump_impl() const {
|
||||
Fn->dump();
|
||||
std::cerr << "(";
|
||||
for (unsigned i = 0, e = getNumArgs(); i != e; ++i) {
|
||||
if (i) std::cerr << ", ";
|
||||
getArg(i)->dump();
|
||||
}
|
||||
std::cerr << ")";
|
||||
}
|
||||
|
||||
|
||||
void MemberExpr::dump_impl() const {
|
||||
Base->dump();
|
||||
std::cerr << (isArrow ? "->" : ".");
|
||||
|
||||
if (MemberDecl)
|
||||
/*TODO: Print MemberDecl*/;
|
||||
std::cerr << "member";
|
||||
}
|
||||
|
||||
|
||||
void CastExpr::dump_impl() const {
|
||||
std::cerr << "'('";
|
||||
// TODO PRINT TYPE
|
||||
std::cerr << "<type>";
|
||||
std::cerr << "')'";
|
||||
Op->dump();
|
||||
}
|
||||
|
||||
/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
|
||||
/// corresponds to, e.g. "<<=".
|
||||
const char *BinaryOperator::getOpcodeStr(Opcode Op) {
|
||||
|
@ -204,17 +130,3 @@ const char *BinaryOperator::getOpcodeStr(Opcode Op) {
|
|||
case Comma: return ",";
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryOperator::dump_impl() const {
|
||||
LHS->dump();
|
||||
std::cerr << " " << getOpcodeStr(Opc) << " ";
|
||||
RHS->dump();
|
||||
}
|
||||
|
||||
void ConditionalOperator::dump_impl() const {
|
||||
Cond->dump();
|
||||
std::cerr << " ? ";
|
||||
LHS->dump();
|
||||
std::cerr << " : ";
|
||||
RHS->dump();
|
||||
}
|
||||
|
|
|
@ -14,46 +14,15 @@
|
|||
#include "clang/AST/Stmt.h"
|
||||
#include "clang/AST/Expr.h"
|
||||
#include "clang/AST/StmtVisitor.h"
|
||||
#include <iostream>
|
||||
using namespace llvm;
|
||||
using namespace clang;
|
||||
|
||||
void Stmt::dump() const {
|
||||
if (this == 0) {
|
||||
std::cerr << "<null>";
|
||||
return;
|
||||
}
|
||||
if (isExpr()) std::cerr << "(";
|
||||
dump_impl();
|
||||
if (isExpr()) std::cerr << ")";
|
||||
}
|
||||
#define MAKE_VISITOR(CLASS) \
|
||||
void CLASS::visit(StmtVisitor &V) { return V.Visit##CLASS(this); }
|
||||
|
||||
void Stmt ::visit(StmtVisitor *V) { return V->VisitStmt(this); }
|
||||
void CompoundStmt::visit(StmtVisitor *V) { return V->VisitCompoundStmt(this); }
|
||||
void IfStmt ::visit(StmtVisitor *V) { return V->VisitIfStmt(this); }
|
||||
void ReturnStmt ::visit(StmtVisitor *V) { return V->VisitReturnStmt(this); }
|
||||
MAKE_VISITOR(Stmt)
|
||||
MAKE_VISITOR(CompoundStmt)
|
||||
MAKE_VISITOR(IfStmt)
|
||||
MAKE_VISITOR(ReturnStmt)
|
||||
|
||||
|
||||
void CompoundStmt::dump_impl() const {
|
||||
std::cerr << "{\n";
|
||||
for (unsigned i = 0, e = Body.size(); i != e; ++i) {
|
||||
Body[i]->dump();
|
||||
std::cerr << "\n";
|
||||
}
|
||||
std::cerr << "}";
|
||||
}
|
||||
|
||||
void IfStmt::dump_impl() const {
|
||||
std::cerr << "if ";
|
||||
Cond->dump();
|
||||
std::cerr << " then\n";
|
||||
Then->dump();
|
||||
std::cerr << "\n else ";
|
||||
Else->dump();
|
||||
}
|
||||
|
||||
void ReturnStmt::dump_impl() const {
|
||||
std::cerr << "return ";
|
||||
if (RetExpr)
|
||||
RetExpr->dump();
|
||||
}
|
||||
#undef MAKE_VISITOR
|
||||
|
|
|
@ -32,10 +32,7 @@ public:
|
|||
Expr() {}
|
||||
~Expr() {}
|
||||
|
||||
|
||||
// FIXME: move to isa/dyncast etc.
|
||||
virtual bool isExpr() const { return true; }
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -49,22 +46,19 @@ class DeclRefExpr : public Expr {
|
|||
Decl &D;
|
||||
public:
|
||||
DeclRefExpr(Decl &d) : D(d) {}
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
class IntegerConstant : public Expr {
|
||||
public:
|
||||
IntegerConstant() {}
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
class FloatingConstant : public Expr {
|
||||
public:
|
||||
FloatingConstant() {}
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
class StringExpr : public Expr {
|
||||
|
@ -74,8 +68,7 @@ class StringExpr : public Expr {
|
|||
public:
|
||||
StringExpr(const char *strData, unsigned byteLength, bool Wide);
|
||||
virtual ~StringExpr();
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This
|
||||
|
@ -86,8 +79,7 @@ class ParenExpr : public Expr {
|
|||
public:
|
||||
ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
|
||||
: L(l), R(r), Val(val) {}
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
|
||||
|
@ -115,8 +107,7 @@ public:
|
|||
/// corresponds to, e.g. "sizeof" or "[pre]++"
|
||||
static const char *getOpcodeStr(Opcode Op);
|
||||
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
|
||||
private:
|
||||
Expr *Input;
|
||||
|
@ -132,8 +123,7 @@ public:
|
|||
SizeOfAlignOfTypeExpr(bool issizeof, Type *ty) : isSizeof(issizeof), Ty(ty) {
|
||||
}
|
||||
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -146,8 +136,7 @@ class ArraySubscriptExpr : public Expr {
|
|||
public:
|
||||
ArraySubscriptExpr(Expr *base, Expr *idx) : Base(base), Idx(idx) {}
|
||||
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
|
||||
|
@ -177,8 +166,7 @@ public:
|
|||
/// this function call.
|
||||
unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
|
||||
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.
|
||||
|
@ -191,8 +179,7 @@ public:
|
|||
MemberExpr(Expr *base, bool isarrow, Decl *memberdecl)
|
||||
: Base(base), MemberDecl(memberdecl), isArrow(isarrow) {
|
||||
}
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
/// CastExpr - [C99 6.5.4] Cast Operators.
|
||||
|
@ -203,8 +190,7 @@ class CastExpr : public Expr {
|
|||
public:
|
||||
CastExpr(Type *ty, Expr *op) : Ty(ty), Op(op) {}
|
||||
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
|
||||
|
@ -238,8 +224,7 @@ public:
|
|||
/// corresponds to, e.g. "<<=".
|
||||
static const char *getOpcodeStr(Opcode Op);
|
||||
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
|
||||
private:
|
||||
Expr *LHS, *RHS;
|
||||
|
@ -254,8 +239,7 @@ class ConditionalOperator : public Expr {
|
|||
public:
|
||||
ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs)
|
||||
: Cond(cond), LHS(lhs), RHS(rhs) {}
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include <iosfwd>
|
||||
|
||||
namespace llvm {
|
||||
namespace clang {
|
||||
|
@ -29,16 +30,11 @@ public:
|
|||
Stmt() {}
|
||||
virtual ~Stmt() {}
|
||||
|
||||
// FIXME: Change to non-virtual method that uses visitor pattern to do this.
|
||||
void dump() const;
|
||||
|
||||
// FIXME: move to isa/dyncast etc.
|
||||
virtual bool isExpr() const { return false; }
|
||||
void print(std::ostream &OS) const;
|
||||
|
||||
// Implement visitor support.
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
private:
|
||||
virtual void dump_impl() const = 0;
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
/// CompoundStmt - This represents a group of statements like { stmt stmt }.
|
||||
|
@ -49,9 +45,11 @@ public:
|
|||
CompoundStmt(Stmt **StmtStart, unsigned NumStmts)
|
||||
: Body(StmtStart, StmtStart+NumStmts) {}
|
||||
|
||||
virtual void dump_impl() const;
|
||||
typedef SmallVector<Stmt*, 16>::iterator body_iterator;
|
||||
body_iterator body_begin() { return Body.begin(); }
|
||||
body_iterator body_end() { return Body.end(); }
|
||||
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
/// IfStmt - This represents an if/then/else.
|
||||
|
@ -63,8 +61,15 @@ public:
|
|||
IfStmt(Expr *cond, Stmt *then, Stmt *elsev = 0)
|
||||
: Cond(cond), Then(then), Else(elsev) {}
|
||||
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
const Expr *getCond() const { return Cond; }
|
||||
const Stmt *getThen() const { return Then; }
|
||||
const Stmt *getElse() const { return Else; }
|
||||
|
||||
Expr *getCond() { return Cond; }
|
||||
Stmt *getThen() { return Then; }
|
||||
Stmt *getElse() { return Else; }
|
||||
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
|
||||
|
@ -76,8 +81,7 @@ class ReturnStmt : public Stmt {
|
|||
public:
|
||||
ReturnStmt(Expr *E = 0) : RetExpr(E) {}
|
||||
|
||||
virtual void dump_impl() const;
|
||||
virtual void visit(StmtVisitor *Visitor);
|
||||
virtual void visit(StmtVisitor &Visitor);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ namespace clang {
|
|||
|
||||
/// StmtVisitor - This class implements a simple visitor for Stmt subclasses.
|
||||
/// Since Expr derives from Stmt, this also includes support for visiting Exprs.
|
||||
struct StmtVisitor {
|
||||
class StmtVisitor {
|
||||
public:
|
||||
virtual ~StmtVisitor();
|
||||
|
||||
/// VisitNull - Visit a null pointer.
|
||||
|
@ -50,8 +51,8 @@ struct StmtVisitor {
|
|||
|
||||
// Visitation methods for various Stmt subclasses.
|
||||
virtual void VisitCompoundStmt(CompoundStmt *Node);
|
||||
virtual void VisitIfStmt(IfStmt *Node);
|
||||
virtual void VisitReturnStmt(ReturnStmt *Node);
|
||||
virtual void VisitIfStmt(IfStmt *Node);
|
||||
virtual void VisitReturnStmt(ReturnStmt *Node);
|
||||
|
||||
// Visitation methods for various Expr subclasses.
|
||||
virtual void VisitDeclRefExpr(DeclRefExpr *Node);
|
||||
|
|
Loading…
Reference in New Issue