Coverage Report

Created: 2020-09-22 08:39

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