Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/Expr.h
Line
Count
Source (jump to first uncovered line)
1
//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
//  This file defines the Expr interface and subclasses.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_EXPR_H
15
#define LLVM_CLANG_AST_EXPR_H
16
17
#include "clang/AST/APValue.h"
18
#include "clang/AST/ASTVector.h"
19
#include "clang/AST/Decl.h"
20
#include "clang/AST/DeclAccessPair.h"
21
#include "clang/AST/OperationKinds.h"
22
#include "clang/AST/Stmt.h"
23
#include "clang/AST/TemplateBase.h"
24
#include "clang/AST/Type.h"
25
#include "clang/Basic/CharInfo.h"
26
#include "clang/Basic/LangOptions.h"
27
#include "clang/Basic/SyncScope.h"
28
#include "clang/Basic/TypeTraits.h"
29
#include "llvm/ADT/APFloat.h"
30
#include "llvm/ADT/APSInt.h"
31
#include "llvm/ADT/SmallVector.h"
32
#include "llvm/ADT/StringRef.h"
33
#include "llvm/Support/AtomicOrdering.h"
34
#include "llvm/Support/Compiler.h"
35
#include "llvm/Support/TrailingObjects.h"
36
37
namespace clang {
38
  class APValue;
39
  class ASTContext;
40
  class BlockDecl;
41
  class CXXBaseSpecifier;
42
  class CXXMemberCallExpr;
43
  class CXXOperatorCallExpr;
44
  class CastExpr;
45
  class Decl;
46
  class IdentifierInfo;
47
  class MaterializeTemporaryExpr;
48
  class NamedDecl;
49
  class ObjCPropertyRefExpr;
50
  class OpaqueValueExpr;
51
  class ParmVarDecl;
52
  class StringLiteral;
53
  class TargetInfo;
54
  class ValueDecl;
55
56
/// A simple array of base specifiers.
57
typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
58
59
/// An adjustment to be made to the temporary created when emitting a
60
/// reference binding, which accesses a particular subobject of that temporary.
61
struct SubobjectAdjustment {
62
  enum {
63
    DerivedToBaseAdjustment,
64
    FieldAdjustment,
65
    MemberPointerAdjustment
66
  } Kind;
67
68
  struct DTB {
69
    const CastExpr *BasePath;
70
    const CXXRecordDecl *DerivedClass;
71
  };
72
73
  struct P {
74
    const MemberPointerType *MPT;
75
    Expr *RHS;
76
  };
77
78
  union {
79
    struct DTB DerivedToBase;
80
    FieldDecl *Field;
81
    struct P Ptr;
82
  };
83
84
  SubobjectAdjustment(const CastExpr *BasePath,
85
                      const CXXRecordDecl *DerivedClass)
86
4.06k
    : Kind(DerivedToBaseAdjustment) {
87
4.06k
    DerivedToBase.BasePath = BasePath;
88
4.06k
    DerivedToBase.DerivedClass = DerivedClass;
89
4.06k
  }
90
91
  SubobjectAdjustment(FieldDecl *Field)
92
53.7k
    : Kind(FieldAdjustment) {
93
53.7k
    this->Field = Field;
94
53.7k
  }
95
96
  SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS)
97
89
    : Kind(MemberPointerAdjustment) {
98
89
    this->Ptr.MPT = MPT;
99
89
    this->Ptr.RHS = RHS;
100
89
  }
101
};
102
103
/// This represents one expression.  Note that Expr's are subclasses of Stmt.
104
/// This allows an expression to be transparently used any place a Stmt is
105
/// required.
106
class Expr : public Stmt {
107
  QualType TR;
108
109
protected:
110
  Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
111
       bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
112
    : Stmt(SC)
113
91.1M
  {
114
91.1M
    ExprBits.TypeDependent = TD;
115
91.1M
    ExprBits.ValueDependent = VD;
116
91.1M
    ExprBits.InstantiationDependent = ID;
117
91.1M
    ExprBits.ValueKind = VK;
118
91.1M
    ExprBits.ObjectKind = OK;
119
91.1M
    assert(ExprBits.ObjectKind == OK && "truncated kind");
120
91.1M
    ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
121
91.1M
    setType(T);
122
91.1M
  }
123
124
  /// Construct an empty expression.
125
484k
  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
126
127
public:
128
850M
  QualType getType() const { return TR; }
129
95.7M
  void setType(QualType t) {
130
95.7M
    // In C++, the type of an expression is always adjusted so that it
131
95.7M
    // will not have reference type (C++ [expr]p6). Use
132
95.7M
    // QualType::getNonReferenceType() to retrieve the non-reference
133
95.7M
    // type. Additionally, inspect Expr::isLvalue to determine whether
134
95.7M
    // an expression that is adjusted in this manner should be
135
95.7M
    // considered an lvalue.
136
95.7M
    assert((t.isNull() || !t->isReferenceType()) &&
137
95.7M
           "Expressions can't have reference type");
138
95.7M
139
95.7M
    TR = t;
140
95.7M
  }
141
142
  /// isValueDependent - Determines whether this expression is
143
  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
144
  /// array bound of "Chars" in the following example is
145
  /// value-dependent.
146
  /// @code
147
  /// template<int Size, char (&Chars)[Size]> struct meta_string;
148
  /// @endcode
149
166M
  bool isValueDependent() const { return ExprBits.ValueDependent; }
150
151
  /// Set whether this expression is value-dependent or not.
152
505k
  void setValueDependent(bool VD) {
153
505k
    ExprBits.ValueDependent = VD;
154
505k
  }
155
156
  /// isTypeDependent - Determines whether this expression is
157
  /// type-dependent (C++ [temp.dep.expr]), which means that its type
158
  /// could change from one template instantiation to the next. For
159
  /// example, the expressions "x" and "x + y" are type-dependent in
160
  /// the following code, but "y" is not type-dependent:
161
  /// @code
162
  /// template<typename T>
163
  /// void add(T x, int y) {
164
  ///   x + y;
165
  /// }
166
  /// @endcode
167
168M
  bool isTypeDependent() const { return ExprBits.TypeDependent; }
168
169
  /// Set whether this expression is type-dependent or not.
170
487k
  void setTypeDependent(bool TD) {
171
487k
    ExprBits.TypeDependent = TD;
172
487k
  }
173
174
  /// Whether this expression is instantiation-dependent, meaning that
175
  /// it depends in some way on a template parameter, even if neither its type
176
  /// nor (constant) value can change due to the template instantiation.
177
  ///
178
  /// In the following example, the expression \c sizeof(sizeof(T() + T())) is
179
  /// instantiation-dependent (since it involves a template parameter \c T), but
180
  /// is neither type- nor value-dependent, since the type of the inner
181
  /// \c sizeof is known (\c std::size_t) and therefore the size of the outer
182
  /// \c sizeof is known.
183
  ///
184
  /// \code
185
  /// template<typename T>
186
  /// void f(T x, T y) {
187
  ///   sizeof(sizeof(T() + T());
188
  /// }
189
  /// \endcode
190
  ///
191
91.4M
  bool isInstantiationDependent() const {
192
91.4M
    return ExprBits.InstantiationDependent;
193
91.4M
  }
194
195
  /// Set whether this expression is instantiation-dependent or not.
196
505k
  void setInstantiationDependent(bool ID) {
197
505k
    ExprBits.InstantiationDependent = ID;
198
505k
  }
199
200
  /// Whether this expression contains an unexpanded parameter
201
  /// pack (for C++11 variadic templates).
202
  ///
203
  /// Given the following function template:
204
  ///
205
  /// \code
206
  /// template<typename F, typename ...Types>
207
  /// void forward(const F &f, Types &&...args) {
208
  ///   f(static_cast<Types&&>(args)...);
209
  /// }
210
  /// \endcode
211
  ///
212
  /// The expressions \c args and \c static_cast<Types&&>(args) both
213
  /// contain parameter packs.
214
95.3M
  bool containsUnexpandedParameterPack() const {
215
95.3M
    return ExprBits.ContainsUnexpandedParameterPack;
216
95.3M
  }
217
218
  /// Set the bit that describes whether this expression
219
  /// contains an unexpanded parameter pack.
220
2.21k
  void setContainsUnexpandedParameterPack(bool PP = true) {
221
2.21k
    ExprBits.ContainsUnexpandedParameterPack = PP;
222
2.21k
  }
223
224
  /// getExprLoc - Return the preferred location for the arrow when diagnosing
225
  /// a problem with a generic expression.
226
  SourceLocation getExprLoc() const LLVM_READONLY;
227
228
  /// isUnusedResultAWarning - Return true if this immediate expression should
229
  /// be warned about if the result is unused.  If so, fill in expr, location,
230
  /// and ranges with expr to warn on and source locations/ranges appropriate
231
  /// for a warning.
232
  bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc,
233
                              SourceRange &R1, SourceRange &R2,
234
                              ASTContext &Ctx) const;
235
236
  /// isLValue - True if this expression is an "l-value" according to
237
  /// the rules of the current language.  C and C++ give somewhat
238
  /// different rules for this concept, but in general, the result of
239
  /// an l-value expression identifies a specific object whereas the
240
  /// result of an r-value expression is a value detached from any
241
  /// specific storage.
242
  ///
243
  /// C++11 divides the concept of "r-value" into pure r-values
244
  /// ("pr-values") and so-called expiring values ("x-values"), which
245
  /// identify specific objects that can be safely cannibalized for
246
  /// their resources.  This is an unfortunate abuse of terminology on
247
  /// the part of the C++ committee.  In Clang, when we say "r-value",
248
  /// we generally mean a pr-value.
249
853k
  bool isLValue() const { return getValueKind() == VK_LValue; }
250
36.5M
  bool isRValue() const { return getValueKind() == VK_RValue; }
251
521
  bool isXValue() const { return getValueKind() == VK_XValue; }
252
98.8M
  bool isGLValue() const { return getValueKind() != VK_RValue; }
253
254
  enum LValueClassification {
255
    LV_Valid,
256
    LV_NotObjectType,
257
    LV_IncompleteVoidType,
258
    LV_DuplicateVectorComponents,
259
    LV_InvalidExpression,
260
    LV_InvalidMessageExpression,
261
    LV_MemberFunction,
262
    LV_SubObjCPropertySetting,
263
    LV_ClassTemporary,
264
    LV_ArrayTemporary
265
  };
266
  /// Reasons why an expression might not be an l-value.
267
  LValueClassification ClassifyLValue(ASTContext &Ctx) const;
268
269
  enum isModifiableLvalueResult {
270
    MLV_Valid,
271
    MLV_NotObjectType,
272
    MLV_IncompleteVoidType,
273
    MLV_DuplicateVectorComponents,
274
    MLV_InvalidExpression,
275
    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
276
    MLV_IncompleteType,
277
    MLV_ConstQualified,
278
    MLV_ConstQualifiedField,
279
    MLV_ConstAddrSpace,
280
    MLV_ArrayType,
281
    MLV_NoSetterProperty,
282
    MLV_MemberFunction,
283
    MLV_SubObjCPropertySetting,
284
    MLV_InvalidMessageExpression,
285
    MLV_ClassTemporary,
286
    MLV_ArrayTemporary
287
  };
288
  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
289
  /// does not have an incomplete type, does not have a const-qualified type,
290
  /// and if it is a structure or union, does not have any member (including,
291
  /// recursively, any member or element of all contained aggregates or unions)
292
  /// with a const-qualified type.
293
  ///
294
  /// \param Loc [in,out] - A source location which *may* be filled
295
  /// in with the location of the expression making this a
296
  /// non-modifiable lvalue, if specified.
297
  isModifiableLvalueResult
298
  isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc = nullptr) const;
299
300
  /// The return type of classify(). Represents the C++11 expression
301
  ///        taxonomy.
302
  class Classification {
303
  public:
304
    /// The various classification results. Most of these mean prvalue.
305
    enum Kinds {
306
      CL_LValue,
307
      CL_XValue,
308
      CL_Function, // Functions cannot be lvalues in C.
309
      CL_Void, // Void cannot be an lvalue in C.
310
      CL_AddressableVoid, // Void expression whose address can be taken in C.
311
      CL_DuplicateVectorComponents, // A vector shuffle with dupes.
312
      CL_MemberFunction, // An expression referring to a member function
313
      CL_SubObjCPropertySetting,
314
      CL_ClassTemporary, // A temporary of class type, or subobject thereof.
315
      CL_ArrayTemporary, // A temporary of array type.
316
      CL_ObjCMessageRValue, // ObjC message is an rvalue
317
      CL_PRValue // A prvalue for any other reason, of any other type
318
    };
319
    /// The results of modification testing.
320
    enum ModifiableType {
321
      CM_Untested, // testModifiable was false.
322
      CM_Modifiable,
323
      CM_RValue, // Not modifiable because it's an rvalue
324
      CM_Function, // Not modifiable because it's a function; C++ only
325
      CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
326
      CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
327
      CM_ConstQualified,
328
      CM_ConstQualifiedField,
329
      CM_ConstAddrSpace,
330
      CM_ArrayType,
331
      CM_IncompleteType
332
    };
333
334
  private:
335
    friend class Expr;
336
337
    unsigned short Kind;
338
    unsigned short Modifiable;
339
340
    explicit Classification(Kinds k, ModifiableType m)
341
      : Kind(k), Modifiable(m)
342
12.4M
    {}
343
344
  public:
345
1.29M
    Classification() {}
346
347
2.08M
    Kinds getKind() const { return static_cast<Kinds>(Kind); }
348
1.89M
    ModifiableType getModifiable() const {
349
1.89M
      assert(Modifiable != CM_Untested && "Did not test for modifiability.");
350
1.89M
      return static_cast<ModifiableType>(Modifiable);
351
1.89M
    }
352
7.03M
    bool isLValue() const { return Kind == CL_LValue; }
353
885k
    bool isXValue() const { return Kind == CL_XValue; }
354
0
    bool isGLValue() const { return Kind <= CL_XValue; }
355
957k
    bool isPRValue() const { return Kind >= CL_Function; }
356
2.78M
    bool isRValue() const { return Kind >= CL_XValue; }
357
0
    bool isModifiable() const { return getModifiable() == CM_Modifiable; }
358
359
    /// Create a simple, modifiably lvalue
360
411k
    static Classification makeSimpleLValue() {
361
411k
      return Classification(CL_LValue, CM_Modifiable);
362
411k
    }
363
364
  };
365
  /// Classify - Classify this expression according to the C++11
366
  ///        expression taxonomy.
367
  ///
368
  /// C++11 defines ([basic.lval]) a new taxonomy of expressions to replace the
369
  /// old lvalue vs rvalue. This function determines the type of expression this
370
  /// is. There are three expression types:
371
  /// - lvalues are classical lvalues as in C++03.
372
  /// - prvalues are equivalent to rvalues in C++03.
373
  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
374
  ///   function returning an rvalue reference.
375
  /// lvalues and xvalues are collectively referred to as glvalues, while
376
  /// prvalues and xvalues together form rvalues.
377
10.1M
  Classification Classify(ASTContext &Ctx) const {
378
10.1M
    return ClassifyImpl(Ctx, nullptr);
379
10.1M
  }
380
381
  /// ClassifyModifiable - Classify this expression according to the
382
  ///        C++11 expression taxonomy, and see if it is valid on the left side
383
  ///        of an assignment.
384
  ///
385
  /// This function extends classify in that it also tests whether the
386
  /// expression is modifiable (C99 6.3.2.1p1).
387
  /// \param Loc A source location that might be filled with a relevant location
388
  ///            if the expression is not modifiable.
389
1.89M
  Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
390
1.89M
    return ClassifyImpl(Ctx, &Loc);
391
1.89M
  }
392
393
  /// getValueKindForType - Given a formal return or parameter type,
394
  /// give its value kind.
395
8.04M
  static ExprValueKind getValueKindForType(QualType T) {
396
8.04M
    if (const ReferenceType *RT = T->getAs<ReferenceType>())
397
467k
      return (isa<LValueReferenceType>(RT)
398
467k
                ? 
VK_LValue349k
399
467k
                : (RT->getPointeeType()->isFunctionType()
400
117k
                     ? 
VK_LValue3
:
VK_XValue117k
));
401
7.57M
    return VK_RValue;
402
7.57M
  }
403
404
  /// getValueKind - The value kind that this expression produces.
405
146M
  ExprValueKind getValueKind() const {
406
146M
    return static_cast<ExprValueKind>(ExprBits.ValueKind);
407
146M
  }
408
409
  /// getObjectKind - The object kind that this expression produces.
410
  /// Object kinds are meaningful only for expressions that yield an
411
  /// l-value or x-value.
412
9.81M
  ExprObjectKind getObjectKind() const {
413
9.81M
    return static_cast<ExprObjectKind>(ExprBits.ObjectKind);
414
9.81M
  }
415
416
18.6k
  bool isOrdinaryOrBitFieldObject() const {
417
18.6k
    ExprObjectKind OK = getObjectKind();
418
18.6k
    return (OK == OK_Ordinary || 
OK == OK_BitField46
);
419
18.6k
  }
420
421
  /// setValueKind - Set the value kind produced by this expression.
422
3.34M
  void setValueKind(ExprValueKind Cat) { ExprBits.ValueKind = Cat; }
423
424
  /// setObjectKind - Set the object kind produced by this expression.
425
487k
  void setObjectKind(ExprObjectKind Cat) { ExprBits.ObjectKind = Cat; }
426
427
private:
428
  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
429
430
public:
431
432
  /// Returns true if this expression is a gl-value that
433
  /// potentially refers to a bit-field.
434
  ///
435
  /// In C++, whether a gl-value refers to a bitfield is essentially
436
  /// an aspect of the value-kind type system.
437
546k
  bool refersToBitField() const { return getObjectKind() == OK_BitField; }
438
439
  /// If this expression refers to a bit-field, retrieve the
440
  /// declaration of that bit-field.
441
  ///
442
  /// Note that this returns a non-null pointer in subtly different
443
  /// places than refersToBitField returns true.  In particular, this can
444
  /// return a non-null pointer even for r-values loaded from
445
  /// bit-fields, but it will return null for a conditional bit-field.
446
  FieldDecl *getSourceBitField();
447
448
385k
  const FieldDecl *getSourceBitField() const {
449
385k
    return const_cast<Expr*>(this)->getSourceBitField();
450
385k
  }
451
452
  Decl *getReferencedDeclOfCallee();
453
4.87k
  const Decl *getReferencedDeclOfCallee() const {
454
4.87k
    return const_cast<Expr*>(this)->getReferencedDeclOfCallee();
455
4.87k
  }
456
457
  /// If this expression is an l-value for an Objective C
458
  /// property, find the underlying property reference expression.
459
  const ObjCPropertyRefExpr *getObjCProperty() const;
460
461
  /// Check if this expression is the ObjC 'self' implicit parameter.
462
  bool isObjCSelfExpr() const;
463
464
  /// Returns whether this expression refers to a vector element.
465
  bool refersToVectorElement() const;
466
467
  /// Returns whether this expression refers to a global register
468
  /// variable.
469
  bool refersToGlobalRegisterVar() const;
470
471
  /// Returns whether this expression has a placeholder type.
472
4.25M
  bool hasPlaceholderType() const {
473
4.25M
    return getType()->isPlaceholderType();
474
4.25M
  }
475
476
  /// Returns whether this expression has a specific placeholder type.
477
6.34k
  bool hasPlaceholderType(BuiltinType::Kind K) const {
478
6.34k
    assert(BuiltinType::isPlaceholderTypeKind(K));
479
6.34k
    if (const BuiltinType *BT = dyn_cast<BuiltinType>(getType()))
480
3.30k
      return BT->getKind() == K;
481
3.04k
    return false;
482
3.04k
  }
483
484
  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
485
  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
486
  /// but also int expressions which are produced by things like comparisons in
487
  /// C.
488
  bool isKnownToHaveBooleanValue() const;
489
490
  /// isIntegerConstantExpr - Return true if this expression is a valid integer
491
  /// constant expression, and, if so, return its value in Result.  If not a
492
  /// valid i-c-e, return false and fill in Loc (if specified) with the location
493
  /// of the invalid expression.
494
  ///
495
  /// Note: This does not perform the implicit conversions required by C++11
496
  /// [expr.const]p5.
497
  bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx,
498
                             SourceLocation *Loc = nullptr,
499
                             bool isEvaluated = true) const;
500
  bool isIntegerConstantExpr(const ASTContext &Ctx,
501
                             SourceLocation *Loc = nullptr) const;
502
503
  /// isCXX98IntegralConstantExpr - Return true if this expression is an
504
  /// integral constant expression in C++98. Can only be used in C++.
505
  bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const;
506
507
  /// isCXX11ConstantExpr - Return true if this expression is a constant
508
  /// expression in C++11. Can only be used in C++.
509
  ///
510
  /// Note: This does not perform the implicit conversions required by C++11
511
  /// [expr.const]p5.
512
  bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr,
513
                           SourceLocation *Loc = nullptr) const;
514
515
  /// isPotentialConstantExpr - Return true if this function's definition
516
  /// might be usable in a constant expression in C++11, if it were marked
517
  /// constexpr. Return false if the function can never produce a constant
518
  /// expression, along with diagnostics describing why not.
519
  static bool isPotentialConstantExpr(const FunctionDecl *FD,
520
                                      SmallVectorImpl<
521
                                        PartialDiagnosticAt> &Diags);
522
523
  /// isPotentialConstantExprUnevaluted - Return true if this expression might
524
  /// be usable in a constant expression in C++11 in an unevaluated context, if
525
  /// it were in function FD marked constexpr. Return false if the function can
526
  /// never produce a constant expression, along with diagnostics describing
527
  /// why not.
528
  static bool isPotentialConstantExprUnevaluated(Expr *E,
529
                                                 const FunctionDecl *FD,
530
                                                 SmallVectorImpl<
531
                                                   PartialDiagnosticAt> &Diags);
532
533
  /// isConstantInitializer - Returns true if this expression can be emitted to
534
  /// IR as a constant, and thus can be used as a constant initializer in C.
535
  /// If this expression is not constant and Culprit is non-null,
536
  /// it is used to store the address of first non constant expr.
537
  bool isConstantInitializer(ASTContext &Ctx, bool ForRef,
538
                             const Expr **Culprit = nullptr) const;
539
540
  /// EvalStatus is a struct with detailed info about an evaluation in progress.
541
  struct EvalStatus {
542
    /// Whether the evaluated expression has side effects.
543
    /// For example, (f() && 0) can be folded, but it still has side effects.
544
    bool HasSideEffects;
545
546
    /// Whether the evaluation hit undefined behavior.
547
    /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior.
548
    /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
549
    bool HasUndefinedBehavior;
550
551
    /// Diag - If this is non-null, it will be filled in with a stack of notes
552
    /// indicating why evaluation failed (or why it failed to produce a constant
553
    /// expression).
554
    /// If the expression is unfoldable, the notes will indicate why it's not
555
    /// foldable. If the expression is foldable, but not a constant expression,
556
    /// the notes will describes why it isn't a constant expression. If the
557
    /// expression *is* a constant expression, no notes will be produced.
558
    SmallVectorImpl<PartialDiagnosticAt> *Diag;
559
560
    EvalStatus()
561
29.9M
        : HasSideEffects(false), HasUndefinedBehavior(false), Diag(nullptr) {}
562
563
    // hasSideEffects - Return true if the evaluated expression has
564
    // side effects.
565
1.94k
    bool hasSideEffects() const {
566
1.94k
      return HasSideEffects;
567
1.94k
    }
568
  };
569
570
  /// EvalResult is a struct with detailed info about an evaluated expression.
571
  struct EvalResult : EvalStatus {
572
    /// Val - This is the value the expression can be folded to.
573
    APValue Val;
574
575
    // isGlobalLValue - Return true if the evaluated lvalue expression
576
    // is global.
577
    bool isGlobalLValue() const;
578
  };
579
580
  /// EvaluateAsRValue - Return true if this is a constant which we can fold to
581
  /// an rvalue using any crazy technique (that has nothing to do with language
582
  /// standards) that we want to, even if the expression has side-effects. If
583
  /// this function returns true, it returns the folded constant in Result. If
584
  /// the expression is a glvalue, an lvalue-to-rvalue conversion will be
585
  /// applied.
586
  bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const;
587
588
  /// EvaluateAsBooleanCondition - Return true if this is a constant
589
  /// which we can fold and convert to a boolean condition using
590
  /// any crazy technique that we want to, even if the expression has
591
  /// side-effects.
592
  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const;
593
594
  enum SideEffectsKind {
595
    SE_NoSideEffects,          ///< Strictly evaluate the expression.
596
    SE_AllowUndefinedBehavior, ///< Allow UB that we can give a value, but not
597
                               ///< arbitrary unmodeled side effects.
598
    SE_AllowSideEffects        ///< Allow any unmodeled side effect.
599
  };
600
601
  /// EvaluateAsInt - Return true if this is a constant which we can fold and
602
  /// convert to an integer, using any crazy technique that we want to.
603
  bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx,
604
                     SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
605
606
  /// EvaluateAsFloat - Return true if this is a constant which we can fold and
607
  /// convert to a floating point value, using any crazy technique that we
608
  /// want to.
609
  bool
610
  EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx,
611
                  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
612
613
  /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
614
  /// constant folded without side-effects, but discard the result.
