Coverage Report

Created: 2019-02-23 12:57

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