Coverage Report

Created: 2018-11-16 02:38

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