615
  bool isEvaluatable(const ASTContext &Ctx,
616
                     SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
617
618
  /// HasSideEffects - This routine returns true for all those expressions
619
  /// which have any effect other than producing a value. Example is a function
620
  /// call, volatile variable read, or throwing an exception. If
621
  /// IncludePossibleEffects is false, this call treats certain expressions with
622
  /// potential side effects (such as function call-like expressions,
623
  /// instantiation-dependent expressions, or invocations from a macro) as not
624
  /// having side effects.
625
  bool HasSideEffects(const ASTContext &Ctx,
626
                      bool IncludePossibleEffects = true) const;
627
628
  /// Determine whether this expression involves a call to any function
629
  /// that is not trivial.
630
  bool hasNonTrivialCall(const ASTContext &Ctx) const;
631
632
  /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
633
  /// integer. This must be called on an expression that constant folds to an
634
  /// integer.
635
  llvm::APSInt EvaluateKnownConstInt(
636
      const ASTContext &Ctx,
637
      SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const;
638
639
  llvm::APSInt EvaluateKnownConstIntCheckOverflow(
640
      const ASTContext &Ctx,
641
      SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr) const;
642
643
  void EvaluateForOverflow(const ASTContext &Ctx) const;
644
645
  /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
646
  /// lvalue with link time known address, with no side-effects.
647
  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
648
649
  /// EvaluateAsInitializer - Evaluate an expression as if it were the
650
  /// initializer of the given declaration. Returns true if the initializer
651
  /// can be folded to a constant, and produces any relevant notes. In C++11,
652
  /// notes will be produced if the expression is not a constant expression.
653
  bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
654
                             const VarDecl *VD,
655
                             SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
656
657
  /// EvaluateWithSubstitution - Evaluate an expression as if from the context
658
  /// of a call to the given function with the given arguments, inside an
659
  /// unevaluated context. Returns true if the expression could be folded to a
660
  /// constant.
661
  bool EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx,
662
                                const FunctionDecl *Callee,
663
                                ArrayRef<const Expr*> Args,
664
                                const Expr *This = nullptr) const;
665
666
  /// Indicates how the constant expression will be used.
667
  enum ConstExprUsage { EvaluateForCodeGen, EvaluateForMangling };
668
669
  /// Evaluate an expression that is required to be a constant expression.
670
  bool EvaluateAsConstantExpr(EvalResult &Result, ConstExprUsage Usage,
671
                              const ASTContext &Ctx) const;
672
673
  /// If the current Expr is a pointer, this will try to statically
674
  /// determine the number of bytes available where the pointer is pointing.
675
  /// Returns true if all of the above holds and we were able to figure out the
676
  /// size, false otherwise.
677
  ///
678
  /// \param Type - How to evaluate the size of the Expr, as defined by the
679
  /// "type" parameter of __builtin_object_size
680
  bool tryEvaluateObjectSize(uint64_t &Result, ASTContext &Ctx,
681
                             unsigned Type) const;
682
683
  /// Enumeration used to describe the kind of Null pointer constant
684
  /// returned from \c isNullPointerConstant().
685
  enum NullPointerConstantKind {
686
    /// Expression is not a Null pointer constant.
687
    NPCK_NotNull = 0,
688
689
    /// Expression is a Null pointer constant built from a zero integer
690
    /// expression that is not a simple, possibly parenthesized, zero literal.
691
    /// C++ Core Issue 903 will classify these expressions as "not pointers"
692
    /// once it is adopted.
693
    /// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#903
694
    NPCK_ZeroExpression,
695
696
    /// Expression is a Null pointer constant built from a literal zero.
697
    NPCK_ZeroLiteral,
698
699
    /// Expression is a C++11 nullptr.
700
    NPCK_CXX11_nullptr,
701
702
    /// Expression is a GNU-style __null constant.
703
    NPCK_GNUNull
704
  };
705
706
  /// Enumeration used to describe how \c isNullPointerConstant()
707
  /// should cope with value-dependent expressions.
708
  enum NullPointerConstantValueDependence {
709
    /// Specifies that the expression should never be value-dependent.
710
    NPC_NeverValueDependent = 0,
711
712
    /// Specifies that a value-dependent expression of integral or
713
    /// dependent type should be considered a null pointer constant.
714
    NPC_ValueDependentIsNull,
715
716
    /// Specifies that a value-dependent expression should be considered
717
    /// to never be a null pointer constant.
718
    NPC_ValueDependentIsNotNull
719
  };
720
721
  /// isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to
722
  /// a Null pointer constant. The return value can further distinguish the
723
  /// kind of NULL pointer constant that was detected.
724
  NullPointerConstantKind isNullPointerConstant(
725
      ASTContext &Ctx,
726
      NullPointerConstantValueDependence NPC) const;
727
728
  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
729
  /// write barrier.
730
  bool isOBJCGCCandidate(ASTContext &Ctx) const;
731
732
  /// Returns true if this expression is a bound member function.
733
  bool isBoundMemberFunction(ASTContext &Ctx) const;
734
735
  /// Given an expression of bound-member type, find the type
736
  /// of the member.  Returns null if this is an *overloaded* bound
737
  /// member expression.
738
  static QualType findBoundMemberType(const Expr *expr);
739
740
  /// IgnoreImpCasts - Skip past any implicit casts which might
741
  /// surround this expression.  Only skips ImplicitCastExprs.
742
  Expr *IgnoreImpCasts() LLVM_READONLY;
743
744
  /// IgnoreImplicit - Skip past any implicit AST nodes which might
745
  /// surround this expression.
746
411k
  Expr *IgnoreImplicit() LLVM_READONLY {
747
411k
    return cast<Expr>(Stmt::IgnoreImplicit());
748
411k
  }
749
750
27.9k
  const Expr *IgnoreImplicit() const LLVM_READONLY {
751
27.9k
    return const_cast<Expr*>(this)->IgnoreImplicit();
752
27.9k
  }
753
754
  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
755
  ///  its subexpression.  If that subexpression is also a ParenExpr,
756
  ///  then this method recursively returns its subexpression, and so forth.
757
  ///  Otherwise, the method returns the current Expr.
758
  Expr *IgnoreParens() LLVM_READONLY;
759
760
  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
761
  /// or CastExprs, returning their operand.
762
  Expr *IgnoreParenCasts() LLVM_READONLY;
763
764
  /// Ignore casts.  Strip off any CastExprs, returning their operand.
765
  Expr *IgnoreCasts() LLVM_READONLY;
766
767
  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off
768
  /// any ParenExpr or ImplicitCastExprs, returning their operand.
769
  Expr *IgnoreParenImpCasts() LLVM_READONLY;
770
771
  /// IgnoreConversionOperator - Ignore conversion operator. If this Expr is a
772
  /// call to a conversion operator, return the argument.
773
  Expr *IgnoreConversionOperator() LLVM_READONLY;
774
775
0
  const Expr *IgnoreConversionOperator() const LLVM_READONLY {
776
0
    return const_cast<Expr*>(this)->IgnoreConversionOperator();
777
0
  }
778
779
33.1M
  const Expr *IgnoreParenImpCasts() const LLVM_READONLY {
780
33.1M
    return const_cast<Expr*>(this)->IgnoreParenImpCasts();
781
33.1M
  }
782
783
  /// Ignore parentheses and lvalue casts.  Strip off any ParenExpr and
784
  /// CastExprs that represent lvalue casts, returning their operand.
785
  Expr *IgnoreParenLValueCasts() LLVM_READONLY;
786
787
1.36k
  const Expr *IgnoreParenLValueCasts() const LLVM_READONLY {
788
1.36k
    return const_cast<Expr*>(this)->IgnoreParenLValueCasts();
789
1.36k
  }
790
791
  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
792
  /// value (including ptr->int casts of the same size).  Strip off any
793
  /// ParenExpr or CastExprs, returning their operand.
794
  Expr *IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY;
795
796
  /// Ignore parentheses and derived-to-base casts.
797
  Expr *ignoreParenBaseCasts() LLVM_READONLY;
798
799
102k
  const Expr *ignoreParenBaseCasts() const LLVM_READONLY {
800
102k
    return const_cast<Expr*>(this)->ignoreParenBaseCasts();
801
102k
  }
802
803
  /// Determine whether this expression is a default function argument.
804
  ///
805
  /// Default arguments are implicitly generated in the abstract syntax tree
806
  /// by semantic analysis for function calls, object constructions, etc. in
807
  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
808
  /// this routine also looks through any implicit casts to determine whether
809
  /// the expression is a default argument.
810
  bool isDefaultArgument() const;
811
812
  /// Determine whether the result of this expression is a
813
  /// temporary object of the given class type.
814
  bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const;
815
816
  /// Whether this expression is an implicit reference to 'this' in C++.
817
  bool isImplicitCXXThis() const;
818
819
984k
  const Expr *IgnoreImpCasts() const LLVM_READONLY {
820
984k
    return const_cast<Expr*>(this)->IgnoreImpCasts();
821
984k
  }
822
38.3M
  const Expr *IgnoreParens() const LLVM_READONLY {
823
38.3M
    return const_cast<Expr*>(this)->IgnoreParens();
824
38.3M
  }
825
1.14M
  const Expr *IgnoreParenCasts() const LLVM_READONLY {
826
1.14M
    return const_cast<Expr*>(this)->IgnoreParenCasts();
827
1.14M
  }
828
  /// Strip off casts, but keep parentheses.
829
944
  const Expr *IgnoreCasts() const LLVM_READONLY {
830
944
    return const_cast<Expr*>(this)->IgnoreCasts();
831
944
  }
832
833
2.05M
  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const LLVM_READONLY {
834
2.05M
    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
835
2.05M
  }
836
837
  static bool hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs);
838
839
  /// For an expression of class type or pointer to class type,
840
  /// return the most derived class decl the expression is known to refer to.
841
  ///
842
  /// If this expression is a cast, this method looks through it to find the
843
  /// most derived decl that can be inferred from the expression.
844
  /// This is valid because derived-to-base conversions have undefined
845
  /// behavior if the object isn't dynamically of the derived type.
846
  const CXXRecordDecl *getBestDynamicClassType() const;
847
848
  /// Get the inner expression that determines the best dynamic class.
849
  /// If this is a prvalue, we guarantee that it is of the most-derived type
850
  /// for the object itself.
851
  const Expr *getBestDynamicClassTypeExpr() const;
852
853
  /// Walk outwards from an expression we want to bind a reference to and
854
  /// find the expression whose lifetime needs to be extended. Record
855
  /// the LHSs of comma expressions and adjustments needed along the path.
856
  const Expr *skipRValueSubobjectAdjustments(
857
      SmallVectorImpl<const Expr *> &CommaLHS,
858
      SmallVectorImpl<SubobjectAdjustment> &Adjustments) const;
859
8.54M
  const Expr *skipRValueSubobjectAdjustments() const {
860
8.54M
    SmallVector<const Expr *, 8> CommaLHSs;
861
8.54M
    SmallVector<SubobjectAdjustment, 8> Adjustments;
862
8.54M
    return skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
863
8.54M
  }
864
865
65.0M
  static bool classof(const Stmt *T) {
866
65.0M
    return T->getStmtClass() >= firstExprConstant &&
867
65.0M
           
T->getStmtClass() <= lastExprConstant59.5M
;
868
65.0M
  }
869
};
870
871
//===----------------------------------------------------------------------===//
872
// Wrapper Expressions.
873
//===----------------------------------------------------------------------===//
874
875
/// FullExpr - Represents a "full-expression" node.
876
class FullExpr : public Expr {
877
protected:
878
 Stmt *SubExpr;
879
880
 FullExpr(StmtClass SC, Expr *subexpr)
881
    : Expr(SC, subexpr->getType(),
882
           subexpr->getValueKind(), subexpr->getObjectKind(),
883
           subexpr->isTypeDependent(), subexpr->isValueDependent(),
884
           subexpr->isInstantiationDependent(),
885
2.51M
           subexpr->containsUnexpandedParameterPack()), SubExpr(subexpr) {}
886
  FullExpr(StmtClass SC, EmptyShell Empty)
887
8.89k
    : Expr(SC, Empty) {}
888
public:
889
370k
  const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
890
982k
  Expr *getSubExpr() { return cast<Expr>(SubExpr); }
891
892
  /// As with any mutator of the AST, be very careful when modifying an
893
  /// existing AST to preserve its invariants.
894
7.79k
  void setSubExpr(Expr *E) { SubExpr = E; }
895
896
12.5M
  static bool classof(const Stmt *T) {
897
12.5M
    return T->getStmtClass() >= firstFullExprConstant &&
898
12.5M
           
T->getStmtClass() <= lastFullExprConstant3.03M
;
899
12.5M
  }
900
};
901
902
/// ConstantExpr - An expression that occurs in a constant context.
903
class ConstantExpr : public FullExpr {
904
public:
905
  ConstantExpr(Expr *subexpr)
906
2.39M
    : FullExpr(ConstantExprClass, subexpr) {}
907
908
  /// Build an empty constant expression wrapper.
909
  explicit ConstantExpr(EmptyShell Empty)
910
7.79k
    : FullExpr(ConstantExprClass, Empty) {}
911
912
627k
  SourceLocation getBeginLoc() const LLVM_READONLY {
913
627k
    return SubExpr->getBeginLoc();
914
627k
  }
915
136k
  SourceLocation getEndLoc() const LLVM_READONLY {
916
136k
    return SubExpr->getEndLoc();
917
136k
  }
918
919
177M
  static bool classof(const Stmt *T) {
920
177M
    return T->getStmtClass() == ConstantExprClass;
921
177M
  }
922
923
  // Iterators
924
161k
  child_range children() { return child_range(&SubExpr, &SubExpr+1); }
925
0
  const_child_range children() const {
926
0
    return const_child_range(&SubExpr, &SubExpr + 1);
927
0
  }
928
};
929
930
//===----------------------------------------------------------------------===//
931
// Primary Expressions.
932
//===----------------------------------------------------------------------===//
933
934
/// OpaqueValueExpr - An expression referring to an opaque object of a
935
/// fixed type and value class.  These don't correspond to concrete
936
/// syntax; instead they're used to express operations (usually copy
937
/// operations) on values whose source is generally obvious from
938
/// context.
939
class OpaqueValueExpr : public Expr {
940
  friend class ASTStmtReader;
941
  Expr *SourceExpr;
942
  SourceLocation Loc;
943
944
public:
945
  OpaqueValueExpr(SourceLocation Loc, QualType T, ExprValueKind VK,
946
                  ExprObjectKind OK = OK_Ordinary,
947
                  Expr *SourceExpr = nullptr)
948
    : Expr(OpaqueValueExprClass, T, VK, OK,
949
           T->isDependentType() ||
950
           (SourceExpr && SourceExpr->isTypeDependent()),
951
           T->isDependentType() ||
952
           (SourceExpr && SourceExpr->isValueDependent()),
953
           T->isInstantiationDependentType() ||
954
           (SourceExpr && SourceExpr->isInstantiationDependent()),
955
           false),
956
554k
      SourceExpr(SourceExpr), Loc(Loc) {
957
554k
    setIsUnique(false);
958
554k
  }
959
960
  /// Given an expression which invokes a copy constructor --- i.e.  a
961
  /// CXXConstructExpr, possibly wrapped in an ExprWithCleanups ---
962
  /// find the OpaqueValueExpr that's the source of the construction.
963
  static const OpaqueValueExpr *findInCopyConstruct(const Expr *expr);
964
965
  explicit OpaqueValueExpr(EmptyShell Empty)
966
623
    : Expr(OpaqueValueExprClass, Empty) { }
967
968
  /// Retrieve the location of this expression.
969
623
  SourceLocation getLocation() const { return Loc; }
970
971
479k
  SourceLocation getBeginLoc() const LLVM_READONLY {
972
479k
    return SourceExpr ? 
SourceExpr->getBeginLoc()42.9k
:
Loc436k
;
973
479k
  }
974
8.36k
  SourceLocation getEndLoc() const LLVM_READONLY {
975
8.36k
    return SourceExpr ? 
SourceExpr->getEndLoc()6.28k
:
Loc2.08k
;
976
8.36k
  }
977
25.5k
  SourceLocation getExprLoc() const LLVM_READONLY {
978
25.5k
    if (SourceExpr) 
return SourceExpr->getExprLoc()16.1k
;
979
9.37k
    return Loc;
980
9.37k
  }
981
982
32.1k
  child_range children() {
983
32.1k
    return child_range(child_iterator(), child_iterator());
984
32.1k
  }
985
986
0
  const_child_range children() const {
987
0
    return const_child_range(const_child_iterator(), const_child_iterator());
988
0
  }
989
990
  /// The source expression of an opaque value expression is the
991
  /// expression which originally generated the value.  This is
992
  /// provided as a convenience for analyses that don't wish to
993
  /// precisely model the execution behavior of the program.
994
  ///
995
  /// The source expression is typically set when building the
996
  /// expression which binds the opaque value expression in the first
997
  /// place.
998
22.3k
  Expr *getSourceExpr() const { return SourceExpr; }
999
1000
560k
  void setIsUnique(bool V) {
1001
560k
    assert((!V || SourceExpr) &&
1002
560k
           "unique OVEs are expected to have source expressions");
1003
560k
    OpaqueValueExprBits.IsUnique = V;
1004
560k
  }
1005
1006
1.30k
  bool isUnique() const { return OpaqueValueExprBits.IsUnique; }
1007
1008
7.27M
  static bool classof(const Stmt *T) {
1009
7.27M
    return T->getStmtClass() == OpaqueValueExprClass;
1010
7.27M
  }
1011
};
1012
1013
/// A reference to a declared variable, function, enum, etc.
1014
/// [C99 6.5.1p2]
1015
///
1016
/// This encodes all the information about how a declaration is referenced
1017
/// within an expression.
1018
///
1019
/// There are several optional constructs attached to DeclRefExprs only when
1020
/// they apply in order to conserve memory. These are laid out past the end of
1021
/// the object, and flags in the DeclRefExprBitfield track whether they exist:
1022
///
1023
///   DeclRefExprBits.HasQualifier:
1024
///       Specifies when this declaration reference expression has a C++
1025
///       nested-name-specifier.
1026
///   DeclRefExprBits.HasFoundDecl:
1027
///       Specifies when this declaration reference expression has a record of
1028
///       a NamedDecl (different from the referenced ValueDecl) which was found
1029
///       during name lookup and/or overload resolution.
1030
///   DeclRefExprBits.HasTemplateKWAndArgsInfo:
1031
///       Specifies when this declaration reference expression has an explicit
1032
///       C++ template keyword and/or template argument list.
1033
///   DeclRefExprBits.RefersToEnclosingVariableOrCapture
1034
///       Specifies when this declaration reference expression (validly)
1035
///       refers to an enclosed local or a captured variable.
1036
class DeclRefExpr final
1037
    : public Expr,
1038
      private llvm::TrailingObjects<DeclRefExpr, NestedNameSpecifierLoc,
1039
                                    NamedDecl *, ASTTemplateKWAndArgsInfo,
1040
                                    TemplateArgumentLoc> {
1041
  friend class ASTStmtReader;
1042
  friend class ASTStmtWriter;
1043
  friend TrailingObjects;
1044
1045
  /// The declaration that we are referencing.
1046
  ValueDecl *D;
1047
1048
  /// Provides source/type location info for the declaration name
1049
  /// embedded in D.
1050
  DeclarationNameLoc DNLoc;
1051
1052
1.16M
  size_t numTrailingObjects(OverloadToken<NestedNameSpecifierLoc>) const {
1053
1.16M
    return hasQualifier();
1054
1.16M
  }
1055
1056
846k
  size_t numTrailingObjects(OverloadToken<NamedDecl *>) const {
1057
846k
    return hasFoundDecl();
1058
846k
  }
1059
1060
207k
  size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
1061
207k
    return hasTemplateKWAndArgsInfo();
1062
207k
  }
1063
1064
  /// Test whether there is a distinct FoundDecl attached to the end of
1065
  /// this DRE.
1066
1.69M
  bool hasFoundDecl() const { return DeclRefExprBits.HasFoundDecl; }
1067
1068
  DeclRefExpr(const ASTContext &Ctx, NestedNameSpecifierLoc QualifierLoc,
1069
              SourceLocation TemplateKWLoc, ValueDecl *D,
1070
              bool RefersToEnlosingVariableOrCapture,
1071
              const DeclarationNameInfo &NameInfo, NamedDecl *FoundD,
1072
              const TemplateArgumentListInfo *TemplateArgs, QualType T,
1073
              ExprValueKind VK);
1074
1075
  /// Construct an empty declaration reference expression.
1076
137k
  explicit DeclRefExpr(EmptyShell Empty) : Expr(DeclRefExprClass, Empty) {}
1077
1078
  /// Computes the type- and value-dependence flags for this
1079
  /// declaration reference expression.
1080
  void computeDependence(const ASTContext &Ctx);
1081
1082
public:
1083
  DeclRefExpr(ValueDecl *D, bool RefersToEnclosingVariableOrCapture, QualType T,
1084
              ExprValueKind VK, SourceLocation L,
1085
              const DeclarationNameLoc &LocInfo = DeclarationNameLoc())
1086
      : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false),
1087
1.59M
        D(D), DNLoc(LocInfo) {
1088
1.59M
    DeclRefExprBits.HasQualifier = false;
1089
1.59M
    DeclRefExprBits.HasTemplateKWAndArgsInfo = false;
1090
1.59M
    DeclRefExprBits.HasFoundDecl = false;
1091
1.59M
    DeclRefExprBits.HadMultipleCandidates = false;
1092
1.59M
    DeclRefExprBits.RefersToEnclosingVariableOrCapture =
1093
1.59M
        RefersToEnclosingVariableOrCapture;
1094
1.59M
    DeclRefExprBits.Loc = L;
1095
1.59M
    computeDependence(D->getASTContext());
1096
1.59M
  }
1097
1098
  static DeclRefExpr *
1099
  Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1100
         SourceLocation TemplateKWLoc, ValueDecl *D,
1101
         bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc,
1102
         QualType T, ExprValueKind VK, NamedDecl *FoundD = nullptr,
1103
         const TemplateArgumentListInfo *TemplateArgs = nullptr);
1104
1105
  static DeclRefExpr *
1106
  Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc,
1107
         SourceLocation TemplateKWLoc, ValueDecl *D,
1108
         bool RefersToEnclosingVariableOrCapture,
1109
         const DeclarationNameInfo &NameInfo, QualType T, ExprValueKind VK,
1110
         NamedDecl *FoundD = nullptr,
1111
         const TemplateArgumentListInfo *TemplateArgs = nullptr);
1112
1113
  /// Construct an empty declaration reference expression.
1114
  static DeclRefExpr *CreateEmpty(const ASTContext &Context, bool HasQualifier,
1115
                                  bool HasFoundDecl,
1116
                                  bool HasTemplateKWAndArgsInfo,
1117
                                  unsigned NumTemplateArgs);
1118
1119
119M
  ValueDecl *getDecl() { return D; }
1120
162M
  const ValueDecl *getDecl() const { return D; }
1121
137k
  void setDecl(ValueDecl *NewD) { D = NewD; }
1122
1123
113M
  DeclarationNameInfo getNameInfo() const {
1124
113M
    return DeclarationNameInfo(getDecl()->getDeclName(), getLocation(), DNLoc);
1125
113M
  }
1126
1127
134M
  SourceLocation getLocation() const { return DeclRefExprBits.Loc; }
1128
137k
  void setLocation(SourceLocation L) { DeclRefExprBits.Loc = L; }
1129
  SourceLocation getBeginLoc() const LLVM_READONLY;
1130
  SourceLocation getEndLoc() const LLVM_READONLY;
1131
1132
  /// Determine whether this declaration reference was preceded by a
1133
  /// C++ nested-name-specifier, e.g., \c N::foo.
1134
127M
  bool hasQualifier() const { return DeclRefExprBits.HasQualifier; }
1135
1136
  /// If the name was qualified, retrieves the nested-name-specifier
1137
  /// that precedes the name, with source-location information.
1138
12.4M
  NestedNameSpecifierLoc getQualifierLoc() const {
1139
12.4M
    if (!hasQualifier())
1140
3.44M
      return NestedNameSpecifierLoc();
1141
8.98M
    return *getTrailingObjects<NestedNameSpecifierLoc>();
1142
8.98M
  }
1143
1144
  /// If the name was qualified, retrieves the nested-name-specifier
1145
  /// that precedes the name. Otherwise, returns NULL.
1146
562k
  NestedNameSpecifier *getQualifier() const {
1147
562k
    return getQualifierLoc().getNestedNameSpecifier();
1148
562k
  }
1149
1150
  /// Get the NamedDecl through which this reference occurred.
1151
  ///
1152
  /// This Decl may be different from the ValueDecl actually referred to in the
1153
  /// presence of using declarations, etc. It always returns non-NULL, and may
1154
  /// simple return the ValueDecl when appropriate.
1155
1156
708k
  NamedDecl *getFoundDecl() {
1157
708k
    return hasFoundDecl() ? 
*getTrailingObjects<NamedDecl *>()2.79k
:
D705k
;
1158
708k
  }
1159
1160
  /// Get the NamedDecl through which this reference occurred.
1161
  /// See non-const variant.
1162
1.59k
  const NamedDecl *getFoundDecl() const {
1163
1.59k
    return hasFoundDecl() ? 
*getTrailingObjects<NamedDecl *>()166
:
D1.42k
;
1164
1.59k
  }
1165
1166
12.6M
  bool hasTemplateKWAndArgsInfo() const {
1167
12.6M
    return DeclRefExprBits.HasTemplateKWAndArgsInfo;
1168
12.6M
  }
1169
1170
  /// Retrieve the location of the template keyword preceding
1171
  /// this name, if any.
1172
123k
  SourceLocation getTemplateKeywordLoc() const {
1173
123k
    if (!hasTemplateKWAndArgsInfo())
1174
118k
      return SourceLocation();
1175
4.93k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
1176
4.93k
  }
1177
1178
  /// Retrieve the location of the left angle bracket starting the
1179
  /// explicit template argument list following the name, if any.
1180
10.8M
  SourceLocation getLAngleLoc() const {
1181
10.8M
    if (!hasTemplateKWAndArgsInfo())
1182
10.6M
      return SourceLocation();
1183
226k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
1184
226k
  }
1185
1186
  /// Retrieve the location of the right angle bracket ending the
1187
  /// explicit template argument list following the name, if any.
1188
261k
  SourceLocation getRAngleLoc() const {
1189
261k
    if (!hasTemplateKWAndArgsInfo())
1190
63.4k
      return SourceLocation();
1191
198k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
1192
198k
  }
1193
1194
  /// Determines whether the name in this declaration reference
1195
  /// was preceded by the template keyword.
1196
123k
  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
1197
1198
  /// Determines whether this declaration reference was followed by an
1199
  /// explicit template argument list.
1200
10.8M
  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
1201
1202
  /// Copies the template arguments (if present) into the given
1203
  /// structure.
1204
0
  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1205
0
    if (hasExplicitTemplateArgs())
1206
0
      getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
1207
0
          getTrailingObjects<TemplateArgumentLoc>(), List);
1208
0
  }
1209
1210
  /// Retrieve the template arguments provided as part of this
1211
  /// template-id.
1212
162k
  const TemplateArgumentLoc *getTemplateArgs() const {
1213
162k
    if (!hasExplicitTemplateArgs())
1214
153k
      return nullptr;
1215
8.29k
    return getTrailingObjects<TemplateArgumentLoc>();
1216
8.29k
  }
1217
1218
  /// Retrieve the number of template arguments provided as part of this
1219
  /// template-id.
1220
162k
  unsigned getNumTemplateArgs() const {
1221
162k
    if (!hasExplicitTemplateArgs())
1222
153k
      return 0;
1223
9.04k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
1224
9.04k
  }
1225
1226
4.93k
  ArrayRef<TemplateArgumentLoc> template_arguments() const {
1227
4.93k
    return {getTemplateArgs(), getNumTemplateArgs()};
1228
4.93k
  }
1229
1230
  /// Returns true if this expression refers to a function that
1231
  /// was resolved from an overloaded set having size greater than 1.
1232
228k
  bool hadMultipleCandidates() const {
1233
228k
    return DeclRefExprBits.HadMultipleCandidates;
1234
228k
  }
1235
  /// Sets the flag telling whether this expression refers to
1236
  /// a function that was resolved from an overloaded set having size
1237
  /// greater than 1.
1238
955k
  void setHadMultipleCandidates(bool V = true) {
1239
955k
    DeclRefExprBits.HadMultipleCandidates = V;
1240
955k
  }
1241
1242
  /// Does this DeclRefExpr refer to an enclosing local or a captured
1243
  /// variable?
1244
4.48M
  bool refersToEnclosingVariableOrCapture() const {
1245
4.48M
    return DeclRefExprBits.RefersToEnclosingVariableOrCapture;
1246
4.48M
  }
1247
1248
60.9M
  static bool classof(const Stmt *T) {
1249
60.9M
    return T->getStmtClass() == DeclRefExprClass;
1250
60.9M
  }
1251
1252
  // Iterators
1253
20.8M
  child_range children() {
1254
20.8M
    return child_range(child_iterator(), child_iterator());
1255
20.8M
  }
1256
1257
0
  const_child_range children() const {
1258
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1259
0
  }
1260
};
1261
1262
/// Used by IntegerLiteral/FloatingLiteral to store the numeric without
1263
/// leaking memory.
1264
///
1265
/// For large floats/integers, APFloat/APInt will allocate memory from the heap
1266
/// to represent these numbers.  Unfortunately, when we use a BumpPtrAllocator
1267
/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
1268
/// the APFloat/APInt values will never get freed. APNumericStorage uses
1269
/// ASTContext's allocator for memory allocation.
1270
class APNumericStorage {
1271
  union {
1272
    uint64_t VAL;    ///< Used to store the <= 64 bits integer value.
1273
    uint64_t *pVal;  ///< Used to store the >64 bits integer value.
1274
  };
1275
  unsigned BitWidth;
1276
1277
6.72M
  bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
1278
1279
  APNumericStorage(const APNumericStorage &) = delete;
1280
  void operator=(const APNumericStorage &) = delete;
1281
1282
protected:
1283
6.72M
  APNumericStorage() : VAL(0), BitWidth(0) { }
1284
1285
13.1M
  llvm::APInt getIntValue() const {
1286
13.1M
    unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
1287
13.1M
    if (NumWords > 1)
1288
938
      return llvm::APInt(BitWidth, NumWords, pVal);
1289
13.1M
    else
1290
13.1M
      return llvm::APInt(BitWidth, VAL);
1291
13.1M
  }
1292
  void setIntValue(const ASTContext &C, const llvm::APInt &Val);
1293
};
1294
1295
class APIntStorage : private APNumericStorage {
1296
public:
1297
12.8M
  llvm::APInt getValue() const { return getIntValue(); }
1298
6.48M
  void setValue(const ASTContext &C, const llvm::APInt &Val) {
1299
6.48M
    setIntValue(C, Val);
1300
6.48M
  }
1301
};
1302
1303
class APFloatStorage : private APNumericStorage {
1304
public:
1305
299k
  llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
1306
299k
    return llvm::APFloat(Semantics, getIntValue());
1307
299k
  }
1308
237k
  void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1309
237k
    setIntValue(C, Val.bitcastToAPInt());
1310
237k
  }
1311
};
1312
1313
class IntegerLiteral : public Expr, public APIntStorage {
1314
  SourceLocation Loc;
1315
1316
  /// Construct an empty integer literal.
1317
  explicit IntegerLiteral(EmptyShell Empty)
1318
69.1k
    : Expr(IntegerLiteralClass, Empty) { }
1319
1320
public:
1321
  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
1322
  // or UnsignedLongLongTy
1323
  IntegerLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1324
                 SourceLocation l);
1325
1326
  /// Returns a new integer literal with value 'V' and type 'type'.
1327
  /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
1328
  /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
1329
  /// \param V - the value that the returned integer literal contains.
1330
  static IntegerLiteral *Create(const ASTContext &C, const llvm::APInt &V,
1331
                                QualType type, SourceLocation l);
1332
  /// Returns a new empty integer literal.
1333
  static IntegerLiteral *Create(const ASTContext &C, EmptyShell Empty);
1334
1335
24.0M
  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1336
753k
  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1337
1338
  /// Retrieve the location of the literal.
1339
87.2k
  SourceLocation getLocation() const { return Loc; }
1340
1341
69.1k
  void setLocation(SourceLocation Location) { Loc = Location; }
1342
1343
13.7M
  static bool classof(const Stmt *T) {
1344
13.7M
    return T->getStmtClass() == IntegerLiteralClass;
1345
13.7M
  }
1346
1347
  // Iterators
1348
13.7M
  child_range children() {
1349
13.7M
    return child_range(child_iterator(), child_iterator());
1350
13.7M
  }
1351
0
  const_child_range children() const {
1352
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1353
0
  }
