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