1 //===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the Expr interface and subclasses for C++ expressions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_EXPRCXX_H
15 #define LLVM_CLANG_AST_EXPRCXX_H
16
17 #include "clang/AST/Expr.h"
18 #include "clang/AST/UnresolvedSet.h"
19 #include "clang/AST/TemplateBase.h"
20 #include "clang/Basic/ExpressionTraits.h"
21 #include "clang/Basic/Lambda.h"
22 #include "clang/Basic/TypeTraits.h"
23 #include "llvm/Support/Compiler.h"
24
25 namespace clang {
26
27 class CXXConstructorDecl;
28 class CXXDestructorDecl;
29 class CXXMethodDecl;
30 class CXXTemporary;
31 class TemplateArgumentListInfo;
32
33 //===--------------------------------------------------------------------===//
34 // C++ Expressions.
35 //===--------------------------------------------------------------------===//
36
37 /// \brief A call to an overloaded operator written using operator
38 /// syntax.
39 ///
40 /// Represents a call to an overloaded operator written using operator
41 /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a
42 /// normal call, this AST node provides better information about the
43 /// syntactic representation of the call.
44 ///
45 /// In a C++ template, this expression node kind will be used whenever
46 /// any of the arguments are type-dependent. In this case, the
47 /// function itself will be a (possibly empty) set of functions and
48 /// function templates that were found by name lookup at template
49 /// definition time.
50 class CXXOperatorCallExpr : public CallExpr {
51 /// \brief The overloaded operator.
52 OverloadedOperatorKind Operator;
53
54 public:
CXXOperatorCallExpr(ASTContext & C,OverloadedOperatorKind Op,Expr * fn,Expr ** args,unsigned numargs,QualType t,ExprValueKind VK,SourceLocation operatorloc)55 CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
56 Expr **args, unsigned numargs, QualType t,
57 ExprValueKind VK, SourceLocation operatorloc)
58 : CallExpr(C, CXXOperatorCallExprClass, fn, 0, args, numargs, t, VK,
59 operatorloc),
60 Operator(Op) {}
CXXOperatorCallExpr(ASTContext & C,EmptyShell Empty)61 explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
62 CallExpr(C, CXXOperatorCallExprClass, Empty) { }
63
64
65 /// getOperator - Returns the kind of overloaded operator that this
66 /// expression refers to.
getOperator()67 OverloadedOperatorKind getOperator() const { return Operator; }
setOperator(OverloadedOperatorKind Kind)68 void setOperator(OverloadedOperatorKind Kind) { Operator = Kind; }
69
70 /// getOperatorLoc - Returns the location of the operator symbol in
71 /// the expression. When @c getOperator()==OO_Call, this is the
72 /// location of the right parentheses; when @c
73 /// getOperator()==OO_Subscript, this is the location of the right
74 /// bracket.
getOperatorLoc()75 SourceLocation getOperatorLoc() const { return getRParenLoc(); }
76
77 SourceRange getSourceRange() const LLVM_READONLY;
78
classof(const Stmt * T)79 static bool classof(const Stmt *T) {
80 return T->getStmtClass() == CXXOperatorCallExprClass;
81 }
classof(const CXXOperatorCallExpr *)82 static bool classof(const CXXOperatorCallExpr *) { return true; }
83 };
84
85 /// CXXMemberCallExpr - Represents a call to a member function that
86 /// may be written either with member call syntax (e.g., "obj.func()"
87 /// or "objptr->func()") or with normal function-call syntax
88 /// ("func()") within a member function that ends up calling a member
89 /// function. The callee in either case is a MemberExpr that contains
90 /// both the object argument and the member function, while the
91 /// arguments are the arguments within the parentheses (not including
92 /// the object argument).
93 class CXXMemberCallExpr : public CallExpr {
94 public:
CXXMemberCallExpr(ASTContext & C,Expr * fn,Expr ** args,unsigned numargs,QualType t,ExprValueKind VK,SourceLocation RP)95 CXXMemberCallExpr(ASTContext &C, Expr *fn, Expr **args, unsigned numargs,
96 QualType t, ExprValueKind VK, SourceLocation RP)
97 : CallExpr(C, CXXMemberCallExprClass, fn, 0, args, numargs, t, VK, RP) {}
98
CXXMemberCallExpr(ASTContext & C,EmptyShell Empty)99 CXXMemberCallExpr(ASTContext &C, EmptyShell Empty)
100 : CallExpr(C, CXXMemberCallExprClass, Empty) { }
101
102 /// getImplicitObjectArgument - Retrieves the implicit object
103 /// argument for the member call. For example, in "x.f(5)", this
104 /// operation would return "x".
105 Expr *getImplicitObjectArgument() const;
106
107 /// Retrieves the declaration of the called method.
108 CXXMethodDecl *getMethodDecl() const;
109
110 /// getRecordDecl - Retrieves the CXXRecordDecl for the underlying type of
111 /// the implicit object argument. Note that this is may not be the same
112 /// declaration as that of the class context of the CXXMethodDecl which this
113 /// function is calling.
114 /// FIXME: Returns 0 for member pointer call exprs.
115 CXXRecordDecl *getRecordDecl();
116
classof(const Stmt * T)117 static bool classof(const Stmt *T) {
118 return T->getStmtClass() == CXXMemberCallExprClass;
119 }
classof(const CXXMemberCallExpr *)120 static bool classof(const CXXMemberCallExpr *) { return true; }
121 };
122
123 /// CUDAKernelCallExpr - Represents a call to a CUDA kernel function.
124 class CUDAKernelCallExpr : public CallExpr {
125 private:
126 enum { CONFIG, END_PREARG };
127
128 public:
CUDAKernelCallExpr(ASTContext & C,Expr * fn,CallExpr * Config,Expr ** args,unsigned numargs,QualType t,ExprValueKind VK,SourceLocation RP)129 CUDAKernelCallExpr(ASTContext &C, Expr *fn, CallExpr *Config,
130 Expr **args, unsigned numargs, QualType t,
131 ExprValueKind VK, SourceLocation RP)
132 : CallExpr(C, CUDAKernelCallExprClass, fn, END_PREARG, args, numargs, t, VK,
133 RP) {
134 setConfig(Config);
135 }
136
CUDAKernelCallExpr(ASTContext & C,EmptyShell Empty)137 CUDAKernelCallExpr(ASTContext &C, EmptyShell Empty)
138 : CallExpr(C, CUDAKernelCallExprClass, END_PREARG, Empty) { }
139
getConfig()140 const CallExpr *getConfig() const {
141 return cast_or_null<CallExpr>(getPreArg(CONFIG));
142 }
getConfig()143 CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); }
setConfig(CallExpr * E)144 void setConfig(CallExpr *E) { setPreArg(CONFIG, E); }
145
classof(const Stmt * T)146 static bool classof(const Stmt *T) {
147 return T->getStmtClass() == CUDAKernelCallExprClass;
148 }
classof(const CUDAKernelCallExpr *)149 static bool classof(const CUDAKernelCallExpr *) { return true; }
150 };
151
152 /// CXXNamedCastExpr - Abstract class common to all of the C++ "named"
153 /// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c
154 /// const_cast.
155 ///
156 /// This abstract class is inherited by all of the classes
157 /// representing "named" casts, e.g., CXXStaticCastExpr,
158 /// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr.
159 class CXXNamedCastExpr : public ExplicitCastExpr {
160 private:
161 SourceLocation Loc; // the location of the casting op
162 SourceLocation RParenLoc; // the location of the right parenthesis
163
164 protected:
CXXNamedCastExpr(StmtClass SC,QualType ty,ExprValueKind VK,CastKind kind,Expr * op,unsigned PathSize,TypeSourceInfo * writtenTy,SourceLocation l,SourceLocation RParenLoc)165 CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK,
166 CastKind kind, Expr *op, unsigned PathSize,
167 TypeSourceInfo *writtenTy, SourceLocation l,
168 SourceLocation RParenLoc)
169 : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, writtenTy), Loc(l),
170 RParenLoc(RParenLoc) {}
171
CXXNamedCastExpr(StmtClass SC,EmptyShell Shell,unsigned PathSize)172 explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
173 : ExplicitCastExpr(SC, Shell, PathSize) { }
174
175 friend class ASTStmtReader;
176
177 public:
178 const char *getCastName() const;
179
180 /// \brief Retrieve the location of the cast operator keyword, e.g.,
181 /// "static_cast".
getOperatorLoc()182 SourceLocation getOperatorLoc() const { return Loc; }
183
184 /// \brief Retrieve the location of the closing parenthesis.
getRParenLoc()185 SourceLocation getRParenLoc() const { return RParenLoc; }
186
getSourceRange()187 SourceRange getSourceRange() const LLVM_READONLY {
188 return SourceRange(Loc, RParenLoc);
189 }
classof(const Stmt * T)190 static bool classof(const Stmt *T) {
191 switch (T->getStmtClass()) {
192 case CXXStaticCastExprClass:
193 case CXXDynamicCastExprClass:
194 case CXXReinterpretCastExprClass:
195 case CXXConstCastExprClass:
196 return true;
197 default:
198 return false;
199 }
200 }
classof(const CXXNamedCastExpr *)201 static bool classof(const CXXNamedCastExpr *) { return true; }
202 };
203
204 /// CXXStaticCastExpr - A C++ @c static_cast expression
205 /// (C++ [expr.static.cast]).
206 ///
207 /// This expression node represents a C++ static cast, e.g.,
208 /// @c static_cast<int>(1.0).
209 class CXXStaticCastExpr : public CXXNamedCastExpr {
CXXStaticCastExpr(QualType ty,ExprValueKind vk,CastKind kind,Expr * op,unsigned pathSize,TypeSourceInfo * writtenTy,SourceLocation l,SourceLocation RParenLoc)210 CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op,
211 unsigned pathSize, TypeSourceInfo *writtenTy,
212 SourceLocation l, SourceLocation RParenLoc)
213 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize,
214 writtenTy, l, RParenLoc) {}
215
CXXStaticCastExpr(EmptyShell Empty,unsigned PathSize)216 explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize)
217 : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize) { }
218
219 public:
220 static CXXStaticCastExpr *Create(ASTContext &Context, QualType T,
221 ExprValueKind VK, CastKind K, Expr *Op,
222 const CXXCastPath *Path,
223 TypeSourceInfo *Written, SourceLocation L,
224 SourceLocation RParenLoc);
225 static CXXStaticCastExpr *CreateEmpty(ASTContext &Context,
226 unsigned PathSize);
227
classof(const Stmt * T)228 static bool classof(const Stmt *T) {
229 return T->getStmtClass() == CXXStaticCastExprClass;
230 }
classof(const CXXStaticCastExpr *)231 static bool classof(const CXXStaticCastExpr *) { return true; }
232 };
233
234 /// CXXDynamicCastExpr - A C++ @c dynamic_cast expression
235 /// (C++ [expr.dynamic.cast]), which may perform a run-time check to
236 /// determine how to perform the type cast.
237 ///
238 /// This expression node represents a dynamic cast, e.g.,
239 /// @c dynamic_cast<Derived*>(BasePtr).
240 class CXXDynamicCastExpr : public CXXNamedCastExpr {
CXXDynamicCastExpr(QualType ty,ExprValueKind VK,CastKind kind,Expr * op,unsigned pathSize,TypeSourceInfo * writtenTy,SourceLocation l,SourceLocation RParenLoc)241 CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind,
242 Expr *op, unsigned pathSize, TypeSourceInfo *writtenTy,
243 SourceLocation l, SourceLocation RParenLoc)
244 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize,
245 writtenTy, l, RParenLoc) {}
246
CXXDynamicCastExpr(EmptyShell Empty,unsigned pathSize)247 explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize)
248 : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize) { }
249
250 public:
251 static CXXDynamicCastExpr *Create(ASTContext &Context, QualType T,
252 ExprValueKind VK, CastKind Kind, Expr *Op,
253 const CXXCastPath *Path,
254 TypeSourceInfo *Written, SourceLocation L,
255 SourceLocation RParenLoc);
256
257 static CXXDynamicCastExpr *CreateEmpty(ASTContext &Context,
258 unsigned pathSize);
259
260 bool isAlwaysNull() const;
261
classof(const Stmt * T)262 static bool classof(const Stmt *T) {
263 return T->getStmtClass() == CXXDynamicCastExprClass;
264 }
classof(const CXXDynamicCastExpr *)265 static bool classof(const CXXDynamicCastExpr *) { return true; }
266 };
267
268 /// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++
269 /// [expr.reinterpret.cast]), which provides a differently-typed view
270 /// of a value but performs no actual work at run time.
271 ///
272 /// This expression node represents a reinterpret cast, e.g.,
273 /// @c reinterpret_cast<int>(VoidPtr).
274 class CXXReinterpretCastExpr : public CXXNamedCastExpr {
CXXReinterpretCastExpr(QualType ty,ExprValueKind vk,CastKind kind,Expr * op,unsigned pathSize,TypeSourceInfo * writtenTy,SourceLocation l,SourceLocation RParenLoc)275 CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind,
276 Expr *op, unsigned pathSize,
277 TypeSourceInfo *writtenTy, SourceLocation l,
278 SourceLocation RParenLoc)
279 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op,
280 pathSize, writtenTy, l, RParenLoc) {}
281
CXXReinterpretCastExpr(EmptyShell Empty,unsigned pathSize)282 CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize)
283 : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize) { }
284
285 public:
286 static CXXReinterpretCastExpr *Create(ASTContext &Context, QualType T,
287 ExprValueKind VK, CastKind Kind,
288 Expr *Op, const CXXCastPath *Path,
289 TypeSourceInfo *WrittenTy, SourceLocation L,
290 SourceLocation RParenLoc);
291 static CXXReinterpretCastExpr *CreateEmpty(ASTContext &Context,
292 unsigned pathSize);
293
classof(const Stmt * T)294 static bool classof(const Stmt *T) {
295 return T->getStmtClass() == CXXReinterpretCastExprClass;
296 }
classof(const CXXReinterpretCastExpr *)297 static bool classof(const CXXReinterpretCastExpr *) { return true; }
298 };
299
300 /// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]),
301 /// which can remove type qualifiers but does not change the underlying value.
302 ///
303 /// This expression node represents a const cast, e.g.,
304 /// @c const_cast<char*>(PtrToConstChar).
305 class CXXConstCastExpr : public CXXNamedCastExpr {
CXXConstCastExpr(QualType ty,ExprValueKind VK,Expr * op,TypeSourceInfo * writtenTy,SourceLocation l,SourceLocation RParenLoc)306 CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op,
307 TypeSourceInfo *writtenTy, SourceLocation l,
308 SourceLocation RParenLoc)
309 : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op,
310 0, writtenTy, l, RParenLoc) {}
311
CXXConstCastExpr(EmptyShell Empty)312 explicit CXXConstCastExpr(EmptyShell Empty)
313 : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0) { }
314
315 public:
316 static CXXConstCastExpr *Create(ASTContext &Context, QualType T,
317 ExprValueKind VK, Expr *Op,
318 TypeSourceInfo *WrittenTy, SourceLocation L,
319 SourceLocation RParenLoc);
320 static CXXConstCastExpr *CreateEmpty(ASTContext &Context);
321
classof(const Stmt * T)322 static bool classof(const Stmt *T) {
323 return T->getStmtClass() == CXXConstCastExprClass;
324 }
classof(const CXXConstCastExpr *)325 static bool classof(const CXXConstCastExpr *) { return true; }
326 };
327
328 /// UserDefinedLiteral - A call to a literal operator (C++11 [over.literal])
329 /// written as a user-defined literal (C++11 [lit.ext]).
330 ///
331 /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this
332 /// is semantically equivalent to a normal call, this AST node provides better
333 /// information about the syntactic representation of the literal.
334 ///
335 /// Since literal operators are never found by ADL and can only be declared at
336 /// namespace scope, a user-defined literal is never dependent.
337 class UserDefinedLiteral : public CallExpr {
338 /// \brief The location of a ud-suffix within the literal.
339 SourceLocation UDSuffixLoc;
340
341 public:
UserDefinedLiteral(ASTContext & C,Expr * Fn,Expr ** Args,unsigned NumArgs,QualType T,ExprValueKind VK,SourceLocation LitEndLoc,SourceLocation SuffixLoc)342 UserDefinedLiteral(ASTContext &C, Expr *Fn, Expr **Args, unsigned NumArgs,
343 QualType T, ExprValueKind VK, SourceLocation LitEndLoc,
344 SourceLocation SuffixLoc)
345 : CallExpr(C, UserDefinedLiteralClass, Fn, 0, Args, NumArgs, T, VK,
346 LitEndLoc), UDSuffixLoc(SuffixLoc) {}
UserDefinedLiteral(ASTContext & C,EmptyShell Empty)347 explicit UserDefinedLiteral(ASTContext &C, EmptyShell Empty)
348 : CallExpr(C, UserDefinedLiteralClass, Empty) {}
349
350 /// The kind of literal operator which is invoked.
351 enum LiteralOperatorKind {
352 LOK_Raw, ///< Raw form: operator "" X (const char *)
353 LOK_Template, ///< Raw form: operator "" X<cs...> ()
354 LOK_Integer, ///< operator "" X (unsigned long long)
355 LOK_Floating, ///< operator "" X (long double)
356 LOK_String, ///< operator "" X (const CharT *, size_t)
357 LOK_Character ///< operator "" X (CharT)
358 };
359
360 /// getLiteralOperatorKind - Returns the kind of literal operator invocation
361 /// which this expression represents.
362 LiteralOperatorKind getLiteralOperatorKind() const;
363
364 /// getCookedLiteral - If this is not a raw user-defined literal, get the
365 /// underlying cooked literal (representing the literal with the suffix
366 /// removed).
367 Expr *getCookedLiteral();
getCookedLiteral()368 const Expr *getCookedLiteral() const {
369 return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral();
370 }
371
372 /// getUDSuffixLoc - Returns the location of a ud-suffix in the expression.
373 /// For a string literal, there may be multiple identical suffixes. This
374 /// returns the first.
getUDSuffixLoc()375 SourceLocation getUDSuffixLoc() const { return getRParenLoc(); }
376
377 /// getUDSuffix - Returns the ud-suffix specified for this literal.
378 const IdentifierInfo *getUDSuffix() const;
379
classof(const Stmt * S)380 static bool classof(const Stmt *S) {
381 return S->getStmtClass() == UserDefinedLiteralClass;
382 }
classof(const UserDefinedLiteral *)383 static bool classof(const UserDefinedLiteral *) { return true; }
384
385 friend class ASTStmtReader;
386 friend class ASTStmtWriter;
387 };
388
389 /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal.
390 ///
391 class CXXBoolLiteralExpr : public Expr {
392 bool Value;
393 SourceLocation Loc;
394 public:
CXXBoolLiteralExpr(bool val,QualType Ty,SourceLocation l)395 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) :
396 Expr(CXXBoolLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
397 false, false),
398 Value(val), Loc(l) {}
399
CXXBoolLiteralExpr(EmptyShell Empty)400 explicit CXXBoolLiteralExpr(EmptyShell Empty)
401 : Expr(CXXBoolLiteralExprClass, Empty) { }
402
getValue()403 bool getValue() const { return Value; }
setValue(bool V)404 void setValue(bool V) { Value = V; }
405
getSourceRange()406 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
407
getLocation()408 SourceLocation getLocation() const { return Loc; }
setLocation(SourceLocation L)409 void setLocation(SourceLocation L) { Loc = L; }
410
classof(const Stmt * T)411 static bool classof(const Stmt *T) {
412 return T->getStmtClass() == CXXBoolLiteralExprClass;
413 }
classof(const CXXBoolLiteralExpr *)414 static bool classof(const CXXBoolLiteralExpr *) { return true; }
415
416 // Iterators
children()417 child_range children() { return child_range(); }
418 };
419
420 /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal
421 class CXXNullPtrLiteralExpr : public Expr {
422 SourceLocation Loc;
423 public:
CXXNullPtrLiteralExpr(QualType Ty,SourceLocation l)424 CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) :
425 Expr(CXXNullPtrLiteralExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
426 false, false),
427 Loc(l) {}
428
CXXNullPtrLiteralExpr(EmptyShell Empty)429 explicit CXXNullPtrLiteralExpr(EmptyShell Empty)
430 : Expr(CXXNullPtrLiteralExprClass, Empty) { }
431
getSourceRange()432 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
433
getLocation()434 SourceLocation getLocation() const { return Loc; }
setLocation(SourceLocation L)435 void setLocation(SourceLocation L) { Loc = L; }
436
classof(const Stmt * T)437 static bool classof(const Stmt *T) {
438 return T->getStmtClass() == CXXNullPtrLiteralExprClass;
439 }
classof(const CXXNullPtrLiteralExpr *)440 static bool classof(const CXXNullPtrLiteralExpr *) { return true; }
441
children()442 child_range children() { return child_range(); }
443 };
444
445 /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets
446 /// the type_info that corresponds to the supplied type, or the (possibly
447 /// dynamic) type of the supplied expression.
448 ///
449 /// This represents code like @c typeid(int) or @c typeid(*objPtr)
450 class CXXTypeidExpr : public Expr {
451 private:
452 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
453 SourceRange Range;
454
455 public:
CXXTypeidExpr(QualType Ty,TypeSourceInfo * Operand,SourceRange R)456 CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
457 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
458 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
459 false,
460 // typeid is value-dependent if the type or expression are dependent
461 Operand->getType()->isDependentType(),
462 Operand->getType()->isInstantiationDependentType(),
463 Operand->getType()->containsUnexpandedParameterPack()),
464 Operand(Operand), Range(R) { }
465
CXXTypeidExpr(QualType Ty,Expr * Operand,SourceRange R)466 CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R)
467 : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary,
468 // typeid is never type-dependent (C++ [temp.dep.expr]p4)
469 false,
470 // typeid is value-dependent if the type or expression are dependent
471 Operand->isTypeDependent() || Operand->isValueDependent(),
472 Operand->isInstantiationDependent(),
473 Operand->containsUnexpandedParameterPack()),
474 Operand(Operand), Range(R) { }
475
CXXTypeidExpr(EmptyShell Empty,bool isExpr)476 CXXTypeidExpr(EmptyShell Empty, bool isExpr)
477 : Expr(CXXTypeidExprClass, Empty) {
478 if (isExpr)
479 Operand = (Expr*)0;
480 else
481 Operand = (TypeSourceInfo*)0;
482 }
483
isTypeOperand()484 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
485
486 /// \brief Retrieves the type operand of this typeid() expression after
487 /// various required adjustments (removing reference types, cv-qualifiers).
488 QualType getTypeOperand() const;
489
490 /// \brief Retrieve source information for the type operand.
getTypeOperandSourceInfo()491 TypeSourceInfo *getTypeOperandSourceInfo() const {
492 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
493 return Operand.get<TypeSourceInfo *>();
494 }
495
setTypeOperandSourceInfo(TypeSourceInfo * TSI)496 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
497 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
498 Operand = TSI;
499 }
500
getExprOperand()501 Expr *getExprOperand() const {
502 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
503 return static_cast<Expr*>(Operand.get<Stmt *>());
504 }
505
setExprOperand(Expr * E)506 void setExprOperand(Expr *E) {
507 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)");
508 Operand = E;
509 }
510
getSourceRange()511 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
setSourceRange(SourceRange R)512 void setSourceRange(SourceRange R) { Range = R; }
513
classof(const Stmt * T)514 static bool classof(const Stmt *T) {
515 return T->getStmtClass() == CXXTypeidExprClass;
516 }
classof(const CXXTypeidExpr *)517 static bool classof(const CXXTypeidExpr *) { return true; }
518
519 // Iterators
children()520 child_range children() {
521 if (isTypeOperand()) return child_range();
522 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
523 return child_range(begin, begin + 1);
524 }
525 };
526
527 /// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets
528 /// the _GUID that corresponds to the supplied type or expression.
529 ///
530 /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr)
531 class CXXUuidofExpr : public Expr {
532 private:
533 llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand;
534 SourceRange Range;
535
536 public:
CXXUuidofExpr(QualType Ty,TypeSourceInfo * Operand,SourceRange R)537 CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R)
538 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
539 false, Operand->getType()->isDependentType(),
540 Operand->getType()->isInstantiationDependentType(),
541 Operand->getType()->containsUnexpandedParameterPack()),
542 Operand(Operand), Range(R) { }
543
CXXUuidofExpr(QualType Ty,Expr * Operand,SourceRange R)544 CXXUuidofExpr(QualType Ty, Expr *Operand, SourceRange R)
545 : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary,
546 false, Operand->isTypeDependent(),
547 Operand->isInstantiationDependent(),
548 Operand->containsUnexpandedParameterPack()),
549 Operand(Operand), Range(R) { }
550
CXXUuidofExpr(EmptyShell Empty,bool isExpr)551 CXXUuidofExpr(EmptyShell Empty, bool isExpr)
552 : Expr(CXXUuidofExprClass, Empty) {
553 if (isExpr)
554 Operand = (Expr*)0;
555 else
556 Operand = (TypeSourceInfo*)0;
557 }
558
isTypeOperand()559 bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); }
560
561 /// \brief Retrieves the type operand of this __uuidof() expression after
562 /// various required adjustments (removing reference types, cv-qualifiers).
563 QualType getTypeOperand() const;
564
565 /// \brief Retrieve source information for the type operand.
getTypeOperandSourceInfo()566 TypeSourceInfo *getTypeOperandSourceInfo() const {
567 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
568 return Operand.get<TypeSourceInfo *>();
569 }
570
setTypeOperandSourceInfo(TypeSourceInfo * TSI)571 void setTypeOperandSourceInfo(TypeSourceInfo *TSI) {
572 assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)");
573 Operand = TSI;
574 }
575
getExprOperand()576 Expr *getExprOperand() const {
577 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
578 return static_cast<Expr*>(Operand.get<Stmt *>());
579 }
580
setExprOperand(Expr * E)581 void setExprOperand(Expr *E) {
582 assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)");
583 Operand = E;
584 }
585
getSourceRange()586 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
setSourceRange(SourceRange R)587 void setSourceRange(SourceRange R) { Range = R; }
588
classof(const Stmt * T)589 static bool classof(const Stmt *T) {
590 return T->getStmtClass() == CXXUuidofExprClass;
591 }
classof(const CXXUuidofExpr *)592 static bool classof(const CXXUuidofExpr *) { return true; }
593
594 // Iterators
children()595 child_range children() {
596 if (isTypeOperand()) return child_range();
597 Stmt **begin = reinterpret_cast<Stmt**>(&Operand);
598 return child_range(begin, begin + 1);
599 }
600 };
601
602 /// CXXThisExpr - Represents the "this" expression in C++, which is a
603 /// pointer to the object on which the current member function is
604 /// executing (C++ [expr.prim]p3). Example:
605 ///
606 /// @code
607 /// class Foo {
608 /// public:
609 /// void bar();
610 /// void test() { this->bar(); }
611 /// };
612 /// @endcode
613 class CXXThisExpr : public Expr {
614 SourceLocation Loc;
615 bool Implicit : 1;
616
617 public:
CXXThisExpr(SourceLocation L,QualType Type,bool isImplicit)618 CXXThisExpr(SourceLocation L, QualType Type, bool isImplicit)
619 : Expr(CXXThisExprClass, Type, VK_RValue, OK_Ordinary,
620 // 'this' is type-dependent if the class type of the enclosing
621 // member function is dependent (C++ [temp.dep.expr]p2)
622 Type->isDependentType(), Type->isDependentType(),
623 Type->isInstantiationDependentType(),
624 /*ContainsUnexpandedParameterPack=*/false),
625 Loc(L), Implicit(isImplicit) { }
626
CXXThisExpr(EmptyShell Empty)627 CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {}
628
getLocation()629 SourceLocation getLocation() const { return Loc; }
setLocation(SourceLocation L)630 void setLocation(SourceLocation L) { Loc = L; }
631
getSourceRange()632 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc); }
633
isImplicit()634 bool isImplicit() const { return Implicit; }
setImplicit(bool I)635 void setImplicit(bool I) { Implicit = I; }
636
classof(const Stmt * T)637 static bool classof(const Stmt *T) {
638 return T->getStmtClass() == CXXThisExprClass;
639 }
classof(const CXXThisExpr *)640 static bool classof(const CXXThisExpr *) { return true; }
641
642 // Iterators
children()643 child_range children() { return child_range(); }
644 };
645
646 /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles
647 /// 'throw' and 'throw' assignment-expression. When
648 /// assignment-expression isn't present, Op will be null.
649 ///
650 class CXXThrowExpr : public Expr {
651 Stmt *Op;
652 SourceLocation ThrowLoc;
653 /// \brief Whether the thrown variable (if any) is in scope.
654 unsigned IsThrownVariableInScope : 1;
655
656 friend class ASTStmtReader;
657
658 public:
659 // Ty is the void type which is used as the result type of the
660 // exepression. The l is the location of the throw keyword. expr
661 // can by null, if the optional expression to throw isn't present.
CXXThrowExpr(Expr * expr,QualType Ty,SourceLocation l,bool IsThrownVariableInScope)662 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l,
663 bool IsThrownVariableInScope) :
664 Expr(CXXThrowExprClass, Ty, VK_RValue, OK_Ordinary, false, false,
665 expr && expr->isInstantiationDependent(),
666 expr && expr->containsUnexpandedParameterPack()),
667 Op(expr), ThrowLoc(l), IsThrownVariableInScope(IsThrownVariableInScope) {}
CXXThrowExpr(EmptyShell Empty)668 CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {}
669
getSubExpr()670 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); }
getSubExpr()671 Expr *getSubExpr() { return cast_or_null<Expr>(Op); }
672
getThrowLoc()673 SourceLocation getThrowLoc() const { return ThrowLoc; }
674
675 /// \brief Determines whether the variable thrown by this expression (if any!)
676 /// is within the innermost try block.
677 ///
678 /// This information is required to determine whether the NRVO can apply to
679 /// this variable.
isThrownVariableInScope()680 bool isThrownVariableInScope() const { return IsThrownVariableInScope; }
681
getSourceRange()682 SourceRange getSourceRange() const LLVM_READONLY {
683 if (getSubExpr() == 0)
684 return SourceRange(ThrowLoc, ThrowLoc);
685 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd());
686 }
687
classof(const Stmt * T)688 static bool classof(const Stmt *T) {
689 return T->getStmtClass() == CXXThrowExprClass;
690 }
classof(const CXXThrowExpr *)691 static bool classof(const CXXThrowExpr *) { return true; }
692
693 // Iterators
children()694 child_range children() {
695 return child_range(&Op, Op ? &Op+1 : &Op);
696 }
697 };
698
699 /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a
700 /// function call argument that was created from the corresponding
701 /// parameter's default argument, when the call did not explicitly
702 /// supply arguments for all of the parameters.
703 class CXXDefaultArgExpr : public Expr {
704 /// \brief The parameter whose default is being used.
705 ///
706 /// When the bit is set, the subexpression is stored after the
707 /// CXXDefaultArgExpr itself. When the bit is clear, the parameter's
708 /// actual default expression is the subexpression.
709 llvm::PointerIntPair<ParmVarDecl *, 1, bool> Param;
710
711 /// \brief The location where the default argument expression was used.
712 SourceLocation Loc;
713
CXXDefaultArgExpr(StmtClass SC,SourceLocation Loc,ParmVarDecl * param)714 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param)
715 : Expr(SC,
716 param->hasUnparsedDefaultArg()
717 ? param->getType().getNonReferenceType()
718 : param->getDefaultArg()->getType(),
719 param->getDefaultArg()->getValueKind(),
720 param->getDefaultArg()->getObjectKind(), false, false, false, false),
721 Param(param, false), Loc(Loc) { }
722
CXXDefaultArgExpr(StmtClass SC,SourceLocation Loc,ParmVarDecl * param,Expr * SubExpr)723 CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *param,
724 Expr *SubExpr)
725 : Expr(SC, SubExpr->getType(),
726 SubExpr->getValueKind(), SubExpr->getObjectKind(),
727 false, false, false, false),
728 Param(param, true), Loc(Loc) {
729 *reinterpret_cast<Expr **>(this + 1) = SubExpr;
730 }
731
732 public:
CXXDefaultArgExpr(EmptyShell Empty)733 CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
734
735
736 // Param is the parameter whose default argument is used by this
737 // expression.
Create(ASTContext & C,SourceLocation Loc,ParmVarDecl * Param)738 static CXXDefaultArgExpr *Create(ASTContext &C, SourceLocation Loc,
739 ParmVarDecl *Param) {
740 return new (C) CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param);
741 }
742
743 // Param is the parameter whose default argument is used by this
744 // expression, and SubExpr is the expression that will actually be used.
745 static CXXDefaultArgExpr *Create(ASTContext &C,
746 SourceLocation Loc,
747 ParmVarDecl *Param,
748 Expr *SubExpr);
749
750 // Retrieve the parameter that the argument was created from.
getParam()751 const ParmVarDecl *getParam() const { return Param.getPointer(); }
getParam()752 ParmVarDecl *getParam() { return Param.getPointer(); }
753
754 // Retrieve the actual argument to the function call.
getExpr()755 const Expr *getExpr() const {
756 if (Param.getInt())
757 return *reinterpret_cast<Expr const * const*> (this + 1);
758 return getParam()->getDefaultArg();
759 }
getExpr()760 Expr *getExpr() {
761 if (Param.getInt())
762 return *reinterpret_cast<Expr **> (this + 1);
763 return getParam()->getDefaultArg();
764 }
765
766 /// \brief Retrieve the location where this default argument was actually
767 /// used.
getUsedLocation()768 SourceLocation getUsedLocation() const { return Loc; }
769
getSourceRange()770 SourceRange getSourceRange() const LLVM_READONLY {
771 // Default argument expressions have no representation in the
772 // source, so they have an empty source range.
773 return SourceRange();
774 }
775
classof(const Stmt * T)776 static bool classof(const Stmt *T) {
777 return T->getStmtClass() == CXXDefaultArgExprClass;
778 }
classof(const CXXDefaultArgExpr *)779 static bool classof(const CXXDefaultArgExpr *) { return true; }
780
781 // Iterators
children()782 child_range children() { return child_range(); }
783
784 friend class ASTStmtReader;
785 friend class ASTStmtWriter;
786 };
787
788 /// CXXTemporary - Represents a C++ temporary.
789 class CXXTemporary {
790 /// Destructor - The destructor that needs to be called.
791 const CXXDestructorDecl *Destructor;
792
CXXTemporary(const CXXDestructorDecl * destructor)793 CXXTemporary(const CXXDestructorDecl *destructor)
794 : Destructor(destructor) { }
795
796 public:
797 static CXXTemporary *Create(ASTContext &C,
798 const CXXDestructorDecl *Destructor);
799
getDestructor()800 const CXXDestructorDecl *getDestructor() const { return Destructor; }
setDestructor(const CXXDestructorDecl * Dtor)801 void setDestructor(const CXXDestructorDecl *Dtor) {
802 Destructor = Dtor;
803 }
804 };
805
806 /// \brief Represents binding an expression to a temporary.
807 ///
808 /// This ensures the destructor is called for the temporary. It should only be
809 /// needed for non-POD, non-trivially destructable class types. For example:
810 ///
811 /// \code
812 /// struct S {
813 /// S() { } // User defined constructor makes S non-POD.
814 /// ~S() { } // User defined destructor makes it non-trivial.
815 /// };
816 /// void test() {
817 /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
818 /// }
819 /// \endcode
820 class CXXBindTemporaryExpr : public Expr {
821 CXXTemporary *Temp;
822
823 Stmt *SubExpr;
824
CXXBindTemporaryExpr(CXXTemporary * temp,Expr * SubExpr)825 CXXBindTemporaryExpr(CXXTemporary *temp, Expr* SubExpr)
826 : Expr(CXXBindTemporaryExprClass, SubExpr->getType(),
827 VK_RValue, OK_Ordinary, SubExpr->isTypeDependent(),
828 SubExpr->isValueDependent(),
829 SubExpr->isInstantiationDependent(),
830 SubExpr->containsUnexpandedParameterPack()),
831 Temp(temp), SubExpr(SubExpr) { }
832
833 public:
CXXBindTemporaryExpr(EmptyShell Empty)834 CXXBindTemporaryExpr(EmptyShell Empty)
835 : Expr(CXXBindTemporaryExprClass, Empty), Temp(0), SubExpr(0) {}
836
837 static CXXBindTemporaryExpr *Create(ASTContext &C, CXXTemporary *Temp,
838 Expr* SubExpr);
839
getTemporary()840 CXXTemporary *getTemporary() { return Temp; }
getTemporary()841 const CXXTemporary *getTemporary() const { return Temp; }
setTemporary(CXXTemporary * T)842 void setTemporary(CXXTemporary *T) { Temp = T; }
843
getSubExpr()844 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
getSubExpr()845 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
setSubExpr(Expr * E)846 void setSubExpr(Expr *E) { SubExpr = E; }
847
getSourceRange()848 SourceRange getSourceRange() const LLVM_READONLY {
849 return SubExpr->getSourceRange();
850 }
851
852 // Implement isa/cast/dyncast/etc.
classof(const Stmt * T)853 static bool classof(const Stmt *T) {
854 return T->getStmtClass() == CXXBindTemporaryExprClass;
855 }
classof(const CXXBindTemporaryExpr *)856 static bool classof(const CXXBindTemporaryExpr *) { return true; }
857
858 // Iterators
children()859 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
860 };
861
862 /// CXXConstructExpr - Represents a call to a C++ constructor.
863 class CXXConstructExpr : public Expr {
864 public:
865 enum ConstructionKind {
866 CK_Complete,
867 CK_NonVirtualBase,
868 CK_VirtualBase,
869 CK_Delegating
870 };
871
872 private:
873 CXXConstructorDecl *Constructor;
874
875 SourceLocation Loc;
876 SourceRange ParenRange;
877 unsigned NumArgs : 16;
878 bool Elidable : 1;
879 bool HadMultipleCandidates : 1;
880 bool ListInitialization : 1;
881 bool ZeroInitialization : 1;
882 unsigned ConstructKind : 2;
883 Stmt **Args;
884
885 protected:
886 CXXConstructExpr(ASTContext &C, StmtClass SC, QualType T,
887 SourceLocation Loc,
888 CXXConstructorDecl *d, bool elidable,
889 Expr **args, unsigned numargs,
890 bool HadMultipleCandidates,
891 bool ListInitialization,
892 bool ZeroInitialization,
893 ConstructionKind ConstructKind,
894 SourceRange ParenRange);
895
896 /// \brief Construct an empty C++ construction expression.
CXXConstructExpr(StmtClass SC,EmptyShell Empty)897 CXXConstructExpr(StmtClass SC, EmptyShell Empty)
898 : Expr(SC, Empty), Constructor(0), NumArgs(0), Elidable(false),
899 HadMultipleCandidates(false), ListInitialization(false),
900 ZeroInitialization(false), ConstructKind(0), Args(0)
901 { }
902
903 public:
904 /// \brief Construct an empty C++ construction expression.
CXXConstructExpr(EmptyShell Empty)905 explicit CXXConstructExpr(EmptyShell Empty)
906 : Expr(CXXConstructExprClass, Empty), Constructor(0),
907 NumArgs(0), Elidable(false), HadMultipleCandidates(false),
908 ListInitialization(false), ZeroInitialization(false),
909 ConstructKind(0), Args(0)
910 { }
911
912 static CXXConstructExpr *Create(ASTContext &C, QualType T,
913 SourceLocation Loc,
914 CXXConstructorDecl *D, bool Elidable,
915 Expr **Args, unsigned NumArgs,
916 bool HadMultipleCandidates,
917 bool ListInitialization,
918 bool ZeroInitialization,
919 ConstructionKind ConstructKind,
920 SourceRange ParenRange);
921
getConstructor()922 CXXConstructorDecl* getConstructor() const { return Constructor; }
setConstructor(CXXConstructorDecl * C)923 void setConstructor(CXXConstructorDecl *C) { Constructor = C; }
924
getLocation()925 SourceLocation getLocation() const { return Loc; }
setLocation(SourceLocation Loc)926 void setLocation(SourceLocation Loc) { this->Loc = Loc; }
927
928 /// \brief Whether this construction is elidable.
isElidable()929 bool isElidable() const { return Elidable; }
setElidable(bool E)930 void setElidable(bool E) { Elidable = E; }
931
932 /// \brief Whether the referred constructor was resolved from
933 /// an overloaded set having size greater than 1.
hadMultipleCandidates()934 bool hadMultipleCandidates() const { return HadMultipleCandidates; }
setHadMultipleCandidates(bool V)935 void setHadMultipleCandidates(bool V) { HadMultipleCandidates = V; }
936
937 /// \brief Whether this constructor call was written as list-initialization.
isListInitialization()938 bool isListInitialization() const { return ListInitialization; }
setListInitialization(bool V)939 void setListInitialization(bool V) { ListInitialization = V; }
940
941 /// \brief Whether this construction first requires
942 /// zero-initialization before the initializer is called.
requiresZeroInitialization()943 bool requiresZeroInitialization() const { return ZeroInitialization; }
setRequiresZeroInitialization(bool ZeroInit)944 void setRequiresZeroInitialization(bool ZeroInit) {
945 ZeroInitialization = ZeroInit;
946 }
947
948 /// \brief Determines whether this constructor is actually constructing
949 /// a base class (rather than a complete object).
getConstructionKind()950 ConstructionKind getConstructionKind() const {
951 return (ConstructionKind)ConstructKind;
952 }
setConstructionKind(ConstructionKind CK)953 void setConstructionKind(ConstructionKind CK) {
954 ConstructKind = CK;
955 }
956
957 typedef ExprIterator arg_iterator;
958 typedef ConstExprIterator const_arg_iterator;
959
arg_begin()960 arg_iterator arg_begin() { return Args; }
arg_end()961 arg_iterator arg_end() { return Args + NumArgs; }
arg_begin()962 const_arg_iterator arg_begin() const { return Args; }
arg_end()963 const_arg_iterator arg_end() const { return Args + NumArgs; }
964
getArgs()965 Expr **getArgs() const { return reinterpret_cast<Expr **>(Args); }
getNumArgs()966 unsigned getNumArgs() const { return NumArgs; }
967
968 /// getArg - Return the specified argument.
getArg(unsigned Arg)969 Expr *getArg(unsigned Arg) {
970 assert(Arg < NumArgs && "Arg access out of range!");
971 return cast<Expr>(Args[Arg]);
972 }
getArg(unsigned Arg)973 const Expr *getArg(unsigned Arg) const {
974 assert(Arg < NumArgs && "Arg access out of range!");
975 return cast<Expr>(Args[Arg]);
976 }
977
978 /// setArg - Set the specified argument.
setArg(unsigned Arg,Expr * ArgExpr)979 void setArg(unsigned Arg, Expr *ArgExpr) {
980 assert(Arg < NumArgs && "Arg access out of range!");
981 Args[Arg] = ArgExpr;
982 }
983
984 SourceRange getSourceRange() const LLVM_READONLY;
getParenRange()985 SourceRange getParenRange() const { return ParenRange; }
986
classof(const Stmt * T)987 static bool classof(const Stmt *T) {
988 return T->getStmtClass() == CXXConstructExprClass ||
989 T->getStmtClass() == CXXTemporaryObjectExprClass;
990 }
classof(const CXXConstructExpr *)991 static bool classof(const CXXConstructExpr *) { return true; }
992
993 // Iterators
children()994 child_range children() {
995 return child_range(&Args[0], &Args[0]+NumArgs);
996 }
997
998 friend class ASTStmtReader;
999 };
1000
1001 /// CXXFunctionalCastExpr - Represents an explicit C++ type conversion
1002 /// that uses "functional" notion (C++ [expr.type.conv]). Example: @c
1003 /// x = int(0.5);
1004 class CXXFunctionalCastExpr : public ExplicitCastExpr {
1005 SourceLocation TyBeginLoc;
1006 SourceLocation RParenLoc;
1007
CXXFunctionalCastExpr(QualType ty,ExprValueKind VK,TypeSourceInfo * writtenTy,SourceLocation tyBeginLoc,CastKind kind,Expr * castExpr,unsigned pathSize,SourceLocation rParenLoc)1008 CXXFunctionalCastExpr(QualType ty, ExprValueKind VK,
1009 TypeSourceInfo *writtenTy,
1010 SourceLocation tyBeginLoc, CastKind kind,
1011 Expr *castExpr, unsigned pathSize,
1012 SourceLocation rParenLoc)
1013 : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind,
1014 castExpr, pathSize, writtenTy),
1015 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
1016
CXXFunctionalCastExpr(EmptyShell Shell,unsigned PathSize)1017 explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize)
1018 : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize) { }
1019
1020 public:
1021 static CXXFunctionalCastExpr *Create(ASTContext &Context, QualType T,
1022 ExprValueKind VK,
1023 TypeSourceInfo *Written,
1024 SourceLocation TyBeginLoc,
1025 CastKind Kind, Expr *Op,
1026 const CXXCastPath *Path,
1027 SourceLocation RPLoc);
1028 static CXXFunctionalCastExpr *CreateEmpty(ASTContext &Context,
1029 unsigned PathSize);
1030
getTypeBeginLoc()1031 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
setTypeBeginLoc(SourceLocation L)1032 void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
getRParenLoc()1033 SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)1034 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1035
getSourceRange()1036 SourceRange getSourceRange() const LLVM_READONLY {
1037 return SourceRange(TyBeginLoc, RParenLoc);
1038 }
classof(const Stmt * T)1039 static bool classof(const Stmt *T) {
1040 return T->getStmtClass() == CXXFunctionalCastExprClass;
1041 }
classof(const CXXFunctionalCastExpr *)1042 static bool classof(const CXXFunctionalCastExpr *) { return true; }
1043 };
1044
1045 /// @brief Represents a C++ functional cast expression that builds a
1046 /// temporary object.
1047 ///
1048 /// This expression type represents a C++ "functional" cast
1049 /// (C++[expr.type.conv]) with N != 1 arguments that invokes a
1050 /// constructor to build a temporary object. With N == 1 arguments the
1051 /// functional cast expression will be represented by CXXFunctionalCastExpr.
1052 /// Example:
1053 /// @code
1054 /// struct X { X(int, float); }
1055 ///
1056 /// X create_X() {
1057 /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr
1058 /// };
1059 /// @endcode
1060 class CXXTemporaryObjectExpr : public CXXConstructExpr {
1061 TypeSourceInfo *Type;
1062
1063 public:
1064 CXXTemporaryObjectExpr(ASTContext &C, CXXConstructorDecl *Cons,
1065 TypeSourceInfo *Type,
1066 Expr **Args,unsigned NumArgs,
1067 SourceRange parenRange,
1068 bool HadMultipleCandidates,
1069 bool ZeroInitialization = false);
CXXTemporaryObjectExpr(EmptyShell Empty)1070 explicit CXXTemporaryObjectExpr(EmptyShell Empty)
1071 : CXXConstructExpr(CXXTemporaryObjectExprClass, Empty), Type() { }
1072
getTypeSourceInfo()1073 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
1074
1075 SourceRange getSourceRange() const LLVM_READONLY;
1076
classof(const Stmt * T)1077 static bool classof(const Stmt *T) {
1078 return T->getStmtClass() == CXXTemporaryObjectExprClass;
1079 }
classof(const CXXTemporaryObjectExpr *)1080 static bool classof(const CXXTemporaryObjectExpr *) { return true; }
1081
1082 friend class ASTStmtReader;
1083 };
1084
1085 /// \brief A C++ lambda expression, which produces a function object
1086 /// (of unspecified type) that can be invoked later.
1087 ///
1088 /// Example:
1089 /// \code
1090 /// void low_pass_filter(std::vector<double> &values, double cutoff) {
1091 /// values.erase(std::remove_if(values.begin(), values.end(),
1092 // [=](double value) { return value > cutoff; });
1093 /// }
1094 /// \endcode
1095 ///
1096 /// Lambda expressions can capture local variables, either by copying
1097 /// the values of those local variables at the time the function
1098 /// object is constructed (not when it is called!) or by holding a
1099 /// reference to the local variable. These captures can occur either
1100 /// implicitly or can be written explicitly between the square
1101 /// brackets ([...]) that start the lambda expression.
1102 class LambdaExpr : public Expr {
1103 enum {
1104 /// \brief Flag used by the Capture class to indicate that the given
1105 /// capture was implicit.
1106 Capture_Implicit = 0x01,
1107
1108 /// \brief Flag used by the Capture class to indciate that the
1109 /// given capture was by-copy.
1110 Capture_ByCopy = 0x02
1111 };
1112
1113 /// \brief The source range that covers the lambda introducer ([...]).
1114 SourceRange IntroducerRange;
1115
1116 /// \brief The number of captures.
1117 unsigned NumCaptures : 16;
1118
1119 /// \brief The default capture kind, which is a value of type
1120 /// LambdaCaptureDefault.
1121 unsigned CaptureDefault : 2;
1122
1123 /// \brief Whether this lambda had an explicit parameter list vs. an
1124 /// implicit (and empty) parameter list.
1125 unsigned ExplicitParams : 1;
1126
1127 /// \brief Whether this lambda had the result type explicitly specified.
1128 unsigned ExplicitResultType : 1;
1129
1130 /// \brief Whether there are any array index variables stored at the end of
1131 /// this lambda expression.
1132 unsigned HasArrayIndexVars : 1;
1133
1134 /// \brief The location of the closing brace ('}') that completes
1135 /// the lambda.
1136 ///
1137 /// The location of the brace is also available by looking up the
1138 /// function call operator in the lambda class. However, it is
1139 /// stored here to improve the performance of getSourceRange(), and
1140 /// to avoid having to deserialize the function call operator from a
1141 /// module file just to determine the source range.
1142 SourceLocation ClosingBrace;
1143
1144 // Note: The capture initializers are stored directly after the lambda
1145 // expression, along with the index variables used to initialize by-copy
1146 // array captures.
1147
1148 public:
1149 /// \brief Describes the capture of either a variable or 'this'.
1150 class Capture {
1151 llvm::PointerIntPair<VarDecl *, 2> VarAndBits;
1152 SourceLocation Loc;
1153 SourceLocation EllipsisLoc;
1154
1155 friend class ASTStmtReader;
1156 friend class ASTStmtWriter;
1157
1158 public:
1159 /// \brief Create a new capture.
1160 ///
1161 /// \param Loc The source location associated with this capture.
1162 ///
1163 /// \param Kind The kind of capture (this, byref, bycopy).
1164 ///
1165 /// \param Implicit Whether the capture was implicit or explicit.
1166 ///
1167 /// \param Var The local variable being captured, or null if capturing this.
1168 ///
1169 /// \param EllipsisLoc The location of the ellipsis (...) for a
1170 /// capture that is a pack expansion, or an invalid source
1171 /// location to indicate that this is not a pack expansion.
1172 Capture(SourceLocation Loc, bool Implicit,
1173 LambdaCaptureKind Kind, VarDecl *Var = 0,
1174 SourceLocation EllipsisLoc = SourceLocation());
1175
1176 /// \brief Determine the kind of capture.
1177 LambdaCaptureKind getCaptureKind() const;
1178
1179 /// \brief Determine whether this capture handles the C++ 'this'
1180 /// pointer.
capturesThis()1181 bool capturesThis() const { return VarAndBits.getPointer() == 0; }
1182
1183 /// \brief Determine whether this capture handles a variable.
capturesVariable()1184 bool capturesVariable() const { return VarAndBits.getPointer() != 0; }
1185
1186 /// \brief Retrieve the declaration of the local variable being
1187 /// captured.
1188 ///
1189 /// This operation is only valid if this capture does not capture
1190 /// 'this'.
getCapturedVar()1191 VarDecl *getCapturedVar() const {
1192 assert(!capturesThis() && "No variable available for 'this' capture");
1193 return VarAndBits.getPointer();
1194 }
1195
1196 /// \brief Determine whether this was an implicit capture (not
1197 /// written between the square brackets introducing the lambda).
isImplicit()1198 bool isImplicit() const { return VarAndBits.getInt() & Capture_Implicit; }
1199
1200 /// \brief Determine whether this was an explicit capture, written
1201 /// between the square brackets introducing the lambda.
isExplicit()1202 bool isExplicit() const { return !isImplicit(); }
1203
1204 /// \brief Retrieve the source location of the capture.
1205 ///
1206 /// For an explicit capture, this returns the location of the
1207 /// explicit capture in the source. For an implicit capture, this
1208 /// returns the location at which the variable or 'this' was first
1209 /// used.
getLocation()1210 SourceLocation getLocation() const { return Loc; }
1211
1212 /// \brief Determine whether this capture is a pack expansion,
1213 /// which captures a function parameter pack.
isPackExpansion()1214 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
1215
1216 /// \brief Retrieve the location of the ellipsis for a capture
1217 /// that is a pack expansion.
getEllipsisLoc()1218 SourceLocation getEllipsisLoc() const {
1219 assert(isPackExpansion() && "No ellipsis location for a non-expansion");
1220 return EllipsisLoc;
1221 }
1222 };
1223
1224 private:
1225 /// \brief Construct a lambda expression.
1226 LambdaExpr(QualType T, SourceRange IntroducerRange,
1227 LambdaCaptureDefault CaptureDefault,
1228 ArrayRef<Capture> Captures,
1229 bool ExplicitParams,
1230 bool ExplicitResultType,
1231 ArrayRef<Expr *> CaptureInits,
1232 ArrayRef<VarDecl *> ArrayIndexVars,
1233 ArrayRef<unsigned> ArrayIndexStarts,
1234 SourceLocation ClosingBrace);
1235
1236 /// \brief Construct an empty lambda expression.
LambdaExpr(EmptyShell Empty,unsigned NumCaptures,bool HasArrayIndexVars)1237 LambdaExpr(EmptyShell Empty, unsigned NumCaptures, bool HasArrayIndexVars)
1238 : Expr(LambdaExprClass, Empty),
1239 NumCaptures(NumCaptures), CaptureDefault(LCD_None), ExplicitParams(false),
1240 ExplicitResultType(false), HasArrayIndexVars(true) {
1241 getStoredStmts()[NumCaptures] = 0;
1242 }
1243
getStoredStmts()1244 Stmt **getStoredStmts() const {
1245 return reinterpret_cast<Stmt **>(const_cast<LambdaExpr *>(this) + 1);
1246 }
1247
1248 /// \brief Retrieve the mapping from captures to the first array index
1249 /// variable.
getArrayIndexStarts()1250 unsigned *getArrayIndexStarts() const {
1251 return reinterpret_cast<unsigned *>(getStoredStmts() + NumCaptures + 1);
1252 }
1253
1254 /// \brief Retrieve the complete set of array-index variables.
getArrayIndexVars()1255 VarDecl **getArrayIndexVars() const {
1256 return reinterpret_cast<VarDecl **>(
1257 getArrayIndexStarts() + NumCaptures + 1);
1258 }
1259
1260 public:
1261 /// \brief Construct a new lambda expression.
1262 static LambdaExpr *Create(ASTContext &C,
1263 CXXRecordDecl *Class,
1264 SourceRange IntroducerRange,
1265 LambdaCaptureDefault CaptureDefault,
1266 ArrayRef<Capture> Captures,
1267 bool ExplicitParams,
1268 bool ExplicitResultType,
1269 ArrayRef<Expr *> CaptureInits,
1270 ArrayRef<VarDecl *> ArrayIndexVars,
1271 ArrayRef<unsigned> ArrayIndexStarts,
1272 SourceLocation ClosingBrace);
1273
1274 /// \brief Construct a new lambda expression that will be deserialized from
1275 /// an external source.
1276 static LambdaExpr *CreateDeserialized(ASTContext &C, unsigned NumCaptures,
1277 unsigned NumArrayIndexVars);
1278
1279 /// \brief Determine the default capture kind for this lambda.
getCaptureDefault()1280 LambdaCaptureDefault getCaptureDefault() const {
1281 return static_cast<LambdaCaptureDefault>(CaptureDefault);
1282 }
1283
1284 /// \brief An iterator that walks over the captures of the lambda,
1285 /// both implicit and explicit.
1286 typedef const Capture *capture_iterator;
1287
1288 /// \brief Retrieve an iterator pointing to the first lambda capture.
1289 capture_iterator capture_begin() const;
1290
1291 /// \brief Retrieve an iterator pointing past the end of the
1292 /// sequence of lambda captures.
1293 capture_iterator capture_end() const;
1294
1295 /// \brief Determine the number of captures in this lambda.
capture_size()1296 unsigned capture_size() const { return NumCaptures; }
1297
1298 /// \brief Retrieve an iterator pointing to the first explicit
1299 /// lambda capture.
1300 capture_iterator explicit_capture_begin() const;
1301
1302 /// \brief Retrieve an iterator pointing past the end of the sequence of
1303 /// explicit lambda captures.
1304 capture_iterator explicit_capture_end() const;
1305
1306 /// \brief Retrieve an iterator pointing to the first implicit
1307 /// lambda capture.
1308 capture_iterator implicit_capture_begin() const;
1309
1310 /// \brief Retrieve an iterator pointing past the end of the sequence of
1311 /// implicit lambda captures.
1312 capture_iterator implicit_capture_end() const;
1313
1314 /// \brief Iterator that walks over the capture initialization
1315 /// arguments.
1316 typedef Expr **capture_init_iterator;
1317
1318 /// \brief Retrieve the first initialization argument for this
1319 /// lambda expression (which initializes the first capture field).
capture_init_begin()1320 capture_init_iterator capture_init_begin() const {
1321 return reinterpret_cast<Expr **>(getStoredStmts());
1322 }
1323
1324 /// \brief Retrieve the iterator pointing one past the last
1325 /// initialization argument for this lambda expression.
capture_init_end()1326 capture_init_iterator capture_init_end() const {
1327 return capture_init_begin() + NumCaptures;
1328 }
1329
1330 /// \brief Retrieve the set of index variables used in the capture
1331 /// initializer of an array captured by copy.
1332 ///
1333 /// \param Iter The iterator that points at the capture initializer for
1334 /// which we are extracting the corresponding index variables.
1335 ArrayRef<VarDecl *> getCaptureInitIndexVars(capture_init_iterator Iter) const;
1336
1337 /// \brief Retrieve the source range covering the lambda introducer,
1338 /// which contains the explicit capture list surrounded by square
1339 /// brackets ([...]).
getIntroducerRange()1340 SourceRange getIntroducerRange() const { return IntroducerRange; }
1341
1342 /// \brief Retrieve the class that corresponds to the lambda, which
1343 /// stores the captures in its fields and provides the various
1344 /// operations permitted on a lambda (copying, calling).
1345 CXXRecordDecl *getLambdaClass() const;
1346
1347 /// \brief Retrieve the function call operator associated with this
1348 /// lambda expression.
1349 CXXMethodDecl *getCallOperator() const;
1350
1351 /// \brief Retrieve the body of the lambda.
1352 CompoundStmt *getBody() const;
1353
1354 /// \brief Determine whether the lambda is mutable, meaning that any
1355 /// captures values can be modified.
1356 bool isMutable() const;
1357
1358 /// \brief Determine whether this lambda has an explicit parameter
1359 /// list vs. an implicit (empty) parameter list.
hasExplicitParameters()1360 bool hasExplicitParameters() const { return ExplicitParams; }
1361
1362 /// \brief Whether this lambda had its result type explicitly specified.
hasExplicitResultType()1363 bool hasExplicitResultType() const { return ExplicitResultType; }
1364
classof(const Stmt * T)1365 static bool classof(const Stmt *T) {
1366 return T->getStmtClass() == LambdaExprClass;
1367 }
classof(const LambdaExpr *)1368 static bool classof(const LambdaExpr *) { return true; }
1369
getSourceRange()1370 SourceRange getSourceRange() const LLVM_READONLY {
1371 return SourceRange(IntroducerRange.getBegin(), ClosingBrace);
1372 }
1373
children()1374 child_range children() {
1375 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures + 1);
1376 }
1377
1378 friend class ASTStmtReader;
1379 friend class ASTStmtWriter;
1380 };
1381
1382 /// CXXScalarValueInitExpr - [C++ 5.2.3p2]
1383 /// Expression "T()" which creates a value-initialized rvalue of type
1384 /// T, which is a non-class type.
1385 ///
1386 class CXXScalarValueInitExpr : public Expr {
1387 SourceLocation RParenLoc;
1388 TypeSourceInfo *TypeInfo;
1389
1390 friend class ASTStmtReader;
1391
1392 public:
1393 /// \brief Create an explicitly-written scalar-value initialization
1394 /// expression.
CXXScalarValueInitExpr(QualType Type,TypeSourceInfo * TypeInfo,SourceLocation rParenLoc)1395 CXXScalarValueInitExpr(QualType Type,
1396 TypeSourceInfo *TypeInfo,
1397 SourceLocation rParenLoc ) :
1398 Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
1399 false, false, Type->isInstantiationDependentType(), false),
1400 RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
1401
CXXScalarValueInitExpr(EmptyShell Shell)1402 explicit CXXScalarValueInitExpr(EmptyShell Shell)
1403 : Expr(CXXScalarValueInitExprClass, Shell) { }
1404
getTypeSourceInfo()1405 TypeSourceInfo *getTypeSourceInfo() const {
1406 return TypeInfo;
1407 }
1408
getRParenLoc()1409 SourceLocation getRParenLoc() const { return RParenLoc; }
1410
1411 SourceRange getSourceRange() const LLVM_READONLY;
1412
classof(const Stmt * T)1413 static bool classof(const Stmt *T) {
1414 return T->getStmtClass() == CXXScalarValueInitExprClass;
1415 }
classof(const CXXScalarValueInitExpr *)1416 static bool classof(const CXXScalarValueInitExpr *) { return true; }
1417
1418 // Iterators
children()1419 child_range children() { return child_range(); }
1420 };
1421
1422 /// CXXNewExpr - A new expression for memory allocation and constructor calls,
1423 /// e.g: "new CXXNewExpr(foo)".
1424 class CXXNewExpr : public Expr {
1425 // Contains an optional array size expression, an optional initialization
1426 // expression, and any number of optional placement arguments, in that order.
1427 Stmt **SubExprs;
1428 // Points to the allocation function used.
1429 FunctionDecl *OperatorNew;
1430 // Points to the deallocation function used in case of error. May be null.
1431 FunctionDecl *OperatorDelete;
1432
1433 /// \brief The allocated type-source information, as written in the source.
1434 TypeSourceInfo *AllocatedTypeInfo;
1435
1436 /// \brief If the allocated type was expressed as a parenthesized type-id,
1437 /// the source range covering the parenthesized type-id.
1438 SourceRange TypeIdParens;
1439
1440 /// \brief Location of the first token.
1441 SourceLocation StartLoc;
1442
1443 /// \brief Source-range of a paren-delimited initializer.
1444 SourceRange DirectInitRange;
1445
1446 // Was the usage ::new, i.e. is the global new to be used?
1447 bool GlobalNew : 1;
1448 // Do we allocate an array? If so, the first SubExpr is the size expression.
1449 bool Array : 1;
1450 // If this is an array allocation, does the usual deallocation
1451 // function for the allocated type want to know the allocated size?
1452 bool UsualArrayDeleteWantsSize : 1;
1453 // The number of placement new arguments.
1454 unsigned NumPlacementArgs : 13;
1455 // What kind of initializer do we have? Could be none, parens, or braces.
1456 // In storage, we distinguish between "none, and no initializer expr", and
1457 // "none, but an implicit initializer expr".
1458 unsigned StoredInitializationStyle : 2;
1459
1460 friend class ASTStmtReader;
1461 friend class ASTStmtWriter;
1462 public:
1463 enum InitializationStyle {
1464 NoInit, ///< New-expression has no initializer as written.
1465 CallInit, ///< New-expression has a C++98 paren-delimited initializer.
1466 ListInit ///< New-expression has a C++11 list-initializer.
1467 };
1468
1469 CXXNewExpr(ASTContext &C, bool globalNew, FunctionDecl *operatorNew,
1470 FunctionDecl *operatorDelete, bool usualArrayDeleteWantsSize,
1471 Expr **placementArgs, unsigned numPlaceArgs,
1472 SourceRange typeIdParens, Expr *arraySize,
1473 InitializationStyle initializationStyle, Expr *initializer,
1474 QualType ty, TypeSourceInfo *AllocatedTypeInfo,
1475 SourceLocation startLoc, SourceRange directInitRange);
CXXNewExpr(EmptyShell Shell)1476 explicit CXXNewExpr(EmptyShell Shell)
1477 : Expr(CXXNewExprClass, Shell), SubExprs(0) { }
1478
1479 void AllocateArgsArray(ASTContext &C, bool isArray, unsigned numPlaceArgs,
1480 bool hasInitializer);
1481
getAllocatedType()1482 QualType getAllocatedType() const {
1483 assert(getType()->isPointerType());
1484 return getType()->getAs<PointerType>()->getPointeeType();
1485 }
1486
getAllocatedTypeSourceInfo()1487 TypeSourceInfo *getAllocatedTypeSourceInfo() const {
1488 return AllocatedTypeInfo;
1489 }
1490
1491 /// \brief True if the allocation result needs to be null-checked.
1492 /// C++0x [expr.new]p13:
1493 /// If the allocation function returns null, initialization shall
1494 /// not be done, the deallocation function shall not be called,
1495 /// and the value of the new-expression shall be null.
1496 /// An allocation function is not allowed to return null unless it
1497 /// has a non-throwing exception-specification. The '03 rule is
1498 /// identical except that the definition of a non-throwing
1499 /// exception specification is just "is it throw()?".
1500 bool shouldNullCheckAllocation(ASTContext &Ctx) const;
1501
getOperatorNew()1502 FunctionDecl *getOperatorNew() const { return OperatorNew; }
setOperatorNew(FunctionDecl * D)1503 void setOperatorNew(FunctionDecl *D) { OperatorNew = D; }
getOperatorDelete()1504 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
setOperatorDelete(FunctionDecl * D)1505 void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; }
1506
isArray()1507 bool isArray() const { return Array; }
getArraySize()1508 Expr *getArraySize() {
1509 return Array ? cast<Expr>(SubExprs[0]) : 0;
1510 }
getArraySize()1511 const Expr *getArraySize() const {
1512 return Array ? cast<Expr>(SubExprs[0]) : 0;
1513 }
1514
getNumPlacementArgs()1515 unsigned getNumPlacementArgs() const { return NumPlacementArgs; }
getPlacementArgs()1516 Expr **getPlacementArgs() {
1517 return reinterpret_cast<Expr **>(SubExprs + Array + hasInitializer());
1518 }
1519
getPlacementArg(unsigned i)1520 Expr *getPlacementArg(unsigned i) {
1521 assert(i < NumPlacementArgs && "Index out of range");
1522 return getPlacementArgs()[i];
1523 }
getPlacementArg(unsigned i)1524 const Expr *getPlacementArg(unsigned i) const {
1525 assert(i < NumPlacementArgs && "Index out of range");
1526 return const_cast<CXXNewExpr*>(this)->getPlacementArg(i);
1527 }
1528
isParenTypeId()1529 bool isParenTypeId() const { return TypeIdParens.isValid(); }
getTypeIdParens()1530 SourceRange getTypeIdParens() const { return TypeIdParens; }
1531
isGlobalNew()1532 bool isGlobalNew() const { return GlobalNew; }
1533
1534 /// \brief Whether this new-expression has any initializer at all.
hasInitializer()1535 bool hasInitializer() const { return StoredInitializationStyle > 0; }
1536
1537 /// \brief The kind of initializer this new-expression has.
getInitializationStyle()1538 InitializationStyle getInitializationStyle() const {
1539 if (StoredInitializationStyle == 0)
1540 return NoInit;
1541 return static_cast<InitializationStyle>(StoredInitializationStyle-1);
1542 }
1543
1544 /// \brief The initializer of this new-expression.
getInitializer()1545 Expr *getInitializer() {
1546 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
1547 }
getInitializer()1548 const Expr *getInitializer() const {
1549 return hasInitializer() ? cast<Expr>(SubExprs[Array]) : 0;
1550 }
1551
1552 /// \brief Returns the CXXConstructExpr from this new-expression, or NULL.
getConstructExpr()1553 const CXXConstructExpr* getConstructExpr() {
1554 return dyn_cast_or_null<CXXConstructExpr>(getInitializer());
1555 }
1556
1557 /// Answers whether the usual array deallocation function for the
1558 /// allocated type expects the size of the allocation as a
1559 /// parameter.
doesUsualArrayDeleteWantSize()1560 bool doesUsualArrayDeleteWantSize() const {
1561 return UsualArrayDeleteWantsSize;
1562 }
1563
1564 typedef ExprIterator arg_iterator;
1565 typedef ConstExprIterator const_arg_iterator;
1566
placement_arg_begin()1567 arg_iterator placement_arg_begin() {
1568 return SubExprs + Array + hasInitializer();
1569 }
placement_arg_end()1570 arg_iterator placement_arg_end() {
1571 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1572 }
placement_arg_begin()1573 const_arg_iterator placement_arg_begin() const {
1574 return SubExprs + Array + hasInitializer();
1575 }
placement_arg_end()1576 const_arg_iterator placement_arg_end() const {
1577 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1578 }
1579
1580 typedef Stmt **raw_arg_iterator;
raw_arg_begin()1581 raw_arg_iterator raw_arg_begin() { return SubExprs; }
raw_arg_end()1582 raw_arg_iterator raw_arg_end() {
1583 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1584 }
raw_arg_begin()1585 const_arg_iterator raw_arg_begin() const { return SubExprs; }
raw_arg_end()1586 const_arg_iterator raw_arg_end() const {
1587 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
1588 }
1589
getStartLoc()1590 SourceLocation getStartLoc() const { return StartLoc; }
1591 SourceLocation getEndLoc() const;
1592
getDirectInitRange()1593 SourceRange getDirectInitRange() const { return DirectInitRange; }
1594
getSourceRange()1595 SourceRange getSourceRange() const LLVM_READONLY {
1596 return SourceRange(getStartLoc(), getEndLoc());
1597 }
1598
classof(const Stmt * T)1599 static bool classof(const Stmt *T) {
1600 return T->getStmtClass() == CXXNewExprClass;
1601 }
classof(const CXXNewExpr *)1602 static bool classof(const CXXNewExpr *) { return true; }
1603
1604 // Iterators
children()1605 child_range children() {
1606 return child_range(raw_arg_begin(), raw_arg_end());
1607 }
1608 };
1609
1610 /// CXXDeleteExpr - A delete expression for memory deallocation and destructor
1611 /// calls, e.g. "delete[] pArray".
1612 class CXXDeleteExpr : public Expr {
1613 // Points to the operator delete overload that is used. Could be a member.
1614 FunctionDecl *OperatorDelete;
1615 // The pointer expression to be deleted.
1616 Stmt *Argument;
1617 // Location of the expression.
1618 SourceLocation Loc;
1619 // Is this a forced global delete, i.e. "::delete"?
1620 bool GlobalDelete : 1;
1621 // Is this the array form of delete, i.e. "delete[]"?
1622 bool ArrayForm : 1;
1623 // ArrayFormAsWritten can be different from ArrayForm if 'delete' is applied
1624 // to pointer-to-array type (ArrayFormAsWritten will be false while ArrayForm
1625 // will be true).
1626 bool ArrayFormAsWritten : 1;
1627 // Does the usual deallocation function for the element type require
1628 // a size_t argument?
1629 bool UsualArrayDeleteWantsSize : 1;
1630 public:
CXXDeleteExpr(QualType ty,bool globalDelete,bool arrayForm,bool arrayFormAsWritten,bool usualArrayDeleteWantsSize,FunctionDecl * operatorDelete,Expr * arg,SourceLocation loc)1631 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm,
1632 bool arrayFormAsWritten, bool usualArrayDeleteWantsSize,
1633 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc)
1634 : Expr(CXXDeleteExprClass, ty, VK_RValue, OK_Ordinary, false, false,
1635 arg->isInstantiationDependent(),
1636 arg->containsUnexpandedParameterPack()),
1637 OperatorDelete(operatorDelete), Argument(arg), Loc(loc),
1638 GlobalDelete(globalDelete),
1639 ArrayForm(arrayForm), ArrayFormAsWritten(arrayFormAsWritten),
1640 UsualArrayDeleteWantsSize(usualArrayDeleteWantsSize) { }
CXXDeleteExpr(EmptyShell Shell)1641 explicit CXXDeleteExpr(EmptyShell Shell)
1642 : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { }
1643
isGlobalDelete()1644 bool isGlobalDelete() const { return GlobalDelete; }
isArrayForm()1645 bool isArrayForm() const { return ArrayForm; }
isArrayFormAsWritten()1646 bool isArrayFormAsWritten() const { return ArrayFormAsWritten; }
1647
1648 /// Answers whether the usual array deallocation function for the
1649 /// allocated type expects the size of the allocation as a
1650 /// parameter. This can be true even if the actual deallocation
1651 /// function that we're using doesn't want a size.
doesUsualArrayDeleteWantSize()1652 bool doesUsualArrayDeleteWantSize() const {
1653 return UsualArrayDeleteWantsSize;
1654 }
1655
getOperatorDelete()1656 FunctionDecl *getOperatorDelete() const { return OperatorDelete; }
1657
getArgument()1658 Expr *getArgument() { return cast<Expr>(Argument); }
getArgument()1659 const Expr *getArgument() const { return cast<Expr>(Argument); }
1660
1661 /// \brief Retrieve the type being destroyed. If the type being
1662 /// destroyed is a dependent type which may or may not be a pointer,
1663 /// return an invalid type.
1664 QualType getDestroyedType() const;
1665
getSourceRange()1666 SourceRange getSourceRange() const LLVM_READONLY {
1667 return SourceRange(Loc, Argument->getLocEnd());
1668 }
1669
classof(const Stmt * T)1670 static bool classof(const Stmt *T) {
1671 return T->getStmtClass() == CXXDeleteExprClass;
1672 }
classof(const CXXDeleteExpr *)1673 static bool classof(const CXXDeleteExpr *) { return true; }
1674
1675 // Iterators
children()1676 child_range children() { return child_range(&Argument, &Argument+1); }
1677
1678 friend class ASTStmtReader;
1679 };
1680
1681 /// \brief Structure used to store the type being destroyed by a
1682 /// pseudo-destructor expression.
1683 class PseudoDestructorTypeStorage {
1684 /// \brief Either the type source information or the name of the type, if
1685 /// it couldn't be resolved due to type-dependence.
1686 llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type;
1687
1688 /// \brief The starting source location of the pseudo-destructor type.
1689 SourceLocation Location;
1690
1691 public:
PseudoDestructorTypeStorage()1692 PseudoDestructorTypeStorage() { }
1693
PseudoDestructorTypeStorage(IdentifierInfo * II,SourceLocation Loc)1694 PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc)
1695 : Type(II), Location(Loc) { }
1696
1697 PseudoDestructorTypeStorage(TypeSourceInfo *Info);
1698
getTypeSourceInfo()1699 TypeSourceInfo *getTypeSourceInfo() const {
1700 return Type.dyn_cast<TypeSourceInfo *>();
1701 }
1702
getIdentifier()1703 IdentifierInfo *getIdentifier() const {
1704 return Type.dyn_cast<IdentifierInfo *>();
1705 }
1706
getLocation()1707 SourceLocation getLocation() const { return Location; }
1708 };
1709
1710 /// \brief Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
1711 ///
1712 /// A pseudo-destructor is an expression that looks like a member access to a
1713 /// destructor of a scalar type, except that scalar types don't have
1714 /// destructors. For example:
1715 ///
1716 /// \code
1717 /// typedef int T;
1718 /// void f(int *p) {
1719 /// p->T::~T();
1720 /// }
1721 /// \endcode
1722 ///
1723 /// Pseudo-destructors typically occur when instantiating templates such as:
1724 ///
1725 /// \code
1726 /// template<typename T>
1727 /// void destroy(T* ptr) {
1728 /// ptr->T::~T();
1729 /// }
1730 /// \endcode
1731 ///
1732 /// for scalar types. A pseudo-destructor expression has no run-time semantics
1733 /// beyond evaluating the base expression.
1734 class CXXPseudoDestructorExpr : public Expr {
1735 /// \brief The base expression (that is being destroyed).
1736 Stmt *Base;
1737
1738 /// \brief Whether the operator was an arrow ('->'); otherwise, it was a
1739 /// period ('.').
1740 bool IsArrow : 1;
1741
1742 /// \brief The location of the '.' or '->' operator.
1743 SourceLocation OperatorLoc;
1744
1745 /// \brief The nested-name-specifier that follows the operator, if present.
1746 NestedNameSpecifierLoc QualifierLoc;
1747
1748 /// \brief The type that precedes the '::' in a qualified pseudo-destructor
1749 /// expression.
1750 TypeSourceInfo *ScopeType;
1751
1752 /// \brief The location of the '::' in a qualified pseudo-destructor
1753 /// expression.
1754 SourceLocation ColonColonLoc;
1755
1756 /// \brief The location of the '~'.
1757 SourceLocation TildeLoc;
1758
1759 /// \brief The type being destroyed, or its name if we were unable to
1760 /// resolve the name.
1761 PseudoDestructorTypeStorage DestroyedType;
1762
1763 friend class ASTStmtReader;
1764
1765 public:
1766 CXXPseudoDestructorExpr(ASTContext &Context,
1767 Expr *Base, bool isArrow, SourceLocation OperatorLoc,
1768 NestedNameSpecifierLoc QualifierLoc,
1769 TypeSourceInfo *ScopeType,
1770 SourceLocation ColonColonLoc,
1771 SourceLocation TildeLoc,
1772 PseudoDestructorTypeStorage DestroyedType);
1773
CXXPseudoDestructorExpr(EmptyShell Shell)1774 explicit CXXPseudoDestructorExpr(EmptyShell Shell)
1775 : Expr(CXXPseudoDestructorExprClass, Shell),
1776 Base(0), IsArrow(false), QualifierLoc(), ScopeType(0) { }
1777
getBase()1778 Expr *getBase() const { return cast<Expr>(Base); }
1779
1780 /// \brief Determines whether this member expression actually had
1781 /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1782 /// x->Base::foo.
hasQualifier()1783 bool hasQualifier() const { return QualifierLoc; }
1784
1785 /// \brief Retrieves the nested-name-specifier that qualifies the type name,
1786 /// with source-location information.
getQualifierLoc()1787 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1788
1789 /// \brief If the member name was qualified, retrieves the
1790 /// nested-name-specifier that precedes the member name. Otherwise, returns
1791 /// NULL.
getQualifier()1792 NestedNameSpecifier *getQualifier() const {
1793 return QualifierLoc.getNestedNameSpecifier();
1794 }
1795
1796 /// \brief Determine whether this pseudo-destructor expression was written
1797 /// using an '->' (otherwise, it used a '.').
isArrow()1798 bool isArrow() const { return IsArrow; }
1799
1800 /// \brief Retrieve the location of the '.' or '->' operator.
getOperatorLoc()1801 SourceLocation getOperatorLoc() const { return OperatorLoc; }
1802
1803 /// \brief Retrieve the scope type in a qualified pseudo-destructor
1804 /// expression.
1805 ///
1806 /// Pseudo-destructor expressions can have extra qualification within them
1807 /// that is not part of the nested-name-specifier, e.g., \c p->T::~T().
1808 /// Here, if the object type of the expression is (or may be) a scalar type,
1809 /// \p T may also be a scalar type and, therefore, cannot be part of a
1810 /// nested-name-specifier. It is stored as the "scope type" of the pseudo-
1811 /// destructor expression.
getScopeTypeInfo()1812 TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; }
1813
1814 /// \brief Retrieve the location of the '::' in a qualified pseudo-destructor
1815 /// expression.
getColonColonLoc()1816 SourceLocation getColonColonLoc() const { return ColonColonLoc; }
1817
1818 /// \brief Retrieve the location of the '~'.
getTildeLoc()1819 SourceLocation getTildeLoc() const { return TildeLoc; }
1820
1821 /// \brief Retrieve the source location information for the type
1822 /// being destroyed.
1823 ///
1824 /// This type-source information is available for non-dependent
1825 /// pseudo-destructor expressions and some dependent pseudo-destructor
1826 /// expressions. Returns NULL if we only have the identifier for a
1827 /// dependent pseudo-destructor expression.
getDestroyedTypeInfo()1828 TypeSourceInfo *getDestroyedTypeInfo() const {
1829 return DestroyedType.getTypeSourceInfo();
1830 }
1831
1832 /// \brief In a dependent pseudo-destructor expression for which we do not
1833 /// have full type information on the destroyed type, provides the name
1834 /// of the destroyed type.
getDestroyedTypeIdentifier()1835 IdentifierInfo *getDestroyedTypeIdentifier() const {
1836 return DestroyedType.getIdentifier();
1837 }
1838
1839 /// \brief Retrieve the type being destroyed.
1840 QualType getDestroyedType() const;
1841
1842 /// \brief Retrieve the starting location of the type being destroyed.
getDestroyedTypeLoc()1843 SourceLocation getDestroyedTypeLoc() const {
1844 return DestroyedType.getLocation();
1845 }
1846
1847 /// \brief Set the name of destroyed type for a dependent pseudo-destructor
1848 /// expression.
setDestroyedType(IdentifierInfo * II,SourceLocation Loc)1849 void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) {
1850 DestroyedType = PseudoDestructorTypeStorage(II, Loc);
1851 }
1852
1853 /// \brief Set the destroyed type.
setDestroyedType(TypeSourceInfo * Info)1854 void setDestroyedType(TypeSourceInfo *Info) {
1855 DestroyedType = PseudoDestructorTypeStorage(Info);
1856 }
1857
1858 SourceRange getSourceRange() const LLVM_READONLY;
1859
classof(const Stmt * T)1860 static bool classof(const Stmt *T) {
1861 return T->getStmtClass() == CXXPseudoDestructorExprClass;
1862 }
classof(const CXXPseudoDestructorExpr *)1863 static bool classof(const CXXPseudoDestructorExpr *) { return true; }
1864
1865 // Iterators
children()1866 child_range children() { return child_range(&Base, &Base + 1); }
1867 };
1868
1869 /// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the
1870 /// implementation of TR1/C++0x type trait templates.
1871 /// Example:
1872 /// __is_pod(int) == true
1873 /// __is_enum(std::string) == false
1874 class UnaryTypeTraitExpr : public Expr {
1875 /// UTT - The trait. A UnaryTypeTrait enum in MSVC compat unsigned.
1876 unsigned UTT : 31;
1877 /// The value of the type trait. Unspecified if dependent.
1878 bool Value : 1;
1879
1880 /// Loc - The location of the type trait keyword.
1881 SourceLocation Loc;
1882
1883 /// RParen - The location of the closing paren.
1884 SourceLocation RParen;
1885
1886 /// The type being queried.
1887 TypeSourceInfo *QueriedType;
1888
1889 public:
UnaryTypeTraitExpr(SourceLocation loc,UnaryTypeTrait utt,TypeSourceInfo * queried,bool value,SourceLocation rparen,QualType ty)1890 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt,
1891 TypeSourceInfo *queried, bool value,
1892 SourceLocation rparen, QualType ty)
1893 : Expr(UnaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
1894 false, queried->getType()->isDependentType(),
1895 queried->getType()->isInstantiationDependentType(),
1896 queried->getType()->containsUnexpandedParameterPack()),
1897 UTT(utt), Value(value), Loc(loc), RParen(rparen), QueriedType(queried) { }
1898
UnaryTypeTraitExpr(EmptyShell Empty)1899 explicit UnaryTypeTraitExpr(EmptyShell Empty)
1900 : Expr(UnaryTypeTraitExprClass, Empty), UTT(0), Value(false),
1901 QueriedType() { }
1902
getSourceRange()1903 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParen);}
1904
getTrait()1905 UnaryTypeTrait getTrait() const { return static_cast<UnaryTypeTrait>(UTT); }
1906
getQueriedType()1907 QualType getQueriedType() const { return QueriedType->getType(); }
1908
getQueriedTypeSourceInfo()1909 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
1910
getValue()1911 bool getValue() const { return Value; }
1912
classof(const Stmt * T)1913 static bool classof(const Stmt *T) {
1914 return T->getStmtClass() == UnaryTypeTraitExprClass;
1915 }
classof(const UnaryTypeTraitExpr *)1916 static bool classof(const UnaryTypeTraitExpr *) { return true; }
1917
1918 // Iterators
children()1919 child_range children() { return child_range(); }
1920
1921 friend class ASTStmtReader;
1922 };
1923
1924 /// BinaryTypeTraitExpr - A GCC or MS binary type trait, as used in the
1925 /// implementation of TR1/C++0x type trait templates.
1926 /// Example:
1927 /// __is_base_of(Base, Derived) == true
1928 class BinaryTypeTraitExpr : public Expr {
1929 /// BTT - The trait. A BinaryTypeTrait enum in MSVC compat unsigned.
1930 unsigned BTT : 8;
1931
1932 /// The value of the type trait. Unspecified if dependent.
1933 bool Value : 1;
1934
1935 /// Loc - The location of the type trait keyword.
1936 SourceLocation Loc;
1937
1938 /// RParen - The location of the closing paren.
1939 SourceLocation RParen;
1940
1941 /// The lhs type being queried.
1942 TypeSourceInfo *LhsType;
1943
1944 /// The rhs type being queried.
1945 TypeSourceInfo *RhsType;
1946
1947 public:
BinaryTypeTraitExpr(SourceLocation loc,BinaryTypeTrait btt,TypeSourceInfo * lhsType,TypeSourceInfo * rhsType,bool value,SourceLocation rparen,QualType ty)1948 BinaryTypeTraitExpr(SourceLocation loc, BinaryTypeTrait btt,
1949 TypeSourceInfo *lhsType, TypeSourceInfo *rhsType,
1950 bool value, SourceLocation rparen, QualType ty)
1951 : Expr(BinaryTypeTraitExprClass, ty, VK_RValue, OK_Ordinary, false,
1952 lhsType->getType()->isDependentType() ||
1953 rhsType->getType()->isDependentType(),
1954 (lhsType->getType()->isInstantiationDependentType() ||
1955 rhsType->getType()->isInstantiationDependentType()),
1956 (lhsType->getType()->containsUnexpandedParameterPack() ||
1957 rhsType->getType()->containsUnexpandedParameterPack())),
1958 BTT(btt), Value(value), Loc(loc), RParen(rparen),
1959 LhsType(lhsType), RhsType(rhsType) { }
1960
1961
BinaryTypeTraitExpr(EmptyShell Empty)1962 explicit BinaryTypeTraitExpr(EmptyShell Empty)
1963 : Expr(BinaryTypeTraitExprClass, Empty), BTT(0), Value(false),
1964 LhsType(), RhsType() { }
1965
getSourceRange()1966 SourceRange getSourceRange() const LLVM_READONLY {
1967 return SourceRange(Loc, RParen);
1968 }
1969
getTrait()1970 BinaryTypeTrait getTrait() const {
1971 return static_cast<BinaryTypeTrait>(BTT);
1972 }
1973
getLhsType()1974 QualType getLhsType() const { return LhsType->getType(); }
getRhsType()1975 QualType getRhsType() const { return RhsType->getType(); }
1976
getLhsTypeSourceInfo()1977 TypeSourceInfo *getLhsTypeSourceInfo() const { return LhsType; }
getRhsTypeSourceInfo()1978 TypeSourceInfo *getRhsTypeSourceInfo() const { return RhsType; }
1979
getValue()1980 bool getValue() const { assert(!isTypeDependent()); return Value; }
1981
classof(const Stmt * T)1982 static bool classof(const Stmt *T) {
1983 return T->getStmtClass() == BinaryTypeTraitExprClass;
1984 }
classof(const BinaryTypeTraitExpr *)1985 static bool classof(const BinaryTypeTraitExpr *) { return true; }
1986
1987 // Iterators
children()1988 child_range children() { return child_range(); }
1989
1990 friend class ASTStmtReader;
1991 };
1992
1993 /// \brief A type trait used in the implementation of various C++11 and
1994 /// Library TR1 trait templates.
1995 ///
1996 /// \code
1997 /// __is_trivially_constructible(vector<int>, int*, int*)
1998 /// \endcode
1999 class TypeTraitExpr : public Expr {
2000 /// \brief The location of the type trait keyword.
2001 SourceLocation Loc;
2002
2003 /// \brief The location of the closing parenthesis.
2004 SourceLocation RParenLoc;
2005
2006 // Note: The TypeSourceInfos for the arguments are allocated after the
2007 // TypeTraitExpr.
2008
2009 TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
2010 ArrayRef<TypeSourceInfo *> Args,
2011 SourceLocation RParenLoc,
2012 bool Value);
2013
TypeTraitExpr(EmptyShell Empty)2014 TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) { }
2015
2016 /// \brief Retrieve the argument types.
getTypeSourceInfos()2017 TypeSourceInfo **getTypeSourceInfos() {
2018 return reinterpret_cast<TypeSourceInfo **>(this+1);
2019 }
2020
2021 /// \brief Retrieve the argument types.
getTypeSourceInfos()2022 TypeSourceInfo * const *getTypeSourceInfos() const {
2023 return reinterpret_cast<TypeSourceInfo * const*>(this+1);
2024 }
2025
2026 public:
2027 /// \brief Create a new type trait expression.
2028 static TypeTraitExpr *Create(ASTContext &C, QualType T, SourceLocation Loc,
2029 TypeTrait Kind,
2030 ArrayRef<TypeSourceInfo *> Args,
2031 SourceLocation RParenLoc,
2032 bool Value);
2033
2034 static TypeTraitExpr *CreateDeserialized(ASTContext &C, unsigned NumArgs);
2035
2036 /// \brief Determine which type trait this expression uses.
getTrait()2037 TypeTrait getTrait() const {
2038 return static_cast<TypeTrait>(TypeTraitExprBits.Kind);
2039 }
2040
getValue()2041 bool getValue() const {
2042 assert(!isValueDependent());
2043 return TypeTraitExprBits.Value;
2044 }
2045
2046 /// \brief Determine the number of arguments to this type trait.
getNumArgs()2047 unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; }
2048
2049 /// \brief Retrieve the Ith argument.
getArg(unsigned I)2050 TypeSourceInfo *getArg(unsigned I) const {
2051 assert(I < getNumArgs() && "Argument out-of-range");
2052 return getArgs()[I];
2053 }
2054
2055 /// \brief Retrieve the argument types.
getArgs()2056 ArrayRef<TypeSourceInfo *> getArgs() const {
2057 return ArrayRef<TypeSourceInfo *>(getTypeSourceInfos(), getNumArgs());
2058 }
2059
2060 typedef TypeSourceInfo **arg_iterator;
arg_begin()2061 arg_iterator arg_begin() {
2062 return getTypeSourceInfos();
2063 }
arg_end()2064 arg_iterator arg_end() {
2065 return getTypeSourceInfos() + getNumArgs();
2066 }
2067
2068 typedef TypeSourceInfo const * const *arg_const_iterator;
arg_begin()2069 arg_const_iterator arg_begin() const { return getTypeSourceInfos(); }
arg_end()2070 arg_const_iterator arg_end() const {
2071 return getTypeSourceInfos() + getNumArgs();
2072 }
2073
getSourceRange()2074 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParenLoc); }
2075
classof(const Stmt * T)2076 static bool classof(const Stmt *T) {
2077 return T->getStmtClass() == TypeTraitExprClass;
2078 }
classof(const TypeTraitExpr *)2079 static bool classof(const TypeTraitExpr *) { return true; }
2080
2081 // Iterators
children()2082 child_range children() { return child_range(); }
2083
2084 friend class ASTStmtReader;
2085 friend class ASTStmtWriter;
2086
2087 };
2088
2089 /// ArrayTypeTraitExpr - An Embarcadero array type trait, as used in the
2090 /// implementation of __array_rank and __array_extent.
2091 /// Example:
2092 /// __array_rank(int[10][20]) == 2
2093 /// __array_extent(int, 1) == 20
2094 class ArrayTypeTraitExpr : public Expr {
2095 virtual void anchor();
2096
2097 /// ATT - The trait. An ArrayTypeTrait enum in MSVC compat unsigned.
2098 unsigned ATT : 2;
2099
2100 /// The value of the type trait. Unspecified if dependent.
2101 uint64_t Value;
2102
2103 /// The array dimension being queried, or -1 if not used
2104 Expr *Dimension;
2105
2106 /// Loc - The location of the type trait keyword.
2107 SourceLocation Loc;
2108
2109 /// RParen - The location of the closing paren.
2110 SourceLocation RParen;
2111
2112 /// The type being queried.
2113 TypeSourceInfo *QueriedType;
2114
2115 public:
ArrayTypeTraitExpr(SourceLocation loc,ArrayTypeTrait att,TypeSourceInfo * queried,uint64_t value,Expr * dimension,SourceLocation rparen,QualType ty)2116 ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att,
2117 TypeSourceInfo *queried, uint64_t value,
2118 Expr *dimension, SourceLocation rparen, QualType ty)
2119 : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary,
2120 false, queried->getType()->isDependentType(),
2121 (queried->getType()->isInstantiationDependentType() ||
2122 (dimension && dimension->isInstantiationDependent())),
2123 queried->getType()->containsUnexpandedParameterPack()),
2124 ATT(att), Value(value), Dimension(dimension),
2125 Loc(loc), RParen(rparen), QueriedType(queried) { }
2126
2127
ArrayTypeTraitExpr(EmptyShell Empty)2128 explicit ArrayTypeTraitExpr(EmptyShell Empty)
2129 : Expr(ArrayTypeTraitExprClass, Empty), ATT(0), Value(false),
2130 QueriedType() { }
2131
~ArrayTypeTraitExpr()2132 virtual ~ArrayTypeTraitExpr() { }
2133
getSourceRange()2134 virtual SourceRange getSourceRange() const LLVM_READONLY {
2135 return SourceRange(Loc, RParen);
2136 }
2137
getTrait()2138 ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); }
2139
getQueriedType()2140 QualType getQueriedType() const { return QueriedType->getType(); }
2141
getQueriedTypeSourceInfo()2142 TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; }
2143
getValue()2144 uint64_t getValue() const { assert(!isTypeDependent()); return Value; }
2145
getDimensionExpression()2146 Expr *getDimensionExpression() const { return Dimension; }
2147
classof(const Stmt * T)2148 static bool classof(const Stmt *T) {
2149 return T->getStmtClass() == ArrayTypeTraitExprClass;
2150 }
classof(const ArrayTypeTraitExpr *)2151 static bool classof(const ArrayTypeTraitExpr *) { return true; }
2152
2153 // Iterators
children()2154 child_range children() { return child_range(); }
2155
2156 friend class ASTStmtReader;
2157 };
2158
2159 /// ExpressionTraitExpr - An expression trait intrinsic
2160 /// Example:
2161 /// __is_lvalue_expr(std::cout) == true
2162 /// __is_lvalue_expr(1) == false
2163 class ExpressionTraitExpr : public Expr {
2164 /// ET - The trait. A ExpressionTrait enum in MSVC compat unsigned.
2165 unsigned ET : 31;
2166 /// The value of the type trait. Unspecified if dependent.
2167 bool Value : 1;
2168
2169 /// Loc - The location of the type trait keyword.
2170 SourceLocation Loc;
2171
2172 /// RParen - The location of the closing paren.
2173 SourceLocation RParen;
2174
2175 Expr* QueriedExpression;
2176 public:
ExpressionTraitExpr(SourceLocation loc,ExpressionTrait et,Expr * queried,bool value,SourceLocation rparen,QualType resultType)2177 ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et,
2178 Expr *queried, bool value,
2179 SourceLocation rparen, QualType resultType)
2180 : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2181 false, // Not type-dependent
2182 // Value-dependent if the argument is type-dependent.
2183 queried->isTypeDependent(),
2184 queried->isInstantiationDependent(),
2185 queried->containsUnexpandedParameterPack()),
2186 ET(et), Value(value), Loc(loc), RParen(rparen),
2187 QueriedExpression(queried) { }
2188
ExpressionTraitExpr(EmptyShell Empty)2189 explicit ExpressionTraitExpr(EmptyShell Empty)
2190 : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false),
2191 QueriedExpression() { }
2192
getSourceRange()2193 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(Loc, RParen);}
2194
getTrait()2195 ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); }
2196
getQueriedExpression()2197 Expr *getQueriedExpression() const { return QueriedExpression; }
2198
getValue()2199 bool getValue() const { return Value; }
2200
classof(const Stmt * T)2201 static bool classof(const Stmt *T) {
2202 return T->getStmtClass() == ExpressionTraitExprClass;
2203 }
classof(const ExpressionTraitExpr *)2204 static bool classof(const ExpressionTraitExpr *) { return true; }
2205
2206 // Iterators
children()2207 child_range children() { return child_range(); }
2208
2209 friend class ASTStmtReader;
2210 };
2211
2212
2213 /// \brief A reference to an overloaded function set, either an
2214 /// \t UnresolvedLookupExpr or an \t UnresolvedMemberExpr.
2215 class OverloadExpr : public Expr {
2216 /// The common name of these declarations.
2217 DeclarationNameInfo NameInfo;
2218
2219 /// \brief The nested-name-specifier that qualifies the name, if any.
2220 NestedNameSpecifierLoc QualifierLoc;
2221
2222 /// The results. These are undesugared, which is to say, they may
2223 /// include UsingShadowDecls. Access is relative to the naming
2224 /// class.
2225 // FIXME: Allocate this data after the OverloadExpr subclass.
2226 DeclAccessPair *Results;
2227 unsigned NumResults;
2228
2229 protected:
2230 /// \brief Whether the name includes info for explicit template
2231 /// keyword and arguments.
2232 bool HasTemplateKWAndArgsInfo;
2233
2234 /// \brief Return the optional template keyword and arguments info.
2235 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo(); // defined far below.
2236
2237 /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2238 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2239 return const_cast<OverloadExpr*>(this)->getTemplateKWAndArgsInfo();
2240 }
2241
2242 OverloadExpr(StmtClass K, ASTContext &C,
2243 NestedNameSpecifierLoc QualifierLoc,
2244 SourceLocation TemplateKWLoc,
2245 const DeclarationNameInfo &NameInfo,
2246 const TemplateArgumentListInfo *TemplateArgs,
2247 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2248 bool KnownDependent,
2249 bool KnownInstantiationDependent,
2250 bool KnownContainsUnexpandedParameterPack);
2251
OverloadExpr(StmtClass K,EmptyShell Empty)2252 OverloadExpr(StmtClass K, EmptyShell Empty)
2253 : Expr(K, Empty), QualifierLoc(), Results(0), NumResults(0),
2254 HasTemplateKWAndArgsInfo(false) { }
2255
2256 void initializeResults(ASTContext &C,
2257 UnresolvedSetIterator Begin,
2258 UnresolvedSetIterator End);
2259
2260 public:
2261 struct FindResult {
2262 OverloadExpr *Expression;
2263 bool IsAddressOfOperand;
2264 bool HasFormOfMemberPointer;
2265 };
2266
2267 /// Finds the overloaded expression in the given expression of
2268 /// OverloadTy.
2269 ///
2270 /// \return the expression (which must be there) and true if it has
2271 /// the particular form of a member pointer expression
find(Expr * E)2272 static FindResult find(Expr *E) {
2273 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
2274
2275 FindResult Result;
2276
2277 E = E->IgnoreParens();
2278 if (isa<UnaryOperator>(E)) {
2279 assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf);
2280 E = cast<UnaryOperator>(E)->getSubExpr();
2281 OverloadExpr *Ovl = cast<OverloadExpr>(E->IgnoreParens());
2282
2283 Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
2284 Result.IsAddressOfOperand = true;
2285 Result.Expression = Ovl;
2286 } else {
2287 Result.HasFormOfMemberPointer = false;
2288 Result.IsAddressOfOperand = false;
2289 Result.Expression = cast<OverloadExpr>(E);
2290 }
2291
2292 return Result;
2293 }
2294
2295 /// Gets the naming class of this lookup, if any.
2296 CXXRecordDecl *getNamingClass() const;
2297
2298 typedef UnresolvedSetImpl::iterator decls_iterator;
decls_begin()2299 decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
decls_end()2300 decls_iterator decls_end() const {
2301 return UnresolvedSetIterator(Results + NumResults);
2302 }
2303
2304 /// Gets the number of declarations in the unresolved set.
getNumDecls()2305 unsigned getNumDecls() const { return NumResults; }
2306
2307 /// Gets the full name info.
getNameInfo()2308 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2309
2310 /// Gets the name looked up.
getName()2311 DeclarationName getName() const { return NameInfo.getName(); }
2312
2313 /// Gets the location of the name.
getNameLoc()2314 SourceLocation getNameLoc() const { return NameInfo.getLoc(); }
2315
2316 /// Fetches the nested-name qualifier, if one was given.
getQualifier()2317 NestedNameSpecifier *getQualifier() const {
2318 return QualifierLoc.getNestedNameSpecifier();
2319 }
2320
2321 /// Fetches the nested-name qualifier with source-location information, if
2322 /// one was given.
getQualifierLoc()2323 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2324
2325 /// \brief Retrieve the location of the template keyword preceding
2326 /// this name, if any.
getTemplateKeywordLoc()2327 SourceLocation getTemplateKeywordLoc() const {
2328 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2329 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2330 }
2331
2332 /// \brief Retrieve the location of the left angle bracket starting the
2333 /// explicit template argument list following the name, if any.
getLAngleLoc()2334 SourceLocation getLAngleLoc() const {
2335 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2336 return getTemplateKWAndArgsInfo()->LAngleLoc;
2337 }
2338
2339 /// \brief Retrieve the location of the right angle bracket ending the
2340 /// explicit template argument list following the name, if any.
getRAngleLoc()2341 SourceLocation getRAngleLoc() const {
2342 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2343 return getTemplateKWAndArgsInfo()->RAngleLoc;
2344 }
2345
2346 /// Determines whether the name was preceded by the template keyword.
hasTemplateKeyword()2347 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2348
2349 /// Determines whether this expression had explicit template arguments.
hasExplicitTemplateArgs()2350 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2351
2352 // Note that, inconsistently with the explicit-template-argument AST
2353 // nodes, users are *forbidden* from calling these methods on objects
2354 // without explicit template arguments.
2355
getExplicitTemplateArgs()2356 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2357 assert(hasExplicitTemplateArgs());
2358 return *getTemplateKWAndArgsInfo();
2359 }
2360
getExplicitTemplateArgs()2361 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2362 return const_cast<OverloadExpr*>(this)->getExplicitTemplateArgs();
2363 }
2364
getTemplateArgs()2365 TemplateArgumentLoc const *getTemplateArgs() const {
2366 return getExplicitTemplateArgs().getTemplateArgs();
2367 }
2368
getNumTemplateArgs()2369 unsigned getNumTemplateArgs() const {
2370 return getExplicitTemplateArgs().NumTemplateArgs;
2371 }
2372
2373 /// Copies the template arguments into the given structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)2374 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2375 getExplicitTemplateArgs().copyInto(List);
2376 }
2377
2378 /// \brief Retrieves the optional explicit template arguments.
2379 /// This points to the same data as getExplicitTemplateArgs(), but
2380 /// returns null if there are no explicit template arguments.
getOptionalExplicitTemplateArgs()2381 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2382 if (!hasExplicitTemplateArgs()) return 0;
2383 return &getExplicitTemplateArgs();
2384 }
2385
classof(const Stmt * T)2386 static bool classof(const Stmt *T) {
2387 return T->getStmtClass() == UnresolvedLookupExprClass ||
2388 T->getStmtClass() == UnresolvedMemberExprClass;
2389 }
classof(const OverloadExpr *)2390 static bool classof(const OverloadExpr *) { return true; }
2391
2392 friend class ASTStmtReader;
2393 friend class ASTStmtWriter;
2394 };
2395
2396 /// \brief A reference to a name which we were able to look up during
2397 /// parsing but could not resolve to a specific declaration. This
2398 /// arises in several ways:
2399 /// * we might be waiting for argument-dependent lookup
2400 /// * the name might resolve to an overloaded function
2401 /// and eventually:
2402 /// * the lookup might have included a function template
2403 /// These never include UnresolvedUsingValueDecls, which are always
2404 /// class members and therefore appear only in
2405 /// UnresolvedMemberLookupExprs.
2406 class UnresolvedLookupExpr : public OverloadExpr {
2407 /// True if these lookup results should be extended by
2408 /// argument-dependent lookup if this is the operand of a function
2409 /// call.
2410 bool RequiresADL;
2411
2412 /// True if namespace ::std should be considered an associated namespace
2413 /// for the purposes of argument-dependent lookup. See C++0x [stmt.ranged]p1.
2414 bool StdIsAssociatedNamespace;
2415
2416 /// True if these lookup results are overloaded. This is pretty
2417 /// trivially rederivable if we urgently need to kill this field.
2418 bool Overloaded;
2419
2420 /// The naming class (C++ [class.access.base]p5) of the lookup, if
2421 /// any. This can generally be recalculated from the context chain,
2422 /// but that can be fairly expensive for unqualified lookups. If we
2423 /// want to improve memory use here, this could go in a union
2424 /// against the qualified-lookup bits.
2425 CXXRecordDecl *NamingClass;
2426
UnresolvedLookupExpr(ASTContext & C,CXXRecordDecl * NamingClass,NestedNameSpecifierLoc QualifierLoc,SourceLocation TemplateKWLoc,const DeclarationNameInfo & NameInfo,bool RequiresADL,bool Overloaded,const TemplateArgumentListInfo * TemplateArgs,UnresolvedSetIterator Begin,UnresolvedSetIterator End,bool StdIsAssociatedNamespace)2427 UnresolvedLookupExpr(ASTContext &C,
2428 CXXRecordDecl *NamingClass,
2429 NestedNameSpecifierLoc QualifierLoc,
2430 SourceLocation TemplateKWLoc,
2431 const DeclarationNameInfo &NameInfo,
2432 bool RequiresADL, bool Overloaded,
2433 const TemplateArgumentListInfo *TemplateArgs,
2434 UnresolvedSetIterator Begin, UnresolvedSetIterator End,
2435 bool StdIsAssociatedNamespace)
2436 : OverloadExpr(UnresolvedLookupExprClass, C, QualifierLoc, TemplateKWLoc,
2437 NameInfo, TemplateArgs, Begin, End, false, false, false),
2438 RequiresADL(RequiresADL),
2439 StdIsAssociatedNamespace(StdIsAssociatedNamespace),
2440 Overloaded(Overloaded), NamingClass(NamingClass)
2441 {}
2442
UnresolvedLookupExpr(EmptyShell Empty)2443 UnresolvedLookupExpr(EmptyShell Empty)
2444 : OverloadExpr(UnresolvedLookupExprClass, Empty),
2445 RequiresADL(false), StdIsAssociatedNamespace(false), Overloaded(false),
2446 NamingClass(0)
2447 {}
2448
2449 friend class ASTStmtReader;
2450
2451 public:
2452 static UnresolvedLookupExpr *Create(ASTContext &C,
2453 CXXRecordDecl *NamingClass,
2454 NestedNameSpecifierLoc QualifierLoc,
2455 const DeclarationNameInfo &NameInfo,
2456 bool ADL, bool Overloaded,
2457 UnresolvedSetIterator Begin,
2458 UnresolvedSetIterator End,
2459 bool StdIsAssociatedNamespace = false) {
2460 assert((ADL || !StdIsAssociatedNamespace) &&
2461 "std considered associated namespace when not performing ADL");
2462 return new(C) UnresolvedLookupExpr(C, NamingClass, QualifierLoc,
2463 SourceLocation(), NameInfo,
2464 ADL, Overloaded, 0, Begin, End,
2465 StdIsAssociatedNamespace);
2466 }
2467
2468 static UnresolvedLookupExpr *Create(ASTContext &C,
2469 CXXRecordDecl *NamingClass,
2470 NestedNameSpecifierLoc QualifierLoc,
2471 SourceLocation TemplateKWLoc,
2472 const DeclarationNameInfo &NameInfo,
2473 bool ADL,
2474 const TemplateArgumentListInfo *Args,
2475 UnresolvedSetIterator Begin,
2476 UnresolvedSetIterator End);
2477
2478 static UnresolvedLookupExpr *CreateEmpty(ASTContext &C,
2479 bool HasTemplateKWAndArgsInfo,
2480 unsigned NumTemplateArgs);
2481
2482 /// True if this declaration should be extended by
2483 /// argument-dependent lookup.
requiresADL()2484 bool requiresADL() const { return RequiresADL; }
2485
2486 /// True if namespace ::std should be artificially added to the set of
2487 /// associated namespaecs for argument-dependent lookup purposes.
isStdAssociatedNamespace()2488 bool isStdAssociatedNamespace() const { return StdIsAssociatedNamespace; }
2489
2490 /// True if this lookup is overloaded.
isOverloaded()2491 bool isOverloaded() const { return Overloaded; }
2492
2493 /// Gets the 'naming class' (in the sense of C++0x
2494 /// [class.access.base]p5) of the lookup. This is the scope
2495 /// that was looked in to find these results.
getNamingClass()2496 CXXRecordDecl *getNamingClass() const { return NamingClass; }
2497
getSourceRange()2498 SourceRange getSourceRange() const LLVM_READONLY {
2499 SourceRange Range(getNameInfo().getSourceRange());
2500 if (getQualifierLoc())
2501 Range.setBegin(getQualifierLoc().getBeginLoc());
2502 if (hasExplicitTemplateArgs())
2503 Range.setEnd(getRAngleLoc());
2504 return Range;
2505 }
2506
children()2507 child_range children() { return child_range(); }
2508
classof(const Stmt * T)2509 static bool classof(const Stmt *T) {
2510 return T->getStmtClass() == UnresolvedLookupExprClass;
2511 }
classof(const UnresolvedLookupExpr *)2512 static bool classof(const UnresolvedLookupExpr *) { return true; }
2513 };
2514
2515 /// \brief A qualified reference to a name whose declaration cannot
2516 /// yet be resolved.
2517 ///
2518 /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that
2519 /// it expresses a reference to a declaration such as
2520 /// X<T>::value. The difference, however, is that an
2521 /// DependentScopeDeclRefExpr node is used only within C++ templates when
2522 /// the qualification (e.g., X<T>::) refers to a dependent type. In
2523 /// this case, X<T>::value cannot resolve to a declaration because the
2524 /// declaration will differ from on instantiation of X<T> to the
2525 /// next. Therefore, DependentScopeDeclRefExpr keeps track of the
2526 /// qualifier (X<T>::) and the name of the entity being referenced
2527 /// ("value"). Such expressions will instantiate to a DeclRefExpr once the
2528 /// declaration can be found.
2529 class DependentScopeDeclRefExpr : public Expr {
2530 /// \brief The nested-name-specifier that qualifies this unresolved
2531 /// declaration name.
2532 NestedNameSpecifierLoc QualifierLoc;
2533
2534 /// The name of the entity we will be referencing.
2535 DeclarationNameInfo NameInfo;
2536
2537 /// \brief Whether the name includes info for explicit template
2538 /// keyword and arguments.
2539 bool HasTemplateKWAndArgsInfo;
2540
2541 /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2542 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2543 if (!HasTemplateKWAndArgsInfo) return 0;
2544 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2545 }
2546 /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2547 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2548 return const_cast<DependentScopeDeclRefExpr*>(this)
2549 ->getTemplateKWAndArgsInfo();
2550 }
2551
2552 DependentScopeDeclRefExpr(QualType T,
2553 NestedNameSpecifierLoc QualifierLoc,
2554 SourceLocation TemplateKWLoc,
2555 const DeclarationNameInfo &NameInfo,
2556 const TemplateArgumentListInfo *Args);
2557
2558 public:
2559 static DependentScopeDeclRefExpr *Create(ASTContext &C,
2560 NestedNameSpecifierLoc QualifierLoc,
2561 SourceLocation TemplateKWLoc,
2562 const DeclarationNameInfo &NameInfo,
2563 const TemplateArgumentListInfo *TemplateArgs);
2564
2565 static DependentScopeDeclRefExpr *CreateEmpty(ASTContext &C,
2566 bool HasTemplateKWAndArgsInfo,
2567 unsigned NumTemplateArgs);
2568
2569 /// \brief Retrieve the name that this expression refers to.
getNameInfo()2570 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2571
2572 /// \brief Retrieve the name that this expression refers to.
getDeclName()2573 DeclarationName getDeclName() const { return NameInfo.getName(); }
2574
2575 /// \brief Retrieve the location of the name within the expression.
getLocation()2576 SourceLocation getLocation() const { return NameInfo.getLoc(); }
2577
2578 /// \brief Retrieve the nested-name-specifier that qualifies the
2579 /// name, with source location information.
getQualifierLoc()2580 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2581
2582
2583 /// \brief Retrieve the nested-name-specifier that qualifies this
2584 /// declaration.
getQualifier()2585 NestedNameSpecifier *getQualifier() const {
2586 return QualifierLoc.getNestedNameSpecifier();
2587 }
2588
2589 /// \brief Retrieve the location of the template keyword preceding
2590 /// this name, if any.
getTemplateKeywordLoc()2591 SourceLocation getTemplateKeywordLoc() const {
2592 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2593 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
2594 }
2595
2596 /// \brief Retrieve the location of the left angle bracket starting the
2597 /// explicit template argument list following the name, if any.
getLAngleLoc()2598 SourceLocation getLAngleLoc() const {
2599 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2600 return getTemplateKWAndArgsInfo()->LAngleLoc;
2601 }
2602
2603 /// \brief Retrieve the location of the right angle bracket ending the
2604 /// explicit template argument list following the name, if any.
getRAngleLoc()2605 SourceLocation getRAngleLoc() const {
2606 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
2607 return getTemplateKWAndArgsInfo()->RAngleLoc;
2608 }
2609
2610 /// Determines whether the name was preceded by the template keyword.
hasTemplateKeyword()2611 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2612
2613 /// Determines whether this lookup had explicit template arguments.
hasExplicitTemplateArgs()2614 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2615
2616 // Note that, inconsistently with the explicit-template-argument AST
2617 // nodes, users are *forbidden* from calling these methods on objects
2618 // without explicit template arguments.
2619
getExplicitTemplateArgs()2620 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
2621 assert(hasExplicitTemplateArgs());
2622 return *reinterpret_cast<ASTTemplateArgumentListInfo*>(this + 1);
2623 }
2624
2625 /// Gets a reference to the explicit template argument list.
getExplicitTemplateArgs()2626 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
2627 assert(hasExplicitTemplateArgs());
2628 return *reinterpret_cast<const ASTTemplateArgumentListInfo*>(this + 1);
2629 }
2630
2631 /// \brief Retrieves the optional explicit template arguments.
2632 /// This points to the same data as getExplicitTemplateArgs(), but
2633 /// returns null if there are no explicit template arguments.
getOptionalExplicitTemplateArgs()2634 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
2635 if (!hasExplicitTemplateArgs()) return 0;
2636 return &getExplicitTemplateArgs();
2637 }
2638
2639 /// \brief Copies the template arguments (if present) into the given
2640 /// structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)2641 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2642 getExplicitTemplateArgs().copyInto(List);
2643 }
2644
getTemplateArgs()2645 TemplateArgumentLoc const *getTemplateArgs() const {
2646 return getExplicitTemplateArgs().getTemplateArgs();
2647 }
2648
getNumTemplateArgs()2649 unsigned getNumTemplateArgs() const {
2650 return getExplicitTemplateArgs().NumTemplateArgs;
2651 }
2652
getSourceRange()2653 SourceRange getSourceRange() const LLVM_READONLY {
2654 SourceRange Range(QualifierLoc.getBeginLoc(), getLocation());
2655 if (hasExplicitTemplateArgs())
2656 Range.setEnd(getRAngleLoc());
2657 return Range;
2658 }
2659
classof(const Stmt * T)2660 static bool classof(const Stmt *T) {
2661 return T->getStmtClass() == DependentScopeDeclRefExprClass;
2662 }
classof(const DependentScopeDeclRefExpr *)2663 static bool classof(const DependentScopeDeclRefExpr *) { return true; }
2664
children()2665 child_range children() { return child_range(); }
2666
2667 friend class ASTStmtReader;
2668 friend class ASTStmtWriter;
2669 };
2670
2671 /// Represents an expression --- generally a full-expression --- which
2672 /// introduces cleanups to be run at the end of the sub-expression's
2673 /// evaluation. The most common source of expression-introduced
2674 /// cleanups is temporary objects in C++, but several other kinds of
2675 /// expressions can create cleanups, including basically every
2676 /// call in ARC that returns an Objective-C pointer.
2677 ///
2678 /// This expression also tracks whether the sub-expression contains a
2679 /// potentially-evaluated block literal. The lifetime of a block
2680 /// literal is the extent of the enclosing scope.
2681 class ExprWithCleanups : public Expr {
2682 public:
2683 /// The type of objects that are kept in the cleanup.
2684 /// It's useful to remember the set of blocks; we could also
2685 /// remember the set of temporaries, but there's currently
2686 /// no need.
2687 typedef BlockDecl *CleanupObject;
2688
2689 private:
2690 Stmt *SubExpr;
2691
2692 ExprWithCleanups(EmptyShell, unsigned NumObjects);
2693 ExprWithCleanups(Expr *SubExpr, ArrayRef<CleanupObject> Objects);
2694
getObjectsBuffer()2695 CleanupObject *getObjectsBuffer() {
2696 return reinterpret_cast<CleanupObject*>(this + 1);
2697 }
getObjectsBuffer()2698 const CleanupObject *getObjectsBuffer() const {
2699 return reinterpret_cast<const CleanupObject*>(this + 1);
2700 }
2701 friend class ASTStmtReader;
2702
2703 public:
2704 static ExprWithCleanups *Create(ASTContext &C, EmptyShell empty,
2705 unsigned numObjects);
2706
2707 static ExprWithCleanups *Create(ASTContext &C, Expr *subexpr,
2708 ArrayRef<CleanupObject> objects);
2709
getObjects()2710 ArrayRef<CleanupObject> getObjects() const {
2711 return ArrayRef<CleanupObject>(getObjectsBuffer(), getNumObjects());
2712 }
2713
getNumObjects()2714 unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; }
2715
getObject(unsigned i)2716 CleanupObject getObject(unsigned i) const {
2717 assert(i < getNumObjects() && "Index out of range");
2718 return getObjects()[i];
2719 }
2720
getSubExpr()2721 Expr *getSubExpr() { return cast<Expr>(SubExpr); }
getSubExpr()2722 const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
2723
2724 /// setSubExpr - As with any mutator of the AST, be very careful
2725 /// when modifying an existing AST to preserve its invariants.
setSubExpr(Expr * E)2726 void setSubExpr(Expr *E) { SubExpr = E; }
2727
getSourceRange()2728 SourceRange getSourceRange() const LLVM_READONLY {
2729 return SubExpr->getSourceRange();
2730 }
2731
2732 // Implement isa/cast/dyncast/etc.
classof(const Stmt * T)2733 static bool classof(const Stmt *T) {
2734 return T->getStmtClass() == ExprWithCleanupsClass;
2735 }
classof(const ExprWithCleanups *)2736 static bool classof(const ExprWithCleanups *) { return true; }
2737
2738 // Iterators
children()2739 child_range children() { return child_range(&SubExpr, &SubExpr + 1); }
2740 };
2741
2742 /// \brief Describes an explicit type conversion that uses functional
2743 /// notion but could not be resolved because one or more arguments are
2744 /// type-dependent.
2745 ///
2746 /// The explicit type conversions expressed by
2747 /// CXXUnresolvedConstructExpr have the form \c T(a1, a2, ..., aN),
2748 /// where \c T is some type and \c a1, a2, ..., aN are values, and
2749 /// either \C T is a dependent type or one or more of the \c a's is
2750 /// type-dependent. For example, this would occur in a template such
2751 /// as:
2752 ///
2753 /// \code
2754 /// template<typename T, typename A1>
2755 /// inline T make_a(const A1& a1) {
2756 /// return T(a1);
2757 /// }
2758 /// \endcode
2759 ///
2760 /// When the returned expression is instantiated, it may resolve to a
2761 /// constructor call, conversion function call, or some kind of type
2762 /// conversion.
2763 class CXXUnresolvedConstructExpr : public Expr {
2764 /// \brief The type being constructed.
2765 TypeSourceInfo *Type;
2766
2767 /// \brief The location of the left parentheses ('(').
2768 SourceLocation LParenLoc;
2769
2770 /// \brief The location of the right parentheses (')').
2771 SourceLocation RParenLoc;
2772
2773 /// \brief The number of arguments used to construct the type.
2774 unsigned NumArgs;
2775
2776 CXXUnresolvedConstructExpr(TypeSourceInfo *Type,
2777 SourceLocation LParenLoc,
2778 Expr **Args,
2779 unsigned NumArgs,
2780 SourceLocation RParenLoc);
2781
CXXUnresolvedConstructExpr(EmptyShell Empty,unsigned NumArgs)2782 CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
2783 : Expr(CXXUnresolvedConstructExprClass, Empty), Type(), NumArgs(NumArgs) { }
2784
2785 friend class ASTStmtReader;
2786
2787 public:
2788 static CXXUnresolvedConstructExpr *Create(ASTContext &C,
2789 TypeSourceInfo *Type,
2790 SourceLocation LParenLoc,
2791 Expr **Args,
2792 unsigned NumArgs,
2793 SourceLocation RParenLoc);
2794
2795 static CXXUnresolvedConstructExpr *CreateEmpty(ASTContext &C,
2796 unsigned NumArgs);
2797
2798 /// \brief Retrieve the type that is being constructed, as specified
2799 /// in the source code.
getTypeAsWritten()2800 QualType getTypeAsWritten() const { return Type->getType(); }
2801
2802 /// \brief Retrieve the type source information for the type being
2803 /// constructed.
getTypeSourceInfo()2804 TypeSourceInfo *getTypeSourceInfo() const { return Type; }
2805
2806 /// \brief Retrieve the location of the left parentheses ('(') that
2807 /// precedes the argument list.
getLParenLoc()2808 SourceLocation getLParenLoc() const { return LParenLoc; }
setLParenLoc(SourceLocation L)2809 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2810
2811 /// \brief Retrieve the location of the right parentheses (')') that
2812 /// follows the argument list.
getRParenLoc()2813 SourceLocation getRParenLoc() const { return RParenLoc; }
setRParenLoc(SourceLocation L)2814 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2815
2816 /// \brief Retrieve the number of arguments.
arg_size()2817 unsigned arg_size() const { return NumArgs; }
2818
2819 typedef Expr** arg_iterator;
arg_begin()2820 arg_iterator arg_begin() { return reinterpret_cast<Expr**>(this + 1); }
arg_end()2821 arg_iterator arg_end() { return arg_begin() + NumArgs; }
2822
2823 typedef const Expr* const * const_arg_iterator;
arg_begin()2824 const_arg_iterator arg_begin() const {
2825 return reinterpret_cast<const Expr* const *>(this + 1);
2826 }
arg_end()2827 const_arg_iterator arg_end() const {
2828 return arg_begin() + NumArgs;
2829 }
2830
getArg(unsigned I)2831 Expr *getArg(unsigned I) {
2832 assert(I < NumArgs && "Argument index out-of-range");
2833 return *(arg_begin() + I);
2834 }
2835
getArg(unsigned I)2836 const Expr *getArg(unsigned I) const {
2837 assert(I < NumArgs && "Argument index out-of-range");
2838 return *(arg_begin() + I);
2839 }
2840
setArg(unsigned I,Expr * E)2841 void setArg(unsigned I, Expr *E) {
2842 assert(I < NumArgs && "Argument index out-of-range");
2843 *(arg_begin() + I) = E;
2844 }
2845
2846 SourceRange getSourceRange() const LLVM_READONLY;
2847
classof(const Stmt * T)2848 static bool classof(const Stmt *T) {
2849 return T->getStmtClass() == CXXUnresolvedConstructExprClass;
2850 }
classof(const CXXUnresolvedConstructExpr *)2851 static bool classof(const CXXUnresolvedConstructExpr *) { return true; }
2852
2853 // Iterators
children()2854 child_range children() {
2855 Stmt **begin = reinterpret_cast<Stmt**>(this+1);
2856 return child_range(begin, begin + NumArgs);
2857 }
2858 };
2859
2860 /// \brief Represents a C++ member access expression where the actual
2861 /// member referenced could not be resolved because the base
2862 /// expression or the member name was dependent.
2863 ///
2864 /// Like UnresolvedMemberExprs, these can be either implicit or
2865 /// explicit accesses. It is only possible to get one of these with
2866 /// an implicit access if a qualifier is provided.
2867 class CXXDependentScopeMemberExpr : public Expr {
2868 /// \brief The expression for the base pointer or class reference,
2869 /// e.g., the \c x in x.f. Can be null in implicit accesses.
2870 Stmt *Base;
2871
2872 /// \brief The type of the base expression. Never null, even for
2873 /// implicit accesses.
2874 QualType BaseType;
2875
2876 /// \brief Whether this member expression used the '->' operator or
2877 /// the '.' operator.
2878 bool IsArrow : 1;
2879
2880 /// \brief Whether this member expression has info for explicit template
2881 /// keyword and arguments.
2882 bool HasTemplateKWAndArgsInfo : 1;
2883
2884 /// \brief The location of the '->' or '.' operator.
2885 SourceLocation OperatorLoc;
2886
2887 /// \brief The nested-name-specifier that precedes the member name, if any.
2888 NestedNameSpecifierLoc QualifierLoc;
2889
2890 /// \brief In a qualified member access expression such as t->Base::f, this
2891 /// member stores the resolves of name lookup in the context of the member
2892 /// access expression, to be used at instantiation time.
2893 ///
2894 /// FIXME: This member, along with the QualifierLoc, could
2895 /// be stuck into a structure that is optionally allocated at the end of
2896 /// the CXXDependentScopeMemberExpr, to save space in the common case.
2897 NamedDecl *FirstQualifierFoundInScope;
2898
2899 /// \brief The member to which this member expression refers, which
2900 /// can be name, overloaded operator, or destructor.
2901 /// FIXME: could also be a template-id
2902 DeclarationNameInfo MemberNameInfo;
2903
2904 /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2905 ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() {
2906 if (!HasTemplateKWAndArgsInfo) return 0;
2907 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>(this + 1);
2908 }
2909 /// \brief Return the optional template keyword and arguments info.
getTemplateKWAndArgsInfo()2910 const ASTTemplateKWAndArgsInfo *getTemplateKWAndArgsInfo() const {
2911 return const_cast<CXXDependentScopeMemberExpr*>(this)
2912 ->getTemplateKWAndArgsInfo();
2913 }
2914
2915 CXXDependentScopeMemberExpr(ASTContext &C,
2916 Expr *Base, QualType BaseType, bool IsArrow,
2917 SourceLocation OperatorLoc,
2918 NestedNameSpecifierLoc QualifierLoc,
2919 SourceLocation TemplateKWLoc,
2920 NamedDecl *FirstQualifierFoundInScope,
2921 DeclarationNameInfo MemberNameInfo,
2922 const TemplateArgumentListInfo *TemplateArgs);
2923
2924 public:
2925 CXXDependentScopeMemberExpr(ASTContext &C,
2926 Expr *Base, QualType BaseType,
2927 bool IsArrow,
2928 SourceLocation OperatorLoc,
2929 NestedNameSpecifierLoc QualifierLoc,
2930 NamedDecl *FirstQualifierFoundInScope,
2931 DeclarationNameInfo MemberNameInfo);
2932
2933 static CXXDependentScopeMemberExpr *
2934 Create(ASTContext &C,
2935 Expr *Base, QualType BaseType, bool IsArrow,
2936 SourceLocation OperatorLoc,
2937 NestedNameSpecifierLoc QualifierLoc,
2938 SourceLocation TemplateKWLoc,
2939 NamedDecl *FirstQualifierFoundInScope,
2940 DeclarationNameInfo MemberNameInfo,
2941 const TemplateArgumentListInfo *TemplateArgs);
2942
2943 static CXXDependentScopeMemberExpr *
2944 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
2945 unsigned NumTemplateArgs);
2946
2947 /// \brief True if this is an implicit access, i.e. one in which the
2948 /// member being accessed was not written in the source. The source
2949 /// location of the operator is invalid in this case.
2950 bool isImplicitAccess() const;
2951
2952 /// \brief Retrieve the base object of this member expressions,
2953 /// e.g., the \c x in \c x.m.
getBase()2954 Expr *getBase() const {
2955 assert(!isImplicitAccess());
2956 return cast<Expr>(Base);
2957 }
2958
getBaseType()2959 QualType getBaseType() const { return BaseType; }
2960
2961 /// \brief Determine whether this member expression used the '->'
2962 /// operator; otherwise, it used the '.' operator.
isArrow()2963 bool isArrow() const { return IsArrow; }
2964
2965 /// \brief Retrieve the location of the '->' or '.' operator.
getOperatorLoc()2966 SourceLocation getOperatorLoc() const { return OperatorLoc; }
2967
2968 /// \brief Retrieve the nested-name-specifier that qualifies the member
2969 /// name.
getQualifier()2970 NestedNameSpecifier *getQualifier() const {
2971 return QualifierLoc.getNestedNameSpecifier();
2972 }
2973
2974 /// \brief Retrieve the nested-name-specifier that qualifies the member
2975 /// name, with source location information.
getQualifierLoc()2976 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2977
2978
2979 /// \brief Retrieve the first part of the nested-name-specifier that was
2980 /// found in the scope of the member access expression when the member access
2981 /// was initially parsed.
2982 ///
2983 /// This function only returns a useful result when member access expression
2984 /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration
2985 /// returned by this function describes what was found by unqualified name
2986 /// lookup for the identifier "Base" within the scope of the member access
2987 /// expression itself. At template instantiation time, this information is
2988 /// combined with the results of name lookup into the type of the object
2989 /// expression itself (the class type of x).
getFirstQualifierFoundInScope()2990 NamedDecl *getFirstQualifierFoundInScope() const {
2991 return FirstQualifierFoundInScope;
2992 }
2993
2994 /// \brief Retrieve the name of the member that this expression
2995 /// refers to.
getMemberNameInfo()2996 const DeclarationNameInfo &getMemberNameInfo() const {
2997 return MemberNameInfo;
2998 }
2999
3000 /// \brief Retrieve the name of the member that this expression
3001 /// refers to.
getMember()3002 DeclarationName getMember() const { return MemberNameInfo.getName(); }
3003
3004 // \brief Retrieve the location of the name of the member that this
3005 // expression refers to.
getMemberLoc()3006 SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); }
3007
3008 /// \brief Retrieve the location of the template keyword preceding the
3009 /// member name, if any.
getTemplateKeywordLoc()3010 SourceLocation getTemplateKeywordLoc() const {
3011 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3012 return getTemplateKWAndArgsInfo()->getTemplateKeywordLoc();
3013 }
3014
3015 /// \brief Retrieve the location of the left angle bracket starting the
3016 /// explicit template argument list following the member name, if any.
getLAngleLoc()3017 SourceLocation getLAngleLoc() const {
3018 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3019 return getTemplateKWAndArgsInfo()->LAngleLoc;
3020 }
3021
3022 /// \brief Retrieve the location of the right angle bracket ending the
3023 /// explicit template argument list following the member name, if any.
getRAngleLoc()3024 SourceLocation getRAngleLoc() const {
3025 if (!HasTemplateKWAndArgsInfo) return SourceLocation();
3026 return getTemplateKWAndArgsInfo()->RAngleLoc;
3027 }
3028
3029 /// Determines whether the member name was preceded by the template keyword.
hasTemplateKeyword()3030 bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
3031
3032 /// \brief Determines whether this member expression actually had a C++
3033 /// template argument list explicitly specified, e.g., x.f<int>.
hasExplicitTemplateArgs()3034 bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
3035
3036 /// \brief Retrieve the explicit template argument list that followed the
3037 /// member template name, if any.
getExplicitTemplateArgs()3038 ASTTemplateArgumentListInfo &getExplicitTemplateArgs() {
3039 assert(hasExplicitTemplateArgs());
3040 return *reinterpret_cast<ASTTemplateArgumentListInfo *>(this + 1);
3041 }
3042
3043 /// \brief Retrieve the explicit template argument list that followed the
3044 /// member template name, if any.
getExplicitTemplateArgs()3045 const ASTTemplateArgumentListInfo &getExplicitTemplateArgs() const {
3046 return const_cast<CXXDependentScopeMemberExpr *>(this)
3047 ->getExplicitTemplateArgs();
3048 }
3049
3050 /// \brief Retrieves the optional explicit template arguments.
3051 /// This points to the same data as getExplicitTemplateArgs(), but
3052 /// returns null if there are no explicit template arguments.
getOptionalExplicitTemplateArgs()3053 const ASTTemplateArgumentListInfo *getOptionalExplicitTemplateArgs() {
3054 if (!hasExplicitTemplateArgs()) return 0;
3055 return &getExplicitTemplateArgs();
3056 }
3057
3058 /// \brief Copies the template arguments (if present) into the given
3059 /// structure.
copyTemplateArgumentsInto(TemplateArgumentListInfo & List)3060 void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
3061 getExplicitTemplateArgs().copyInto(List);
3062 }
3063
3064 /// \brief Initializes the template arguments using the given structure.
initializeTemplateArgumentsFrom(const TemplateArgumentListInfo & List)3065 void initializeTemplateArgumentsFrom(const TemplateArgumentListInfo &List) {
3066 getExplicitTemplateArgs().initializeFrom(List);
3067 }
3068
3069 /// \brief Retrieve the template arguments provided as part of this
3070 /// template-id.
getTemplateArgs()3071 const TemplateArgumentLoc *getTemplateArgs() const {
3072 return getExplicitTemplateArgs().getTemplateArgs();
3073 }
3074
3075 /// \brief Retrieve the number of template arguments provided as part of this
3076 /// template-id.
getNumTemplateArgs()3077 unsigned getNumTemplateArgs() const {
3078 return getExplicitTemplateArgs().NumTemplateArgs;
3079 }
3080
getSourceRange()3081 SourceRange getSourceRange() const LLVM_READONLY {
3082 SourceRange Range;
3083 if (!isImplicitAccess())
3084 Range.setBegin(Base->getSourceRange().getBegin());
3085 else if (getQualifier())
3086 Range.setBegin(getQualifierLoc().getBeginLoc());
3087 else
3088 Range.setBegin(MemberNameInfo.getBeginLoc());
3089
3090 if (hasExplicitTemplateArgs())
3091 Range.setEnd(getRAngleLoc());
3092 else
3093 Range.setEnd(MemberNameInfo.getEndLoc());
3094 return Range;
3095 }
3096
classof(const Stmt * T)3097 static bool classof(const Stmt *T) {
3098 return T->getStmtClass() == CXXDependentScopeMemberExprClass;
3099 }
classof(const CXXDependentScopeMemberExpr *)3100 static bool classof(const CXXDependentScopeMemberExpr *) { return true; }
3101
3102 // Iterators
children()3103 child_range children() {
3104 if (isImplicitAccess()) return child_range();
3105 return child_range(&Base, &Base + 1);
3106 }
3107
3108 friend class ASTStmtReader;
3109 friend class ASTStmtWriter;
3110 };
3111
3112 /// \brief Represents a C++ member access expression for which lookup
3113 /// produced a set of overloaded functions.
3114 ///
3115 /// The member access may be explicit or implicit:
3116 /// struct A {
3117 /// int a, b;
3118 /// int explicitAccess() { return this->a + this->A::b; }
3119 /// int implicitAccess() { return a + A::b; }
3120 /// };
3121 ///
3122 /// In the final AST, an explicit access always becomes a MemberExpr.
3123 /// An implicit access may become either a MemberExpr or a
3124 /// DeclRefExpr, depending on whether the member is static.
3125 class UnresolvedMemberExpr : public OverloadExpr {
3126 /// \brief Whether this member expression used the '->' operator or
3127 /// the '.' operator.
3128 bool IsArrow : 1;
3129
3130 /// \brief Whether the lookup results contain an unresolved using
3131 /// declaration.
3132 bool HasUnresolvedUsing : 1;
3133
3134 /// \brief The expression for the base pointer or class reference,
3135 /// e.g., the \c x in x.f. This can be null if this is an 'unbased'
3136 /// member expression
3137 Stmt *Base;
3138
3139 /// \brief The type of the base expression; never null.
3140 QualType BaseType;
3141
3142 /// \brief The location of the '->' or '.' operator.
3143 SourceLocation OperatorLoc;
3144
3145 UnresolvedMemberExpr(ASTContext &C, bool HasUnresolvedUsing,
3146 Expr *Base, QualType BaseType, bool IsArrow,
3147 SourceLocation OperatorLoc,
3148 NestedNameSpecifierLoc QualifierLoc,
3149 SourceLocation TemplateKWLoc,
3150 const DeclarationNameInfo &MemberNameInfo,
3151 const TemplateArgumentListInfo *TemplateArgs,
3152 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3153
UnresolvedMemberExpr(EmptyShell Empty)3154 UnresolvedMemberExpr(EmptyShell Empty)
3155 : OverloadExpr(UnresolvedMemberExprClass, Empty), IsArrow(false),
3156 HasUnresolvedUsing(false), Base(0) { }
3157
3158 friend class ASTStmtReader;
3159
3160 public:
3161 static UnresolvedMemberExpr *
3162 Create(ASTContext &C, bool HasUnresolvedUsing,
3163 Expr *Base, QualType BaseType, bool IsArrow,
3164 SourceLocation OperatorLoc,
3165 NestedNameSpecifierLoc QualifierLoc,
3166 SourceLocation TemplateKWLoc,
3167 const DeclarationNameInfo &MemberNameInfo,
3168 const TemplateArgumentListInfo *TemplateArgs,
3169 UnresolvedSetIterator Begin, UnresolvedSetIterator End);
3170
3171 static UnresolvedMemberExpr *
3172 CreateEmpty(ASTContext &C, bool HasTemplateKWAndArgsInfo,
3173 unsigned NumTemplateArgs);
3174
3175 /// \brief True if this is an implicit access, i.e. one in which the
3176 /// member being accessed was not written in the source. The source
3177 /// location of the operator is invalid in this case.
3178 bool isImplicitAccess() const;
3179
3180 /// \brief Retrieve the base object of this member expressions,
3181 /// e.g., the \c x in \c x.m.
getBase()3182 Expr *getBase() {
3183 assert(!isImplicitAccess());
3184 return cast<Expr>(Base);
3185 }
getBase()3186 const Expr *getBase() const {
3187 assert(!isImplicitAccess());
3188 return cast<Expr>(Base);
3189 }
3190
getBaseType()3191 QualType getBaseType() const { return BaseType; }
3192
3193 /// \brief Determine whether the lookup results contain an unresolved using
3194 /// declaration.
hasUnresolvedUsing()3195 bool hasUnresolvedUsing() const { return HasUnresolvedUsing; }
3196
3197 /// \brief Determine whether this member expression used the '->'
3198 /// operator; otherwise, it used the '.' operator.
isArrow()3199 bool isArrow() const { return IsArrow; }
3200
3201 /// \brief Retrieve the location of the '->' or '.' operator.
getOperatorLoc()3202 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3203
3204 /// \brief Retrieves the naming class of this lookup.
3205 CXXRecordDecl *getNamingClass() const;
3206
3207 /// \brief Retrieve the full name info for the member that this expression
3208 /// refers to.
getMemberNameInfo()3209 const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); }
3210
3211 /// \brief Retrieve the name of the member that this expression
3212 /// refers to.
getMemberName()3213 DeclarationName getMemberName() const { return getName(); }
3214
3215 // \brief Retrieve the location of the name of the member that this
3216 // expression refers to.
getMemberLoc()3217 SourceLocation getMemberLoc() const { return getNameLoc(); }
3218
getSourceRange()3219 SourceRange getSourceRange() const LLVM_READONLY {
3220 SourceRange Range = getMemberNameInfo().getSourceRange();
3221 if (!isImplicitAccess())
3222 Range.setBegin(Base->getSourceRange().getBegin());
3223 else if (getQualifierLoc())
3224 Range.setBegin(getQualifierLoc().getBeginLoc());
3225
3226 if (hasExplicitTemplateArgs())
3227 Range.setEnd(getRAngleLoc());
3228 return Range;
3229 }
3230
classof(const Stmt * T)3231 static bool classof(const Stmt *T) {
3232 return T->getStmtClass() == UnresolvedMemberExprClass;
3233 }
classof(const UnresolvedMemberExpr *)3234 static bool classof(const UnresolvedMemberExpr *) { return true; }
3235
3236 // Iterators
children()3237 child_range children() {
3238 if (isImplicitAccess()) return child_range();
3239 return child_range(&Base, &Base + 1);
3240 }
3241 };
3242
3243 /// \brief Represents a C++0x noexcept expression (C++ [expr.unary.noexcept]).
3244 ///
3245 /// The noexcept expression tests whether a given expression might throw. Its
3246 /// result is a boolean constant.
3247 class CXXNoexceptExpr : public Expr {
3248 bool Value : 1;
3249 Stmt *Operand;
3250 SourceRange Range;
3251
3252 friend class ASTStmtReader;
3253
3254 public:
CXXNoexceptExpr(QualType Ty,Expr * Operand,CanThrowResult Val,SourceLocation Keyword,SourceLocation RParen)3255 CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
3256 SourceLocation Keyword, SourceLocation RParen)
3257 : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
3258 /*TypeDependent*/false,
3259 /*ValueDependent*/Val == CT_Dependent,
3260 Val == CT_Dependent || Operand->isInstantiationDependent(),
3261 Operand->containsUnexpandedParameterPack()),
3262 Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen)
3263 { }
3264
CXXNoexceptExpr(EmptyShell Empty)3265 CXXNoexceptExpr(EmptyShell Empty)
3266 : Expr(CXXNoexceptExprClass, Empty)
3267 { }
3268
getOperand()3269 Expr *getOperand() const { return static_cast<Expr*>(Operand); }
3270
getSourceRange()3271 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
3272
getValue()3273 bool getValue() const { return Value; }
3274
classof(const Stmt * T)3275 static bool classof(const Stmt *T) {
3276 return T->getStmtClass() == CXXNoexceptExprClass;
3277 }
classof(const CXXNoexceptExpr *)3278 static bool classof(const CXXNoexceptExpr *) { return true; }
3279
3280 // Iterators
children()3281 child_range children() { return child_range(&Operand, &Operand + 1); }
3282 };
3283
3284 /// \brief Represents a C++0x pack expansion that produces a sequence of
3285 /// expressions.
3286 ///
3287 /// A pack expansion expression contains a pattern (which itself is an
3288 /// expression) followed by an ellipsis. For example:
3289 ///
3290 /// \code
3291 /// template<typename F, typename ...Types>
3292 /// void forward(F f, Types &&...args) {
3293 /// f(static_cast<Types&&>(args)...);
3294 /// }
3295 /// \endcode
3296 ///
3297 /// Here, the argument to the function object \c f is a pack expansion whose
3298 /// pattern is \c static_cast<Types&&>(args). When the \c forward function
3299 /// template is instantiated, the pack expansion will instantiate to zero or
3300 /// or more function arguments to the function object \c f.
3301 class PackExpansionExpr : public Expr {
3302 SourceLocation EllipsisLoc;
3303
3304 /// \brief The number of expansions that will be produced by this pack
3305 /// expansion expression, if known.
3306 ///
3307 /// When zero, the number of expansions is not known. Otherwise, this value
3308 /// is the number of expansions + 1.
3309 unsigned NumExpansions;
3310
3311 Stmt *Pattern;
3312
3313 friend class ASTStmtReader;
3314 friend class ASTStmtWriter;
3315
3316 public:
PackExpansionExpr(QualType T,Expr * Pattern,SourceLocation EllipsisLoc,llvm::Optional<unsigned> NumExpansions)3317 PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
3318 llvm::Optional<unsigned> NumExpansions)
3319 : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
3320 Pattern->getObjectKind(), /*TypeDependent=*/true,
3321 /*ValueDependent=*/true, /*InstantiationDependent=*/true,
3322 /*ContainsUnexpandedParameterPack=*/false),
3323 EllipsisLoc(EllipsisLoc),
3324 NumExpansions(NumExpansions? *NumExpansions + 1 : 0),
3325 Pattern(Pattern) { }
3326
PackExpansionExpr(EmptyShell Empty)3327 PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) { }
3328
3329 /// \brief Retrieve the pattern of the pack expansion.
getPattern()3330 Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); }
3331
3332 /// \brief Retrieve the pattern of the pack expansion.
getPattern()3333 const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); }
3334
3335 /// \brief Retrieve the location of the ellipsis that describes this pack
3336 /// expansion.
getEllipsisLoc()3337 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
3338
3339 /// \brief Determine the number of expansions that will be produced when
3340 /// this pack expansion is instantiated, if already known.
getNumExpansions()3341 llvm::Optional<unsigned> getNumExpansions() const {
3342 if (NumExpansions)
3343 return NumExpansions - 1;
3344
3345 return llvm::Optional<unsigned>();
3346 }
3347
getSourceRange()3348 SourceRange getSourceRange() const LLVM_READONLY {
3349 return SourceRange(Pattern->getLocStart(), EllipsisLoc);
3350 }
3351
classof(const Stmt * T)3352 static bool classof(const Stmt *T) {
3353 return T->getStmtClass() == PackExpansionExprClass;
3354 }
classof(const PackExpansionExpr *)3355 static bool classof(const PackExpansionExpr *) { return true; }
3356
3357 // Iterators
children()3358 child_range children() {
3359 return child_range(&Pattern, &Pattern + 1);
3360 }
3361 };
3362
getTemplateKWAndArgsInfo()3363 inline ASTTemplateKWAndArgsInfo *OverloadExpr::getTemplateKWAndArgsInfo() {
3364 if (!HasTemplateKWAndArgsInfo) return 0;
3365 if (isa<UnresolvedLookupExpr>(this))
3366 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3367 (cast<UnresolvedLookupExpr>(this) + 1);
3368 else
3369 return reinterpret_cast<ASTTemplateKWAndArgsInfo*>
3370 (cast<UnresolvedMemberExpr>(this) + 1);
3371 }
3372
3373 /// \brief Represents an expression that computes the length of a parameter
3374 /// pack.
3375 ///
3376 /// \code
3377 /// template<typename ...Types>
3378 /// struct count {
3379 /// static const unsigned value = sizeof...(Types);
3380 /// };
3381 /// \endcode
3382 class SizeOfPackExpr : public Expr {
3383 /// \brief The location of the 'sizeof' keyword.
3384 SourceLocation OperatorLoc;
3385
3386 /// \brief The location of the name of the parameter pack.
3387 SourceLocation PackLoc;
3388
3389 /// \brief The location of the closing parenthesis.
3390 SourceLocation RParenLoc;
3391
3392 /// \brief The length of the parameter pack, if known.
3393 ///
3394 /// When this expression is value-dependent, the length of the parameter pack
3395 /// is unknown. When this expression is not value-dependent, the length is
3396 /// known.
3397 unsigned Length;
3398
3399 /// \brief The parameter pack itself.
3400 NamedDecl *Pack;
3401
3402 friend class ASTStmtReader;
3403 friend class ASTStmtWriter;
3404
3405 public:
3406 /// \brief Creates a value-dependent expression that computes the length of
3407 /// the given parameter pack.
SizeOfPackExpr(QualType SizeType,SourceLocation OperatorLoc,NamedDecl * Pack,SourceLocation PackLoc,SourceLocation RParenLoc)3408 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3409 SourceLocation PackLoc, SourceLocation RParenLoc)
3410 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3411 /*TypeDependent=*/false, /*ValueDependent=*/true,
3412 /*InstantiationDependent=*/true,
3413 /*ContainsUnexpandedParameterPack=*/false),
3414 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3415 Length(0), Pack(Pack) { }
3416
3417 /// \brief Creates an expression that computes the length of
3418 /// the given parameter pack, which is already known.
SizeOfPackExpr(QualType SizeType,SourceLocation OperatorLoc,NamedDecl * Pack,SourceLocation PackLoc,SourceLocation RParenLoc,unsigned Length)3419 SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack,
3420 SourceLocation PackLoc, SourceLocation RParenLoc,
3421 unsigned Length)
3422 : Expr(SizeOfPackExprClass, SizeType, VK_RValue, OK_Ordinary,
3423 /*TypeDependent=*/false, /*ValueDependent=*/false,
3424 /*InstantiationDependent=*/false,
3425 /*ContainsUnexpandedParameterPack=*/false),
3426 OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc),
3427 Length(Length), Pack(Pack) { }
3428
3429 /// \brief Create an empty expression.
SizeOfPackExpr(EmptyShell Empty)3430 SizeOfPackExpr(EmptyShell Empty) : Expr(SizeOfPackExprClass, Empty) { }
3431
3432 /// \brief Determine the location of the 'sizeof' keyword.
getOperatorLoc()3433 SourceLocation getOperatorLoc() const { return OperatorLoc; }
3434
3435 /// \brief Determine the location of the parameter pack.
getPackLoc()3436 SourceLocation getPackLoc() const { return PackLoc; }
3437
3438 /// \brief Determine the location of the right parenthesis.
getRParenLoc()3439 SourceLocation getRParenLoc() const { return RParenLoc; }
3440
3441 /// \brief Retrieve the parameter pack.
getPack()3442 NamedDecl *getPack() const { return Pack; }
3443
3444 /// \brief Retrieve the length of the parameter pack.
3445 ///
3446 /// This routine may only be invoked when the expression is not
3447 /// value-dependent.
getPackLength()3448 unsigned getPackLength() const {
3449 assert(!isValueDependent() &&
3450 "Cannot get the length of a value-dependent pack size expression");
3451 return Length;
3452 }
3453
getSourceRange()3454 SourceRange getSourceRange() const LLVM_READONLY {
3455 return SourceRange(OperatorLoc, RParenLoc);
3456 }
3457
classof(const Stmt * T)3458 static bool classof(const Stmt *T) {
3459 return T->getStmtClass() == SizeOfPackExprClass;
3460 }
classof(const SizeOfPackExpr *)3461 static bool classof(const SizeOfPackExpr *) { return true; }
3462
3463 // Iterators
children()3464 child_range children() { return child_range(); }
3465 };
3466
3467 /// \brief Represents a reference to a non-type template parameter
3468 /// that has been substituted with a template argument.
3469 class SubstNonTypeTemplateParmExpr : public Expr {
3470 /// \brief The replaced parameter.
3471 NonTypeTemplateParmDecl *Param;
3472
3473 /// \brief The replacement expression.
3474 Stmt *Replacement;
3475
3476 /// \brief The location of the non-type template parameter reference.
3477 SourceLocation NameLoc;
3478
3479 friend class ASTReader;
3480 friend class ASTStmtReader;
SubstNonTypeTemplateParmExpr(EmptyShell Empty)3481 explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
3482 : Expr(SubstNonTypeTemplateParmExprClass, Empty) { }
3483
3484 public:
SubstNonTypeTemplateParmExpr(QualType type,ExprValueKind valueKind,SourceLocation loc,NonTypeTemplateParmDecl * param,Expr * replacement)3485 SubstNonTypeTemplateParmExpr(QualType type,
3486 ExprValueKind valueKind,
3487 SourceLocation loc,
3488 NonTypeTemplateParmDecl *param,
3489 Expr *replacement)
3490 : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
3491 replacement->isTypeDependent(), replacement->isValueDependent(),
3492 replacement->isInstantiationDependent(),
3493 replacement->containsUnexpandedParameterPack()),
3494 Param(param), Replacement(replacement), NameLoc(loc) {}
3495
getNameLoc()3496 SourceLocation getNameLoc() const { return NameLoc; }
getSourceRange()3497 SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
3498
getReplacement()3499 Expr *getReplacement() const { return cast<Expr>(Replacement); }
3500
getParameter()3501 NonTypeTemplateParmDecl *getParameter() const { return Param; }
3502
classof(const Stmt * s)3503 static bool classof(const Stmt *s) {
3504 return s->getStmtClass() == SubstNonTypeTemplateParmExprClass;
3505 }
classof(const SubstNonTypeTemplateParmExpr *)3506 static bool classof(const SubstNonTypeTemplateParmExpr *) {
3507 return true;
3508 }
3509
3510 // Iterators
children()3511 child_range children() { return child_range(&Replacement, &Replacement+1); }
3512 };
3513
3514 /// \brief Represents a reference to a non-type template parameter pack that
3515 /// has been substituted with a non-template argument pack.
3516 ///
3517 /// When a pack expansion in the source code contains multiple parameter packs
3518 /// and those parameter packs correspond to different levels of template
3519 /// parameter lists, this node node is used to represent a non-type template
3520 /// parameter pack from an outer level, which has already had its argument pack
3521 /// substituted but that still lives within a pack expansion that itself
3522 /// could not be instantiated. When actually performing a substitution into
3523 /// that pack expansion (e.g., when all template parameters have corresponding
3524 /// arguments), this type will be replaced with the appropriate underlying
3525 /// expression at the current pack substitution index.
3526 class SubstNonTypeTemplateParmPackExpr : public Expr {
3527 /// \brief The non-type template parameter pack itself.
3528 NonTypeTemplateParmDecl *Param;
3529
3530 /// \brief A pointer to the set of template arguments that this
3531 /// parameter pack is instantiated with.
3532 const TemplateArgument *Arguments;
3533
3534 /// \brief The number of template arguments in \c Arguments.
3535 unsigned NumArguments;
3536
3537 /// \brief The location of the non-type template parameter pack reference.
3538 SourceLocation NameLoc;
3539
3540 friend class ASTReader;
3541 friend class ASTStmtReader;
SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)3542 explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty)
3543 : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) { }
3544
3545 public:
3546 SubstNonTypeTemplateParmPackExpr(QualType T,
3547 NonTypeTemplateParmDecl *Param,
3548 SourceLocation NameLoc,
3549 const TemplateArgument &ArgPack);
3550
3551 /// \brief Retrieve the non-type template parameter pack being substituted.
getParameterPack()3552 NonTypeTemplateParmDecl *getParameterPack() const { return Param; }
3553
3554 /// \brief Retrieve the location of the parameter pack name.
getParameterPackLocation()3555 SourceLocation getParameterPackLocation() const { return NameLoc; }
3556
3557 /// \brief Retrieve the template argument pack containing the substituted
3558 /// template arguments.
3559 TemplateArgument getArgumentPack() const;
3560
getSourceRange()3561 SourceRange getSourceRange() const LLVM_READONLY { return NameLoc; }
3562
classof(const Stmt * T)3563 static bool classof(const Stmt *T) {
3564 return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass;
3565 }
classof(const SubstNonTypeTemplateParmPackExpr *)3566 static bool classof(const SubstNonTypeTemplateParmPackExpr *) {
3567 return true;
3568 }
3569
3570 // Iterators
children()3571 child_range children() { return child_range(); }
3572 };
3573
3574 /// \brief Represents a prvalue temporary that written into memory so that
3575 /// a reference can bind to it.
3576 ///
3577 /// Prvalue expressions are materialized when they need to have an address
3578 /// in memory for a reference to bind to. This happens when binding a
3579 /// reference to the result of a conversion, e.g.,
3580 ///
3581 /// \code
3582 /// const int &r = 1.0;
3583 /// \endcode
3584 ///
3585 /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is
3586 /// then materialized via a \c MaterializeTemporaryExpr, and the reference
3587 /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues
3588 /// (either an lvalue or an xvalue, depending on the kind of reference binding
3589 /// to it), maintaining the invariant that references always bind to glvalues.
3590 class MaterializeTemporaryExpr : public Expr {
3591 /// \brief The temporary-generating expression whose value will be
3592 /// materialized.
3593 Stmt *Temporary;
3594
3595 friend class ASTStmtReader;
3596 friend class ASTStmtWriter;
3597
3598 public:
MaterializeTemporaryExpr(QualType T,Expr * Temporary,bool BoundToLvalueReference)3599 MaterializeTemporaryExpr(QualType T, Expr *Temporary,
3600 bool BoundToLvalueReference)
3601 : Expr(MaterializeTemporaryExprClass, T,
3602 BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
3603 Temporary->isTypeDependent(), Temporary->isValueDependent(),
3604 Temporary->isInstantiationDependent(),
3605 Temporary->containsUnexpandedParameterPack()),
3606 Temporary(Temporary) { }
3607
MaterializeTemporaryExpr(EmptyShell Empty)3608 MaterializeTemporaryExpr(EmptyShell Empty)
3609 : Expr(MaterializeTemporaryExprClass, Empty) { }
3610
3611 /// \brief Retrieve the temporary-generating subexpression whose value will
3612 /// be materialized into a glvalue.
GetTemporaryExpr()3613 Expr *GetTemporaryExpr() const { return reinterpret_cast<Expr *>(Temporary); }
3614
3615 /// \brief Determine whether this materialized temporary is bound to an
3616 /// lvalue reference; otherwise, it's bound to an rvalue reference.
isBoundToLvalueReference()3617 bool isBoundToLvalueReference() const {
3618 return getValueKind() == VK_LValue;
3619 }
3620
getSourceRange()3621 SourceRange getSourceRange() const LLVM_READONLY {
3622 return Temporary->getSourceRange();
3623 }
3624
classof(const Stmt * T)3625 static bool classof(const Stmt *T) {
3626 return T->getStmtClass() == MaterializeTemporaryExprClass;
3627 }
classof(const MaterializeTemporaryExpr *)3628 static bool classof(const MaterializeTemporaryExpr *) {
3629 return true;
3630 }
3631
3632 // Iterators
children()3633 child_range children() { return child_range(&Temporary, &Temporary + 1); }
3634 };
3635
3636 } // end namespace clang
3637
3638 #endif
3639