1354
};
1355
1356
class FixedPointLiteral : public Expr, public APIntStorage {
1357
  SourceLocation Loc;
1358
  unsigned Scale;
1359
1360
  /// \brief Construct an empty integer literal.
1361
  explicit FixedPointLiteral(EmptyShell Empty)
1362
      : Expr(FixedPointLiteralClass, Empty) {}
1363
1364
 public:
1365
  FixedPointLiteral(const ASTContext &C, const llvm::APInt &V, QualType type,
1366
                    SourceLocation l, unsigned Scale);
1367
1368
  // Store the int as is without any bit shifting.
1369
  static FixedPointLiteral *CreateFromRawInt(const ASTContext &C,
1370
                                             const llvm::APInt &V,
1371
                                             QualType type, SourceLocation l,
1372
                                             unsigned Scale);
1373
1374
894
  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1375
115
  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1376
1377
  /// \brief Retrieve the location of the literal.
1378
0
  SourceLocation getLocation() const { return Loc; }
1379
1380
0
  void setLocation(SourceLocation Location) { Loc = Location; }
1381
1382
0
  static bool classof(const Stmt *T) {
1383
0
    return T->getStmtClass() == FixedPointLiteralClass;
1384
0
  }
1385
1386
  std::string getValueAsString(unsigned Radix) const;
1387
1388
  // Iterators
1389
595
  child_range children() {
1390
595
    return child_range(child_iterator(), child_iterator());
1391
595
  }
1392
0
  const_child_range children() const {
1393
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1394
0
  }
1395
};
1396
1397
class CharacterLiteral : public Expr {
1398
public:
1399
  enum CharacterKind {
1400
    Ascii,
1401
    Wide,
1402
    UTF8,
1403
    UTF16,
1404
    UTF32
1405
  };
1406
1407
private:
1408
  unsigned Value;
1409
  SourceLocation Loc;
1410
public:
1411
  // type should be IntTy
1412
  CharacterLiteral(unsigned value, CharacterKind kind, QualType type,
1413
                   SourceLocation l)
1414
    : Expr(CharacterLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
1415
           false, false),
1416
78.8k
      Value(value), Loc(l) {
1417
78.8k
    CharacterLiteralBits.Kind = kind;
1418
78.8k
  }
1419
1420
  /// Construct an empty character literal.
1421
207
  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
1422
1423
221
  SourceLocation getLocation() const { return Loc; }
1424
542
  CharacterKind getKind() const {
1425
542
    return static_cast<CharacterKind>(CharacterLiteralBits.Kind);
1426
542
  }
1427
1428
441k
  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1429
15.8k
  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1430
1431
205k
  unsigned getValue() const { return Value; }
1432
1433
207
  void setLocation(SourceLocation Location) { Loc = Location; }
1434
207
  void setKind(CharacterKind kind) { CharacterLiteralBits.Kind = kind; }
1435
207
  void setValue(unsigned Val) { Value = Val; }
1436
1437
1.44M
  static bool classof(const Stmt *T) {
1438
1.44M
    return T->getStmtClass() == CharacterLiteralClass;
1439
1.44M
  }
1440
1441
  // Iterators
1442
205k
  child_range children() {
1443
205k
    return child_range(child_iterator(), child_iterator());
1444
205k
  }
1445
0
  const_child_range children() const {
1446
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1447
0
  }
1448
};
1449
1450
class FloatingLiteral : public Expr, private APFloatStorage {
1451
  SourceLocation Loc;
1452
1453
  FloatingLiteral(const ASTContext &C, const llvm::APFloat &V, bool isexact,
1454
                  QualType Type, SourceLocation L);
1455
1456
  /// Construct an empty floating-point literal.
1457
  explicit FloatingLiteral(const ASTContext &C, EmptyShell Empty);
1458
1459
public:
1460
  static FloatingLiteral *Create(const ASTContext &C, const llvm::APFloat &V,
1461
                                 bool isexact, QualType Type, SourceLocation L);
1462
  static FloatingLiteral *Create(const ASTContext &C, EmptyShell Empty);
1463
1464
299k
  llvm::APFloat getValue() const {
1465
299k
    return APFloatStorage::getValue(getSemantics());
1466
299k
  }
1467
237k
  void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1468
237k
    assert(&getSemantics() == &Val.getSemantics() && "Inconsistent semantics");
1469
237k
    APFloatStorage::setValue(C, Val);
1470
237k
  }
1471
1472
  /// Get a raw enumeration value representing the floating-point semantics of
1473
  /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1474
1.03k
  APFloatSemantics getRawSemantics() const {
1475
1.03k
    return static_cast<APFloatSemantics>(FloatingLiteralBits.Semantics);
1476
1.03k
  }
1477
1478
  /// Set the raw enumeration value representing the floating-point semantics of
1479
  /// this literal (32-bit IEEE, x87, ...), suitable for serialisation.
1480
1.86k
  void setRawSemantics(APFloatSemantics Sem) {
1481
1.86k
    FloatingLiteralBits.Semantics = Sem;
1482
1.86k
  }
1483
1484
  /// Return the APFloat semantics this literal uses.
1485
  const llvm::fltSemantics &getSemantics() const;
1486
1487
  /// Set the APFloat semantics this literal uses.
1488
  void setSemantics(const llvm::fltSemantics &Sem);
1489
1490
3.64k
  bool isExact() const { return FloatingLiteralBits.IsExact; }
1491
933
  void setExact(bool E) { FloatingLiteralBits.IsExact = E; }
1492
1493
  /// getValueAsApproximateDouble - This returns the value as an inaccurate
1494
  /// double.  Note that this may cause loss of precision, but is useful for
1495
  /// debugging dumps, etc.
1496
  double getValueAsApproximateDouble() const;
1497
1498
1.08k
  SourceLocation getLocation() const { return Loc; }
1499
933
  void setLocation(SourceLocation L) { Loc = L; }
1500
1501
1.01M
  SourceLocation getBeginLoc() const LLVM_READONLY { return Loc; }
1502
39.3k
  SourceLocation getEndLoc() const LLVM_READONLY { return Loc; }
1503
1504
147k
  static bool classof(const Stmt *T) {
1505
147k
    return T->getStmtClass() == FloatingLiteralClass;
1506
147k
  }
1507
1508
  // Iterators
1509
675k
  child_range children() {
1510
675k
    return child_range(child_iterator(), child_iterator());
1511
675k
  }
1512
0
  const_child_range children() const {
1513
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1514
0
  }
1515
};
1516
1517
/// ImaginaryLiteral - We support imaginary integer and floating point literals,
1518
/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
1519
/// IntegerLiteral classes.  Instances of this class always have a Complex type
1520
/// whose element type matches the subexpression.
1521
///
1522
class ImaginaryLiteral : public Expr {
1523
  Stmt *Val;
1524
public:
1525
  ImaginaryLiteral(Expr *val, QualType Ty)
1526
    : Expr(ImaginaryLiteralClass, Ty, VK_RValue, OK_Ordinary, false, false,
1527
           false, false),
1528
362
      Val(val) {}
1529
1530
  /// Build an empty imaginary literal.
1531
  explicit ImaginaryLiteral(EmptyShell Empty)
1532
1
    : Expr(ImaginaryLiteralClass, Empty) { }
1533
1534
463
  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1535
9
  Expr *getSubExpr() { return cast<Expr>(Val); }
1536
1
  void setSubExpr(Expr *E) { Val = E; }
1537
1538
949
  SourceLocation getBeginLoc() const LLVM_READONLY {
1539
949
    return Val->getBeginLoc();
1540
949
  }
1541
105
  SourceLocation getEndLoc() const LLVM_READONLY { return Val->getEndLoc(); }
1542
1543
  static bool classof(const Stmt *T) {
1544
    return T->getStmtClass() == ImaginaryLiteralClass;
1545
  }
1546
1547
  // Iterators
1548
895
  child_range children() { return child_range(&Val, &Val+1); }
1549
0
  const_child_range children() const {
1550
0
    return const_child_range(&Val, &Val + 1);
1551
0
  }
1552
};
1553
1554
/// StringLiteral - This represents a string literal expression, e.g. "foo"
1555
/// or L"bar" (wide strings). The actual string data can be obtained with
1556
/// getBytes() and is NOT null-terminated. The length of the string data is
1557
/// determined by calling getByteLength().
1558
///
1559
/// The C type for a string is always a ConstantArrayType. In C++, the char
1560
/// type is const qualified, in C it is not.
1561
///
1562
/// Note that strings in C can be formed by concatenation of multiple string
1563
/// literal pptokens in translation phase #6. This keeps track of the locations
1564
/// of each of these pieces.
1565
///
1566
/// Strings in C can also be truncated and extended by assigning into arrays,
1567
/// e.g. with constructs like:
1568
///   char X[2] = "foobar";
1569
/// In this case, getByteLength() will return 6, but the string literal will
1570
/// have type "char[2]".
1571
class StringLiteral final
1572
    : public Expr,
1573
      private llvm::TrailingObjects<StringLiteral, unsigned, SourceLocation,
1574
                                    char> {
1575
  friend class ASTStmtReader;
1576
  friend TrailingObjects;
1577
1578
  /// StringLiteral is followed by several trailing objects. They are in order:
1579
  ///
1580
  /// * A single unsigned storing the length in characters of this string. The
1581
  ///   length in bytes is this length times the width of a single character.
1582
  ///   Always present and stored as a trailing objects because storing it in
1583
  ///   StringLiteral would increase the size of StringLiteral by sizeof(void *)
1584
  ///   due to alignment requirements. If you add some data to StringLiteral,
1585
  ///   consider moving it inside StringLiteral.
1586
  ///
1587
  /// * An array of getNumConcatenated() SourceLocation, one for each of the
1588
  ///   token this string is made of.
1589
  ///
1590
  /// * An array of getByteLength() char used to store the string data.
1591
1592
public:
1593
  enum StringKind { Ascii, Wide, UTF8, UTF16, UTF32 };
1594
1595
private:
1596
14.5M
  unsigned numTrailingObjects(OverloadToken<unsigned>) const { return 1; }
1597
5.32M
  unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
1598
5.32M
    return getNumConcatenated();
1599
5.32M
  }
1600
1601
0
  unsigned numTrailingObjects(OverloadToken<char>) const {
1602
0
    return getByteLength();
1603
0
  }
1604
1605
197
  char *getStrDataAsChar() { return getTrailingObjects<char>(); }
1606
2.65M
  const char *getStrDataAsChar() const { return getTrailingObjects<char>(); }
1607
1608
2.42k
  const uint16_t *getStrDataAsUInt16() const {
1609
2.42k
    return reinterpret_cast<const uint16_t *>(getTrailingObjects<char>());
1610
2.42k
  }
1611
1612
4.21k
  const uint32_t *getStrDataAsUInt32() const {
1613
4.21k
    return reinterpret_cast<const uint32_t *>(getTrailingObjects<char>());
1614
4.21k
  }
1615
1616
  /// Build a string literal.
1617
  StringLiteral(const ASTContext &Ctx, StringRef Str, StringKind Kind,
1618
                bool Pascal, QualType Ty, const SourceLocation *Loc,
1619
                unsigned NumConcatenated);
1620
1621
  /// Build an empty string literal.
1622
  StringLiteral(EmptyShell Empty, unsigned NumConcatenated, unsigned Length,
1623
                unsigned CharByteWidth);
1624
1625
  /// Map a target and string kind to the appropriate character width.
1626
  static unsigned mapCharByteWidth(TargetInfo const &Target, StringKind SK);
1627
1628
  /// Set one of the string literal token.
1629
203
  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
1630
203
    assert(TokNum < getNumConcatenated() && "Invalid tok number");
1631
203
    getTrailingObjects<SourceLocation>()[TokNum] = L;
1632
203
  }
1633
1634
public:
1635
  /// This is the "fully general" constructor that allows representation of
1636
  /// strings formed from multiple concatenated tokens.
1637
  static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
1638
                               StringKind Kind, bool Pascal, QualType Ty,
1639
                               const SourceLocation *Loc,
1640
                               unsigned NumConcatenated);
1641
1642
  /// Simple constructor for string literals made from one token.
1643
  static StringLiteral *Create(const ASTContext &Ctx, StringRef Str,
1644
                               StringKind Kind, bool Pascal, QualType Ty,
1645
2.67k
                               SourceLocation Loc) {
1646
2.67k
    return Create(Ctx, Str, Kind, Pascal, Ty, &Loc, 1);
1647
2.67k
  }
1648
1649
  /// Construct an empty string literal.
1650
  static StringLiteral *CreateEmpty(const ASTContext &Ctx,
1651
                                    unsigned NumConcatenated, unsigned Length,
1652
                                    unsigned CharByteWidth);
1653
1654
2.63M
  StringRef getString() const {
1655
2.63M
    assert(getCharByteWidth() == 1 &&
1656
2.63M
           "This function is used in places that assume strings use char");
1657
2.63M
    return StringRef(getStrDataAsChar(), getByteLength());
1658
2.63M
  }
1659
1660
  /// Allow access to clients that need the byte representation, such as
1661
  /// ASTWriterStmt::VisitStringLiteral().
1662
1.34k
  StringRef getBytes() const {
1663
1.34k
    // FIXME: StringRef may not be the right type to use as a result for this.
1664
1.34k
    return StringRef(getStrDataAsChar(), getByteLength());
1665
1.34k
  }
1666
1667
  void outputString(raw_ostream &OS) const;
1668
1669
19.8k
  uint32_t getCodeUnit(size_t i) const {
1670
19.8k
    assert(i < getLength() && "out of bounds access");
1671
19.8k
    switch (getCharByteWidth()) {
1672
19.8k
    case 1:
1673
13.1k
      return static_cast<unsigned char>(getStrDataAsChar()[i]);
1674
19.8k
    case 2:
1675
2.42k
      return getStrDataAsUInt16()[i];
1676
19.8k
    case 4:
1677
4.21k
      return getStrDataAsUInt32()[i];
1678
0
    }
1679
0
    llvm_unreachable("Unsupported character width!");
1680
0
  }
1681
1682
2.64M
  unsigned getByteLength() const { return getCharByteWidth() * getLength(); }
1683
2.69M
  unsigned getLength() const { return *getTrailingObjects<unsigned>(); }
1684
2.90M
  unsigned getCharByteWidth() const { return StringLiteralBits.CharByteWidth; }
1685
1686
2.19M
  StringKind getKind() const {
1687
2.19M
    return static_cast<StringKind>(StringLiteralBits.Kind);
1688
2.19M
  }
1689
1690
2.17M
  bool isAscii() const { return getKind() == Ascii; }
1691
4.68k
  bool isWide() const { return getKind() == Wide; }
1692
6
  bool isUTF8() const { return getKind() == UTF8; }
1693
0
  bool isUTF16() const { return getKind() == UTF16; }
1694
0
  bool isUTF32() const { return getKind() == UTF32; }
1695
805
  bool isPascal() const { return StringLiteralBits.IsPascal; }
1696
1697
3
  bool containsNonAscii() const {
1698
3
    for (auto c : getString())
1699
25
      if (!isASCII(c))
1700
0
        return true;
1701
3
    return false;
1702
3
  }
1703
1704
1.83k
  bool containsNonAsciiOrNull() const {
1705
1.83k
    for (auto c : getString())
1706
10.8k
      if (!isASCII(c) || 
!c10.7k
)
1707
53
        return true;
1708
1.83k
    
return false1.78k
;
1709
1.83k
  }
1710
1711
  /// getNumConcatenated - Get the number of string literal tokens that were
1712
  /// concatenated in translation phase #6 to form this string literal.
1713
5.34M
  unsigned getNumConcatenated() const {
1714
5.34M
    return StringLiteralBits.NumConcatenated;
1715
5.34M
  }
1716
1717
  /// Get one of the string literal token.
1718
228k
  SourceLocation getStrTokenLoc(unsigned TokNum) const {
1719
228k
    assert(TokNum < getNumConcatenated() && "Invalid tok number");
1720
228k
    return getTrailingObjects<SourceLocation>()[TokNum];
1721
228k
  }
1722
1723
  /// getLocationOfByte - Return a source location that points to the specified
1724
  /// byte of this string literal.
1725
  ///
1726
  /// Strings are amazingly complex.  They can be formed from multiple tokens
1727
  /// and can have escape sequences in them in addition to the usual trigraph
1728
  /// and escaped newline business.  This routine handles this complexity.
1729
  ///
1730
  SourceLocation
1731
  getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1732
                    const LangOptions &Features, const TargetInfo &Target,
1733
                    unsigned *StartToken = nullptr,
1734
                    unsigned *StartTokenByteOffset = nullptr) const;
1735
1736
  typedef const SourceLocation *tokloc_iterator;
1737
1738
6.35M
  tokloc_iterator tokloc_begin() const {
1739
6.35M
    return getTrailingObjects<SourceLocation>();
1740
6.35M
  }
1741
1742
19.4k
  tokloc_iterator tokloc_end() const {
1743
19.4k
    return getTrailingObjects<SourceLocation>() + getNumConcatenated();
1744
19.4k
  }
1745
1746
6.35M
  SourceLocation getBeginLoc() const LLVM_READONLY { return *tokloc_begin(); }
1747
19.3k
  SourceLocation getEndLoc() const LLVM_READONLY { return *(tokloc_end() - 1); }
1748
1749
6.33M
  static bool classof(const Stmt *T) {
1750
6.33M
    return T->getStmtClass() == StringLiteralClass;
1751
6.33M
  }
1752
1753
  // Iterators
1754
1.30M
  child_range children() {
1755
1.30M
    return child_range(child_iterator(), child_iterator());
1756
1.30M
  }
1757
0
  const_child_range children() const {
1758
0
    return const_child_range(const_child_iterator(), const_child_iterator());
1759
0
  }
1760
};
1761
1762
/// [C99 6.4.2.2] - A predefined identifier such as __func__.
1763
class PredefinedExpr final
1764
    : public Expr,
1765
      private llvm::TrailingObjects<PredefinedExpr, Stmt *> {
1766
  friend class ASTStmtReader;
1767
  friend TrailingObjects;
1768
1769
  // PredefinedExpr is optionally followed by a single trailing
1770
  // "Stmt *" for the predefined identifier. It is present if and only if
1771
  // hasFunctionName() is true and is always a "StringLiteral *".
1772
1773
public:
1774
  enum IdentKind {
1775
    Func,
1776
    Function,
1777
    LFunction, // Same as Function, but as wide string.
1778
    FuncDName,
1779
    FuncSig,
1780
    LFuncSig, // Same as FuncSig, but as as wide string
1781
    PrettyFunction,
1782
    /// The same as PrettyFunction, except that the
1783
    /// 'virtual' keyword is omitted for virtual member functions.
1784
    PrettyFunctionNoVirtual
1785
  };
1786
1787
private:
1788
  PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
1789
                 StringLiteral *SL);
1790
1791
  explicit PredefinedExpr(EmptyShell Empty, bool HasFunctionName);
1792
1793
  /// True if this PredefinedExpr has storage for a function name.
1794
12.1k
  bool hasFunctionName() const { return PredefinedExprBits.HasFunctionName; }
1795
1796
2.34k
  void setFunctionName(StringLiteral *SL) {
1797
2.34k
    assert(hasFunctionName() &&
1798
2.34k
           "This PredefinedExpr has no storage for a function name!");
1799
2.34k
    *getTrailingObjects<Stmt *>() = SL;
1800
2.34k
  }
1801
1802
public:
1803
  /// Create a PredefinedExpr.
1804
  static PredefinedExpr *Create(const ASTContext &Ctx, SourceLocation L,
1805
                                QualType FNTy, IdentKind IK, StringLiteral *SL);
1806
1807
  /// Create an empty PredefinedExpr.
1808
  static PredefinedExpr *CreateEmpty(const ASTContext &Ctx,
1809
                                     bool HasFunctionName);
1810
1811
2.27k
  IdentKind getIdentKind() const {
1812
2.27k
    return static_cast<IdentKind>(PredefinedExprBits.Kind);
1813
2.27k
  }
1814
1815
25.4k
  SourceLocation getLocation() const { return PredefinedExprBits.Loc; }
1816
16
  void setLocation(SourceLocation L) { PredefinedExprBits.Loc = L; }
1817
1818
41
  StringLiteral *getFunctionName() {
1819
41
    return hasFunctionName()
1820
41
               ? 
static_cast<StringLiteral *>(*getTrailingObjects<Stmt *>())34
1821
41
               : 
nullptr7
;
1822
41
  }
1823
1824
2.13k
  const StringLiteral *getFunctionName() const {
1825
2.13k
    return hasFunctionName()
1826
2.13k
               ? static_cast<StringLiteral *>(*getTrailingObjects<Stmt *>())
1827
2.13k
               : 
nullptr0
;
1828
2.13k
  }
1829
1830
  static StringRef getIdentKindName(IdentKind IK);
1831
  static std::string ComputeName(IdentKind IK, const Decl *CurrentDecl);
1832
1833
25.1k
  SourceLocation getBeginLoc() const { return getLocation(); }
1834
127
  SourceLocation getEndLoc() const { return getLocation(); }
1835
1836
102k
  static bool classof(const Stmt *T) {
1837
102k
    return T->getStmtClass() == PredefinedExprClass;
1838
102k
  }
1839
1840
  // Iterators
1841
9.96k
  child_range children() {
1842
9.96k
    return child_range(getTrailingObjects<Stmt *>(),
1843
9.96k
                       getTrailingObjects<Stmt *>() + hasFunctionName());
1844
9.96k
  }
1845
};
1846
1847
/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
1848
/// AST node is only formed if full location information is requested.
1849
class ParenExpr : public Expr {
1850
  SourceLocation L, R;
1851
  Stmt *Val;
1852
public:
1853
  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
1854
    : Expr(ParenExprClass, val->getType(),
1855
           val->getValueKind(), val->getObjectKind(),
1856
           val->isTypeDependent(), val->isValueDependent(),
1857
           val->isInstantiationDependent(),
1858
           val->containsUnexpandedParameterPack()),
1859
2.54M
      L(l), R(r), Val(val) {}
1860
1861
  /// Construct an empty parenthesized expression.
1862
  explicit ParenExpr(EmptyShell Empty)
1863
11.8k
    : Expr(ParenExprClass, Empty) { }
1864
1865
2.27M
  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1866
14.2M
  Expr *getSubExpr() { return cast<Expr>(Val); }
1867
11.8k
  void setSubExpr(Expr *E) { Val = E; }
1868
1869
5.88M
  SourceLocation getBeginLoc() const LLVM_READONLY { return L; }
1870
1.27M
  SourceLocation getEndLoc() const LLVM_READONLY { return R; }
1871
1872
  /// Get the location of the left parentheses '('.
1873
280k
  SourceLocation getLParen() const { return L; }
1874
11.8k
  void setLParen(SourceLocation Loc) { L = Loc; }
1875
1876
  /// Get the location of the right parentheses ')'.
1877
280k
  SourceLocation getRParen() const { return R; }
1878
11.8k
  void setRParen(SourceLocation Loc) { R = Loc; }
1879
1880
392M
  static bool classof(const Stmt *T) {
1881
392M
    return T->getStmtClass() == ParenExprClass;
1882
392M
  }
1883
1884
  // Iterators
1885
2.98M
  child_range children() { return child_range(&Val, &Val+1); }
1886
0
  const_child_range children() const {
1887
0
    return const_child_range(&Val, &Val + 1);
1888
0
  }
1889
};
1890
1891
/// UnaryOperator - This represents the unary-expression's (except sizeof and
1892
/// alignof), the postinc/postdec operators from postfix-expression, and various
1893
/// extensions.
1894
///
1895
/// Notes on various nodes:
1896
///
1897
/// Real/Imag - These return the real/imag part of a complex operand.  If
1898
///   applied to a non-complex value, the former returns its operand and the
1899
///   later returns zero in the type of the operand.
1900
///
1901
class UnaryOperator : public Expr {
1902
  Stmt *Val;
1903
1904
public:
1905
  typedef UnaryOperatorKind Opcode;
1906
1907
  UnaryOperator(Expr *input, Opcode opc, QualType type, ExprValueKind VK,
1908
                ExprObjectKind OK, SourceLocation l, bool CanOverflow)
1909
      : Expr(UnaryOperatorClass, type, VK, OK,
1910
             input->isTypeDependent() || type->isDependentType(),
1911
             input->isValueDependent(),
1912
             (input->isInstantiationDependent() ||
1913
              type->isInstantiationDependentType()),
1914
             input->containsUnexpandedParameterPack()),
1915
2.59M
        Val(input) {
1916
2.59M
    UnaryOperatorBits.Opc = opc;
1917
2.59M
    UnaryOperatorBits.CanOverflow = CanOverflow;
1918
2.59M
    UnaryOperatorBits.Loc = l;
1919
2.59M
  }
1920
1921
  /// Build an empty unary operator.
1922
9.89k
  explicit UnaryOperator(EmptyShell Empty) : Expr(UnaryOperatorClass, Empty) {
1923
9.89k
    UnaryOperatorBits.Opc = UO_AddrOf;
1924
9.89k
  }
1925
1926
28.9M
  Opcode getOpcode() const {
1927
28.9M
    return static_cast<Opcode>(UnaryOperatorBits.Opc);
1928
28.9M
  }
1929
9.89k
  void setOpcode(Opcode Opc) { UnaryOperatorBits.Opc = Opc; }
1930
1931
7.26M
  Expr *getSubExpr() const { return cast<Expr>(Val); }
1932
9.89k
  void setSubExpr(Expr *E) { Val = E; }
1933
1934
  /// getOperatorLoc - Return the location of the operator.
1935
8.83M
  SourceLocation getOperatorLoc() const { return UnaryOperatorBits.Loc; }
1936
9.89k
  void setOperatorLoc(SourceLocation L) { UnaryOperatorBits.Loc = L; }
1937
1938
  /// Returns true if the unary operator can cause an overflow. For instance,
1939
  ///   signed int i = INT_MAX; i++;
1940
  ///   signed char c = CHAR_MAX; c++;
1941
  /// Due to integer promotions, c++ is promoted to an int before the postfix
1942
  /// increment, and the result is an int that cannot overflow. However, i++
1943
  /// can overflow.
1944
77.1k
  bool canOverflow() const { return UnaryOperatorBits.CanOverflow; }
1945
9.89k
  void setCanOverflow(bool C) { UnaryOperatorBits.CanOverflow = C; }
1946
1947
  /// isPostfix - Return true if this is a postfix operation, like x++.
1948
5.38M
  static bool isPostfix(Opcode Op) {
1949
5.38M
    return Op == UO_PostInc || 
Op == UO_PostDec5.17M
;
1950
5.38M
  }
1951
1952
  /// isPrefix - Return true if this is a prefix operation, like --x.
1953
329k
  static bool isPrefix(Opcode Op) {
1954
329k
    return Op == UO_PreInc || 
Op == UO_PreDec327k
;
1955
329k
  }
1956
1957
329k
  bool isPrefix() const { return isPrefix(getOpcode()); }
1958
5.38M
  bool isPostfix() const { return isPostfix(getOpcode()); }
1959
1960
58.1k
  static bool isIncrementOp(Opcode Op) {
1961
58.1k
    return Op == UO_PreInc || 
Op == UO_PostInc21.1k
;
1962
58.1k
  }
1963
58.1k
  bool isIncrementOp() const {
1964
58.1k
    return isIncrementOp(getOpcode());
1965
58.1k
  }
1966
1967
72.5k
  static bool isDecrementOp(Opcode Op) {
1968
72.5k
    return Op == UO_PreDec || 
Op == UO_PostDec72.5k
;
1969
72.5k
  }
1970
72.5k
  bool isDecrementOp() const {
1971
72.5k
    return isDecrementOp(getOpcode());
1972
72.5k
  }
1973
1974
636k
  static bool isIncrementDecrementOp(Opcode Op) { return Op <= UO_PreDec; }
1975
636k
  bool isIncrementDecrementOp() const {
1976
636k
    return isIncrementDecrementOp(getOpcode());
1977
636k
  }
1978
1979
  static bool isArithmeticOp(Opcode Op) {
1980
    return Op >= UO_Plus && Op <= UO_LNot;
1981
  }
1982
  bool isArithmeticOp() const { return isArithmeticOp(getOpcode()); }
1983
1984
  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1985
  /// corresponds to, e.g. "sizeof" or "[pre]++"
1986
  static StringRef getOpcodeStr(Opcode Op);
1987
1988
  /// Retrieve the unary opcode that corresponds to the given
1989
  /// overloaded operator.
1990
  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
1991
1992
  /// Retrieve the overloaded operator kind that corresponds to
1993
  /// the given unary opcode.
1994
  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1995
1996
4.88M
  SourceLocation getBeginLoc() const LLVM_READONLY {
1997
4.88M
    return isPostfix() ? 
Val->getBeginLoc()185k
:
getOperatorLoc()4.70M
;
1998
4.88M
  }
1999
430k
  SourceLocation getEndLoc() const LLVM_READONLY {
2000
430k
    return isPostfix() ? 
getOperatorLoc()32.5k
:
Val->getEndLoc()397k
;
2001
430k
  }
2002
3.69M
  SourceLocation getExprLoc() const { return getOperatorLoc(); }
2003
2004
573M
  static bool classof(const Stmt *T) {
2005
573M
    return T->getStmtClass() == UnaryOperatorClass;
2006
573M
  }
2007
2008
  // Iterators
2009
3.78M
  child_range children() { return child_range(&Val, &Val+1); }
2010
0
  const_child_range children() const {
2011
0
    return const_child_range(&Val, &Val + 1);
2012
0
  }
2013
};
2014
2015
/// Helper class for OffsetOfExpr.
2016
2017
// __builtin_offsetof(type, identifier(.identifier|[expr])*)
2018
0
class OffsetOfNode {
2019
public:
2020
  /// The kind of offsetof node we have.
2021
  enum Kind {
2022
    /// An index into an array.
2023
    Array = 0x00,
2024
    /// A field.
2025
    Field = 0x01,
2026
    /// A field in a dependent type, known only by its name.
2027
    Identifier = 0x02,
2028
    /// An implicit indirection through a C++ base class, when the
2029
    /// field found is in a base class.
2030
    Base = 0x03
2031
  };
2032
2033
private:
2034
  enum { MaskBits = 2, Mask = 0x03 };
2035
2036
  /// The source range that covers this part of the designator.
2037
  SourceRange Range;
2038
2039
  /// The data describing the designator, which comes in three
2040
  /// different forms, depending on the lower two bits.
2041
  ///   - An unsigned index into the array of Expr*'s stored after this node
2042
  ///     in memory, for [constant-expression] designators.
2043
  ///   - A FieldDecl*, for references to a known field.
2044
  ///   - An IdentifierInfo*, for references to a field with a given name
2045
  ///     when the class type is dependent.
2046
  ///   - A CXXBaseSpecifier*, for references that look at a field in a
2047
  ///     base class.
2048
  uintptr_t Data;
2049
2050
public:
2051
  /// Create an offsetof node that refers to an array element.
2052
  OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
2053
               SourceLocation RBracketLoc)
2054
45
      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) {}
2055
2056
  /// Create an offsetof node that refers to a field.
2057
  OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field, SourceLocation NameLoc)
2058
      : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2059
4.28k
        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) {}
2060
2061
  /// Create an offsetof node that refers to an identifier.
2062
  OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
