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