Expr.h revision 5baba9d98364a3525d6afa15a04cdad82fd6dd30
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/Stmt.h"
19#include "clang/AST/Type.h"
20#include "clang/AST/DeclAccessPair.h"
21#include "clang/AST/OperationKinds.h"
22#include "clang/AST/ASTVector.h"
23#include "clang/AST/UsuallyTinyPtrVector.h"
24#include "llvm/ADT/APSInt.h"
25#include "llvm/ADT/APFloat.h"
26#include "llvm/ADT/SmallVector.h"
27#include "llvm/ADT/StringRef.h"
28#include <vector>
29
30namespace clang {
31  class ASTContext;
32  class APValue;
33  class Decl;
34  class IdentifierInfo;
35  class ParmVarDecl;
36  class NamedDecl;
37  class ValueDecl;
38  class BlockDecl;
39  class CXXBaseSpecifier;
40  class CXXOperatorCallExpr;
41  class CXXMemberCallExpr;
42  class TemplateArgumentLoc;
43  class TemplateArgumentListInfo;
44
45/// \brief A simple array of base specifiers.
46typedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath;
47
48/// Expr - This represents one expression.  Note that Expr's are subclasses of
49/// Stmt.  This allows an expression to be transparently used any place a Stmt
50/// is required.
51///
52class Expr : public Stmt {
53  QualType TR;
54
55  virtual void ANCHOR(); // key function.
56protected:
57  /// TypeDependent - Whether this expression is type-dependent
58  /// (C++ [temp.dep.expr]).
59  bool TypeDependent : 1;
60
61  /// ValueDependent - Whether this expression is value-dependent
62  /// (C++ [temp.dep.constexpr]).
63  bool ValueDependent : 1;
64
65  /// ValueKind - The value classification of this expression.
66  /// Only actually used by certain subclasses.
67  unsigned ValueKind : 2;
68
69  enum { BitsRemaining = 28 };
70
71  Expr(StmtClass SC, QualType T, bool TD, bool VD)
72    : Stmt(SC), TypeDependent(TD), ValueDependent(VD), ValueKind(0) {
73    setType(T);
74  }
75
76  /// \brief Construct an empty expression.
77  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
78
79public:
80  /// \brief Increases the reference count for this expression.
81  ///
82  /// Invoke the Retain() operation when this expression
83  /// is being shared by another owner.
84  Expr *Retain() {
85    Stmt::Retain();
86    return this;
87  }
88
89  QualType getType() const { return TR; }
90  void setType(QualType t) {
91    // In C++, the type of an expression is always adjusted so that it
92    // will not have reference type an expression will never have
93    // reference type (C++ [expr]p6). Use
94    // QualType::getNonReferenceType() to retrieve the non-reference
95    // type. Additionally, inspect Expr::isLvalue to determine whether
96    // an expression that is adjusted in this manner should be
97    // considered an lvalue.
98    assert((t.isNull() || !t->isReferenceType()) &&
99           "Expressions can't have reference type");
100
101    TR = t;
102  }
103
104  /// isValueDependent - Determines whether this expression is
105  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
106  /// array bound of "Chars" in the following example is
107  /// value-dependent.
108  /// @code
109  /// template<int Size, char (&Chars)[Size]> struct meta_string;
110  /// @endcode
111  bool isValueDependent() const { return ValueDependent; }
112
113  /// \brief Set whether this expression is value-dependent or not.
114  void setValueDependent(bool VD) { ValueDependent = VD; }
115
116  /// isTypeDependent - Determines whether this expression is
117  /// type-dependent (C++ [temp.dep.expr]), which means that its type
118  /// could change from one template instantiation to the next. For
119  /// example, the expressions "x" and "x + y" are type-dependent in
120  /// the following code, but "y" is not type-dependent:
121  /// @code
122  /// template<typename T>
123  /// void add(T x, int y) {
124  ///   x + y;
125  /// }
126  /// @endcode
127  bool isTypeDependent() const { return TypeDependent; }
128
129  /// \brief Set whether this expression is type-dependent or not.
130  void setTypeDependent(bool TD) { TypeDependent = TD; }
131
132  /// SourceLocation tokens are not useful in isolation - they are low level
133  /// value objects created/interpreted by SourceManager. We assume AST
134  /// clients will have a pointer to the respective SourceManager.
135  virtual SourceRange getSourceRange() const = 0;
136
137  /// getExprLoc - Return the preferred location for the arrow when diagnosing
138  /// a problem with a generic expression.
139  virtual SourceLocation getExprLoc() const { return getLocStart(); }
140
141  /// isUnusedResultAWarning - Return true if this immediate expression should
142  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
143  /// with location to warn on and the source range[s] to report with the
144  /// warning.
145  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
146                              SourceRange &R2, ASTContext &Ctx) const;
147
148  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
149  /// incomplete type other than void. Nonarray expressions that can be lvalues:
150  ///  - name, where name must be a variable
151  ///  - e[i]
152  ///  - (e), where e must be an lvalue
153  ///  - e.name, where e must be an lvalue
154  ///  - e->name
155  ///  - *e, the type of e cannot be a function type
156  ///  - string-constant
157  ///  - reference type [C++ [expr]]
158  ///  - b ? x : y, where x and y are lvalues of suitable types [C++]
159  ///
160  enum isLvalueResult {
161    LV_Valid,
162    LV_NotObjectType,
163    LV_IncompleteVoidType,
164    LV_DuplicateVectorComponents,
165    LV_InvalidExpression,
166    LV_MemberFunction,
167    LV_SubObjCPropertySetting,
168    LV_ClassTemporary
169  };
170  isLvalueResult isLvalue(ASTContext &Ctx) const;
171
172  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
173  /// does not have an incomplete type, does not have a const-qualified type,
174  /// and if it is a structure or union, does not have any member (including,
175  /// recursively, any member or element of all contained aggregates or unions)
176  /// with a const-qualified type.
177  ///
178  /// \param Loc [in] [out] - A source location which *may* be filled
179  /// in with the location of the expression making this a
180  /// non-modifiable lvalue, if specified.
181  enum isModifiableLvalueResult {
182    MLV_Valid,
183    MLV_NotObjectType,
184    MLV_IncompleteVoidType,
185    MLV_DuplicateVectorComponents,
186    MLV_InvalidExpression,
187    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
188    MLV_IncompleteType,
189    MLV_ConstQualified,
190    MLV_ArrayType,
191    MLV_NotBlockQualified,
192    MLV_ReadonlyProperty,
193    MLV_NoSetterProperty,
194    MLV_MemberFunction,
195    MLV_SubObjCPropertySetting,
196    MLV_ClassTemporary
197  };
198  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
199                                              SourceLocation *Loc = 0) const;
200
201  /// \brief The return type of classify(). Represents the C++0x expression
202  ///        taxonomy.
203  class Classification {
204  public:
205    /// \brief The various classification results. Most of these mean prvalue.
206    enum Kinds {
207      CL_LValue,
208      CL_XValue,
209      CL_Function, // Functions cannot be lvalues in C.
210      CL_Void, // Void cannot be an lvalue in C.
211      CL_DuplicateVectorComponents, // A vector shuffle with dupes.
212      CL_MemberFunction, // An expression referring to a member function
213      CL_SubObjCPropertySetting,
214      CL_ClassTemporary, // A prvalue of class type
215      CL_PRValue // A prvalue for any other reason, of any other type
216    };
217    /// \brief The results of modification testing.
218    enum ModifiableType {
219      CM_Untested, // testModifiable was false.
220      CM_Modifiable,
221      CM_RValue, // Not modifiable because it's an rvalue
222      CM_Function, // Not modifiable because it's a function; C++ only
223      CM_LValueCast, // Same as CM_RValue, but indicates GCC cast-as-lvalue ext
224      CM_NotBlockQualified, // Not captured in the closure
225      CM_NoSetterProperty,// Implicit assignment to ObjC property without setter
226      CM_ConstQualified,
227      CM_ArrayType,
228      CM_IncompleteType
229    };
230
231  private:
232    friend class Expr;
233
234    unsigned short Kind;
235    unsigned short Modifiable;
236
237    explicit Classification(Kinds k, ModifiableType m)
238      : Kind(k), Modifiable(m)
239    {}
240
241  public:
242    Classification() {}
243
244    Kinds getKind() const { return static_cast<Kinds>(Kind); }
245    ModifiableType getModifiable() const {
246      assert(Modifiable != CM_Untested && "Did not test for modifiability.");
247      return static_cast<ModifiableType>(Modifiable);
248    }
249    bool isLValue() const { return Kind == CL_LValue; }
250    bool isXValue() const { return Kind == CL_XValue; }
251    bool isGLValue() const { return Kind <= CL_XValue; }
252    bool isPRValue() const { return Kind >= CL_Function; }
253    bool isRValue() const { return Kind >= CL_XValue; }
254    bool isModifiable() const { return getModifiable() == CM_Modifiable; }
255  };
256  /// \brief classify - Classify this expression according to the C++0x
257  ///        expression taxonomy.
258  ///
259  /// C++0x defines ([basic.lval]) a new taxonomy of expressions to replace the
260  /// old lvalue vs rvalue. This function determines the type of expression this
261  /// is. There are three expression types:
262  /// - lvalues are classical lvalues as in C++03.
263  /// - prvalues are equivalent to rvalues in C++03.
264  /// - xvalues are expressions yielding unnamed rvalue references, e.g. a
265  ///   function returning an rvalue reference.
266  /// lvalues and xvalues are collectively referred to as glvalues, while
267  /// prvalues and xvalues together form rvalues.
268  Classification Classify(ASTContext &Ctx) const {
269    return ClassifyImpl(Ctx, 0);
270  }
271
272  /// \brief classifyModifiable - Classify this expression according to the
273  ///        C++0x expression taxonomy, and see if it is valid on the left side
274  ///        of an assignment.
275  ///
276  /// This function extends classify in that it also tests whether the
277  /// expression is modifiable (C99 6.3.2.1p1).
278  /// \param Loc A source location that might be filled with a relevant location
279  ///            if the expression is not modifiable.
280  Classification ClassifyModifiable(ASTContext &Ctx, SourceLocation &Loc) const{
281    return ClassifyImpl(Ctx, &Loc);
282  }
283
284private:
285  Classification ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) const;
286
287public:
288
289  /// \brief If this expression refers to a bit-field, retrieve the
290  /// declaration of that bit-field.
291  FieldDecl *getBitField();
292
293  const FieldDecl *getBitField() const {
294    return const_cast<Expr*>(this)->getBitField();
295  }
296
297  /// \brief Returns whether this expression refers to a vector element.
298  bool refersToVectorElement() const;
299
300  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
301  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
302  /// but also int expressions which are produced by things like comparisons in
303  /// C.
304  bool isKnownToHaveBooleanValue() const;
305
306  /// isIntegerConstantExpr - Return true if this expression is a valid integer
307  /// constant expression, and, if so, return its value in Result.  If not a
308  /// valid i-c-e, return false and fill in Loc (if specified) with the location
309  /// of the invalid expression.
310  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
311                             SourceLocation *Loc = 0,
312                             bool isEvaluated = true) const;
313  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
314    llvm::APSInt X;
315    return isIntegerConstantExpr(X, Ctx, Loc);
316  }
317  /// isConstantInitializer - Returns true if this expression is a constant
318  /// initializer, which can be emitted at compile-time.
319  bool isConstantInitializer(ASTContext &Ctx, bool ForRef) const;
320
321  /// EvalResult is a struct with detailed info about an evaluated expression.
322  struct EvalResult {
323    /// Val - This is the value the expression can be folded to.
324    APValue Val;
325
326    /// HasSideEffects - Whether the evaluated expression has side effects.
327    /// For example, (f() && 0) can be folded, but it still has side effects.
328    bool HasSideEffects;
329
330    /// Diag - If the expression is unfoldable, then Diag contains a note
331    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
332    /// position for the error, and DiagExpr is the expression that caused
333    /// the error.
334    /// If the expression is foldable, but not an integer constant expression,
335    /// Diag contains a note diagnostic that describes why it isn't an integer
336    /// constant expression. If the expression *is* an integer constant
337    /// expression, then Diag will be zero.
338    unsigned Diag;
339    const Expr *DiagExpr;
340    SourceLocation DiagLoc;
341
342    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
343
344    // isGlobalLValue - Return true if the evaluated lvalue expression
345    // is global.
346    bool isGlobalLValue() const;
347    // hasSideEffects - Return true if the evaluated expression has
348    // side effects.
349    bool hasSideEffects() const {
350      return HasSideEffects;
351    }
352  };
353
354  /// Evaluate - Return true if this is a constant which we can fold using
355  /// any crazy technique (that has nothing to do with language standards) that
356  /// we want to.  If this function returns true, it returns the folded constant
357  /// in Result.
358  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
359
360  /// EvaluateAsBooleanCondition - Return true if this is a constant
361  /// which we we can fold and convert to a boolean condition using
362  /// any crazy technique that we want to.
363  bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const;
364
365  /// isEvaluatable - Call Evaluate to see if this expression can be constant
366  /// folded, but discard the result.
367  bool isEvaluatable(ASTContext &Ctx) const;
368
369  /// HasSideEffects - This routine returns true for all those expressions
370  /// which must be evaluated each time and must not be optimization away
371  /// or evaluated at compile time. Example is a function call, volatile
372  /// variable read.
373  bool HasSideEffects(ASTContext &Ctx) const;
374
375  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
376  /// must be called on an expression that constant folds to an integer.
377  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
378
379  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue
380  /// with link time known address.
381  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
382
383  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue.
384  bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const;
385
386  /// \brief Enumeration used to describe how \c isNullPointerConstant()
387  /// should cope with value-dependent expressions.
388  enum NullPointerConstantValueDependence {
389    /// \brief Specifies that the expression should never be value-dependent.
390    NPC_NeverValueDependent = 0,
391
392    /// \brief Specifies that a value-dependent expression of integral or
393    /// dependent type should be considered a null pointer constant.
394    NPC_ValueDependentIsNull,
395
396    /// \brief Specifies that a value-dependent expression should be considered
397    /// to never be a null pointer constant.
398    NPC_ValueDependentIsNotNull
399  };
400
401  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
402  /// integer constant expression with the value zero, or if this is one that is
403  /// cast to void*.
404  bool isNullPointerConstant(ASTContext &Ctx,
405                             NullPointerConstantValueDependence NPC) const;
406
407  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
408  /// write barrier.
409  bool isOBJCGCCandidate(ASTContext &Ctx) const;
410
411  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
412  ///  its subexpression.  If that subexpression is also a ParenExpr,
413  ///  then this method recursively returns its subexpression, and so forth.
414  ///  Otherwise, the method returns the current Expr.
415  Expr *IgnoreParens();
416
417  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
418  /// or CastExprs, returning their operand.
419  Expr *IgnoreParenCasts();
420
421  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off any
422  /// ParenExpr or ImplicitCastExprs, returning their operand.
423  Expr *IgnoreParenImpCasts();
424
425  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
426  /// value (including ptr->int casts of the same size).  Strip off any
427  /// ParenExpr or CastExprs, returning their operand.
428  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
429
430  /// \brief Determine whether this expression is a default function argument.
431  ///
432  /// Default arguments are implicitly generated in the abstract syntax tree
433  /// by semantic analysis for function calls, object constructions, etc. in
434  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
435  /// this routine also looks through any implicit casts to determine whether
436  /// the expression is a default argument.
437  bool isDefaultArgument() const;
438
439  /// \brief Determine whether this expression directly creates a
440  /// temporary object (of class type).
441  bool isTemporaryObject() const { return getTemporaryObject() != 0; }
442
443  /// \brief If this expression directly creates a temporary object of
444  /// class type, return the expression that actually constructs that
445  /// temporary object.
446  const Expr *getTemporaryObject() const;
447
448  const Expr *IgnoreParens() const {
449    return const_cast<Expr*>(this)->IgnoreParens();
450  }
451  const Expr *IgnoreParenCasts() const {
452    return const_cast<Expr*>(this)->IgnoreParenCasts();
453  }
454  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
455    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
456  }
457
458  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
459  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
460
461  static bool classof(const Stmt *T) {
462    return T->getStmtClass() >= firstExprConstant &&
463           T->getStmtClass() <= lastExprConstant;
464  }
465  static bool classof(const Expr *) { return true; }
466};
467
468
469//===----------------------------------------------------------------------===//
470// Primary Expressions.
471//===----------------------------------------------------------------------===//
472
473/// \brief Represents the qualifier that may precede a C++ name, e.g., the
474/// "std::" in "std::sort".
475struct NameQualifier {
476  /// \brief The nested name specifier.
477  NestedNameSpecifier *NNS;
478
479  /// \brief The source range covered by the nested name specifier.
480  SourceRange Range;
481};
482
483/// \brief Represents an explicit template argument list in C++, e.g.,
484/// the "<int>" in "sort<int>".
485struct ExplicitTemplateArgumentList {
486  /// \brief The source location of the left angle bracket ('<');
487  SourceLocation LAngleLoc;
488
489  /// \brief The source location of the right angle bracket ('>');
490  SourceLocation RAngleLoc;
491
492  /// \brief The number of template arguments in TemplateArgs.
493  /// The actual template arguments (if any) are stored after the
494  /// ExplicitTemplateArgumentList structure.
495  unsigned NumTemplateArgs;
496
497  /// \brief Retrieve the template arguments
498  TemplateArgumentLoc *getTemplateArgs() {
499    return reinterpret_cast<TemplateArgumentLoc *> (this + 1);
500  }
501
502  /// \brief Retrieve the template arguments
503  const TemplateArgumentLoc *getTemplateArgs() const {
504    return reinterpret_cast<const TemplateArgumentLoc *> (this + 1);
505  }
506
507  void initializeFrom(const TemplateArgumentListInfo &List);
508  void copyInto(TemplateArgumentListInfo &List) const;
509  static std::size_t sizeFor(unsigned NumTemplateArgs);
510  static std::size_t sizeFor(const TemplateArgumentListInfo &List);
511};
512
513/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
514/// enum, etc.
515class DeclRefExpr : public Expr {
516  enum {
517    // Flag on DecoratedD that specifies when this declaration reference
518    // expression has a C++ nested-name-specifier.
519    HasQualifierFlag = 0x01,
520    // Flag on DecoratedD that specifies when this declaration reference
521    // expression has an explicit C++ template argument list.
522    HasExplicitTemplateArgumentListFlag = 0x02
523  };
524
525  // DecoratedD - The declaration that we are referencing, plus two bits to
526  // indicate whether (1) the declaration's name was explicitly qualified and
527  // (2) the declaration's name was followed by an explicit template
528  // argument list.
529  llvm::PointerIntPair<ValueDecl *, 2> DecoratedD;
530
531  // Loc - The location of the declaration name itself.
532  SourceLocation Loc;
533
534  /// DNLoc - Provides source/type location info for the
535  /// declaration name embedded in DecoratedD.
536  DeclarationNameLoc DNLoc;
537
538  /// \brief Retrieve the qualifier that preceded the declaration name, if any.
539  NameQualifier *getNameQualifier() {
540    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
541      return 0;
542
543    return reinterpret_cast<NameQualifier *> (this + 1);
544  }
545
546  /// \brief Retrieve the qualifier that preceded the member name, if any.
547  const NameQualifier *getNameQualifier() const {
548    return const_cast<DeclRefExpr *>(this)->getNameQualifier();
549  }
550
551  DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
552              ValueDecl *D, SourceLocation NameLoc,
553              const TemplateArgumentListInfo *TemplateArgs,
554              QualType T);
555
556  DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
557              ValueDecl *D, const DeclarationNameInfo &NameInfo,
558              const TemplateArgumentListInfo *TemplateArgs,
559              QualType T);
560
561  /// \brief Construct an empty declaration reference expression.
562  explicit DeclRefExpr(EmptyShell Empty)
563    : Expr(DeclRefExprClass, Empty) { }
564
565  /// \brief Computes the type- and value-dependence flags for this
566  /// declaration reference expression.
567  void computeDependence();
568
569public:
570  DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
571    Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) {
572    computeDependence();
573  }
574
575  static DeclRefExpr *Create(ASTContext &Context,
576                             NestedNameSpecifier *Qualifier,
577                             SourceRange QualifierRange,
578                             ValueDecl *D,
579                             SourceLocation NameLoc,
580                             QualType T,
581                             const TemplateArgumentListInfo *TemplateArgs = 0);
582
583  static DeclRefExpr *Create(ASTContext &Context,
584                             NestedNameSpecifier *Qualifier,
585                             SourceRange QualifierRange,
586                             ValueDecl *D,
587                             const DeclarationNameInfo &NameInfo,
588                             QualType T,
589                             const TemplateArgumentListInfo *TemplateArgs = 0);
590
591  /// \brief Construct an empty declaration reference expression.
592  static DeclRefExpr *CreateEmpty(ASTContext &Context,
593                                  bool HasQualifier, unsigned NumTemplateArgs);
594
595  ValueDecl *getDecl() { return DecoratedD.getPointer(); }
596  const ValueDecl *getDecl() const { return DecoratedD.getPointer(); }
597  void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); }
598
599  DeclarationNameInfo getNameInfo() const {
600    return DeclarationNameInfo(getDecl()->getDeclName(), Loc, DNLoc);
601  }
602
603  SourceLocation getLocation() const { return Loc; }
604  void setLocation(SourceLocation L) { Loc = L; }
605  virtual SourceRange getSourceRange() const;
606
607  /// \brief Determine whether this declaration reference was preceded by a
608  /// C++ nested-name-specifier, e.g., \c N::foo.
609  bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; }
610
611  /// \brief If the name was qualified, retrieves the source range of
612  /// the nested-name-specifier that precedes the name. Otherwise,
613  /// returns an empty source range.
614  SourceRange getQualifierRange() const {
615    if (!hasQualifier())
616      return SourceRange();
617
618    return getNameQualifier()->Range;
619  }
620
621  /// \brief If the name was qualified, retrieves the nested-name-specifier
622  /// that precedes the name. Otherwise, returns NULL.
623  NestedNameSpecifier *getQualifier() const {
624    if (!hasQualifier())
625      return 0;
626
627    return getNameQualifier()->NNS;
628  }
629
630  bool hasExplicitTemplateArgs() const {
631    return (DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag);
632  }
633
634  /// \brief Retrieve the explicit template argument list that followed the
635  /// member template name.
636  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
637    assert(hasExplicitTemplateArgs());
638
639    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
640      return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
641
642    return *reinterpret_cast<ExplicitTemplateArgumentList *>(
643                                                      getNameQualifier() + 1);
644  }
645
646  /// \brief Retrieve the explicit template argument list that followed the
647  /// member template name.
648  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
649    return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgs();
650  }
651
652  /// \brief Retrieves the optional explicit template arguments.
653  /// This points to the same data as getExplicitTemplateArgs(), but
654  /// returns null if there are no explicit template arguments.
655  const ExplicitTemplateArgumentList *getExplicitTemplateArgsOpt() const {
656    if (!hasExplicitTemplateArgs()) return 0;
657    return &getExplicitTemplateArgs();
658  }
659
660  /// \brief Copies the template arguments (if present) into the given
661  /// structure.
662  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
663    if (hasExplicitTemplateArgs())
664      getExplicitTemplateArgs().copyInto(List);
665  }
666
667  /// \brief Retrieve the location of the left angle bracket following the
668  /// member name ('<'), if any.
669  SourceLocation getLAngleLoc() const {
670    if (!hasExplicitTemplateArgs())
671      return SourceLocation();
672
673    return getExplicitTemplateArgs().LAngleLoc;
674  }
675
676  /// \brief Retrieve the template arguments provided as part of this
677  /// template-id.
678  const TemplateArgumentLoc *getTemplateArgs() const {
679    if (!hasExplicitTemplateArgs())
680      return 0;
681
682    return getExplicitTemplateArgs().getTemplateArgs();
683  }
684
685  /// \brief Retrieve the number of template arguments provided as part of this
686  /// template-id.
687  unsigned getNumTemplateArgs() const {
688    if (!hasExplicitTemplateArgs())
689      return 0;
690
691    return getExplicitTemplateArgs().NumTemplateArgs;
692  }
693
694  /// \brief Retrieve the location of the right angle bracket following the
695  /// template arguments ('>').
696  SourceLocation getRAngleLoc() const {
697    if (!hasExplicitTemplateArgs())
698      return SourceLocation();
699
700    return getExplicitTemplateArgs().RAngleLoc;
701  }
702
703  static bool classof(const Stmt *T) {
704    return T->getStmtClass() == DeclRefExprClass;
705  }
706  static bool classof(const DeclRefExpr *) { return true; }
707
708  // Iterators
709  virtual child_iterator child_begin();
710  virtual child_iterator child_end();
711
712  friend class ASTStmtReader;
713  friend class ASTStmtWriter;
714};
715
716/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
717class PredefinedExpr : public Expr {
718public:
719  enum IdentType {
720    Func,
721    Function,
722    PrettyFunction,
723    /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
724    /// 'virtual' keyword is omitted for virtual member functions.
725    PrettyFunctionNoVirtual
726  };
727
728private:
729  SourceLocation Loc;
730  IdentType Type;
731public:
732  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
733    : Expr(PredefinedExprClass, type, type->isDependentType(),
734           type->isDependentType()), Loc(l), Type(IT) {}
735
736  /// \brief Construct an empty predefined expression.
737  explicit PredefinedExpr(EmptyShell Empty)
738    : Expr(PredefinedExprClass, Empty) { }
739
740  IdentType getIdentType() const { return Type; }
741  void setIdentType(IdentType IT) { Type = IT; }
742
743  SourceLocation getLocation() const { return Loc; }
744  void setLocation(SourceLocation L) { Loc = L; }
745
746  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
747
748  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
749
750  static bool classof(const Stmt *T) {
751    return T->getStmtClass() == PredefinedExprClass;
752  }
753  static bool classof(const PredefinedExpr *) { return true; }
754
755  // Iterators
756  virtual child_iterator child_begin();
757  virtual child_iterator child_end();
758};
759
760class IntegerLiteral : public Expr {
761  llvm::APInt Value;
762  SourceLocation Loc;
763public:
764  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
765  // or UnsignedLongLongTy
766  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
767    : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) {
768    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
769  }
770
771  /// \brief Construct an empty integer literal.
772  explicit IntegerLiteral(EmptyShell Empty)
773    : Expr(IntegerLiteralClass, Empty) { }
774
775  const llvm::APInt &getValue() const { return Value; }
776  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
777
778  /// \brief Retrieve the location of the literal.
779  SourceLocation getLocation() const { return Loc; }
780
781  void setValue(const llvm::APInt &Val) { Value = Val; }
782  void setLocation(SourceLocation Location) { Loc = Location; }
783
784  static bool classof(const Stmt *T) {
785    return T->getStmtClass() == IntegerLiteralClass;
786  }
787  static bool classof(const IntegerLiteral *) { return true; }
788
789  // Iterators
790  virtual child_iterator child_begin();
791  virtual child_iterator child_end();
792};
793
794class CharacterLiteral : public Expr {
795  unsigned Value;
796  SourceLocation Loc;
797  bool IsWide;
798public:
799  // type should be IntTy
800  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
801    : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l),
802      IsWide(iswide) {
803  }
804
805  /// \brief Construct an empty character literal.
806  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
807
808  SourceLocation getLocation() const { return Loc; }
809  bool isWide() const { return IsWide; }
810
811  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
812
813  unsigned getValue() const { return Value; }
814
815  void setLocation(SourceLocation Location) { Loc = Location; }
816  void setWide(bool W) { IsWide = W; }
817  void setValue(unsigned Val) { Value = Val; }
818
819  static bool classof(const Stmt *T) {
820    return T->getStmtClass() == CharacterLiteralClass;
821  }
822  static bool classof(const CharacterLiteral *) { return true; }
823
824  // Iterators
825  virtual child_iterator child_begin();
826  virtual child_iterator child_end();
827};
828
829class FloatingLiteral : public Expr {
830  llvm::APFloat Value;
831  bool IsExact : 1;
832  SourceLocation Loc;
833public:
834  FloatingLiteral(const llvm::APFloat &V, bool isexact,
835                  QualType Type, SourceLocation L)
836    : Expr(FloatingLiteralClass, Type, false, false), Value(V),
837      IsExact(isexact), Loc(L) {}
838
839  /// \brief Construct an empty floating-point literal.
840  explicit FloatingLiteral(EmptyShell Empty)
841    : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
842
843  const llvm::APFloat &getValue() const { return Value; }
844  void setValue(const llvm::APFloat &Val) { Value = Val; }
845
846  bool isExact() const { return IsExact; }
847  void setExact(bool E) { IsExact = E; }
848
849  /// getValueAsApproximateDouble - This returns the value as an inaccurate
850  /// double.  Note that this may cause loss of precision, but is useful for
851  /// debugging dumps, etc.
852  double getValueAsApproximateDouble() const;
853
854  SourceLocation getLocation() const { return Loc; }
855  void setLocation(SourceLocation L) { Loc = L; }
856
857  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
858
859  static bool classof(const Stmt *T) {
860    return T->getStmtClass() == FloatingLiteralClass;
861  }
862  static bool classof(const FloatingLiteral *) { return true; }
863
864  // Iterators
865  virtual child_iterator child_begin();
866  virtual child_iterator child_end();
867};
868
869/// ImaginaryLiteral - We support imaginary integer and floating point literals,
870/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
871/// IntegerLiteral classes.  Instances of this class always have a Complex type
872/// whose element type matches the subexpression.
873///
874class ImaginaryLiteral : public Expr {
875  Stmt *Val;
876public:
877  ImaginaryLiteral(Expr *val, QualType Ty)
878    : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {}
879
880  /// \brief Build an empty imaginary literal.
881  explicit ImaginaryLiteral(EmptyShell Empty)
882    : Expr(ImaginaryLiteralClass, Empty) { }
883
884  const Expr *getSubExpr() const { return cast<Expr>(Val); }
885  Expr *getSubExpr() { return cast<Expr>(Val); }
886  void setSubExpr(Expr *E) { Val = E; }
887
888  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
889  static bool classof(const Stmt *T) {
890    return T->getStmtClass() == ImaginaryLiteralClass;
891  }
892  static bool classof(const ImaginaryLiteral *) { return true; }
893
894  // Iterators
895  virtual child_iterator child_begin();
896  virtual child_iterator child_end();
897};
898
899/// StringLiteral - This represents a string literal expression, e.g. "foo"
900/// or L"bar" (wide strings).  The actual string is returned by getStrData()
901/// is NOT null-terminated, and the length of the string is determined by
902/// calling getByteLength().  The C type for a string is always a
903/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
904/// not.
905///
906/// Note that strings in C can be formed by concatenation of multiple string
907/// literal pptokens in translation phase #6.  This keeps track of the locations
908/// of each of these pieces.
909///
910/// Strings in C can also be truncated and extended by assigning into arrays,
911/// e.g. with constructs like:
912///   char X[2] = "foobar";
913/// In this case, getByteLength() will return 6, but the string literal will
914/// have type "char[2]".
915class StringLiteral : public Expr {
916  const char *StrData;
917  unsigned ByteLength;
918  bool IsWide;
919  unsigned NumConcatenated;
920  SourceLocation TokLocs[1];
921
922  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {}
923
924public:
925  /// This is the "fully general" constructor that allows representation of
926  /// strings formed from multiple concatenated tokens.
927  static StringLiteral *Create(ASTContext &C, const char *StrData,
928                               unsigned ByteLength, bool Wide, QualType Ty,
929                               const SourceLocation *Loc, unsigned NumStrs);
930
931  /// Simple constructor for string literals made from one token.
932  static StringLiteral *Create(ASTContext &C, const char *StrData,
933                               unsigned ByteLength,
934                               bool Wide, QualType Ty, SourceLocation Loc) {
935    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
936  }
937
938  /// \brief Construct an empty string literal.
939  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
940
941  llvm::StringRef getString() const {
942    return llvm::StringRef(StrData, ByteLength);
943  }
944
945  unsigned getByteLength() const { return ByteLength; }
946
947  /// \brief Sets the string data to the given string data.
948  void setString(ASTContext &C, llvm::StringRef Str);
949
950  bool isWide() const { return IsWide; }
951  void setWide(bool W) { IsWide = W; }
952
953  bool containsNonAsciiOrNull() const {
954    llvm::StringRef Str = getString();
955    for (unsigned i = 0, e = Str.size(); i != e; ++i)
956      if (!isascii(Str[i]) || !Str[i])
957        return true;
958    return false;
959  }
960  /// getNumConcatenated - Get the number of string literal tokens that were
961  /// concatenated in translation phase #6 to form this string literal.
962  unsigned getNumConcatenated() const { return NumConcatenated; }
963
964  SourceLocation getStrTokenLoc(unsigned TokNum) const {
965    assert(TokNum < NumConcatenated && "Invalid tok number");
966    return TokLocs[TokNum];
967  }
968  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
969    assert(TokNum < NumConcatenated && "Invalid tok number");
970    TokLocs[TokNum] = L;
971  }
972
973  typedef const SourceLocation *tokloc_iterator;
974  tokloc_iterator tokloc_begin() const { return TokLocs; }
975  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
976
977  virtual SourceRange getSourceRange() const {
978    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
979  }
980  static bool classof(const Stmt *T) {
981    return T->getStmtClass() == StringLiteralClass;
982  }
983  static bool classof(const StringLiteral *) { return true; }
984
985  // Iterators
986  virtual child_iterator child_begin();
987  virtual child_iterator child_end();
988};
989
990/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
991/// AST node is only formed if full location information is requested.
992class ParenExpr : public Expr {
993  SourceLocation L, R;
994  Stmt *Val;
995public:
996  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
997    : Expr(ParenExprClass, val->getType(),
998           val->isTypeDependent(), val->isValueDependent()),
999      L(l), R(r), Val(val) {}
1000
1001  /// \brief Construct an empty parenthesized expression.
1002  explicit ParenExpr(EmptyShell Empty)
1003    : Expr(ParenExprClass, Empty) { }
1004
1005  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1006  Expr *getSubExpr() { return cast<Expr>(Val); }
1007  void setSubExpr(Expr *E) { Val = E; }
1008
1009  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
1010
1011  /// \brief Get the location of the left parentheses '('.
1012  SourceLocation getLParen() const { return L; }
1013  void setLParen(SourceLocation Loc) { L = Loc; }
1014
1015  /// \brief Get the location of the right parentheses ')'.
1016  SourceLocation getRParen() const { return R; }
1017  void setRParen(SourceLocation Loc) { R = Loc; }
1018
1019  static bool classof(const Stmt *T) {
1020    return T->getStmtClass() == ParenExprClass;
1021  }
1022  static bool classof(const ParenExpr *) { return true; }
1023
1024  // Iterators
1025  virtual child_iterator child_begin();
1026  virtual child_iterator child_end();
1027};
1028
1029
1030/// UnaryOperator - This represents the unary-expression's (except sizeof and
1031/// alignof), the postinc/postdec operators from postfix-expression, and various
1032/// extensions.
1033///
1034/// Notes on various nodes:
1035///
1036/// Real/Imag - These return the real/imag part of a complex operand.  If
1037///   applied to a non-complex value, the former returns its operand and the
1038///   later returns zero in the type of the operand.
1039///
1040class UnaryOperator : public Expr {
1041public:
1042  typedef UnaryOperatorKind Opcode;
1043  static const Opcode PostInc = UO_PostInc;
1044  static const Opcode PostDec = UO_PostDec;
1045  static const Opcode PreInc = UO_PreInc;
1046  static const Opcode PreDec = UO_PreDec;
1047  static const Opcode AddrOf = UO_AddrOf;
1048  static const Opcode Deref = UO_Deref;
1049  static const Opcode Plus = UO_Plus;
1050  static const Opcode Minus = UO_Minus;
1051  static const Opcode Not = UO_Not;
1052  static const Opcode LNot = UO_LNot;
1053  static const Opcode Real = UO_Real;
1054  static const Opcode Imag = UO_Imag;
1055  static const Opcode Extension = UO_Extension;
1056
1057private:
1058  Stmt *Val;
1059  Opcode Opc;
1060  SourceLocation Loc;
1061public:
1062
1063  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
1064    : Expr(UnaryOperatorClass, type,
1065           input->isTypeDependent() || type->isDependentType(),
1066           input->isValueDependent()),
1067      Val(input), Opc(opc), Loc(l) {}
1068
1069  /// \brief Build an empty unary operator.
1070  explicit UnaryOperator(EmptyShell Empty)
1071    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
1072
1073  Opcode getOpcode() const { return Opc; }
1074  void setOpcode(Opcode O) { Opc = O; }
1075
1076  Expr *getSubExpr() const { return cast<Expr>(Val); }
1077  void setSubExpr(Expr *E) { Val = E; }
1078
1079  /// getOperatorLoc - Return the location of the operator.
1080  SourceLocation getOperatorLoc() const { return Loc; }
1081  void setOperatorLoc(SourceLocation L) { Loc = L; }
1082
1083  /// isPostfix - Return true if this is a postfix operation, like x++.
1084  static bool isPostfix(Opcode Op) {
1085    return Op == PostInc || Op == PostDec;
1086  }
1087
1088  /// isPostfix - Return true if this is a prefix operation, like --x.
1089  static bool isPrefix(Opcode Op) {
1090    return Op == PreInc || Op == PreDec;
1091  }
1092
1093  bool isPrefix() const { return isPrefix(Opc); }
1094  bool isPostfix() const { return isPostfix(Opc); }
1095  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
1096  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
1097  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
1098  bool isArithmeticOp() const { return isArithmeticOp(Opc); }
1099
1100  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1101  /// corresponds to, e.g. "sizeof" or "[pre]++"
1102  static const char *getOpcodeStr(Opcode Op);
1103
1104  /// \brief Retrieve the unary opcode that corresponds to the given
1105  /// overloaded operator.
1106  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
1107
1108  /// \brief Retrieve the overloaded operator kind that corresponds to
1109  /// the given unary opcode.
1110  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1111
1112  virtual SourceRange getSourceRange() const {
1113    if (isPostfix())
1114      return SourceRange(Val->getLocStart(), Loc);
1115    else
1116      return SourceRange(Loc, Val->getLocEnd());
1117  }
1118  virtual SourceLocation getExprLoc() const { return Loc; }
1119
1120  static bool classof(const Stmt *T) {
1121    return T->getStmtClass() == UnaryOperatorClass;
1122  }
1123  static bool classof(const UnaryOperator *) { return true; }
1124
1125  // Iterators
1126  virtual child_iterator child_begin();
1127  virtual child_iterator child_end();
1128};
1129
1130/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
1131/// offsetof(record-type, member-designator). For example, given:
1132/// @code
1133/// struct S {
1134///   float f;
1135///   double d;
1136/// };
1137/// struct T {
1138///   int i;
1139///   struct S s[10];
1140/// };
1141/// @endcode
1142/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
1143
1144class OffsetOfExpr : public Expr {
1145public:
1146  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
1147  class OffsetOfNode {
1148  public:
1149    /// \brief The kind of offsetof node we have.
1150    enum Kind {
1151      /// \brief An index into an array.
1152      Array = 0x00,
1153      /// \brief A field.
1154      Field = 0x01,
1155      /// \brief A field in a dependent type, known only by its name.
1156      Identifier = 0x02,
1157      /// \brief An implicit indirection through a C++ base class, when the
1158      /// field found is in a base class.
1159      Base = 0x03
1160    };
1161
1162  private:
1163    enum { MaskBits = 2, Mask = 0x03 };
1164
1165    /// \brief The source range that covers this part of the designator.
1166    SourceRange Range;
1167
1168    /// \brief The data describing the designator, which comes in three
1169    /// different forms, depending on the lower two bits.
1170    ///   - An unsigned index into the array of Expr*'s stored after this node
1171    ///     in memory, for [constant-expression] designators.
1172    ///   - A FieldDecl*, for references to a known field.
1173    ///   - An IdentifierInfo*, for references to a field with a given name
1174    ///     when the class type is dependent.
1175    ///   - A CXXBaseSpecifier*, for references that look at a field in a
1176    ///     base class.
1177    uintptr_t Data;
1178
1179  public:
1180    /// \brief Create an offsetof node that refers to an array element.
1181    OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
1182                 SourceLocation RBracketLoc)
1183      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
1184
1185    /// \brief Create an offsetof node that refers to a field.
1186    OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
1187                 SourceLocation NameLoc)
1188      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
1189        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
1190
1191    /// \brief Create an offsetof node that refers to an identifier.
1192    OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
1193                 SourceLocation NameLoc)
1194      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
1195        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
1196
1197    /// \brief Create an offsetof node that refers into a C++ base class.
1198    explicit OffsetOfNode(const CXXBaseSpecifier *Base)
1199      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
1200
1201    /// \brief Determine what kind of offsetof node this is.
1202    Kind getKind() const {
1203      return static_cast<Kind>(Data & Mask);
1204    }
1205
1206    /// \brief For an array element node, returns the index into the array
1207    /// of expressions.
1208    unsigned getArrayExprIndex() const {
1209      assert(getKind() == Array);
1210      return Data >> 2;
1211    }
1212
1213    /// \brief For a field offsetof node, returns the field.
1214    FieldDecl *getField() const {
1215      assert(getKind() == Field);
1216      return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
1217    }
1218
1219    /// \brief For a field or identifier offsetof node, returns the name of
1220    /// the field.
1221    IdentifierInfo *getFieldName() const;
1222
1223    /// \brief For a base class node, returns the base specifier.
1224    CXXBaseSpecifier *getBase() const {
1225      assert(getKind() == Base);
1226      return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
1227    }
1228
1229    /// \brief Retrieve the source range that covers this offsetof node.
1230    ///
1231    /// For an array element node, the source range contains the locations of
1232    /// the square brackets. For a field or identifier node, the source range
1233    /// contains the location of the period (if there is one) and the
1234    /// identifier.
1235    SourceRange getRange() const { return Range; }
1236  };
1237
1238private:
1239
1240  SourceLocation OperatorLoc, RParenLoc;
1241  // Base type;
1242  TypeSourceInfo *TSInfo;
1243  // Number of sub-components (i.e. instances of OffsetOfNode).
1244  unsigned NumComps;
1245  // Number of sub-expressions (i.e. array subscript expressions).
1246  unsigned NumExprs;
1247
1248  OffsetOfExpr(ASTContext &C, QualType type,
1249               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1250               OffsetOfNode* compsPtr, unsigned numComps,
1251               Expr** exprsPtr, unsigned numExprs,
1252               SourceLocation RParenLoc);
1253
1254  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
1255    : Expr(OffsetOfExprClass, EmptyShell()),
1256      TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
1257
1258public:
1259
1260  static OffsetOfExpr *Create(ASTContext &C, QualType type,
1261                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1262                              OffsetOfNode* compsPtr, unsigned numComps,
1263                              Expr** exprsPtr, unsigned numExprs,
1264                              SourceLocation RParenLoc);
1265
1266  static OffsetOfExpr *CreateEmpty(ASTContext &C,
1267                                   unsigned NumComps, unsigned NumExprs);
1268
1269  /// getOperatorLoc - Return the location of the operator.
1270  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1271  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1272
1273  /// \brief Return the location of the right parentheses.
1274  SourceLocation getRParenLoc() const { return RParenLoc; }
1275  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
1276
1277  TypeSourceInfo *getTypeSourceInfo() const {
1278    return TSInfo;
1279  }
1280  void setTypeSourceInfo(TypeSourceInfo *tsi) {
1281    TSInfo = tsi;
1282  }
1283
1284  const OffsetOfNode &getComponent(unsigned Idx) {
1285    assert(Idx < NumComps && "Subscript out of range");
1286    return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx];
1287  }
1288
1289  void setComponent(unsigned Idx, OffsetOfNode ON) {
1290    assert(Idx < NumComps && "Subscript out of range");
1291    reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
1292  }
1293
1294  unsigned getNumComponents() const {
1295    return NumComps;
1296  }
1297
1298  Expr* getIndexExpr(unsigned Idx) {
1299    assert(Idx < NumExprs && "Subscript out of range");
1300    return reinterpret_cast<Expr **>(
1301                    reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
1302  }
1303
1304  void setIndexExpr(unsigned Idx, Expr* E) {
1305    assert(Idx < NumComps && "Subscript out of range");
1306    reinterpret_cast<Expr **>(
1307                reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
1308  }
1309
1310  unsigned getNumExpressions() const {
1311    return NumExprs;
1312  }
1313
1314  virtual SourceRange getSourceRange() const {
1315    return SourceRange(OperatorLoc, RParenLoc);
1316  }
1317
1318  static bool classof(const Stmt *T) {
1319    return T->getStmtClass() == OffsetOfExprClass;
1320  }
1321
1322  static bool classof(const OffsetOfExpr *) { return true; }
1323
1324  // Iterators
1325  virtual child_iterator child_begin();
1326  virtual child_iterator child_end();
1327};
1328
1329/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
1330/// types and expressions.
1331class SizeOfAlignOfExpr : public Expr {
1332  bool isSizeof : 1;  // true if sizeof, false if alignof.
1333  bool isType : 1;    // true if operand is a type, false if an expression
1334  union {
1335    TypeSourceInfo *Ty;
1336    Stmt *Ex;
1337  } Argument;
1338  SourceLocation OpLoc, RParenLoc;
1339
1340public:
1341  SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo,
1342                    QualType resultType, SourceLocation op,
1343                    SourceLocation rp) :
1344      Expr(SizeOfAlignOfExprClass, resultType,
1345           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1346           // Value-dependent if the argument is type-dependent.
1347           TInfo->getType()->isDependentType()),
1348      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
1349    Argument.Ty = TInfo;
1350  }
1351
1352  SizeOfAlignOfExpr(bool issizeof, Expr *E,
1353                    QualType resultType, SourceLocation op,
1354                    SourceLocation rp) :
1355      Expr(SizeOfAlignOfExprClass, resultType,
1356           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1357           // Value-dependent if the argument is type-dependent.
1358           E->isTypeDependent()),
1359      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
1360    Argument.Ex = E;
1361  }
1362
1363  /// \brief Construct an empty sizeof/alignof expression.
1364  explicit SizeOfAlignOfExpr(EmptyShell Empty)
1365    : Expr(SizeOfAlignOfExprClass, Empty) { }
1366
1367  bool isSizeOf() const { return isSizeof; }
1368  void setSizeof(bool S) { isSizeof = S; }
1369
1370  bool isArgumentType() const { return isType; }
1371  QualType getArgumentType() const {
1372    return getArgumentTypeInfo()->getType();
1373  }
1374  TypeSourceInfo *getArgumentTypeInfo() const {
1375    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
1376    return Argument.Ty;
1377  }
1378  Expr *getArgumentExpr() {
1379    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
1380    return static_cast<Expr*>(Argument.Ex);
1381  }
1382  const Expr *getArgumentExpr() const {
1383    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
1384  }
1385
1386  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
1387  void setArgument(TypeSourceInfo *TInfo) {
1388    Argument.Ty = TInfo;
1389    isType = true;
1390  }
1391
1392  /// Gets the argument type, or the type of the argument expression, whichever
1393  /// is appropriate.
1394  QualType getTypeOfArgument() const {
1395    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
1396  }
1397
1398  SourceLocation getOperatorLoc() const { return OpLoc; }
1399  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1400
1401  SourceLocation getRParenLoc() const { return RParenLoc; }
1402  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1403
1404  virtual SourceRange getSourceRange() const {
1405    return SourceRange(OpLoc, RParenLoc);
1406  }
1407
1408  static bool classof(const Stmt *T) {
1409    return T->getStmtClass() == SizeOfAlignOfExprClass;
1410  }
1411  static bool classof(const SizeOfAlignOfExpr *) { return true; }
1412
1413  // Iterators
1414  virtual child_iterator child_begin();
1415  virtual child_iterator child_end();
1416};
1417
1418//===----------------------------------------------------------------------===//
1419// Postfix Operators.
1420//===----------------------------------------------------------------------===//
1421
1422/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
1423class ArraySubscriptExpr : public Expr {
1424  enum { LHS, RHS, END_EXPR=2 };
1425  Stmt* SubExprs[END_EXPR];
1426  SourceLocation RBracketLoc;
1427public:
1428  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
1429                     SourceLocation rbracketloc)
1430  : Expr(ArraySubscriptExprClass, t,
1431         lhs->isTypeDependent() || rhs->isTypeDependent(),
1432         lhs->isValueDependent() || rhs->isValueDependent()),
1433    RBracketLoc(rbracketloc) {
1434    SubExprs[LHS] = lhs;
1435    SubExprs[RHS] = rhs;
1436  }
1437
1438  /// \brief Create an empty array subscript expression.
1439  explicit ArraySubscriptExpr(EmptyShell Shell)
1440    : Expr(ArraySubscriptExprClass, Shell) { }
1441
1442  /// An array access can be written A[4] or 4[A] (both are equivalent).
1443  /// - getBase() and getIdx() always present the normalized view: A[4].
1444  ///    In this case getBase() returns "A" and getIdx() returns "4".
1445  /// - getLHS() and getRHS() present the syntactic view. e.g. for
1446  ///    4[A] getLHS() returns "4".
1447  /// Note: Because vector element access is also written A[4] we must
1448  /// predicate the format conversion in getBase and getIdx only on the
1449  /// the type of the RHS, as it is possible for the LHS to be a vector of
1450  /// integer type
1451  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
1452  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1453  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1454
1455  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
1456  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1457  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1458
1459  Expr *getBase() {
1460    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1461  }
1462
1463  const Expr *getBase() const {
1464    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1465  }
1466
1467  Expr *getIdx() {
1468    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
1469  }
1470
1471  const Expr *getIdx() const {
1472    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
1473  }
1474
1475  virtual SourceRange getSourceRange() const {
1476    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
1477  }
1478
1479  SourceLocation getRBracketLoc() const { return RBracketLoc; }
1480  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
1481
1482  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
1483
1484  static bool classof(const Stmt *T) {
1485    return T->getStmtClass() == ArraySubscriptExprClass;
1486  }
1487  static bool classof(const ArraySubscriptExpr *) { return true; }
1488
1489  // Iterators
1490  virtual child_iterator child_begin();
1491  virtual child_iterator child_end();
1492};
1493
1494
1495/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
1496/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
1497/// while its subclasses may represent alternative syntax that (semantically)
1498/// results in a function call. For example, CXXOperatorCallExpr is
1499/// a subclass for overloaded operator calls that use operator syntax, e.g.,
1500/// "str1 + str2" to resolve to a function call.
1501class CallExpr : public Expr {
1502  enum { FN=0, ARGS_START=1 };
1503  Stmt **SubExprs;
1504  unsigned NumArgs;
1505  SourceLocation RParenLoc;
1506
1507protected:
1508  // This version of the constructor is for derived classes.
1509  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
1510           QualType t, SourceLocation rparenloc);
1511
1512public:
1513  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
1514           SourceLocation rparenloc);
1515
1516  /// \brief Build an empty call expression.
1517  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
1518
1519  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
1520  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
1521  void setCallee(Expr *F) { SubExprs[FN] = F; }
1522
1523  Decl *getCalleeDecl();
1524  const Decl *getCalleeDecl() const {
1525    return const_cast<CallExpr*>(this)->getCalleeDecl();
1526  }
1527
1528  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
1529  FunctionDecl *getDirectCallee();
1530  const FunctionDecl *getDirectCallee() const {
1531    return const_cast<CallExpr*>(this)->getDirectCallee();
1532  }
1533
1534  /// getNumArgs - Return the number of actual arguments to this call.
1535  ///
1536  unsigned getNumArgs() const { return NumArgs; }
1537
1538  /// getArg - Return the specified argument.
1539  Expr *getArg(unsigned Arg) {
1540    assert(Arg < NumArgs && "Arg access out of range!");
1541    return cast<Expr>(SubExprs[Arg+ARGS_START]);
1542  }
1543  const Expr *getArg(unsigned Arg) const {
1544    assert(Arg < NumArgs && "Arg access out of range!");
1545    return cast<Expr>(SubExprs[Arg+ARGS_START]);
1546  }
1547
1548  /// setArg - Set the specified argument.
1549  void setArg(unsigned Arg, Expr *ArgExpr) {
1550    assert(Arg < NumArgs && "Arg access out of range!");
1551    SubExprs[Arg+ARGS_START] = ArgExpr;
1552  }
1553
1554  /// setNumArgs - This changes the number of arguments present in this call.
1555  /// Any orphaned expressions are deleted by this, and any new operands are set
1556  /// to null.
1557  void setNumArgs(ASTContext& C, unsigned NumArgs);
1558
1559  typedef ExprIterator arg_iterator;
1560  typedef ConstExprIterator const_arg_iterator;
1561
1562  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
1563  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
1564  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
1565  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
1566
1567  /// getNumCommas - Return the number of commas that must have been present in
1568  /// this function call.
1569  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
1570
1571  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
1572  /// not, return 0.
1573  unsigned isBuiltinCall(ASTContext &Context) const;
1574
1575  /// getCallReturnType - Get the return type of the call expr. This is not
1576  /// always the type of the expr itself, if the return type is a reference
1577  /// type.
1578  QualType getCallReturnType() const;
1579
1580  SourceLocation getRParenLoc() const { return RParenLoc; }
1581  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1582
1583  virtual SourceRange getSourceRange() const {
1584    return SourceRange(getCallee()->getLocStart(), RParenLoc);
1585  }
1586
1587  static bool classof(const Stmt *T) {
1588    return T->getStmtClass() >= firstCallExprConstant &&
1589           T->getStmtClass() <= lastCallExprConstant;
1590  }
1591  static bool classof(const CallExpr *) { return true; }
1592
1593  // Iterators
1594  virtual child_iterator child_begin();
1595  virtual child_iterator child_end();
1596};
1597
1598/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
1599///
1600class MemberExpr : public Expr {
1601  /// Extra data stored in some member expressions.
1602  struct MemberNameQualifier : public NameQualifier {
1603    DeclAccessPair FoundDecl;
1604  };
1605
1606  /// Base - the expression for the base pointer or structure references.  In
1607  /// X.F, this is "X".
1608  Stmt *Base;
1609
1610  /// MemberDecl - This is the decl being referenced by the field/member name.
1611  /// In X.F, this is the decl referenced by F.
1612  ValueDecl *MemberDecl;
1613
1614  /// MemberLoc - This is the location of the member name.
1615  SourceLocation MemberLoc;
1616
1617  /// MemberDNLoc - Provides source/type location info for the
1618  /// declaration name embedded in MemberDecl.
1619  DeclarationNameLoc MemberDNLoc;
1620
1621  /// IsArrow - True if this is "X->F", false if this is "X.F".
1622  bool IsArrow : 1;
1623
1624  /// \brief True if this member expression used a nested-name-specifier to
1625  /// refer to the member, e.g., "x->Base::f", or found its member via a using
1626  /// declaration.  When true, a MemberNameQualifier
1627  /// structure is allocated immediately after the MemberExpr.
1628  bool HasQualifierOrFoundDecl : 1;
1629
1630  /// \brief True if this member expression specified a template argument list
1631  /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList
1632  /// structure (and its TemplateArguments) are allocated immediately after
1633  /// the MemberExpr or, if the member expression also has a qualifier, after
1634  /// the MemberNameQualifier structure.
1635  bool HasExplicitTemplateArgumentList : 1;
1636
1637  /// \brief Retrieve the qualifier that preceded the member name, if any.
1638  MemberNameQualifier *getMemberQualifier() {
1639    assert(HasQualifierOrFoundDecl);
1640    return reinterpret_cast<MemberNameQualifier *> (this + 1);
1641  }
1642
1643  /// \brief Retrieve the qualifier that preceded the member name, if any.
1644  const MemberNameQualifier *getMemberQualifier() const {
1645    return const_cast<MemberExpr *>(this)->getMemberQualifier();
1646  }
1647
1648public:
1649  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
1650             const DeclarationNameInfo &NameInfo, QualType ty)
1651    : Expr(MemberExprClass, ty,
1652           base->isTypeDependent(), base->isValueDependent()),
1653      Base(base), MemberDecl(memberdecl), MemberLoc(NameInfo.getLoc()),
1654      MemberDNLoc(NameInfo.getInfo()), IsArrow(isarrow),
1655      HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {
1656    assert(memberdecl->getDeclName() == NameInfo.getName());
1657  }
1658
1659  // NOTE: this constructor should be used only when it is known that
1660  // the member name can not provide additional syntactic info
1661  // (i.e., source locations for C++ operator names or type source info
1662  // for constructors, destructors and conversion oeprators).
1663  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
1664             SourceLocation l, QualType ty)
1665    : Expr(MemberExprClass, ty,
1666           base->isTypeDependent(), base->isValueDependent()),
1667      Base(base), MemberDecl(memberdecl), MemberLoc(l), MemberDNLoc(),
1668      IsArrow(isarrow),
1669      HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {}
1670
1671  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
1672                            NestedNameSpecifier *qual, SourceRange qualrange,
1673                            ValueDecl *memberdecl, DeclAccessPair founddecl,
1674                            DeclarationNameInfo MemberNameInfo,
1675                            const TemplateArgumentListInfo *targs,
1676                            QualType ty);
1677
1678  void setBase(Expr *E) { Base = E; }
1679  Expr *getBase() const { return cast<Expr>(Base); }
1680
1681  /// \brief Retrieve the member declaration to which this expression refers.
1682  ///
1683  /// The returned declaration will either be a FieldDecl or (in C++)
1684  /// a CXXMethodDecl.
1685  ValueDecl *getMemberDecl() const { return MemberDecl; }
1686  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
1687
1688  /// \brief Retrieves the declaration found by lookup.
1689  DeclAccessPair getFoundDecl() const {
1690    if (!HasQualifierOrFoundDecl)
1691      return DeclAccessPair::make(getMemberDecl(),
1692                                  getMemberDecl()->getAccess());
1693    return getMemberQualifier()->FoundDecl;
1694  }
1695
1696  /// \brief Determines whether this member expression actually had
1697  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1698  /// x->Base::foo.
1699  bool hasQualifier() const { return getQualifier() != 0; }
1700
1701  /// \brief If the member name was qualified, retrieves the source range of
1702  /// the nested-name-specifier that precedes the member name. Otherwise,
1703  /// returns an empty source range.
1704  SourceRange getQualifierRange() const {
1705    if (!HasQualifierOrFoundDecl)
1706      return SourceRange();
1707
1708    return getMemberQualifier()->Range;
1709  }
1710
1711  /// \brief If the member name was qualified, retrieves the
1712  /// nested-name-specifier that precedes the member name. Otherwise, returns
1713  /// NULL.
1714  NestedNameSpecifier *getQualifier() const {
1715    if (!HasQualifierOrFoundDecl)
1716      return 0;
1717
1718    return getMemberQualifier()->NNS;
1719  }
1720
1721  /// \brief Determines whether this member expression actually had a C++
1722  /// template argument list explicitly specified, e.g., x.f<int>.
1723  bool hasExplicitTemplateArgs() const {
1724    return HasExplicitTemplateArgumentList;
1725  }
1726
1727  /// \brief Copies the template arguments (if present) into the given
1728  /// structure.
1729  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1730    if (hasExplicitTemplateArgs())
1731      getExplicitTemplateArgs().copyInto(List);
1732  }
1733
1734  /// \brief Retrieve the explicit template argument list that
1735  /// follow the member template name.  This must only be called on an
1736  /// expression with explicit template arguments.
1737  ExplicitTemplateArgumentList &getExplicitTemplateArgs() {
1738    assert(HasExplicitTemplateArgumentList);
1739    if (!HasQualifierOrFoundDecl)
1740      return *reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
1741
1742    return *reinterpret_cast<ExplicitTemplateArgumentList *>(
1743                                                      getMemberQualifier() + 1);
1744  }
1745
1746  /// \brief Retrieve the explicit template argument list that
1747  /// followed the member template name.  This must only be called on
1748  /// an expression with explicit template arguments.
1749  const ExplicitTemplateArgumentList &getExplicitTemplateArgs() const {
1750    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgs();
1751  }
1752
1753  /// \brief Retrieves the optional explicit template arguments.
1754  /// This points to the same data as getExplicitTemplateArgs(), but
1755  /// returns null if there are no explicit template arguments.
1756  const ExplicitTemplateArgumentList *getOptionalExplicitTemplateArgs() const {
1757    if (!hasExplicitTemplateArgs()) return 0;
1758    return &getExplicitTemplateArgs();
1759  }
1760
1761  /// \brief Retrieve the location of the left angle bracket following the
1762  /// member name ('<'), if any.
1763  SourceLocation getLAngleLoc() const {
1764    if (!HasExplicitTemplateArgumentList)
1765      return SourceLocation();
1766
1767    return getExplicitTemplateArgs().LAngleLoc;
1768  }
1769
1770  /// \brief Retrieve the template arguments provided as part of this
1771  /// template-id.
1772  const TemplateArgumentLoc *getTemplateArgs() const {
1773    if (!HasExplicitTemplateArgumentList)
1774      return 0;
1775
1776    return getExplicitTemplateArgs().getTemplateArgs();
1777  }
1778
1779  /// \brief Retrieve the number of template arguments provided as part of this
1780  /// template-id.
1781  unsigned getNumTemplateArgs() const {
1782    if (!HasExplicitTemplateArgumentList)
1783      return 0;
1784
1785    return getExplicitTemplateArgs().NumTemplateArgs;
1786  }
1787
1788  /// \brief Retrieve the location of the right angle bracket following the
1789  /// template arguments ('>').
1790  SourceLocation getRAngleLoc() const {
1791    if (!HasExplicitTemplateArgumentList)
1792      return SourceLocation();
1793
1794    return getExplicitTemplateArgs().RAngleLoc;
1795  }
1796
1797  /// \brief Retrieve the member declaration name info.
1798  DeclarationNameInfo getMemberNameInfo() const {
1799    return DeclarationNameInfo(MemberDecl->getDeclName(),
1800                               MemberLoc, MemberDNLoc);
1801  }
1802
1803  bool isArrow() const { return IsArrow; }
1804  void setArrow(bool A) { IsArrow = A; }
1805
1806  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1807  /// location of 'F'.
1808  SourceLocation getMemberLoc() const { return MemberLoc; }
1809  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
1810
1811  virtual SourceRange getSourceRange() const {
1812    // If we have an implicit base (like a C++ implicit this),
1813    // make sure not to return its location
1814    SourceLocation EndLoc = (HasExplicitTemplateArgumentList)
1815      ? getRAngleLoc() : getMemberNameInfo().getEndLoc();
1816
1817    SourceLocation BaseLoc = getBase()->getLocStart();
1818    if (BaseLoc.isInvalid())
1819      return SourceRange(MemberLoc, EndLoc);
1820    return SourceRange(BaseLoc, EndLoc);
1821  }
1822
1823  virtual SourceLocation getExprLoc() const { return MemberLoc; }
1824
1825  static bool classof(const Stmt *T) {
1826    return T->getStmtClass() == MemberExprClass;
1827  }
1828  static bool classof(const MemberExpr *) { return true; }
1829
1830  // Iterators
1831  virtual child_iterator child_begin();
1832  virtual child_iterator child_end();
1833};
1834
1835/// CompoundLiteralExpr - [C99 6.5.2.5]
1836///
1837class CompoundLiteralExpr : public Expr {
1838  /// LParenLoc - If non-null, this is the location of the left paren in a
1839  /// compound literal like "(int){4}".  This can be null if this is a
1840  /// synthesized compound expression.
1841  SourceLocation LParenLoc;
1842
1843  /// The type as written.  This can be an incomplete array type, in
1844  /// which case the actual expression type will be different.
1845  TypeSourceInfo *TInfo;
1846  Stmt *Init;
1847  bool FileScope;
1848public:
1849  // FIXME: Can compound literals be value-dependent?
1850  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
1851                      QualType T, Expr *init, bool fileScope)
1852    : Expr(CompoundLiteralExprClass, T,
1853           tinfo->getType()->isDependentType(), false),
1854      LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {}
1855
1856  /// \brief Construct an empty compound literal.
1857  explicit CompoundLiteralExpr(EmptyShell Empty)
1858    : Expr(CompoundLiteralExprClass, Empty) { }
1859
1860  const Expr *getInitializer() const { return cast<Expr>(Init); }
1861  Expr *getInitializer() { return cast<Expr>(Init); }
1862  void setInitializer(Expr *E) { Init = E; }
1863
1864  bool isFileScope() const { return FileScope; }
1865  void setFileScope(bool FS) { FileScope = FS; }
1866
1867  SourceLocation getLParenLoc() const { return LParenLoc; }
1868  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1869
1870  TypeSourceInfo *getTypeSourceInfo() const { return TInfo; }
1871  void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; }
1872
1873  virtual SourceRange getSourceRange() const {
1874    // FIXME: Init should never be null.
1875    if (!Init)
1876      return SourceRange();
1877    if (LParenLoc.isInvalid())
1878      return Init->getSourceRange();
1879    return SourceRange(LParenLoc, Init->getLocEnd());
1880  }
1881
1882  static bool classof(const Stmt *T) {
1883    return T->getStmtClass() == CompoundLiteralExprClass;
1884  }
1885  static bool classof(const CompoundLiteralExpr *) { return true; }
1886
1887  // Iterators
1888  virtual child_iterator child_begin();
1889  virtual child_iterator child_end();
1890};
1891
1892/// CastExpr - Base class for type casts, including both implicit
1893/// casts (ImplicitCastExpr) and explicit casts that have some
1894/// representation in the source code (ExplicitCastExpr's derived
1895/// classes).
1896class CastExpr : public Expr {
1897public:
1898  typedef clang::CastKind CastKind;
1899
1900  /// CK_Unknown - Unknown cast kind.
1901  /// FIXME: The goal is to get rid of this and make all casts have a
1902  /// kind so that the AST client doesn't have to try to figure out what's
1903  /// going on.
1904  static const CastKind CK_Unknown = clang::CK_Unknown;
1905
1906  /// CK_BitCast - Used for reinterpret_cast.
1907  static const CastKind CK_BitCast = clang::CK_BitCast;
1908
1909  /// CK_LValueBitCast - Used for reinterpret_cast of expressions to
1910  /// a reference type.
1911  static const CastKind CK_LValueBitCast = clang::CK_LValueBitCast;
1912
1913  /// CK_NoOp - Used for const_cast.
1914  static const CastKind CK_NoOp = clang::CK_NoOp;
1915
1916  /// CK_BaseToDerived - Base to derived class casts.
1917  static const CastKind CK_BaseToDerived = clang::CK_BaseToDerived;
1918
1919  /// CK_DerivedToBase - Derived to base class casts.
1920  static const CastKind CK_DerivedToBase = clang::CK_DerivedToBase;
1921
1922  /// CK_UncheckedDerivedToBase - Derived to base class casts that
1923  /// assume that the derived pointer is not null.
1924  static const CastKind CK_UncheckedDerivedToBase
1925    = clang::CK_UncheckedDerivedToBase;
1926
1927  /// CK_Dynamic - Dynamic cast.
1928  static const CastKind CK_Dynamic = clang::CK_Dynamic;
1929
1930  /// CK_ToUnion - Cast to union (GCC extension).
1931  static const CastKind CK_ToUnion = clang::CK_ToUnion;
1932
1933  /// CK_ArrayToPointerDecay - Array to pointer decay.
1934  static const CastKind CK_ArrayToPointerDecay
1935    = clang::CK_ArrayToPointerDecay;
1936
1937  // CK_FunctionToPointerDecay - Function to pointer decay.
1938  static const CastKind CK_FunctionToPointerDecay
1939    = clang::CK_FunctionToPointerDecay;
1940
1941  /// CK_NullToMemberPointer - Null pointer to member pointer.
1942  static const CastKind CK_NullToMemberPointer
1943    = clang::CK_NullToMemberPointer;
1944
1945  /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
1946  /// member pointer in derived class.
1947  static const CastKind CK_BaseToDerivedMemberPointer
1948    = clang::CK_BaseToDerivedMemberPointer;
1949
1950  /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
1951  /// member pointer in base class.
1952  static const CastKind CK_DerivedToBaseMemberPointer
1953    = clang::CK_DerivedToBaseMemberPointer;
1954
1955  /// CK_UserDefinedConversion - Conversion using a user defined type
1956  /// conversion function.
1957  static const CastKind CK_UserDefinedConversion
1958    = clang::CK_UserDefinedConversion;
1959
1960  /// CK_ConstructorConversion - Conversion by constructor
1961  static const CastKind CK_ConstructorConversion
1962    = clang::CK_ConstructorConversion;
1963
1964  /// CK_IntegralToPointer - Integral to pointer
1965  static const CastKind CK_IntegralToPointer = clang::CK_IntegralToPointer;
1966
1967  /// CK_PointerToIntegral - Pointer to integral
1968  static const CastKind CK_PointerToIntegral = clang::CK_PointerToIntegral;
1969
1970  /// CK_ToVoid - Cast to void.
1971  static const CastKind CK_ToVoid = clang::CK_ToVoid;
1972
1973  /// CK_VectorSplat - Casting from an integer/floating type to an extended
1974  /// vector type with the same element type as the src type. Splats the
1975  /// src expression into the destination expression.
1976  static const CastKind CK_VectorSplat = clang::CK_VectorSplat;
1977
1978  /// CK_IntegralCast - Casting between integral types of different size.
1979  static const CastKind CK_IntegralCast = clang::CK_IntegralCast;
1980
1981  /// CK_IntegralToFloating - Integral to floating point.
1982  static const CastKind CK_IntegralToFloating = clang::CK_IntegralToFloating;
1983
1984  /// CK_FloatingToIntegral - Floating point to integral.
1985  static const CastKind CK_FloatingToIntegral = clang::CK_FloatingToIntegral;
1986
1987  /// CK_FloatingCast - Casting between floating types of different size.
1988  static const CastKind CK_FloatingCast = clang::CK_FloatingCast;
1989
1990  /// CK_MemberPointerToBoolean - Member pointer to boolean
1991  static const CastKind CK_MemberPointerToBoolean
1992    = clang::CK_MemberPointerToBoolean;
1993
1994  /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c
1995  /// pointer
1996  static const CastKind CK_AnyPointerToObjCPointerCast
1997    = clang::CK_AnyPointerToObjCPointerCast;
1998
1999  /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block
2000  /// pointer
2001  static const CastKind CK_AnyPointerToBlockPointerCast
2002    = clang::CK_AnyPointerToBlockPointerCast;
2003
2004  /// \brief Converting between two Objective-C object types, which
2005  /// can occur when performing reference binding to an Objective-C
2006  /// object.
2007  static const CastKind CK_ObjCObjectLValueCast
2008    = clang::CK_ObjCObjectLValueCast;
2009
2010private:
2011  unsigned Kind : 5;
2012  unsigned BasePathSize : BitsRemaining - 5;
2013  Stmt *Op;
2014
2015  void CheckBasePath() const {
2016#ifndef NDEBUG
2017    switch (getCastKind()) {
2018    case CK_DerivedToBase:
2019    case CK_UncheckedDerivedToBase:
2020    case CK_DerivedToBaseMemberPointer:
2021    case CK_BaseToDerived:
2022    case CK_BaseToDerivedMemberPointer:
2023      assert(!path_empty() && "Cast kind should have a base path!");
2024      break;
2025
2026    // These should not have an inheritance path.
2027    case CK_Unknown:
2028    case CK_BitCast:
2029    case CK_LValueBitCast:
2030    case CK_NoOp:
2031    case CK_Dynamic:
2032    case CK_ToUnion:
2033    case CK_ArrayToPointerDecay:
2034    case CK_FunctionToPointerDecay:
2035    case CK_NullToMemberPointer:
2036    case CK_UserDefinedConversion:
2037    case CK_ConstructorConversion:
2038    case CK_IntegralToPointer:
2039    case CK_PointerToIntegral:
2040    case CK_ToVoid:
2041    case CK_VectorSplat:
2042    case CK_IntegralCast:
2043    case CK_IntegralToFloating:
2044    case CK_FloatingToIntegral:
2045    case CK_FloatingCast:
2046    case CK_MemberPointerToBoolean:
2047    case CK_AnyPointerToObjCPointerCast:
2048    case CK_AnyPointerToBlockPointerCast:
2049    case CK_ObjCObjectLValueCast:
2050      assert(path_empty() && "Cast kind should not have a base path!");
2051      break;
2052    }
2053#endif
2054  }
2055
2056  const CXXBaseSpecifier * const *path_buffer() const {
2057    return const_cast<CastExpr*>(this)->path_buffer();
2058  }
2059  CXXBaseSpecifier **path_buffer();
2060
2061protected:
2062  CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op,
2063           unsigned BasePathSize) :
2064    Expr(SC, ty,
2065         // Cast expressions are type-dependent if the type is
2066         // dependent (C++ [temp.dep.expr]p3).
2067         ty->isDependentType(),
2068         // Cast expressions are value-dependent if the type is
2069         // dependent or if the subexpression is value-dependent.
2070         ty->isDependentType() || (op && op->isValueDependent())),
2071    Kind(kind), BasePathSize(BasePathSize), Op(op) {
2072    CheckBasePath();
2073  }
2074
2075  /// \brief Construct an empty cast.
2076  CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
2077    : Expr(SC, Empty), BasePathSize(BasePathSize) { }
2078
2079public:
2080  CastKind getCastKind() const { return static_cast<CastKind>(Kind); }
2081  void setCastKind(CastKind K) { Kind = K; }
2082  const char *getCastKindName() const;
2083
2084  Expr *getSubExpr() { return cast<Expr>(Op); }
2085  const Expr *getSubExpr() const { return cast<Expr>(Op); }
2086  void setSubExpr(Expr *E) { Op = E; }
2087
2088  /// \brief Retrieve the cast subexpression as it was written in the source
2089  /// code, looking through any implicit casts or other intermediate nodes
2090  /// introduced by semantic analysis.
2091  Expr *getSubExprAsWritten();
2092  const Expr *getSubExprAsWritten() const {
2093    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
2094  }
2095
2096  typedef CXXBaseSpecifier **path_iterator;
2097  typedef const CXXBaseSpecifier * const *path_const_iterator;
2098  bool path_empty() const { return BasePathSize == 0; }
2099  unsigned path_size() const { return BasePathSize; }
2100  path_iterator path_begin() { return path_buffer(); }
2101  path_iterator path_end() { return path_buffer() + path_size(); }
2102  path_const_iterator path_begin() const { return path_buffer(); }
2103  path_const_iterator path_end() const { return path_buffer() + path_size(); }
2104
2105  void setCastPath(const CXXCastPath &Path);
2106
2107  static bool classof(const Stmt *T) {
2108    return T->getStmtClass() >= firstCastExprConstant &&
2109           T->getStmtClass() <= lastCastExprConstant;
2110  }
2111  static bool classof(const CastExpr *) { return true; }
2112
2113  // Iterators
2114  virtual child_iterator child_begin();
2115  virtual child_iterator child_end();
2116};
2117
2118/// ImplicitCastExpr - Allows us to explicitly represent implicit type
2119/// conversions, which have no direct representation in the original
2120/// source code. For example: converting T[]->T*, void f()->void
2121/// (*f)(), float->double, short->int, etc.
2122///
2123/// In C, implicit casts always produce rvalues. However, in C++, an
2124/// implicit cast whose result is being bound to a reference will be
2125/// an lvalue or xvalue. For example:
2126///
2127/// @code
2128/// class Base { };
2129/// class Derived : public Base { };
2130/// Derived &&ref();
2131/// void f(Derived d) {
2132///   Base& b = d; // initializer is an ImplicitCastExpr
2133///                // to an lvalue of type Base
2134///   Base&& r = ref(); // initializer is an ImplicitCastExpr
2135///                     // to an xvalue of type Base
2136/// }
2137/// @endcode
2138class ImplicitCastExpr : public CastExpr {
2139private:
2140  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
2141                   unsigned BasePathLength, ExprValueKind VK)
2142    : CastExpr(ImplicitCastExprClass, ty, kind, op, BasePathLength) {
2143    ValueKind = VK;
2144  }
2145
2146  /// \brief Construct an empty implicit cast.
2147  explicit ImplicitCastExpr(EmptyShell Shell, unsigned PathSize)
2148    : CastExpr(ImplicitCastExprClass, Shell, PathSize) { }
2149
2150public:
2151  enum OnStack_t { OnStack };
2152  ImplicitCastExpr(OnStack_t _, QualType ty, CastKind kind, Expr *op,
2153                   ExprValueKind VK)
2154    : CastExpr(ImplicitCastExprClass, ty, kind, op, 0) {
2155    ValueKind = VK;
2156  }
2157
2158  static ImplicitCastExpr *Create(ASTContext &Context, QualType T,
2159                                  CastKind Kind, Expr *Operand,
2160                                  const CXXCastPath *BasePath,
2161                                  ExprValueKind Cat);
2162
2163  static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2164
2165  virtual SourceRange getSourceRange() const {
2166    return getSubExpr()->getSourceRange();
2167  }
2168
2169  /// getValueKind - The value kind that this cast produces.
2170  ExprValueKind getValueKind() const {
2171    return static_cast<ExprValueKind>(ValueKind);
2172  }
2173
2174  /// setValueKind - Set the value kind this cast produces.
2175  void setValueKind(ExprValueKind Cat) { ValueKind = Cat; }
2176
2177  static bool classof(const Stmt *T) {
2178    return T->getStmtClass() == ImplicitCastExprClass;
2179  }
2180  static bool classof(const ImplicitCastExpr *) { return true; }
2181};
2182
2183/// ExplicitCastExpr - An explicit cast written in the source
2184/// code.
2185///
2186/// This class is effectively an abstract class, because it provides
2187/// the basic representation of an explicitly-written cast without
2188/// specifying which kind of cast (C cast, functional cast, static
2189/// cast, etc.) was written; specific derived classes represent the
2190/// particular style of cast and its location information.
2191///
2192/// Unlike implicit casts, explicit cast nodes have two different
2193/// types: the type that was written into the source code, and the
2194/// actual type of the expression as determined by semantic
2195/// analysis. These types may differ slightly. For example, in C++ one
2196/// can cast to a reference type, which indicates that the resulting
2197/// expression will be an lvalue or xvalue. The reference type, however,
2198/// will not be used as the type of the expression.
2199class ExplicitCastExpr : public CastExpr {
2200  /// TInfo - Source type info for the (written) type
2201  /// this expression is casting to.
2202  TypeSourceInfo *TInfo;
2203
2204protected:
2205  ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind,
2206                   Expr *op, unsigned PathSize, TypeSourceInfo *writtenTy)
2207    : CastExpr(SC, exprTy, kind, op, PathSize), TInfo(writtenTy) {}
2208
2209  /// \brief Construct an empty explicit cast.
2210  ExplicitCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize)
2211    : CastExpr(SC, Shell, PathSize) { }
2212
2213public:
2214  /// getTypeInfoAsWritten - Returns the type source info for the type
2215  /// that this expression is casting to.
2216  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
2217  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
2218
2219  /// getTypeAsWritten - Returns the type that this expression is
2220  /// casting to, as written in the source code.
2221  QualType getTypeAsWritten() const { return TInfo->getType(); }
2222
2223  static bool classof(const Stmt *T) {
2224     return T->getStmtClass() >= firstExplicitCastExprConstant &&
2225            T->getStmtClass() <= lastExplicitCastExprConstant;
2226  }
2227  static bool classof(const ExplicitCastExpr *) { return true; }
2228};
2229
2230/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
2231/// cast in C++ (C++ [expr.cast]), which uses the syntax
2232/// (Type)expr. For example: @c (int)f.
2233class CStyleCastExpr : public ExplicitCastExpr {
2234  SourceLocation LPLoc; // the location of the left paren
2235  SourceLocation RPLoc; // the location of the right paren
2236
2237  CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op,
2238                 unsigned PathSize, TypeSourceInfo *writtenTy,
2239                 SourceLocation l, SourceLocation r)
2240    : ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, PathSize,
2241                       writtenTy), LPLoc(l), RPLoc(r) {}
2242
2243  /// \brief Construct an empty C-style explicit cast.
2244  explicit CStyleCastExpr(EmptyShell Shell, unsigned PathSize)
2245    : ExplicitCastExpr(CStyleCastExprClass, Shell, PathSize) { }
2246
2247public:
2248  static CStyleCastExpr *Create(ASTContext &Context, QualType T, CastKind K,
2249                                Expr *Op, const CXXCastPath *BasePath,
2250                                TypeSourceInfo *WrittenTy, SourceLocation L,
2251                                SourceLocation R);
2252
2253  static CStyleCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize);
2254
2255  SourceLocation getLParenLoc() const { return LPLoc; }
2256  void setLParenLoc(SourceLocation L) { LPLoc = L; }
2257
2258  SourceLocation getRParenLoc() const { return RPLoc; }
2259  void setRParenLoc(SourceLocation L) { RPLoc = L; }
2260
2261  virtual SourceRange getSourceRange() const {
2262    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
2263  }
2264  static bool classof(const Stmt *T) {
2265    return T->getStmtClass() == CStyleCastExprClass;
2266  }
2267  static bool classof(const CStyleCastExpr *) { return true; }
2268};
2269
2270/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
2271///
2272/// This expression node kind describes a builtin binary operation,
2273/// such as "x + y" for integer values "x" and "y". The operands will
2274/// already have been converted to appropriate types (e.g., by
2275/// performing promotions or conversions).
2276///
2277/// In C++, where operators may be overloaded, a different kind of
2278/// expression node (CXXOperatorCallExpr) is used to express the
2279/// invocation of an overloaded operator with operator syntax. Within
2280/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
2281/// used to store an expression "x + y" depends on the subexpressions
2282/// for x and y. If neither x or y is type-dependent, and the "+"
2283/// operator resolves to a built-in operation, BinaryOperator will be
2284/// used to express the computation (x and y may still be
2285/// value-dependent). If either x or y is type-dependent, or if the
2286/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
2287/// be used to express the computation.
2288class BinaryOperator : public Expr {
2289public:
2290  typedef BinaryOperatorKind Opcode;
2291
2292  static const Opcode PtrMemD = BO_PtrMemD;
2293  static const Opcode PtrMemI = BO_PtrMemI;
2294  static const Opcode Mul = BO_Mul;
2295  static const Opcode Div = BO_Div;
2296  static const Opcode Rem = BO_Rem;
2297  static const Opcode Add = BO_Add;
2298  static const Opcode Sub = BO_Sub;
2299  static const Opcode Shl = BO_Shl;
2300  static const Opcode Shr = BO_Shr;
2301  static const Opcode LT = BO_LT;
2302  static const Opcode GT = BO_GT;
2303  static const Opcode LE = BO_LE;
2304  static const Opcode GE = BO_GE;
2305  static const Opcode EQ = BO_EQ;
2306  static const Opcode NE = BO_NE;
2307  static const Opcode And = BO_And;
2308  static const Opcode Xor = BO_Xor;
2309  static const Opcode Or = BO_Or;
2310  static const Opcode LAnd = BO_LAnd;
2311  static const Opcode LOr = BO_LOr;
2312  static const Opcode Assign = BO_Assign;
2313  static const Opcode MulAssign = BO_MulAssign;
2314  static const Opcode DivAssign = BO_DivAssign;
2315  static const Opcode RemAssign = BO_RemAssign;
2316  static const Opcode AddAssign = BO_AddAssign;
2317  static const Opcode SubAssign = BO_SubAssign;
2318  static const Opcode ShlAssign = BO_ShlAssign;
2319  static const Opcode ShrAssign = BO_ShrAssign;
2320  static const Opcode AndAssign = BO_AndAssign;
2321  static const Opcode XorAssign = BO_XorAssign;
2322  static const Opcode OrAssign = BO_OrAssign;
2323  static const Opcode Comma = BO_Comma;
2324
2325private:
2326  enum { LHS, RHS, END_EXPR };
2327  Stmt* SubExprs[END_EXPR];
2328  Opcode Opc;
2329  SourceLocation OpLoc;
2330public:
2331
2332  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2333                 SourceLocation opLoc)
2334    : Expr(BinaryOperatorClass, ResTy,
2335           lhs->isTypeDependent() || rhs->isTypeDependent(),
2336           lhs->isValueDependent() || rhs->isValueDependent()),
2337      Opc(opc), OpLoc(opLoc) {
2338    SubExprs[LHS] = lhs;
2339    SubExprs[RHS] = rhs;
2340    assert(!isCompoundAssignmentOp() &&
2341           "Use ArithAssignBinaryOperator for compound assignments");
2342  }
2343
2344  /// \brief Construct an empty binary operator.
2345  explicit BinaryOperator(EmptyShell Empty)
2346    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
2347
2348  SourceLocation getOperatorLoc() const { return OpLoc; }
2349  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2350
2351  Opcode getOpcode() const { return Opc; }
2352  void setOpcode(Opcode O) { Opc = O; }
2353
2354  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2355  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2356  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2357  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2358
2359  virtual SourceRange getSourceRange() const {
2360    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
2361  }
2362
2363  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
2364  /// corresponds to, e.g. "<<=".
2365  static const char *getOpcodeStr(Opcode Op);
2366
2367  const char *getOpcodeStr() const { return getOpcodeStr(Opc); }
2368
2369  /// \brief Retrieve the binary opcode that corresponds to the given
2370  /// overloaded operator.
2371  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
2372
2373  /// \brief Retrieve the overloaded operator kind that corresponds to
2374  /// the given binary opcode.
2375  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
2376
2377  /// predicates to categorize the respective opcodes.
2378  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
2379  static bool isAdditiveOp(Opcode Opc) { return Opc == Add || Opc == Sub; }
2380  bool isAdditiveOp() const { return isAdditiveOp(Opc); }
2381  static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; }
2382  bool isShiftOp() const { return isShiftOp(Opc); }
2383
2384  static bool isBitwiseOp(Opcode Opc) { return Opc >= And && Opc <= Or; }
2385  bool isBitwiseOp() const { return isBitwiseOp(Opc); }
2386
2387  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
2388  bool isRelationalOp() const { return isRelationalOp(Opc); }
2389
2390  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
2391  bool isEqualityOp() const { return isEqualityOp(Opc); }
2392
2393  static bool isComparisonOp(Opcode Opc) { return Opc >= LT && Opc <= NE; }
2394  bool isComparisonOp() const { return isComparisonOp(Opc); }
2395
2396  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
2397  bool isLogicalOp() const { return isLogicalOp(Opc); }
2398
2399  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
2400  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
2401  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
2402
2403  static bool classof(const Stmt *S) {
2404    return S->getStmtClass() >= firstBinaryOperatorConstant &&
2405           S->getStmtClass() <= lastBinaryOperatorConstant;
2406  }
2407  static bool classof(const BinaryOperator *) { return true; }
2408
2409  // Iterators
2410  virtual child_iterator child_begin();
2411  virtual child_iterator child_end();
2412
2413protected:
2414  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2415                 SourceLocation opLoc, bool dead)
2416    : Expr(CompoundAssignOperatorClass, ResTy,
2417           lhs->isTypeDependent() || rhs->isTypeDependent(),
2418           lhs->isValueDependent() || rhs->isValueDependent()),
2419      Opc(opc), OpLoc(opLoc) {
2420    SubExprs[LHS] = lhs;
2421    SubExprs[RHS] = rhs;
2422  }
2423
2424  BinaryOperator(StmtClass SC, EmptyShell Empty)
2425    : Expr(SC, Empty), Opc(MulAssign) { }
2426};
2427
2428/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
2429/// track of the type the operation is performed in.  Due to the semantics of
2430/// these operators, the operands are promoted, the aritmetic performed, an
2431/// implicit conversion back to the result type done, then the assignment takes
2432/// place.  This captures the intermediate type which the computation is done
2433/// in.
2434class CompoundAssignOperator : public BinaryOperator {
2435  QualType ComputationLHSType;
2436  QualType ComputationResultType;
2437public:
2438  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
2439                         QualType ResType, QualType CompLHSType,
2440                         QualType CompResultType,
2441                         SourceLocation OpLoc)
2442    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
2443      ComputationLHSType(CompLHSType),
2444      ComputationResultType(CompResultType) {
2445    assert(isCompoundAssignmentOp() &&
2446           "Only should be used for compound assignments");
2447  }
2448
2449  /// \brief Build an empty compound assignment operator expression.
2450  explicit CompoundAssignOperator(EmptyShell Empty)
2451    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
2452
2453  // The two computation types are the type the LHS is converted
2454  // to for the computation and the type of the result; the two are
2455  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
2456  QualType getComputationLHSType() const { return ComputationLHSType; }
2457  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
2458
2459  QualType getComputationResultType() const { return ComputationResultType; }
2460  void setComputationResultType(QualType T) { ComputationResultType = T; }
2461
2462  static bool classof(const CompoundAssignOperator *) { return true; }
2463  static bool classof(const Stmt *S) {
2464    return S->getStmtClass() == CompoundAssignOperatorClass;
2465  }
2466};
2467
2468/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
2469/// GNU "missing LHS" extension is in use.
2470///
2471class ConditionalOperator : public Expr {
2472  enum { COND, LHS, RHS, END_EXPR };
2473  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2474  SourceLocation QuestionLoc, ColonLoc;
2475public:
2476  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
2477                      SourceLocation CLoc, Expr *rhs, QualType t)
2478    : Expr(ConditionalOperatorClass, t,
2479           // FIXME: the type of the conditional operator doesn't
2480           // depend on the type of the conditional, but the standard
2481           // seems to imply that it could. File a bug!
2482           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
2483           (cond->isValueDependent() ||
2484            (lhs && lhs->isValueDependent()) ||
2485            (rhs && rhs->isValueDependent()))),
2486      QuestionLoc(QLoc),
2487      ColonLoc(CLoc) {
2488    SubExprs[COND] = cond;
2489    SubExprs[LHS] = lhs;
2490    SubExprs[RHS] = rhs;
2491  }
2492
2493  /// \brief Build an empty conditional operator.
2494  explicit ConditionalOperator(EmptyShell Empty)
2495    : Expr(ConditionalOperatorClass, Empty) { }
2496
2497  // getCond - Return the expression representing the condition for
2498  //  the ?: operator.
2499  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
2500  void setCond(Expr *E) { SubExprs[COND] = E; }
2501
2502  // getTrueExpr - Return the subexpression representing the value of the ?:
2503  //  expression if the condition evaluates to true.  In most cases this value
2504  //  will be the same as getLHS() except a GCC extension allows the left
2505  //  subexpression to be omitted, and instead of the condition be returned.
2506  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
2507  //  is only evaluated once.
2508  Expr *getTrueExpr() const {
2509    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
2510  }
2511
2512  // getTrueExpr - Return the subexpression representing the value of the ?:
2513  // expression if the condition evaluates to false. This is the same as getRHS.
2514  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
2515
2516  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
2517  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2518
2519  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2520  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2521
2522  SourceLocation getQuestionLoc() const { return QuestionLoc; }
2523  void setQuestionLoc(SourceLocation L) { QuestionLoc = L; }
2524
2525  SourceLocation getColonLoc() const { return ColonLoc; }
2526  void setColonLoc(SourceLocation L) { ColonLoc = L; }
2527
2528  virtual SourceRange getSourceRange() const {
2529    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
2530  }
2531  static bool classof(const Stmt *T) {
2532    return T->getStmtClass() == ConditionalOperatorClass;
2533  }
2534  static bool classof(const ConditionalOperator *) { return true; }
2535
2536  // Iterators
2537  virtual child_iterator child_begin();
2538  virtual child_iterator child_end();
2539};
2540
2541/// AddrLabelExpr - The GNU address of label extension, representing &&label.
2542class AddrLabelExpr : public Expr {
2543  SourceLocation AmpAmpLoc, LabelLoc;
2544  LabelStmt *Label;
2545public:
2546  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
2547                QualType t)
2548    : Expr(AddrLabelExprClass, t, false, false),
2549      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
2550
2551  /// \brief Build an empty address of a label expression.
2552  explicit AddrLabelExpr(EmptyShell Empty)
2553    : Expr(AddrLabelExprClass, Empty) { }
2554
2555  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
2556  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
2557  SourceLocation getLabelLoc() const { return LabelLoc; }
2558  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
2559
2560  virtual SourceRange getSourceRange() const {
2561    return SourceRange(AmpAmpLoc, LabelLoc);
2562  }
2563
2564  LabelStmt *getLabel() const { return Label; }
2565  void setLabel(LabelStmt *S) { Label = S; }
2566
2567  static bool classof(const Stmt *T) {
2568    return T->getStmtClass() == AddrLabelExprClass;
2569  }
2570  static bool classof(const AddrLabelExpr *) { return true; }
2571
2572  // Iterators
2573  virtual child_iterator child_begin();
2574  virtual child_iterator child_end();
2575};
2576
2577/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
2578/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
2579/// takes the value of the last subexpression.
2580class StmtExpr : public Expr {
2581  Stmt *SubStmt;
2582  SourceLocation LParenLoc, RParenLoc;
2583public:
2584  // FIXME: Does type-dependence need to be computed differently?
2585  StmtExpr(CompoundStmt *substmt, QualType T,
2586           SourceLocation lp, SourceLocation rp) :
2587    Expr(StmtExprClass, T, T->isDependentType(), false),
2588    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
2589
2590  /// \brief Build an empty statement expression.
2591  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
2592
2593  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
2594  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
2595  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
2596
2597  virtual SourceRange getSourceRange() const {
2598    return SourceRange(LParenLoc, RParenLoc);
2599  }
2600
2601  SourceLocation getLParenLoc() const { return LParenLoc; }
2602  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2603  SourceLocation getRParenLoc() const { return RParenLoc; }
2604  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2605
2606  static bool classof(const Stmt *T) {
2607    return T->getStmtClass() == StmtExprClass;
2608  }
2609  static bool classof(const StmtExpr *) { return true; }
2610
2611  // Iterators
2612  virtual child_iterator child_begin();
2613  virtual child_iterator child_end();
2614};
2615
2616/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p.
2617/// This AST node represents a function that returns 1 if two *types* (not
2618/// expressions) are compatible. The result of this built-in function can be
2619/// used in integer constant expressions.
2620class TypesCompatibleExpr : public Expr {
2621  TypeSourceInfo *TInfo1;
2622  TypeSourceInfo *TInfo2;
2623  SourceLocation BuiltinLoc, RParenLoc;
2624public:
2625  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
2626                      TypeSourceInfo *tinfo1, TypeSourceInfo *tinfo2,
2627                      SourceLocation RP) :
2628    Expr(TypesCompatibleExprClass, ReturnType, false, false),
2629    TInfo1(tinfo1), TInfo2(tinfo2), BuiltinLoc(BLoc), RParenLoc(RP) {}
2630
2631  /// \brief Build an empty __builtin_type_compatible_p expression.
2632  explicit TypesCompatibleExpr(EmptyShell Empty)
2633    : Expr(TypesCompatibleExprClass, Empty) { }
2634
2635  TypeSourceInfo *getArgTInfo1() const { return TInfo1; }
2636  void setArgTInfo1(TypeSourceInfo *TInfo) { TInfo1 = TInfo; }
2637  TypeSourceInfo *getArgTInfo2() const { return TInfo2; }
2638  void setArgTInfo2(TypeSourceInfo *TInfo) { TInfo2 = TInfo; }
2639
2640  QualType getArgType1() const { return TInfo1->getType(); }
2641  QualType getArgType2() const { return TInfo2->getType(); }
2642
2643  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2644  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2645
2646  SourceLocation getRParenLoc() const { return RParenLoc; }
2647  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2648
2649  virtual SourceRange getSourceRange() const {
2650    return SourceRange(BuiltinLoc, RParenLoc);
2651  }
2652  static bool classof(const Stmt *T) {
2653    return T->getStmtClass() == TypesCompatibleExprClass;
2654  }
2655  static bool classof(const TypesCompatibleExpr *) { return true; }
2656
2657  // Iterators
2658  virtual child_iterator child_begin();
2659  virtual child_iterator child_end();
2660};
2661
2662/// ShuffleVectorExpr - clang-specific builtin-in function
2663/// __builtin_shufflevector.
2664/// This AST node represents a operator that does a constant
2665/// shuffle, similar to LLVM's shufflevector instruction. It takes
2666/// two vectors and a variable number of constant indices,
2667/// and returns the appropriately shuffled vector.
2668class ShuffleVectorExpr : public Expr {
2669  SourceLocation BuiltinLoc, RParenLoc;
2670
2671  // SubExprs - the list of values passed to the __builtin_shufflevector
2672  // function. The first two are vectors, and the rest are constant
2673  // indices.  The number of values in this list is always
2674  // 2+the number of indices in the vector type.
2675  Stmt **SubExprs;
2676  unsigned NumExprs;
2677
2678public:
2679  // FIXME: Can a shufflevector be value-dependent?  Does type-dependence need
2680  // to be computed differently?
2681  ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
2682                    QualType Type, SourceLocation BLoc,
2683                    SourceLocation RP) :
2684    Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false),
2685    BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) {
2686
2687    SubExprs = new (C) Stmt*[nexpr];
2688    for (unsigned i = 0; i < nexpr; i++)
2689      SubExprs[i] = args[i];
2690  }
2691
2692  /// \brief Build an empty vector-shuffle expression.
2693  explicit ShuffleVectorExpr(EmptyShell Empty)
2694    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
2695
2696  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2697  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2698
2699  SourceLocation getRParenLoc() const { return RParenLoc; }
2700  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2701
2702  virtual SourceRange getSourceRange() const {
2703    return SourceRange(BuiltinLoc, RParenLoc);
2704  }
2705  static bool classof(const Stmt *T) {
2706    return T->getStmtClass() == ShuffleVectorExprClass;
2707  }
2708  static bool classof(const ShuffleVectorExpr *) { return true; }
2709
2710  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
2711  /// constant expression, the actual arguments passed in, and the function
2712  /// pointers.
2713  unsigned getNumSubExprs() const { return NumExprs; }
2714
2715  /// getExpr - Return the Expr at the specified index.
2716  Expr *getExpr(unsigned Index) {
2717    assert((Index < NumExprs) && "Arg access out of range!");
2718    return cast<Expr>(SubExprs[Index]);
2719  }
2720  const Expr *getExpr(unsigned Index) const {
2721    assert((Index < NumExprs) && "Arg access out of range!");
2722    return cast<Expr>(SubExprs[Index]);
2723  }
2724
2725  void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
2726
2727  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
2728    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
2729    return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
2730  }
2731
2732  // Iterators
2733  virtual child_iterator child_begin();
2734  virtual child_iterator child_end();
2735};
2736
2737/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
2738/// This AST node is similar to the conditional operator (?:) in C, with
2739/// the following exceptions:
2740/// - the test expression must be a integer constant expression.
2741/// - the expression returned acts like the chosen subexpression in every
2742///   visible way: the type is the same as that of the chosen subexpression,
2743///   and all predicates (whether it's an l-value, whether it's an integer
2744///   constant expression, etc.) return the same result as for the chosen
2745///   sub-expression.
2746class ChooseExpr : public Expr {
2747  enum { COND, LHS, RHS, END_EXPR };
2748  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2749  SourceLocation BuiltinLoc, RParenLoc;
2750public:
2751  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
2752             SourceLocation RP, bool TypeDependent, bool ValueDependent)
2753    : Expr(ChooseExprClass, t, TypeDependent, ValueDependent),
2754      BuiltinLoc(BLoc), RParenLoc(RP) {
2755      SubExprs[COND] = cond;
2756      SubExprs[LHS] = lhs;
2757      SubExprs[RHS] = rhs;
2758    }
2759
2760  /// \brief Build an empty __builtin_choose_expr.
2761  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
2762
2763  /// isConditionTrue - Return whether the condition is true (i.e. not
2764  /// equal to zero).
2765  bool isConditionTrue(ASTContext &C) const;
2766
2767  /// getChosenSubExpr - Return the subexpression chosen according to the
2768  /// condition.
2769  Expr *getChosenSubExpr(ASTContext &C) const {
2770    return isConditionTrue(C) ? getLHS() : getRHS();
2771  }
2772
2773  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
2774  void setCond(Expr *E) { SubExprs[COND] = E; }
2775  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2776  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2777  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2778  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2779
2780  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2781  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2782
2783  SourceLocation getRParenLoc() const { return RParenLoc; }
2784  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2785
2786  virtual SourceRange getSourceRange() const {
2787    return SourceRange(BuiltinLoc, RParenLoc);
2788  }
2789  static bool classof(const Stmt *T) {
2790    return T->getStmtClass() == ChooseExprClass;
2791  }
2792  static bool classof(const ChooseExpr *) { return true; }
2793
2794  // Iterators
2795  virtual child_iterator child_begin();
2796  virtual child_iterator child_end();
2797};
2798
2799/// GNUNullExpr - Implements the GNU __null extension, which is a name
2800/// for a null pointer constant that has integral type (e.g., int or
2801/// long) and is the same size and alignment as a pointer. The __null
2802/// extension is typically only used by system headers, which define
2803/// NULL as __null in C++ rather than using 0 (which is an integer
2804/// that may not match the size of a pointer).
2805class GNUNullExpr : public Expr {
2806  /// TokenLoc - The location of the __null keyword.
2807  SourceLocation TokenLoc;
2808
2809public:
2810  GNUNullExpr(QualType Ty, SourceLocation Loc)
2811    : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { }
2812
2813  /// \brief Build an empty GNU __null expression.
2814  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
2815
2816  /// getTokenLocation - The location of the __null token.
2817  SourceLocation getTokenLocation() const { return TokenLoc; }
2818  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
2819
2820  virtual SourceRange getSourceRange() const {
2821    return SourceRange(TokenLoc);
2822  }
2823  static bool classof(const Stmt *T) {
2824    return T->getStmtClass() == GNUNullExprClass;
2825  }
2826  static bool classof(const GNUNullExpr *) { return true; }
2827
2828  // Iterators
2829  virtual child_iterator child_begin();
2830  virtual child_iterator child_end();
2831};
2832
2833/// VAArgExpr, used for the builtin function __builtin_va_arg.
2834class VAArgExpr : public Expr {
2835  Stmt *Val;
2836  TypeSourceInfo *TInfo;
2837  SourceLocation BuiltinLoc, RParenLoc;
2838public:
2839  VAArgExpr(SourceLocation BLoc, Expr* e, TypeSourceInfo *TInfo,
2840            SourceLocation RPLoc, QualType t)
2841    : Expr(VAArgExprClass, t, t->isDependentType(), false),
2842      Val(e), TInfo(TInfo),
2843      BuiltinLoc(BLoc),
2844      RParenLoc(RPLoc) { }
2845
2846  /// \brief Create an empty __builtin_va_arg expression.
2847  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
2848
2849  const Expr *getSubExpr() const { return cast<Expr>(Val); }
2850  Expr *getSubExpr() { return cast<Expr>(Val); }
2851  void setSubExpr(Expr *E) { Val = E; }
2852
2853  TypeSourceInfo *getWrittenTypeInfo() const { return TInfo; }
2854  void setWrittenTypeInfo(TypeSourceInfo *TI) { TInfo = TI; }
2855
2856  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2857  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2858
2859  SourceLocation getRParenLoc() const { return RParenLoc; }
2860  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2861
2862  virtual SourceRange getSourceRange() const {
2863    return SourceRange(BuiltinLoc, RParenLoc);
2864  }
2865  static bool classof(const Stmt *T) {
2866    return T->getStmtClass() == VAArgExprClass;
2867  }
2868  static bool classof(const VAArgExpr *) { return true; }
2869
2870  // Iterators
2871  virtual child_iterator child_begin();
2872  virtual child_iterator child_end();
2873};
2874
2875/// @brief Describes an C or C++ initializer list.
2876///
2877/// InitListExpr describes an initializer list, which can be used to
2878/// initialize objects of different types, including
2879/// struct/class/union types, arrays, and vectors. For example:
2880///
2881/// @code
2882/// struct foo x = { 1, { 2, 3 } };
2883/// @endcode
2884///
2885/// Prior to semantic analysis, an initializer list will represent the
2886/// initializer list as written by the user, but will have the
2887/// placeholder type "void". This initializer list is called the
2888/// syntactic form of the initializer, and may contain C99 designated
2889/// initializers (represented as DesignatedInitExprs), initializations
2890/// of subobject members without explicit braces, and so on. Clients
2891/// interested in the original syntax of the initializer list should
2892/// use the syntactic form of the initializer list.
2893///
2894/// After semantic analysis, the initializer list will represent the
2895/// semantic form of the initializer, where the initializations of all
2896/// subobjects are made explicit with nested InitListExpr nodes and
2897/// C99 designators have been eliminated by placing the designated
2898/// initializations into the subobject they initialize. Additionally,
2899/// any "holes" in the initialization, where no initializer has been
2900/// specified for a particular subobject, will be replaced with
2901/// implicitly-generated ImplicitValueInitExpr expressions that
2902/// value-initialize the subobjects. Note, however, that the
2903/// initializer lists may still have fewer initializers than there are
2904/// elements to initialize within the object.
2905///
2906/// Given the semantic form of the initializer list, one can retrieve
2907/// the original syntactic form of that initializer list (if it
2908/// exists) using getSyntacticForm(). Since many initializer lists
2909/// have the same syntactic and semantic forms, getSyntacticForm() may
2910/// return NULL, indicating that the current initializer list also
2911/// serves as its syntactic form.
2912class InitListExpr : public Expr {
2913  // FIXME: Eliminate this vector in favor of ASTContext allocation
2914  typedef ASTVector<Stmt *> InitExprsTy;
2915  InitExprsTy InitExprs;
2916  SourceLocation LBraceLoc, RBraceLoc;
2917
2918  /// Contains the initializer list that describes the syntactic form
2919  /// written in the source code.
2920  InitListExpr *SyntacticForm;
2921
2922  /// If this initializer list initializes a union, specifies which
2923  /// field within the union will be initialized.
2924  FieldDecl *UnionFieldInit;
2925
2926  /// Whether this initializer list originally had a GNU array-range
2927  /// designator in it. This is a temporary marker used by CodeGen.
2928  bool HadArrayRangeDesignator;
2929
2930public:
2931  InitListExpr(ASTContext &C, SourceLocation lbraceloc,
2932               Expr **initexprs, unsigned numinits,
2933               SourceLocation rbraceloc);
2934
2935  /// \brief Build an empty initializer list.
2936  explicit InitListExpr(ASTContext &C, EmptyShell Empty)
2937    : Expr(InitListExprClass, Empty), InitExprs(C) { }
2938
2939  unsigned getNumInits() const { return InitExprs.size(); }
2940
2941  const Expr* getInit(unsigned Init) const {
2942    assert(Init < getNumInits() && "Initializer access out of range!");
2943    return cast_or_null<Expr>(InitExprs[Init]);
2944  }
2945
2946  Expr* getInit(unsigned Init) {
2947    assert(Init < getNumInits() && "Initializer access out of range!");
2948    return cast_or_null<Expr>(InitExprs[Init]);
2949  }
2950
2951  void setInit(unsigned Init, Expr *expr) {
2952    assert(Init < getNumInits() && "Initializer access out of range!");
2953    InitExprs[Init] = expr;
2954  }
2955
2956  /// \brief Reserve space for some number of initializers.
2957  void reserveInits(ASTContext &C, unsigned NumInits);
2958
2959  /// @brief Specify the number of initializers
2960  ///
2961  /// If there are more than @p NumInits initializers, the remaining
2962  /// initializers will be destroyed. If there are fewer than @p
2963  /// NumInits initializers, NULL expressions will be added for the
2964  /// unknown initializers.
2965  void resizeInits(ASTContext &Context, unsigned NumInits);
2966
2967  /// @brief Updates the initializer at index @p Init with the new
2968  /// expression @p expr, and returns the old expression at that
2969  /// location.
2970  ///
2971  /// When @p Init is out of range for this initializer list, the
2972  /// initializer list will be extended with NULL expressions to
2973  /// accomodate the new entry.
2974  Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
2975
2976  /// \brief If this initializes a union, specifies which field in the
2977  /// union to initialize.
2978  ///
2979  /// Typically, this field is the first named field within the
2980  /// union. However, a designated initializer can specify the
2981  /// initialization of a different field within the union.
2982  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
2983  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
2984
2985  // Explicit InitListExpr's originate from source code (and have valid source
2986  // locations). Implicit InitListExpr's are created by the semantic analyzer.
2987  bool isExplicit() {
2988    return LBraceLoc.isValid() && RBraceLoc.isValid();
2989  }
2990
2991  SourceLocation getLBraceLoc() const { return LBraceLoc; }
2992  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
2993  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2994  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
2995
2996  /// @brief Retrieve the initializer list that describes the
2997  /// syntactic form of the initializer.
2998  ///
2999  ///
3000  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
3001  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
3002
3003  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
3004  void sawArrayRangeDesignator(bool ARD = true) {
3005    HadArrayRangeDesignator = ARD;
3006  }
3007
3008  virtual SourceRange getSourceRange() const {
3009    return SourceRange(LBraceLoc, RBraceLoc);
3010  }
3011  static bool classof(const Stmt *T) {
3012    return T->getStmtClass() == InitListExprClass;
3013  }
3014  static bool classof(const InitListExpr *) { return true; }
3015
3016  // Iterators
3017  virtual child_iterator child_begin();
3018  virtual child_iterator child_end();
3019
3020  typedef InitExprsTy::iterator iterator;
3021  typedef InitExprsTy::const_iterator const_iterator;
3022  typedef InitExprsTy::reverse_iterator reverse_iterator;
3023  typedef InitExprsTy::const_reverse_iterator const_reverse_iterator;
3024
3025  iterator begin() { return InitExprs.begin(); }
3026  const_iterator begin() const { return InitExprs.begin(); }
3027  iterator end() { return InitExprs.end(); }
3028  const_iterator end() const { return InitExprs.end(); }
3029  reverse_iterator rbegin() { return InitExprs.rbegin(); }
3030  const_reverse_iterator rbegin() const { return InitExprs.rbegin(); }
3031  reverse_iterator rend() { return InitExprs.rend(); }
3032  const_reverse_iterator rend() const { return InitExprs.rend(); }
3033};
3034
3035/// @brief Represents a C99 designated initializer expression.
3036///
3037/// A designated initializer expression (C99 6.7.8) contains one or
3038/// more designators (which can be field designators, array
3039/// designators, or GNU array-range designators) followed by an
3040/// expression that initializes the field or element(s) that the
3041/// designators refer to. For example, given:
3042///
3043/// @code
3044/// struct point {
3045///   double x;
3046///   double y;
3047/// };
3048/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
3049/// @endcode
3050///
3051/// The InitListExpr contains three DesignatedInitExprs, the first of
3052/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
3053/// designators, one array designator for @c [2] followed by one field
3054/// designator for @c .y. The initalization expression will be 1.0.
3055class DesignatedInitExpr : public Expr {
3056public:
3057  /// \brief Forward declaration of the Designator class.
3058  class Designator;
3059
3060private:
3061  /// The location of the '=' or ':' prior to the actual initializer
3062  /// expression.
3063  SourceLocation EqualOrColonLoc;
3064
3065  /// Whether this designated initializer used the GNU deprecated
3066  /// syntax rather than the C99 '=' syntax.
3067  bool GNUSyntax : 1;
3068
3069  /// The number of designators in this initializer expression.
3070  unsigned NumDesignators : 15;
3071
3072  /// \brief The designators in this designated initialization
3073  /// expression.
3074  Designator *Designators;
3075
3076  /// The number of subexpressions of this initializer expression,
3077  /// which contains both the initializer and any additional
3078  /// expressions used by array and array-range designators.
3079  unsigned NumSubExprs : 16;
3080
3081
3082  DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
3083                     const Designator *Designators,
3084                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
3085                     Expr **IndexExprs, unsigned NumIndexExprs,
3086                     Expr *Init);
3087
3088  explicit DesignatedInitExpr(unsigned NumSubExprs)
3089    : Expr(DesignatedInitExprClass, EmptyShell()),
3090      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
3091
3092public:
3093  /// A field designator, e.g., ".x".
3094  struct FieldDesignator {
3095    /// Refers to the field that is being initialized. The low bit
3096    /// of this field determines whether this is actually a pointer
3097    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
3098    /// initially constructed, a field designator will store an
3099    /// IdentifierInfo*. After semantic analysis has resolved that
3100    /// name, the field designator will instead store a FieldDecl*.
3101    uintptr_t NameOrField;
3102
3103    /// The location of the '.' in the designated initializer.
3104    unsigned DotLoc;
3105
3106    /// The location of the field name in the designated initializer.
3107    unsigned FieldLoc;
3108  };
3109
3110  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
3111  struct ArrayOrRangeDesignator {
3112    /// Location of the first index expression within the designated
3113    /// initializer expression's list of subexpressions.
3114    unsigned Index;
3115    /// The location of the '[' starting the array range designator.
3116    unsigned LBracketLoc;
3117    /// The location of the ellipsis separating the start and end
3118    /// indices. Only valid for GNU array-range designators.
3119    unsigned EllipsisLoc;
3120    /// The location of the ']' terminating the array range designator.
3121    unsigned RBracketLoc;
3122  };
3123
3124  /// @brief Represents a single C99 designator.
3125  ///
3126  /// @todo This class is infuriatingly similar to clang::Designator,
3127  /// but minor differences (storing indices vs. storing pointers)
3128  /// keep us from reusing it. Try harder, later, to rectify these
3129  /// differences.
3130  class Designator {
3131    /// @brief The kind of designator this describes.
3132    enum {
3133      FieldDesignator,
3134      ArrayDesignator,
3135      ArrayRangeDesignator
3136    } Kind;
3137
3138    union {
3139      /// A field designator, e.g., ".x".
3140      struct FieldDesignator Field;
3141      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
3142      struct ArrayOrRangeDesignator ArrayOrRange;
3143    };
3144    friend class DesignatedInitExpr;
3145
3146  public:
3147    Designator() {}
3148
3149    /// @brief Initializes a field designator.
3150    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
3151               SourceLocation FieldLoc)
3152      : Kind(FieldDesignator) {
3153      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
3154      Field.DotLoc = DotLoc.getRawEncoding();
3155      Field.FieldLoc = FieldLoc.getRawEncoding();
3156    }
3157
3158    /// @brief Initializes an array designator.
3159    Designator(unsigned Index, SourceLocation LBracketLoc,
3160               SourceLocation RBracketLoc)
3161      : Kind(ArrayDesignator) {
3162      ArrayOrRange.Index = Index;
3163      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
3164      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
3165      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
3166    }
3167
3168    /// @brief Initializes a GNU array-range designator.
3169    Designator(unsigned Index, SourceLocation LBracketLoc,
3170               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
3171      : Kind(ArrayRangeDesignator) {
3172      ArrayOrRange.Index = Index;
3173      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
3174      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
3175      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
3176    }
3177
3178    bool isFieldDesignator() const { return Kind == FieldDesignator; }
3179    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
3180    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
3181
3182    IdentifierInfo * getFieldName();
3183
3184    FieldDecl *getField() {
3185      assert(Kind == FieldDesignator && "Only valid on a field designator");
3186      if (Field.NameOrField & 0x01)
3187        return 0;
3188      else
3189        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
3190    }
3191
3192    void setField(FieldDecl *FD) {
3193      assert(Kind == FieldDesignator && "Only valid on a field designator");
3194      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
3195    }
3196
3197    SourceLocation getDotLoc() const {
3198      assert(Kind == FieldDesignator && "Only valid on a field designator");
3199      return SourceLocation::getFromRawEncoding(Field.DotLoc);
3200    }
3201
3202    SourceLocation getFieldLoc() const {
3203      assert(Kind == FieldDesignator && "Only valid on a field designator");
3204      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
3205    }
3206
3207    SourceLocation getLBracketLoc() const {
3208      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3209             "Only valid on an array or array-range designator");
3210      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
3211    }
3212
3213    SourceLocation getRBracketLoc() const {
3214      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3215             "Only valid on an array or array-range designator");
3216      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
3217    }
3218
3219    SourceLocation getEllipsisLoc() const {
3220      assert(Kind == ArrayRangeDesignator &&
3221             "Only valid on an array-range designator");
3222      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
3223    }
3224
3225    unsigned getFirstExprIndex() const {
3226      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3227             "Only valid on an array or array-range designator");
3228      return ArrayOrRange.Index;
3229    }
3230
3231    SourceLocation getStartLocation() const {
3232      if (Kind == FieldDesignator)
3233        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
3234      else
3235        return getLBracketLoc();
3236    }
3237  };
3238
3239  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
3240                                    unsigned NumDesignators,
3241                                    Expr **IndexExprs, unsigned NumIndexExprs,
3242                                    SourceLocation EqualOrColonLoc,
3243                                    bool GNUSyntax, Expr *Init);
3244
3245  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
3246
3247  /// @brief Returns the number of designators in this initializer.
3248  unsigned size() const { return NumDesignators; }
3249
3250  // Iterator access to the designators.
3251  typedef Designator* designators_iterator;
3252  designators_iterator designators_begin() { return Designators; }
3253  designators_iterator designators_end() {
3254    return Designators + NumDesignators;
3255  }
3256
3257  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
3258
3259  void setDesignators(ASTContext &C, const Designator *Desigs,
3260                      unsigned NumDesigs);
3261
3262  Expr *getArrayIndex(const Designator& D);
3263  Expr *getArrayRangeStart(const Designator& D);
3264  Expr *getArrayRangeEnd(const Designator& D);
3265
3266  /// @brief Retrieve the location of the '=' that precedes the
3267  /// initializer value itself, if present.
3268  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
3269  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
3270
3271  /// @brief Determines whether this designated initializer used the
3272  /// deprecated GNU syntax for designated initializers.
3273  bool usesGNUSyntax() const { return GNUSyntax; }
3274  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
3275
3276  /// @brief Retrieve the initializer value.
3277  Expr *getInit() const {
3278    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
3279  }
3280
3281  void setInit(Expr *init) {
3282    *child_begin() = init;
3283  }
3284
3285  /// \brief Retrieve the total number of subexpressions in this
3286  /// designated initializer expression, including the actual
3287  /// initialized value and any expressions that occur within array
3288  /// and array-range designators.
3289  unsigned getNumSubExprs() const { return NumSubExprs; }
3290
3291  Expr *getSubExpr(unsigned Idx) {
3292    assert(Idx < NumSubExprs && "Subscript out of range");
3293    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3294    Ptr += sizeof(DesignatedInitExpr);
3295    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
3296  }
3297
3298  void setSubExpr(unsigned Idx, Expr *E) {
3299    assert(Idx < NumSubExprs && "Subscript out of range");
3300    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3301    Ptr += sizeof(DesignatedInitExpr);
3302    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
3303  }
3304
3305  /// \brief Replaces the designator at index @p Idx with the series
3306  /// of designators in [First, Last).
3307  void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
3308                        const Designator *Last);
3309
3310  virtual SourceRange getSourceRange() const;
3311
3312  static bool classof(const Stmt *T) {
3313    return T->getStmtClass() == DesignatedInitExprClass;
3314  }
3315  static bool classof(const DesignatedInitExpr *) { return true; }
3316
3317  // Iterators
3318  virtual child_iterator child_begin();
3319  virtual child_iterator child_end();
3320};
3321
3322/// \brief Represents an implicitly-generated value initialization of
3323/// an object of a given type.
3324///
3325/// Implicit value initializations occur within semantic initializer
3326/// list expressions (InitListExpr) as placeholders for subobject
3327/// initializations not explicitly specified by the user.
3328///
3329/// \see InitListExpr
3330class ImplicitValueInitExpr : public Expr {
3331public:
3332  explicit ImplicitValueInitExpr(QualType ty)
3333    : Expr(ImplicitValueInitExprClass, ty, false, false) { }
3334
3335  /// \brief Construct an empty implicit value initialization.
3336  explicit ImplicitValueInitExpr(EmptyShell Empty)
3337    : Expr(ImplicitValueInitExprClass, Empty) { }
3338
3339  static bool classof(const Stmt *T) {
3340    return T->getStmtClass() == ImplicitValueInitExprClass;
3341  }
3342  static bool classof(const ImplicitValueInitExpr *) { return true; }
3343
3344  virtual SourceRange getSourceRange() const {
3345    return SourceRange();
3346  }
3347
3348  // Iterators
3349  virtual child_iterator child_begin();
3350  virtual child_iterator child_end();
3351};
3352
3353
3354class ParenListExpr : public Expr {
3355  Stmt **Exprs;
3356  unsigned NumExprs;
3357  SourceLocation LParenLoc, RParenLoc;
3358
3359public:
3360  ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
3361                unsigned numexprs, SourceLocation rparenloc);
3362
3363  /// \brief Build an empty paren list.
3364  explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
3365
3366  unsigned getNumExprs() const { return NumExprs; }
3367
3368  const Expr* getExpr(unsigned Init) const {
3369    assert(Init < getNumExprs() && "Initializer access out of range!");
3370    return cast_or_null<Expr>(Exprs[Init]);
3371  }
3372
3373  Expr* getExpr(unsigned Init) {
3374    assert(Init < getNumExprs() && "Initializer access out of range!");
3375    return cast_or_null<Expr>(Exprs[Init]);
3376  }
3377
3378  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
3379
3380  SourceLocation getLParenLoc() const { return LParenLoc; }
3381  SourceLocation getRParenLoc() const { return RParenLoc; }
3382
3383  virtual SourceRange getSourceRange() const {
3384    return SourceRange(LParenLoc, RParenLoc);
3385  }
3386  static bool classof(const Stmt *T) {
3387    return T->getStmtClass() == ParenListExprClass;
3388  }
3389  static bool classof(const ParenListExpr *) { return true; }
3390
3391  // Iterators
3392  virtual child_iterator child_begin();
3393  virtual child_iterator child_end();
3394
3395  friend class ASTStmtReader;
3396  friend class ASTStmtWriter;
3397};
3398
3399
3400//===----------------------------------------------------------------------===//
3401// Clang Extensions
3402//===----------------------------------------------------------------------===//
3403
3404
3405/// ExtVectorElementExpr - This represents access to specific elements of a
3406/// vector, and may occur on the left hand side or right hand side.  For example
3407/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
3408///
3409/// Note that the base may have either vector or pointer to vector type, just
3410/// like a struct field reference.
3411///
3412class ExtVectorElementExpr : public Expr {
3413  Stmt *Base;
3414  IdentifierInfo *Accessor;
3415  SourceLocation AccessorLoc;
3416public:
3417  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
3418                       SourceLocation loc)
3419    : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(),
3420           base->isValueDependent()),
3421      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
3422
3423  /// \brief Build an empty vector element expression.
3424  explicit ExtVectorElementExpr(EmptyShell Empty)
3425    : Expr(ExtVectorElementExprClass, Empty) { }
3426
3427  const Expr *getBase() const { return cast<Expr>(Base); }
3428  Expr *getBase() { return cast<Expr>(Base); }
3429  void setBase(Expr *E) { Base = E; }
3430
3431  IdentifierInfo &getAccessor() const { return *Accessor; }
3432  void setAccessor(IdentifierInfo *II) { Accessor = II; }
3433
3434  SourceLocation getAccessorLoc() const { return AccessorLoc; }
3435  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
3436
3437  /// getNumElements - Get the number of components being selected.
3438  unsigned getNumElements() const;
3439
3440  /// containsDuplicateElements - Return true if any element access is
3441  /// repeated.
3442  bool containsDuplicateElements() const;
3443
3444  /// getEncodedElementAccess - Encode the elements accessed into an llvm
3445  /// aggregate Constant of ConstantInt(s).
3446  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
3447
3448  virtual SourceRange getSourceRange() const {
3449    return SourceRange(getBase()->getLocStart(), AccessorLoc);
3450  }
3451
3452  /// isArrow - Return true if the base expression is a pointer to vector,
3453  /// return false if the base expression is a vector.
3454  bool isArrow() const;
3455
3456  static bool classof(const Stmt *T) {
3457    return T->getStmtClass() == ExtVectorElementExprClass;
3458  }
3459  static bool classof(const ExtVectorElementExpr *) { return true; }
3460
3461  // Iterators
3462  virtual child_iterator child_begin();
3463  virtual child_iterator child_end();
3464};
3465
3466
3467/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
3468/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
3469class BlockExpr : public Expr {
3470protected:
3471  BlockDecl *TheBlock;
3472  bool HasBlockDeclRefExprs;
3473public:
3474  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
3475    : Expr(BlockExprClass, ty, ty->isDependentType(), false),
3476      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
3477
3478  /// \brief Build an empty block expression.
3479  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
3480
3481  const BlockDecl *getBlockDecl() const { return TheBlock; }
3482  BlockDecl *getBlockDecl() { return TheBlock; }
3483  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
3484
3485  // Convenience functions for probing the underlying BlockDecl.
3486  SourceLocation getCaretLocation() const;
3487  const Stmt *getBody() const;
3488  Stmt *getBody();
3489
3490  virtual SourceRange getSourceRange() const {
3491    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
3492  }
3493
3494  /// getFunctionType - Return the underlying function type for this block.
3495  const FunctionType *getFunctionType() const;
3496
3497  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
3498  /// inside of the block that reference values outside the block.
3499  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
3500  void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
3501
3502  static bool classof(const Stmt *T) {
3503    return T->getStmtClass() == BlockExprClass;
3504  }
3505  static bool classof(const BlockExpr *) { return true; }
3506
3507  // Iterators
3508  virtual child_iterator child_begin();
3509  virtual child_iterator child_end();
3510};
3511
3512/// BlockDeclRefExpr - A reference to a declared variable, function,
3513/// enum, etc.
3514class BlockDeclRefExpr : public Expr {
3515  ValueDecl *D;
3516  SourceLocation Loc;
3517  bool IsByRef : 1;
3518  bool ConstQualAdded : 1;
3519  Stmt *CopyConstructorVal;
3520public:
3521  // FIXME: Fix type/value dependence!
3522  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef,
3523                   bool constAdded = false,
3524                   Stmt *copyConstructorVal = 0)
3525  : Expr(BlockDeclRefExprClass, t, (!t.isNull() && t->isDependentType()),false),
3526    D(d), Loc(l), IsByRef(ByRef),
3527    ConstQualAdded(constAdded),  CopyConstructorVal(copyConstructorVal) {}
3528
3529  // \brief Build an empty reference to a declared variable in a
3530  // block.
3531  explicit BlockDeclRefExpr(EmptyShell Empty)
3532    : Expr(BlockDeclRefExprClass, Empty) { }
3533
3534  ValueDecl *getDecl() { return D; }
3535  const ValueDecl *getDecl() const { return D; }
3536  void setDecl(ValueDecl *VD) { D = VD; }
3537
3538  SourceLocation getLocation() const { return Loc; }
3539  void setLocation(SourceLocation L) { Loc = L; }
3540
3541  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
3542
3543  bool isByRef() const { return IsByRef; }
3544  void setByRef(bool BR) { IsByRef = BR; }
3545
3546  bool isConstQualAdded() const { return ConstQualAdded; }
3547  void setConstQualAdded(bool C) { ConstQualAdded = C; }
3548
3549  const Expr *getCopyConstructorExpr() const
3550    { return cast_or_null<Expr>(CopyConstructorVal); }
3551  Expr *getCopyConstructorExpr()
3552    { return cast_or_null<Expr>(CopyConstructorVal); }
3553  void setCopyConstructorExpr(Expr *E) { CopyConstructorVal = E; }
3554
3555  static bool classof(const Stmt *T) {
3556    return T->getStmtClass() == BlockDeclRefExprClass;
3557  }
3558  static bool classof(const BlockDeclRefExpr *) { return true; }
3559
3560  // Iterators
3561  virtual child_iterator child_begin();
3562  virtual child_iterator child_end();
3563};
3564
3565}  // end namespace clang
3566
3567#endif
3568