2063
               SourceLocation NameLoc)
2064
      : Range(DotLoc.isValid() ? DotLoc : NameLoc, NameLoc),
2065
17
        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) {}
2066
2067
  /// Create an offsetof node that refers into a C++ base class.
2068
  explicit OffsetOfNode(const CXXBaseSpecifier *Base)
2069
19
      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
2070
2071
  /// Determine what kind of offsetof node this is.
2072
5.24k
  Kind getKind() const { return static_cast<Kind>(Data & Mask); }
2073
2074
  /// For an array element node, returns the index into the array
2075
  /// of expressions.
2076
45
  unsigned getArrayExprIndex() const {
2077
45
    assert(getKind() == Array);
2078
45
    return Data >> 2;
2079
45
  }
2080
2081
  /// For a field offsetof node, returns the field.
2082
5.07k
  FieldDecl *getField() const {
2083
5.07k
    assert(getKind() == Field);
2084
5.07k
    return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
2085
5.07k
  }
2086
2087
  /// For a field or identifier offsetof node, returns the name of
2088
  /// the field.
2089
  IdentifierInfo *getFieldName() const;
2090
2091
  /// For a base class node, returns the base specifier.
2092
35
  CXXBaseSpecifier *getBase() const {
2093
35
    assert(getKind() == Base);
2094
35
    return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
2095
35
  }
2096
2097
  /// Retrieve the source range that covers this offsetof node.
2098
  ///
2099
  /// For an array element node, the source range contains the locations of
2100
  /// the square brackets. For a field or identifier node, the source range
2101
  /// contains the location of the period (if there is one) and the
2102
  /// identifier.
2103
40
  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
2104
3
  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
2105
37
  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
2106
};
2107
2108
/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
2109
/// offsetof(record-type, member-designator). For example, given:
2110
/// @code
2111
/// struct S {
2112
///   float f;
2113
///   double d;
2114
/// };
2115
/// struct T {
2116
///   int i;
2117
///   struct S s[10];
2118
/// };
2119
/// @endcode
2120
/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
2121
2122
class OffsetOfExpr final
2123
    : public Expr,
2124
      private llvm::TrailingObjects<OffsetOfExpr, OffsetOfNode, Expr *> {
2125
  SourceLocation OperatorLoc, RParenLoc;
2126
  // Base type;
2127
  TypeSourceInfo *TSInfo;
2128
  // Number of sub-components (i.e. instances of OffsetOfNode).
2129
  unsigned NumComps;
2130
  // Number of sub-expressions (i.e. array subscript expressions).
2131
  unsigned NumExprs;
2132
2133
621
  size_t numTrailingObjects(OverloadToken<OffsetOfNode>) const {
2134
621
    return NumComps;
2135
621
  }
2136
2137
  OffsetOfExpr(const ASTContext &C, QualType type,
2138
               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2139
               ArrayRef<OffsetOfNode> comps, ArrayRef<Expr*> exprs,
2140
               SourceLocation RParenLoc);
2141
2142
  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
2143
    : Expr(OffsetOfExprClass, EmptyShell()),
2144
3
      TSInfo(nullptr), NumComps(numComps), NumExprs(numExprs) {}
2145
2146
public:
2147
2148
  static OffsetOfExpr *Create(const ASTContext &C, QualType type,
2149
                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
2150
                              ArrayRef<OffsetOfNode> comps,
2151
                              ArrayRef<Expr*> exprs, SourceLocation RParenLoc);
2152
2153
  static OffsetOfExpr *CreateEmpty(const ASTContext &C,
2154
                                   unsigned NumComps, unsigned NumExprs);
2155
2156
  /// getOperatorLoc - Return the location of the operator.
2157
8
  SourceLocation getOperatorLoc() const { return OperatorLoc; }
2158
3
  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
2159
2160
  /// Return the location of the right parentheses.
2161
8
  SourceLocation getRParenLoc() const { return RParenLoc; }
2162
3
  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
2163
2164
5.12k
  TypeSourceInfo *getTypeSourceInfo() const {
2165
5.12k
    return TSInfo;
2166
5.12k
  }
2167
3
  void setTypeSourceInfo(TypeSourceInfo *tsi) {
2168
3
    TSInfo = tsi;
2169
3
  }
2170
2171
5.19k
  const OffsetOfNode &getComponent(unsigned Idx) const {
2172
5.19k
    assert(Idx < NumComps && "Subscript out of range");
2173
5.19k
    return getTrailingObjects<OffsetOfNode>()[Idx];
2174
5.19k
  }
2175
2176
4.36k
  void setComponent(unsigned Idx, OffsetOfNode ON) {
2177
4.36k
    assert(Idx < NumComps && "Subscript out of range");
2178
4.36k
    getTrailingObjects<OffsetOfNode>()[Idx] = ON;
2179
4.36k
  }
2180
2181
5.05k
  unsigned getNumComponents() const {
2182
5.05k
    return NumComps;
2183
5.05k
  }
2184
2185
6
  Expr* getIndexExpr(unsigned Idx) {
2186
6
    assert(Idx < NumExprs && "Subscript out of range");
2187
6
    return getTrailingObjects<Expr *>()[Idx];
2188
6
  }
2189
2190
39
  const Expr *getIndexExpr(unsigned Idx) const {
2191
39
    assert(Idx < NumExprs && "Subscript out of range");
2192
39
    return getTrailingObjects<Expr *>()[Idx];
2193
39
  }
2194
2195
43
  void setIndexExpr(unsigned Idx, Expr* E) {
2196
43
    assert(Idx < NumComps && "Subscript out of range");
2197
43
    getTrailingObjects<Expr *>()[Idx] = E;
2198
43
  }
2199
2200
11
  unsigned getNumExpressions() const {
2201
11
    return NumExprs;
2202
11
  }
2203
2204
3.90k
  SourceLocation getBeginLoc() const LLVM_READONLY { return OperatorLoc; }
2205
73
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2206
2207
110
  static bool classof(const Stmt *T) {
2208
110
    return T->getStmtClass() == OffsetOfExprClass;
2209
110
  }
2210
2211
  // Iterators
2212
533
  child_range children() {
2213
533
    Stmt **begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
2214
533
    return child_range(begin, begin + NumExprs);
2215
533
  }
2216
0
  const_child_range children() const {
2217
0
    Stmt *const *begin =
2218
0
        reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
2219
0
    return const_child_range(begin, begin + NumExprs);
2220
0
  }
2221
  friend TrailingObjects;
2222
};
2223
2224
/// UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated)
2225
/// expression operand.  Used for sizeof/alignof (C99 6.5.3.4) and
2226
/// vec_step (OpenCL 1.1 6.11.12).
2227
class UnaryExprOrTypeTraitExpr : public Expr {
2228
  union {
2229
    TypeSourceInfo *Ty;
2230
    Stmt *Ex;
2231
  } Argument;
2232
  SourceLocation OpLoc, RParenLoc;
2233
2234
public:
2235
  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo,
2236
                           QualType resultType, SourceLocation op,
2237
                           SourceLocation rp) :
2238
      Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
2239
           false, // Never type-dependent (C++ [temp.dep.expr]p3).
2240
           // Value-dependent if the argument is type-dependent.
2241
           TInfo->getType()->isDependentType(),
2242
           TInfo->getType()->isInstantiationDependentType(),
2243
           TInfo->getType()->containsUnexpandedParameterPack()),
2244
158k
      OpLoc(op), RParenLoc(rp) {
2245
158k
    UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
2246
158k
    UnaryExprOrTypeTraitExprBits.IsType = true;
2247
158k
    Argument.Ty = TInfo;
2248
158k
  }
2249
2250
  UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, Expr *E,
2251
                           QualType resultType, SourceLocation op,
2252
                           SourceLocation rp);
2253
2254
  /// Construct an empty sizeof/alignof expression.
2255
  explicit UnaryExprOrTypeTraitExpr(EmptyShell Empty)
2256
32
    : Expr(UnaryExprOrTypeTraitExprClass, Empty) { }
2257
2258
571k
  UnaryExprOrTypeTrait getKind() const {
2259
571k
    return static_cast<UnaryExprOrTypeTrait>(UnaryExprOrTypeTraitExprBits.Kind);
2260
571k
  }
2261
32
  void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = K;}
2262
2263
778k
  bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
2264
514k
  QualType getArgumentType() const {
2265
514k
    return getArgumentTypeInfo()->getType();
2266
514k
  }
2267
581k
  TypeSourceInfo *getArgumentTypeInfo() const {
2268
581k
    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
2269
581k
    return Argument.Ty;
2270
581k
  }
2271
182k
  Expr *getArgumentExpr() {
2272
182k
    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
2273
182k
    return static_cast<Expr*>(Argument.Ex);
2274
182k
  }
2275
115k
  const Expr *getArgumentExpr() const {
2276
115k
    return const_cast<UnaryExprOrTypeTraitExpr*>(this)->getArgumentExpr();
2277
115k
  }
2278
2279
18
  void setArgument(Expr *E) {
2280
18
    Argument.Ex = E;
2281
18
    UnaryExprOrTypeTraitExprBits.IsType = false;
2282
18
  }
2283
14
  void setArgument(TypeSourceInfo *TInfo) {
2284
14
    Argument.Ty = TInfo;
2285
14
    UnaryExprOrTypeTraitExprBits.IsType = true;
2286
14
  }
2287
2288
  /// Gets the argument type, or the type of the argument expression, whichever
2289
  /// is appropriate.
2290
392k
  QualType getTypeOfArgument() const {
2291
392k
    return isArgumentType() ? 
getArgumentType()289k
:
getArgumentExpr()->getType()103k
;
2292
392k
  }
2293
2294
67.8k
  SourceLocation getOperatorLoc() const { return OpLoc; }
2295
32
  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2296
2297
50
  SourceLocation getRParenLoc() const { return RParenLoc; }
2298
32
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2299
2300
848k
  SourceLocation getBeginLoc() const LLVM_READONLY { return OpLoc; }
2301
54.9k
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
2302
2303
30.0M
  static bool classof(const Stmt *T) {
2304
30.0M
    return T->getStmtClass() == UnaryExprOrTypeTraitExprClass;
2305
30.0M
  }
2306
2307
  // Iterators
2308
  child_range children();
2309
  const_child_range children() const;
2310
};
2311
2312
//===----------------------------------------------------------------------===//
2313
// Postfix Operators.
2314
//===----------------------------------------------------------------------===//
2315
2316
/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
2317
class ArraySubscriptExpr : public Expr {
2318
  enum { LHS, RHS, END_EXPR=2 };
2319
  Stmt* SubExprs[END_EXPR];
2320
  SourceLocation RBracketLoc;
2321
public:
2322
  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
2323
                     ExprValueKind VK, ExprObjectKind OK,
2324
                     SourceLocation rbracketloc)
2325
  : Expr(ArraySubscriptExprClass, t, VK, OK,
2326
         lhs->isTypeDependent() || rhs->isTypeDependent(),
2327
         lhs->isValueDependent() || rhs->isValueDependent(),
2328
         (lhs->isInstantiationDependent() ||
2329
          rhs->isInstantiationDependent()),
2330
         (lhs->containsUnexpandedParameterPack() ||
2331
          rhs->containsUnexpandedParameterPack())),
2332
696k
    RBracketLoc(rbracketloc) {
2333
696k
    SubExprs[LHS] = lhs;
2334
696k
    SubExprs[RHS] = rhs;
2335
696k
  }
2336
2337
  /// Create an empty array subscript expression.
2338
  explicit ArraySubscriptExpr(EmptyShell Shell)
2339
5.15k
    : Expr(ArraySubscriptExprClass, Shell) { }
2340
2341
  /// An array access can be written A[4] or 4[A] (both are equivalent).
2342
  /// - getBase() and getIdx() always present the normalized view: A[4].
2343
  ///    In this case getBase() returns "A" and getIdx() returns "4".
2344
  /// - getLHS() and getRHS() present the syntactic view. e.g. for
2345
  ///    4[A] getLHS() returns "4".
2346
  /// Note: Because vector element access is also written A[4] we must
2347
  /// predicate the format conversion in getBase and getIdx only on the
2348
  /// the type of the RHS, as it is possible for the LHS to be a vector of
2349
  /// integer type
2350
406k
  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
2351
8.57M
  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2352
5.15k
  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2353
2354
251k
  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
2355
9.24M
  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2356
5.15k
  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2357
2358
161k
  Expr *getBase() {
2359
161k
    return getRHS()->getType()->isIntegerType() ? 
getLHS()161k
:
getRHS()35
;
2360
161k
  }
2361
2362
5.87M
  const Expr *getBase() const {
2363
5.87M
    return getRHS()->getType()->isIntegerType() ? 
getLHS()5.87M
:
getRHS()6.64k
;
2364
5.87M
  }
2365
2366
1.63k
  Expr *getIdx() {
2367
1.63k
    return getRHS()->getType()->isIntegerType() ? getRHS() : 
getLHS()0
;
2368
1.63k
  }
2369
2370
1.68M
  const Expr *getIdx() const {
2371
1.68M
    return getRHS()->getType()->isIntegerType() ? 
getRHS()1.68M
:
getLHS()130
;
2372
1.68M
  }
2373
2374
2.26M
  SourceLocation getBeginLoc() const LLVM_READONLY {
2375
2.26M
    return getLHS()->getBeginLoc();
2376
2.26M
  }
2377
146k
  SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; }
2378
2379
95.2k
  SourceLocation getRBracketLoc() const { return RBracketLoc; }
2380
5.15k
  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
2381
2382
1.67M
  SourceLocation getExprLoc() const LLVM_READONLY {
2383
1.67M
    return getBase()->getExprLoc();
2384
1.67M
  }
2385
2386
3.24M
  static bool classof(const Stmt *T) {
2387
3.24M
    return T->getStmtClass() == ArraySubscriptExprClass;
2388
3.24M
  }
2389
2390
  // Iterators
2391
1.45M
  child_range children() {
2392
1.45M
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
2393
1.45M
  }
2394
0
  const_child_range children() const {
2395
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
2396
0
  }
2397
};
2398
2399
/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
2400
/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
2401
/// while its subclasses may represent alternative syntax that (semantically)
2402
/// results in a function call. For example, CXXOperatorCallExpr is
2403
/// a subclass for overloaded operator calls that use operator syntax, e.g.,
2404
/// "str1 + str2" to resolve to a function call.
2405
class CallExpr : public Expr {
2406
  enum { FN=0, PREARGS_START=1 };
2407
  Stmt **SubExprs;
2408
  unsigned NumArgs;
2409
  SourceLocation RParenLoc;
2410
2411
  void updateDependenciesFromArg(Expr *Arg);
2412
2413
protected:
2414
  // These versions of the constructor are for derived classes.
2415
  CallExpr(const ASTContext &C, StmtClass SC, Expr *fn,
2416
           ArrayRef<Expr *> preargs, ArrayRef<Expr *> args, QualType t,
2417
           ExprValueKind VK, SourceLocation rparenloc);
2418
  CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, ArrayRef<Expr *> args,
2419
           QualType t, ExprValueKind VK, SourceLocation rparenloc);
2420
  CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs,
2421
           EmptyShell Empty);
2422
2423
4
  Stmt *getPreArg(unsigned i) {
2424
4
    assert(i < getNumPreArgs() && "Prearg access out of range!");
2425
4
    return SubExprs[PREARGS_START+i];
2426
4
  }
2427
8
  const Stmt *getPreArg(unsigned i) const {
2428
8
    assert(i < getNumPreArgs() && "Prearg access out of range!");
2429
8
    return SubExprs[PREARGS_START+i];
2430
8
  }
2431
0
  void setPreArg(unsigned i, Stmt *PreArg) {
2432
0
    assert(i < getNumPreArgs() && "Prearg access out of range!");
2433
0
    SubExprs[PREARGS_START+i] = PreArg;
2434
0
  }
2435
2436
44.2M
  unsigned getNumPreArgs() const { return CallExprBits.NumPreArgs; }
2437
2438
public:
2439
  CallExpr(const ASTContext& C, Expr *fn, ArrayRef<Expr*> args, QualType t,
2440
           ExprValueKind VK, SourceLocation rparenloc);
2441
2442
  /// Build an empty call expression.
2443
  CallExpr(const ASTContext &C, StmtClass SC, EmptyShell Empty);
2444
2445
33.7M
  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
2446
17.0M
  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
2447
14.2k
  void setCallee(Expr *F) { SubExprs[FN] = F; }
2448
2449
  Decl *getCalleeDecl();
2450
1.87M
  const Decl *getCalleeDecl() const {
2451
1.87M
    return const_cast<CallExpr*>(this)->getCalleeDecl();
2452
1.87M
  }
2453
2454
  /// If the callee is a FunctionDecl, return it. Otherwise return 0.
2455
  FunctionDecl *getDirectCallee();
2456
2.59M
  const FunctionDecl *getDirectCallee() const {
2457
2.59M
    return const_cast<CallExpr*>(this)->getDirectCallee();
2458
2.59M
  }
2459
2460
  /// getNumArgs - Return the number of actual arguments to this call.
2461
  ///
2462
25.4M
  unsigned getNumArgs() const { return NumArgs; }
2463
2464
  /// Retrieve the call arguments.
2465
6.41M
  Expr **getArgs() {
2466
6.41M
    return reinterpret_cast<Expr **>(SubExprs+getNumPreArgs()+PREARGS_START);
2467
6.41M
  }
2468
926k
  const Expr *const *getArgs() const {
2469
926k
    return reinterpret_cast<Expr **>(SubExprs + getNumPreArgs() +
2470
926k
                                     PREARGS_START);
2471
926k
  }
2472
2473
  /// getArg - Return the specified argument.
2474
10.7M
  Expr *getArg(unsigned Arg) {
2475
10.7M
    assert(Arg < NumArgs && "Arg access out of range!");
2476
10.7M
    return cast_or_null<Expr>(SubExprs[Arg + getNumPreArgs() + PREARGS_START]);
2477
10.7M
  }
2478
2.52M
  const Expr *getArg(unsigned Arg) const {
2479
2.52M
    assert(Arg < NumArgs && "Arg access out of range!");
2480
2.52M
    return cast_or_null<Expr>(SubExprs[Arg + getNumPreArgs() + PREARGS_START]);
2481
2.52M
  }
2482
2483
  /// setArg - Set the specified argument.
2484
7.38M
  void setArg(unsigned Arg, Expr *ArgExpr) {
2485
7.38M
    assert(Arg < NumArgs && "Arg access out of range!");
2486
7.38M
    SubExprs[Arg+getNumPreArgs()+PREARGS_START] = ArgExpr;
2487
7.38M
  }
2488
2489
  /// setNumArgs - This changes the number of arguments present in this call.
2490
  /// Any orphaned expressions are deleted by this, and any new operands are set
2491
  /// to null.
2492
  void setNumArgs(const ASTContext& C, unsigned NumArgs);
2493
2494
  typedef ExprIterator arg_iterator;
2495
  typedef ConstExprIterator const_arg_iterator;
2496
  typedef llvm::iterator_range<arg_iterator> arg_range;
2497
  typedef llvm::iterator_range<const_arg_iterator> const_arg_range;
2498
2499
11.5k
  arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
2500
847k
  const_arg_range arguments() const {
2501
847k
    return const_arg_range(arg_begin(), arg_end());
2502
847k
  }
2503
2504
2.86M
  arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); }
2505
2.86M
  arg_iterator arg_end() {
2506
2.86M
    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2507
2.86M
  }
2508
858k
  const_arg_iterator arg_begin() const {
2509
858k
    return SubExprs+PREARGS_START+getNumPreArgs();
2510
858k
  }
2511
853k
  const_arg_iterator arg_end() const {
2512
853k
    return SubExprs+PREARGS_START+getNumPreArgs()+getNumArgs();
2513
853k
  }
2514
2515
  /// This method provides fast access to all the subexpressions of
2516
  /// a CallExpr without going through the slower virtual child_iterator
2517
  /// interface.  This provides efficient reverse iteration of the
2518
  /// subexpressions.  This is currently used for CFG construction.
2519
724k
  ArrayRef<Stmt*> getRawSubExprs() {
2520
724k
    return llvm::makeArrayRef(SubExprs,
2521
724k
                              getNumPreArgs() + PREARGS_START + getNumArgs());
2522
724k
  }
2523
2524
  /// getNumCommas - Return the number of commas that must have been present in
2525
  /// this function call.
2526
0
  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
2527
2528
  /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID
2529
  /// of the callee. If not, return 0.
2530
  unsigned getBuiltinCallee() const;
2531
2532
  /// Returns \c true if this is a call to a builtin which does not
2533
  /// evaluate side-effects within its arguments.
2534
  bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const;
2535
2536
  /// getCallReturnType - Get the return type of the call expr. This is not
2537
  /// always the type of the expr itself, if the return type is a reference
2538
  /// type.
2539
  QualType getCallReturnType(const ASTContext &Ctx) const;
2540
2541
6.86M
  SourceLocation getRParenLoc() const { return RParenLoc; }
2542
4.55k
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2543
2544
  SourceLocation getBeginLoc() const LLVM_READONLY;
2545
  SourceLocation getEndLoc() const LLVM_READONLY;
2546
2547
  /// Return true if this is a call to __assume() or __builtin_assume() with
2548
  /// a non-value-dependent constant parameter evaluating as false.
2549
  bool isBuiltinAssumeFalse(const ASTContext &Ctx) const;
2550
2551
537k
  bool isCallToStdMove() const {
2552
537k
    const FunctionDecl* FD = getDirectCallee();
2553
537k
    return getNumArgs() == 1 && 
FD140k
&&
FD->isInStdNamespace()127k
&&
2554
537k
           
FD->getIdentifier()1.91k
&&
FD->getIdentifier()->isStr("move")1.88k
;
2555
537k
  }
2556
2557
69.4M
  static bool classof(const Stmt *T) {
2558
69.4M
    return T->getStmtClass() >= firstCallExprConstant &&
2559
69.4M
           
T->getStmtClass() <= lastCallExprConstant57.8M
;
2560
69.4M
  }
2561
2562
  // Iterators
2563
8.02M
  child_range children() {
2564
8.02M
    return child_range(&SubExprs[0],
2565
8.02M
                       &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START);
2566
8.02M
  }
2567
2568
0
  const_child_range children() const {
2569
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + NumArgs +
2570
0
                                               getNumPreArgs() + PREARGS_START);
2571
0
  }
2572
};
2573
2574
/// Extra data stored in some MemberExpr objects.
2575
struct MemberExprNameQualifier {
2576
  /// The nested-name-specifier that qualifies the name, including
2577
  /// source-location information.
2578
  NestedNameSpecifierLoc QualifierLoc;
2579
2580
  /// The DeclAccessPair through which the MemberDecl was found due to
2581
  /// name qualifiers.
2582
  DeclAccessPair FoundDecl;
2583
};
2584
2585
/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
2586
///
2587
class MemberExpr final
2588
    : public Expr,
2589
      private llvm::TrailingObjects<MemberExpr, MemberExprNameQualifier,
2590
                                    ASTTemplateKWAndArgsInfo,
2591
                                    TemplateArgumentLoc> {
2592
  friend class ASTReader;
2593
  friend class ASTStmtWriter;
2594
  friend TrailingObjects;
2595
2596
  /// Base - the expression for the base pointer or structure references.  In
2597
  /// X.F, this is "X".
2598
  Stmt *Base;
2599
2600
  /// MemberDecl - This is the decl being referenced by the field/member name.
2601
  /// In X.F, this is the decl referenced by F.
2602
  ValueDecl *MemberDecl;
2603
2604
  /// MemberDNLoc - Provides source/type location info for the
2605
  /// declaration name embedded in MemberDecl.
2606
  DeclarationNameLoc MemberDNLoc;
2607
2608
  /// MemberLoc - This is the location of the member name.
2609
  SourceLocation MemberLoc;
2610
2611
7.43k
  size_t numTrailingObjects(OverloadToken<MemberExprNameQualifier>) const {
2612
7.43k
    return hasQualifierOrFoundDecl();
2613
7.43k
  }
2614
2615
1.80k
  size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const {
2616
1.80k
    return hasTemplateKWAndArgsInfo();
2617
1.80k
  }
2618
2619
9.73M
  bool hasQualifierOrFoundDecl() const {
2620
9.73M
    return MemberExprBits.HasQualifierOrFoundDecl;
2621
9.73M
  }
2622
2623
1.97M
  bool hasTemplateKWAndArgsInfo() const {
2624
1.97M
    return MemberExprBits.HasTemplateKWAndArgsInfo;
2625
1.97M
  }
2626
2627
public:
2628
  MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc,
2629
             ValueDecl *memberdecl, const DeclarationNameInfo &NameInfo,
2630
             QualType ty, ExprValueKind VK, ExprObjectKind OK)
2631
      : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(),
2632
             base->isValueDependent(), base->isInstantiationDependent(),
2633
             base->containsUnexpandedParameterPack()),
2634
        Base(base), MemberDecl(memberdecl), MemberDNLoc(NameInfo.getInfo()),
2635
2.82M
        MemberLoc(NameInfo.getLoc()) {
2636
2.82M
    assert(memberdecl->getDeclName() == NameInfo.getName());
2637
2.82M
    MemberExprBits.IsArrow = isarrow;
2638
2.82M
    MemberExprBits.HasQualifierOrFoundDecl = false;
2639
2.82M
    MemberExprBits.HasTemplateKWAndArgsInfo = false;
2640
2.82M
    MemberExprBits.HadMultipleCandidates = false;
2641
2.82M
    MemberExprBits.OperatorLoc = operatorloc;
2642
2.82M
  }
2643
2644
  // NOTE: this constructor should be used only when it is known that
2645
  // the member name can not provide additional syntactic info
2646
  // (i.e., source locations for C++ operator names or type source info
2647
  // for constructors, destructors and conversion operators).
2648
  MemberExpr(Expr *base, bool isarrow, SourceLocation operatorloc,
2649
             ValueDecl *memberdecl, SourceLocation l, QualType ty,
2650
             ExprValueKind VK, ExprObjectKind OK)
2651
      : Expr(MemberExprClass, ty, VK, OK, base->isTypeDependent(),
2652
             base->isValueDependent(), base->isInstantiationDependent(),
2653
             base->containsUnexpandedParameterPack()),
2654
29.4k
        Base(base), MemberDecl(memberdecl), MemberDNLoc(), MemberLoc(l) {
2655
29.4k
    MemberExprBits.IsArrow = isarrow;
2656
29.4k
    MemberExprBits.HasQualifierOrFoundDecl = false;
2657
29.4k
    MemberExprBits.HasTemplateKWAndArgsInfo = false;
2658
29.4k
    MemberExprBits.HadMultipleCandidates = false;
2659
29.4k
    MemberExprBits.OperatorLoc = operatorloc;
2660
29.4k
  }
2661
2662
  static MemberExpr *Create(const ASTContext &C, Expr *base, bool isarrow,
2663
                            SourceLocation OperatorLoc,
2664
                            NestedNameSpecifierLoc QualifierLoc,
2665
                            SourceLocation TemplateKWLoc, ValueDecl *memberdecl,
2666
                            DeclAccessPair founddecl,
2667
                            DeclarationNameInfo MemberNameInfo,
2668
                            const TemplateArgumentListInfo *targs, QualType ty,
2669
                            ExprValueKind VK, ExprObjectKind OK);
2670
2671
512k
  void setBase(Expr *E) { Base = E; }
2672
42.0M
  Expr *getBase() const { return cast<Expr>(Base); }
2673
2674
  /// Retrieve the member declaration to which this expression refers.
2675
  ///
2676
  /// The returned declaration will be a FieldDecl or (in C++) a VarDecl (for
2677
  /// static data members), a CXXMethodDecl, or an EnumConstantDecl.
2678
20.6M
  ValueDecl *getMemberDecl() const { return MemberDecl; }
2679
  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
2680
2681
  /// Retrieves the declaration found by lookup.
2682
651k
  DeclAccessPair getFoundDecl() const {
2683
651k
    if (!hasQualifierOrFoundDecl())
2684
638k
      return DeclAccessPair::make(getMemberDecl(),
2685
638k
                                  getMemberDecl()->getAccess());
2686
13.1k
    return getTrailingObjects<MemberExprNameQualifier>()->FoundDecl;
2687
13.1k
  }
2688
2689
  /// Determines whether this member expression actually had
2690
  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
2691
  /// x->Base::foo.
2692
8.59M
  bool hasQualifier() const { return getQualifier() != nullptr; }
2693
2694
  /// If the member name was qualified, retrieves the
2695
  /// nested-name-specifier that precedes the member name, with source-location
2696
  /// information.
2697
9.07M
  NestedNameSpecifierLoc getQualifierLoc() const {
2698
9.07M
    if (!hasQualifierOrFoundDecl())
2699
8.78M
      return NestedNameSpecifierLoc();
2700
283k
    return getTrailingObjects<MemberExprNameQualifier>()->QualifierLoc;
2701
283k
  }
2702
2703
  /// If the member name was qualified, retrieves the
2704
  /// nested-name-specifier that precedes the member name. Otherwise, returns
2705
  /// NULL.
2706
8.98M
  NestedNameSpecifier *getQualifier() const {
2707
8.98M
    return getQualifierLoc().getNestedNameSpecifier();
2708
8.98M
  }
2709
2710
  /// Retrieve the location of the template keyword preceding
2711
  /// the member name, if any.
2712
270k
  SourceLocation getTemplateKeywordLoc() const {
2713
270k
    if (!hasTemplateKWAndArgsInfo())
2714
270k
      return SourceLocation();
2715
31
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc;
2716
31
  }
2717
2718
  /// Retrieve the location of the left angle bracket starting the
2719
  /// explicit template argument list following the member name, if any.
2720
1.69M
  SourceLocation getLAngleLoc() const {
2721
1.69M
    if (!hasTemplateKWAndArgsInfo())
2722
1.68M
      return SourceLocation();
2723
1.96k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc;
2724
1.96k
  }
