[cfe-commits] r39343 - in /cfe/cfe/trunk: AST/ASTContext.cpp AST/Expr.cpp AST/SemaType.cpp Sema/SemaType.cpp include/clang/AST/ASTContext.h include/clang/AST/Expr.h include/clang/AST/Stmt.h
snaroff at cs.uiuc.edu
snaroff at cs.uiuc.edu
Wed Jul 11 09:43:22 PDT 2007
Author: snaroff
Date: Wed Jul 11 11:43:22 2007
New Revision: 39343
URL: http://llvm.org/viewvc/llvm-project?rev=39343&view=rev
Log:
Added isa<> support for Statements and Expressions. This involved:
- adding enum constants & instance data to Stmt.
- adding classof() functions to all Stmt's.
- modifying contructors to pass the appropriate enum as an arg.
Also tightened up a couple "void *" declarations/casts for arrays.
Modified:
cfe/cfe/trunk/AST/ASTContext.cpp
cfe/cfe/trunk/AST/Expr.cpp
cfe/cfe/trunk/AST/SemaType.cpp
cfe/cfe/trunk/Sema/SemaType.cpp
cfe/cfe/trunk/include/clang/AST/ASTContext.h
cfe/cfe/trunk/include/clang/AST/Expr.h
cfe/cfe/trunk/include/clang/AST/Stmt.h
Modified: cfe/cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/ASTContext.cpp?rev=39343&r1=39342&r2=39343&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/cfe/trunk/AST/ASTContext.cpp Wed Jul 11 11:43:22 2007
@@ -160,14 +160,14 @@
/// getArrayType - Return the unique reference to the type for an array of the
/// specified element type.
TypeRef ASTContext::getArrayType(TypeRef EltTy,ArrayType::ArraySizeModifier ASM,
- unsigned EltTypeQuals, void *NumElts) {
+ unsigned EltTypeQuals, Expr *NumElts) {
#warning "IGNORING SIZE"
// Unique array types, to guarantee there is only one array of a particular
// structure.
FoldingSetNodeID ID;
ArrayType::Profile(ID, ASM, EltTypeQuals, EltTy);
-
+
void *InsertPos = 0;
if (ArrayType *ATP = ArrayTypes.FindNodeOrInsertPos(ID, InsertPos))
return ATP;
Modified: cfe/cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Expr.cpp?rev=39343&r1=39342&r2=39343&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:43:22 2007
@@ -21,7 +21,8 @@
// Primary Expressions.
//===----------------------------------------------------------------------===//
-StringLiteral::StringLiteral(const char *strData, unsigned byteLength, bool Wide) {
+StringLiteral::StringLiteral(const char *strData, unsigned byteLength,
+ bool Wide) : Expr(StringLiteralClass) {
// OPTIMIZE: could allocate this appended to the StringLiteral.
char *AStrData = new char[byteLength];
memcpy(AStrData, strData, byteLength);
@@ -72,7 +73,7 @@
//===----------------------------------------------------------------------===//
CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs)
- : Fn(fn), NumArgs(numargs) {
+ : Expr(CallExprClass), Fn(fn), NumArgs(numargs) {
Args = new Expr*[numargs];
for (unsigned i = 0; i != numargs; ++i)
Args[i] = args[i];
Modified: cfe/cfe/trunk/AST/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaType.cpp?rev=39343&r1=39342&r2=39343&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaType.cpp (original)
+++ cfe/cfe/trunk/AST/SemaType.cpp Wed Jul 11 11:43:22 2007
@@ -141,7 +141,8 @@
}
}
- T = Context.getArrayType(T, ASM, ATI.TypeQuals, ATI.NumElts);
+ T = Context.getArrayType(T, ASM, ATI.TypeQuals,
+ static_cast<Expr *>(ATI.NumElts));
break;
}
case DeclaratorChunk::Function:
Modified: cfe/cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaType.cpp?rev=39343&r1=39342&r2=39343&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaType.cpp Wed Jul 11 11:43:22 2007
@@ -141,7 +141,8 @@
}
}
- T = Context.getArrayType(T, ASM, ATI.TypeQuals, ATI.NumElts);
+ T = Context.getArrayType(T, ASM, ATI.TypeQuals,
+ static_cast<Expr *>(ATI.NumElts));
break;
}
case DeclaratorChunk::Function:
Modified: cfe/cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/ASTContext.h?rev=39343&r1=39342&r2=39343&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ASTContext.h Wed Jul 11 11:43:22 2007
@@ -16,6 +16,7 @@
#include "clang/AST/Builtins.h"
#include "clang/AST/Type.h"
+#include "clang/AST/Expr.h"
#include <vector>
namespace llvm {
@@ -59,7 +60,7 @@
/// getArrayType - Return the unique reference to the type for an array of the
/// specified element type.
TypeRef getArrayType(TypeRef EltTy, ArrayType::ArraySizeModifier ASM,
- unsigned EltTypeQuals, void *NumElts);
+ unsigned EltTypeQuals, Expr *NumElts);
/// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'.
///
Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=39343&r1=39342&r2=39343&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:43:22 2007
@@ -29,10 +29,15 @@
class Expr : public Stmt {
/// TODO: Type.
public:
- Expr() {}
+ Expr() : Stmt(ExprClass) {}
+ Expr(StmtClass SC) : Stmt(SC) {}
~Expr() {}
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ExprClass;
+ }
+ static bool classof(const Expr *) { return true; }
};
//===----------------------------------------------------------------------===//
@@ -44,23 +49,35 @@
class DeclRefExpr : public Expr {
Decl *D;
public:
- DeclRefExpr(Decl *d) : D(d) {}
+ DeclRefExpr(Decl *d) : Expr(DeclRefExprClass), D(d) {}
Decl *getDecl() const { return D; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == DeclRefExprClass;
+ }
+ static bool classof(const DeclRefExpr *) { return true; }
};
class IntegerLiteral : public Expr {
public:
- IntegerLiteral() {}
+ IntegerLiteral() : Expr(IntegerLiteralClass) {}
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == IntegerLiteralClass;
+ }
+ static bool classof(const IntegerLiteral *) { return true; }
};
class FloatingLiteral : public Expr {
public:
- FloatingLiteral() {}
+ FloatingLiteral() : Expr(FloatingLiteralClass) {}
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == FloatingLiteralClass;
+ }
+ static bool classof(const FloatingLiteral *) { return true; }
};
class StringLiteral : public Expr {
@@ -76,6 +93,10 @@
bool isWide() const { return IsWide; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == StringLiteralClass;
+ }
+ static bool classof(const StringLiteral *) { return true; }
};
/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This
@@ -85,11 +106,15 @@
Expr *Val;
public:
ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
- : L(l), R(r), Val(val) {}
+ : Expr(ParenExprClass), L(l), R(r), Val(val) {}
Expr *getSubExpr() { return Val; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ParenExprClass;
+ }
+ static bool classof(const ParenExpr *) { return true; }
};
@@ -111,7 +136,7 @@
};
UnaryOperator(Expr *input, Opcode opc)
- : Val(input), Opc(opc) {}
+ : Expr(UnaryOperatorClass), Val(input), Opc(opc) {}
/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
/// corresponds to, e.g. "sizeof" or "[pre]++"
@@ -127,7 +152,11 @@
bool isPostfix() const { return isPostfix(Opc); }
virtual void visit(StmtVisitor &Visitor);
-
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == UnaryOperatorClass;
+ }
+ static bool classof(const UnaryOperator *) { return true; }
+
private:
Expr *Val;
Opcode Opc;
@@ -139,13 +168,18 @@
bool isSizeof; // true if sizeof, false if alignof.
TypeRef Ty;
public:
- SizeOfAlignOfTypeExpr(bool issizeof, TypeRef ty) : isSizeof(issizeof), Ty(ty){
- }
+ SizeOfAlignOfTypeExpr(bool issizeof, TypeRef ty) :
+ Expr(SizeOfAlignOfTypeExprClass),
+ isSizeof(issizeof), Ty(ty) {}
bool isSizeOf() const { return isSizeof; }
TypeRef getArgumentType() const { return Ty; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == SizeOfAlignOfTypeExprClass;
+ }
+ static bool classof(const SizeOfAlignOfTypeExpr *) { return true; }
};
//===----------------------------------------------------------------------===//
@@ -156,12 +190,18 @@
class ArraySubscriptExpr : public Expr {
Expr *Base, *Idx;
public:
- ArraySubscriptExpr(Expr *base, Expr *idx) : Base(base), Idx(idx) {}
+ ArraySubscriptExpr(Expr *base, Expr *idx) :
+ Expr(ArraySubscriptExprClass),
+ Base(base), Idx(idx) {}
Expr *getBase() { return Base; }
Expr *getIdx() { return Idx; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ArraySubscriptExprClass;
+ }
+ static bool classof(const ArraySubscriptExpr *) { return true; }
};
@@ -194,6 +234,10 @@
unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == CallExprClass;
+ }
+ static bool classof(const CallExpr *) { return true; }
};
/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.
@@ -204,14 +248,18 @@
bool IsArrow; // True if this is "X->F", false if this is "X.F".
public:
MemberExpr(Expr *base, bool isarrow, Decl *memberdecl)
- : Base(base), MemberDecl(memberdecl), IsArrow(isarrow) {
- }
+ : Expr(MemberExprClass),
+ Base(base), MemberDecl(memberdecl), IsArrow(isarrow) {}
Expr *getBase() { return Base; }
Decl *getMemberDecl() { return MemberDecl; }
bool isArrow() const { return IsArrow; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == MemberExprClass;
+ }
+ static bool classof(const MemberExpr *) { return true; }
};
/// CastExpr - [C99 6.5.4] Cast Operators.
@@ -220,12 +268,16 @@
TypeRef Ty;
Expr *Op;
public:
- CastExpr(TypeRef ty, Expr *op) : Ty(ty), Op(op) {}
+ CastExpr(TypeRef ty, Expr *op) : Expr(CastExprClass), Ty(ty), Op(op) {}
TypeRef getDestType() const { return Ty; }
Expr *getSubExpr() { return Op; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == CastExprClass;
+ }
+ static bool classof(const CastExpr *) { return true; }
};
@@ -253,7 +305,7 @@
};
BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc)
- : LHS(lhs), RHS(rhs), Opc(opc) {}
+ : Expr(BinaryOperatorClass), LHS(lhs), RHS(rhs), Opc(opc) {}
/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
/// corresponds to, e.g. "<<=".
@@ -264,7 +316,11 @@
Expr *getRHS() { return RHS; }
virtual void visit(StmtVisitor &Visitor);
-
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == BinaryOperatorClass;
+ }
+ static bool classof(const BinaryOperator *) { return true; }
+
private:
Expr *LHS, *RHS;
Opcode Opc;
@@ -277,14 +333,17 @@
Expr *Cond, *LHS, *RHS; // Left/Middle/Right hand sides.
public:
ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs)
- : Cond(cond), LHS(lhs), RHS(rhs) {}
+ : Expr(ConditionalOperatorClass), Cond(cond), LHS(lhs), RHS(rhs) {}
Expr *getCond() { return Cond; }
Expr *getLHS() { return LHS; }
Expr *getRHS() { return RHS; }
-
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ConditionalOperatorClass;
+ }
+ static bool classof(const ConditionalOperator *) { return true; }
};
Modified: cfe/cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Stmt.h?rev=39343&r1=39342&r2=39343&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Stmt.h Wed Jul 11 11:43:22 2007
@@ -28,14 +28,27 @@
///
class Stmt {
public:
- Stmt() {}
+ enum StmtClass {
+#define STMT(CLASS, PARENT) CLASS##Class,
+#include "clang/AST/StmtNodes.def"
+ LastStmtClass
+ };
+private:
+ StmtClass sClass;
+public:
+ Stmt(StmtClass SC) : sClass(SC) {}
virtual ~Stmt() {}
-
+
+ StmtClass getStmtClass() const { return sClass; }
+
void dump() const;
void print(std::ostream &OS) const;
// Implement visitor support.
virtual void visit(StmtVisitor &Visitor);
+
+ // Implement isa<T> support.
+ static bool classof(const Stmt *) { return true; }
};
/// CompoundStmt - This represents a group of statements like { stmt stmt }.
@@ -44,13 +57,17 @@
SmallVector<Stmt*, 16> Body;
public:
CompoundStmt(Stmt **StmtStart, unsigned NumStmts)
- : Body(StmtStart, StmtStart+NumStmts) {}
+ : Stmt(CompoundStmtClass), Body(StmtStart, StmtStart+NumStmts) {}
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);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == CompoundStmtClass;
+ }
+ static bool classof(const CompoundStmt *) { return true; }
};
class CaseStmt : public Stmt {
@@ -59,23 +76,31 @@
Stmt *SubStmt;
public:
CaseStmt(Expr *lhs, Expr *rhs, Stmt *substmt)
- : LHSVal(lhs), RHSVal(rhs), SubStmt(substmt) {}
+ : Stmt(CaseStmtClass), LHSVal(lhs), RHSVal(rhs), SubStmt(substmt) {}
Expr *getLHS() { return LHSVal; }
Expr *getRHS() { return RHSVal; }
Stmt *getSubStmt() { return SubStmt; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == CaseStmtClass;
+ }
+ static bool classof(const CaseStmt *) { return true; }
};
class DefaultStmt : public Stmt {
Stmt *SubStmt;
public:
- DefaultStmt(Stmt *substmt) : SubStmt(substmt) {}
+ DefaultStmt(Stmt *substmt) : Stmt(DefaultStmtClass), SubStmt(substmt) {}
Stmt *getSubStmt() { return SubStmt; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == DefaultStmtClass;
+ }
+ static bool classof(const DefaultStmt *) { return true; }
};
class LabelStmt : public Stmt {
@@ -83,12 +108,16 @@
Stmt *SubStmt;
public:
LabelStmt(IdentifierInfo *label, Stmt *substmt)
- : Label(label), SubStmt(substmt) {}
+ : Stmt(LabelStmtClass), Label(label), SubStmt(substmt) {}
IdentifierInfo *getLabel() { return Label; }
Stmt *getSubStmt() { return SubStmt; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == LabelStmtClass;
+ }
+ static bool classof(const LabelStmt *) { return true; }
};
@@ -99,7 +128,7 @@
Stmt *Then, *Else;
public:
IfStmt(Expr *cond, Stmt *then, Stmt *elsev = 0)
- : Cond(cond), Then(then), Else(elsev) {}
+ : Stmt(IfStmtClass), Cond(cond), Then(then), Else(elsev) {}
const Expr *getCond() const { return Cond; }
const Stmt *getThen() const { return Then; }
@@ -110,6 +139,10 @@
Stmt *getElse() { return Else; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == IfStmtClass;
+ }
+ static bool classof(const IfStmt *) { return true; }
};
/// SwitchStmt - This represents a 'switch' stmt.
@@ -119,12 +152,16 @@
Stmt *Body;
public:
SwitchStmt(Expr *cond, Stmt *body)
- : Cond(cond), Body(body) {}
+ : Stmt(SwitchStmtClass), Cond(cond), Body(body) {}
Expr *getCond() { return Cond; }
Stmt *getBody() { return Body; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == SwitchStmtClass;
+ }
+ static bool classof(const SwitchStmt *) { return true; }
};
@@ -135,12 +172,16 @@
Stmt *Body;
public:
WhileStmt(Expr *cond, Stmt *body)
- : Cond(cond), Body(body) {}
+ : Stmt(WhileStmtClass), Cond(cond), Body(body) {}
Expr *getCond() { return Cond; }
Stmt *getBody() { return Body; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == WhileStmtClass;
+ }
+ static bool classof(const WhileStmt *) { return true; }
};
/// DoStmt - This represents a 'do/while' stmt.
@@ -150,12 +191,16 @@
Expr *Cond;
public:
DoStmt(Stmt *body, Expr *cond)
- : Body(body), Cond(cond) {}
+ : Stmt(DoStmtClass), Body(body), Cond(cond) {}
Stmt *getBody() { return Body; }
Expr *getCond() { return Cond; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == DoStmtClass;
+ }
+ static bool classof(const DoStmt *) { return true; }
};
@@ -167,7 +212,8 @@
Stmt *Body;
public:
ForStmt(Stmt *first, Expr *second, Expr *third, Stmt *body)
- : First(first), Second(second), Third(third), Body(body) {}
+ : Stmt(ForStmtClass),
+ First(first), Second(second), Third(third), Body(body) {}
Stmt *getFirst() { return First; }
Expr *getSecond() { return Second; }
@@ -175,6 +221,10 @@
Stmt *getBody() { return Body; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ForStmtClass;
+ }
+ static bool classof(const ForStmt *) { return true; }
};
/// GotoStmt - This represents a direct goto.
@@ -182,11 +232,15 @@
class GotoStmt : public Stmt {
IdentifierInfo *Label;
public:
- GotoStmt(IdentifierInfo *label) : Label(label) {}
+ GotoStmt(IdentifierInfo *label) : Stmt(GotoStmtClass), Label(label) {}
IdentifierInfo *getLabel() { return Label; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == GotoStmtClass;
+ }
+ static bool classof(const GotoStmt *) { return true; }
};
/// IndirectGotoStmt - This represents an indirect goto.
@@ -194,11 +248,16 @@
class IndirectGotoStmt : public Stmt {
Expr *Target;
public:
- IndirectGotoStmt(Expr *target) : Target(target) {}
+ IndirectGotoStmt(Expr *target) : Stmt(IndirectGotoStmtClass),
+ Target(target) {}
Expr *getTarget() { return Target; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == IndirectGotoStmtClass;
+ }
+ static bool classof(const IndirectGotoStmt *) { return true; }
};
@@ -206,14 +265,24 @@
///
class ContinueStmt : public Stmt {
public:
+ ContinueStmt() : Stmt(ContinueStmtClass) {}
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ContinueStmtClass;
+ }
+ static bool classof(const ContinueStmt *) { return true; }
};
/// BreakStmt - This represents a break.
///
class BreakStmt : public Stmt {
public:
+ BreakStmt() : Stmt(BreakStmtClass) {}
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == BreakStmtClass;
+ }
+ static bool classof(const BreakStmt *) { return true; }
};
@@ -222,11 +291,15 @@
class ReturnStmt : public Stmt {
Expr *RetExpr;
public:
- ReturnStmt(Expr *E = 0) : RetExpr(E) {}
+ ReturnStmt(Expr *E = 0) : Stmt(ReturnStmtClass), RetExpr(E) {}
Expr *getRetValue() { return RetExpr; }
virtual void visit(StmtVisitor &Visitor);
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ReturnStmtClass;
+ }
+ static bool classof(const ReturnStmt *) { return true; }
};
More information about the cfe-commits
mailing list