1 //===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the Expr interface and subclasses for C++ expressions.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_EXPRCXX_H
15 #define LLVM_CLANG_AST_EXPRCXX_H
17 #include "clang/AST/Expr.h"
21 //===--------------------------------------------------------------------===//
23 //===--------------------------------------------------------------------===//
25 /// CXXCastExpr - [C++ 5.2.7, 5.2.9, 5.2.10, 5.2.11] C++ Cast Operators.
27 class CXXCastExpr : public Expr {
39 SourceLocation Loc; // the location of the casting op
41 CXXCastExpr(Opcode op, QualType ty, Expr *expr, SourceLocation l)
42 : Expr(CXXCastExprClass, ty), Ty(ty), Opc(op), Op(expr), Loc(l) {}
44 QualType getDestType() const { return Ty; }
45 Expr *getSubExpr() const { return Op; }
47 Opcode getOpcode() const { return Opc; }
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.
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";
62 virtual SourceRange getSourceRange() const {
63 return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
65 static bool classof(const Stmt *T) {
66 return T->getStmtClass() == CXXCastExprClass;
68 static bool classof(const CXXCastExpr *) { return true; }
71 virtual child_iterator child_begin();
72 virtual child_iterator child_end();
75 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
77 class CXXBoolLiteralExpr : public Expr {
81 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
82 Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {}
84 bool getValue() const { return Value; }
86 virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
88 static bool classof(const Stmt *T) {
89 return T->getStmtClass() == CXXBoolLiteralExprClass;
91 static bool classof(const CXXBoolLiteralExpr *) { return true; }
94 virtual child_iterator child_begin();
95 virtual child_iterator child_end();
98 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
99 /// 'throw' and 'throw' assignment-expression. When
100 /// assignment-expression isn't present, Op will be null.
102 class CXXThrowExpr : public Expr {
104 SourceLocation ThrowLoc;
106 // Ty is the void type which is used as the result type of the
107 // exepression. The l is the location of the throw keyword. expr
108 // can by null, if the optional expression to throw isn't present.
109 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
110 Expr(CXXThrowExprClass, Ty), Op(expr), ThrowLoc(l) {}
111 const Expr *getSubExpr() const { return Op; }
112 Expr *getSubExpr() { return Op; }
114 virtual SourceRange getSourceRange() const {
115 if (getSubExpr() == 0)
116 return SourceRange(ThrowLoc, ThrowLoc);
117 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
120 static bool classof(const Stmt *T) {
121 return T->getStmtClass() == CXXThrowExprClass;
123 static bool classof(const CXXThrowExpr *) { return true; }
126 virtual child_iterator child_begin();
127 virtual child_iterator child_end();
130 } // end namespace clang