2725
2726
  /// Retrieve the location of the right angle bracket ending the
2727
  /// explicit template argument list following the member name, if any.
2728
1.81k
  SourceLocation getRAngleLoc() const {
2729
1.81k
    if (!hasTemplateKWAndArgsInfo())
2730
50
      return SourceLocation();
2731
1.76k
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc;
2732
1.76k
  }
2733
2734
  /// Determines whether the member name was preceded by the template keyword.
2735
4.23k
  bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); }
2736
2737
  /// Determines whether the member name was followed by an
2738
  /// explicit template argument list.
2739
1.69M
  bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); }
2740
2741
  /// Copies the template arguments (if present) into the given
2742
  /// structure.
2743
  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
2744
    if (hasExplicitTemplateArgs())
2745
      getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto(
2746
          getTrailingObjects<TemplateArgumentLoc>(), List);
2747
  }
2748
2749
  /// Retrieve the template arguments provided as part of this
2750
  /// template-id.
2751
18.7k
  const TemplateArgumentLoc *getTemplateArgs() const {
2752
18.7k
    if (!hasExplicitTemplateArgs())
2753
18.7k
      return nullptr;
2754
57
2755
57
    return getTrailingObjects<TemplateArgumentLoc>();
2756
57
  }
2757
2758
  /// Retrieve the number of template arguments provided as part of this
2759
  /// template-id.
2760
18.7k
  unsigned getNumTemplateArgs() const {
2761
18.7k
    if (!hasExplicitTemplateArgs())
2762
18.7k
      return 0;
2763
57
2764
57
    return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs;
2765
57
  }
2766
2767
9
  ArrayRef<TemplateArgumentLoc> template_arguments() const {
2768
9
    return {getTemplateArgs(), getNumTemplateArgs()};
2769
9
  }
2770
2771
  /// Retrieve the member declaration name info.
2772
1.40M
  DeclarationNameInfo getMemberNameInfo() const {
2773
1.40M
    return DeclarationNameInfo(MemberDecl->getDeclName(),
2774
1.40M
                               MemberLoc, MemberDNLoc);
2775
1.40M
  }
2776
2777
6.53k
  SourceLocation getOperatorLoc() const { return MemberExprBits.OperatorLoc; }
2778
2779
4.41M
  bool isArrow() const { return MemberExprBits.IsArrow; }
2780
  void setArrow(bool A) { MemberExprBits.IsArrow = A; }
2781
2782
  /// getMemberLoc - Return the location of the "member", in X->F, it is the
2783
  /// location of 'F'.
2784
6.45M
  SourceLocation getMemberLoc() const { return MemberLoc; }
2785
  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
2786
2787
  SourceLocation getBeginLoc() const LLVM_READONLY;
2788
  SourceLocation getEndLoc() const LLVM_READONLY;
2789
2790
6.59M
  SourceLocation getExprLoc() const LLVM_READONLY { return MemberLoc; }
2791
2792
  /// Determine whether the base of this explicit is implicit.
2793
11.6M
  bool isImplicitAccess() const {
2794
11.6M
    return getBase() && getBase()->isImplicitCXXThis();
2795
11.6M
  }
2796
2797
  /// Returns true if this member expression refers to a method that
2798
  /// was resolved from an overloaded set having size greater than 1.
2799
6.47k
  bool hadMultipleCandidates() const {
2800
6.47k
    return MemberExprBits.HadMultipleCandidates;
2801
6.47k
  }
2802
  /// Sets the flag telling whether this expression refers to
2803
  /// a method that was resolved from an overloaded set having size
2804
  /// greater than 1.
2805
160k
  void setHadMultipleCandidates(bool V = true) {
2806
160k
    MemberExprBits.HadMultipleCandidates = V;
2807
160k
  }
2808
2809
  /// Returns true if virtual dispatch is performed.
2810
  /// If the member access is fully qualified, (i.e. X::f()), virtual
2811
  /// dispatching is not performed. In -fapple-kext mode qualified
2812
  /// calls to virtual method will still go through the vtable.
2813
2.88M
  bool performsVirtualDispatch(const LangOptions &LO) const {
2814
2.88M
    return LO.AppleKext || 
!hasQualifier()2.88M
;
2815
2.88M
  }
2816
2817
48.0M
  static bool classof(const Stmt *T) {
2818
48.0M
    return T->getStmtClass() == MemberExprClass;
2819
48.0M
  }
2820
2821
  // Iterators
2822
2.69M
  child_range children() { return child_range(&Base, &Base+1); }
2823
0
  const_child_range children() const {
2824
0
    return const_child_range(&Base, &Base + 1);
2825
0
  }
2826
};
2827
2828
/// CompoundLiteralExpr - [C99 6.5.2.5]
2829
///
2830
class CompoundLiteralExpr : public Expr {
2831
  /// LParenLoc - If non-null, this is the location of the left paren in a
2832
  /// compound literal like "(int){4}".  This can be null if this is a
2833
  /// synthesized compound expression.
2834
  SourceLocation LParenLoc;
2835
2836
  /// The type as written.  This can be an incomplete array type, in
2837
  /// which case the actual expression type will be different.
2838
  /// The int part of the pair stores whether this expr is file scope.
2839
  llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfoAndScope;
2840
  Stmt *Init;
2841
public:
2842
  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
2843
                      QualType T, ExprValueKind VK, Expr *init, bool fileScope)
2844
    : Expr(CompoundLiteralExprClass, T, VK, OK_Ordinary,
2845
           tinfo->getType()->isDependentType(),
2846
           init->isValueDependent(),
2847
           (init->isInstantiationDependent() ||
2848
            tinfo->getType()->isInstantiationDependentType()),
2849
           init->containsUnexpandedParameterPack()),
2850
29.8k
      LParenLoc(lparenloc), TInfoAndScope(tinfo, fileScope), Init(init) {}
2851
2852
  /// Construct an empty compound literal.
2853
  explicit CompoundLiteralExpr(EmptyShell Empty)
2854
4
    : Expr(CompoundLiteralExprClass, Empty) { }
2855
2856
3.85k
  const Expr *getInitializer() const { return cast<Expr>(Init); }
2857
678
  Expr *getInitializer() { return cast<Expr>(Init); }
2858
4
  void setInitializer(Expr *E) { Init = E; }
2859
2860
3.55k
  bool isFileScope() const { return TInfoAndScope.getInt(); }
2861
4
  void setFileScope(bool FS) { TInfoAndScope.setInt(FS); }
2862
2863
561
  SourceLocation getLParenLoc() const { return LParenLoc; }
2864
4
  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2865
2866
687
  TypeSourceInfo *getTypeSourceInfo() const {
2867
687
    return TInfoAndScope.getPointer();
2868
687
  }
2869
4
  void setTypeSourceInfo(TypeSourceInfo *tinfo) {
2870
4
    TInfoAndScope.setPointer(tinfo);
2871
4
  }
2872
2873
83.8k
  SourceLocation getBeginLoc() const LLVM_READONLY {
2874
83.8k
    // FIXME: Init should never be null.
2875
83.8k
    if (!Init)
2876
0
      return SourceLocation();
2877
83.8k
    if (LParenLoc.isInvalid())
2878
99
      return Init->getBeginLoc();
2879
83.7k
    return LParenLoc;
2880
83.7k
  }
2881
7.82k
  SourceLocation getEndLoc() const LLVM_READONLY {
2882
7.82k
    // FIXME: Init should never be null.
2883
7.82k
    if (!Init)
2884
0
      return SourceLocation();
2885
7.82k
    return Init->getEndLoc();
2886
7.82k
  }
2887
2888
6.28k
  static bool classof(const Stmt *T) {
2889
6.28k
    return T->getStmtClass() == CompoundLiteralExprClass;
2890
6.28k
  }
2891
2892
  // Iterators
2893
62.4k
  child_range children() { return child_range(&Init, &Init+1); }
2894
0
  const_child_range children() const {
2895
0
    return const_child_range(&Init, &Init + 1);
2896
0
  }
2897
};
2898
2899
/// CastExpr - Base class for type casts, including both implicit
2900
/// casts (ImplicitCastExpr) and explicit casts that have some
2901
/// representation in the source code (ExplicitCastExpr's derived
2902
/// classes).
2903
class CastExpr : public Expr {
2904
public:
2905
  using BasePathSizeTy = unsigned int;
2906
  static_assert(std::numeric_limits<BasePathSizeTy>::max() >= 16384,
2907
                "[implimits] Direct and indirect base classes [16384].");
2908
2909
private:
2910
  Stmt *Op;
2911
2912
  bool CastConsistency() const;
2913
2914
  BasePathSizeTy *BasePathSize();
2915
2916
179k
  const CXXBaseSpecifier * const *path_buffer() const {
2917
179k
    return const_cast<CastExpr*>(this)->path_buffer();
2918
179k
  }
2919
  CXXBaseSpecifier **path_buffer();
2920
2921
182k
  void setBasePathSize(BasePathSizeTy basePathSize) {
2922
182k
    assert(!path_empty() && basePathSize != 0);
2923
182k
    *(BasePathSize()) = basePathSize;
2924
182k
  }
2925
2926
protected:
2927
  CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, const CastKind kind,
2928
           Expr *op, unsigned BasePathSize)
2929
      : Expr(SC, ty, VK, OK_Ordinary,
2930
             // Cast expressions are type-dependent if the type is
2931
             // dependent (C++ [temp.dep.expr]p3).
2932
             ty->isDependentType(),
2933
             // Cast expressions are value-dependent if the type is
2934
             // dependent or if the subexpression is value-dependent.
2935
             ty->isDependentType() || (op && op->isValueDependent()),
2936
             (ty->isInstantiationDependentType() ||
2937
              (op && op->isInstantiationDependent())),
2938
             // An implicit cast expression doesn't (lexically) contain an
2939
             // unexpanded pack, even if its target type does.
2940
             ((SC != ImplicitCastExprClass &&
2941
               ty->containsUnexpandedParameterPack()) ||
2942
              (op && op->containsUnexpandedParameterPack()))),
2943
23.0M
        Op(op) {
2944
23.0M
    CastExprBits.Kind = kind;
2945
23.0M
    CastExprBits.PartOfExplicitCast = false;
2946
23.0M
    CastExprBits.BasePathIsEmpty = BasePathSize == 0;
2947
23.0M
    if (!path_empty())
2948
182k
      setBasePathSize(BasePathSize);
2949
23.0M
    assert(CastConsistency());
2950
23.0M
  }
2951
2952
  /// Construct an empty cast.
2953
  CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
2954
104k
    : Expr(SC, Empty) {
2955
104k
    CastExprBits.PartOfExplicitCast = false;
2956
104k
    CastExprBits.BasePathIsEmpty = BasePathSize == 0;
2957
104k
    if (!path_empty())
2958
579
      setBasePathSize(BasePathSize);
2959
104k
  }
2960
2961
public:
2962
86.6M
  CastKind getCastKind() const { return (CastKind) CastExprBits.Kind; }
2963
104k
  void setCastKind(CastKind K) { CastExprBits.Kind = K; }
2964
2965
  static const char *getCastKindName(CastKind CK);
2966
2.60k
  const char *getCastKindName() const { return getCastKindName(getCastKind()); }
2967
2968
93.6M
  Expr *getSubExpr() { return cast<Expr>(Op); }
2969
100M
  const Expr *getSubExpr() const { return cast<Expr>(Op); }
2970
105k
  void setSubExpr(Expr *E) { Op = E; }
2971
2972
  /// Retrieve the cast subexpression as it was written in the source
2973
  /// code, looking through any implicit casts or other intermediate nodes
2974
  /// introduced by semantic analysis.
2975
  Expr *getSubExprAsWritten();
2976
291k
  const Expr *getSubExprAsWritten() const {
2977
291k
    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
2978
291k
  }
2979
2980
  /// If this cast applies a user-defined conversion, retrieve the conversion
2981
  /// function that it invokes.
2982
  NamedDecl *getConversionFunction() const;
2983
2984
  typedef CXXBaseSpecifier **path_iterator;
2985
  typedef const CXXBaseSpecifier * const *path_const_iterator;
2986
24.9M
  bool path_empty() const { return CastExprBits.BasePathIsEmpty; }
2987
790k
  unsigned path_size() const {
2988
790k
    if (path_empty())
2989
697k
      return 0U;
2990
93.5k
    return *(const_cast<CastExpr *>(this)->BasePathSize());
2991
93.5k
  }
2992
359k
  path_iterator path_begin() { return path_buffer(); }
2993
255k
  path_iterator path_end() { return path_buffer() + path_size(); }
2994
89.6k
  path_const_iterator path_begin() const { return path_buffer(); }
2995
89.6k
  path_const_iterator path_end() const { return path_buffer() + path_size(); }
2996
2997
4
  const FieldDecl *getTargetUnionField() const {
2998
4
    assert(getCastKind() == CK_ToUnion);
2999
4
    return getTargetFieldForToUnionCast(getType(), getSubExpr()->getType());
3000
4
  }
3001
3002
  static const FieldDecl *getTargetFieldForToUnionCast(QualType unionType,
3003
                                                       QualType opType);
3004
  static const FieldDecl *getTargetFieldForToUnionCast(const RecordDecl *RD,
3005
                                                       QualType opType);
3006
3007
110M
  static bool classof(const Stmt *T) {
3008
110M
    return T->getStmtClass() >= firstCastExprConstant &&
3009
110M
           
T->getStmtClass() <= lastCastExprConstant96.1M
;
3010
110M
  }
3011
3012
  // Iterators
3013
27.1M
  child_range children() { return child_range(&Op, &Op+1); }
3014
0
  const_child_range children() const { return const_child_range(&Op, &Op + 1); }
3015
};
3016
3017
/// ImplicitCastExpr - Allows us to explicitly represent implicit type
3018
/// conversions, which have no direct representation in the original
3019
/// source code. For example: converting T[]->T*, void f()->void
3020
/// (*f)(), float->double, short->int, etc.
3021
///
3022
/// In C, implicit casts always produce rvalues. However, in C++, an
3023
/// implicit cast whose result is being bound to a reference will be
3024
/// an lvalue or xvalue. For example:
3025
///
3026
/// @code
3027
/// class Base { };
3028
/// class Derived : public Base { };
3029
/// Derived &&ref();
3030
/// void f(Derived d) {
3031
///   Base& b = d; // initializer is an ImplicitCastExpr
3032
///                // to an lvalue of type Base
3033
///   Base&& r = ref(); // initializer is an ImplicitCastExpr
3034
///                     // to an xvalue of type Base
3035
/// }
3036
/// @endcode
3037
class ImplicitCastExpr final
3038
    : public CastExpr,
3039
      private llvm::TrailingObjects<ImplicitCastExpr, CastExpr::BasePathSizeTy,
3040
                                    CXXBaseSpecifier *> {
3041
845k
  size_t numTrailingObjects(OverloadToken<CastExpr::BasePathSizeTy>) const {
3042
845k
    return path_empty() ? 
0487k
:
1357k
;
3043
845k
  }
3044
3045
private:
3046
  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
3047
                   unsigned BasePathLength, ExprValueKind VK)
3048
18.6M
    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { }
3049
3050
  /// Construct an empty implicit cast.
3051
  explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
3052
103k
    : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
3053
3054
public:
3055
  enum OnStack_t { OnStack };
3056
  ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op,
3057
                   ExprValueKind VK)
3058
1.10M
    : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, 0) {
3059
1.10M
  }
3060
3061
194k
  bool isPartOfExplicitCast() const { return CastExprBits.PartOfExplicitCast; }
3062
2.01M
  void setIsPartOfExplicitCast(bool PartOfExplicitCast) {
3063
2.01M
    CastExprBits.PartOfExplicitCast = PartOfExplicitCast;
3064
2.01M
  }
3065
3066
  static ImplicitCastExpr *Create(const ASTContext &Context, QualType T,
3067
                                  CastKind Kind, Expr *Operand,
3068
                                  const CXXCastPath *BasePath,
3069
                                  ExprValueKind Cat);
3070
3071
  static ImplicitCastExpr *CreateEmpty(const ASTContext &Context,
3072
                                       unsigned PathSize);
3073
3074
53.0M
  SourceLocation getBeginLoc() const LLVM_READONLY {
3075
53.0M
    return getSubExpr()->getBeginLoc();
3076
53.0M
  }
3077
4.72M
  SourceLocation getEndLoc() const LLVM_READONLY {
3078
4.72M
    return getSubExpr()->getEndLoc();
3079
4.72M
  }
3080
3081
231M
  static bool classof(const Stmt *T) {
3082
231M
    return T->getStmtClass() == ImplicitCastExprClass;
3083
231M
  }
3084
3085
  friend TrailingObjects;
3086
  friend class CastExpr;
3087
};
3088
3089
6.50M
inline Expr *Expr::IgnoreImpCasts() {
3090
6.50M
  Expr *e = this;
3091
9.51M
  while (true)
3092
9.51M
    if (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
3093
3.00M
      e = ice->getSubExpr();
3094
6.50M
    else if (ConstantExpr *ce = dyn_cast<ConstantExpr>(e))
3095
333
      e = ce->getSubExpr();
3096
6.50M
    else
3097
6.50M
      break;
3098
6.50M
  return e;
3099
6.50M
}
3100
3101
/// ExplicitCastExpr - An explicit cast written in the source
3102
/// code.
3103
///
3104
/// This class is effectively an abstract class, because it provides
3105
/// the basic representation of an explicitly-written cast without
3106
/// specifying which kind of cast (C cast, functional cast, static
3107
/// cast, etc.) was written; specific derived classes represent the
3108
/// particular style of cast and its location information.
3109
///
3110
/// Unlike implicit casts, explicit cast nodes have two different
3111
/// types: the type that was written into the source code, and the
3112
/// actual type of the expression as determined by semantic
3113
/// analysis. These types may differ slightly. For example, in C++ one
3114
/// can cast to a reference type, which indicates that the resulting
3115
/// expression will be an lvalue or xvalue. The reference type, however,
3116
/// will not be used as the type of the expression.
3117
class ExplicitCastExpr : public CastExpr {
3118
  /// TInfo - Source type info for the (written) type
3119
  /// this expression is casting to.
3120
  TypeSourceInfo *TInfo;
3121
3122
protected:
3123
  ExplicitCastExpr(StmtClass SC, QualType exprTy, ExprValueKind VK,
3124
                   CastKind kind, Expr *op, unsigned PathSize,
3125
                   TypeSourceInfo *writtenTy)
3126
3.32M
    : CastExpr(SC, exprTy, VK, kind, op, PathSize), TInfo(writtenTy) {}
3127
3128
  /// Construct an empty explicit cast.
3129
  ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
3130
1.04k
    : CastExpr(SC, Shell, PathSize) { }
3131
3132
public:
3133
  /// getTypeInfoAsWritten - Returns the type source info for the type
3134
  /// that this expression is casting to.
3135
706k
  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
3136
1.04k
  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
3137
3138
  /// getTypeAsWritten - Returns the type that this expression is
3139
  /// casting to, as written in the source code.
3140
283k
  QualType getTypeAsWritten() const { return TInfo->getType(); }
3141
3142
45.5M
  static bool classof(const Stmt *T) {
3143
45.5M
     return T->getStmtClass() >= firstExplicitCastExprConstant &&
3144
45.5M
            
T->getStmtClass() <= lastExplicitCastExprConstant34.8M
;
3145
45.5M
  }
3146
};
3147
3148
/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
3149
/// cast in C++ (C++ [expr.cast]), which uses the syntax
3150
/// (Type)expr. For example: @c (int)f.
3151
class CStyleCastExpr final
3152
    : public ExplicitCastExpr,
3153
      private llvm::TrailingObjects<CStyleCastExpr, CastExpr::BasePathSizeTy,
3154
                                    CXXBaseSpecifier *> {
3155
  SourceLocation LPLoc; // the location of the left paren
3156
  SourceLocation RPLoc; // the location of the right paren
3157
3158
  CStyleCastExpr(QualType exprTy, ExprValueKind vk, CastKind kind, Expr *op,
3159
                 unsigned PathSize, TypeSourceInfo *writtenTy,
3160
                 SourceLocation l, SourceLocation r)
3161
    : ExplicitCastExpr(CStyleCastExprClass, exprTy, vk, kind, op, PathSize,
3162
2.98M
                       writtenTy), LPLoc(l), RPLoc(r) {}
3163
3164
  /// Construct an empty C-style explicit cast.
3165
  explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
3166
950
    : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
3167
3168
121k
  size_t numTrailingObjects(OverloadToken<CastExpr::BasePathSizeTy>) const {
3169
121k
    return path_empty() ? 
0120k
:
1672
;
3170
121k
  }
3171
3172
public:
3173
  static CStyleCastExpr *Create(const ASTContext &Context, QualType T,
3174
                                ExprValueKind VK, CastKind K,
3175
                                Expr *Op, const CXXCastPath *BasePath,
3176
                                TypeSourceInfo *WrittenTy, SourceLocation L,
3177
                                SourceLocation R);
3178
3179
  static CStyleCastExpr *CreateEmpty(const ASTContext &Context,
3180
                                     unsigned PathSize);
3181
3182
134k
  SourceLocation getLParenLoc() const { return LPLoc; }
3183
950
  void setLParenLoc(SourceLocation L) { LPLoc = L; }
3184
3185
133k
  SourceLocation getRParenLoc() const { return RPLoc; }
3186
950
  void setRParenLoc(SourceLocation L) { RPLoc = L; }
3187
3188
12.2M
  SourceLocation getBeginLoc() const LLVM_READONLY { return LPLoc; }
3189
101k
  SourceLocation getEndLoc() const LLVM_READONLY {
3190
101k
    return getSubExpr()->getEndLoc();
3191
101k
  }
3192
3193
1.50M
  static bool classof(const Stmt *T) {
3194
1.50M
    return T->getStmtClass() == CStyleCastExprClass;
3195
1.50M
  }
3196
3197
  friend TrailingObjects;
3198
  friend class CastExpr;
3199
};
3200
3201
/// A builtin binary operation expression such as "x + y" or "x <= y".
3202
///
3203
/// This expression node kind describes a builtin binary operation,
3204
/// such as "x + y" for integer values "x" and "y". The operands will
3205
/// already have been converted to appropriate types (e.g., by
3206
/// performing promotions or conversions).
3207
///
3208
/// In C++, where operators may be overloaded, a different kind of
3209
/// expression node (CXXOperatorCallExpr) is used to express the
3210
/// invocation of an overloaded operator with operator syntax. Within
3211
/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
3212
/// used to store an expression "x + y" depends on the subexpressions
3213
/// for x and y. If neither x or y is type-dependent, and the "+"
3214
/// operator resolves to a built-in operation, BinaryOperator will be
3215
/// used to express the computation (x and y may still be
3216
/// value-dependent). If either x or y is type-dependent, or if the
3217
/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
3218
/// be used to express the computation.
3219
class BinaryOperator : public Expr {
3220
  enum { LHS, RHS, END_EXPR };
3221
  Stmt *SubExprs[END_EXPR];
3222
3223
public:
3224
  typedef BinaryOperatorKind Opcode;
3225
3226
  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
3227
                 ExprValueKind VK, ExprObjectKind OK,
3228
                 SourceLocation opLoc, FPOptions FPFeatures)
3229
    : Expr(BinaryOperatorClass, ResTy, VK, OK,
3230
           lhs->isTypeDependent() || rhs->isTypeDependent(),
3231
           lhs->isValueDependent() || rhs->isValueDependent(),
3232
           (lhs->isInstantiationDependent() ||
3233
            rhs->isInstantiationDependent()),
3234
           (lhs->containsUnexpandedParameterPack() ||
3235
6.51M
            rhs->containsUnexpandedParameterPack())) {
3236
6.51M
    BinaryOperatorBits.Opc = opc;
3237
6.51M
    BinaryOperatorBits.FPFeatures = FPFeatures.getInt();
3238
6.51M
    BinaryOperatorBits.OpLoc = opLoc;
3239
6.51M
    SubExprs[LHS] = lhs;
3240
6.51M
    SubExprs[RHS] = rhs;
3241
6.51M
    assert(!isCompoundAssignmentOp() &&
3242
6.51M
           "Use CompoundAssignOperator for compound assignments");
3243
6.51M
  }
3244
3245
  /// Construct an empty binary operator.
3246
104k
  explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) {
3247
104k
    BinaryOperatorBits.Opc = BO_Comma;
3248
104k
  }
3249
3250
11.5M
  SourceLocation getExprLoc() const { return getOperatorLoc(); }
3251
17.4M
  SourceLocation getOperatorLoc() const { return BinaryOperatorBits.OpLoc; }
3252
108k
  void setOperatorLoc(SourceLocation L) { BinaryOperatorBits.OpLoc = L; }
3253
3254
113M
  Opcode getOpcode() const {
3255
113M
    return static_cast<Opcode>(BinaryOperatorBits.Opc);
3256
113M
  }
3257
108k
  void setOpcode(Opcode Opc) { BinaryOperatorBits.Opc = Opc; }
3258
3259
43.2M
  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3260
108k
  void setLHS(Expr *E) { SubExprs[LHS] = E; }
3261
29.6M
  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3262
108k
  void setRHS(Expr *E) { SubExprs[RHS] = E; }
3263
3264
6.62M
  SourceLocation getBeginLoc() const LLVM_READONLY {
3265
6.62M
    return getLHS()->getBeginLoc();
3266
6.62M
  }
3267
772k
  SourceLocation getEndLoc() const LLVM_READONLY {
3268
772k
    return getRHS()->getEndLoc();
3269
772k
  }
3270
3271
  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
3272
  /// corresponds to, e.g. "<<=".
3273
  static StringRef getOpcodeStr(Opcode Op);
3274
3275
1.28k
  StringRef getOpcodeStr() const { return getOpcodeStr(getOpcode()); }
3276
3277
  /// Retrieve the binary opcode that corresponds to the given
3278
  /// overloaded operator.
3279
  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
3280
3281
  /// Retrieve the overloaded operator kind that corresponds to
3282
  /// the given binary opcode.
3283
  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
3284
3285
  /// predicates to categorize the respective opcodes.
3286
150k
  static bool isPtrMemOp(Opcode Opc) {
3287
150k
    return Opc == BO_PtrMemD || 
Opc == BO_PtrMemI150k
;
3288
150k
  }
3289
150k
  bool isPtrMemOp() const { return isPtrMemOp(getOpcode()); }
3290
3291
171k
  static bool isMultiplicativeOp(Opcode Opc) {
3292
171k
    return Opc >= BO_Mul && Opc <= BO_Rem;
3293
171k
  }
3294
1.75k
  bool isMultiplicativeOp() const { return isMultiplicativeOp(getOpcode()); }
3295
2.79M
  static bool isAdditiveOp(Opcode Opc) { return Opc == BO_Add || 
Opc==BO_Sub2.36M
; }
3296
2.61M
  bool isAdditiveOp() const { return isAdditiveOp(getOpcode()); }
3297
183k
  static bool isShiftOp(Opcode Opc) { return Opc == BO_Shl || 
Opc == BO_Shr183k
; }
3298
209
  bool isShiftOp() const { return isShiftOp(getOpcode()); }
3299
3300
5.02M
  static bool isBitwiseOp(Opcode Opc) { return Opc >= BO_And && 
Opc <= BO_Or2.12M
; }
3301
17.5k
  bool isBitwiseOp() const { return isBitwiseOp(getOpcode()); }
3302
3303
1.69M
  static bool isRelationalOp(Opcode Opc) { return Opc >= BO_LT && 
Opc<=BO_GE1.68M
; }
3304
446k
  bool isRelationalOp() const { return isRelationalOp(getOpcode()); }
3305
3306
555k
  static bool isEqualityOp(Opcode Opc) { return Opc == BO_EQ || 
Opc == BO_NE365k
; }
3307
495k
  bool isEqualityOp() const { return isEqualityOp(getOpcode()); }
3308
3309
10.2M
  static bool isComparisonOp(Opcode Opc) { return Opc >= BO_Cmp && 
Opc<=BO_NE6.63M
; }
3310
4.97M
  bool isComparisonOp() const { return isComparisonOp(getOpcode()); }
3311
3312
74.0k
  static Opcode negateComparisonOp(Opcode Opc) {
3313
74.0k
    switch (Opc) {
3314
74.0k
    default:
3315
0
      llvm_unreachable("Not a comparison operator.");
3316
74.0k
    
case BO_LT: return BO_GE476
;
3317
74.0k
    
case BO_GT: return BO_LE806
;
3318
74.0k
    
case BO_LE: return BO_GT3.21k
;
3319
74.0k
    
case BO_GE: return BO_LT1.83k
;
3320
74.0k
    
case BO_EQ: return BO_NE2.62k
;
3321
74.0k
    
case BO_NE: return BO_EQ65.1k
;
3322
74.0k
    }
3323
74.0k
  }
3324
3325
1.21k
  static Opcode reverseComparisonOp(Opcode Opc) {
3326
1.21k
    switch (Opc) {
3327
1.21k
    default:
3328
0
      llvm_unreachable("Not a comparison operator.");
3329
1.21k
    
case BO_LT: return BO_GT470
;
3330
1.21k
    
case BO_GT: return BO_LT54
;
3331
1.21k
    
case BO_LE: return BO_GE31
;
3332
1.21k
    
case BO_GE: return BO_LE77
;
3333
1.21k
    case BO_EQ:
3334
585
    case BO_NE:
3335
585
      return Opc;
3336
1.21k
    }
3337
1.21k
  }
3338
3339
23.8M
  static bool isLogicalOp(Opcode Opc) { return Opc == BO_LAnd || 
Opc==BO_LOr22.4M
; }
3340
23.8M
  bool isLogicalOp() const { return isLogicalOp(getOpcode()); }
