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