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