3341
3342
12.3M
  static bool isAssignmentOp(Opcode Opc) {
3343
12.3M
    return Opc >= BO_Assign && 
Opc <= BO_OrAssign1.61M
;
3344
12.3M
  }
3345
12.3M
  bool isAssignmentOp() const { return isAssignmentOp(getOpcode()); }
3346
3347
777k
  static bool isCompoundAssignmentOp(Opcode Opc) {
3348
777k
    return Opc > BO_Assign && 
Opc <= BO_OrAssign14.4k
;
3349
777k
  }
3350
777k
  bool isCompoundAssignmentOp() const {
3351
777k
    return isCompoundAssignmentOp(getOpcode());
3352
777k
  }
3353
20.3k
  static Opcode getOpForCompoundAssignment(Opcode Opc) {
3354
20.3k
    assert(isCompoundAssignmentOp(Opc));
3355
20.3k
    if (Opc >= BO_AndAssign)
3356
5.04k
      return Opcode(unsigned(Opc) - BO_AndAssign + BO_And);
3357
15.3k
    else
3358
15.3k
      return Opcode(unsigned(Opc) - BO_MulAssign + BO_Mul);
3359
20.3k
  }
3360
3361
  static bool isShiftAssignOp(Opcode Opc) {
3362
    return Opc == BO_ShlAssign || Opc == BO_ShrAssign;
3363
  }
3364
  bool isShiftAssignOp() const {
3365
    return isShiftAssignOp(getOpcode());
3366
  }
3367
3368
  // Return true if a binary operator using the specified opcode and operands
3369
  // would match the 'p = (i8*)nullptr + n' idiom for casting a pointer-sized
3370
  // integer to a pointer.
3371
  static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc,
3372
                                               Expr *LHS, Expr *RHS);
3373
3374
269M
  static bool classof(const Stmt *S) {
3375
269M
    return S->getStmtClass() >= firstBinaryOperatorConstant &&
3376
269M
           
S->getStmtClass() <= lastBinaryOperatorConstant264M
;
3377
269M
  }
3378
3379
  // Iterators
3380
8.67M
  child_range children() {
3381
8.67M
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3382
8.67M
  }
3383
0
  const_child_range children() const {
3384
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3385
0
  }
3386
3387
  // Set the FP contractability status of this operator. Only meaningful for
3388
  // operations on floating point types.
3389
108k
  void setFPFeatures(FPOptions F) {
3390
108k
    BinaryOperatorBits.FPFeatures = F.getInt();
3391
108k
  }
3392
3393
1.63M
  FPOptions getFPFeatures() const {
3394
1.63M
    return FPOptions(BinaryOperatorBits.FPFeatures);
3395
1.63M
  }
3396
3397
  // Get the FP contractability status of this operator. Only meaningful for
3398
  // operations on floating point types.
3399
  bool isFPContractableWithinStatement() const {
3400
    return getFPFeatures().allowFPContractWithinStatement();
3401
  }
3402
3403
  // Get the FENV_ACCESS status of this operator. Only meaningful for
3404
  // operations on floating point types.
3405
  bool isFEnvAccessOn() const { return getFPFeatures().allowFEnvAccess(); }
3406
3407
protected:
3408
  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
3409
                 ExprValueKind VK, ExprObjectKind OK,
3410
                 SourceLocation opLoc, FPOptions FPFeatures, bool dead2)
3411
    : Expr(CompoundAssignOperatorClass, ResTy, VK, OK,
3412
           lhs->isTypeDependent() || rhs->isTypeDependent(),
3413
           lhs->isValueDependent() || rhs->isValueDependent(),
3414
           (lhs->isInstantiationDependent() ||
3415
            rhs->isInstantiationDependent()),
3416
           (lhs->containsUnexpandedParameterPack() ||
3417
202k
            rhs->containsUnexpandedParameterPack())) {
3418
202k
    BinaryOperatorBits.Opc = opc;
3419
202k
    BinaryOperatorBits.FPFeatures = FPFeatures.getInt();
3420
202k
    BinaryOperatorBits.OpLoc = opLoc;
3421
202k
    SubExprs[LHS] = lhs;
3422
202k
    SubExprs[RHS] = rhs;
3423
202k
  }
3424
3425
4.24k
  BinaryOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
3426
4.24k
    BinaryOperatorBits.Opc = BO_MulAssign;
3427
4.24k
  }
3428
};
3429
3430
/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
3431
/// track of the type the operation is performed in.  Due to the semantics of
3432
/// these operators, the operands are promoted, the arithmetic performed, an
3433
/// implicit conversion back to the result type done, then the assignment takes
3434
/// place.  This captures the intermediate type which the computation is done
3435
/// in.
3436
class CompoundAssignOperator : public BinaryOperator {
3437
  QualType ComputationLHSType;
3438
  QualType ComputationResultType;
3439
public:
3440
  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResType,
3441
                         ExprValueKind VK, ExprObjectKind OK,
3442
                         QualType CompLHSType, QualType CompResultType,
3443
                         SourceLocation OpLoc, FPOptions FPFeatures)
3444
    : BinaryOperator(lhs, rhs, opc, ResType, VK, OK, OpLoc, FPFeatures,
3445
                     true),
3446
      ComputationLHSType(CompLHSType),
3447
202k
      ComputationResultType(CompResultType) {
3448
202k
    assert(isCompoundAssignmentOp() &&
3449
202k
           "Only should be used for compound assignments");
3450
202k
  }
3451
3452
  /// Build an empty compound assignment operator expression.
3453
  explicit CompoundAssignOperator(EmptyShell Empty)
3454
4.24k
    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
3455
3456
  // The two computation types are the type the LHS is converted
3457
  // to for the computation and the type of the result; the two are
3458
  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
3459
72.5k
  QualType getComputationLHSType() const { return ComputationLHSType; }
3460
4.24k
  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
3461
3462
240k
  QualType getComputationResultType() const { return ComputationResultType; }
3463
4.24k
  void setComputationResultType(QualType T) { ComputationResultType = T; }
3464
3465
2.27M
  static bool classof(const Stmt *S) {
3466
2.27M
    return S->getStmtClass() == CompoundAssignOperatorClass;
3467
2.27M
  }
3468
};
3469
3470
/// AbstractConditionalOperator - An abstract base class for
3471
/// ConditionalOperator and BinaryConditionalOperator.
3472
class AbstractConditionalOperator : public Expr {
3473
  SourceLocation QuestionLoc, ColonLoc;
3474
  friend class ASTStmtReader;
3475
3476
protected:
3477
  AbstractConditionalOperator(StmtClass SC, QualType T,
3478
                              ExprValueKind VK, ExprObjectKind OK,
3479
                              bool TD, bool VD, bool ID,
3480
                              bool ContainsUnexpandedParameterPack,
3481
                              SourceLocation qloc,
3482
                              SourceLocation cloc)
3483
    : Expr(SC, T, VK, OK, TD, VD, ID, ContainsUnexpandedParameterPack),
3484
232k
      QuestionLoc(qloc), ColonLoc(cloc) {}
3485
3486
  AbstractConditionalOperator(StmtClass SC, EmptyShell Empty)
3487
4.22k
    : Expr(SC, Empty) { }
3488
3489
public:
3490
  // getCond - Return the expression representing the condition for
3491
  //   the ?: operator.
3492
  Expr *getCond() const;
3493
3494
  // getTrueExpr - Return the subexpression representing the value of
3495
  //   the expression if the condition evaluates to true.
3496
  Expr *getTrueExpr() const;
3497
3498
  // getFalseExpr - Return the subexpression representing the value of
3499
  //   the expression if the condition evaluates to false.  This is
3500
  //   the same as getRHS.
3501
  Expr *getFalseExpr() const;
3502
3503
205k
  SourceLocation getQuestionLoc() const { return QuestionLoc; }
3504
34.0k
  SourceLocation getColonLoc() const { return ColonLoc; }
3505
3506
1.77k
  static bool classof(const Stmt *T) {
3507
1.77k
    return T->getStmtClass() == ConditionalOperatorClass ||
3508
1.77k
           
T->getStmtClass() == BinaryConditionalOperatorClass1.75k
;
3509
1.77k
  }
3510
};
3511
3512
/// ConditionalOperator - The ?: ternary operator.  The GNU "missing
3513
/// middle" extension is a BinaryConditionalOperator.
3514
class ConditionalOperator : public AbstractConditionalOperator {
3515
  enum { COND, LHS, RHS, END_EXPR };
3516
  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3517
3518
  friend class ASTStmtReader;
3519
public:
3520
  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
3521
                      SourceLocation CLoc, Expr *rhs,
3522
                      QualType t, ExprValueKind VK, ExprObjectKind OK)
3523
    : AbstractConditionalOperator(ConditionalOperatorClass, t, VK, OK,
3524
           // FIXME: the type of the conditional operator doesn't
3525
           // depend on the type of the conditional, but the standard
3526
           // seems to imply that it could. File a bug!
3527
           (lhs->isTypeDependent() || rhs->isTypeDependent()),
3528
           (cond->isValueDependent() || lhs->isValueDependent() ||
3529
            rhs->isValueDependent()),
3530
           (cond->isInstantiationDependent() ||
3531
            lhs->isInstantiationDependent() ||
3532
            rhs->isInstantiationDependent()),
3533
           (cond->containsUnexpandedParameterPack() ||
3534
            lhs->containsUnexpandedParameterPack() ||
3535
            rhs->containsUnexpandedParameterPack()),
3536
231k
                                  QLoc, CLoc) {
3537
231k
    SubExprs[COND] = cond;
3538
231k
    SubExprs[LHS] = lhs;
3539
231k
    SubExprs[RHS] = rhs;
3540
231k
  }
3541
3542
  /// Build an empty conditional operator.
3543
  explicit ConditionalOperator(EmptyShell Empty)
3544
4.22k
    : AbstractConditionalOperator(ConditionalOperatorClass, Empty) { }
3545
3546
  // getCond - Return the expression representing the condition for
3547
  //   the ?: operator.
3548
1.51M
  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3549
3550
  // getTrueExpr - Return the subexpression representing the value of
3551
  //   the expression if the condition evaluates to true.
3552
603k
  Expr *getTrueExpr() const { return cast<Expr>(SubExprs[LHS]); }
3553
3554
  // getFalseExpr - Return the subexpression representing the value of
3555
  //   the expression if the condition evaluates to false.  This is
3556
  //   the same as getRHS.
3557
609k
  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
3558
3559
207k
  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3560
215k
  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3561
3562
522k
  SourceLocation getBeginLoc() const LLVM_READONLY {
3563
522k
    return getCond()->getBeginLoc();
3564
522k
  }
3565
6.72k
  SourceLocation getEndLoc() const LLVM_READONLY {
3566
6.72k
    return getRHS()->getEndLoc();
3567
6.72k
  }
3568
3569
39.3M
  static bool classof(const Stmt *T) {
3570
39.3M
    return T->getStmtClass() == ConditionalOperatorClass;
3571
39.3M
  }
3572
3573
  // Iterators
3574
102k
  child_range children() {
3575
102k
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3576
102k
  }
3577
0
  const_child_range children() const {
3578
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3579
0
  }
3580
};
3581
3582
/// BinaryConditionalOperator - The GNU extension to the conditional
3583
/// operator which allows the middle operand to be omitted.
3584
///
3585
/// This is a different expression kind on the assumption that almost
3586
/// every client ends up needing to know that these are different.
3587
class BinaryConditionalOperator : public AbstractConditionalOperator {
3588
  enum { COMMON, COND, LHS, RHS, NUM_SUBEXPRS };
3589
3590
  /// - the common condition/left-hand-side expression, which will be
3591
  ///   evaluated as the opaque value
3592
  /// - the condition, expressed in terms of the opaque value
3593
  /// - the left-hand-side, expressed in terms of the opaque value
3594
  /// - the right-hand-side
3595
  Stmt *SubExprs[NUM_SUBEXPRS];
3596
  OpaqueValueExpr *OpaqueValue;
3597
3598
  friend class ASTStmtReader;
3599
public:
3600
  BinaryConditionalOperator(Expr *common, OpaqueValueExpr *opaqueValue,
3601
                            Expr *cond, Expr *lhs, Expr *rhs,
3602
                            SourceLocation qloc, SourceLocation cloc,
3603
                            QualType t, ExprValueKind VK, ExprObjectKind OK)
3604
    : AbstractConditionalOperator(BinaryConditionalOperatorClass, t, VK, OK,
3605
           (common->isTypeDependent() || rhs->isTypeDependent()),
3606
           (common->isValueDependent() || rhs->isValueDependent()),
3607
           (common->isInstantiationDependent() ||
3608
            rhs->isInstantiationDependent()),
3609
           (common->containsUnexpandedParameterPack() ||
3610
            rhs->containsUnexpandedParameterPack()),
3611
                                  qloc, cloc),
3612
208
      OpaqueValue(opaqueValue) {
3613
208
    SubExprs[COMMON] = common;
3614
208
    SubExprs[COND] = cond;
3615
208
    SubExprs[LHS] = lhs;
3616
208
    SubExprs[RHS] = rhs;
3617
208
    assert(OpaqueValue->getSourceExpr() == common && "Wrong opaque value");
3618
208
  }
3619
3620
  /// Build an empty conditional operator.
3621
  explicit BinaryConditionalOperator(EmptyShell Empty)
3622
1
    : AbstractConditionalOperator(BinaryConditionalOperatorClass, Empty) { }
3623
3624
  /// getCommon - Return the common expression, written to the
3625
  ///   left of the condition.  The opaque value will be bound to the
3626
  ///   result of this expression.
3627
2.06k
  Expr *getCommon() const { return cast<Expr>(SubExprs[COMMON]); }
3628
3629
  /// getOpaqueValue - Return the opaque value placeholder.
3630
694
  OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; }
3631
3632
  /// getCond - Return the condition expression; this is defined
3633
  ///   in terms of the opaque value.
3634
1.51k
  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3635
3636
  /// getTrueExpr - Return the subexpression which will be
3637
  ///   evaluated if the condition evaluates to true;  this is defined
3638
  ///   in terms of the opaque value.
3639
1.27k
  Expr *getTrueExpr() const {
3640
1.27k
    return cast<Expr>(SubExprs[LHS]);
3641
1.27k
  }
3642
3643
  /// getFalseExpr - Return the subexpression which will be
3644
  ///   evaluated if the condnition evaluates to false; this is
3645
  ///   defined in terms of the opaque value.
3646
1.18k
  Expr *getFalseExpr() const {
3647
1.18k
    return cast<Expr>(SubExprs[RHS]);
3648
1.18k
  }
3649
3650
1.24k
  SourceLocation getBeginLoc() const LLVM_READONLY {
3651
1.24k
    return getCommon()->getBeginLoc();
3652
1.24k
  }
3653
208
  SourceLocation getEndLoc() const LLVM_READONLY {
3654
208
    return getFalseExpr()->getEndLoc();
3655
208
  }
3656
3657
1.57M
  static bool classof(const Stmt *T) {
3658
1.57M
    return T->getStmtClass() == BinaryConditionalOperatorClass;
3659
1.57M
  }
3660
3661
  // Iterators
3662
441
  child_range children() {
3663
441
    return child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
3664
441
  }
3665
0
  const_child_range children() const {
3666
0
    return const_child_range(SubExprs, SubExprs + NUM_SUBEXPRS);
3667
0
  }
3668
};
3669
3670
377k
inline Expr *AbstractConditionalOperator::getCond() const {
3671
377k
  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3672
376k
    return co->getCond();
3673
908
  return cast<BinaryConditionalOperator>(this)->getCond();
3674
908
}
3675
3676
294k
inline Expr *AbstractConditionalOperator::getTrueExpr() const {
3677
294k
  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3678
293k
    return co->getTrueExpr();
3679
712
  return cast<BinaryConditionalOperator>(this)->getTrueExpr();
3680
712
}
3681
3682
282k
inline Expr *AbstractConditionalOperator::getFalseExpr() const {
3683
282k
  if (const ConditionalOperator *co = dyn_cast<ConditionalOperator>(this))
3684
281k
    return co->getFalseExpr();
3685
649
  return cast<BinaryConditionalOperator>(this)->getFalseExpr();
3686
649
}
3687
3688
/// AddrLabelExpr - The GNU address of label extension, representing &&label.
3689
class AddrLabelExpr : public Expr {
3690
  SourceLocation AmpAmpLoc, LabelLoc;
3691
  LabelDecl *Label;
3692
public:
3693
  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelDecl *L,
3694
                QualType t)
3695
    : Expr(AddrLabelExprClass, t, VK_RValue, OK_Ordinary, false, false, false,
3696
           false),
3697
275
      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
3698
3699
  /// Build an empty address of a label expression.
3700
  explicit AddrLabelExpr(EmptyShell Empty)
3701
2
    : Expr(AddrLabelExprClass, Empty) { }
3702
3703
12
  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
3704
2
  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
3705
13
  SourceLocation getLabelLoc() const { return LabelLoc; }
3706
2
  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
3707
3708
1.71k
  SourceLocation getBeginLoc() const LLVM_READONLY { return AmpAmpLoc; }
3709
518
  SourceLocation getEndLoc() const LLVM_READONLY { return LabelLoc; }
3710
3711
740
  LabelDecl *getLabel() const { return Label; }
3712
2
  void setLabel(LabelDecl *L) { Label = L; }
3713
3714
312
  static bool classof(const Stmt *T) {
3715
312
    return T->getStmtClass() == AddrLabelExprClass;
3716
312
  }
3717
3718
  // Iterators
3719
1.14k
  child_range children() {
3720
1.14k
    return child_range(child_iterator(), child_iterator());
3721
1.14k
  }
3722
0
  const_child_range children() const {
3723
0
    return const_child_range(const_child_iterator(), const_child_iterator());
3724
0
  }
3725
};
3726
3727
/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
3728
/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
3729
/// takes the value of the last subexpression.
3730
///
3731
/// A StmtExpr is always an r-value; values "returned" out of a
3732
/// StmtExpr will be copied.
3733
class StmtExpr : public Expr {
3734
  Stmt *SubStmt;
3735
  SourceLocation LParenLoc, RParenLoc;
3736
public:
3737
  // FIXME: Does type-dependence need to be computed differently?
3738
  // FIXME: Do we need to compute instantiation instantiation-dependence for
3739
  // statements? (ugh!)
3740
  StmtExpr(CompoundStmt *substmt, QualType T,
3741
           SourceLocation lp, SourceLocation rp) :
3742
    Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
3743
         T->isDependentType(), false, false, false),
3744
11.1k
    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
3745
3746
  /// Build an empty statement expression.
3747
13
  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
3748
3749
2.89k
  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
3750
13.3k
  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
3751
13
  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
3752
3753
20.9k
  SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
3754
341
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3755
3756
29
  SourceLocation getLParenLoc() const { return LParenLoc; }
3757
13
  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
3758
29
  SourceLocation getRParenLoc() const { return RParenLoc; }
3759
13
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3760
3761
43.7M
  static bool classof(const Stmt *T) {
3762
43.7M
    return T->getStmtClass() == StmtExprClass;
3763
43.7M
  }
3764
3765
  // Iterators
3766
18.6k
  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
3767
0
  const_child_range children() const {
3768
0
    return const_child_range(&SubStmt, &SubStmt + 1);
3769
0
  }
3770
};
3771
3772
/// ShuffleVectorExpr - clang-specific builtin-in function
3773
/// __builtin_shufflevector.
3774
/// This AST node represents a operator that does a constant
3775
/// shuffle, similar to LLVM's shufflevector instruction. It takes
3776
/// two vectors and a variable number of constant indices,
3777
/// and returns the appropriately shuffled vector.
3778
class ShuffleVectorExpr : public Expr {
3779
  SourceLocation BuiltinLoc, RParenLoc;
3780
3781
  // SubExprs - the list of values passed to the __builtin_shufflevector
3782
  // function. The first two are vectors, and the rest are constant
3783
  // indices.  The number of values in this list is always
3784
  // 2+the number of indices in the vector type.
3785
  Stmt **SubExprs;
3786
  unsigned NumExprs;
3787
3788
public:
3789
  ShuffleVectorExpr(const ASTContext &C, ArrayRef<Expr*> args, QualType Type,
3790
                    SourceLocation BLoc, SourceLocation RP);
3791
3792
  /// Build an empty vector-shuffle expression.
3793
  explicit ShuffleVectorExpr(EmptyShell Empty)
3794
2
    : Expr(ShuffleVectorExprClass, Empty), SubExprs(nullptr) { }
3795
3796
1.30k
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3797
2
  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3798
3799
1.30k
  SourceLocation getRParenLoc() const { return RParenLoc; }
3800
2
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3801
3802
338k
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3803
20.0k
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3804
3805
0
  static bool classof(const Stmt *T) {
3806
0
    return T->getStmtClass() == ShuffleVectorExprClass;
3807
0
  }
3808
3809
  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
3810
  /// constant expression, the actual arguments passed in, and the function
3811
  /// pointers.
3812
16.0k
  unsigned getNumSubExprs() const { return NumExprs; }
3813
3814
  /// Retrieve the array of expressions.
3815
4
  Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
3816
3817
  /// getExpr - Return the Expr at the specified index.
3818
15.5k
  Expr *getExpr(unsigned Index) {
3819
15.5k
    assert((Index < NumExprs) && "Arg access out of range!");
3820
15.5k
    return cast<Expr>(SubExprs[Index]);
3821
15.5k
  }
3822
9.99k
  const Expr *getExpr(unsigned Index) const {
3823
9.99k
    assert((Index < NumExprs) && "Arg access out of range!");
3824
9.99k
    return cast<Expr>(SubExprs[Index]);
3825
9.99k
  }
3826
3827
  void setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs);
3828
3829
9.99k
  llvm::APSInt getShuffleMaskIdx(const ASTContext &Ctx, unsigned N) const {
3830
9.99k
    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
3831
9.99k
    return getExpr(N+2)->EvaluateKnownConstInt(Ctx);
3832
9.99k
  }
3833
3834
  // Iterators
3835
214k
  child_range children() {
3836
214k
    return child_range(&SubExprs[0], &SubExprs[0]+NumExprs);
3837
214k
  }
3838
0
  const_child_range children() const {
3839
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + NumExprs);
3840
0
  }
3841
};
3842
3843
/// ConvertVectorExpr - Clang builtin function __builtin_convertvector
3844
/// This AST node provides support for converting a vector type to another
3845
/// vector type of the same arity.
3846
class ConvertVectorExpr : public Expr {
3847
private:
3848
  Stmt *SrcExpr;
3849
  TypeSourceInfo *TInfo;
3850
  SourceLocation BuiltinLoc, RParenLoc;
3851
3852
  friend class ASTReader;
3853
  friend class ASTStmtReader;
3854
0
  explicit ConvertVectorExpr(EmptyShell Empty) : Expr(ConvertVectorExprClass, Empty) {}
3855
3856
public:
3857
  ConvertVectorExpr(Expr* SrcExpr, TypeSourceInfo *TI, QualType DstType,
3858
             ExprValueKind VK, ExprObjectKind OK,
3859
             SourceLocation BuiltinLoc, SourceLocation RParenLoc)
3860
    : Expr(ConvertVectorExprClass, DstType, VK, OK,
3861
           DstType->isDependentType(),
3862
           DstType->isDependentType() || SrcExpr->isValueDependent(),
3863
           (DstType->isInstantiationDependentType() ||
3864
            SrcExpr->isInstantiationDependent()),
3865
           (DstType->containsUnexpandedParameterPack() ||
3866
            SrcExpr->containsUnexpandedParameterPack())),
3867
12.8k
  SrcExpr(SrcExpr), TInfo(TI), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
3868
3869
  /// getSrcExpr - Return the Expr to be converted.
3870
896
  Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
3871
3872
  /// getTypeSourceInfo - Return the destination type.
3873
351
  TypeSourceInfo *getTypeSourceInfo() const {
3874
351
    return TInfo;
3875
351
  }
3876
  void setTypeSourceInfo(TypeSourceInfo *ti) {
3877
    TInfo = ti;
3878
  }
3879
3880
  /// getBuiltinLoc - Return the location of the __builtin_convertvector token.
3881
350
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3882
3883
  /// getRParenLoc - Return the location of final right parenthesis.
3884
350
  SourceLocation getRParenLoc() const { return RParenLoc; }
3885
3886
17.0k
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3887
10.4k
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3888
3889
  static bool classof(const Stmt *T) {
3890
    return T->getStmtClass() == ConvertVectorExprClass;
3891
  }
3892
3893
  // Iterators
3894
26.2k
  child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
3895
0
  const_child_range children() const {
3896
0
    return const_child_range(&SrcExpr, &SrcExpr + 1);
3897
0
  }
3898
};
3899
3900
/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
3901
/// This AST node is similar to the conditional operator (?:) in C, with
3902
/// the following exceptions:
3903
/// - the test expression must be a integer constant expression.
3904
/// - the expression returned acts like the chosen subexpression in every
3905
///   visible way: the type is the same as that of the chosen subexpression,
3906
///   and all predicates (whether it's an l-value, whether it's an integer
3907
///   constant expression, etc.) return the same result as for the chosen
3908
///   sub-expression.
3909
class ChooseExpr : public Expr {
3910
  enum { COND, LHS, RHS, END_EXPR };
3911
  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
3912
  SourceLocation BuiltinLoc, RParenLoc;
3913
  bool CondIsTrue;
3914
public:
3915
  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs,
3916
             QualType t, ExprValueKind VK, ExprObjectKind OK,
3917
             SourceLocation RP, bool condIsTrue,
3918
             bool TypeDependent, bool ValueDependent)
3919
    : Expr(ChooseExprClass, t, VK, OK, TypeDependent, ValueDependent,
3920
           (cond->isInstantiationDependent() ||
3921
            lhs->isInstantiationDependent() ||
3922
            rhs->isInstantiationDependent()),
3923
           (cond->containsUnexpandedParameterPack() ||
3924
            lhs->containsUnexpandedParameterPack() ||
3925
            rhs->containsUnexpandedParameterPack())),
3926
41
      BuiltinLoc(BLoc), RParenLoc(RP), CondIsTrue(condIsTrue) {
3927
41
      SubExprs[COND] = cond;
3928
41
      SubExprs[LHS] = lhs;
3929
41
      SubExprs[RHS] = rhs;
3930
41
    }
3931
3932
  /// Build an empty __builtin_choose_expr.
3933
1
  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
3934
3935
  /// isConditionTrue - Return whether the condition is true (i.e. not
3936
  /// equal to zero).
3937
220
  bool isConditionTrue() const {
3938
220
    assert(!isConditionDependent() &&
3939
220
           "Dependent condition isn't true or false");
3940
220
    return CondIsTrue;
3941
220
  }
3942
1
  void setIsConditionTrue(bool isTrue) { CondIsTrue = isTrue; }
3943
3944
174
  bool isConditionDependent() const {
3945
174
    return getCond()->isTypeDependent() || getCond()->isValueDependent();
3946
174
  }
3947
3948
  /// getChosenSubExpr - Return the subexpression chosen according to the
3949
  /// condition.
3950
217
  Expr *getChosenSubExpr() const {
3951
217
    return isConditionTrue() ? 
getLHS()99
:
getRHS()118
;
3952
217
  }
3953
3954
384
  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
3955
1
  void setCond(Expr *E) { SubExprs[COND] = E; }
3956
106
  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
3957
1
  void setLHS(Expr *E) { SubExprs[LHS] = E; }
3958
125
  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
3959
1
  void setRHS(Expr *E) { SubExprs[RHS] = E; }
3960
3961
7
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
3962
1
  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
3963
3964
7
  SourceLocation getRParenLoc() const { return RParenLoc; }
3965
1
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
3966
3967
61
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
3968
12
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
3969
3970
353M
  static bool classof(const Stmt *T) {
3971
353M
    return T->getStmtClass() == ChooseExprClass;
3972
353M
  }
3973
3974
  // Iterators
3975
24
  child_range children() {
3976
24
    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
3977
24
  }
3978
0
  const_child_range children() const {
3979
0
    return const_child_range(&SubExprs[0], &SubExprs[0] + END_EXPR);
3980
0
  }
