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