ExprCXX.h revision 4076dacf1497fb95cb298b9d964fbdbdaf9bde6c
1ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
2ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//
3ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//                     The LLVM Compiler Infrastructure
4ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//
5ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown// This file is distributed under the University of Illinois Open Source
6ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown// License. See LICENSE.TXT for details.
7ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//
8ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//===----------------------------------------------------------------------===//
9ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//
10436e89c602e787e7a27dd6624b09beed41a0da8aDmitriy Ivanov//  This file defines the Expr interface and subclasses for C++ expressions.
11ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//
12ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//===----------------------------------------------------------------------===//
13ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
14ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown#ifndef LLVM_CLANG_AST_EXPRCXX_H
15ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown#define LLVM_CLANG_AST_EXPRCXX_H
16ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
17ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown#include "clang/Basic/TypeTraits.h"
18ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown#include "clang/AST/Expr.h"
19ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown#include "clang/AST/UnresolvedSet.h"
20ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown#include "clang/AST/TemplateBase.h"
21ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
22ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownnamespace clang {
23ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
24ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  class CXXConstructorDecl;
25ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  class CXXDestructorDecl;
26ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  class CXXMethodDecl;
27ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  class CXXTemporary;
28ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  class TemplateArgumentListInfo;
29ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
30ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//===--------------------------------------------------------------------===//
31ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown// C++ Expressions.
32ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown//===--------------------------------------------------------------------===//
33ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
34ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// \brief A call to an overloaded operator written using operator
35ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// syntax.
36ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown///
37ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// Represents a call to an overloaded operator written using operator
38ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
39ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// normal call, this AST node provides better information about the
40ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// syntactic representation of the call.
41ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown///
42ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// In a C++ template, this expression node kind will be used whenever
43ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// any of the arguments are type-dependent. In this case, the
44ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// function itself will be a (possibly empty) set of functions and
45ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// function templates that were found by name lookup at template
46ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// definition time.
47ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownclass CXXOperatorCallExpr : public CallExpr {
48ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// \brief The overloaded operator.
49ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  OverloadedOperatorKind Operator;
50ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
51ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownpublic:
52ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
53ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                      Expr **args, unsigned numargs, QualType t,
54ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                      SourceLocation operatorloc)
55ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : CallExpr(C, CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc),
56ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown      Operator(Op) {}
57ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
58ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    CallExpr(C, CXXOperatorCallExprClass, Empty) { }
59ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
60ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
61ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// getOperator - Returns the kind of overloaded operator that this
62ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// expression refers to.
63ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  OverloadedOperatorKind getOperator() const { return Operator; }
64ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
65ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
66ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// getOperatorLoc - Returns the location of the operator symbol in
67ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// the expression. When @c getOperator()==OO_Call, this is the
68ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// location of the right parentheses; when @c
69ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// getOperator()==OO_Subscript, this is the location of the right
70ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// bracket.
71ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  SourceLocation getOperatorLoc() const { return getRParenLoc(); }
72ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
73ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  virtual SourceRange getSourceRange() const;
74ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
75ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const Stmt *T) {
76436e89c602e787e7a27dd6624b09beed41a0da8aDmitriy Ivanov    return T->getStmtClass() == CXXOperatorCallExprClass;
77436e89c602e787e7a27dd6624b09beed41a0da8aDmitriy Ivanov  }
78ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const CXXOperatorCallExpr *) { return true; }
79ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown};
80ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
81ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// CXXMemberCallExpr - Represents a call to a member function that
82ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// may be written either with member call syntax (e.g., "obj.func()"
83ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// or "objptr->func()") or with normal function-call syntax
84ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// ("func()") within a member function that ends up calling a member
85ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// function. The callee in either case is a MemberExpr that contains
86ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// both the object argument and the member function, while the
87ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// arguments are the arguments within the parentheses (not including
88ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// the object argument).
89eb0bae136f4eeaaf29761dddb148b118fb824632Dmitriy Ivanovclass CXXMemberCallExpr : public CallExpr {
90eb0bae136f4eeaaf29761dddb148b118fb824632Dmitriy Ivanovpublic:
91eb0bae136f4eeaaf29761dddb148b118fb824632Dmitriy Ivanov  CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs,
92eb0bae136f4eeaaf29761dddb148b118fb824632Dmitriy Ivanov                    QualType t, SourceLocation rparenloc)
93eb0bae136f4eeaaf29761dddb148b118fb824632Dmitriy Ivanov    : CallExpr(C, CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) {}
94eb0bae136f4eeaaf29761dddb148b118fb824632Dmitriy Ivanov
95ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
96ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : CallExpr(C, CXXMemberCallExprClass, Empty) { }
97ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
98ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// getImplicitObjectArgument - Retrieves the implicit object
99ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// argument for the member call. For example, in "x.f(5)", this
100ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// operation would return "x".
101ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  Expr *getImplicitObjectArgument();
102ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
103ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  virtual SourceRange getSourceRange() const;
104ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
105ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const Stmt *T) {
106ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return T->getStmtClass() == CXXMemberCallExprClass;
107ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
108436e89c602e787e7a27dd6624b09beed41a0da8aDmitriy Ivanov  static bool classof(const CXXMemberCallExpr *) { return true; }
109ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown};
110ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
111ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
112ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
113ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// const_cast.
114ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown///
115ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// This abstract class is inherited by all of the classes
116ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// representing "named" casts, e.g., CXXStaticCastExpr,
117ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
118ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownclass CXXNamedCastExpr : public ExplicitCastExpr {
119ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownprivate:
120ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  SourceLocation Loc; // the location of the casting op
121ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
122ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownprotected:
123ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXNamedCastExpr(StmtClass SC, QualType ty, CastKind kind, Expr *op,
124ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                   unsigned PathSize, TypeSourceInfo *writtenTy,
125ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                   SourceLocation l)
126ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : ExplicitCastExpr(SC, ty, kind, op, PathSize, writtenTy), Loc(l) {}
127ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
128ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
129ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : ExplicitCastExpr(SC, Shell, PathSize) { }
130ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
131ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownpublic:
132ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  const char *getCastName() const;
133ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
134ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// \brief Retrieve the location of the cast operator keyword, e.g.,
135ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// "static_cast".
136ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  SourceLocation getOperatorLoc() const { return Loc; }
137ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  void setOperatorLoc(SourceLocation L) { Loc = L; }
138ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
139ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  virtual SourceRange getSourceRange() const {
140ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
141ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
142ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const Stmt *T) {
143ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    switch (T->getStmtClass()) {
144ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    case CXXStaticCastExprClass:
145ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    case CXXDynamicCastExprClass:
146ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    case CXXReinterpretCastExprClass:
147ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    case CXXConstCastExprClass:
148ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown      return true;
149ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    default:
150ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown      return false;
151ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    }
152ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
153ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const CXXNamedCastExpr *) { return true; }
154ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown};
155ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
156ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]).
157ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown///
158ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// This expression node represents a C++ static cast, e.g.,
159ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// @c static_cast<int>(1.0).
160ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownclass CXXStaticCastExpr : public CXXNamedCastExpr {
161663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng  CXXStaticCastExpr(QualType ty, CastKind kind, Expr *op,
162663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng                    unsigned pathSize, TypeSourceInfo *writtenTy,
163663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng                    SourceLocation l)
164663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng    : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, pathSize,
165663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng                       writtenTy, l) {}
166663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng
167663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng  explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
168663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
169663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng
170663860b1408516d02ebfcb3a9999a134e6cfb223Ben Chengpublic:
171663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng  static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
172ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                   CastKind K, Expr *Op,
173ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                   const CXXCastPath *Path,
174ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                   TypeSourceInfo *Written, SourceLocation L);
175ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
176ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                        unsigned PathSize);
177ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
178ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const Stmt *T) {
179ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return T->getStmtClass() == CXXStaticCastExprClass;
180ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
181ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const CXXStaticCastExpr *) { return true; }
182ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown};
183ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
184ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
185ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// (C++ [expr.dynamic.cast]), which may perform a run-time check to
186ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// determine how to perform the type cast.
187ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown///
188ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// This expression node represents a dynamic cast, e.g.,
189ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// @c dynamic_cast<Derived*>(BasePtr).
190ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownclass CXXDynamicCastExpr : public CXXNamedCastExpr {
191ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXDynamicCastExpr(QualType ty, CastKind kind, Expr *op,
192ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                     unsigned pathSize, TypeSourceInfo *writtenTy,
193ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                     SourceLocation l)
194ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, pathSize,
195ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                       writtenTy, l) {}
196ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
197ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
198ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
199ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
200ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownpublic:
201ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
202ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                    CastKind Kind, Expr *Op,
203ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                    const CXXCastPath *Path,
204ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                    TypeSourceInfo *Written, SourceLocation L);
205ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
206ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
207ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                         unsigned pathSize);
208ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
209ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const Stmt *T) {
210ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return T->getStmtClass() == CXXDynamicCastExprClass;
211ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
212ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const CXXDynamicCastExpr *) { return true; }
213ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown};
214ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
215ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
216ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// [expr.reinterpret.cast]), which provides a differently-typed view
217ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// of a value but performs no actual work at run time.
218ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown///
219ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// This expression node represents a reinterpret cast, e.g.,
220ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// @c reinterpret_cast<int>(VoidPtr).
221ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownclass CXXReinterpretCastExpr : public CXXNamedCastExpr {
222ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXReinterpretCastExpr(QualType ty, CastKind kind, Expr *op,
223ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                         unsigned pathSize,
224ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                         TypeSourceInfo *writtenTy, SourceLocation l)
225ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op, pathSize,
226ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                       writtenTy, l) {}
227ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
228ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
229ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
230ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
231ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownpublic:
232ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
233ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                        CastKind Kind, Expr *Op,
234ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                        const CXXCastPath *Path,
235ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                 TypeSourceInfo *WrittenTy, SourceLocation L);
236ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
237ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                             unsigned pathSize);
238ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
239ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const Stmt *T) {
240ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return T->getStmtClass() == CXXReinterpretCastExprClass;
241ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
242ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const CXXReinterpretCastExpr *) { return true; }
243b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov};
244ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
245ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
246ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// which can remove type qualifiers but does not change the underlying value.
247ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown///
248ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// This expression node represents a const cast, e.g.,
249b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov/// @c const_cast<char*>(PtrToConstChar).
250b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanovclass CXXConstCastExpr : public CXXNamedCastExpr {
251b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  CXXConstCastExpr(QualType ty, Expr *op, TypeSourceInfo *writtenTy,
252b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov                   SourceLocation l)
253b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov    : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op,
254b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov                       0, writtenTy, l) {}
255ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
256ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  explicit CXXConstCastExpr(EmptyShell Empty)
257ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
258ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
259ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownpublic:
260ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static CXXConstCastExpr *Create(ASTContext &Context, QualType T, Expr *Op,
261ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown                                  TypeSourceInfo *WrittenTy, SourceLocation L);
262ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
263ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
264ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const Stmt *T) {
265ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return T->getStmtClass() == CXXConstCastExprClass;
266ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
267ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const CXXConstCastExpr *) { return true; }
268ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown};
269ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
270ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
271ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown///
272ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownclass CXXBoolLiteralExpr : public Expr {
273ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  bool Value;
274ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  SourceLocation Loc;
275436e89c602e787e7a27dd6624b09beed41a0da8aDmitriy Ivanovpublic:
276ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
277ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {}
278ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
279ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  explicit CXXBoolLiteralExpr(EmptyShell Empty)
280436e89c602e787e7a27dd6624b09beed41a0da8aDmitriy Ivanov    : Expr(CXXBoolLiteralExprClass, Empty) { }
281ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
282ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  bool getValue() const { return Value; }
283ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  void setValue(bool V) { Value = V; }
284ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
285ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
286ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
287ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  SourceLocation getLocation() const { return Loc; }
288ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  void setLocation(SourceLocation L) { Loc = L; }
289ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
290ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const Stmt *T) {
291ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return T->getStmtClass() == CXXBoolLiteralExprClass;
292ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
293ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const CXXBoolLiteralExpr *) { return true; }
294ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
295ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  // Iterators
296ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  virtual child_iterator child_begin();
297ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  virtual child_iterator child_end();
298ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown};
299ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
300ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
301ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownclass CXXNullPtrLiteralExpr : public Expr {
302ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  SourceLocation Loc;
303ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownpublic:
304ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
305ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {}
306436e89c602e787e7a27dd6624b09beed41a0da8aDmitriy Ivanov
307ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
308ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : Expr(CXXNullPtrLiteralExprClass, Empty) { }
309ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
310ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
311ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
312ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  SourceLocation getLocation() const { return Loc; }
313ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  void setLocation(SourceLocation L) { Loc = L; }
314ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
315ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const Stmt *T) {
316ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return T->getStmtClass() == CXXNullPtrLiteralExprClass;
317ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
318436e89c602e787e7a27dd6624b09beed41a0da8aDmitriy Ivanov  static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
319ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
320ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  virtual child_iterator child_begin();
321ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  virtual child_iterator child_end();
322ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown};
323ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
324ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
325ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// the type_info that corresponds to the supplied type, or the (possibly
326ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// dynamic) type of the supplied expression.
327ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown///
328ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown/// This represents code like @c typeid(int) or @c typeid(*objPtr)
329ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownclass CXXTypeidExpr : public Expr {
330ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownprivate:
331ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
332ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  SourceRange Range;
333ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
334ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brownpublic:
335ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
336ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : Expr(CXXTypeidExprClass, Ty,
337663860b1408516d02ebfcb3a9999a134e6cfb223Ben Cheng           // typeid is never type-dependent (C++ [temp.dep.expr]p4)
338436e89c602e787e7a27dd6624b09beed41a0da8aDmitriy Ivanov           false,
339436e89c602e787e7a27dd6624b09beed41a0da8aDmitriy Ivanov           // typeid is value-dependent if the type or expression are dependent
340ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown           Operand->getType()->isDependentType()),
341ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown      Operand(Operand), Range(R) { }
342ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
343ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
344ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : Expr(CXXTypeidExprClass, Ty,
345ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown        // typeid is never type-dependent (C++ [temp.dep.expr]p4)
346ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown        false,
347ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown        // typeid is value-dependent if the type or expression are dependent
348ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown        Operand->isTypeDependent() || Operand->isValueDependent()),
349ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown      Operand(Operand), Range(R) { }
350ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
351ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  CXXTypeidExpr(EmptyShell Empty, bool isExpr)
352ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    : Expr(CXXTypeidExprClass, Empty) {
353ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    if (isExpr)
354ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown      Operand = (Expr*)0;
355ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    else
356eb0bae136f4eeaaf29761dddb148b118fb824632Dmitriy Ivanov      Operand = (TypeSourceInfo*)0;
357ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
358ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
359ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
360ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
361ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// \brief Retrieves the type operand of this typeid() expression after
362ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// various required adjustments (removing reference types, cv-qualifiers).
363ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  QualType getTypeOperand() const;
364ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
365ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  /// \brief Retrieve source information for the type operand.
366ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  TypeSourceInfo *getTypeOperandSourceInfo() const {
367ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
368ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return Operand.get<TypeSourceInfo *>();
369ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
370ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
371ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
372ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
373ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    Operand = TSI;
374ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
375ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
376ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  Expr *getExprOperand() const {
377ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
378ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return static_cast<Expr*>(Operand.get<Stmt *>());
379ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
380ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
381ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  void setExprOperand(Expr *E) {
382ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
383ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    Operand = E;
384ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  }
385ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
386ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  virtual SourceRange getSourceRange() const { return Range; }
387ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  void setSourceRange(SourceRange R) { Range = R; }
388ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown
389ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown  static bool classof(const Stmt *T) {
390ed07e00d438c74b7a23c01bfffde77e3968305e4Jeff Brown    return T->getStmtClass() == CXXTypeidExprClass;
391  }
392  static bool classof(const CXXTypeidExpr *) { return true; }
393
394  // Iterators
395  virtual child_iterator child_begin();
396  virtual child_iterator child_end();
397};
398
399/// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
400/// the _GUID that corresponds to the supplied type or expression.
401///
402/// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
403class CXXUuidofExpr : public Expr {
404private:
405  llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
406  SourceRange Range;
407
408public:
409  CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
410    : Expr(CXXUuidofExprClass, Ty,
411        false, Operand->getType()->isDependentType()),
412      Operand(Operand), Range(R) { }
413
414  CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
415    : Expr(CXXUuidofExprClass, Ty,
416        false, Operand->isTypeDependent()),
417      Operand(Operand), Range(R) { }
418
419  CXXUuidofExpr(EmptyShell Empty, bool isExpr)
420    : Expr(CXXUuidofExprClass, Empty) {
421    if (isExpr)
422      Operand = (Expr*)0;
423    else
424      Operand = (TypeSourceInfo*)0;
425  }
426
427  bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
428
429  /// \brief Retrieves the type operand of this __uuidof() expression after
430  /// various required adjustments (removing reference types, cv-qualifiers).
431  QualType getTypeOperand() const;
432
433  /// \brief Retrieve source information for the type operand.
434  TypeSourceInfo *getTypeOperandSourceInfo() const {
435    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
436    return Operand.get<TypeSourceInfo *>();
437  }
438
439  void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
440    assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
441    Operand = TSI;
442  }
443
444  Expr *getExprOperand() const {
445    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
446    return static_cast<Expr*>(Operand.get<Stmt *>());
447  }
448
449  void setExprOperand(Expr *E) {
450    assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
451    Operand = E;
452  }
453
454  virtual SourceRange getSourceRange() const { return Range; }
455  void setSourceRange(SourceRange R) { Range = R; }
456
457  static bool classof(const Stmt *T) {
458    return T->getStmtClass() == CXXUuidofExprClass;
459  }
460  static bool classof(const CXXUuidofExpr *) { return true; }
461
462  // Iterators
463  virtual child_iterator child_begin();
464  virtual child_iterator child_end();
465};
466
467/// CXXThisExpr - Represents the "this" expression in C++, which is a
468/// pointer to the object on which the current member function is
469/// executing (C++ [expr.prim]p3). Example:
470///
471/// @code
472/// class Foo {
473/// public:
474///   void bar();
475///   void test() { this->bar(); }
476/// };
477/// @endcode
478class CXXThisExpr : public Expr {
479  SourceLocation Loc;
480  bool Implicit : 1;
481
482public:
483  CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
484    : Expr(CXXThisExprClass, Type,
485           // 'this' is type-dependent if the class type of the enclosing
486           // member function is dependent (C++ [temp.dep.expr]p2)
487           Type->isDependentType(), Type->isDependentType()),
488      Loc(L), Implicit(isImplicit) { }
489
490  CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
491
492  SourceLocation getLocation() const { return Loc; }
493  void setLocation(SourceLocation L) { Loc = L; }
494
495  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
496
497  bool isImplicit() const { return Implicit; }
498  void setImplicit(bool I) { Implicit = I; }
499
500  static bool classof(const Stmt *T) {
501    return T->getStmtClass() == CXXThisExprClass;
502  }
503  static bool classof(const CXXThisExpr *) { return true; }
504
505  // Iterators
506  virtual child_iterator child_begin();
507  virtual child_iterator child_end();
508};
509
510///  CXXThrowExpr - [C++ 15] C++ Throw Expression.  This handles
511///  'throw' and 'throw' assignment-expression.  When
512///  assignment-expression isn't present, Op will be null.
513///
514class CXXThrowExpr : public Expr {
515  Stmt *Op;
516  SourceLocation ThrowLoc;
517public:
518  // Ty is the void type which is used as the result type of the
519  // exepression.  The l is the location of the throw keyword.  expr
520  // can by null, if the optional expression to throw isn't present.
521  CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) :
522    Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {}
523  CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
524
525  const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
526  Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
527  void setSubExpr(Expr *E) { Op = E; }
528
529  SourceLocation getThrowLoc() const { return ThrowLoc; }
530  void setThrowLoc(SourceLocation L) { ThrowLoc = L; }
531
532  virtual SourceRange getSourceRange() const {
533    if (getSubExpr() == 0)
534      return SourceRange(ThrowLoc, ThrowLoc);
535    return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
536  }
537
538  static bool classof(const Stmt *T) {
539    return T->getStmtClass() == CXXThrowExprClass;
540  }
541  static bool classof(const CXXThrowExpr *) { return true; }
542
543  // Iterators
544  virtual child_iterator child_begin();
545  virtual child_iterator child_end();
546};
547
548/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
549/// function call argument that was created from the corresponding
550/// parameter's default argument, when the call did not explicitly
551/// supply arguments for all of the parameters.
552class CXXDefaultArgExpr : public Expr {
553  /// \brief The parameter whose default is being used.
554  ///
555  /// When the bit is set, the subexpression is stored after the
556  /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
557  /// actual default expression is the subexpression.
558  llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
559
560  /// \brief The location where the default argument expression was used.
561  SourceLocation Loc;
562
563  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
564    : Expr(SC,
565           param->hasUnparsedDefaultArg()
566             ? param->getType().getNonReferenceType()
567             : param->getDefaultArg()->getType(),
568           false, false),
569      Param(param, false), Loc(Loc) { }
570
571  CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
572                    Expr *SubExpr)
573    : Expr(SC, SubExpr->getType(), false, false), Param(param, true), Loc(Loc) {
574    *reinterpret_cast<Expr **>(this + 1) = SubExpr;
575  }
576
577public:
578  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
579
580
581  // Param is the parameter whose default argument is used by this
582  // expression.
583  static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
584                                   ParmVarDecl *Param) {
585    return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
586  }
587
588  // Param is the parameter whose default argument is used by this
589  // expression, and SubExpr is the expression that will actually be used.
590  static CXXDefaultArgExpr *Create(ASTContext &C,
591                                   SourceLocation Loc,
592                                   ParmVarDecl *Param,
593                                   Expr *SubExpr);
594
595  // Retrieve the parameter that the argument was created from.
596  const ParmVarDecl *getParam() const { return Param.getPointer(); }
597  ParmVarDecl *getParam() { return Param.getPointer(); }
598
599  // Retrieve the actual argument to the function call.
600  const Expr *getExpr() const {
601    if (Param.getInt())
602      return *reinterpret_cast<Expr const * const*> (this + 1);
603    return getParam()->getDefaultArg();
604  }
605  Expr *getExpr() {
606    if (Param.getInt())
607      return *reinterpret_cast<Expr **> (this + 1);
608    return getParam()->getDefaultArg();
609  }
610
611  /// \brief Retrieve the location where this default argument was actually
612  /// used.
613  SourceLocation getUsedLocation() const { return Loc; }
614
615  virtual SourceRange getSourceRange() const {
616    // Default argument expressions have no representation in the
617    // source, so they have an empty source range.
618    return SourceRange();
619  }
620
621  static bool classof(const Stmt *T) {
622    return T->getStmtClass() == CXXDefaultArgExprClass;
623  }
624  static bool classof(const CXXDefaultArgExpr *) { return true; }
625
626  // Iterators
627  virtual child_iterator child_begin();
628  virtual child_iterator child_end();
629
630  friend class ASTStmtReader;
631  friend class ASTStmtWriter;
632};
633
634/// CXXTemporary - Represents a C++ temporary.
635class CXXTemporary {
636  /// Destructor - The destructor that needs to be called.
637  const CXXDestructorDecl *Destructor;
638
639  CXXTemporary(const CXXDestructorDecl *destructor)
640    : Destructor(destructor) { }
641
642public:
643  static CXXTemporary *Create(ASTContext &C,
644                              const CXXDestructorDecl *Destructor);
645
646  const CXXDestructorDecl *getDestructor() const { return Destructor; }
647};
648
649/// \brief Represents binding an expression to a temporary.
650///
651/// This ensures the destructor is called for the temporary. It should only be
652/// needed for non-POD, non-trivially destructable class types. For example:
653///
654/// \code
655///   struct S {
656///     S() { }  // User defined constructor makes S non-POD.
657///     ~S() { } // User defined destructor makes it non-trivial.
658///   };
659///   void test() {
660///     const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
661///   }
662/// \endcode
663class CXXBindTemporaryExpr : public Expr {
664  CXXTemporary *Temp;
665
666  Stmt *SubExpr;
667
668  CXXBindTemporaryExpr(CXXTemporary *temp, Expr* subexpr)
669   : Expr(CXXBindTemporaryExprClass, subexpr->getType(), false, false),
670     Temp(temp), SubExpr(subexpr) { }
671
672public:
673  CXXBindTemporaryExpr(EmptyShell Empty)
674    : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
675
676  static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
677                                      Expr* SubExpr);
678
679  CXXTemporary *getTemporary() { return Temp; }
680  const CXXTemporary *getTemporary() const { return Temp; }
681  void setTemporary(CXXTemporary *T) { Temp = T; }
682
683  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
684  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
685  void setSubExpr(Expr *E) { SubExpr = E; }
686
687  virtual SourceRange getSourceRange() const {
688    return SubExpr->getSourceRange();
689  }
690
691  // Implement isa/cast/dyncast/etc.
692  static bool classof(const Stmt *T) {
693    return T->getStmtClass() == CXXBindTemporaryExprClass;
694  }
695  static bool classof(const CXXBindTemporaryExpr *) { return true; }
696
697  // Iterators
698  virtual child_iterator child_begin();
699  virtual child_iterator child_end();
700};
701
702/// CXXConstructExpr - Represents a call to a C++ constructor.
703class CXXConstructExpr : public Expr {
704public:
705  enum ConstructionKind {
706    CK_Complete,
707    CK_NonVirtualBase,
708    CK_VirtualBase
709  };
710
711private:
712  CXXConstructorDecl *Constructor;
713
714  SourceLocation Loc;
715  bool Elidable : 1;
716  bool ZeroInitialization : 1;
717  unsigned ConstructKind : 2;
718  Stmt **Args;
719  unsigned NumArgs;
720
721protected:
722  CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
723                   SourceLocation Loc,
724                   CXXConstructorDecl *d, bool elidable,
725                   Expr **args, unsigned numargs,
726                   bool ZeroInitialization = false,
727                   ConstructionKind ConstructKind = CK_Complete);
728
729  /// \brief Construct an empty C++ construction expression.
730  CXXConstructExpr(StmtClass SC, EmptyShell Empty)
731    : Expr(SC, Empty), Constructor(0), Elidable(0), ZeroInitialization(0),
732      ConstructKind(0), Args(0), NumArgs(0) { }
733
734public:
735  /// \brief Construct an empty C++ construction expression.
736  explicit CXXConstructExpr(EmptyShell Empty)
737    : Expr(CXXConstructExprClass, Empty), Constructor(0),
738      Elidable(0), ZeroInitialization(0),
739      ConstructKind(0), Args(0), NumArgs(0) { }
740
741  static CXXConstructExpr *Create(ASTContext &C, QualType T,
742                                  SourceLocation Loc,
743                                  CXXConstructorDecl *D, bool Elidable,
744                                  Expr **Args, unsigned NumArgs,
745                                  bool ZeroInitialization = false,
746                                  ConstructionKind ConstructKind = CK_Complete);
747
748
749  CXXConstructorDecl* getConstructor() const { return Constructor; }
750  void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
751
752  SourceLocation getLocation() const { return Loc; }
753  void setLocation(SourceLocation Loc) { this->Loc = Loc; }
754
755  /// \brief Whether this construction is elidable.
756  bool isElidable() const { return Elidable; }
757  void setElidable(bool E) { Elidable = E; }
758
759  /// \brief Whether this construction first requires
760  /// zero-initialization before the initializer is called.
761  bool requiresZeroInitialization() const { return ZeroInitialization; }
762  void setRequiresZeroInitialization(bool ZeroInit) {
763    ZeroInitialization = ZeroInit;
764  }
765
766  /// \brief Determines whether this constructor is actually constructing
767  /// a base class (rather than a complete object).
768  ConstructionKind getConstructionKind() const {
769    return (ConstructionKind)ConstructKind;
770  }
771  void setConstructionKind(ConstructionKind CK) {
772    ConstructKind = CK;
773  }
774
775  typedef ExprIterator arg_iterator;
776  typedef ConstExprIterator const_arg_iterator;
777
778  arg_iterator arg_begin() { return Args; }
779  arg_iterator arg_end() { return Args + NumArgs; }
780  const_arg_iterator arg_begin() const { return Args; }
781  const_arg_iterator arg_end() const { return Args + NumArgs; }
782
783  Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
784  unsigned getNumArgs() const { return NumArgs; }
785
786  /// getArg - Return the specified argument.
787  Expr *getArg(unsigned Arg) {
788    assert(Arg < NumArgs && "Arg access out of range!");
789    return cast<Expr>(Args[Arg]);
790  }
791  const Expr *getArg(unsigned Arg) const {
792    assert(Arg < NumArgs && "Arg access out of range!");
793    return cast<Expr>(Args[Arg]);
794  }
795
796  /// setArg - Set the specified argument.
797  void setArg(unsigned Arg, Expr *ArgExpr) {
798    assert(Arg < NumArgs && "Arg access out of range!");
799    Args[Arg] = ArgExpr;
800  }
801
802  virtual SourceRange getSourceRange() const;
803
804  static bool classof(const Stmt *T) {
805    return T->getStmtClass() == CXXConstructExprClass ||
806      T->getStmtClass() == CXXTemporaryObjectExprClass;
807  }
808  static bool classof(const CXXConstructExpr *) { return true; }
809
810  // Iterators
811  virtual child_iterator child_begin();
812  virtual child_iterator child_end();
813
814  friend class ASTStmtReader;
815};
816
817/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
818/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
819/// x = int(0.5);
820class CXXFunctionalCastExpr : public ExplicitCastExpr {
821  SourceLocation TyBeginLoc;
822  SourceLocation RParenLoc;
823
824  CXXFunctionalCastExpr(QualType ty, TypeSourceInfo *writtenTy,
825                        SourceLocation tyBeginLoc, CastKind kind,
826                        Expr *castExpr, unsigned pathSize,
827                        SourceLocation rParenLoc)
828    : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, kind, castExpr,
829                       pathSize, writtenTy),
830      TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
831
832  explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
833    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
834
835public:
836  static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
837                                       TypeSourceInfo *Written,
838                                       SourceLocation TyBeginLoc,
839                                       CastKind Kind, Expr *Op,
840                                       const CXXCastPath *Path,
841                                       SourceLocation RPLoc);
842  static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
843                                            unsigned PathSize);
844
845  SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
846  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
847  SourceLocation getRParenLoc() const { return RParenLoc; }
848  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
849
850  virtual SourceRange getSourceRange() const {
851    return SourceRange(TyBeginLoc, RParenLoc);
852  }
853  static bool classof(const Stmt *T) {
854    return T->getStmtClass() == CXXFunctionalCastExprClass;
855  }
856  static bool classof(const CXXFunctionalCastExpr *) { return true; }
857};
858
859/// @brief Represents a C++ functional cast expression that builds a
860/// temporary object.
861///
862/// This expression type represents a C++ "functional" cast
863/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
864/// constructor to build a temporary object. With N == 1 arguments the
865/// functional cast expression will be represented by CXXFunctionalCastExpr.
866/// Example:
867/// @code
868/// struct X { X(int, float); }
869///
870/// X create_X() {
871///   return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
872/// };
873/// @endcode
874class CXXTemporaryObjectExpr : public CXXConstructExpr {
875  SourceLocation RParenLoc;
876  TypeSourceInfo *Type;
877
878public:
879  CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
880                         TypeSourceInfo *Type,
881                         Expr **Args,unsigned NumArgs,
882                         SourceLocation rParenLoc,
883                         bool ZeroInitialization = false);
884  explicit CXXTemporaryObjectExpr(EmptyShell Empty)
885    : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
886
887  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
888  SourceLocation getRParenLoc() const { return RParenLoc; }
889
890  virtual SourceRange getSourceRange() const;
891
892  static bool classof(const Stmt *T) {
893    return T->getStmtClass() == CXXTemporaryObjectExprClass;
894  }
895  static bool classof(const CXXTemporaryObjectExpr *) { return true; }
896
897  friend class ASTStmtReader;
898};
899
900/// CXXScalarValueInitExpr - [C++ 5.2.3p2]
901/// Expression "T()" which creates a value-initialized rvalue of type
902/// T, which is a non-class type.
903///
904class CXXScalarValueInitExpr : public Expr {
905  SourceLocation RParenLoc;
906  TypeSourceInfo *TypeInfo;
907
908  friend class ASTStmtReader;
909
910public:
911  /// \brief Create an explicitly-written scalar-value initialization
912  /// expression.
913  CXXScalarValueInitExpr(QualType Type,
914                         TypeSourceInfo *TypeInfo,
915                         SourceLocation rParenLoc ) :
916    Expr(CXXScalarValueInitExprClass, Type, false, false),
917    RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
918
919  explicit CXXScalarValueInitExpr(EmptyShell Shell)
920    : Expr(CXXScalarValueInitExprClass, Shell) { }
921
922  TypeSourceInfo *getTypeSourceInfo() const {
923    return TypeInfo;
924  }
925
926  SourceLocation getRParenLoc() const { return RParenLoc; }
927
928  virtual SourceRange getSourceRange() const;
929
930  static bool classof(const Stmt *T) {
931    return T->getStmtClass() == CXXScalarValueInitExprClass;
932  }
933  static bool classof(const CXXScalarValueInitExpr *) { return true; }
934
935  // Iterators
936  virtual child_iterator child_begin();
937  virtual child_iterator child_end();
938};
939
940/// CXXNewExpr - A new expression for memory allocation and constructor calls,
941/// e.g: "new CXXNewExpr(foo)".
942class CXXNewExpr : public Expr {
943  // Was the usage ::new, i.e. is the global new to be used?
944  bool GlobalNew : 1;
945  // Is there an initializer? If not, built-ins are uninitialized, else they're
946  // value-initialized.
947  bool Initializer : 1;
948  // Do we allocate an array? If so, the first SubExpr is the size expression.
949  bool Array : 1;
950  // The number of placement new arguments.
951  unsigned NumPlacementArgs : 15;
952  // The number of constructor arguments. This may be 1 even for non-class
953  // types; use the pseudo copy constructor.
954  unsigned NumConstructorArgs : 14;
955  // Contains an optional array size expression, any number of optional
956  // placement arguments, and any number of optional constructor arguments,
957  // in that order.
958  Stmt **SubExprs;
959  // Points to the allocation function used.
960  FunctionDecl *OperatorNew;
961  // Points to the deallocation function used in case of error. May be null.
962  FunctionDecl *OperatorDelete;
963  // Points to the constructor used. Cannot be null if AllocType is a record;
964  // it would still point at the default constructor (even an implicit one).
965  // Must be null for all other types.
966  CXXConstructorDecl *Constructor;
967
968  /// \brief The allocated type-source information, as written in the source.
969  TypeSourceInfo *AllocatedTypeInfo;
970
971  /// \brief If the allocated type was expressed as a parenthesized type-id,
972  /// the source range covering the parenthesized type-id.
973  SourceRange TypeIdParens;
974
975  SourceLocation StartLoc;
976  SourceLocation EndLoc;
977
978  friend class ASTStmtReader;
979public:
980  CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
981             Expr **placementArgs, unsigned numPlaceArgs,
982             SourceRange TypeIdParens,
983             Expr *arraySize, CXXConstructorDecl *constructor, bool initializer,
984             Expr **constructorArgs, unsigned numConsArgs,
985             FunctionDecl *operatorDelete, QualType ty,
986             TypeSourceInfo *AllocatedTypeInfo,
987             SourceLocation startLoc, SourceLocation endLoc);
988  explicit CXXNewExpr(EmptyShell Shell)
989    : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
990
991  void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
992                         unsigned numConsArgs);
993
994  QualType getAllocatedType() const {
995    assert(getType()->isPointerType());
996    return getType()->getAs<PointerType>()->getPointeeType();
997  }
998
999  TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1000    return AllocatedTypeInfo;
1001  }
1002
1003  FunctionDecl *getOperatorNew() const { return OperatorNew; }
1004  void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
1005  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1006  void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1007  CXXConstructorDecl *getConstructor() const { return Constructor; }
1008  void setConstructor(CXXConstructorDecl *D) { Constructor = D; }
1009
1010  bool isArray() const { return Array; }
1011  Expr *getArraySize() {
1012    return Array ? cast<Expr>(SubExprs[0]) : 0;
1013  }
1014  const Expr *getArraySize() const {
1015    return Array ? cast<Expr>(SubExprs[0]) : 0;
1016  }
1017
1018  unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
1019  Expr *getPlacementArg(unsigned i) {
1020    assert(i < NumPlacementArgs && "Index out of range");
1021    return cast<Expr>(SubExprs[Array + i]);
1022  }
1023  const Expr *getPlacementArg(unsigned i) const {
1024    assert(i < NumPlacementArgs && "Index out of range");
1025    return cast<Expr>(SubExprs[Array + i]);
1026  }
1027
1028  bool isParenTypeId() const { return TypeIdParens.isValid(); }
1029  SourceRange getTypeIdParens() const { return TypeIdParens; }
1030
1031  bool isGlobalNew() const { return GlobalNew; }
1032  void setGlobalNew(bool V) { GlobalNew = V; }
1033  bool hasInitializer() const { return Initializer; }
1034  void setHasInitializer(bool V) { Initializer = V; }
1035
1036  unsigned getNumConstructorArgs() const { return NumConstructorArgs; }
1037  Expr *getConstructorArg(unsigned i) {
1038    assert(i < NumConstructorArgs && "Index out of range");
1039    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1040  }
1041  const Expr *getConstructorArg(unsigned i) const {
1042    assert(i < NumConstructorArgs && "Index out of range");
1043    return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]);
1044  }
1045
1046  typedef ExprIterator arg_iterator;
1047  typedef ConstExprIterator const_arg_iterator;
1048
1049  arg_iterator placement_arg_begin() {
1050    return SubExprs + Array;
1051  }
1052  arg_iterator placement_arg_end() {
1053    return SubExprs + Array + getNumPlacementArgs();
1054  }
1055  const_arg_iterator placement_arg_begin() const {
1056    return SubExprs + Array;
1057  }
1058  const_arg_iterator placement_arg_end() const {
1059    return SubExprs + Array + getNumPlacementArgs();
1060  }
1061
1062  arg_iterator constructor_arg_begin() {
1063    return SubExprs + Array + getNumPlacementArgs();
1064  }
1065  arg_iterator constructor_arg_end() {
1066    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1067  }
1068  const_arg_iterator constructor_arg_begin() const {
1069    return SubExprs + Array + getNumPlacementArgs();
1070  }
1071  const_arg_iterator constructor_arg_end() const {
1072    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1073  }
1074
1075  typedef Stmt **raw_arg_iterator;
1076  raw_arg_iterator raw_arg_begin() { return SubExprs; }
1077  raw_arg_iterator raw_arg_end() {
1078    return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs();
1079  }
1080  const_arg_iterator raw_arg_begin() const { return SubExprs; }
1081  const_arg_iterator raw_arg_end() const { return constructor_arg_end(); }
1082
1083
1084  SourceLocation getStartLoc() const { return StartLoc; }
1085  void setStartLoc(SourceLocation L) { StartLoc = L; }
1086  SourceLocation getEndLoc() const { return EndLoc; }
1087  void setEndLoc(SourceLocation L) { EndLoc = L; }
1088
1089  virtual SourceRange getSourceRange() const {
1090    return SourceRange(StartLoc, EndLoc);
1091  }
1092
1093  static bool classof(const Stmt *T) {
1094    return T->getStmtClass() == CXXNewExprClass;
1095  }
1096  static bool classof(const CXXNewExpr *) { return true; }
1097
1098  // Iterators
1099  virtual child_iterator child_begin();
1100  virtual child_iterator child_end();
1101};
1102
1103/// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1104/// calls, e.g. "delete[] pArray".
1105class CXXDeleteExpr : public Expr {
1106  // Is this a forced global delete, i.e. "::delete"?
1107  bool GlobalDelete : 1;
1108  // Is this the array form of delete, i.e. "delete[]"?
1109  bool ArrayForm : 1;
1110  // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1111  // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1112  // will be true).
1113  bool ArrayFormAsWritten : 1;
1114  // Points to the operator delete overload that is used. Could be a member.
1115  FunctionDecl *OperatorDelete;
1116  // The pointer expression to be deleted.
1117  Stmt *Argument;
1118  // Location of the expression.
1119  SourceLocation Loc;
1120public:
1121  CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1122                bool arrayFormAsWritten, FunctionDecl *operatorDelete,
1123                Expr *arg, SourceLocation loc)
1124    : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete),
1125      ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1126      OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { }
1127  explicit CXXDeleteExpr(EmptyShell Shell)
1128    : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1129
1130  bool isGlobalDelete() const { return GlobalDelete; }
1131  bool isArrayForm() const { return ArrayForm; }
1132  bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1133
1134  FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1135
1136  Expr *getArgument() { return cast<Expr>(Argument); }
1137  const Expr *getArgument() const { return cast<Expr>(Argument); }
1138
1139  virtual SourceRange getSourceRange() const {
1140    return SourceRange(Loc, Argument->getLocEnd());
1141  }
1142
1143  static bool classof(const Stmt *T) {
1144    return T->getStmtClass() == CXXDeleteExprClass;
1145  }
1146  static bool classof(const CXXDeleteExpr *) { return true; }
1147
1148  // Iterators
1149  virtual child_iterator child_begin();
1150  virtual child_iterator child_end();
1151
1152  friend class ASTStmtReader;
1153};
1154
1155/// \brief Structure used to store the type being destroyed by a
1156/// pseudo-destructor expression.
1157class PseudoDestructorTypeStorage {
1158  /// \brief Either the type source information or the name of the type, if
1159  /// it couldn't be resolved due to type-dependence.
1160  llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1161
1162  /// \brief The starting source location of the pseudo-destructor type.
1163  SourceLocation Location;
1164
1165public:
1166  PseudoDestructorTypeStorage() { }
1167
1168  PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1169    : Type(II), Location(Loc) { }
1170
1171  PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1172
1173  TypeSourceInfo *getTypeSourceInfo() const {
1174    return Type.dyn_cast<TypeSourceInfo *>();
1175  }
1176
1177  IdentifierInfo *getIdentifier() const {
1178    return Type.dyn_cast<IdentifierInfo *>();
1179  }
1180
1181  SourceLocation getLocation() const { return Location; }
1182};
1183
1184/// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1185///
1186/// A pseudo-destructor is an expression that looks like a member access to a
1187/// destructor of a scalar type, except that scalar types don't have
1188/// destructors. For example:
1189///
1190/// \code
1191/// typedef int T;
1192/// void f(int *p) {
1193///   p->T::~T();
1194/// }
1195/// \endcode
1196///
1197/// Pseudo-destructors typically occur when instantiating templates such as:
1198///
1199/// \code
1200/// template<typename T>
1201/// void destroy(T* ptr) {
1202///   ptr->T::~T();
1203/// }
1204/// \endcode
1205///
1206/// for scalar types. A pseudo-destructor expression has no run-time semantics
1207/// beyond evaluating the base expression.
1208class CXXPseudoDestructorExpr : public Expr {
1209  /// \brief The base expression (that is being destroyed).
1210  Stmt *Base;
1211
1212  /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1213  /// period ('.').
1214  bool IsArrow : 1;
1215
1216  /// \brief The location of the '.' or '->' operator.
1217  SourceLocation OperatorLoc;
1218
1219  /// \brief The nested-name-specifier that follows the operator, if present.
1220  NestedNameSpecifier *Qualifier;
1221
1222  /// \brief The source range that covers the nested-name-specifier, if
1223  /// present.
1224  SourceRange QualifierRange;
1225
1226  /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1227  /// expression.
1228  TypeSourceInfo *ScopeType;
1229
1230  /// \brief The location of the '::' in a qualified pseudo-destructor
1231  /// expression.
1232  SourceLocation ColonColonLoc;
1233
1234  /// \brief The location of the '~'.
1235  SourceLocation TildeLoc;
1236
1237  /// \brief The type being destroyed, or its name if we were unable to
1238  /// resolve the name.
1239  PseudoDestructorTypeStorage DestroyedType;
1240
1241public:
1242  CXXPseudoDestructorExpr(ASTContext &Context,
1243                          Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1244                          NestedNameSpecifier *Qualifier,
1245                          SourceRange QualifierRange,
1246                          TypeSourceInfo *ScopeType,
1247                          SourceLocation ColonColonLoc,
1248                          SourceLocation TildeLoc,
1249                          PseudoDestructorTypeStorage DestroyedType)
1250    : Expr(CXXPseudoDestructorExprClass,
1251           Context.getPointerType(Context.getFunctionType(Context.VoidTy, 0, 0,
1252                                                          false, 0, false,
1253                                                          false, 0, 0,
1254                                                      FunctionType::ExtInfo())),
1255           /*isTypeDependent=*/(Base->isTypeDependent() ||
1256            (DestroyedType.getTypeSourceInfo() &&
1257              DestroyedType.getTypeSourceInfo()->getType()->isDependentType())),
1258           /*isValueDependent=*/Base->isValueDependent()),
1259      Base(static_cast<Stmt *>(Base)), IsArrow(isArrow),
1260      OperatorLoc(OperatorLoc), Qualifier(Qualifier),
1261      QualifierRange(QualifierRange),
1262      ScopeType(ScopeType), ColonColonLoc(ColonColonLoc), TildeLoc(TildeLoc),
1263      DestroyedType(DestroyedType) { }
1264
1265  explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1266    : Expr(CXXPseudoDestructorExprClass, Shell),
1267      Base(0), IsArrow(false), Qualifier(0), ScopeType(0) { }
1268
1269  void setBase(Expr *E) { Base = E; }
1270  Expr *getBase() const { return cast<Expr>(Base); }
1271
1272  /// \brief Determines whether this member expression actually had
1273  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1274  /// x->Base::foo.
1275  bool hasQualifier() const { return Qualifier != 0; }
1276
1277  /// \brief If the member name was qualified, retrieves the source range of
1278  /// the nested-name-specifier that precedes the member name. Otherwise,
1279  /// returns an empty source range.
1280  SourceRange getQualifierRange() const { return QualifierRange; }
1281  void setQualifierRange(SourceRange R) { QualifierRange = R; }
1282
1283  /// \brief If the member name was qualified, retrieves the
1284  /// nested-name-specifier that precedes the member name. Otherwise, returns
1285  /// NULL.
1286  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1287  void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1288
1289  /// \brief Determine whether this pseudo-destructor expression was written
1290  /// using an '->' (otherwise, it used a '.').
1291  bool isArrow() const { return IsArrow; }
1292  void setArrow(bool A) { IsArrow = A; }
1293
1294  /// \brief Retrieve the location of the '.' or '->' operator.
1295  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1296  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1297
1298  /// \brief Retrieve the scope type in a qualified pseudo-destructor
1299  /// expression.
1300  ///
1301  /// Pseudo-destructor expressions can have extra qualification within them
1302  /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1303  /// Here, if the object type of the expression is (or may be) a scalar type,
1304  /// \p T may also be a scalar type and, therefore, cannot be part of a
1305  /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1306  /// destructor expression.
1307  TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1308  void setScopeTypeInfo(TypeSourceInfo *Info) { ScopeType = Info; }
1309
1310  /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1311  /// expression.
1312  SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1313  void setColonColonLoc(SourceLocation L) { ColonColonLoc = L; }
1314
1315  /// \brief Retrieve the location of the '~'.
1316  SourceLocation getTildeLoc() const { return TildeLoc; }
1317  void setTildeLoc(SourceLocation L) { TildeLoc = L; }
1318
1319  /// \brief Retrieve the source location information for the type
1320  /// being destroyed.
1321  ///
1322  /// This type-source information is available for non-dependent
1323  /// pseudo-destructor expressions and some dependent pseudo-destructor
1324  /// expressions. Returns NULL if we only have the identifier for a
1325  /// dependent pseudo-destructor expression.
1326  TypeSourceInfo *getDestroyedTypeInfo() const {
1327    return DestroyedType.getTypeSourceInfo();
1328  }
1329
1330  /// \brief In a dependent pseudo-destructor expression for which we do not
1331  /// have full type information on the destroyed type, provides the name
1332  /// of the destroyed type.
1333  IdentifierInfo *getDestroyedTypeIdentifier() const {
1334    return DestroyedType.getIdentifier();
1335  }
1336
1337  /// \brief Retrieve the type being destroyed.
1338  QualType getDestroyedType() const;
1339
1340  /// \brief Retrieve the starting location of the type being destroyed.
1341  SourceLocation getDestroyedTypeLoc() const {
1342    return DestroyedType.getLocation();
1343  }
1344
1345  /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1346  /// expression.
1347  void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1348    DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1349  }
1350
1351  /// \brief Set the destroyed type.
1352  void setDestroyedType(TypeSourceInfo *Info) {
1353    DestroyedType = PseudoDestructorTypeStorage(Info);
1354  }
1355
1356  virtual SourceRange getSourceRange() const;
1357
1358  static bool classof(const Stmt *T) {
1359    return T->getStmtClass() == CXXPseudoDestructorExprClass;
1360  }
1361  static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1362
1363  // Iterators
1364  virtual child_iterator child_begin();
1365  virtual child_iterator child_end();
1366};
1367
1368/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1369/// implementation of TR1/C++0x type trait templates.
1370/// Example:
1371/// __is_pod(int) == true
1372/// __is_enum(std::string) == false
1373class UnaryTypeTraitExpr : public Expr {
1374  /// UTT - The trait.
1375  UnaryTypeTrait UTT;
1376
1377  /// Loc - The location of the type trait keyword.
1378  SourceLocation Loc;
1379
1380  /// RParen - The location of the closing paren.
1381  SourceLocation RParen;
1382
1383  TypeSourceInfo *QueriedType;
1384
1385public:
1386  UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
1387                     TypeSourceInfo *queried,
1388                     SourceLocation rparen, QualType ty)
1389    : Expr(UnaryTypeTraitExprClass, ty, false,
1390           queried->getType()->isDependentType()),
1391      UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { }
1392
1393  explicit UnaryTypeTraitExpr(EmptyShell Empty)
1394    : Expr(UnaryTypeTraitExprClass, Empty), UTT((UnaryTypeTrait)0),
1395      QueriedType() { }
1396
1397  virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);}
1398
1399  UnaryTypeTrait getTrait() const { return UTT; }
1400
1401  QualType getQueriedType() const { return QueriedType->getType(); }
1402
1403  TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1404
1405  bool EvaluateTrait(ASTContext&) const;
1406
1407  static bool classof(const Stmt *T) {
1408    return T->getStmtClass() == UnaryTypeTraitExprClass;
1409  }
1410  static bool classof(const UnaryTypeTraitExpr *) { return true; }
1411
1412  // Iterators
1413  virtual child_iterator child_begin();
1414  virtual child_iterator child_end();
1415
1416  friend class ASTStmtReader;
1417};
1418
1419/// \brief A reference to an overloaded function set, either an
1420/// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
1421class OverloadExpr : public Expr {
1422  /// The results.  These are undesugared, which is to say, they may
1423  /// include UsingShadowDecls.  Access is relative to the naming
1424  /// class.
1425  // FIXME: Allocate this data after the OverloadExpr subclass.
1426  DeclAccessPair *Results;
1427  unsigned NumResults;
1428
1429  /// The common name of these declarations.
1430  DeclarationNameInfo NameInfo;
1431
1432  /// The scope specifier, if any.
1433  NestedNameSpecifier *Qualifier;
1434
1435  /// The source range of the scope specifier.
1436  SourceRange QualifierRange;
1437
1438protected:
1439  /// True if the name was a template-id.
1440  bool HasExplicitTemplateArgs;
1441
1442  OverloadExpr(StmtClass K, ASTContext &C, QualType T, bool Dependent,
1443               NestedNameSpecifier *Qualifier, SourceRange QRange,
1444               const DeclarationNameInfo &NameInfo,
1445               bool HasTemplateArgs,
1446               UnresolvedSetIterator Begin, UnresolvedSetIterator End);
1447
1448  OverloadExpr(StmtClass K, EmptyShell Empty)
1449    : Expr(K, Empty), Results(0), NumResults(0),
1450      Qualifier(0), HasExplicitTemplateArgs(false) { }
1451
1452public:
1453  /// Computes whether an unresolved lookup on the given declarations
1454  /// and optional template arguments is type- and value-dependent.
1455  static bool ComputeDependence(UnresolvedSetIterator Begin,
1456                                UnresolvedSetIterator End,
1457                                const TemplateArgumentListInfo *Args);
1458
1459  struct FindResult {
1460    OverloadExpr *Expression;
1461    bool IsAddressOfOperand;
1462    bool HasFormOfMemberPointer;
1463  };
1464
1465  /// Finds the overloaded expression in the given expression of
1466  /// OverloadTy.
1467  ///
1468  /// \return the expression (which must be there) and true if it has
1469  /// the particular form of a member pointer expression
1470  static FindResult find(Expr *E) {
1471    assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
1472
1473    FindResult Result;
1474
1475    E = E->IgnoreParens();
1476    if (isa<UnaryOperator>(E)) {
1477      assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
1478      E = cast<UnaryOperator>(E)->getSubExpr();
1479      OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
1480
1481      Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
1482      Result.IsAddressOfOperand = true;
1483      Result.Expression = Ovl;
1484    } else {
1485      Result.HasFormOfMemberPointer = false;
1486      Result.IsAddressOfOperand = false;
1487      Result.Expression = cast<OverloadExpr>(E);
1488    }
1489
1490    return Result;
1491  }
1492
1493  /// Gets the naming class of this lookup, if any.
1494  CXXRecordDecl *getNamingClass() const;
1495
1496  typedef UnresolvedSetImpl::iterator decls_iterator;
1497  decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
1498  decls_iterator decls_end() const {
1499    return UnresolvedSetIterator(Results + NumResults);
1500  }
1501
1502  void initializeResults(ASTContext &C,
1503                         UnresolvedSetIterator Begin,UnresolvedSetIterator End);
1504
1505  /// Gets the number of declarations in the unresolved set.
1506  unsigned getNumDecls() const { return NumResults; }
1507
1508  /// Gets the full name info.
1509  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1510  void setNameInfo(const DeclarationNameInfo &N) { NameInfo = N; }
1511
1512  /// Gets the name looked up.
1513  DeclarationName getName() const { return NameInfo.getName(); }
1514  void setName(DeclarationName N) { NameInfo.setName(N); }
1515
1516  /// Gets the location of the name.
1517  SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
1518  void setNameLoc(SourceLocation Loc) { NameInfo.setLoc(Loc); }
1519
1520  /// Fetches the nested-name qualifier, if one was given.
1521  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1522  void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1523
1524  /// Fetches the range of the nested-name qualifier.
1525  SourceRange getQualifierRange() const { return QualifierRange; }
1526  void setQualifierRange(SourceRange R) { QualifierRange = R; }
1527
1528  /// \brief Determines whether this expression had an explicit
1529  /// template argument list, e.g. f<int>.
1530  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1531
1532  ExplicitTemplateArgumentList &getExplicitTemplateArgs(); // defined far below
1533
1534  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1535    return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
1536  }
1537
1538  /// \brief Retrieves the optional explicit template arguments.
1539  /// This points to the same data as getExplicitTemplateArgs(), but
1540  /// returns null if there are no explicit template arguments.
1541  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1542    if (!hasExplicitTemplateArgs()) return 0;
1543    return &getExplicitTemplateArgs();
1544  }
1545
1546  static bool classof(const Stmt *T) {
1547    return T->getStmtClass() == UnresolvedLookupExprClass ||
1548           T->getStmtClass() == UnresolvedMemberExprClass;
1549  }
1550  static bool classof(const OverloadExpr *) { return true; }
1551};
1552
1553/// \brief A reference to a name which we were able to look up during
1554/// parsing but could not resolve to a specific declaration.  This
1555/// arises in several ways:
1556///   * we might be waiting for argument-dependent lookup
1557///   * the name might resolve to an overloaded function
1558/// and eventually:
1559///   * the lookup might have included a function template
1560/// These never include UnresolvedUsingValueDecls, which are always
1561/// class members and therefore appear only in
1562/// UnresolvedMemberLookupExprs.
1563class UnresolvedLookupExpr : public OverloadExpr {
1564  /// True if these lookup results should be extended by
1565  /// argument-dependent lookup if this is the operand of a function
1566  /// call.
1567  bool RequiresADL;
1568
1569  /// True if these lookup results are overloaded.  This is pretty
1570  /// trivially rederivable if we urgently need to kill this field.
1571  bool Overloaded;
1572
1573  /// The naming class (C++ [class.access.base]p5) of the lookup, if
1574  /// any.  This can generally be recalculated from the context chain,
1575  /// but that can be fairly expensive for unqualified lookups.  If we
1576  /// want to improve memory use here, this could go in a union
1577  /// against the qualified-lookup bits.
1578  CXXRecordDecl *NamingClass;
1579
1580  UnresolvedLookupExpr(ASTContext &C, QualType T, bool Dependent,
1581                       CXXRecordDecl *NamingClass,
1582                       NestedNameSpecifier *Qualifier, SourceRange QRange,
1583                       const DeclarationNameInfo &NameInfo,
1584                       bool RequiresADL, bool Overloaded, bool HasTemplateArgs,
1585                       UnresolvedSetIterator Begin, UnresolvedSetIterator End)
1586    : OverloadExpr(UnresolvedLookupExprClass, C, T, Dependent, Qualifier,
1587                   QRange, NameInfo, HasTemplateArgs, Begin, End),
1588      RequiresADL(RequiresADL), Overloaded(Overloaded), NamingClass(NamingClass)
1589  {}
1590
1591  UnresolvedLookupExpr(EmptyShell Empty)
1592    : OverloadExpr(UnresolvedLookupExprClass, Empty),
1593      RequiresADL(false), Overloaded(false), NamingClass(0)
1594  {}
1595
1596public:
1597  static UnresolvedLookupExpr *Create(ASTContext &C,
1598                                      bool Dependent,
1599                                      CXXRecordDecl *NamingClass,
1600                                      NestedNameSpecifier *Qualifier,
1601                                      SourceRange QualifierRange,
1602                                      const DeclarationNameInfo &NameInfo,
1603                                      bool ADL, bool Overloaded,
1604                                      UnresolvedSetIterator Begin,
1605                                      UnresolvedSetIterator End) {
1606    return new(C) UnresolvedLookupExpr(C,
1607                                       Dependent ? C.DependentTy : C.OverloadTy,
1608                                       Dependent, NamingClass,
1609                                       Qualifier, QualifierRange, NameInfo,
1610                                       ADL, Overloaded, false,
1611                                       Begin, End);
1612  }
1613
1614  static UnresolvedLookupExpr *Create(ASTContext &C,
1615                                      bool Dependent,
1616                                      CXXRecordDecl *NamingClass,
1617                                      NestedNameSpecifier *Qualifier,
1618                                      SourceRange QualifierRange,
1619                                      const DeclarationNameInfo &NameInfo,
1620                                      bool ADL,
1621                                      const TemplateArgumentListInfo &Args,
1622                                      UnresolvedSetIterator Begin,
1623                                      UnresolvedSetIterator End);
1624
1625  static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
1626                                           unsigned NumTemplateArgs);
1627
1628  /// True if this declaration should be extended by
1629  /// argument-dependent lookup.
1630  bool requiresADL() const { return RequiresADL; }
1631  void setRequiresADL(bool V) { RequiresADL = V; }
1632
1633  /// True if this lookup is overloaded.
1634  bool isOverloaded() const { return Overloaded; }
1635  void setOverloaded(bool V) { Overloaded = V; }
1636
1637  /// Gets the 'naming class' (in the sense of C++0x
1638  /// [class.access.base]p5) of the lookup.  This is the scope
1639  /// that was looked in to find these results.
1640  CXXRecordDecl *getNamingClass() const { return NamingClass; }
1641  void setNamingClass(CXXRecordDecl *D) { NamingClass = D; }
1642
1643  // Note that, inconsistently with the explicit-template-argument AST
1644  // nodes, users are *forbidden* from calling these methods on objects
1645  // without explicit template arguments.
1646
1647  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1648    assert(hasExplicitTemplateArgs());
1649    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1650  }
1651
1652  /// Gets a reference to the explicit template argument list.
1653  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1654    assert(hasExplicitTemplateArgs());
1655    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1656  }
1657
1658  /// \brief Retrieves the optional explicit template arguments.
1659  /// This points to the same data as getExplicitTemplateArgs(), but
1660  /// returns null if there are no explicit template arguments.
1661  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1662    if (!hasExplicitTemplateArgs()) return 0;
1663    return &getExplicitTemplateArgs();
1664  }
1665
1666  /// \brief Copies the template arguments (if present) into the given
1667  /// structure.
1668  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1669    getExplicitTemplateArgs().copyInto(List);
1670  }
1671
1672  SourceLocation getLAngleLoc() const {
1673    return getExplicitTemplateArgs().LAngleLoc;
1674  }
1675
1676  SourceLocation getRAngleLoc() const {
1677    return getExplicitTemplateArgs().RAngleLoc;
1678  }
1679
1680  TemplateArgumentLoc const *getTemplateArgs() const {
1681    return getExplicitTemplateArgs().getTemplateArgs();
1682  }
1683
1684  unsigned getNumTemplateArgs() const {
1685    return getExplicitTemplateArgs().NumTemplateArgs;
1686  }
1687
1688  virtual SourceRange getSourceRange() const {
1689    SourceRange Range(getNameInfo().getSourceRange());
1690    if (getQualifier()) Range.setBegin(getQualifierRange().getBegin());
1691    if (hasExplicitTemplateArgs()) Range.setEnd(getRAngleLoc());
1692    return Range;
1693  }
1694
1695  virtual StmtIterator child_begin();
1696  virtual StmtIterator child_end();
1697
1698  static bool classof(const Stmt *T) {
1699    return T->getStmtClass() == UnresolvedLookupExprClass;
1700  }
1701  static bool classof(const UnresolvedLookupExpr *) { return true; }
1702};
1703
1704/// \brief A qualified reference to a name whose declaration cannot
1705/// yet be resolved.
1706///
1707/// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
1708/// it expresses a reference to a declaration such as
1709/// X<T>::value. The difference, however, is that an
1710/// DependentScopeDeclRefExpr node is used only within C++ templates when
1711/// the qualification (e.g., X<T>::) refers to a dependent type. In
1712/// this case, X<T>::value cannot resolve to a declaration because the
1713/// declaration will differ from on instantiation of X<T> to the
1714/// next. Therefore, DependentScopeDeclRefExpr keeps track of the
1715/// qualifier (X<T>::) and the name of the entity being referenced
1716/// ("value"). Such expressions will instantiate to a DeclRefExpr once the
1717/// declaration can be found.
1718class DependentScopeDeclRefExpr : public Expr {
1719  /// The name of the entity we will be referencing.
1720  DeclarationNameInfo NameInfo;
1721
1722  /// QualifierRange - The source range that covers the
1723  /// nested-name-specifier.
1724  SourceRange QualifierRange;
1725
1726  /// \brief The nested-name-specifier that qualifies this unresolved
1727  /// declaration name.
1728  NestedNameSpecifier *Qualifier;
1729
1730  /// \brief Whether the name includes explicit template arguments.
1731  bool HasExplicitTemplateArgs;
1732
1733  DependentScopeDeclRefExpr(QualType T,
1734                            NestedNameSpecifier *Qualifier,
1735                            SourceRange QualifierRange,
1736                            const DeclarationNameInfo &NameInfo,
1737                            bool HasExplicitTemplateArgs)
1738    : Expr(DependentScopeDeclRefExprClass, T, true, true),
1739      NameInfo(NameInfo), QualifierRange(QualifierRange), Qualifier(Qualifier),
1740      HasExplicitTemplateArgs(HasExplicitTemplateArgs)
1741  {}
1742
1743public:
1744  static DependentScopeDeclRefExpr *Create(ASTContext &C,
1745                                           NestedNameSpecifier *Qualifier,
1746                                           SourceRange QualifierRange,
1747                                           const DeclarationNameInfo &NameInfo,
1748                              const TemplateArgumentListInfo *TemplateArgs = 0);
1749
1750  static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
1751                                                unsigned NumTemplateArgs);
1752
1753  /// \brief Retrieve the name that this expression refers to.
1754  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1755  void setNameInfo(const DeclarationNameInfo &N) { NameInfo =  N; }
1756
1757  /// \brief Retrieve the name that this expression refers to.
1758  DeclarationName getDeclName() const { return NameInfo.getName(); }
1759  void setDeclName(DeclarationName N) { NameInfo.setName(N); }
1760
1761  /// \brief Retrieve the location of the name within the expression.
1762  SourceLocation getLocation() const { return NameInfo.getLoc(); }
1763  void setLocation(SourceLocation L) { NameInfo.setLoc(L); }
1764
1765  /// \brief Retrieve the source range of the nested-name-specifier.
1766  SourceRange getQualifierRange() const { return QualifierRange; }
1767  void setQualifierRange(SourceRange R) { QualifierRange = R; }
1768
1769  /// \brief Retrieve the nested-name-specifier that qualifies this
1770  /// declaration.
1771  NestedNameSpecifier *getQualifier() const { return Qualifier; }
1772  void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
1773
1774  /// Determines whether this lookup had explicit template arguments.
1775  bool hasExplicitTemplateArgs() const { return HasExplicitTemplateArgs; }
1776
1777  // Note that, inconsistently with the explicit-template-argument AST
1778  // nodes, users are *forbidden* from calling these methods on objects
1779  // without explicit template arguments.
1780
1781  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1782    assert(hasExplicitTemplateArgs());
1783    return *reinterpret_cast<ExplicitTemplateArgumentList*>(this + 1);
1784  }
1785
1786  /// Gets a reference to the explicit template argument list.
1787  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1788    assert(hasExplicitTemplateArgs());
1789    return *reinterpret_cast<const ExplicitTemplateArgumentList*>(this + 1);
1790  }
1791
1792  /// \brief Retrieves the optional explicit template arguments.
1793  /// This points to the same data as getExplicitTemplateArgs(), but
1794  /// returns null if there are no explicit template arguments.
1795  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
1796    if (!hasExplicitTemplateArgs()) return 0;
1797    return &getExplicitTemplateArgs();
1798  }
1799
1800  /// \brief Copies the template arguments (if present) into the given
1801  /// structure.
1802  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1803    getExplicitTemplateArgs().copyInto(List);
1804  }
1805
1806  SourceLocation getLAngleLoc() const {
1807    return getExplicitTemplateArgs().LAngleLoc;
1808  }
1809
1810  SourceLocation getRAngleLoc() const {
1811    return getExplicitTemplateArgs().RAngleLoc;
1812  }
1813
1814  TemplateArgumentLoc const *getTemplateArgs() const {
1815    return getExplicitTemplateArgs().getTemplateArgs();
1816  }
1817
1818  unsigned getNumTemplateArgs() const {
1819    return getExplicitTemplateArgs().NumTemplateArgs;
1820  }
1821
1822  virtual SourceRange getSourceRange() const {
1823    SourceRange Range(QualifierRange.getBegin(), getLocation());
1824    if (hasExplicitTemplateArgs())
1825      Range.setEnd(getRAngleLoc());
1826    return Range;
1827  }
1828
1829  static bool classof(const Stmt *T) {
1830    return T->getStmtClass() == DependentScopeDeclRefExprClass;
1831  }
1832  static bool classof(const DependentScopeDeclRefExpr *) { return true; }
1833
1834  virtual StmtIterator child_begin();
1835  virtual StmtIterator child_end();
1836};
1837
1838class CXXExprWithTemporaries : public Expr {
1839  Stmt *SubExpr;
1840
1841  CXXTemporary **Temps;
1842  unsigned NumTemps;
1843
1844  CXXExprWithTemporaries(ASTContext &C, Expr *SubExpr, CXXTemporary **Temps,
1845                         unsigned NumTemps);
1846
1847public:
1848  CXXExprWithTemporaries(EmptyShell Empty)
1849    : Expr(CXXExprWithTemporariesClass, Empty),
1850      SubExpr(0), Temps(0), NumTemps(0) {}
1851
1852  static CXXExprWithTemporaries *Create(ASTContext &C, Expr *SubExpr,
1853                                        CXXTemporary **Temps,
1854                                        unsigned NumTemps);
1855
1856  unsigned getNumTemporaries() const { return NumTemps; }
1857  void setNumTemporaries(ASTContext &C, unsigned N);
1858
1859  CXXTemporary *getTemporary(unsigned i) {
1860    assert(i < NumTemps && "Index out of range");
1861    return Temps[i];
1862  }
1863  const CXXTemporary *getTemporary(unsigned i) const {
1864    return const_cast<CXXExprWithTemporaries*>(this)->getTemporary(i);
1865  }
1866  void setTemporary(unsigned i, CXXTemporary *T) {
1867    assert(i < NumTemps && "Index out of range");
1868    Temps[i] = T;
1869  }
1870
1871  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
1872  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
1873  void setSubExpr(Expr *E) { SubExpr = E; }
1874
1875  virtual SourceRange getSourceRange() const {
1876    return SubExpr->getSourceRange();
1877  }
1878
1879  // Implement isa/cast/dyncast/etc.
1880  static bool classof(const Stmt *T) {
1881    return T->getStmtClass() == CXXExprWithTemporariesClass;
1882  }
1883  static bool classof(const CXXExprWithTemporaries *) { return true; }
1884
1885  // Iterators
1886  virtual child_iterator child_begin();
1887  virtual child_iterator child_end();
1888};
1889
1890/// \brief Describes an explicit type conversion that uses functional
1891/// notion but could not be resolved because one or more arguments are
1892/// type-dependent.
1893///
1894/// The explicit type conversions expressed by
1895/// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
1896/// where \c T is some type and \c a1, a2, ..., aN are values, and
1897/// either \C T is a dependent type or one or more of the \c a's is
1898/// type-dependent. For example, this would occur in a template such
1899/// as:
1900///
1901/// \code
1902///   template<typename T, typename A1>
1903///   inline T make_a(const A1& a1) {
1904///     return T(a1);
1905///   }
1906/// \endcode
1907///
1908/// When the returned expression is instantiated, it may resolve to a
1909/// constructor call, conversion function call, or some kind of type
1910/// conversion.
1911class CXXUnresolvedConstructExpr : public Expr {
1912  /// \brief The type being constructed.
1913  TypeSourceInfo *Type;
1914
1915  /// \brief The location of the left parentheses ('(').
1916  SourceLocation LParenLoc;
1917
1918  /// \brief The location of the right parentheses (')').
1919  SourceLocation RParenLoc;
1920
1921  /// \brief The number of arguments used to construct the type.
1922  unsigned NumArgs;
1923
1924  CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
1925                             SourceLocation LParenLoc,
1926                             Expr **Args,
1927                             unsigned NumArgs,
1928                             SourceLocation RParenLoc);
1929
1930  CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
1931    : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
1932
1933  friend class ASTStmtReader;
1934
1935public:
1936  static CXXUnresolvedConstructExpr *Create(ASTContext &C,
1937                                            TypeSourceInfo *Type,
1938                                            SourceLocation LParenLoc,
1939                                            Expr **Args,
1940                                            unsigned NumArgs,
1941                                            SourceLocation RParenLoc);
1942
1943  static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
1944                                                 unsigned NumArgs);
1945
1946  /// \brief Retrieve the type that is being constructed, as specified
1947  /// in the source code.
1948  QualType getTypeAsWritten() const { return Type->getType(); }
1949
1950  /// \brief Retrieve the type source information for the type being
1951  /// constructed.
1952  TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1953
1954  /// \brief Retrieve the location of the left parentheses ('(') that
1955  /// precedes the argument list.
1956  SourceLocation getLParenLoc() const { return LParenLoc; }
1957  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1958
1959  /// \brief Retrieve the location of the right parentheses (')') that
1960  /// follows the argument list.
1961  SourceLocation getRParenLoc() const { return RParenLoc; }
1962  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1963
1964  /// \brief Retrieve the number of arguments.
1965  unsigned arg_size() const { return NumArgs; }
1966
1967  typedef Expr** arg_iterator;
1968  arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
1969  arg_iterator arg_end() { return arg_begin() + NumArgs; }
1970
1971  typedef const Expr* const * const_arg_iterator;
1972  const_arg_iterator arg_begin() const {
1973    return reinterpret_cast<const Expr* const *>(this + 1);
1974  }
1975  const_arg_iterator arg_end() const {
1976    return arg_begin() + NumArgs;
1977  }
1978
1979  Expr *getArg(unsigned I) {
1980    assert(I < NumArgs && "Argument index out-of-range");
1981    return *(arg_begin() + I);
1982  }
1983
1984  const Expr *getArg(unsigned I) const {
1985    assert(I < NumArgs && "Argument index out-of-range");
1986    return *(arg_begin() + I);
1987  }
1988
1989  void setArg(unsigned I, Expr *E) {
1990    assert(I < NumArgs && "Argument index out-of-range");
1991    *(arg_begin() + I) = E;
1992  }
1993
1994  virtual SourceRange getSourceRange() const;
1995
1996  static bool classof(const Stmt *T) {
1997    return T->getStmtClass() == CXXUnresolvedConstructExprClass;
1998  }
1999  static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2000
2001  // Iterators
2002  virtual child_iterator child_begin();
2003  virtual child_iterator child_end();
2004};
2005
2006/// \brief Represents a C++ member access expression where the actual
2007/// member referenced could not be resolved because the base
2008/// expression or the member name was dependent.
2009///
2010/// Like UnresolvedMemberExprs, these can be either implicit or
2011/// explicit accesses.  It is only possible to get one of these with
2012/// an implicit access if a qualifier is provided.
2013class CXXDependentScopeMemberExpr : public Expr {
2014  /// \brief The expression for the base pointer or class reference,
2015  /// e.g., the \c x in x.f.  Can be null in implicit accesses.
2016  Stmt *Base;
2017
2018  /// \brief The type of the base expression.  Never null, even for
2019  /// implicit accesses.
2020  QualType BaseType;
2021
2022  /// \brief Whether this member expression used the '->' operator or
2023  /// the '.' operator.
2024  bool IsArrow : 1;
2025
2026  /// \brief Whether this member expression has explicitly-specified template
2027  /// arguments.
2028  bool HasExplicitTemplateArgs : 1;
2029
2030  /// \brief The location of the '->' or '.' operator.
2031  SourceLocation OperatorLoc;
2032
2033  /// \brief The nested-name-specifier that precedes the member name, if any.
2034  NestedNameSpecifier *Qualifier;
2035
2036  /// \brief The source range covering the nested name specifier.
2037  SourceRange QualifierRange;
2038
2039  /// \brief In a qualified member access expression such as t->Base::f, this
2040  /// member stores the resolves of name lookup in the context of the member
2041  /// access expression, to be used at instantiation time.
2042  ///
2043  /// FIXME: This member, along with the Qualifier and QualifierRange, could
2044  /// be stuck into a structure that is optionally allocated at the end of
2045  /// the CXXDependentScopeMemberExpr, to save space in the common case.
2046  NamedDecl *FirstQualifierFoundInScope;
2047
2048  /// \brief The member to which this member expression refers, which
2049  /// can be name, overloaded operator, or destructor.
2050  /// FIXME: could also be a template-id
2051  DeclarationNameInfo MemberNameInfo;
2052
2053  CXXDependentScopeMemberExpr(ASTContext &C,
2054                          Expr *Base, QualType BaseType, bool IsArrow,
2055                          SourceLocation OperatorLoc,
2056                          NestedNameSpecifier *Qualifier,
2057                          SourceRange QualifierRange,
2058                          NamedDecl *FirstQualifierFoundInScope,
2059                          DeclarationNameInfo MemberNameInfo,
2060                          const TemplateArgumentListInfo *TemplateArgs);
2061
2062public:
2063  CXXDependentScopeMemberExpr(ASTContext &C,
2064                          Expr *Base, QualType BaseType,
2065                          bool IsArrow,
2066                          SourceLocation OperatorLoc,
2067                          NestedNameSpecifier *Qualifier,
2068                          SourceRange QualifierRange,
2069                          NamedDecl *FirstQualifierFoundInScope,
2070                          DeclarationNameInfo MemberNameInfo)
2071  : Expr(CXXDependentScopeMemberExprClass, C.DependentTy, true, true),
2072    Base(Base), BaseType(BaseType), IsArrow(IsArrow),
2073    HasExplicitTemplateArgs(false), OperatorLoc(OperatorLoc),
2074    Qualifier(Qualifier), QualifierRange(QualifierRange),
2075    FirstQualifierFoundInScope(FirstQualifierFoundInScope),
2076    MemberNameInfo(MemberNameInfo) { }
2077
2078  static CXXDependentScopeMemberExpr *
2079  Create(ASTContext &C,
2080         Expr *Base, QualType BaseType, bool IsArrow,
2081         SourceLocation OperatorLoc,
2082         NestedNameSpecifier *Qualifier,
2083         SourceRange QualifierRange,
2084         NamedDecl *FirstQualifierFoundInScope,
2085         DeclarationNameInfo MemberNameInfo,
2086         const TemplateArgumentListInfo *TemplateArgs);
2087
2088  static CXXDependentScopeMemberExpr *
2089  CreateEmpty(ASTContext &C, unsigned NumTemplateArgs);
2090
2091  /// \brief True if this is an implicit access, i.e. one in which the
2092  /// member being accessed was not written in the source.  The source
2093  /// location of the operator is invalid in this case.
2094  bool isImplicitAccess() const { return Base == 0; }
2095
2096  /// \brief Retrieve the base object of this member expressions,
2097  /// e.g., the \c x in \c x.m.
2098  Expr *getBase() const {
2099    assert(!isImplicitAccess());
2100    return cast<Expr>(Base);
2101  }
2102  void setBase(Expr *E) { Base = E; }
2103
2104  QualType getBaseType() const { return BaseType; }
2105  void setBaseType(QualType T) { BaseType = T; }
2106
2107  /// \brief Determine whether this member expression used the '->'
2108  /// operator; otherwise, it used the '.' operator.
2109  bool isArrow() const { return IsArrow; }
2110  void setArrow(bool A) { IsArrow = A; }
2111
2112  /// \brief Retrieve the location of the '->' or '.' operator.
2113  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2114  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2115
2116  /// \brief Retrieve the nested-name-specifier that qualifies the member
2117  /// name.
2118  NestedNameSpecifier *getQualifier() const { return Qualifier; }
2119  void setQualifier(NestedNameSpecifier *NNS) { Qualifier = NNS; }
2120
2121  /// \brief Retrieve the source range covering the nested-name-specifier
2122  /// that qualifies the member name.
2123  SourceRange getQualifierRange() const { return QualifierRange; }
2124  void setQualifierRange(SourceRange R) { QualifierRange = R; }
2125
2126  /// \brief Retrieve the first part of the nested-name-specifier that was
2127  /// found in the scope of the member access expression when the member access
2128  /// was initially parsed.
2129  ///
2130  /// This function only returns a useful result when member access expression
2131  /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2132  /// returned by this function describes what was found by unqualified name
2133  /// lookup for the identifier "Base" within the scope of the member access
2134  /// expression itself. At template instantiation time, this information is
2135  /// combined with the results of name lookup into the type of the object
2136  /// expression itself (the class type of x).
2137  NamedDecl *getFirstQualifierFoundInScope() const {
2138    return FirstQualifierFoundInScope;
2139  }
2140  void setFirstQualifierFoundInScope(NamedDecl *D) {
2141    FirstQualifierFoundInScope = D;
2142  }
2143
2144  /// \brief Retrieve the name of the member that this expression
2145  /// refers to.
2146  const DeclarationNameInfo &getMemberNameInfo() const {
2147    return MemberNameInfo;
2148  }
2149  void setMemberNameInfo(const DeclarationNameInfo &N) { MemberNameInfo = N; }
2150
2151  /// \brief Retrieve the name of the member that this expression
2152  /// refers to.
2153  DeclarationName getMember() const { return MemberNameInfo.getName(); }
2154  void setMember(DeclarationName N) { MemberNameInfo.setName(N); }
2155
2156  // \brief Retrieve the location of the name of the member that this
2157  // expression refers to.
2158  SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
2159  void setMemberLoc(SourceLocation L) { MemberNameInfo.setLoc(L); }
2160
2161  /// \brief Determines whether this member expression actually had a C++
2162  /// template argument list explicitly specified, e.g., x.f<int>.
2163  bool hasExplicitTemplateArgs() const {
2164    return HasExplicitTemplateArgs;
2165  }
2166
2167  /// \brief Retrieve the explicit template argument list that followed the
2168  /// member template name, if any.
2169  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2170    assert(HasExplicitTemplateArgs);
2171    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2172  }
2173
2174  /// \brief Retrieve the explicit template argument list that followed the
2175  /// member template name, if any.
2176  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2177    return const_cast<CXXDependentScopeMemberExpr *>(this)
2178             ->getExplicitTemplateArgs();
2179  }
2180
2181  /// \brief Retrieves the optional explicit template arguments.
2182  /// This points to the same data as getExplicitTemplateArgs(), but
2183  /// returns null if there are no explicit template arguments.
2184  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2185    if (!hasExplicitTemplateArgs()) return 0;
2186    return &getExplicitTemplateArgs();
2187  }
2188
2189  /// \brief Copies the template arguments (if present) into the given
2190  /// structure.
2191  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2192    getExplicitTemplateArgs().copyInto(List);
2193  }
2194
2195  /// \brief Initializes the template arguments using the given structure.
2196  void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
2197    getExplicitTemplateArgs().initializeFrom(List);
2198  }
2199
2200  /// \brief Retrieve the location of the left angle bracket following the
2201  /// member name ('<'), if any.
2202  SourceLocation getLAngleLoc() const {
2203    return getExplicitTemplateArgs().LAngleLoc;
2204  }
2205
2206  /// \brief Retrieve the template arguments provided as part of this
2207  /// template-id.
2208  const TemplateArgumentLoc *getTemplateArgs() const {
2209    return getExplicitTemplateArgs().getTemplateArgs();
2210  }
2211
2212  /// \brief Retrieve the number of template arguments provided as part of this
2213  /// template-id.
2214  unsigned getNumTemplateArgs() const {
2215    return getExplicitTemplateArgs().NumTemplateArgs;
2216  }
2217
2218  /// \brief Retrieve the location of the right angle bracket following the
2219  /// template arguments ('>').
2220  SourceLocation getRAngleLoc() const {
2221    return getExplicitTemplateArgs().RAngleLoc;
2222  }
2223
2224  virtual SourceRange getSourceRange() const {
2225    SourceRange Range;
2226    if (!isImplicitAccess())
2227      Range.setBegin(Base->getSourceRange().getBegin());
2228    else if (getQualifier())
2229      Range.setBegin(getQualifierRange().getBegin());
2230    else
2231      Range.setBegin(MemberNameInfo.getBeginLoc());
2232
2233    if (hasExplicitTemplateArgs())
2234      Range.setEnd(getRAngleLoc());
2235    else
2236      Range.setEnd(MemberNameInfo.getEndLoc());
2237    return Range;
2238  }
2239
2240  static bool classof(const Stmt *T) {
2241    return T->getStmtClass() == CXXDependentScopeMemberExprClass;
2242  }
2243  static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
2244
2245  // Iterators
2246  virtual child_iterator child_begin();
2247  virtual child_iterator child_end();
2248};
2249
2250/// \brief Represents a C++ member access expression for which lookup
2251/// produced a set of overloaded functions.
2252///
2253/// The member access may be explicit or implicit:
2254///    struct A {
2255///      int a, b;
2256///      int explicitAccess() { return this->a + this->A::b; }
2257///      int implicitAccess() { return a + A::b; }
2258///    };
2259///
2260/// In the final AST, an explicit access always becomes a MemberExpr.
2261/// An implicit access may become either a MemberExpr or a
2262/// DeclRefExpr, depending on whether the member is static.
2263class UnresolvedMemberExpr : public OverloadExpr {
2264  /// \brief Whether this member expression used the '->' operator or
2265  /// the '.' operator.
2266  bool IsArrow : 1;
2267
2268  /// \brief Whether the lookup results contain an unresolved using
2269  /// declaration.
2270  bool HasUnresolvedUsing : 1;
2271
2272  /// \brief The expression for the base pointer or class reference,
2273  /// e.g., the \c x in x.f.  This can be null if this is an 'unbased'
2274  /// member expression
2275  Stmt *Base;
2276
2277  /// \brief The type of the base expression;  never null.
2278  QualType BaseType;
2279
2280  /// \brief The location of the '->' or '.' operator.
2281  SourceLocation OperatorLoc;
2282
2283  UnresolvedMemberExpr(ASTContext &C, QualType T, bool Dependent,
2284                       bool HasUnresolvedUsing,
2285                       Expr *Base, QualType BaseType, bool IsArrow,
2286                       SourceLocation OperatorLoc,
2287                       NestedNameSpecifier *Qualifier,
2288                       SourceRange QualifierRange,
2289                       const DeclarationNameInfo &MemberNameInfo,
2290                       const TemplateArgumentListInfo *TemplateArgs,
2291                       UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2292
2293  UnresolvedMemberExpr(EmptyShell Empty)
2294    : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
2295      HasUnresolvedUsing(false), Base(0) { }
2296
2297public:
2298  static UnresolvedMemberExpr *
2299  Create(ASTContext &C, bool Dependent, bool HasUnresolvedUsing,
2300         Expr *Base, QualType BaseType, bool IsArrow,
2301         SourceLocation OperatorLoc,
2302         NestedNameSpecifier *Qualifier,
2303         SourceRange QualifierRange,
2304         const DeclarationNameInfo &MemberNameInfo,
2305         const TemplateArgumentListInfo *TemplateArgs,
2306         UnresolvedSetIterator Begin, UnresolvedSetIterator End);
2307
2308  static UnresolvedMemberExpr *
2309  CreateEmpty(ASTContext &C, unsigned NumTemplateArgs);
2310
2311  /// \brief True if this is an implicit access, i.e. one in which the
2312  /// member being accessed was not written in the source.  The source
2313  /// location of the operator is invalid in this case.
2314  bool isImplicitAccess() const { return Base == 0; }
2315
2316  /// \brief Retrieve the base object of this member expressions,
2317  /// e.g., the \c x in \c x.m.
2318  Expr *getBase() {
2319    assert(!isImplicitAccess());
2320    return cast<Expr>(Base);
2321  }
2322  const Expr *getBase() const {
2323    assert(!isImplicitAccess());
2324    return cast<Expr>(Base);
2325  }
2326  void setBase(Expr *E) { Base = E; }
2327
2328  QualType getBaseType() const { return BaseType; }
2329  void setBaseType(QualType T) { BaseType = T; }
2330
2331  /// \brief Determine whether the lookup results contain an unresolved using
2332  /// declaration.
2333  bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
2334  void setHasUnresolvedUsing(bool V) { HasUnresolvedUsing = V; }
2335
2336  /// \brief Determine whether this member expression used the '->'
2337  /// operator; otherwise, it used the '.' operator.
2338  bool isArrow() const { return IsArrow; }
2339  void setArrow(bool A) { IsArrow = A; }
2340
2341  /// \brief Retrieve the location of the '->' or '.' operator.
2342  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2343  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2344
2345  /// \brief Retrieves the naming class of this lookup.
2346  CXXRecordDecl *getNamingClass() const;
2347
2348  /// \brief Retrieve the full name info for the member that this expression
2349  /// refers to.
2350  const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
2351  void setMemberNameInfo(const DeclarationNameInfo &N) { setNameInfo(N); }
2352
2353  /// \brief Retrieve the name of the member that this expression
2354  /// refers to.
2355  DeclarationName getMemberName() const { return getName(); }
2356  void setMemberName(DeclarationName N) { setName(N); }
2357
2358  // \brief Retrieve the location of the name of the member that this
2359  // expression refers to.
2360  SourceLocation getMemberLoc() const { return getNameLoc(); }
2361  void setMemberLoc(SourceLocation L) { setNameLoc(L); }
2362
2363  /// \brief Retrieve the explicit template argument list that followed the
2364  /// member template name.
2365  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
2366    assert(hasExplicitTemplateArgs());
2367    return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
2368  }
2369
2370  /// \brief Retrieve the explicit template argument list that followed the
2371  /// member template name, if any.
2372  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
2373    assert(hasExplicitTemplateArgs());
2374    return *reinterpret_cast<const ExplicitTemplateArgumentList *>(this + 1);
2375  }
2376
2377  /// \brief Retrieves the optional explicit template arguments.
2378  /// This points to the same data as getExplicitTemplateArgs(), but
2379  /// returns null if there are no explicit template arguments.
2380  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() {
2381    if (!hasExplicitTemplateArgs()) return 0;
2382    return &getExplicitTemplateArgs();
2383  }
2384
2385  /// \brief Copies the template arguments into the given structure.
2386  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2387    getExplicitTemplateArgs().copyInto(List);
2388  }
2389
2390  /// \brief Retrieve the location of the left angle bracket following
2391  /// the member name ('<').
2392  SourceLocation getLAngleLoc() const {
2393    return getExplicitTemplateArgs().LAngleLoc;
2394  }
2395
2396  /// \brief Retrieve the template arguments provided as part of this
2397  /// template-id.
2398  const TemplateArgumentLoc *getTemplateArgs() const {
2399    return getExplicitTemplateArgs().getTemplateArgs();
2400  }
2401
2402  /// \brief Retrieve the number of template arguments provided as
2403  /// part of this template-id.
2404  unsigned getNumTemplateArgs() const {
2405    return getExplicitTemplateArgs().NumTemplateArgs;
2406  }
2407
2408  /// \brief Retrieve the location of the right angle bracket
2409  /// following the template arguments ('>').
2410  SourceLocation getRAngleLoc() const {
2411    return getExplicitTemplateArgs().RAngleLoc;
2412  }
2413
2414  virtual SourceRange getSourceRange() const {
2415    SourceRange Range = getMemberNameInfo().getSourceRange();
2416    if (!isImplicitAccess())
2417      Range.setBegin(Base->getSourceRange().getBegin());
2418    else if (getQualifier())
2419      Range.setBegin(getQualifierRange().getBegin());
2420
2421    if (hasExplicitTemplateArgs())
2422      Range.setEnd(getRAngleLoc());
2423    return Range;
2424  }
2425
2426  static bool classof(const Stmt *T) {
2427    return T->getStmtClass() == UnresolvedMemberExprClass;
2428  }
2429  static bool classof(const UnresolvedMemberExpr *) { return true; }
2430
2431  // Iterators
2432  virtual child_iterator child_begin();
2433  virtual child_iterator child_end();
2434};
2435
2436/// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
2437///
2438/// The noexcept expression tests whether a given expression might throw. Its
2439/// result is a boolean constant.
2440class CXXNoexceptExpr : public Expr {
2441  bool Value : 1;
2442  Stmt *Operand;
2443  SourceRange Range;
2444
2445  friend class ASTStmtReader;
2446
2447public:
2448  CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
2449                  SourceLocation Keyword, SourceLocation RParen)
2450    : Expr(CXXNoexceptExprClass, Ty, /*TypeDependent*/false,
2451           /*ValueDependent*/Val == CT_Dependent),
2452      Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
2453  { }
2454
2455  CXXNoexceptExpr(EmptyShell Empty)
2456    : Expr(CXXNoexceptExprClass, Empty)
2457  { }
2458
2459  Expr *getOperand() const { return static_cast<Expr*>(Operand); }
2460
2461  virtual SourceRange getSourceRange() const { return Range; }
2462
2463  bool getValue() const { return Value; }
2464
2465  static bool classof(const Stmt *T) {
2466    return T->getStmtClass() == CXXNoexceptExprClass;
2467  }
2468  static bool classof(const CXXNoexceptExpr *) { return true; }
2469
2470  // Iterators
2471  virtual child_iterator child_begin();
2472  virtual child_iterator child_end();
2473};
2474
2475inline ExplicitTemplateArgumentList &OverloadExpr::getExplicitTemplateArgs() {
2476  if (isa<UnresolvedLookupExpr>(this))
2477    return cast<UnresolvedLookupExpr>(this)->getExplicitTemplateArgs();
2478  else
2479    return cast<UnresolvedMemberExpr>(this)->getExplicitTemplateArgs();
2480}
2481
2482}  // end namespace clang
2483
2484#endif
2485