3981
};
3982
3983
/// GNUNullExpr - Implements the GNU __null extension, which is a name
3984
/// for a null pointer constant that has integral type (e.g., int or
3985
/// long) and is the same size and alignment as a pointer. The __null
3986
/// extension is typically only used by system headers, which define
3987
/// NULL as __null in C++ rather than using 0 (which is an integer
3988
/// that may not match the size of a pointer).
3989
class GNUNullExpr : public Expr {
3990
  /// TokenLoc - The location of the __null keyword.
3991
  SourceLocation TokenLoc;
3992
3993
public:
3994
  GNUNullExpr(QualType Ty, SourceLocation Loc)
3995
    : Expr(GNUNullExprClass, Ty, VK_RValue, OK_Ordinary, false, false, false,
3996
           false),
3997
7.44k
      TokenLoc(Loc) { }
3998
3999
  /// Build an empty GNU __null expression.
4000
0
  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
4001
4002
  /// getTokenLocation - The location of the __null token.
4003
0
  SourceLocation getTokenLocation() const { return TokenLoc; }
4004
0
  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
4005
4006
33.9k
  SourceLocation getBeginLoc() const LLVM_READONLY { return TokenLoc; }
4007
10.3k
  SourceLocation getEndLoc() const LLVM_READONLY { return TokenLoc; }
4008
4009
12.1M
  static bool classof(const Stmt *T) {
4010
12.1M
    return T->getStmtClass() == GNUNullExprClass;
4011
12.1M
  }
4012
4013
  // Iterators
4014
8.15k
  child_range children() {
4015
8.15k
    return child_range(child_iterator(), child_iterator());
4016
8.15k
  }
4017
0
  const_child_range children() const {
4018
0
    return const_child_range(const_child_iterator(), const_child_iterator());
4019
0
  }
4020
};
4021
4022
/// Represents a call to the builtin function \c __builtin_va_arg.
4023
class VAArgExpr : public Expr {
4024
  Stmt *Val;
4025
  llvm::PointerIntPair<TypeSourceInfo *, 1, bool> TInfo;
4026
  SourceLocation BuiltinLoc, RParenLoc;
4027
public:
4028
  VAArgExpr(SourceLocation BLoc, Expr *e, TypeSourceInfo *TInfo,
4029
            SourceLocation RPLoc, QualType t, bool IsMS)
4030
      : Expr(VAArgExprClass, t, VK_RValue, OK_Ordinary, t->isDependentType(),
4031
             false, (TInfo->getType()->isInstantiationDependentType() ||
4032
                     e->isInstantiationDependent()),
4033
             (TInfo->getType()->containsUnexpandedParameterPack() ||
4034
              e->containsUnexpandedParameterPack())),
4035
1.35k
        Val(e), TInfo(TInfo, IsMS), BuiltinLoc(BLoc), RParenLoc(RPLoc) {}
4036
4037
  /// Create an empty __builtin_va_arg expression.
4038
  explicit VAArgExpr(EmptyShell Empty)
4039
2
      : Expr(VAArgExprClass, Empty), Val(nullptr), TInfo(nullptr, false) {}
4040
4041
37
  const Expr *getSubExpr() const { return cast<Expr>(Val); }
4042
1.03k
  Expr *getSubExpr() { return cast<Expr>(Val); }
4043
2
  void setSubExpr(Expr *E) { Val = E; }
4044
4045
  /// Returns whether this is really a Win64 ABI va_arg expression.
4046
2.03k
  bool isMicrosoftABI() const { return TInfo.getInt(); }
4047
2
  void setIsMicrosoftABI(bool IsMS) { TInfo.setInt(IsMS); }
4048
4049
74
  TypeSourceInfo *getWrittenTypeInfo() const { return TInfo.getPointer(); }
4050
2
  void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo.setPointer(TI); }
4051
4052
14
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
4053
2
  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
4054
4055
14
  SourceLocation getRParenLoc() const { return RParenLoc; }
4056
2
  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4057
4058
7.20k
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
4059
357
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4060
4061
44
  static bool classof(const Stmt *T) {
4062
44
    return T->getStmtClass() == VAArgExprClass;
4063
44
  }
4064
4065
  // Iterators
4066
5.61k
  child_range children() { return child_range(&Val, &Val+1); }
4067
0
  const_child_range children() const {
4068
0
    return const_child_range(&Val, &Val + 1);
4069
0
  }
4070
};
4071
4072
/// Describes an C or C++ initializer list.
4073
///
4074
/// InitListExpr describes an initializer list, which can be used to
4075
/// initialize objects of different types, including
4076
/// struct/class/union types, arrays, and vectors. For example:
4077
///
4078
/// @code
4079
/// struct foo x = { 1, { 2, 3 } };
4080
/// @endcode
4081
///
4082
/// Prior to semantic analysis, an initializer list will represent the
4083
/// initializer list as written by the user, but will have the
4084
/// placeholder type "void". This initializer list is called the
4085
/// syntactic form of the initializer, and may contain C99 designated
4086
/// initializers (represented as DesignatedInitExprs), initializations
4087
/// of subobject members without explicit braces, and so on. Clients
4088
/// interested in the original syntax of the initializer list should
4089
/// use the syntactic form of the initializer list.
4090
///
4091
/// After semantic analysis, the initializer list will represent the
4092
/// semantic form of the initializer, where the initializations of all
4093
/// subobjects are made explicit with nested InitListExpr nodes and
4094
/// C99 designators have been eliminated by placing the designated
4095
/// initializations into the subobject they initialize. Additionally,
4096
/// any "holes" in the initialization, where no initializer has been
4097
/// specified for a particular subobject, will be replaced with
4098
/// implicitly-generated ImplicitValueInitExpr expressions that
4099
/// value-initialize the subobjects. Note, however, that the
4100
/// initializer lists may still have fewer initializers than there are
4101
/// elements to initialize within the object.
4102
///
4103
/// After semantic analysis has completed, given an initializer list,
4104
/// method isSemanticForm() returns true if and only if this is the
4105
/// semantic form of the initializer list (note: the same AST node
4106
/// may at the same time be the syntactic form).
4107
/// Given the semantic form of the initializer list, one can retrieve
4108
/// the syntactic form of that initializer list (when different)
4109
/// using method getSyntacticForm(); the method returns null if applied
4110
/// to a initializer list which is already in syntactic form.
4111
/// Similarly, given the syntactic form (i.e., an initializer list such
4112
/// that isSemanticForm() returns false), one can retrieve the semantic
4113
/// form using method getSemanticForm().
4114
/// Since many initializer lists have the same syntactic and semantic forms,
4115
/// getSyntacticForm() may return NULL, indicating that the current
4116
/// semantic initializer list also serves as its syntactic form.
4117
class InitListExpr : public Expr {
4118
  // FIXME: Eliminate this vector in favor of ASTContext allocation
4119
  typedef ASTVector<Stmt *> InitExprsTy;
4120
  InitExprsTy InitExprs;
4121
  SourceLocation LBraceLoc, RBraceLoc;
4122
4123
  /// The alternative form of the initializer list (if it exists).
4124
  /// The int part of the pair stores whether this initializer list is
4125
  /// in semantic form. If not null, the pointer points to:
4126
  ///   - the syntactic form, if this is in semantic form;
4127
  ///   - the semantic form, if this is in syntactic form.
4128
  llvm::PointerIntPair<InitListExpr *, 1, bool> AltForm;
4129
4130
  /// Either:
4131
  ///  If this initializer list initializes an array with more elements than
4132
  ///  there are initializers in the list, specifies an expression to be used
4133
  ///  for value initialization of the rest of the elements.
4134
  /// Or
4135
  ///  If this initializer list initializes a union, specifies which
4136
  ///  field within the union will be initialized.
4137
  llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit;
4138
4139
public:
4140
  InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
4141
               ArrayRef<Expr*> initExprs, SourceLocation rbraceloc);
4142
4143
  /// Build an empty initializer list.
4144
  explicit InitListExpr(EmptyShell Empty)
4145
1.73k
    : Expr(InitListExprClass, Empty), AltForm(nullptr, true) { }
4146
4147
5.40M
  unsigned getNumInits() const { return InitExprs.size(); }
4148
4149
  /// Retrieve the set of initializers.
4150
190k
  Expr **getInits() { return reinterpret_cast<Expr **>(InitExprs.data()); }
4151
4152
  /// Retrieve the set of initializers.
4153
0
  Expr * const *getInits() const {
4154
0
    return reinterpret_cast<Expr * const *>(InitExprs.data());
4155
0
  }
4156
4157
149k
  ArrayRef<Expr *> inits() {
4158
149k
    return llvm::makeArrayRef(getInits(), getNumInits());
4159
149k
  }
4160
4161
0
  ArrayRef<Expr *> inits() const {
4162
0
    return llvm::makeArrayRef(getInits(), getNumInits());
4163
0
  }
4164
4165
715k
  const Expr *getInit(unsigned Init) const {
4166
715k
    assert(Init < getNumInits() && "Initializer access out of range!");
4167
715k
    return cast_or_null<Expr>(InitExprs[Init]);
4168
715k
  }
4169
4170
7.76M
  Expr *getInit(unsigned Init) {
4171
7.76M
    assert(Init < getNumInits() && "Initializer access out of range!");
4172
7.76M
    return cast_or_null<Expr>(InitExprs[Init]);
4173
7.76M
  }
4174
4175
1.70M
  void setInit(unsigned Init, Expr *expr) {
4176
1.70M
    assert(Init < getNumInits() && "Initializer access out of range!");
4177
1.70M
    InitExprs[Init] = expr;
4178
1.70M
4179
1.70M
    if (expr) {
4180
1.70M
      ExprBits.TypeDependent |= expr->isTypeDependent();
4181
1.70M
      ExprBits.ValueDependent |= expr->isValueDependent();
4182
1.70M
      ExprBits.InstantiationDependent |= expr->isInstantiationDependent();
4183
1.70M
      ExprBits.ContainsUnexpandedParameterPack |=
4184
1.70M
          expr->containsUnexpandedParameterPack();
4185
1.70M
    }
4186
1.70M
  }
4187
4188
  /// Reserve space for some number of initializers.
4189
  void reserveInits(const ASTContext &C, unsigned NumInits);
4190
4191
  /// Specify the number of initializers
4192
  ///
4193
  /// If there are more than @p NumInits initializers, the remaining
4194
  /// initializers will be destroyed. If there are fewer than @p
4195
  /// NumInits initializers, NULL expressions will be added for the
4196
  /// unknown initializers.
4197
  void resizeInits(const ASTContext &Context, unsigned NumInits);
4198
4199
  /// Updates the initializer at index @p Init with the new
4200
  /// expression @p expr, and returns the old expression at that
4201
  /// location.
4202
  ///
4203
  /// When @p Init is out of range for this initializer list, the
4204
  /// initializer list will be extended with NULL expressions to
4205
  /// accommodate the new entry.
4206
  Expr *updateInit(const ASTContext &C, unsigned Init, Expr *expr);
4207
4208
  /// If this initializer list initializes an array with more elements
4209
  /// than there are initializers in the list, specifies an expression to be
4210
  /// used for value initialization of the rest of the elements.
4211
158k
  Expr *getArrayFiller() {
4212
158k
    return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>();
4213
158k
  }
4214
134k
  const Expr *getArrayFiller() const {
4215
134k
    return const_cast<InitListExpr *>(this)->getArrayFiller();
4216
134k
  }
4217
  void setArrayFiller(Expr *filler);
4218
4219
  /// Return true if this is an array initializer and its array "filler"
4220
  /// has been set.
4221
39.1k
  bool hasArrayFiller() const { return getArrayFiller(); }
4222
4223
  /// If this initializes a union, specifies which field in the
4224
  /// union to initialize.
4225
  ///
4226
  /// Typically, this field is the first named field within the
4227
  /// union. However, a designated initializer can specify the
4228
  /// initialization of a different field within the union.
4229
19.0k
  FieldDecl *getInitializedFieldInUnion() {
4230
19.0k
    return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
4231
19.0k
  }
4232
3.86k
  const FieldDecl *getInitializedFieldInUnion() const {
4233
3.86k
    return const_cast<InitListExpr *>(this)->getInitializedFieldInUnion();
4234
3.86k
  }
4235
3.02k
  void setInitializedFieldInUnion(FieldDecl *FD) {
4236
3.02k
    assert((FD == nullptr
4237
3.02k
            || getInitializedFieldInUnion() == nullptr
4238
3.02k
            || getInitializedFieldInUnion() == FD)
4239
3.02k
           && "Only one field of a union may be initialized at a time!");
4240
3.02k
    ArrayFillerOrUnionFieldInit = FD;
4241
3.02k
  }
4242
4243
  // Explicit InitListExpr's originate from source code (and have valid source
4244
  // locations). Implicit InitListExpr's are created by the semantic analyzer.
4245
0
  bool isExplicit() const {
4246
0
    return LBraceLoc.isValid() && RBraceLoc.isValid();
4247
0
  }
4248
4249
  // Is this an initializer for an array of characters, initialized by a string
4250
  // literal or an @encode?
4251
  bool isStringLiteralInit() const;
4252
4253
  /// Is this a transparent initializer list (that is, an InitListExpr that is
4254
  /// purely syntactic, and whose semantics are that of the sole contained
4255
  /// initializer)?
4256
  bool isTransparent() const;
4257
4258
  /// Is this the zero initializer {0} in a language which considers it
4259
  /// idiomatic?
4260
  bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const;
4261
4262
14.9k
  SourceLocation getLBraceLoc() const { return LBraceLoc; }
4263
1.73k
  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
4264
14.9k
  SourceLocation getRBraceLoc() const { return RBraceLoc; }
4265
2.94k
  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
4266
4267
1.39M
  bool isSemanticForm() const { return AltForm.getInt(); }
4268
392
  InitListExpr *getSemanticForm() const {
4269
392
    return isSemanticForm() ? 
nullptr0
: AltForm.getPointer();
4270
392
  }
4271
0
  bool isSyntacticForm() const {
4272
0
    return !AltForm.getInt() || !AltForm.getPointer();
4273
0
  }
4274
1.38M
  InitListExpr *getSyntacticForm() const {
4275
1.38M
    return isSemanticForm() ? 
AltForm.getPointer()1.05M
:
nullptr332k
;
4276
1.38M
  }
4277
4278
194k
  void setSyntacticForm(InitListExpr *Init) {
4279
194k
    AltForm.setPointer(Init);
4280
194k
    AltForm.setInt(true);
4281
194k
    Init->AltForm.setPointer(this);
4282
194k
    Init->AltForm.setInt(false);
4283
194k
  }
4284
4285
11.8k
  bool hadArrayRangeDesignator() const {
4286
11.8k
    return InitListExprBits.HadArrayRangeDesignator != 0;
4287
11.8k
  }
4288
261k
  void sawArrayRangeDesignator(bool ARD = true) {
4289
261k
    InitListExprBits.HadArrayRangeDesignator = ARD;
4290
261k
  }
4291
4292
  SourceLocation getBeginLoc() const LLVM_READONLY;
4293
  SourceLocation getEndLoc() const LLVM_READONLY;
4294
4295
105M
  static bool classof(const Stmt *T) {
4296
105M
    return T->getStmtClass() == InitListExprClass;
4297
105M
  }
4298
4299
  // Iterators
4300
371k
  child_range children() {
4301
371k
    const_child_range CCR = const_cast<const InitListExpr *>(this)->children();
4302
371k
    return child_range(cast_away_const(CCR.begin()),
4303
371k
                       cast_away_const(CCR.end()));
4304
371k
  }
4305
4306
371k
  const_child_range children() const {
4307
371k
    // FIXME: This does not include the array filler expression.
4308
371k
    if (InitExprs.empty())
4309
31.6k
      return const_child_range(const_child_iterator(), const_child_iterator());
4310
340k
    return const_child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size());
4311
340k
  }
4312
4313
  typedef InitExprsTy::iterator iterator;
4314
  typedef InitExprsTy::const_iterator const_iterator;
4315
  typedef InitExprsTy::reverse_iterator reverse_iterator;
4316
  typedef InitExprsTy::const_reverse_iterator const_reverse_iterator;
4317
4318
0
  iterator begin() { return InitExprs.begin(); }
4319
7
  const_iterator begin() const { return InitExprs.begin(); }
4320
0
  iterator end() { return InitExprs.end(); }
4321
0
  const_iterator end() const { return InitExprs.end(); }
4322
0
  reverse_iterator rbegin() { return InitExprs.rbegin(); }
4323
851
  const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
4324
0
  reverse_iterator rend() { return InitExprs.rend(); }
4325
851
  const_reverse_iterator rend() const { return InitExprs.rend(); }
4326
4327
  friend class ASTStmtReader;
4328
  friend class ASTStmtWriter;
4329
};
4330
4331
/// Represents a C99 designated initializer expression.
4332
///
4333
/// A designated initializer expression (C99 6.7.8) contains one or
4334
/// more designators (which can be field designators, array
4335
/// designators, or GNU array-range designators) followed by an
4336
/// expression that initializes the field or element(s) that the
4337
/// designators refer to. For example, given:
4338
///
4339
/// @code
4340
/// struct point {
4341
///   double x;
4342
///   double y;
4343
/// };
4344
/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
4345
/// @endcode
4346
///
4347
/// The InitListExpr contains three DesignatedInitExprs, the first of
4348
/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
4349
/// designators, one array designator for @c [2] followed by one field
4350
/// designator for @c .y. The initialization expression will be 1.0.
4351
class DesignatedInitExpr final
4352
    : public Expr,
4353
      private llvm::TrailingObjects<DesignatedInitExpr, Stmt *> {
4354
public:
4355
  /// Forward declaration of the Designator class.
4356
  class Designator;
4357
4358
private:
4359
  /// The location of the '=' or ':' prior to the actual initializer
4360
  /// expression.
4361
  SourceLocation EqualOrColonLoc;
4362
4363
  /// Whether this designated initializer used the GNU deprecated
4364
  /// syntax rather than the C99 '=' syntax.
4365
  unsigned GNUSyntax : 1;
4366
4367
  /// The number of designators in this initializer expression.
4368
  unsigned NumDesignators : 15;
4369
4370
  /// The number of subexpressions of this initializer expression,
4371
  /// which contains both the initializer and any additional
4372
  /// expressions used by array and array-range designators.
4373
  unsigned NumSubExprs : 16;
4374
4375
  /// The designators in this designated initialization
4376
  /// expression.
4377
  Designator *Designators;
4378
4379
  DesignatedInitExpr(const ASTContext &C, QualType Ty,
4380
                     llvm::ArrayRef<Designator> Designators,
4381
                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
4382
                     ArrayRef<Expr *> IndexExprs, Expr *Init);
4383
4384
  explicit DesignatedInitExpr(unsigned NumSubExprs)
4385
    : Expr(DesignatedInitExprClass, EmptyShell()),
4386
9
      NumDesignators(0), NumSubExprs(NumSubExprs), Designators(nullptr) { }
4387
4388
public:
4389
  /// A field designator, e.g., ".x".
4390
  struct FieldDesignator {
4391
    /// Refers to the field that is being initialized. The low bit
4392
    /// of this field determines whether this is actually a pointer
4393
    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
4394
    /// initially constructed, a field designator will store an
4395
    /// IdentifierInfo*. After semantic analysis has resolved that
4396
    /// name, the field designator will instead store a FieldDecl*.
4397
    uintptr_t NameOrField;
4398
4399
    /// The location of the '.' in the designated initializer.
4400
    unsigned DotLoc;
4401
4402
    /// The location of the field name in the designated initializer.
4403
    unsigned FieldLoc;
4404
  };
4405
4406
  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
4407
  struct ArrayOrRangeDesignator {
4408
    /// Location of the first index expression within the designated
4409
    /// initializer expression's list of subexpressions.
4410
    unsigned Index;
4411
    /// The location of the '[' starting the array range designator.
4412
    unsigned LBracketLoc;
4413
    /// The location of the ellipsis separating the start and end
4414
    /// indices. Only valid for GNU array-range designators.
4415
    unsigned EllipsisLoc;
4416
    /// The location of the ']' terminating the array range designator.
4417
    unsigned RBracketLoc;
4418
  };
4419
4420
  /// Represents a single C99 designator.
4421
  ///
4422
  /// @todo This class is infuriatingly similar to clang::Designator,
4423
  /// but minor differences (storing indices vs. storing pointers)
4424
  /// keep us from reusing it. Try harder, later, to rectify these
4425
  /// differences.
4426
  class Designator {
4427
    /// The kind of designator this describes.
4428
    enum {
4429
      FieldDesignator,
4430
      ArrayDesignator,
4431
      ArrayRangeDesignator
4432
    } Kind;
4433
4434
    union {
4435
      /// A field designator, e.g., ".x".
4436
      struct FieldDesignator Field;
4437
      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
4438
      struct ArrayOrRangeDesignator ArrayOrRange;
4439
    };
4440
    friend class DesignatedInitExpr;
4441
4442
  public:
4443
3.16k
    Designator() {}
4444
4445
    /// Initializes a field designator.
4446
    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
4447
               SourceLocation FieldLoc)
4448
2.77k
      : Kind(FieldDesignator) {
4449
2.77k
      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
4450
2.77k
      Field.DotLoc = DotLoc.getRawEncoding();
4451
2.77k
      Field.FieldLoc = FieldLoc.getRawEncoding();
4452
2.77k
    }
4453
4454
    /// Initializes an array designator.
4455
    Designator(unsigned Index, SourceLocation LBracketLoc,
4456
               SourceLocation RBracketLoc)
4457
302
      : Kind(ArrayDesignator) {
4458
302
      ArrayOrRange.Index = Index;
4459
302
      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
4460
302
      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
4461
302
      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
4462
302
    }
4463
4464
    /// Initializes a GNU array-range designator.
4465
    Designator(unsigned Index, SourceLocation LBracketLoc,
4466
               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
4467
26
      : Kind(ArrayRangeDesignator) {
4468
26
      ArrayOrRange.Index = Index;
4469
26
      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
4470
26
      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
4471
26
      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
4472
26
    }
4473
4474
11.9k
    bool isFieldDesignator() const { return Kind == FieldDesignator; }
4475
3.72k
    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
4476
2.74k
    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
4477
4478
    IdentifierInfo *getFieldName() const;
4479
4480
5.55k
    FieldDecl *getField() const {
4481
5.55k
      assert(Kind == FieldDesignator && "Only valid on a field designator");
4482
5.55k
      if (Field.NameOrField & 0x01)
4483
5.31k
        return nullptr;
4484
243
      else
4485
243
        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
4486
5.55k
    }
4487
4488
2.76k
    void setField(FieldDecl *FD) {
4489
2.76k
      assert(Kind == FieldDesignator && "Only valid on a field designator");
4490
2.76k
      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
4491
2.76k
    }
4492
4493
605
    SourceLocation getDotLoc() const {
4494
605
      assert(Kind == FieldDesignator && "Only valid on a field designator");
4495
605
      return SourceLocation::getFromRawEncoding(Field.DotLoc);
4496
605
    }
4497
4498
2.89k
    SourceLocation getFieldLoc() const {
4499
2.89k
      assert(Kind == FieldDesignator && "Only valid on a field designator");
4500
2.89k
      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
4501
2.89k
    }
4502
4503
161
    SourceLocation getLBracketLoc() const {
4504
161
      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4505
161
             "Only valid on an array or array-range designator");
4506
161
      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
4507
161
    }
4508
4509
52
    SourceLocation getRBracketLoc() const {
4510
52
      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4511
52
             "Only valid on an array or array-range designator");
4512
52
      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
4513
52
    }
4514
4515
8
    SourceLocation getEllipsisLoc() const {
4516
8
      assert(Kind == ArrayRangeDesignator &&
4517
8
             "Only valid on an array-range designator");
4518
8
      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
4519
8
    }
4520
4521
61
    unsigned getFirstExprIndex() const {
4522
61
      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
4523
61
             "Only valid on an array or array-range designator");
4524
61
      return ArrayOrRange.Index;
4525
61
    }
4526
4527
301
    SourceLocation getBeginLoc() const LLVM_READONLY {
4528
301
      if (Kind == FieldDesignator)
4529
225
        return getDotLoc().isInvalid()? 
getFieldLoc()8
:
getDotLoc()217
;
4530
76
      else
4531
76
        return getLBracketLoc();
4532
301
    }
4533
18
    SourceLocation getEndLoc() const LLVM_READONLY {
4534
18
      return Kind == FieldDesignator ? getFieldLoc() : 
getRBracketLoc()0
;
4535
18
    }
4536
18
    SourceRange getSourceRange() const LLVM_READONLY {
4537
18
      return SourceRange(getBeginLoc(), getEndLoc());
4538
18
    }
4539
  };
4540
4541
  static DesignatedInitExpr *Create(const ASTContext &C,
4542
                                    llvm::ArrayRef<Designator> Designators,
4543
                                    ArrayRef<Expr*> IndexExprs,
4544
                                    SourceLocation EqualOrColonLoc,
4545
                                    bool GNUSyntax, Expr *Init);
4546
4547
  static DesignatedInitExpr *CreateEmpty(const ASTContext &C,
4548
                                         unsigned NumIndexExprs);
4549
4550
  /// Returns the number of designators in this initializer.
4551
11.4k
  unsigned size() const { return NumDesignators; }
4552
4553
  // Iterator access to the designators.
4554
11.9k
  llvm::MutableArrayRef<Designator> designators() {
4555
11.9k
    return {Designators, NumDesignators};
4556
11.9k
  }
4557
4558
32
  llvm::ArrayRef<Designator> designators() const {
4559
32
    return {Designators, NumDesignators};
4560
32
  }
4561
4562
11.7k
  Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; }
4563
0
  const Designator *getDesignator(unsigned Idx) const {
4564
0
    return &designators()[Idx];
4565
0
  }
4566
4567
  void setDesignators(const ASTContext &C, const Designator *Desigs,
4568
                      unsigned NumDesigs);
4569
4570
  Expr *getArrayIndex(const Designator &D) const;
4571
  Expr *getArrayRangeStart(const Designator &D) const;
4572
  Expr *getArrayRangeEnd(const Designator &D) const;
4573
4574
  /// Retrieve the location of the '=' that precedes the
4575
  /// initializer value itself, if present.
4576
153
  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
4577
9
  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
4578
4579
  /// Determines whether this designated initializer used the
4580
  /// deprecated GNU syntax for designated initializers.
4581
170
  bool usesGNUSyntax() const { return GNUSyntax; }
4582
9
  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
4583
4584
  /// Retrieve the initializer value.
4585
11.7k
  Expr *getInit() const {
4586
11.7k
    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
4587
11.7k
  }
4588
4589
2.21k
  void setInit(Expr *init) {
4590
2.21k
    *child_begin() = init;
4591
2.21k
  }
4592
4593
  /// Retrieve the total number of subexpressions in this
4594
  /// designated initializer expression, including the actual
4595
  /// initialized value and any expressions that occur within array
4596
  /// and array-range designators.
4597
148
  unsigned getNumSubExprs() const { return NumSubExprs; }
4598
4599
831
  Expr *getSubExpr(unsigned Idx) const {
4600
831
    assert(Idx < NumSubExprs && "Subscript out of range");
4601
831
    return cast<Expr>(getTrailingObjects<Stmt *>()[Idx]);
4602
831
  }
4603
4604
14
  void setSubExpr(unsigned Idx, Expr *E) {
4605
14
    assert(Idx < NumSubExprs && "Subscript out of range");
4606
14
    getTrailingObjects<Stmt *>()[Idx] = E;
4607
14
  }
4608
4609
  /// Replaces the designator at index @p Idx with the series
4610
  /// of designators in [First, Last).
4611
  void ExpandDesignator(const ASTContext &C, unsigned Idx,
4612
                        const Designator *First, const Designator *Last);
4613
4614
  SourceRange getDesignatorsSourceRange() const;
4615
4616
  SourceLocation getBeginLoc() const LLVM_READONLY;
4617
  SourceLocation getEndLoc() const LLVM_READONLY;
4618
4619
2.93M
  static bool classof(const Stmt *T) {
4620
2.93M
    return T->getStmtClass() == DesignatedInitExprClass;
4621
2.93M
  }
4622
4623
  // Iterators
4624
17.1k
  child_range children() {
4625
17.1k
    Stmt **begin = getTrailingObjects<Stmt *>();
4626
17.1k
    return child_range(begin, begin + NumSubExprs);
4627
17.1k
  }
4628
0
  const_child_range children() const {
4629
0
    Stmt * const *begin = getTrailingObjects<Stmt *>();
4630
0
    return const_child_range(begin, begin + NumSubExprs);
4631
0
  }
4632
4633
  friend TrailingObjects;
