diff options
author | Anders Carlsson <andersca@mac.com> | 2009-07-31 00:48:10 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-07-31 00:48:10 +0000 |
commit | cdef2b75aa60cde1ca00e0aa3f89139ac89c6ae4 (patch) | |
tree | 495c26d02b13cb3150354187e8c586b665e17387 /include/clang | |
parent | 82ec2e99084996eecbdf3a304f3cbba8c16c2f6b (diff) |
Add a CastKind enum to CastExpr. Right now it's not used for much but it will be :)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77650 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/AST/Expr.h | 38 | ||||
-rw-r--r-- | include/clang/AST/ExprCXX.h | 27 |
2 files changed, 45 insertions, 20 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index c25a66aa42..33450866ae 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1154,9 +1154,27 @@ public: /// representation in the source code (ExplicitCastExpr's derived /// classes). class CastExpr : public Expr { +public: + /// CastKind - the kind of cast this represents. + enum CastKind { + /// CK_Unknown - Unknown cast kind. + /// FIXME: The goal is to get rid of this and make all casts have a + /// kind so that the AST client doesn't have to try to figure out what's + /// going on. + CK_Unknown, + + /// CK_BitCast - Used for reinterpret_cast. + CK_BitCast, + + /// CK_NoOp - Used for const_cast. + CK_NoOp + }; + +private: + CastKind Kind; Stmt *Op; protected: - CastExpr(StmtClass SC, QualType ty, Expr *op) : + CastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op) : Expr(SC, ty, // Cast expressions are type-dependent if the type is // dependent (C++ [temp.dep.expr]p3). @@ -1164,13 +1182,16 @@ protected: // Cast expressions are value-dependent if the type is // dependent or if the subexpression is value-dependent. ty->isDependentType() || (op && op->isValueDependent())), - Op(op) {} + Kind(kind), Op(op) {} /// \brief Construct an empty cast. CastExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) { } public: + CastKind getCastKind() const { return Kind; } + void setCastKind(CastKind K) { Kind = K; } + Expr *getSubExpr() { return cast<Expr>(Op); } const Expr *getSubExpr() const { return cast<Expr>(Op); } void setSubExpr(Expr *E) { Op = E; } @@ -1213,8 +1234,8 @@ class ImplicitCastExpr : public CastExpr { bool LvalueCast; public: - ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) : - CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) { } + ImplicitCastExpr(QualType ty, CastKind kind, Expr *op, bool Lvalue) : + CastExpr(ImplicitCastExprClass, ty, kind, op), LvalueCast(Lvalue) { } /// \brief Construct an empty implicit cast. explicit ImplicitCastExpr(EmptyShell Shell) @@ -1259,8 +1280,9 @@ class ExplicitCastExpr : public CastExpr { QualType TypeAsWritten; protected: - ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy) - : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {} + ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind, Expr *op, + QualType writtenTy) + : CastExpr(SC, exprTy, kind, op), TypeAsWritten(writtenTy) {} /// \brief Construct an empty explicit cast. ExplicitCastExpr(StmtClass SC, EmptyShell Shell) @@ -1291,9 +1313,9 @@ class CStyleCastExpr : public ExplicitCastExpr { SourceLocation LPLoc; // the location of the left paren SourceLocation RPLoc; // the location of the right paren public: - CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy, + CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op, QualType writtenTy, SourceLocation l, SourceLocation r) : - ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy), + ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, writtenTy), LPLoc(l), RPLoc(r) {} /// \brief Construct an empty C-style explicit cast. diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 86f2d59780..ae1c04a175 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -112,9 +112,9 @@ private: SourceLocation Loc; // the location of the casting op protected: - CXXNamedCastExpr(StmtClass SC, QualType ty, Expr *op, QualType writtenTy, - SourceLocation l) - : ExplicitCastExpr(SC, ty, op, writtenTy), Loc(l) {} + CXXNamedCastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op, + QualType writtenTy, SourceLocation l) + : ExplicitCastExpr(SC, ty, kind, op, writtenTy), Loc(l) {} public: const char *getCastName() const; @@ -148,8 +148,9 @@ public: /// @c static_cast<int>(1.0). class CXXStaticCastExpr : public CXXNamedCastExpr { public: - CXXStaticCastExpr(QualType ty, Expr *op, QualType writtenTy, SourceLocation l) - : CXXNamedCastExpr(CXXStaticCastExprClass, ty, op, writtenTy, l) {} + CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op, QualType writtenTy, + SourceLocation l) + : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, writtenTy, l) {} static bool classof(const Stmt *T) { return T->getStmtClass() == CXXStaticCastExprClass; @@ -165,8 +166,9 @@ public: /// @c dynamic_cast<Derived*>(BasePtr). class CXXDynamicCastExpr : public CXXNamedCastExpr { public: - CXXDynamicCastExpr(QualType ty, Expr *op, QualType writtenTy, SourceLocation l) - : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, op, writtenTy, l) {} + CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op, QualType writtenTy, + SourceLocation l) + : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, writtenTy, l) {} static bool classof(const Stmt *T) { return T->getStmtClass() == CXXDynamicCastExprClass; @@ -184,7 +186,8 @@ class CXXReinterpretCastExpr : public CXXNamedCastExpr { public: CXXReinterpretCastExpr(QualType ty, Expr *op, QualType writtenTy, SourceLocation l) - : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, op, writtenTy, l) {} + : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, CK_BitCast, op, + writtenTy, l) {} static bool classof(const Stmt *T) { return T->getStmtClass() == CXXReinterpretCastExprClass; @@ -201,7 +204,7 @@ class CXXConstCastExpr : public CXXNamedCastExpr { public: CXXConstCastExpr(QualType ty, Expr *op, QualType writtenTy, SourceLocation l) - : CXXNamedCastExpr(CXXConstCastExprClass, ty, op, writtenTy, l) {} + : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op, writtenTy, l) {} static bool classof(const Stmt *T) { return T->getStmtClass() == CXXConstCastExprClass; @@ -529,9 +532,9 @@ class CXXFunctionalCastExpr : public ExplicitCastExpr { SourceLocation RParenLoc; public: CXXFunctionalCastExpr(QualType ty, QualType writtenTy, - SourceLocation tyBeginLoc, Expr *castExpr, - SourceLocation rParenLoc) : - ExplicitCastExpr(CXXFunctionalCastExprClass, ty, castExpr, writtenTy), + SourceLocation tyBeginLoc, CastKind kind, + Expr *castExpr, SourceLocation rParenLoc) : + ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr, writtenTy), TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } |