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