4634
};
4635
4636
/// Represents a place-holder for an object not to be initialized by
4637
/// anything.
4638
///
4639
/// This only makes sense when it appears as part of an updater of a
4640
/// DesignatedInitUpdateExpr (see below). The base expression of a DIUE
4641
/// initializes a big object, and the NoInitExpr's mark the spots within the
4642
/// big object not to be overwritten by the updater.
4643
///
4644
/// \see DesignatedInitUpdateExpr
4645
class NoInitExpr : public Expr {
4646
public:
4647
  explicit NoInitExpr(QualType ty)
4648
    : Expr(NoInitExprClass, ty, VK_RValue, OK_Ordinary,
4649
39
           false, false, ty->isInstantiationDependentType(), false) { }
4650
4651
  explicit NoInitExpr(EmptyShell Empty)
4652
1
    : Expr(NoInitExprClass, Empty) { }
4653
4654
13.7k
  static bool classof(const Stmt *T) {
4655
13.7k
    return T->getStmtClass() == NoInitExprClass;
4656
13.7k
  }
4657
4658
51
  SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
4659
0
  SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
4660
4661
  // Iterators
4662
166
  child_range children() {
4663
166
    return child_range(child_iterator(), child_iterator());
4664
166
  }
4665
0
  const_child_range children() const {
4666
0
    return const_child_range(const_child_iterator(), const_child_iterator());
4667
0
  }
4668
};
4669
4670
// In cases like:
4671
//   struct Q { int a, b, c; };
4672
//   Q *getQ();
4673
//   void foo() {
4674
//     struct A { Q q; } a = { *getQ(), .q.b = 3 };
4675
//   }
4676
//
4677
// We will have an InitListExpr for a, with type A, and then a
4678
// DesignatedInitUpdateExpr for "a.q" with type Q. The "base" for this DIUE
4679
// is the call expression *getQ(); the "updater" for the DIUE is ".q.b = 3"
4680
//
4681
class DesignatedInitUpdateExpr : public Expr {
4682
  // BaseAndUpdaterExprs[0] is the base expression;
4683
  // BaseAndUpdaterExprs[1] is an InitListExpr overwriting part of the base.
4684
  Stmt *BaseAndUpdaterExprs[2];
4685
4686
public:
4687
  DesignatedInitUpdateExpr(const ASTContext &C, SourceLocation lBraceLoc,
4688
                           Expr *baseExprs, SourceLocation rBraceLoc);
4689
4690
  explicit DesignatedInitUpdateExpr(EmptyShell Empty)
4691
1
    : Expr(DesignatedInitUpdateExprClass, Empty) { }
4692
4693
  SourceLocation getBeginLoc() const LLVM_READONLY;
4694
  SourceLocation getEndLoc() const LLVM_READONLY;
4695
4696
1.17M
  static bool classof(const Stmt *T) {
4697
1.17M
    return T->getStmtClass() == DesignatedInitUpdateExprClass;
4698
1.17M
  }
4699
4700
138
  Expr *getBase() const { return cast<Expr>(BaseAndUpdaterExprs[0]); }
4701
1
  void setBase(Expr *Base) { BaseAndUpdaterExprs[0] = Base; }
4702
4703
123
  InitListExpr *getUpdater() const {
4704
123
    return cast<InitListExpr>(BaseAndUpdaterExprs[1]);
4705
123
  }
4706
1
  void setUpdater(Expr *Updater) { BaseAndUpdaterExprs[1] = Updater; }
4707
4708
  // Iterators
4709
  // children = the base and the updater
4710
100
  child_range children() {
4711
100
    return child_range(&BaseAndUpdaterExprs[0], &BaseAndUpdaterExprs[0] + 2);
4712
100
  }
4713
0
  const_child_range children() const {
4714
0
    return const_child_range(&BaseAndUpdaterExprs[0],
4715
0
                             &BaseAndUpdaterExprs[0] + 2);
4716
0
  }
4717
};
4718
4719
/// Represents a loop initializing the elements of an array.
4720
///
4721
/// The need to initialize the elements of an array occurs in a number of
4722
/// contexts:
4723
///
4724
///  * in the implicit copy/move constructor for a class with an array member
4725
///  * when a lambda-expression captures an array by value
4726
///  * when a decomposition declaration decomposes an array
4727
///
4728
/// There are two subexpressions: a common expression (the source array)
4729
/// that is evaluated once up-front, and a per-element initializer that
4730
/// runs once for each array element.
4731
///
4732
/// Within the per-element initializer, the common expression may be referenced
4733
/// via an OpaqueValueExpr, and the current index may be obtained via an
4734
/// ArrayInitIndexExpr.
4735
class ArrayInitLoopExpr : public Expr {
4736
  Stmt *SubExprs[2];
4737
4738
  explicit ArrayInitLoopExpr(EmptyShell Empty)
4739
1
      : Expr(ArrayInitLoopExprClass, Empty), SubExprs{} {}
4740
4741
public:
4742
  explicit ArrayInitLoopExpr(QualType T, Expr *CommonInit, Expr *ElementInit)
4743
      : Expr(ArrayInitLoopExprClass, T, VK_RValue, OK_Ordinary, false,
4744
             CommonInit->isValueDependent() || ElementInit->isValueDependent(),
4745
             T->isInstantiationDependentType(),
4746
             CommonInit->containsUnexpandedParameterPack() ||
4747
                 ElementInit->containsUnexpandedParameterPack()),
4748
1.05k
        SubExprs{CommonInit, ElementInit} {}
4749
4750
  /// Get the common subexpression shared by all initializations (the source
4751
  /// array).
4752
911
  OpaqueValueExpr *getCommonExpr() const {
4753
911
    return cast<OpaqueValueExpr>(SubExprs[0]);
4754
911
  }
4755
4756
  /// Get the initializer to use for each array element.
4757
67
  Expr *getSubExpr() const { return cast<Expr>(SubExprs[1]); }
4758
4759
28
  llvm::APInt getArraySize() const {
4760
28
    return cast<ConstantArrayType>(getType()->castAsArrayTypeUnsafe())
4761
28
        ->getSize();
4762
28
  }
4763
4764
1.28M
  static bool classof(const Stmt *S) {
4765
1.28M
    return S->getStmtClass() == ArrayInitLoopExprClass;
4766
1.28M
  }
4767
4768
484
  SourceLocation getBeginLoc() const LLVM_READONLY {
4769
484
    return getCommonExpr()->getBeginLoc();
4770
484
  }
4771
386
  SourceLocation getEndLoc() const LLVM_READONLY {
4772
386
    return getCommonExpr()->getEndLoc();
4773
386
  }
4774
4775
1.14k
  child_range children() {
4776
1.14k
    return child_range(SubExprs, SubExprs + 2);
4777
1.14k
  }
4778
0
  const_child_range children() const {
4779
0
    return const_child_range(SubExprs, SubExprs + 2);
4780
0
  }
4781
4782
  friend class ASTReader;
4783
  friend class ASTStmtReader;
4784
  friend class ASTStmtWriter;
4785
};
4786
4787
/// Represents the index of the current element of an array being
4788
/// initialized by an ArrayInitLoopExpr. This can only appear within the
4789
/// subexpression of an ArrayInitLoopExpr.
4790
class ArrayInitIndexExpr : public Expr {
4791
  explicit ArrayInitIndexExpr(EmptyShell Empty)
4792
1
      : Expr(ArrayInitIndexExprClass, Empty) {}
4793
4794
public:
4795
  explicit ArrayInitIndexExpr(QualType T)
4796
      : Expr(ArrayInitIndexExprClass, T, VK_RValue, OK_Ordinary,
4797
1.05k
             false, false, false, false) {}
4798
4799
  static bool classof(const Stmt *S) {
4800
    return S->getStmtClass() == ArrayInitIndexExprClass;
4801
  }
4802
4803
151
  SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
4804
73
  SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
4805
4806
115
  child_range children() {
4807
115
    return child_range(child_iterator(), child_iterator());
4808
115
  }
4809
0
  const_child_range children() const {
4810
0
    return const_child_range(const_child_iterator(), const_child_iterator());
4811
0
  }
4812
4813
  friend class ASTReader;
4814
  friend class ASTStmtReader;
4815
};
4816
4817
/// Represents an implicitly-generated value initialization of
4818
/// an object of a given type.
4819
///
4820
/// Implicit value initializations occur within semantic initializer
4821
/// list expressions (InitListExpr) as placeholders for subobject
4822
/// initializations not explicitly specified by the user.
4823
///
4824
/// \see InitListExpr
4825
class ImplicitValueInitExpr : public Expr {
4826
public:
4827
  explicit ImplicitValueInitExpr(QualType ty)
4828
    : Expr(ImplicitValueInitExprClass, ty, VK_RValue, OK_Ordinary,
4829
464k
           false, false, ty->isInstantiationDependentType(), false) { }
4830
4831
  /// Construct an empty implicit value initialization.
4832
  explicit ImplicitValueInitExpr(EmptyShell Empty)
4833
63
    : Expr(ImplicitValueInitExprClass, Empty) { }
4834
4835
2.09M
  static bool classof(const Stmt *T) {
4836
2.09M
    return T->getStmtClass() == ImplicitValueInitExprClass;
4837
2.09M
  }
4838
4839
22.7k
  SourceLocation getBeginLoc() const LLVM_READONLY { return SourceLocation(); }
4840
181
  SourceLocation getEndLoc() const LLVM_READONLY { return SourceLocation(); }
4841
4842
  // Iterators
4843
36.5k
  child_range children() {
4844
36.5k
    return child_range(child_iterator(), child_iterator());
4845
36.5k
  }
4846
0
  const_child_range children() const {
4847
0
    return const_child_range(const_child_iterator(), const_child_iterator());
4848
0
  }
4849
};
4850
4851
class ParenListExpr : public Expr {
4852
  Stmt **Exprs;
4853
  unsigned NumExprs;
4854
  SourceLocation LParenLoc, RParenLoc;
4855
4856
public:
4857
  ParenListExpr(const ASTContext& C, SourceLocation lparenloc,
4858
                ArrayRef<Expr*> exprs, SourceLocation rparenloc);
4859
4860
  /// Build an empty paren list.
4861
868
  explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
4862
4863
942k
  unsigned getNumExprs() const { return NumExprs; }
4864
4865
3
  const Expr* getExpr(unsigned Init) const {
4866
3
    assert(Init < getNumExprs() && "Initializer access out of range!");
4867
3
    return cast_or_null<Expr>(Exprs[Init]);
4868
3
  }
4869
4870
481k
  Expr* getExpr(unsigned Init) {
4871
481k
    assert(Init < getNumExprs() && "Initializer access out of range!");
4872
481k
    return cast_or_null<Expr>(Exprs[Init]);
4873
481k
  }
4874
4875
448k
  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
4876
4877
195
  ArrayRef<Expr *> exprs() {
4878
195
    return llvm::makeArrayRef(getExprs(), getNumExprs());
4879
195
  }
4880
4881
531k
  SourceLocation getLParenLoc() const { return LParenLoc; }
4882
531k
  SourceLocation getRParenLoc() const { return RParenLoc; }
4883
4884
414k
  SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
4885
409k
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
4886
4887
19.4M
  static bool classof(const Stmt *T) {
4888
19.4M
    return T->getStmtClass() == ParenListExprClass;
4889
19.4M
  }
4890
4891
  // Iterators
4892
38.4k
  child_range children() {
4893
38.4k
    return child_range(&Exprs[0], &Exprs[0]+NumExprs);
4894
38.4k
  }
4895
0
  const_child_range children() const {
4896
0
    return const_child_range(&Exprs[0], &Exprs[0] + NumExprs);
4897
0
  }
4898
4899
  friend class ASTStmtReader;
4900
  friend class ASTStmtWriter;
4901
};
4902
4903
/// Represents a C11 generic selection.
4904
///
4905
/// A generic selection (C11 6.5.1.1) contains an unevaluated controlling
4906
/// expression, followed by one or more generic associations.  Each generic
4907
/// association specifies a type name and an expression, or "default" and an
4908
/// expression (in which case it is known as a default generic association).
4909
/// The type and value of the generic selection are identical to those of its
4910
/// result expression, which is defined as the expression in the generic
4911
/// association with a type name that is compatible with the type of the
4912
/// controlling expression, or the expression in the default generic association
4913
/// if no types are compatible.  For example:
4914
///
4915
/// @code
4916
/// _Generic(X, double: 1, float: 2, default: 3)
4917
/// @endcode
4918
///
4919
/// The above expression evaluates to 1 if 1.0 is substituted for X, 2 if 1.0f
4920
/// or 3 if "hello".
4921
///
4922
/// As an extension, generic selections are allowed in C++, where the following
4923
/// additional semantics apply:
4924
///
4925
/// Any generic selection whose controlling expression is type-dependent or
4926
/// which names a dependent type in its association list is result-dependent,
4927
/// which means that the choice of result expression is dependent.
4928
/// Result-dependent generic associations are both type- and value-dependent.
4929
class GenericSelectionExpr : public Expr {
4930
  enum { CONTROLLING, END_EXPR };
4931
  TypeSourceInfo **AssocTypes;
4932
  Stmt **SubExprs;
4933
  unsigned NumAssocs, ResultIndex;
4934
  SourceLocation GenericLoc, DefaultLoc, RParenLoc;
4935
4936
public:
4937
  GenericSelectionExpr(const ASTContext &Context,
4938
                       SourceLocation GenericLoc, Expr *ControllingExpr,
4939
                       ArrayRef<TypeSourceInfo*> AssocTypes,
4940
                       ArrayRef<Expr*> AssocExprs,
4941
                       SourceLocation DefaultLoc, SourceLocation RParenLoc,
4942
                       bool ContainsUnexpandedParameterPack,
4943
                       unsigned ResultIndex);
4944
4945
  /// This constructor is used in the result-dependent case.
4946
  GenericSelectionExpr(const ASTContext &Context,
4947
                       SourceLocation GenericLoc, Expr *ControllingExpr,
4948
                       ArrayRef<TypeSourceInfo*> AssocTypes,
4949
                       ArrayRef<Expr*> AssocExprs,
4950
                       SourceLocation DefaultLoc, SourceLocation RParenLoc,
4951
                       bool ContainsUnexpandedParameterPack);
4952
4953
  explicit GenericSelectionExpr(EmptyShell Empty)
4954
1
    : Expr(GenericSelectionExprClass, Empty) { }
4955
4956
114
  unsigned getNumAssocs() const { return NumAssocs; }
4957
4958
15
  SourceLocation getGenericLoc() const { return GenericLoc; }
4959
15
  SourceLocation getDefaultLoc() const { return DefaultLoc; }
4960
15
  SourceLocation getRParenLoc() const { return RParenLoc; }
4961
4962
59
  const Expr *getAssocExpr(unsigned i) const {
4963
59
    return cast<Expr>(SubExprs[END_EXPR+i]);
4964
59
  }
4965
600
  Expr *getAssocExpr(unsigned i) { return cast<Expr>(SubExprs[END_EXPR+i]); }
4966
1
  ArrayRef<Expr *> getAssocExprs() const {
4967
1
    return NumAssocs
4968
1
               ? llvm::makeArrayRef(
4969
1
                     &reinterpret_cast<Expr **>(SubExprs)[END_EXPR], NumAssocs)
4970
1
               : 
None0
;
4971
1
  }
4972
12
  const TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) const {
4973
12
    return AssocTypes[i];
4974
12
  }
4975
76
  TypeSourceInfo *getAssocTypeSourceInfo(unsigned i) { return AssocTypes[i]; }
4976
1
  ArrayRef<TypeSourceInfo *> getAssocTypeSourceInfos() const {
4977
1
    return NumAssocs ? llvm::makeArrayRef(&AssocTypes[0], NumAssocs) : 
None0
;
4978
1
  }
4979
4980
12
  QualType getAssocType(unsigned i) const {
4981
12
    if (const TypeSourceInfo *TS = getAssocTypeSourceInfo(i))
4982
9
      return TS->getType();
4983
3
    else
4984
3
      return QualType();
4985
12
  }
4986
4987
1
  const Expr *getControllingExpr() const {
4988
1
    return cast<Expr>(SubExprs[CONTROLLING]);
4989
1
  }
4990
24
  Expr *getControllingExpr() { return cast<Expr>(SubExprs[CONTROLLING]); }
4991
4992
  /// Whether this generic selection is result-dependent.
4993
489
  bool isResultDependent() const { return ResultIndex == -1U; }
4994
4995
  /// The zero-based index of the result expression's generic association in
4996
  /// the generic selection's association list.  Defined only if the
4997
  /// generic selection is not result-dependent.
4998
581
  unsigned getResultIndex() const {
4999
581
    assert(!isResultDependent() && "Generic selection is result-dependent");
5000
581
    return ResultIndex;
5001
581
  }
5002
5003
  /// The generic selection's result expression.  Defined only if the
5004
  /// generic selection is not result-dependent.
5005
55
  const Expr *getResultExpr() const { return getAssocExpr(getResultIndex()); }
5006
524
  Expr *getResultExpr() { return getAssocExpr(getResultIndex()); }
5007
5008
373
  SourceLocation getBeginLoc() const LLVM_READONLY { return GenericLoc; }
5009
33
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
5010
5011
354M
  static bool classof(const Stmt *T) {
5012
354M
    return T->getStmtClass() == GenericSelectionExprClass;
5013
354M
  }
5014
5015
7
  child_range children() {
5016
7
    return child_range(SubExprs, SubExprs+END_EXPR+NumAssocs);
5017
7
  }
5018
0
  const_child_range children() const {
5019
0
    return const_child_range(SubExprs, SubExprs + END_EXPR + NumAssocs);
5020
0
  }
5021
  friend class ASTStmtReader;
5022
};
5023
5024
//===----------------------------------------------------------------------===//
5025
// Clang Extensions
5026
//===----------------------------------------------------------------------===//
5027
5028
/// ExtVectorElementExpr - This represents access to specific elements of a
5029
/// vector, and may occur on the left hand side or right hand side.  For example
5030
/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
5031
///
5032
/// Note that the base may have either vector or pointer to vector type, just
5033
/// like a struct field reference.
5034
///
5035
class ExtVectorElementExpr : public Expr {
5036
  Stmt *Base;
5037
  IdentifierInfo *Accessor;
5038
  SourceLocation AccessorLoc;
5039
public:
5040
  ExtVectorElementExpr(QualType ty, ExprValueKind VK, Expr *base,
5041
                       IdentifierInfo &accessor, SourceLocation loc)
5042
    : Expr(ExtVectorElementExprClass, ty, VK,
5043
           (VK == VK_RValue ? OK_Ordinary : OK_VectorComponent),
5044
           base->isTypeDependent(), base->isValueDependent(),
5045
           base->isInstantiationDependent(),
5046
           base->containsUnexpandedParameterPack()),
5047
398
      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
5048
5049
  /// Build an empty vector element expression.
5050
  explicit ExtVectorElementExpr(EmptyShell Empty)
5051
15
    : Expr(ExtVectorElementExprClass, Empty) { }
5052
5053
4.25k
  const Expr *getBase() const { return cast<Expr>(Base); }
5054
29
  Expr *getBase() { return cast<Expr>(Base); }
5055
15
  void setBase(Expr *E) { Base = E; }
5056
5057
57
  IdentifierInfo &getAccessor() const { return *Accessor; }
5058
15
  void setAccessor(IdentifierInfo *II) { Accessor = II; }
5059
5060
17
  SourceLocation getAccessorLoc() const { return AccessorLoc; }
5061
15
  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
5062
5063
  /// getNumElements - Get the number of components being selected.
5064
  unsigned getNumElements() const;
5065
5066
  /// containsDuplicateElements - Return true if any element access is
5067
  /// repeated.
5068
  bool containsDuplicateElements() const;
5069
5070
  /// getEncodedElementAccess - Encode the elements accessed into an llvm
5071
  /// aggregate Constant of ConstantInt(s).
5072
  void getEncodedElementAccess(SmallVectorImpl<uint32_t> &Elts) const;
5073
5074
3.26k
  SourceLocation getBeginLoc() const LLVM_READONLY {
5075
3.26k
    return getBase()->getBeginLoc();
5076
3.26k
  }
5077
52
  SourceLocation getEndLoc() const LLVM_READONLY { return AccessorLoc; }
5078
5079
  /// isArrow - Return true if the base expression is a pointer to vector,
5080
  /// return false if the base expression is a vector.
5081
  bool isArrow() const;
5082
5083
707k
  static bool classof(const Stmt *T) {
5084
707k
    return T->getStmtClass() == ExtVectorElementExprClass;
5085
707k
  }
5086
5087
  // Iterators
5088
1.00k
  child_range children() { return child_range(&Base, &Base+1); }
5089
0
  const_child_range children() const {
5090
0
    return const_child_range(&Base, &Base + 1);
5091
0
  }
5092
};
5093
5094
/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
5095
/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
5096
class BlockExpr : public Expr {
5097
protected:
5098
  BlockDecl *TheBlock;
5099
public:
5100
  BlockExpr(BlockDecl *BD, QualType ty)
5101
    : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary,
5102
           ty->isDependentType(), ty->isDependentType(),
5103
           ty->isInstantiationDependentType() || BD->isDependentContext(),
5104
           false),
5105
2.65k
      TheBlock(BD) {}
5106
5107
  /// Build an empty block expression.
5108
11
  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
5109
5110
5.09k
  const BlockDecl *getBlockDecl() const { return TheBlock; }
5111
12.6k
  BlockDecl *getBlockDecl() { return TheBlock; }
5112
11
  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
5113
5114
  // Convenience functions for probing the underlying BlockDecl.
5115
  SourceLocation getCaretLocation() const;
5116
  const Stmt *getBody() const;
5117
  Stmt *getBody();
5118
5119
20.7k
  SourceLocation getBeginLoc() const LLVM_READONLY {
5120
20.7k
    return getCaretLocation();
5121
20.7k
  }
5122
3.47k
  SourceLocation getEndLoc() const LLVM_READONLY {
5123
3.47k
    return getBody()->getEndLoc();
5124
3.47k
  }
5125
5126
  /// getFunctionType - Return the underlying function type for this block.
5127
  const FunctionProtoType *getFunctionType() const;
5128
5129
19.3k
  static bool classof(const Stmt *T) {
5130
19.3k
    return T->getStmtClass() == BlockExprClass;
5131
19.3k
  }
5132
5133
  // Iterators
5134
4.29k
  child_range children() {
5135
4.29k
    return child_range(child_iterator(), child_iterator());
5136
4.29k
  }
5137
0
  const_child_range children() const {
5138
0
    return const_child_range(const_child_iterator(), const_child_iterator());
5139
0
  }
5140
};
5141
5142
/// AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2]
5143
/// This AST node provides support for reinterpreting a type to another
5144
/// type of the same size.
5145
class AsTypeExpr : public Expr {
5146
private:
5147
  Stmt *SrcExpr;
5148
  SourceLocation BuiltinLoc, RParenLoc;
5149
5150
  friend class ASTReader;
5151
  friend class ASTStmtReader;
5152
0
  explicit AsTypeExpr(EmptyShell Empty) : Expr(AsTypeExprClass, Empty) {}
5153
5154
public:
5155
  AsTypeExpr(Expr* SrcExpr, QualType DstType,
5156
             ExprValueKind VK, ExprObjectKind OK,
5157
             SourceLocation BuiltinLoc, SourceLocation RParenLoc)
5158
    : Expr(AsTypeExprClass, DstType, VK, OK,
5159
           DstType->isDependentType(),
5160
           DstType->isDependentType() || SrcExpr->isValueDependent(),
5161
           (DstType->isInstantiationDependentType() ||
5162
            SrcExpr->isInstantiationDependent()),
5163
           (DstType->containsUnexpandedParameterPack() ||
5164
            SrcExpr->containsUnexpandedParameterPack())),
5165
22
  SrcExpr(SrcExpr), BuiltinLoc(BuiltinLoc), RParenLoc(RParenLoc) {}
5166
5167
  /// getSrcExpr - Return the Expr to be converted.
5168
17
  Expr *getSrcExpr() const { return cast<Expr>(SrcExpr); }
5169
5170
  /// getBuiltinLoc - Return the location of the __builtin_astype token.
5171
0
  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
5172
5173
  /// getRParenLoc - Return the location of final right parenthesis.
5174
0
  SourceLocation getRParenLoc() const { return RParenLoc; }
5175
5176
160
  SourceLocation getBeginLoc() const LLVM_READONLY { return BuiltinLoc; }
5177
0
  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
5178
5179
  static bool classof(const Stmt *T) {
5180
    return T->getStmtClass() == AsTypeExprClass;
5181
  }
5182
5183
  // Iterators
5184
76
  child_range children() { return child_range(&SrcExpr, &SrcExpr+1); }
5185
0
  const_child_range children() const {
5186
0
    return const_child_range(&SrcExpr, &SrcExpr + 1);
5187
0
  }
5188
};
5189
5190
/// PseudoObjectExpr - An expression which accesses a pseudo-object
5191
/// l-value.  A pseudo-object is an abstract object, accesses to which
5192
/// are translated to calls.  The pseudo-object expression has a
5193
/// syntactic form, which shows how the expression was actually
5194
/// written in the source code, and a semantic form, which is a series
5195
/// of expressions to be executed in order which detail how the
5196
/// operation is actually evaluated.  Optionally, one of the semantic
5197
/// forms may also provide a result value for the expression.
5198
///
5199
/// If any of the semantic-form expressions is an OpaqueValueExpr,
5200
/// that OVE is required to have a source expression, and it is bound
5201
/// to the result of that source expression.  Such OVEs may appear
5202
/// only in subsequent semantic-form expressions and as
5203
/// sub-expressions of the syntactic form.
5204
///
5205
/// PseudoObjectExpr should be used only when an operation can be
5206
/// usefully described in terms of fairly simple rewrite rules on
5207
/// objects and functions that are meant to be used by end-developers.
5208
/// For example, under the Itanium ABI, dynamic casts are implemented
5209
/// as a call to a runtime function called __dynamic_cast; using this
5210
/// class to describe that would be inappropriate because that call is
5211
/// not really part of the user-visible semantics, and instead the
5212
/// cast is properly reflected in the AST and IR-generation has been
5213
/// taught to generate the call as necessary.  In contrast, an
5214
/// Objective-C property access is semantically defined to be
5215
/// equivalent to a particular message send, and this is very much
5216
/// part of the user model.  The name of this class encourages this
5217
/// modelling design.
5218
class PseudoObjectExpr final
5219
    : public Expr,
5220
      private llvm::TrailingObjects<PseudoObjectExpr, Expr *> {
5221
  // PseudoObjectExprBits.NumSubExprs - The number of sub-expressions.
5222
  // Always at least two, because the first sub-expression is the
5223
  // syntactic form.
5224
5225
  // PseudoObjectExprBits.ResultIndex - The index of the
5226
  // sub-expression holding the result.  0 means the result is void,
5227
  // which is unambiguous because it's the index of the syntactic
5228
  // form.  Note that this is therefore 1 higher than the value passed
5229
  // in to Create, which is an index within the semantic forms.
5230
  // Note also that ASTStmtWriter assumes this encoding.
5231
5232
24.2k
  Expr **getSubExprsBuffer() { return getTrailingObjects<Expr *>(); }
5233
25.2k
  const Expr * const *getSubExprsBuffer() const {
5234
25.2k
    return getTrailingObjects<Expr *>();
5235
25.2k
  }
5236
5237
  PseudoObjectExpr(QualType type, ExprValueKind VK,
5238
                   Expr *syntactic, ArrayRef<Expr*> semantic,
5239
                   unsigned resultIndex);
5240
5241
  PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs);
5242
5243
10.7k
  unsigned getNumSubExprs() const {
5244
10.7k
    return PseudoObjectExprBits.NumSubExprs;
5245
10.7k
  }
5246
5247
public:
5248
  /// NoResult - A value for the result index indicating that there is
5249
  /// no semantic result.
5250
  enum : unsigned { NoResult = ~0U };
5251
5252
  static PseudoObjectExpr *Create(const ASTContext &Context, Expr *syntactic,
5253
                                  ArrayRef<Expr*> semantic,
5254
                                  unsigned resultIndex);
5255
5256
  static PseudoObjectExpr *Create(const ASTContext &Context, EmptyShell shell,
5257
                                  unsigned numSemanticExprs);
5258
5259
  /// Return the syntactic form of this expression, i.e. the
5260
  /// expression it actually looks like.  Likely to be expressed in
5261
  /// terms of OpaqueValueExprs bound in the semantic form.
5262
3.49k
  Expr *getSyntacticForm() { return getSubExprsBuffer()[0]; }
5263
19.2k
  const Expr *getSyntacticForm() const { return getSubExprsBuffer()[0]; }
5264
5265
  /// Return the index of the result-bearing expression into the semantics
5266
  /// expressions, or PseudoObjectExpr::NoResult if there is none.
5267
31
  unsigned getResultExprIndex() const {
5268
31
    if (PseudoObjectExprBits.ResultIndex == 0) 
return NoResult3
;
5269
28
    return PseudoObjectExprBits.ResultIndex - 1;
5270
28
  }
5271
5272
  /// Return the result-bearing expression, or null if there is none.
5273
1.08k
  Expr *getResultExpr() {
5274
1.08k
    if (PseudoObjectExprBits.ResultIndex == 0)
5275
14
      return nullptr;
5276
1.06k
    return getSubExprsBuffer()[PseudoObjectExprBits.ResultIndex];
5277
1.06k
  }
5278
663
  const Expr *getResultExpr() const {
5279
663
    return const_cast<PseudoObjectExpr*>(this)->getResultExpr();
5280
663
  }
5281
5282
963
  unsigned getNumSemanticExprs() const { return getNumSubExprs() - 1; }
5283
5284
  typedef Expr * const *semantics_iterator;
5285
  typedef const Expr * const *const_semantics_iterator;
5286
4.22k
  semantics_iterator semantics_begin() {
5287
4.22k
    return getSubExprsBuffer() + 1;
5288
4.22k
  }
5289
392
  const_semantics_iterator semantics_begin() const {
5290
392
    return getSubExprsBuffer() + 1;
5291
392
  }
5292
4.22k
  semantics_iterator semantics_end() {
5293
4.22k
    return getSubExprsBuffer() + getNumSubExprs();
5294
4.22k
  }
5295
392
  const_semantics_iterator semantics_end() const {
5296
392
    return getSubExprsBuffer() + getNumSubExprs();
5297
392
  }
5298
5299
2.41k
  llvm::iterator_range<semantics_iterator> semantics() {
5300
2.41k
    return llvm::make_range(semantics_begin(), semantics_end());
5301
2.41k
  }
5302
0
  llvm::iterator_range<const_semantics_iterator> semantics() const {
5303
0
    return llvm::make_range(semantics_begin(), semantics_end());
5304
0
  }
5305
5306
2.16k
  Expr *getSemanticExpr(unsigned index) {
5307
2.16k
    assert(index + 1 < getNumSubExprs());
5308
2.16k
    return getSubExprsBuffer()[index + 1];
5309
2.16k
  }
5310
24
  const Expr *getSemanticExpr(unsigned index) const {
5311
24
    return const_cast<PseudoObjectExpr*>(this)->getSemanticExpr(index);
5312
24
  }
5313
5314
6.60k
  SourceLocation getExprLoc() const LLVM_READONLY {
5315
6.60k
    return getSyntacticForm()->getExprLoc();
5316
6.60k
  }
5317
5318
8.52k
  SourceLocation getBeginLoc() const LLVM_READONLY {
5319
8.52k
    return getSyntacticForm()->getBeginLoc();
5320
8.52k
  }
5321
1.81k
  SourceLocation getEndLoc() const LLVM_READONLY {
5322
1.81k
    return getSyntacticForm()->getEndLoc();
5323
1.81k
  }
5324
5325
5.21k
  child_range children() {
5326
5.21k
    const_child_range CCR =
5327
5.21k
        const_cast<const PseudoObjectExpr *>(this)->children();
5328
5.21k
    return child_range(cast_away_const(CCR.begin()),
5329
5.21k
                       cast_away_const(CCR.end()));
5330
5.21k
  }
5331
5.21k
  const_child_range children() const {
5332
5.21k
    Stmt *const *cs = const_cast<Stmt *const *>(
5333
5.21k
        reinterpret_cast<const Stmt *const *>(getSubExprsBuffer()));
5334
5.21k
    return const_child_range(cs, cs + getNumSubExprs());
5335
5.21k
  }
5336
5337
35.7M
  static bool classof(const Stmt *T) {
5338
35.7M
    return T->getStmtClass() == PseudoObjectExprClass;
5339
35.7M
  }
5340
5341
  friend TrailingObjects;
5342
  friend class ASTStmtReader;
5343
};
5344
5345