Coverage Report

Created: 2020-02-15 09:57

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