ExprCXX.h revision 0bc735ffcfb223c0186419547abaa5c84482663e
1//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Expr interface and subclasses for C++ expressions. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_EXPRCXX_H 15#define LLVM_CLANG_AST_EXPRCXX_H 16 17#include "clang/AST/Expr.h" 18 19namespace clang { 20 21 //===--------------------------------------------------------------------===// 22 // C++ Expressions. 23 //===--------------------------------------------------------------------===// 24 25 /// CXXCastExpr - [C++ 5.2.7, 5.2.9, 5.2.10, 5.2.11] C++ Cast Operators. 26 /// 27 class CXXCastExpr : public Expr { 28 public: 29 enum Opcode { 30 DynamicCast, 31 StaticCast, 32 ReinterpretCast, 33 ConstCast 34 }; 35 private: 36 QualType Ty; 37 Opcode Opc; 38 Expr *Op; 39 SourceLocation Loc; // the location of the casting op 40 public: 41 CXXCastExpr(Opcode op, QualType ty, Expr *expr, SourceLocation l) 42 : Expr(CXXCastExprClass, ty), Ty(ty), Opc(op), Op(expr), Loc(l) {} 43 44 QualType getDestType() const { return Ty; } 45 Expr *getSubExpr() const { return Op; } 46 47 Opcode getOpcode() const { return Opc; } 48 49 /// getOpcodeStr - Turn an Opcode enum value into the string it represents, 50 /// e.g. "reinterpret_cast". 51 static const char *getOpcodeStr(Opcode Op) { 52 // FIXME: move out of line. 53 switch (Op) { 54 default: assert(0 && "Not a C++ cast expression"); 55 case CXXCastExpr::ConstCast: return "const_cast"; 56 case CXXCastExpr::DynamicCast: return "dynamic_cast"; 57 case CXXCastExpr::ReinterpretCast: return "reinterpret_cast"; 58 case CXXCastExpr::StaticCast: return "static_cast"; 59 } 60 } 61 62 virtual SourceRange getSourceRange() const { 63 return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); 64 } 65 static bool classof(const Stmt *T) { 66 return T->getStmtClass() == CXXCastExprClass; 67 } 68 static bool classof(const CXXCastExpr *) { return true; } 69 70 // Iterators 71 virtual child_iterator child_begin(); 72 virtual child_iterator child_end(); 73 }; 74 75 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 76 /// 77 class CXXBoolLiteralExpr : public Expr { 78 bool Value; 79 SourceLocation Loc; 80 public: 81 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 82 Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {} 83 84 bool getValue() const { return Value; } 85 86 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 87 88 static bool classof(const Stmt *T) { 89 return T->getStmtClass() == CXXBoolLiteralExprClass; 90 } 91 static bool classof(const CXXBoolLiteralExpr *) { return true; } 92 93 // Iterators 94 virtual child_iterator child_begin(); 95 virtual child_iterator child_end(); 96 }; 97 98} // end namespace clang 99 100#endif 101