Coverage Report

Created: 2018-07-22 10:17

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