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