Expr.h revision 89f9d3a7651d1225f3f56ae3387c83b98a26da00
1474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
2474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//
3474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//                     The LLVM Compiler Infrastructure
4474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//
5474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org// This file is distributed under the University of Illinois Open Source
6474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org// License. See LICENSE.TXT for details.
7474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//
8474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//===----------------------------------------------------------------------===//
9474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//
10474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//  This file defines the Expr interface and subclasses.
11474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//
12474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//===----------------------------------------------------------------------===//
13474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
14474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#ifndef LLVM_CLANG_AST_EXPR_H
15474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#define LLVM_CLANG_AST_EXPR_H
16474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
17474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include "clang/AST/APValue.h"
18474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include "clang/AST/Stmt.h"
19f18f5eb544bb35db231ced346e077907a8c61fc9hclam@chromium.org#include "clang/AST/Type.h"
20474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include "clang/AST/DeclAccessPair.h"
21474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include "clang/AST/ASTVector.h"
22474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include "clang/AST/UsuallyTinyPtrVector.h"
23474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include "llvm/ADT/APSInt.h"
24474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include "llvm/ADT/APFloat.h"
25474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include "llvm/ADT/SmallVector.h"
26474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include "llvm/ADT/StringRef.h"
27474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org#include <vector>
28474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
29474eb7536515fb785e925cc9375d22817c416851hclam@chromium.orgnamespace clang {
30474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class ASTContext;
31474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class APValue;
32474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class Decl;
33474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class IdentifierInfo;
34474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class ParmVarDecl;
35474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class NamedDecl;
36474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class ValueDecl;
37474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class BlockDecl;
38474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class CXXBaseSpecifier;
39474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class CXXOperatorCallExpr;
40167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org  class CXXMemberCallExpr;
41474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class TemplateArgumentLoc;
42474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  class TemplateArgumentListInfo;
43474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
44474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/// \brief A simple array of base specifiers.
45474eb7536515fb785e925cc9375d22817c416851hclam@chromium.orgtypedef UsuallyTinyPtrVector<const CXXBaseSpecifier> CXXBaseSpecifierArray;
46474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
47474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/// Expr - This represents one expression.  Note that Expr's are subclasses of
48474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/// Stmt.  This allows an expression to be transparently used any place a Stmt
49474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/// is required.
50474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org///
51474eb7536515fb785e925cc9375d22817c416851hclam@chromium.orgclass Expr : public Stmt {
52474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  QualType TR;
53474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
54474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  virtual void ANCHOR(); // key function.
55474eb7536515fb785e925cc9375d22817c416851hclam@chromium.orgprotected:
56474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// TypeDependent - Whether this expression is type-dependent
57474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// (C++ [temp.dep.expr]).
58474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool TypeDependent : 1;
59474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
60474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// ValueDependent - Whether this expression is value-dependent
61474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// (C++ [temp.dep.constexpr]).
62474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool ValueDependent : 1;
63474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
64474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  Expr(StmtClass SC, QualType T, bool TD, bool VD)
65474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
66474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    setType(T);
67474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  }
68474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
69474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief Construct an empty expression.
70474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
71167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org
72474eb7536515fb785e925cc9375d22817c416851hclam@chromium.orgpublic:
73474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief Increases the reference count for this expression.
74474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///
75474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// Invoke the Retain() operation when this expression
76474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// is being shared by another owner.
77474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  Expr *Retain() {
78474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    Stmt::Retain();
79474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    return this;
80474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  }
81474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
82474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  QualType getType() const { return TR; }
83474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  void setType(QualType t) {
84474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // In C++, the type of an expression is always adjusted so that it
85474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // will not have reference type an expression will never have
86474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // reference type (C++ [expr]p6). Use
87474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // QualType::getNonReferenceType() to retrieve the non-reference
88474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // type. Additionally, inspect Expr::isLvalue to determine whether
89474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // an expression that is adjusted in this manner should be
90474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // considered an lvalue.
91474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    assert((t.isNull() || !t->isReferenceType()) &&
925c1d3b27608a3f3f6028c069b9bf066a4de474b6hclam@chromium.org           "Expressions can't have reference type");
93f18f5eb544bb35db231ced346e077907a8c61fc9hclam@chromium.org
94474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    TR = t;
95474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  }
96474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
97474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isValueDependent - Determines whether this expression is
98474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
99474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// array bound of "Chars" in the following example is
100474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// value-dependent.
101474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// @code
102474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// template<int Size, char (&Chars)[Size]> struct meta_string;
103474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// @endcode
104474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isValueDependent() const { return ValueDependent; }
105474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
106474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief Set whether this expression is value-dependent or not.
107474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  void setValueDependent(bool VD) { ValueDependent = VD; }
108474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
109474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isTypeDependent - Determines whether this expression is
110474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// type-dependent (C++ [temp.dep.expr]), which means that its type
111474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// could change from one template instantiation to the next. For
112474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// example, the expressions "x" and "x + y" are type-dependent in
113474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// the following code, but "y" is not type-dependent:
114167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org  /// @code
115474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// template<typename T>
116474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// void add(T x, int y) {
117474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///   x + y;
118ed759d81a39febed3a8a395386639d54307504aagrunell@chromium.org  /// }
119474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// @endcode
120474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isTypeDependent() const { return TypeDependent; }
121474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
122474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief Set whether this expression is type-dependent or not.
123474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  void setTypeDependent(bool TD) { TypeDependent = TD; }
124474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
125474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// SourceLocation tokens are not useful in isolation - they are low level
126474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// value objects created/interpreted by SourceManager. We assume AST
127474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// clients will have a pointer to the respective SourceManager.
128474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  virtual SourceRange getSourceRange() const = 0;
129474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
130474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// getExprLoc - Return the preferred location for the arrow when diagnosing
131474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// a problem with a generic expression.
132474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  virtual SourceLocation getExprLoc() const { return getLocStart(); }
133474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
134474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isUnusedResultAWarning - Return true if this immediate expression should
135474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
136167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org  /// with location to warn on and the source range[s] to report with the
137474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// warning.
138474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
139474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org                              SourceRange &R2, ASTContext &Ctx) const;
140167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org
141474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
142474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// incomplete type other than void. Nonarray expressions that can be lvalues:
143474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  - name, where name must be a variable
144474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  - e[i]
145474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  - (e), where e must be an lvalue
146474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  - e.name, where e must be an lvalue
147474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  - e->name
148474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  - *e, the type of e cannot be a function type
149474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  - string-constant
150474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  - reference type [C++ [expr]]
151474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  - b ? x : y, where x and y are lvalues of suitable types [C++]
152474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///
153474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  enum isLvalueResult {
154474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    LV_Valid,
155474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    LV_NotObjectType,
156f18f5eb544bb35db231ced346e077907a8c61fc9hclam@chromium.org    LV_IncompleteVoidType,
157474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    LV_DuplicateVectorComponents,
158474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    LV_InvalidExpression,
159474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    LV_MemberFunction,
160474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    LV_SubObjCPropertySetting,
161474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    LV_ClassTemporary
162474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  };
163474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  isLvalueResult isLvalue(ASTContext &Ctx) const;
164474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
165474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  // Same as above, but excluding checks for non-object and void types in C
166474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  isLvalueResult isLvalueInternal(ASTContext &Ctx) const;
167474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
168474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
169474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// does not have an incomplete type, does not have a const-qualified type,
170474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// and if it is a structure or union, does not have any member (including,
171474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// recursively, any member or element of all contained aggregates or unions)
172474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// with a const-qualified type.
173474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///
174474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \param Loc [in] [out] - A source location which *may* be filled
175167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org  /// in with the location of the expression making this a
176474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// non-modifiable lvalue, if specified.
177474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  enum isModifiableLvalueResult {
178474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_Valid,
179ed759d81a39febed3a8a395386639d54307504aagrunell@chromium.org    MLV_NotObjectType,
180474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_IncompleteVoidType,
181474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_DuplicateVectorComponents,
182474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_InvalidExpression,
183474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
184474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_IncompleteType,
185474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_ConstQualified,
186474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_ArrayType,
187474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_NotBlockQualified,
188474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_ReadonlyProperty,
189474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_NoSetterProperty,
190474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_MemberFunction,
191167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org    MLV_SubObjCPropertySetting,
192474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    MLV_ClassTemporary
193474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  };
194167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
195474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org                                              SourceLocation *Loc = 0) const;
196474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
197474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief If this expression refers to a bit-field, retrieve the
198474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// declaration of that bit-field.
199474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  FieldDecl *getBitField();
200474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
201474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  const FieldDecl *getBitField() const {
202474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    return const_cast<Expr*>(this)->getBitField();
203474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  }
204474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
205474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief Returns whether this expression refers to a vector element.
206474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool refersToVectorElement() const;
207474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
208474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isKnownToHaveBooleanValue - Return true if this is an integer expression
209f18f5eb544bb35db231ced346e077907a8c61fc9hclam@chromium.org  /// that is known to return 0 or 1.  This happens for _Bool/bool expressions
210474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// but also int expressions which are produced by things like comparisons in
211474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// C.
212474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isKnownToHaveBooleanValue() const;
213474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
214474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isIntegerConstantExpr - Return true if this expression is a valid integer
215474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// constant expression, and, if so, return its value in Result.  If not a
216474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// valid i-c-e, return false and fill in Loc (if specified) with the location
217474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// of the invalid expression.
218474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
219474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org                             SourceLocation *Loc = 0,
220474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org                             bool isEvaluated = true) const;
221474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
222474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    llvm::APSInt X;
223474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    return isIntegerConstantExpr(X, Ctx, Loc);
224474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  }
225474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isConstantInitializer - Returns true if this expression is a constant
226474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// initializer, which can be emitted at compile-time.
227474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isConstantInitializer(ASTContext &Ctx) const;
228474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
229474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// EvalResult is a struct with detailed info about an evaluated expression.
230474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  struct EvalResult {
231474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// Val - This is the value the expression can be folded to.
232474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    APValue Val;
233474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
234474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// HasSideEffects - Whether the evaluated expression has side effects.
235474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// For example, (f() && 0) can be folded, but it still has side effects.
236474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    bool HasSideEffects;
237474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
238474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// Diag - If the expression is unfoldable, then Diag contains a note
239474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
240474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// position for the error, and DiagExpr is the expression that caused
241474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// the error.
242474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// If the expression is foldable, but not an integer constant expression,
243474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// Diag contains a note diagnostic that describes why it isn't an integer
244474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// constant expression. If the expression *is* an integer constant
245474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// expression, then Diag will be zero.
246474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    unsigned Diag;
247474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    const Expr *DiagExpr;
248474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    SourceLocation DiagLoc;
249474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
250474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
251474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
252474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // isGlobalLValue - Return true if the evaluated lvalue expression
253474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // is global.
254474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    bool isGlobalLValue() const;
255474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // hasSideEffects - Return true if the evaluated expression has
256474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    // side effects.
257474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    bool hasSideEffects() const {
258474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org      return HasSideEffects;
259474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    }
260474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  };
261474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
262474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// Evaluate - Return true if this is a constant which we can fold using
263474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// any crazy technique (that has nothing to do with language standards) that
264f18f5eb544bb35db231ced346e077907a8c61fc9hclam@chromium.org  /// we want to.  If this function returns true, it returns the folded constant
265474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// in Result.
266474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
267474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
268474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// EvaluateAsBooleanCondition - Return true if this is a constant
269474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// which we we can fold and convert to a boolean condition using
270474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// any crazy technique that we want to.
271474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool EvaluateAsBooleanCondition(bool &Result, ASTContext &Ctx) const;
272474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
273474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isEvaluatable - Call Evaluate to see if this expression can be constant
274474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// folded, but discard the result.
275474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isEvaluatable(ASTContext &Ctx) const;
276474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
277474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// HasSideEffects - This routine returns true for all those expressions
278474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// which must be evaluated each time and must not be optimization away
279474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// or evaluated at compile time. Example is a function call, volatile
280474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// variable read.
281474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool HasSideEffects(ASTContext &Ctx) const;
282474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
283474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
284167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org  /// must be called on an expression that constant folds to an integer.
285474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
286474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
287474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue
288ed759d81a39febed3a8a395386639d54307504aagrunell@chromium.org  /// with link time known address.
289474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
290474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
291474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// EvaluateAsLValue - Evaluate an expression to see if it's a lvalue.
292474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const;
293474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
294474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief Enumeration used to describe how \c isNullPointerConstant()
295474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// should cope with value-dependent expressions.
296474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  enum NullPointerConstantValueDependence {
297474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// \brief Specifies that the expression should never be value-dependent.
298474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    NPC_NeverValueDependent = 0,
299474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
300474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// \brief Specifies that a value-dependent expression of integral or
301474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// dependent type should be considered a null pointer constant.
302474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    NPC_ValueDependentIsNull,
303474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
304474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// \brief Specifies that a value-dependent expression should be considered
305474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    /// to never be a null pointer constant.
306474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    NPC_ValueDependentIsNotNull
307474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  };
308474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
309474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
310474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// integer constant expression with the value zero, or if this is one that is
311474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// cast to void*.
312474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isNullPointerConstant(ASTContext &Ctx,
313474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org                             NullPointerConstantValueDependence NPC) const;
314474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
315474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
316474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// write barrier.
317474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isOBJCGCCandidate(ASTContext &Ctx) const;
318167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org
319474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
320474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  its subexpression.  If that subexpression is also a ParenExpr,
321474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///  then this method recursively returns its subexpression, and so forth.
322167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org  ///  Otherwise, the method returns the current Expr.
323474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  Expr *IgnoreParens();
324474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
325474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
326474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// or CastExprs, returning their operand.
327474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  Expr *IgnoreParenCasts();
328474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
329474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// IgnoreParenImpCasts - Ignore parentheses and implicit casts.  Strip off any
330474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// ParenExpr or ImplicitCastExprs, returning their operand.
331474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  Expr *IgnoreParenImpCasts();
332474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
333474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
334474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// value (including ptr->int casts of the same size).  Strip off any
335474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// ParenExpr or CastExprs, returning their operand.
336474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
337474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
338f18f5eb544bb35db231ced346e077907a8c61fc9hclam@chromium.org  /// \brief Determine whether this expression is a default function argument.
339474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  ///
340474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// Default arguments are implicitly generated in the abstract syntax tree
341474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// by semantic analysis for function calls, object constructions, etc. in
342474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// C++. Default arguments are represented by \c CXXDefaultArgExpr nodes;
343474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// this routine also looks through any implicit casts to determine whether
344474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// the expression is a default argument.
345474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isDefaultArgument() const;
346474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
347474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief Determine whether this expression directly creates a
348474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// temporary object (of class type).
349474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  bool isTemporaryObject() const { return getTemporaryObject() != 0; }
350474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
351474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief If this expression directly creates a temporary object of
352474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// class type, return the expression that actually constructs that
353474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// temporary object.
354474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  const Expr *getTemporaryObject() const;
355167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org
356474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  const Expr *IgnoreParens() const {
357474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    return const_cast<Expr*>(this)->IgnoreParens();
358474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  }
359474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  const Expr *IgnoreParenCasts() const {
360474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    return const_cast<Expr*>(this)->IgnoreParenCasts();
361474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  }
362474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
363474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
364474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  }
365474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
366474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
367474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
368474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
369474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  static bool classof(const Stmt *T) {
370474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    return T->getStmtClass() >= firstExprConstant &&
371474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org           T->getStmtClass() <= lastExprConstant;
372474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  }
373474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  static bool classof(const Expr *) { return true; }
374474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org};
375474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
376474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
377474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//===----------------------------------------------------------------------===//
378474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org// Primary Expressions.
379474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org//===----------------------------------------------------------------------===//
380474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
381474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/// \brief Represents the qualifier that may precede a C++ name, e.g., the
382474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/// "std::" in "std::sort".
383474eb7536515fb785e925cc9375d22817c416851hclam@chromium.orgstruct NameQualifier {
384474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief The nested name specifier.
385474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  NestedNameSpecifier *NNS;
386167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org
387474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief The source range covered by the nested name specifier.
388474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  SourceRange Range;
389167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org};
390474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
391167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org/// \brief Represents an explicit template argument list in C++, e.g.,
392474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org/// the "<int>" in "sort<int>".
393474eb7536515fb785e925cc9375d22817c416851hclam@chromium.orgstruct ExplicitTemplateArgumentList {
394474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief The source location of the left angle bracket ('<');
395474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  SourceLocation LAngleLoc;
396474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
397474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief The source location of the right angle bracket ('>');
398474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  SourceLocation RAngleLoc;
399474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
400474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief The number of template arguments in TemplateArgs.
401167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org  /// The actual template arguments (if any) are stored after the
402474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// ExplicitTemplateArgumentList structure.
403167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org  unsigned NumTemplateArgs;
404474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
405474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief Retrieve the template arguments
406474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  TemplateArgumentLoc *getTemplateArgs() {
407474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org    return reinterpret_cast<TemplateArgumentLoc *> (this + 1);
408474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  }
409474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org
410474eb7536515fb785e925cc9375d22817c416851hclam@chromium.org  /// \brief Retrieve the template arguments
411  const TemplateArgumentLoc *getTemplateArgs() const {
412    return reinterpret_cast<const TemplateArgumentLoc *> (this + 1);
413  }
414
415  void initializeFrom(const TemplateArgumentListInfo &List);
416  void copyInto(TemplateArgumentListInfo &List) const;
417  static std::size_t sizeFor(const TemplateArgumentListInfo &List);
418};
419
420/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
421/// enum, etc.
422class DeclRefExpr : public Expr {
423  enum {
424    // Flag on DecoratedD that specifies when this declaration reference
425    // expression has a C++ nested-name-specifier.
426    HasQualifierFlag = 0x01,
427    // Flag on DecoratedD that specifies when this declaration reference
428    // expression has an explicit C++ template argument list.
429    HasExplicitTemplateArgumentListFlag = 0x02
430  };
431
432  // DecoratedD - The declaration that we are referencing, plus two bits to
433  // indicate whether (1) the declaration's name was explicitly qualified and
434  // (2) the declaration's name was followed by an explicit template
435  // argument list.
436  llvm::PointerIntPair<ValueDecl *, 2> DecoratedD;
437
438  // Loc - The location of the declaration name itself.
439  SourceLocation Loc;
440
441  /// \brief Retrieve the qualifier that preceded the declaration name, if any.
442  NameQualifier *getNameQualifier() {
443    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
444      return 0;
445
446    return reinterpret_cast<NameQualifier *> (this + 1);
447  }
448
449  /// \brief Retrieve the qualifier that preceded the member name, if any.
450  const NameQualifier *getNameQualifier() const {
451    return const_cast<DeclRefExpr *>(this)->getNameQualifier();
452  }
453
454  /// \brief Retrieve the explicit template argument list that followed the
455  /// member template name, if any.
456  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
457    if ((DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag) == 0)
458      return 0;
459
460    if ((DecoratedD.getInt() & HasQualifierFlag) == 0)
461      return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
462
463    return reinterpret_cast<ExplicitTemplateArgumentList *>(
464                                                      getNameQualifier() + 1);
465  }
466
467  /// \brief Retrieve the explicit template argument list that followed the
468  /// member template name, if any.
469  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
470    return const_cast<DeclRefExpr *>(this)->getExplicitTemplateArgumentList();
471  }
472
473  DeclRefExpr(NestedNameSpecifier *Qualifier, SourceRange QualifierRange,
474              ValueDecl *D, SourceLocation NameLoc,
475              const TemplateArgumentListInfo *TemplateArgs,
476              QualType T);
477
478protected:
479  /// \brief Computes the type- and value-dependence flags for this
480  /// declaration reference expression.
481  void computeDependence();
482
483  DeclRefExpr(StmtClass SC, ValueDecl *d, QualType t, SourceLocation l) :
484    Expr(SC, t, false, false), DecoratedD(d, 0), Loc(l) {
485    computeDependence();
486  }
487
488public:
489  DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) :
490    Expr(DeclRefExprClass, t, false, false), DecoratedD(d, 0), Loc(l) {
491    computeDependence();
492  }
493
494  /// \brief Construct an empty declaration reference expression.
495  explicit DeclRefExpr(EmptyShell Empty)
496    : Expr(DeclRefExprClass, Empty) { }
497
498  static DeclRefExpr *Create(ASTContext &Context,
499                             NestedNameSpecifier *Qualifier,
500                             SourceRange QualifierRange,
501                             ValueDecl *D,
502                             SourceLocation NameLoc,
503                             QualType T,
504                             const TemplateArgumentListInfo *TemplateArgs = 0);
505
506  ValueDecl *getDecl() { return DecoratedD.getPointer(); }
507  const ValueDecl *getDecl() const { return DecoratedD.getPointer(); }
508  void setDecl(ValueDecl *NewD) { DecoratedD.setPointer(NewD); }
509
510  SourceLocation getLocation() const { return Loc; }
511  void setLocation(SourceLocation L) { Loc = L; }
512  virtual SourceRange getSourceRange() const;
513
514  /// \brief Determine whether this declaration reference was preceded by a
515  /// C++ nested-name-specifier, e.g., \c N::foo.
516  bool hasQualifier() const { return DecoratedD.getInt() & HasQualifierFlag; }
517
518  /// \brief If the name was qualified, retrieves the source range of
519  /// the nested-name-specifier that precedes the name. Otherwise,
520  /// returns an empty source range.
521  SourceRange getQualifierRange() const {
522    if (!hasQualifier())
523      return SourceRange();
524
525    return getNameQualifier()->Range;
526  }
527
528  /// \brief If the name was qualified, retrieves the nested-name-specifier
529  /// that precedes the name. Otherwise, returns NULL.
530  NestedNameSpecifier *getQualifier() const {
531    if (!hasQualifier())
532      return 0;
533
534    return getNameQualifier()->NNS;
535  }
536
537  /// \brief Determines whether this member expression actually had a C++
538  /// template argument list explicitly specified, e.g., x.f<int>.
539  bool hasExplicitTemplateArgumentList() const {
540    return DecoratedD.getInt() & HasExplicitTemplateArgumentListFlag;
541  }
542
543  /// \brief Copies the template arguments (if present) into the given
544  /// structure.
545  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
546    if (hasExplicitTemplateArgumentList())
547      getExplicitTemplateArgumentList()->copyInto(List);
548  }
549
550  /// \brief Retrieve the location of the left angle bracket following the
551  /// member name ('<'), if any.
552  SourceLocation getLAngleLoc() const {
553    if (!hasExplicitTemplateArgumentList())
554      return SourceLocation();
555
556    return getExplicitTemplateArgumentList()->LAngleLoc;
557  }
558
559  /// \brief Retrieve the template arguments provided as part of this
560  /// template-id.
561  const TemplateArgumentLoc *getTemplateArgs() const {
562    if (!hasExplicitTemplateArgumentList())
563      return 0;
564
565    return getExplicitTemplateArgumentList()->getTemplateArgs();
566  }
567
568  /// \brief Retrieve the number of template arguments provided as part of this
569  /// template-id.
570  unsigned getNumTemplateArgs() const {
571    if (!hasExplicitTemplateArgumentList())
572      return 0;
573
574    return getExplicitTemplateArgumentList()->NumTemplateArgs;
575  }
576
577  /// \brief Retrieve the location of the right angle bracket following the
578  /// template arguments ('>').
579  SourceLocation getRAngleLoc() const {
580    if (!hasExplicitTemplateArgumentList())
581      return SourceLocation();
582
583    return getExplicitTemplateArgumentList()->RAngleLoc;
584  }
585
586  static bool classof(const Stmt *T) {
587    return T->getStmtClass() == DeclRefExprClass;
588  }
589  static bool classof(const DeclRefExpr *) { return true; }
590
591  // Iterators
592  virtual child_iterator child_begin();
593  virtual child_iterator child_end();
594};
595
596/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
597class PredefinedExpr : public Expr {
598public:
599  enum IdentType {
600    Func,
601    Function,
602    PrettyFunction,
603    /// PrettyFunctionNoVirtual - The same as PrettyFunction, except that the
604    /// 'virtual' keyword is omitted for virtual member functions.
605    PrettyFunctionNoVirtual
606  };
607
608private:
609  SourceLocation Loc;
610  IdentType Type;
611public:
612  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
613    : Expr(PredefinedExprClass, type, type->isDependentType(),
614           type->isDependentType()), Loc(l), Type(IT) {}
615
616  /// \brief Construct an empty predefined expression.
617  explicit PredefinedExpr(EmptyShell Empty)
618    : Expr(PredefinedExprClass, Empty) { }
619
620  IdentType getIdentType() const { return Type; }
621  void setIdentType(IdentType IT) { Type = IT; }
622
623  SourceLocation getLocation() const { return Loc; }
624  void setLocation(SourceLocation L) { Loc = L; }
625
626  static std::string ComputeName(IdentType IT, const Decl *CurrentDecl);
627
628  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
629
630  static bool classof(const Stmt *T) {
631    return T->getStmtClass() == PredefinedExprClass;
632  }
633  static bool classof(const PredefinedExpr *) { return true; }
634
635  // Iterators
636  virtual child_iterator child_begin();
637  virtual child_iterator child_end();
638};
639
640class IntegerLiteral : public Expr {
641  llvm::APInt Value;
642  SourceLocation Loc;
643public:
644  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
645  // or UnsignedLongLongTy
646  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
647    : Expr(IntegerLiteralClass, type, false, false), Value(V), Loc(l) {
648    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
649  }
650
651  /// \brief Construct an empty integer literal.
652  explicit IntegerLiteral(EmptyShell Empty)
653    : Expr(IntegerLiteralClass, Empty) { }
654
655  const llvm::APInt &getValue() const { return Value; }
656  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
657
658  /// \brief Retrieve the location of the literal.
659  SourceLocation getLocation() const { return Loc; }
660
661  void setValue(const llvm::APInt &Val) { Value = Val; }
662  void setLocation(SourceLocation Location) { Loc = Location; }
663
664  static bool classof(const Stmt *T) {
665    return T->getStmtClass() == IntegerLiteralClass;
666  }
667  static bool classof(const IntegerLiteral *) { return true; }
668
669  // Iterators
670  virtual child_iterator child_begin();
671  virtual child_iterator child_end();
672};
673
674class CharacterLiteral : public Expr {
675  unsigned Value;
676  SourceLocation Loc;
677  bool IsWide;
678public:
679  // type should be IntTy
680  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
681    : Expr(CharacterLiteralClass, type, false, false), Value(value), Loc(l),
682      IsWide(iswide) {
683  }
684
685  /// \brief Construct an empty character literal.
686  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
687
688  SourceLocation getLocation() const { return Loc; }
689  bool isWide() const { return IsWide; }
690
691  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
692
693  unsigned getValue() const { return Value; }
694
695  void setLocation(SourceLocation Location) { Loc = Location; }
696  void setWide(bool W) { IsWide = W; }
697  void setValue(unsigned Val) { Value = Val; }
698
699  static bool classof(const Stmt *T) {
700    return T->getStmtClass() == CharacterLiteralClass;
701  }
702  static bool classof(const CharacterLiteral *) { return true; }
703
704  // Iterators
705  virtual child_iterator child_begin();
706  virtual child_iterator child_end();
707};
708
709class FloatingLiteral : public Expr {
710  llvm::APFloat Value;
711  bool IsExact : 1;
712  SourceLocation Loc;
713public:
714  FloatingLiteral(const llvm::APFloat &V, bool isexact,
715                  QualType Type, SourceLocation L)
716    : Expr(FloatingLiteralClass, Type, false, false), Value(V),
717      IsExact(isexact), Loc(L) {}
718
719  /// \brief Construct an empty floating-point literal.
720  explicit FloatingLiteral(EmptyShell Empty)
721    : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
722
723  const llvm::APFloat &getValue() const { return Value; }
724  void setValue(const llvm::APFloat &Val) { Value = Val; }
725
726  bool isExact() const { return IsExact; }
727  void setExact(bool E) { IsExact = E; }
728
729  /// getValueAsApproximateDouble - This returns the value as an inaccurate
730  /// double.  Note that this may cause loss of precision, but is useful for
731  /// debugging dumps, etc.
732  double getValueAsApproximateDouble() const;
733
734  SourceLocation getLocation() const { return Loc; }
735  void setLocation(SourceLocation L) { Loc = L; }
736
737  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
738
739  static bool classof(const Stmt *T) {
740    return T->getStmtClass() == FloatingLiteralClass;
741  }
742  static bool classof(const FloatingLiteral *) { return true; }
743
744  // Iterators
745  virtual child_iterator child_begin();
746  virtual child_iterator child_end();
747};
748
749/// ImaginaryLiteral - We support imaginary integer and floating point literals,
750/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
751/// IntegerLiteral classes.  Instances of this class always have a Complex type
752/// whose element type matches the subexpression.
753///
754class ImaginaryLiteral : public Expr {
755  Stmt *Val;
756public:
757  ImaginaryLiteral(Expr *val, QualType Ty)
758    : Expr(ImaginaryLiteralClass, Ty, false, false), Val(val) {}
759
760  /// \brief Build an empty imaginary literal.
761  explicit ImaginaryLiteral(EmptyShell Empty)
762    : Expr(ImaginaryLiteralClass, Empty) { }
763
764  const Expr *getSubExpr() const { return cast<Expr>(Val); }
765  Expr *getSubExpr() { return cast<Expr>(Val); }
766  void setSubExpr(Expr *E) { Val = E; }
767
768  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
769  static bool classof(const Stmt *T) {
770    return T->getStmtClass() == ImaginaryLiteralClass;
771  }
772  static bool classof(const ImaginaryLiteral *) { return true; }
773
774  // Iterators
775  virtual child_iterator child_begin();
776  virtual child_iterator child_end();
777};
778
779/// StringLiteral - This represents a string literal expression, e.g. "foo"
780/// or L"bar" (wide strings).  The actual string is returned by getStrData()
781/// is NOT null-terminated, and the length of the string is determined by
782/// calling getByteLength().  The C type for a string is always a
783/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
784/// not.
785///
786/// Note that strings in C can be formed by concatenation of multiple string
787/// literal pptokens in translation phase #6.  This keeps track of the locations
788/// of each of these pieces.
789///
790/// Strings in C can also be truncated and extended by assigning into arrays,
791/// e.g. with constructs like:
792///   char X[2] = "foobar";
793/// In this case, getByteLength() will return 6, but the string literal will
794/// have type "char[2]".
795class StringLiteral : public Expr {
796  const char *StrData;
797  unsigned ByteLength;
798  bool IsWide;
799  unsigned NumConcatenated;
800  SourceLocation TokLocs[1];
801
802  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty, false, false) {}
803
804protected:
805  virtual void DoDestroy(ASTContext &C);
806
807public:
808  /// This is the "fully general" constructor that allows representation of
809  /// strings formed from multiple concatenated tokens.
810  static StringLiteral *Create(ASTContext &C, const char *StrData,
811                               unsigned ByteLength, bool Wide, QualType Ty,
812                               const SourceLocation *Loc, unsigned NumStrs);
813
814  /// Simple constructor for string literals made from one token.
815  static StringLiteral *Create(ASTContext &C, const char *StrData,
816                               unsigned ByteLength,
817                               bool Wide, QualType Ty, SourceLocation Loc) {
818    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
819  }
820
821  /// \brief Construct an empty string literal.
822  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
823
824  llvm::StringRef getString() const {
825    return llvm::StringRef(StrData, ByteLength);
826  }
827  // FIXME: These are deprecated, replace with StringRef.
828  const char *getStrData() const { return StrData; }
829  unsigned getByteLength() const { return ByteLength; }
830
831  /// \brief Sets the string data to the given string data.
832  void setString(ASTContext &C, llvm::StringRef Str);
833
834  bool isWide() const { return IsWide; }
835  void setWide(bool W) { IsWide = W; }
836
837  bool containsNonAsciiOrNull() const {
838    llvm::StringRef Str = getString();
839    for (unsigned i = 0, e = Str.size(); i != e; ++i)
840      if (!isascii(Str[i]) || !Str[i])
841        return true;
842    return false;
843  }
844  /// getNumConcatenated - Get the number of string literal tokens that were
845  /// concatenated in translation phase #6 to form this string literal.
846  unsigned getNumConcatenated() const { return NumConcatenated; }
847
848  SourceLocation getStrTokenLoc(unsigned TokNum) const {
849    assert(TokNum < NumConcatenated && "Invalid tok number");
850    return TokLocs[TokNum];
851  }
852  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
853    assert(TokNum < NumConcatenated && "Invalid tok number");
854    TokLocs[TokNum] = L;
855  }
856
857  typedef const SourceLocation *tokloc_iterator;
858  tokloc_iterator tokloc_begin() const { return TokLocs; }
859  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
860
861  virtual SourceRange getSourceRange() const {
862    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
863  }
864  static bool classof(const Stmt *T) {
865    return T->getStmtClass() == StringLiteralClass;
866  }
867  static bool classof(const StringLiteral *) { return true; }
868
869  // Iterators
870  virtual child_iterator child_begin();
871  virtual child_iterator child_end();
872};
873
874/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
875/// AST node is only formed if full location information is requested.
876class ParenExpr : public Expr {
877  SourceLocation L, R;
878  Stmt *Val;
879public:
880  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
881    : Expr(ParenExprClass, val->getType(),
882           val->isTypeDependent(), val->isValueDependent()),
883      L(l), R(r), Val(val) {}
884
885  /// \brief Construct an empty parenthesized expression.
886  explicit ParenExpr(EmptyShell Empty)
887    : Expr(ParenExprClass, Empty) { }
888
889  const Expr *getSubExpr() const { return cast<Expr>(Val); }
890  Expr *getSubExpr() { return cast<Expr>(Val); }
891  void setSubExpr(Expr *E) { Val = E; }
892
893  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
894
895  /// \brief Get the location of the left parentheses '('.
896  SourceLocation getLParen() const { return L; }
897  void setLParen(SourceLocation Loc) { L = Loc; }
898
899  /// \brief Get the location of the right parentheses ')'.
900  SourceLocation getRParen() const { return R; }
901  void setRParen(SourceLocation Loc) { R = Loc; }
902
903  static bool classof(const Stmt *T) {
904    return T->getStmtClass() == ParenExprClass;
905  }
906  static bool classof(const ParenExpr *) { return true; }
907
908  // Iterators
909  virtual child_iterator child_begin();
910  virtual child_iterator child_end();
911};
912
913
914/// UnaryOperator - This represents the unary-expression's (except sizeof and
915/// alignof), the postinc/postdec operators from postfix-expression, and various
916/// extensions.
917///
918/// Notes on various nodes:
919///
920/// Real/Imag - These return the real/imag part of a complex operand.  If
921///   applied to a non-complex value, the former returns its operand and the
922///   later returns zero in the type of the operand.
923///
924/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
925///   subexpression is a compound literal with the various MemberExpr and
926///   ArraySubscriptExpr's applied to it. (This is only used in C)
927///
928class UnaryOperator : public Expr {
929public:
930  // Note that additions to this should also update the StmtVisitor class.
931  enum Opcode {
932    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
933    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
934    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
935    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
936    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
937    Real, Imag,       // "__real expr"/"__imag expr" Extension.
938    Extension,        // __extension__ marker.
939    OffsetOf          // __builtin_offsetof
940  };
941private:
942  Stmt *Val;
943  Opcode Opc;
944  SourceLocation Loc;
945public:
946
947  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
948    : Expr(UnaryOperatorClass, type,
949           input->isTypeDependent() && opc != OffsetOf,
950           input->isValueDependent()),
951      Val(input), Opc(opc), Loc(l) {}
952
953  /// \brief Build an empty unary operator.
954  explicit UnaryOperator(EmptyShell Empty)
955    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
956
957  Opcode getOpcode() const { return Opc; }
958  void setOpcode(Opcode O) { Opc = O; }
959
960  Expr *getSubExpr() const { return cast<Expr>(Val); }
961  void setSubExpr(Expr *E) { Val = E; }
962
963  /// getOperatorLoc - Return the location of the operator.
964  SourceLocation getOperatorLoc() const { return Loc; }
965  void setOperatorLoc(SourceLocation L) { Loc = L; }
966
967  /// isPostfix - Return true if this is a postfix operation, like x++.
968  static bool isPostfix(Opcode Op) {
969    return Op == PostInc || Op == PostDec;
970  }
971
972  /// isPostfix - Return true if this is a prefix operation, like --x.
973  static bool isPrefix(Opcode Op) {
974    return Op == PreInc || Op == PreDec;
975  }
976
977  bool isPrefix() const { return isPrefix(Opc); }
978  bool isPostfix() const { return isPostfix(Opc); }
979  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
980  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
981  bool isOffsetOfOp() const { return Opc == OffsetOf; }
982  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
983  bool isArithmeticOp() const { return isArithmeticOp(Opc); }
984
985  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
986  /// corresponds to, e.g. "sizeof" or "[pre]++"
987  static const char *getOpcodeStr(Opcode Op);
988
989  /// \brief Retrieve the unary opcode that corresponds to the given
990  /// overloaded operator.
991  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
992
993  /// \brief Retrieve the overloaded operator kind that corresponds to
994  /// the given unary opcode.
995  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
996
997  virtual SourceRange getSourceRange() const {
998    if (isPostfix())
999      return SourceRange(Val->getLocStart(), Loc);
1000    else
1001      return SourceRange(Loc, Val->getLocEnd());
1002  }
1003  virtual SourceLocation getExprLoc() const { return Loc; }
1004
1005  static bool classof(const Stmt *T) {
1006    return T->getStmtClass() == UnaryOperatorClass;
1007  }
1008  static bool classof(const UnaryOperator *) { return true; }
1009
1010  // Iterators
1011  virtual child_iterator child_begin();
1012  virtual child_iterator child_end();
1013};
1014
1015/// OffsetOfExpr - [C99 7.17] - This represents an expression of the form
1016/// offsetof(record-type, member-designator). For example, given:
1017/// @code
1018/// struct S {
1019///   float f;
1020///   double d;
1021/// };
1022/// struct T {
1023///   int i;
1024///   struct S s[10];
1025/// };
1026/// @endcode
1027/// we can represent and evaluate the expression @c offsetof(struct T, s[2].d).
1028
1029class OffsetOfExpr : public Expr {
1030public:
1031  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
1032  class OffsetOfNode {
1033  public:
1034    /// \brief The kind of offsetof node we have.
1035    enum Kind {
1036      /// \brief An index into an array.
1037      Array = 0x00,
1038      /// \brief A field.
1039      Field = 0x01,
1040      /// \brief A field in a dependent type, known only by its name.
1041      Identifier = 0x02,
1042      /// \brief An implicit indirection through a C++ base class, when the
1043      /// field found is in a base class.
1044      Base = 0x03
1045    };
1046
1047  private:
1048    enum { MaskBits = 2, Mask = 0x03 };
1049
1050    /// \brief The source range that covers this part of the designator.
1051    SourceRange Range;
1052
1053    /// \brief The data describing the designator, which comes in three
1054    /// different forms, depending on the lower two bits.
1055    ///   - An unsigned index into the array of Expr*'s stored after this node
1056    ///     in memory, for [constant-expression] designators.
1057    ///   - A FieldDecl*, for references to a known field.
1058    ///   - An IdentifierInfo*, for references to a field with a given name
1059    ///     when the class type is dependent.
1060    ///   - A CXXBaseSpecifier*, for references that look at a field in a
1061    ///     base class.
1062    uintptr_t Data;
1063
1064  public:
1065    /// \brief Create an offsetof node that refers to an array element.
1066    OffsetOfNode(SourceLocation LBracketLoc, unsigned Index,
1067                 SourceLocation RBracketLoc)
1068      : Range(LBracketLoc, RBracketLoc), Data((Index << 2) | Array) { }
1069
1070    /// \brief Create an offsetof node that refers to a field.
1071    OffsetOfNode(SourceLocation DotLoc, FieldDecl *Field,
1072                 SourceLocation NameLoc)
1073      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
1074        Data(reinterpret_cast<uintptr_t>(Field) | OffsetOfNode::Field) { }
1075
1076    /// \brief Create an offsetof node that refers to an identifier.
1077    OffsetOfNode(SourceLocation DotLoc, IdentifierInfo *Name,
1078                 SourceLocation NameLoc)
1079      : Range(DotLoc.isValid()? DotLoc : NameLoc, NameLoc),
1080        Data(reinterpret_cast<uintptr_t>(Name) | Identifier) { }
1081
1082    /// \brief Create an offsetof node that refers into a C++ base class.
1083    explicit OffsetOfNode(const CXXBaseSpecifier *Base)
1084      : Range(), Data(reinterpret_cast<uintptr_t>(Base) | OffsetOfNode::Base) {}
1085
1086    /// \brief Determine what kind of offsetof node this is.
1087    Kind getKind() const {
1088      return static_cast<Kind>(Data & Mask);
1089    }
1090
1091    /// \brief For an array element node, returns the index into the array
1092    /// of expressions.
1093    unsigned getArrayExprIndex() const {
1094      assert(getKind() == Array);
1095      return Data >> 2;
1096    }
1097
1098    /// \brief For a field offsetof node, returns the field.
1099    FieldDecl *getField() const {
1100      assert(getKind() == Field);
1101      return reinterpret_cast<FieldDecl *>(Data & ~(uintptr_t)Mask);
1102    }
1103
1104    /// \brief For a field or identifier offsetof node, returns the name of
1105    /// the field.
1106    IdentifierInfo *getFieldName() const;
1107
1108    /// \brief For a base class node, returns the base specifier.
1109    CXXBaseSpecifier *getBase() const {
1110      assert(getKind() == Base);
1111      return reinterpret_cast<CXXBaseSpecifier *>(Data & ~(uintptr_t)Mask);
1112    }
1113
1114    /// \brief Retrieve the source range that covers this offsetof node.
1115    ///
1116    /// For an array element node, the source range contains the locations of
1117    /// the square brackets. For a field or identifier node, the source range
1118    /// contains the location of the period (if there is one) and the
1119    /// identifier.
1120    SourceRange getRange() const { return Range; }
1121  };
1122
1123private:
1124
1125  SourceLocation OperatorLoc, RParenLoc;
1126  // Base type;
1127  TypeSourceInfo *TSInfo;
1128  // Number of sub-components (i.e. instances of OffsetOfNode).
1129  unsigned NumComps;
1130  // Number of sub-expressions (i.e. array subscript expressions).
1131  unsigned NumExprs;
1132
1133  OffsetOfExpr(ASTContext &C, QualType type,
1134               SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1135               OffsetOfNode* compsPtr, unsigned numComps,
1136               Expr** exprsPtr, unsigned numExprs,
1137               SourceLocation RParenLoc);
1138
1139  explicit OffsetOfExpr(unsigned numComps, unsigned numExprs)
1140    : Expr(OffsetOfExprClass, EmptyShell()),
1141      TSInfo(0), NumComps(numComps), NumExprs(numExprs) {}
1142
1143public:
1144
1145  static OffsetOfExpr *Create(ASTContext &C, QualType type,
1146                              SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1147                              OffsetOfNode* compsPtr, unsigned numComps,
1148                              Expr** exprsPtr, unsigned numExprs,
1149                              SourceLocation RParenLoc);
1150
1151  static OffsetOfExpr *CreateEmpty(ASTContext &C,
1152                                   unsigned NumComps, unsigned NumExprs);
1153
1154  /// getOperatorLoc - Return the location of the operator.
1155  SourceLocation getOperatorLoc() const { return OperatorLoc; }
1156  void setOperatorLoc(SourceLocation L) { OperatorLoc = L; }
1157
1158  /// \brief Return the location of the right parentheses.
1159  SourceLocation getRParenLoc() const { return RParenLoc; }
1160  void setRParenLoc(SourceLocation R) { RParenLoc = R; }
1161
1162  TypeSourceInfo *getTypeSourceInfo() const {
1163    return TSInfo;
1164  }
1165  void setTypeSourceInfo(TypeSourceInfo *tsi) {
1166    TSInfo = tsi;
1167  }
1168
1169  const OffsetOfNode &getComponent(unsigned Idx) {
1170    assert(Idx < NumComps && "Subscript out of range");
1171    return reinterpret_cast<OffsetOfNode *> (this + 1)[Idx];
1172  }
1173
1174  void setComponent(unsigned Idx, OffsetOfNode ON) {
1175    assert(Idx < NumComps && "Subscript out of range");
1176    reinterpret_cast<OffsetOfNode *> (this + 1)[Idx] = ON;
1177  }
1178
1179  unsigned getNumComponents() const {
1180    return NumComps;
1181  }
1182
1183  Expr* getIndexExpr(unsigned Idx) {
1184    assert(Idx < NumExprs && "Subscript out of range");
1185    return reinterpret_cast<Expr **>(
1186                    reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx];
1187  }
1188
1189  void setIndexExpr(unsigned Idx, Expr* E) {
1190    assert(Idx < NumComps && "Subscript out of range");
1191    reinterpret_cast<Expr **>(
1192                reinterpret_cast<OffsetOfNode *>(this+1) + NumComps)[Idx] = E;
1193  }
1194
1195  unsigned getNumExpressions() const {
1196    return NumExprs;
1197  }
1198
1199  virtual SourceRange getSourceRange() const {
1200    return SourceRange(OperatorLoc, RParenLoc);
1201  }
1202
1203  static bool classof(const Stmt *T) {
1204    return T->getStmtClass() == OffsetOfExprClass;
1205  }
1206
1207  static bool classof(const OffsetOfExpr *) { return true; }
1208
1209  // Iterators
1210  virtual child_iterator child_begin();
1211  virtual child_iterator child_end();
1212};
1213
1214/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
1215/// types and expressions.
1216class SizeOfAlignOfExpr : public Expr {
1217  bool isSizeof : 1;  // true if sizeof, false if alignof.
1218  bool isType : 1;    // true if operand is a type, false if an expression
1219  union {
1220    TypeSourceInfo *Ty;
1221    Stmt *Ex;
1222  } Argument;
1223  SourceLocation OpLoc, RParenLoc;
1224
1225protected:
1226  virtual void DoDestroy(ASTContext& C);
1227
1228public:
1229  SizeOfAlignOfExpr(bool issizeof, TypeSourceInfo *TInfo,
1230                    QualType resultType, SourceLocation op,
1231                    SourceLocation rp) :
1232      Expr(SizeOfAlignOfExprClass, resultType,
1233           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1234           // Value-dependent if the argument is type-dependent.
1235           TInfo->getType()->isDependentType()),
1236      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
1237    Argument.Ty = TInfo;
1238  }
1239
1240  SizeOfAlignOfExpr(bool issizeof, Expr *E,
1241                    QualType resultType, SourceLocation op,
1242                    SourceLocation rp) :
1243      Expr(SizeOfAlignOfExprClass, resultType,
1244           false, // Never type-dependent (C++ [temp.dep.expr]p3).
1245           // Value-dependent if the argument is type-dependent.
1246           E->isTypeDependent()),
1247      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
1248    Argument.Ex = E;
1249  }
1250
1251  /// \brief Construct an empty sizeof/alignof expression.
1252  explicit SizeOfAlignOfExpr(EmptyShell Empty)
1253    : Expr(SizeOfAlignOfExprClass, Empty) { }
1254
1255  bool isSizeOf() const { return isSizeof; }
1256  void setSizeof(bool S) { isSizeof = S; }
1257
1258  bool isArgumentType() const { return isType; }
1259  QualType getArgumentType() const {
1260    return getArgumentTypeInfo()->getType();
1261  }
1262  TypeSourceInfo *getArgumentTypeInfo() const {
1263    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
1264    return Argument.Ty;
1265  }
1266  Expr *getArgumentExpr() {
1267    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
1268    return static_cast<Expr*>(Argument.Ex);
1269  }
1270  const Expr *getArgumentExpr() const {
1271    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
1272  }
1273
1274  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
1275  void setArgument(TypeSourceInfo *TInfo) {
1276    Argument.Ty = TInfo;
1277    isType = true;
1278  }
1279
1280  /// Gets the argument type, or the type of the argument expression, whichever
1281  /// is appropriate.
1282  QualType getTypeOfArgument() const {
1283    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
1284  }
1285
1286  SourceLocation getOperatorLoc() const { return OpLoc; }
1287  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1288
1289  SourceLocation getRParenLoc() const { return RParenLoc; }
1290  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1291
1292  virtual SourceRange getSourceRange() const {
1293    return SourceRange(OpLoc, RParenLoc);
1294  }
1295
1296  static bool classof(const Stmt *T) {
1297    return T->getStmtClass() == SizeOfAlignOfExprClass;
1298  }
1299  static bool classof(const SizeOfAlignOfExpr *) { return true; }
1300
1301  // Iterators
1302  virtual child_iterator child_begin();
1303  virtual child_iterator child_end();
1304};
1305
1306//===----------------------------------------------------------------------===//
1307// Postfix Operators.
1308//===----------------------------------------------------------------------===//
1309
1310/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
1311class ArraySubscriptExpr : public Expr {
1312  enum { LHS, RHS, END_EXPR=2 };
1313  Stmt* SubExprs[END_EXPR];
1314  SourceLocation RBracketLoc;
1315public:
1316  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
1317                     SourceLocation rbracketloc)
1318  : Expr(ArraySubscriptExprClass, t,
1319         lhs->isTypeDependent() || rhs->isTypeDependent(),
1320         lhs->isValueDependent() || rhs->isValueDependent()),
1321    RBracketLoc(rbracketloc) {
1322    SubExprs[LHS] = lhs;
1323    SubExprs[RHS] = rhs;
1324  }
1325
1326  /// \brief Create an empty array subscript expression.
1327  explicit ArraySubscriptExpr(EmptyShell Shell)
1328    : Expr(ArraySubscriptExprClass, Shell) { }
1329
1330  /// An array access can be written A[4] or 4[A] (both are equivalent).
1331  /// - getBase() and getIdx() always present the normalized view: A[4].
1332  ///    In this case getBase() returns "A" and getIdx() returns "4".
1333  /// - getLHS() and getRHS() present the syntactic view. e.g. for
1334  ///    4[A] getLHS() returns "4".
1335  /// Note: Because vector element access is also written A[4] we must
1336  /// predicate the format conversion in getBase and getIdx only on the
1337  /// the type of the RHS, as it is possible for the LHS to be a vector of
1338  /// integer type
1339  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
1340  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1341  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1342
1343  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
1344  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1345  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1346
1347  Expr *getBase() {
1348    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1349  }
1350
1351  const Expr *getBase() const {
1352    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
1353  }
1354
1355  Expr *getIdx() {
1356    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
1357  }
1358
1359  const Expr *getIdx() const {
1360    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
1361  }
1362
1363  virtual SourceRange getSourceRange() const {
1364    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
1365  }
1366
1367  SourceLocation getRBracketLoc() const { return RBracketLoc; }
1368  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
1369
1370  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
1371
1372  static bool classof(const Stmt *T) {
1373    return T->getStmtClass() == ArraySubscriptExprClass;
1374  }
1375  static bool classof(const ArraySubscriptExpr *) { return true; }
1376
1377  // Iterators
1378  virtual child_iterator child_begin();
1379  virtual child_iterator child_end();
1380};
1381
1382
1383/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
1384/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
1385/// while its subclasses may represent alternative syntax that (semantically)
1386/// results in a function call. For example, CXXOperatorCallExpr is
1387/// a subclass for overloaded operator calls that use operator syntax, e.g.,
1388/// "str1 + str2" to resolve to a function call.
1389class CallExpr : public Expr {
1390  enum { FN=0, ARGS_START=1 };
1391  Stmt **SubExprs;
1392  unsigned NumArgs;
1393  SourceLocation RParenLoc;
1394
1395protected:
1396  // This version of the constructor is for derived classes.
1397  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
1398           QualType t, SourceLocation rparenloc);
1399
1400  virtual void DoDestroy(ASTContext& C);
1401
1402public:
1403  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
1404           SourceLocation rparenloc);
1405
1406  /// \brief Build an empty call expression.
1407  CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty);
1408
1409  ~CallExpr() {}
1410
1411  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
1412  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
1413  void setCallee(Expr *F) { SubExprs[FN] = F; }
1414
1415  Decl *getCalleeDecl();
1416  const Decl *getCalleeDecl() const {
1417    return const_cast<CallExpr*>(this)->getCalleeDecl();
1418  }
1419
1420  /// \brief If the callee is a FunctionDecl, return it. Otherwise return 0.
1421  FunctionDecl *getDirectCallee();
1422  const FunctionDecl *getDirectCallee() const {
1423    return const_cast<CallExpr*>(this)->getDirectCallee();
1424  }
1425
1426  /// getNumArgs - Return the number of actual arguments to this call.
1427  ///
1428  unsigned getNumArgs() const { return NumArgs; }
1429
1430  /// getArg - Return the specified argument.
1431  Expr *getArg(unsigned Arg) {
1432    assert(Arg < NumArgs && "Arg access out of range!");
1433    return cast<Expr>(SubExprs[Arg+ARGS_START]);
1434  }
1435  const Expr *getArg(unsigned Arg) const {
1436    assert(Arg < NumArgs && "Arg access out of range!");
1437    return cast<Expr>(SubExprs[Arg+ARGS_START]);
1438  }
1439
1440  /// setArg - Set the specified argument.
1441  void setArg(unsigned Arg, Expr *ArgExpr) {
1442    assert(Arg < NumArgs && "Arg access out of range!");
1443    SubExprs[Arg+ARGS_START] = ArgExpr;
1444  }
1445
1446  /// setNumArgs - This changes the number of arguments present in this call.
1447  /// Any orphaned expressions are deleted by this, and any new operands are set
1448  /// to null.
1449  void setNumArgs(ASTContext& C, unsigned NumArgs);
1450
1451  typedef ExprIterator arg_iterator;
1452  typedef ConstExprIterator const_arg_iterator;
1453
1454  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
1455  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
1456  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
1457  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
1458
1459  /// getNumCommas - Return the number of commas that must have been present in
1460  /// this function call.
1461  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
1462
1463  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
1464  /// not, return 0.
1465  unsigned isBuiltinCall(ASTContext &Context) const;
1466
1467  /// getCallReturnType - Get the return type of the call expr. This is not
1468  /// always the type of the expr itself, if the return type is a reference
1469  /// type.
1470  QualType getCallReturnType() const;
1471
1472  SourceLocation getRParenLoc() const { return RParenLoc; }
1473  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1474
1475  virtual SourceRange getSourceRange() const {
1476    return SourceRange(getCallee()->getLocStart(), RParenLoc);
1477  }
1478
1479  static bool classof(const Stmt *T) {
1480    return T->getStmtClass() >= firstCallExprConstant &&
1481           T->getStmtClass() <= lastCallExprConstant;
1482  }
1483  static bool classof(const CallExpr *) { return true; }
1484
1485  // Iterators
1486  virtual child_iterator child_begin();
1487  virtual child_iterator child_end();
1488};
1489
1490/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
1491///
1492class MemberExpr : public Expr {
1493  /// Extra data stored in some member expressions.
1494  struct MemberNameQualifier : public NameQualifier {
1495    DeclAccessPair FoundDecl;
1496  };
1497
1498  /// Base - the expression for the base pointer or structure references.  In
1499  /// X.F, this is "X".
1500  Stmt *Base;
1501
1502  /// MemberDecl - This is the decl being referenced by the field/member name.
1503  /// In X.F, this is the decl referenced by F.
1504  ValueDecl *MemberDecl;
1505
1506  /// MemberLoc - This is the location of the member name.
1507  SourceLocation MemberLoc;
1508
1509  /// IsArrow - True if this is "X->F", false if this is "X.F".
1510  bool IsArrow : 1;
1511
1512  /// \brief True if this member expression used a nested-name-specifier to
1513  /// refer to the member, e.g., "x->Base::f", or found its member via a using
1514  /// declaration.  When true, a MemberNameQualifier
1515  /// structure is allocated immediately after the MemberExpr.
1516  bool HasQualifierOrFoundDecl : 1;
1517
1518  /// \brief True if this member expression specified a template argument list
1519  /// explicitly, e.g., x->f<int>. When true, an ExplicitTemplateArgumentList
1520  /// structure (and its TemplateArguments) are allocated immediately after
1521  /// the MemberExpr or, if the member expression also has a qualifier, after
1522  /// the MemberNameQualifier structure.
1523  bool HasExplicitTemplateArgumentList : 1;
1524
1525  /// \brief Retrieve the qualifier that preceded the member name, if any.
1526  MemberNameQualifier *getMemberQualifier() {
1527    assert(HasQualifierOrFoundDecl);
1528    return reinterpret_cast<MemberNameQualifier *> (this + 1);
1529  }
1530
1531  /// \brief Retrieve the qualifier that preceded the member name, if any.
1532  const MemberNameQualifier *getMemberQualifier() const {
1533    return const_cast<MemberExpr *>(this)->getMemberQualifier();
1534  }
1535
1536  /// \brief Retrieve the explicit template argument list that followed the
1537  /// member template name, if any.
1538  ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() {
1539    if (!HasExplicitTemplateArgumentList)
1540      return 0;
1541
1542    if (!HasQualifierOrFoundDecl)
1543      return reinterpret_cast<ExplicitTemplateArgumentList *>(this + 1);
1544
1545    return reinterpret_cast<ExplicitTemplateArgumentList *>(
1546                                                      getMemberQualifier() + 1);
1547  }
1548
1549  /// \brief Retrieve the explicit template argument list that followed the
1550  /// member template name, if any.
1551  const ExplicitTemplateArgumentList *getExplicitTemplateArgumentList() const {
1552    return const_cast<MemberExpr *>(this)->getExplicitTemplateArgumentList();
1553  }
1554
1555public:
1556  MemberExpr(Expr *base, bool isarrow, ValueDecl *memberdecl,
1557             SourceLocation l, QualType ty)
1558    : Expr(MemberExprClass, ty,
1559           base->isTypeDependent(), base->isValueDependent()),
1560      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow),
1561      HasQualifierOrFoundDecl(false), HasExplicitTemplateArgumentList(false) {}
1562
1563  /// \brief Build an empty member reference expression.
1564  explicit MemberExpr(EmptyShell Empty)
1565    : Expr(MemberExprClass, Empty), HasQualifierOrFoundDecl(false),
1566      HasExplicitTemplateArgumentList(false) { }
1567
1568  static MemberExpr *Create(ASTContext &C, Expr *base, bool isarrow,
1569                            NestedNameSpecifier *qual, SourceRange qualrange,
1570                            ValueDecl *memberdecl, DeclAccessPair founddecl,
1571                            SourceLocation l,
1572                            const TemplateArgumentListInfo *targs,
1573                            QualType ty);
1574
1575  void setBase(Expr *E) { Base = E; }
1576  Expr *getBase() const { return cast<Expr>(Base); }
1577
1578  /// \brief Retrieve the member declaration to which this expression refers.
1579  ///
1580  /// The returned declaration will either be a FieldDecl or (in C++)
1581  /// a CXXMethodDecl.
1582  ValueDecl *getMemberDecl() const { return MemberDecl; }
1583  void setMemberDecl(ValueDecl *D) { MemberDecl = D; }
1584
1585  /// \brief Retrieves the declaration found by lookup.
1586  DeclAccessPair getFoundDecl() const {
1587    if (!HasQualifierOrFoundDecl)
1588      return DeclAccessPair::make(getMemberDecl(),
1589                                  getMemberDecl()->getAccess());
1590    return getMemberQualifier()->FoundDecl;
1591  }
1592
1593  /// \brief Determines whether this member expression actually had
1594  /// a C++ nested-name-specifier prior to the name of the member, e.g.,
1595  /// x->Base::foo.
1596  bool hasQualifier() const { return getQualifier() != 0; }
1597
1598  /// \brief If the member name was qualified, retrieves the source range of
1599  /// the nested-name-specifier that precedes the member name. Otherwise,
1600  /// returns an empty source range.
1601  SourceRange getQualifierRange() const {
1602    if (!HasQualifierOrFoundDecl)
1603      return SourceRange();
1604
1605    return getMemberQualifier()->Range;
1606  }
1607
1608  /// \brief If the member name was qualified, retrieves the
1609  /// nested-name-specifier that precedes the member name. Otherwise, returns
1610  /// NULL.
1611  NestedNameSpecifier *getQualifier() const {
1612    if (!HasQualifierOrFoundDecl)
1613      return 0;
1614
1615    return getMemberQualifier()->NNS;
1616  }
1617
1618  /// \brief Determines whether this member expression actually had a C++
1619  /// template argument list explicitly specified, e.g., x.f<int>.
1620  bool hasExplicitTemplateArgumentList() const {
1621    return HasExplicitTemplateArgumentList;
1622  }
1623
1624  /// \brief Copies the template arguments (if present) into the given
1625  /// structure.
1626  void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const {
1627    if (hasExplicitTemplateArgumentList())
1628      getExplicitTemplateArgumentList()->copyInto(List);
1629  }
1630
1631  /// \brief Retrieve the location of the left angle bracket following the
1632  /// member name ('<'), if any.
1633  SourceLocation getLAngleLoc() const {
1634    if (!HasExplicitTemplateArgumentList)
1635      return SourceLocation();
1636
1637    return getExplicitTemplateArgumentList()->LAngleLoc;
1638  }
1639
1640  /// \brief Retrieve the template arguments provided as part of this
1641  /// template-id.
1642  const TemplateArgumentLoc *getTemplateArgs() const {
1643    if (!HasExplicitTemplateArgumentList)
1644      return 0;
1645
1646    return getExplicitTemplateArgumentList()->getTemplateArgs();
1647  }
1648
1649  /// \brief Retrieve the number of template arguments provided as part of this
1650  /// template-id.
1651  unsigned getNumTemplateArgs() const {
1652    if (!HasExplicitTemplateArgumentList)
1653      return 0;
1654
1655    return getExplicitTemplateArgumentList()->NumTemplateArgs;
1656  }
1657
1658  /// \brief Retrieve the location of the right angle bracket following the
1659  /// template arguments ('>').
1660  SourceLocation getRAngleLoc() const {
1661    if (!HasExplicitTemplateArgumentList)
1662      return SourceLocation();
1663
1664    return getExplicitTemplateArgumentList()->RAngleLoc;
1665  }
1666
1667  bool isArrow() const { return IsArrow; }
1668  void setArrow(bool A) { IsArrow = A; }
1669
1670  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1671  /// location of 'F'.
1672  SourceLocation getMemberLoc() const { return MemberLoc; }
1673  void setMemberLoc(SourceLocation L) { MemberLoc = L; }
1674
1675  virtual SourceRange getSourceRange() const {
1676    // If we have an implicit base (like a C++ implicit this),
1677    // make sure not to return its location
1678    SourceLocation EndLoc = MemberLoc;
1679    if (HasExplicitTemplateArgumentList)
1680      EndLoc = getRAngleLoc();
1681
1682    SourceLocation BaseLoc = getBase()->getLocStart();
1683    if (BaseLoc.isInvalid())
1684      return SourceRange(MemberLoc, EndLoc);
1685    return SourceRange(BaseLoc, EndLoc);
1686  }
1687
1688  virtual SourceLocation getExprLoc() const { return MemberLoc; }
1689
1690  static bool classof(const Stmt *T) {
1691    return T->getStmtClass() == MemberExprClass;
1692  }
1693  static bool classof(const MemberExpr *) { return true; }
1694
1695  // Iterators
1696  virtual child_iterator child_begin();
1697  virtual child_iterator child_end();
1698};
1699
1700/// CompoundLiteralExpr - [C99 6.5.2.5]
1701///
1702class CompoundLiteralExpr : public Expr {
1703  /// LParenLoc - If non-null, this is the location of the left paren in a
1704  /// compound literal like "(int){4}".  This can be null if this is a
1705  /// synthesized compound expression.
1706  SourceLocation LParenLoc;
1707
1708  /// The type as written.  This can be an incomplete array type, in
1709  /// which case the actual expression type will be different.
1710  TypeSourceInfo *TInfo;
1711  Stmt *Init;
1712  bool FileScope;
1713public:
1714  // FIXME: Can compound literals be value-dependent?
1715  CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo,
1716                      QualType T, Expr *init, bool fileScope)
1717    : Expr(CompoundLiteralExprClass, T,
1718           tinfo->getType()->isDependentType(), false),
1719      LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {}
1720
1721  /// \brief Construct an empty compound literal.
1722  explicit CompoundLiteralExpr(EmptyShell Empty)
1723    : Expr(CompoundLiteralExprClass, Empty) { }
1724
1725  const Expr *getInitializer() const { return cast<Expr>(Init); }
1726  Expr *getInitializer() { return cast<Expr>(Init); }
1727  void setInitializer(Expr *E) { Init = E; }
1728
1729  bool isFileScope() const { return FileScope; }
1730  void setFileScope(bool FS) { FileScope = FS; }
1731
1732  SourceLocation getLParenLoc() const { return LParenLoc; }
1733  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1734
1735  TypeSourceInfo *getTypeSourceInfo() const { return TInfo; }
1736  void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; }
1737
1738  virtual SourceRange getSourceRange() const {
1739    // FIXME: Init should never be null.
1740    if (!Init)
1741      return SourceRange();
1742    if (LParenLoc.isInvalid())
1743      return Init->getSourceRange();
1744    return SourceRange(LParenLoc, Init->getLocEnd());
1745  }
1746
1747  static bool classof(const Stmt *T) {
1748    return T->getStmtClass() == CompoundLiteralExprClass;
1749  }
1750  static bool classof(const CompoundLiteralExpr *) { return true; }
1751
1752  // Iterators
1753  virtual child_iterator child_begin();
1754  virtual child_iterator child_end();
1755};
1756
1757/// CastExpr - Base class for type casts, including both implicit
1758/// casts (ImplicitCastExpr) and explicit casts that have some
1759/// representation in the source code (ExplicitCastExpr's derived
1760/// classes).
1761class CastExpr : public Expr {
1762public:
1763  /// CastKind - the kind of cast this represents.
1764  enum CastKind {
1765    /// CK_Unknown - Unknown cast kind.
1766    /// FIXME: The goal is to get rid of this and make all casts have a
1767    /// kind so that the AST client doesn't have to try to figure out what's
1768    /// going on.
1769    CK_Unknown,
1770
1771    /// CK_BitCast - Used for reinterpret_cast.
1772    CK_BitCast,
1773
1774    /// CK_NoOp - Used for const_cast.
1775    CK_NoOp,
1776
1777    /// CK_BaseToDerived - Base to derived class casts.
1778    CK_BaseToDerived,
1779
1780    /// CK_DerivedToBase - Derived to base class casts.
1781    CK_DerivedToBase,
1782
1783    /// CK_UncheckedDerivedToBase - Derived to base class casts that
1784    /// assume that the derived pointer is not null.
1785    CK_UncheckedDerivedToBase,
1786
1787    /// CK_Dynamic - Dynamic cast.
1788    CK_Dynamic,
1789
1790    /// CK_ToUnion - Cast to union (GCC extension).
1791    CK_ToUnion,
1792
1793    /// CK_ArrayToPointerDecay - Array to pointer decay.
1794    CK_ArrayToPointerDecay,
1795
1796    // CK_FunctionToPointerDecay - Function to pointer decay.
1797    CK_FunctionToPointerDecay,
1798
1799    /// CK_NullToMemberPointer - Null pointer to member pointer.
1800    CK_NullToMemberPointer,
1801
1802    /// CK_BaseToDerivedMemberPointer - Member pointer in base class to
1803    /// member pointer in derived class.
1804    CK_BaseToDerivedMemberPointer,
1805
1806    /// CK_DerivedToBaseMemberPointer - Member pointer in derived class to
1807    /// member pointer in base class.
1808    CK_DerivedToBaseMemberPointer,
1809
1810    /// CK_UserDefinedConversion - Conversion using a user defined type
1811    /// conversion function.
1812    CK_UserDefinedConversion,
1813
1814    /// CK_ConstructorConversion - Conversion by constructor
1815    CK_ConstructorConversion,
1816
1817    /// CK_IntegralToPointer - Integral to pointer
1818    CK_IntegralToPointer,
1819
1820    /// CK_PointerToIntegral - Pointer to integral
1821    CK_PointerToIntegral,
1822
1823    /// CK_ToVoid - Cast to void.
1824    CK_ToVoid,
1825
1826    /// CK_VectorSplat - Casting from an integer/floating type to an extended
1827    /// vector type with the same element type as the src type. Splats the
1828    /// src expression into the destination expression.
1829    CK_VectorSplat,
1830
1831    /// CK_IntegralCast - Casting between integral types of different size.
1832    CK_IntegralCast,
1833
1834    /// CK_IntegralToFloating - Integral to floating point.
1835    CK_IntegralToFloating,
1836
1837    /// CK_FloatingToIntegral - Floating point to integral.
1838    CK_FloatingToIntegral,
1839
1840    /// CK_FloatingCast - Casting between floating types of different size.
1841    CK_FloatingCast,
1842
1843    /// CK_MemberPointerToBoolean - Member pointer to boolean
1844    CK_MemberPointerToBoolean,
1845
1846    /// CK_AnyPointerToObjCPointerCast - Casting any pointer to objective-c
1847    /// pointer
1848    CK_AnyPointerToObjCPointerCast,
1849    /// CK_AnyPointerToBlockPointerCast - Casting any pointer to block
1850    /// pointer
1851    CK_AnyPointerToBlockPointerCast
1852
1853  };
1854
1855private:
1856  CastKind Kind;
1857  Stmt *Op;
1858
1859  /// BasePath - For derived-to-base and base-to-derived casts, the base array
1860  /// contains the inheritance path.
1861  CXXBaseSpecifierArray BasePath;
1862
1863  void CheckBasePath() const {
1864#ifndef NDEBUG
1865    switch (getCastKind()) {
1866    case CK_DerivedToBase:
1867    case CK_UncheckedDerivedToBase:
1868    case CK_DerivedToBaseMemberPointer:
1869    case CK_BaseToDerived:
1870    case CK_BaseToDerivedMemberPointer:
1871      assert(!BasePath.empty() && "Cast kind should have a base path!");
1872      break;
1873
1874    // These should not have an inheritance path.
1875    case CK_Unknown:
1876    case CK_BitCast:
1877    case CK_NoOp:
1878    case CK_Dynamic:
1879    case CK_ToUnion:
1880    case CK_ArrayToPointerDecay:
1881    case CK_FunctionToPointerDecay:
1882    case CK_NullToMemberPointer:
1883    case CK_UserDefinedConversion:
1884    case CK_ConstructorConversion:
1885    case CK_IntegralToPointer:
1886    case CK_PointerToIntegral:
1887    case CK_ToVoid:
1888    case CK_VectorSplat:
1889    case CK_IntegralCast:
1890    case CK_IntegralToFloating:
1891    case CK_FloatingToIntegral:
1892    case CK_FloatingCast:
1893    case CK_MemberPointerToBoolean:
1894    case CK_AnyPointerToObjCPointerCast:
1895    case CK_AnyPointerToBlockPointerCast:
1896      assert(BasePath.empty() && "Cast kind should not have a base path!");
1897      break;
1898    }
1899#endif
1900  }
1901
1902protected:
1903  CastExpr(StmtClass SC, QualType ty, const CastKind kind, Expr *op,
1904           CXXBaseSpecifierArray BasePath) :
1905    Expr(SC, ty,
1906         // Cast expressions are type-dependent if the type is
1907         // dependent (C++ [temp.dep.expr]p3).
1908         ty->isDependentType(),
1909         // Cast expressions are value-dependent if the type is
1910         // dependent or if the subexpression is value-dependent.
1911         ty->isDependentType() || (op && op->isValueDependent())),
1912    Kind(kind), Op(op), BasePath(BasePath) {
1913      CheckBasePath();
1914    }
1915
1916  /// \brief Construct an empty cast.
1917  CastExpr(StmtClass SC, EmptyShell Empty)
1918    : Expr(SC, Empty) { }
1919
1920  virtual void DoDestroy(ASTContext &C);
1921
1922public:
1923  CastKind getCastKind() const { return Kind; }
1924  void setCastKind(CastKind K) { Kind = K; }
1925  const char *getCastKindName() const;
1926
1927  Expr *getSubExpr() { return cast<Expr>(Op); }
1928  const Expr *getSubExpr() const { return cast<Expr>(Op); }
1929  void setSubExpr(Expr *E) { Op = E; }
1930
1931  /// \brief Retrieve the cast subexpression as it was written in the source
1932  /// code, looking through any implicit casts or other intermediate nodes
1933  /// introduced by semantic analysis.
1934  Expr *getSubExprAsWritten();
1935  const Expr *getSubExprAsWritten() const {
1936    return const_cast<CastExpr *>(this)->getSubExprAsWritten();
1937  }
1938
1939  const CXXBaseSpecifierArray& getBasePath() const { return BasePath; }
1940
1941  static bool classof(const Stmt *T) {
1942    return T->getStmtClass() >= firstCastExprConstant &&
1943           T->getStmtClass() <= lastCastExprConstant;
1944  }
1945  static bool classof(const CastExpr *) { return true; }
1946
1947  // Iterators
1948  virtual child_iterator child_begin();
1949  virtual child_iterator child_end();
1950};
1951
1952/// ImplicitCastExpr - Allows us to explicitly represent implicit type
1953/// conversions, which have no direct representation in the original
1954/// source code. For example: converting T[]->T*, void f()->void
1955/// (*f)(), float->double, short->int, etc.
1956///
1957/// In C, implicit casts always produce rvalues. However, in C++, an
1958/// implicit cast whose result is being bound to a reference will be
1959/// an lvalue. For example:
1960///
1961/// @code
1962/// class Base { };
1963/// class Derived : public Base { };
1964/// void f(Derived d) {
1965///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1966/// }
1967/// @endcode
1968class ImplicitCastExpr : public CastExpr {
1969  /// LvalueCast - Whether this cast produces an lvalue.
1970  bool LvalueCast;
1971
1972public:
1973  ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
1974                   CXXBaseSpecifierArray BasePath, bool Lvalue)
1975    : CastExpr(ImplicitCastExprClass, ty, kind, op, BasePath),
1976    LvalueCast(Lvalue) { }
1977
1978  /// \brief Construct an empty implicit cast.
1979  explicit ImplicitCastExpr(EmptyShell Shell)
1980    : CastExpr(ImplicitCastExprClass, Shell) { }
1981
1982  virtual SourceRange getSourceRange() const {
1983    return getSubExpr()->getSourceRange();
1984  }
1985
1986  /// isLvalueCast - Whether this cast produces an lvalue.
1987  bool isLvalueCast() const { return LvalueCast; }
1988
1989  /// setLvalueCast - Set whether this cast produces an lvalue.
1990  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1991
1992  static bool classof(const Stmt *T) {
1993    return T->getStmtClass() == ImplicitCastExprClass;
1994  }
1995  static bool classof(const ImplicitCastExpr *) { return true; }
1996};
1997
1998/// ExplicitCastExpr - An explicit cast written in the source
1999/// code.
2000///
2001/// This class is effectively an abstract class, because it provides
2002/// the basic representation of an explicitly-written cast without
2003/// specifying which kind of cast (C cast, functional cast, static
2004/// cast, etc.) was written; specific derived classes represent the
2005/// particular style of cast and its location information.
2006///
2007/// Unlike implicit casts, explicit cast nodes have two different
2008/// types: the type that was written into the source code, and the
2009/// actual type of the expression as determined by semantic
2010/// analysis. These types may differ slightly. For example, in C++ one
2011/// can cast to a reference type, which indicates that the resulting
2012/// expression will be an lvalue. The reference type, however, will
2013/// not be used as the type of the expression.
2014class ExplicitCastExpr : public CastExpr {
2015  /// TInfo - Source type info for the (written) type
2016  /// this expression is casting to.
2017  TypeSourceInfo *TInfo;
2018
2019protected:
2020  ExplicitCastExpr(StmtClass SC, QualType exprTy, CastKind kind,
2021                   Expr *op, CXXBaseSpecifierArray BasePath,
2022                   TypeSourceInfo *writtenTy)
2023    : CastExpr(SC, exprTy, kind, op, BasePath), TInfo(writtenTy) {}
2024
2025  /// \brief Construct an empty explicit cast.
2026  ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
2027    : CastExpr(SC, Shell) { }
2028
2029public:
2030  /// getTypeInfoAsWritten - Returns the type source info for the type
2031  /// that this expression is casting to.
2032  TypeSourceInfo *getTypeInfoAsWritten() const { return TInfo; }
2033  void setTypeInfoAsWritten(TypeSourceInfo *writtenTy) { TInfo = writtenTy; }
2034
2035  /// getTypeAsWritten - Returns the type that this expression is
2036  /// casting to, as written in the source code.
2037  QualType getTypeAsWritten() const { return TInfo->getType(); }
2038
2039  static bool classof(const Stmt *T) {
2040     return T->getStmtClass() >= firstExplicitCastExprConstant &&
2041            T->getStmtClass() <= lastExplicitCastExprConstant;
2042  }
2043  static bool classof(const ExplicitCastExpr *) { return true; }
2044};
2045
2046/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
2047/// cast in C++ (C++ [expr.cast]), which uses the syntax
2048/// (Type)expr. For example: @c (int)f.
2049class CStyleCastExpr : public ExplicitCastExpr {
2050  SourceLocation LPLoc; // the location of the left paren
2051  SourceLocation RPLoc; // the location of the right paren
2052public:
2053  CStyleCastExpr(QualType exprTy, CastKind kind, Expr *op,
2054                 CXXBaseSpecifierArray BasePath, TypeSourceInfo *writtenTy,
2055                 SourceLocation l, SourceLocation r)
2056    : ExplicitCastExpr(CStyleCastExprClass, exprTy, kind, op, BasePath,
2057                       writtenTy), LPLoc(l), RPLoc(r) {}
2058
2059  /// \brief Construct an empty C-style explicit cast.
2060  explicit CStyleCastExpr(EmptyShell Shell)
2061    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
2062
2063  SourceLocation getLParenLoc() const { return LPLoc; }
2064  void setLParenLoc(SourceLocation L) { LPLoc = L; }
2065
2066  SourceLocation getRParenLoc() const { return RPLoc; }
2067  void setRParenLoc(SourceLocation L) { RPLoc = L; }
2068
2069  virtual SourceRange getSourceRange() const {
2070    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
2071  }
2072  static bool classof(const Stmt *T) {
2073    return T->getStmtClass() == CStyleCastExprClass;
2074  }
2075  static bool classof(const CStyleCastExpr *) { return true; }
2076};
2077
2078/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
2079///
2080/// This expression node kind describes a builtin binary operation,
2081/// such as "x + y" for integer values "x" and "y". The operands will
2082/// already have been converted to appropriate types (e.g., by
2083/// performing promotions or conversions).
2084///
2085/// In C++, where operators may be overloaded, a different kind of
2086/// expression node (CXXOperatorCallExpr) is used to express the
2087/// invocation of an overloaded operator with operator syntax. Within
2088/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
2089/// used to store an expression "x + y" depends on the subexpressions
2090/// for x and y. If neither x or y is type-dependent, and the "+"
2091/// operator resolves to a built-in operation, BinaryOperator will be
2092/// used to express the computation (x and y may still be
2093/// value-dependent). If either x or y is type-dependent, or if the
2094/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
2095/// be used to express the computation.
2096class BinaryOperator : public Expr {
2097public:
2098  enum Opcode {
2099    // Operators listed in order of precedence.
2100    // Note that additions to this should also update the StmtVisitor class.
2101    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
2102    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
2103    Add, Sub,         // [C99 6.5.6] Additive operators.
2104    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
2105    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
2106    EQ, NE,           // [C99 6.5.9] Equality operators.
2107    And,              // [C99 6.5.10] Bitwise AND operator.
2108    Xor,              // [C99 6.5.11] Bitwise XOR operator.
2109    Or,               // [C99 6.5.12] Bitwise OR operator.
2110    LAnd,             // [C99 6.5.13] Logical AND operator.
2111    LOr,              // [C99 6.5.14] Logical OR operator.
2112    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
2113    DivAssign, RemAssign,
2114    AddAssign, SubAssign,
2115    ShlAssign, ShrAssign,
2116    AndAssign, XorAssign,
2117    OrAssign,
2118    Comma             // [C99 6.5.17] Comma operator.
2119  };
2120private:
2121  enum { LHS, RHS, END_EXPR };
2122  Stmt* SubExprs[END_EXPR];
2123  Opcode Opc;
2124  SourceLocation OpLoc;
2125public:
2126
2127  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2128                 SourceLocation opLoc)
2129    : Expr(BinaryOperatorClass, ResTy,
2130           lhs->isTypeDependent() || rhs->isTypeDependent(),
2131           lhs->isValueDependent() || rhs->isValueDependent()),
2132      Opc(opc), OpLoc(opLoc) {
2133    SubExprs[LHS] = lhs;
2134    SubExprs[RHS] = rhs;
2135    assert(!isCompoundAssignmentOp() &&
2136           "Use ArithAssignBinaryOperator for compound assignments");
2137  }
2138
2139  /// \brief Construct an empty binary operator.
2140  explicit BinaryOperator(EmptyShell Empty)
2141    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
2142
2143  SourceLocation getOperatorLoc() const { return OpLoc; }
2144  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
2145
2146  Opcode getOpcode() const { return Opc; }
2147  void setOpcode(Opcode O) { Opc = O; }
2148
2149  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2150  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2151  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2152  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2153
2154  virtual SourceRange getSourceRange() const {
2155    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
2156  }
2157
2158  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
2159  /// corresponds to, e.g. "<<=".
2160  static const char *getOpcodeStr(Opcode Op);
2161
2162  /// \brief Retrieve the binary opcode that corresponds to the given
2163  /// overloaded operator.
2164  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
2165
2166  /// \brief Retrieve the overloaded operator kind that corresponds to
2167  /// the given binary opcode.
2168  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
2169
2170  /// predicates to categorize the respective opcodes.
2171  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
2172  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
2173  static bool isShiftOp(Opcode Opc) { return Opc == Shl || Opc == Shr; }
2174  bool isShiftOp() const { return isShiftOp(Opc); }
2175
2176  static bool isBitwiseOp(Opcode Opc) { return Opc >= And && Opc <= Or; }
2177  bool isBitwiseOp() const { return isBitwiseOp(Opc); }
2178
2179  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
2180  bool isRelationalOp() const { return isRelationalOp(Opc); }
2181
2182  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
2183  bool isEqualityOp() const { return isEqualityOp(Opc); }
2184
2185  static bool isComparisonOp(Opcode Opc) { return Opc >= LT && Opc <= NE; }
2186  bool isComparisonOp() const { return isComparisonOp(Opc); }
2187
2188  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
2189  bool isLogicalOp() const { return isLogicalOp(Opc); }
2190
2191  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
2192  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
2193  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
2194
2195  static bool classof(const Stmt *S) {
2196    return S->getStmtClass() >= firstBinaryOperatorConstant &&
2197           S->getStmtClass() <= lastBinaryOperatorConstant;
2198  }
2199  static bool classof(const BinaryOperator *) { return true; }
2200
2201  // Iterators
2202  virtual child_iterator child_begin();
2203  virtual child_iterator child_end();
2204
2205protected:
2206  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
2207                 SourceLocation opLoc, bool dead)
2208    : Expr(CompoundAssignOperatorClass, ResTy,
2209           lhs->isTypeDependent() || rhs->isTypeDependent(),
2210           lhs->isValueDependent() || rhs->isValueDependent()),
2211      Opc(opc), OpLoc(opLoc) {
2212    SubExprs[LHS] = lhs;
2213    SubExprs[RHS] = rhs;
2214  }
2215
2216  BinaryOperator(StmtClass SC, EmptyShell Empty)
2217    : Expr(SC, Empty), Opc(MulAssign) { }
2218};
2219
2220/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
2221/// track of the type the operation is performed in.  Due to the semantics of
2222/// these operators, the operands are promoted, the aritmetic performed, an
2223/// implicit conversion back to the result type done, then the assignment takes
2224/// place.  This captures the intermediate type which the computation is done
2225/// in.
2226class CompoundAssignOperator : public BinaryOperator {
2227  QualType ComputationLHSType;
2228  QualType ComputationResultType;
2229public:
2230  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
2231                         QualType ResType, QualType CompLHSType,
2232                         QualType CompResultType,
2233                         SourceLocation OpLoc)
2234    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
2235      ComputationLHSType(CompLHSType),
2236      ComputationResultType(CompResultType) {
2237    assert(isCompoundAssignmentOp() &&
2238           "Only should be used for compound assignments");
2239  }
2240
2241  /// \brief Build an empty compound assignment operator expression.
2242  explicit CompoundAssignOperator(EmptyShell Empty)
2243    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
2244
2245  // The two computation types are the type the LHS is converted
2246  // to for the computation and the type of the result; the two are
2247  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
2248  QualType getComputationLHSType() const { return ComputationLHSType; }
2249  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
2250
2251  QualType getComputationResultType() const { return ComputationResultType; }
2252  void setComputationResultType(QualType T) { ComputationResultType = T; }
2253
2254  static bool classof(const CompoundAssignOperator *) { return true; }
2255  static bool classof(const Stmt *S) {
2256    return S->getStmtClass() == CompoundAssignOperatorClass;
2257  }
2258};
2259
2260/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
2261/// GNU "missing LHS" extension is in use.
2262///
2263class ConditionalOperator : public Expr {
2264  enum { COND, LHS, RHS, END_EXPR };
2265  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2266  SourceLocation QuestionLoc, ColonLoc;
2267public:
2268  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
2269                      SourceLocation CLoc, Expr *rhs, QualType t)
2270    : Expr(ConditionalOperatorClass, t,
2271           // FIXME: the type of the conditional operator doesn't
2272           // depend on the type of the conditional, but the standard
2273           // seems to imply that it could. File a bug!
2274           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
2275           (cond->isValueDependent() ||
2276            (lhs && lhs->isValueDependent()) ||
2277            (rhs && rhs->isValueDependent()))),
2278      QuestionLoc(QLoc),
2279      ColonLoc(CLoc) {
2280    SubExprs[COND] = cond;
2281    SubExprs[LHS] = lhs;
2282    SubExprs[RHS] = rhs;
2283  }
2284
2285  /// \brief Build an empty conditional operator.
2286  explicit ConditionalOperator(EmptyShell Empty)
2287    : Expr(ConditionalOperatorClass, Empty) { }
2288
2289  // getCond - Return the expression representing the condition for
2290  //  the ?: operator.
2291  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
2292  void setCond(Expr *E) { SubExprs[COND] = E; }
2293
2294  // getTrueExpr - Return the subexpression representing the value of the ?:
2295  //  expression if the condition evaluates to true.  In most cases this value
2296  //  will be the same as getLHS() except a GCC extension allows the left
2297  //  subexpression to be omitted, and instead of the condition be returned.
2298  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
2299  //  is only evaluated once.
2300  Expr *getTrueExpr() const {
2301    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
2302  }
2303
2304  // getTrueExpr - Return the subexpression representing the value of the ?:
2305  // expression if the condition evaluates to false. This is the same as getRHS.
2306  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
2307
2308  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
2309  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2310
2311  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2312  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2313
2314  SourceLocation getQuestionLoc() const { return QuestionLoc; }
2315  void setQuestionLoc(SourceLocation L) { QuestionLoc = L; }
2316
2317  SourceLocation getColonLoc() const { return ColonLoc; }
2318  void setColonLoc(SourceLocation L) { ColonLoc = L; }
2319
2320  virtual SourceRange getSourceRange() const {
2321    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
2322  }
2323  static bool classof(const Stmt *T) {
2324    return T->getStmtClass() == ConditionalOperatorClass;
2325  }
2326  static bool classof(const ConditionalOperator *) { return true; }
2327
2328  // Iterators
2329  virtual child_iterator child_begin();
2330  virtual child_iterator child_end();
2331};
2332
2333/// AddrLabelExpr - The GNU address of label extension, representing &&label.
2334class AddrLabelExpr : public Expr {
2335  SourceLocation AmpAmpLoc, LabelLoc;
2336  LabelStmt *Label;
2337public:
2338  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
2339                QualType t)
2340    : Expr(AddrLabelExprClass, t, false, false),
2341      AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
2342
2343  /// \brief Build an empty address of a label expression.
2344  explicit AddrLabelExpr(EmptyShell Empty)
2345    : Expr(AddrLabelExprClass, Empty) { }
2346
2347  SourceLocation getAmpAmpLoc() const { return AmpAmpLoc; }
2348  void setAmpAmpLoc(SourceLocation L) { AmpAmpLoc = L; }
2349  SourceLocation getLabelLoc() const { return LabelLoc; }
2350  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
2351
2352  virtual SourceRange getSourceRange() const {
2353    return SourceRange(AmpAmpLoc, LabelLoc);
2354  }
2355
2356  LabelStmt *getLabel() const { return Label; }
2357  void setLabel(LabelStmt *S) { Label = S; }
2358
2359  static bool classof(const Stmt *T) {
2360    return T->getStmtClass() == AddrLabelExprClass;
2361  }
2362  static bool classof(const AddrLabelExpr *) { return true; }
2363
2364  // Iterators
2365  virtual child_iterator child_begin();
2366  virtual child_iterator child_end();
2367};
2368
2369/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
2370/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
2371/// takes the value of the last subexpression.
2372class StmtExpr : public Expr {
2373  Stmt *SubStmt;
2374  SourceLocation LParenLoc, RParenLoc;
2375public:
2376  // FIXME: Does type-dependence need to be computed differently?
2377  StmtExpr(CompoundStmt *substmt, QualType T,
2378           SourceLocation lp, SourceLocation rp) :
2379    Expr(StmtExprClass, T, T->isDependentType(), false),
2380    SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
2381
2382  /// \brief Build an empty statement expression.
2383  explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }
2384
2385  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
2386  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
2387  void setSubStmt(CompoundStmt *S) { SubStmt = S; }
2388
2389  virtual SourceRange getSourceRange() const {
2390    return SourceRange(LParenLoc, RParenLoc);
2391  }
2392
2393  SourceLocation getLParenLoc() const { return LParenLoc; }
2394  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
2395  SourceLocation getRParenLoc() const { return RParenLoc; }
2396  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2397
2398  static bool classof(const Stmt *T) {
2399    return T->getStmtClass() == StmtExprClass;
2400  }
2401  static bool classof(const StmtExpr *) { return true; }
2402
2403  // Iterators
2404  virtual child_iterator child_begin();
2405  virtual child_iterator child_end();
2406};
2407
2408/// TypesCompatibleExpr - GNU builtin-in function __builtin_types_compatible_p.
2409/// This AST node represents a function that returns 1 if two *types* (not
2410/// expressions) are compatible. The result of this built-in function can be
2411/// used in integer constant expressions.
2412class TypesCompatibleExpr : public Expr {
2413  QualType Type1;
2414  QualType Type2;
2415  SourceLocation BuiltinLoc, RParenLoc;
2416public:
2417  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
2418                      QualType t1, QualType t2, SourceLocation RP) :
2419    Expr(TypesCompatibleExprClass, ReturnType, false, false),
2420    Type1(t1), Type2(t2), BuiltinLoc(BLoc), RParenLoc(RP) {}
2421
2422  /// \brief Build an empty __builtin_type_compatible_p expression.
2423  explicit TypesCompatibleExpr(EmptyShell Empty)
2424    : Expr(TypesCompatibleExprClass, Empty) { }
2425
2426  QualType getArgType1() const { return Type1; }
2427  void setArgType1(QualType T) { Type1 = T; }
2428  QualType getArgType2() const { return Type2; }
2429  void setArgType2(QualType T) { Type2 = T; }
2430
2431  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2432  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2433
2434  SourceLocation getRParenLoc() const { return RParenLoc; }
2435  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2436
2437  virtual SourceRange getSourceRange() const {
2438    return SourceRange(BuiltinLoc, RParenLoc);
2439  }
2440  static bool classof(const Stmt *T) {
2441    return T->getStmtClass() == TypesCompatibleExprClass;
2442  }
2443  static bool classof(const TypesCompatibleExpr *) { return true; }
2444
2445  // Iterators
2446  virtual child_iterator child_begin();
2447  virtual child_iterator child_end();
2448};
2449
2450/// ShuffleVectorExpr - clang-specific builtin-in function
2451/// __builtin_shufflevector.
2452/// This AST node represents a operator that does a constant
2453/// shuffle, similar to LLVM's shufflevector instruction. It takes
2454/// two vectors and a variable number of constant indices,
2455/// and returns the appropriately shuffled vector.
2456class ShuffleVectorExpr : public Expr {
2457  SourceLocation BuiltinLoc, RParenLoc;
2458
2459  // SubExprs - the list of values passed to the __builtin_shufflevector
2460  // function. The first two are vectors, and the rest are constant
2461  // indices.  The number of values in this list is always
2462  // 2+the number of indices in the vector type.
2463  Stmt **SubExprs;
2464  unsigned NumExprs;
2465
2466protected:
2467  virtual void DoDestroy(ASTContext &C);
2468
2469public:
2470  // FIXME: Can a shufflevector be value-dependent?  Does type-dependence need
2471  // to be computed differently?
2472  ShuffleVectorExpr(ASTContext &C, Expr **args, unsigned nexpr,
2473                    QualType Type, SourceLocation BLoc,
2474                    SourceLocation RP) :
2475    Expr(ShuffleVectorExprClass, Type, Type->isDependentType(), false),
2476    BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(nexpr) {
2477
2478    SubExprs = new (C) Stmt*[nexpr];
2479    for (unsigned i = 0; i < nexpr; i++)
2480      SubExprs[i] = args[i];
2481  }
2482
2483  /// \brief Build an empty vector-shuffle expression.
2484  explicit ShuffleVectorExpr(EmptyShell Empty)
2485    : Expr(ShuffleVectorExprClass, Empty), SubExprs(0) { }
2486
2487  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2488  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2489
2490  SourceLocation getRParenLoc() const { return RParenLoc; }
2491  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2492
2493  virtual SourceRange getSourceRange() const {
2494    return SourceRange(BuiltinLoc, RParenLoc);
2495  }
2496  static bool classof(const Stmt *T) {
2497    return T->getStmtClass() == ShuffleVectorExprClass;
2498  }
2499  static bool classof(const ShuffleVectorExpr *) { return true; }
2500
2501  ~ShuffleVectorExpr() {}
2502
2503  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
2504  /// constant expression, the actual arguments passed in, and the function
2505  /// pointers.
2506  unsigned getNumSubExprs() const { return NumExprs; }
2507
2508  /// getExpr - Return the Expr at the specified index.
2509  Expr *getExpr(unsigned Index) {
2510    assert((Index < NumExprs) && "Arg access out of range!");
2511    return cast<Expr>(SubExprs[Index]);
2512  }
2513  const Expr *getExpr(unsigned Index) const {
2514    assert((Index < NumExprs) && "Arg access out of range!");
2515    return cast<Expr>(SubExprs[Index]);
2516  }
2517
2518  void setExprs(ASTContext &C, Expr ** Exprs, unsigned NumExprs);
2519
2520  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
2521    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
2522    return getExpr(N+2)->EvaluateAsInt(Ctx).getZExtValue();
2523  }
2524
2525  // Iterators
2526  virtual child_iterator child_begin();
2527  virtual child_iterator child_end();
2528};
2529
2530/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
2531/// This AST node is similar to the conditional operator (?:) in C, with
2532/// the following exceptions:
2533/// - the test expression must be a integer constant expression.
2534/// - the expression returned acts like the chosen subexpression in every
2535///   visible way: the type is the same as that of the chosen subexpression,
2536///   and all predicates (whether it's an l-value, whether it's an integer
2537///   constant expression, etc.) return the same result as for the chosen
2538///   sub-expression.
2539class ChooseExpr : public Expr {
2540  enum { COND, LHS, RHS, END_EXPR };
2541  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
2542  SourceLocation BuiltinLoc, RParenLoc;
2543public:
2544  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
2545             SourceLocation RP, bool TypeDependent, bool ValueDependent)
2546    : Expr(ChooseExprClass, t, TypeDependent, ValueDependent),
2547      BuiltinLoc(BLoc), RParenLoc(RP) {
2548      SubExprs[COND] = cond;
2549      SubExprs[LHS] = lhs;
2550      SubExprs[RHS] = rhs;
2551    }
2552
2553  /// \brief Build an empty __builtin_choose_expr.
2554  explicit ChooseExpr(EmptyShell Empty) : Expr(ChooseExprClass, Empty) { }
2555
2556  /// isConditionTrue - Return whether the condition is true (i.e. not
2557  /// equal to zero).
2558  bool isConditionTrue(ASTContext &C) const;
2559
2560  /// getChosenSubExpr - Return the subexpression chosen according to the
2561  /// condition.
2562  Expr *getChosenSubExpr(ASTContext &C) const {
2563    return isConditionTrue(C) ? getLHS() : getRHS();
2564  }
2565
2566  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
2567  void setCond(Expr *E) { SubExprs[COND] = E; }
2568  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
2569  void setLHS(Expr *E) { SubExprs[LHS] = E; }
2570  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
2571  void setRHS(Expr *E) { SubExprs[RHS] = E; }
2572
2573  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2574  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2575
2576  SourceLocation getRParenLoc() const { return RParenLoc; }
2577  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2578
2579  virtual SourceRange getSourceRange() const {
2580    return SourceRange(BuiltinLoc, RParenLoc);
2581  }
2582  static bool classof(const Stmt *T) {
2583    return T->getStmtClass() == ChooseExprClass;
2584  }
2585  static bool classof(const ChooseExpr *) { return true; }
2586
2587  // Iterators
2588  virtual child_iterator child_begin();
2589  virtual child_iterator child_end();
2590};
2591
2592/// GNUNullExpr - Implements the GNU __null extension, which is a name
2593/// for a null pointer constant that has integral type (e.g., int or
2594/// long) and is the same size and alignment as a pointer. The __null
2595/// extension is typically only used by system headers, which define
2596/// NULL as __null in C++ rather than using 0 (which is an integer
2597/// that may not match the size of a pointer).
2598class GNUNullExpr : public Expr {
2599  /// TokenLoc - The location of the __null keyword.
2600  SourceLocation TokenLoc;
2601
2602public:
2603  GNUNullExpr(QualType Ty, SourceLocation Loc)
2604    : Expr(GNUNullExprClass, Ty, false, false), TokenLoc(Loc) { }
2605
2606  /// \brief Build an empty GNU __null expression.
2607  explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { }
2608
2609  /// getTokenLocation - The location of the __null token.
2610  SourceLocation getTokenLocation() const { return TokenLoc; }
2611  void setTokenLocation(SourceLocation L) { TokenLoc = L; }
2612
2613  virtual SourceRange getSourceRange() const {
2614    return SourceRange(TokenLoc);
2615  }
2616  static bool classof(const Stmt *T) {
2617    return T->getStmtClass() == GNUNullExprClass;
2618  }
2619  static bool classof(const GNUNullExpr *) { return true; }
2620
2621  // Iterators
2622  virtual child_iterator child_begin();
2623  virtual child_iterator child_end();
2624};
2625
2626/// VAArgExpr, used for the builtin function __builtin_va_arg.
2627class VAArgExpr : public Expr {
2628  Stmt *Val;
2629  SourceLocation BuiltinLoc, RParenLoc;
2630public:
2631  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
2632    : Expr(VAArgExprClass, t, t->isDependentType(), false),
2633      Val(e),
2634      BuiltinLoc(BLoc),
2635      RParenLoc(RPLoc) { }
2636
2637  /// \brief Create an empty __builtin_va_arg expression.
2638  explicit VAArgExpr(EmptyShell Empty) : Expr(VAArgExprClass, Empty) { }
2639
2640  const Expr *getSubExpr() const { return cast<Expr>(Val); }
2641  Expr *getSubExpr() { return cast<Expr>(Val); }
2642  void setSubExpr(Expr *E) { Val = E; }
2643
2644  SourceLocation getBuiltinLoc() const { return BuiltinLoc; }
2645  void setBuiltinLoc(SourceLocation L) { BuiltinLoc = L; }
2646
2647  SourceLocation getRParenLoc() const { return RParenLoc; }
2648  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
2649
2650  virtual SourceRange getSourceRange() const {
2651    return SourceRange(BuiltinLoc, RParenLoc);
2652  }
2653  static bool classof(const Stmt *T) {
2654    return T->getStmtClass() == VAArgExprClass;
2655  }
2656  static bool classof(const VAArgExpr *) { return true; }
2657
2658  // Iterators
2659  virtual child_iterator child_begin();
2660  virtual child_iterator child_end();
2661};
2662
2663/// @brief Describes an C or C++ initializer list.
2664///
2665/// InitListExpr describes an initializer list, which can be used to
2666/// initialize objects of different types, including
2667/// struct/class/union types, arrays, and vectors. For example:
2668///
2669/// @code
2670/// struct foo x = { 1, { 2, 3 } };
2671/// @endcode
2672///
2673/// Prior to semantic analysis, an initializer list will represent the
2674/// initializer list as written by the user, but will have the
2675/// placeholder type "void". This initializer list is called the
2676/// syntactic form of the initializer, and may contain C99 designated
2677/// initializers (represented as DesignatedInitExprs), initializations
2678/// of subobject members without explicit braces, and so on. Clients
2679/// interested in the original syntax of the initializer list should
2680/// use the syntactic form of the initializer list.
2681///
2682/// After semantic analysis, the initializer list will represent the
2683/// semantic form of the initializer, where the initializations of all
2684/// subobjects are made explicit with nested InitListExpr nodes and
2685/// C99 designators have been eliminated by placing the designated
2686/// initializations into the subobject they initialize. Additionally,
2687/// any "holes" in the initialization, where no initializer has been
2688/// specified for a particular subobject, will be replaced with
2689/// implicitly-generated ImplicitValueInitExpr expressions that
2690/// value-initialize the subobjects. Note, however, that the
2691/// initializer lists may still have fewer initializers than there are
2692/// elements to initialize within the object.
2693///
2694/// Given the semantic form of the initializer list, one can retrieve
2695/// the original syntactic form of that initializer list (if it
2696/// exists) using getSyntacticForm(). Since many initializer lists
2697/// have the same syntactic and semantic forms, getSyntacticForm() may
2698/// return NULL, indicating that the current initializer list also
2699/// serves as its syntactic form.
2700class InitListExpr : public Expr {
2701  // FIXME: Eliminate this vector in favor of ASTContext allocation
2702  typedef ASTVector<Stmt *> InitExprsTy;
2703  InitExprsTy InitExprs;
2704  SourceLocation LBraceLoc, RBraceLoc;
2705
2706  /// Contains the initializer list that describes the syntactic form
2707  /// written in the source code.
2708  InitListExpr *SyntacticForm;
2709
2710  /// If this initializer list initializes a union, specifies which
2711  /// field within the union will be initialized.
2712  FieldDecl *UnionFieldInit;
2713
2714  /// Whether this initializer list originally had a GNU array-range
2715  /// designator in it. This is a temporary marker used by CodeGen.
2716  bool HadArrayRangeDesignator;
2717
2718public:
2719  InitListExpr(ASTContext &C, SourceLocation lbraceloc,
2720               Expr **initexprs, unsigned numinits,
2721               SourceLocation rbraceloc);
2722
2723  /// \brief Build an empty initializer list.
2724  explicit InitListExpr(ASTContext &C, EmptyShell Empty)
2725    : Expr(InitListExprClass, Empty), InitExprs(C) { }
2726
2727  unsigned getNumInits() const { return InitExprs.size(); }
2728
2729  const Expr* getInit(unsigned Init) const {
2730    assert(Init < getNumInits() && "Initializer access out of range!");
2731    return cast_or_null<Expr>(InitExprs[Init]);
2732  }
2733
2734  Expr* getInit(unsigned Init) {
2735    assert(Init < getNumInits() && "Initializer access out of range!");
2736    return cast_or_null<Expr>(InitExprs[Init]);
2737  }
2738
2739  void setInit(unsigned Init, Expr *expr) {
2740    assert(Init < getNumInits() && "Initializer access out of range!");
2741    InitExprs[Init] = expr;
2742  }
2743
2744  /// \brief Reserve space for some number of initializers.
2745  void reserveInits(ASTContext &C, unsigned NumInits);
2746
2747  /// @brief Specify the number of initializers
2748  ///
2749  /// If there are more than @p NumInits initializers, the remaining
2750  /// initializers will be destroyed. If there are fewer than @p
2751  /// NumInits initializers, NULL expressions will be added for the
2752  /// unknown initializers.
2753  void resizeInits(ASTContext &Context, unsigned NumInits);
2754
2755  /// @brief Updates the initializer at index @p Init with the new
2756  /// expression @p expr, and returns the old expression at that
2757  /// location.
2758  ///
2759  /// When @p Init is out of range for this initializer list, the
2760  /// initializer list will be extended with NULL expressions to
2761  /// accomodate the new entry.
2762  Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
2763
2764  /// \brief If this initializes a union, specifies which field in the
2765  /// union to initialize.
2766  ///
2767  /// Typically, this field is the first named field within the
2768  /// union. However, a designated initializer can specify the
2769  /// initialization of a different field within the union.
2770  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
2771  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
2772
2773  // Explicit InitListExpr's originate from source code (and have valid source
2774  // locations). Implicit InitListExpr's are created by the semantic analyzer.
2775  bool isExplicit() {
2776    return LBraceLoc.isValid() && RBraceLoc.isValid();
2777  }
2778
2779  SourceLocation getLBraceLoc() const { return LBraceLoc; }
2780  void setLBraceLoc(SourceLocation Loc) { LBraceLoc = Loc; }
2781  SourceLocation getRBraceLoc() const { return RBraceLoc; }
2782  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
2783
2784  /// @brief Retrieve the initializer list that describes the
2785  /// syntactic form of the initializer.
2786  ///
2787  ///
2788  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
2789  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
2790
2791  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
2792  void sawArrayRangeDesignator(bool ARD = true) {
2793    HadArrayRangeDesignator = ARD;
2794  }
2795
2796  virtual SourceRange getSourceRange() const {
2797    return SourceRange(LBraceLoc, RBraceLoc);
2798  }
2799  static bool classof(const Stmt *T) {
2800    return T->getStmtClass() == InitListExprClass;
2801  }
2802  static bool classof(const InitListExpr *) { return true; }
2803
2804  // Iterators
2805  virtual child_iterator child_begin();
2806  virtual child_iterator child_end();
2807
2808  typedef InitExprsTy::iterator iterator;
2809  typedef InitExprsTy::reverse_iterator reverse_iterator;
2810
2811  iterator begin() { return InitExprs.begin(); }
2812  iterator end() { return InitExprs.end(); }
2813  reverse_iterator rbegin() { return InitExprs.rbegin(); }
2814  reverse_iterator rend() { return InitExprs.rend(); }
2815};
2816
2817/// @brief Represents a C99 designated initializer expression.
2818///
2819/// A designated initializer expression (C99 6.7.8) contains one or
2820/// more designators (which can be field designators, array
2821/// designators, or GNU array-range designators) followed by an
2822/// expression that initializes the field or element(s) that the
2823/// designators refer to. For example, given:
2824///
2825/// @code
2826/// struct point {
2827///   double x;
2828///   double y;
2829/// };
2830/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
2831/// @endcode
2832///
2833/// The InitListExpr contains three DesignatedInitExprs, the first of
2834/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
2835/// designators, one array designator for @c [2] followed by one field
2836/// designator for @c .y. The initalization expression will be 1.0.
2837class DesignatedInitExpr : public Expr {
2838public:
2839  /// \brief Forward declaration of the Designator class.
2840  class Designator;
2841
2842private:
2843  /// The location of the '=' or ':' prior to the actual initializer
2844  /// expression.
2845  SourceLocation EqualOrColonLoc;
2846
2847  /// Whether this designated initializer used the GNU deprecated
2848  /// syntax rather than the C99 '=' syntax.
2849  bool GNUSyntax : 1;
2850
2851  /// The number of designators in this initializer expression.
2852  unsigned NumDesignators : 15;
2853
2854  /// \brief The designators in this designated initialization
2855  /// expression.
2856  Designator *Designators;
2857
2858  /// The number of subexpressions of this initializer expression,
2859  /// which contains both the initializer and any additional
2860  /// expressions used by array and array-range designators.
2861  unsigned NumSubExprs : 16;
2862
2863
2864  DesignatedInitExpr(ASTContext &C, QualType Ty, unsigned NumDesignators,
2865                     const Designator *Designators,
2866                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
2867                     Expr **IndexExprs, unsigned NumIndexExprs,
2868                     Expr *Init);
2869
2870  explicit DesignatedInitExpr(unsigned NumSubExprs)
2871    : Expr(DesignatedInitExprClass, EmptyShell()),
2872      NumDesignators(0), Designators(0), NumSubExprs(NumSubExprs) { }
2873
2874protected:
2875  virtual void DoDestroy(ASTContext &C);
2876
2877  void DestroyDesignators(ASTContext &C);
2878
2879public:
2880  /// A field designator, e.g., ".x".
2881  struct FieldDesignator {
2882    /// Refers to the field that is being initialized. The low bit
2883    /// of this field determines whether this is actually a pointer
2884    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
2885    /// initially constructed, a field designator will store an
2886    /// IdentifierInfo*. After semantic analysis has resolved that
2887    /// name, the field designator will instead store a FieldDecl*.
2888    uintptr_t NameOrField;
2889
2890    /// The location of the '.' in the designated initializer.
2891    unsigned DotLoc;
2892
2893    /// The location of the field name in the designated initializer.
2894    unsigned FieldLoc;
2895  };
2896
2897  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
2898  struct ArrayOrRangeDesignator {
2899    /// Location of the first index expression within the designated
2900    /// initializer expression's list of subexpressions.
2901    unsigned Index;
2902    /// The location of the '[' starting the array range designator.
2903    unsigned LBracketLoc;
2904    /// The location of the ellipsis separating the start and end
2905    /// indices. Only valid for GNU array-range designators.
2906    unsigned EllipsisLoc;
2907    /// The location of the ']' terminating the array range designator.
2908    unsigned RBracketLoc;
2909  };
2910
2911  /// @brief Represents a single C99 designator.
2912  ///
2913  /// @todo This class is infuriatingly similar to clang::Designator,
2914  /// but minor differences (storing indices vs. storing pointers)
2915  /// keep us from reusing it. Try harder, later, to rectify these
2916  /// differences.
2917  class Designator {
2918    /// @brief The kind of designator this describes.
2919    enum {
2920      FieldDesignator,
2921      ArrayDesignator,
2922      ArrayRangeDesignator
2923    } Kind;
2924
2925    union {
2926      /// A field designator, e.g., ".x".
2927      struct FieldDesignator Field;
2928      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
2929      struct ArrayOrRangeDesignator ArrayOrRange;
2930    };
2931    friend class DesignatedInitExpr;
2932
2933  public:
2934    Designator() {}
2935
2936    /// @brief Initializes a field designator.
2937    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
2938               SourceLocation FieldLoc)
2939      : Kind(FieldDesignator) {
2940      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
2941      Field.DotLoc = DotLoc.getRawEncoding();
2942      Field.FieldLoc = FieldLoc.getRawEncoding();
2943    }
2944
2945    /// @brief Initializes an array designator.
2946    Designator(unsigned Index, SourceLocation LBracketLoc,
2947               SourceLocation RBracketLoc)
2948      : Kind(ArrayDesignator) {
2949      ArrayOrRange.Index = Index;
2950      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
2951      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
2952      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
2953    }
2954
2955    /// @brief Initializes a GNU array-range designator.
2956    Designator(unsigned Index, SourceLocation LBracketLoc,
2957               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
2958      : Kind(ArrayRangeDesignator) {
2959      ArrayOrRange.Index = Index;
2960      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
2961      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
2962      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
2963    }
2964
2965    bool isFieldDesignator() const { return Kind == FieldDesignator; }
2966    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
2967    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
2968
2969    IdentifierInfo * getFieldName();
2970
2971    FieldDecl *getField() {
2972      assert(Kind == FieldDesignator && "Only valid on a field designator");
2973      if (Field.NameOrField & 0x01)
2974        return 0;
2975      else
2976        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
2977    }
2978
2979    void setField(FieldDecl *FD) {
2980      assert(Kind == FieldDesignator && "Only valid on a field designator");
2981      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
2982    }
2983
2984    SourceLocation getDotLoc() const {
2985      assert(Kind == FieldDesignator && "Only valid on a field designator");
2986      return SourceLocation::getFromRawEncoding(Field.DotLoc);
2987    }
2988
2989    SourceLocation getFieldLoc() const {
2990      assert(Kind == FieldDesignator && "Only valid on a field designator");
2991      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
2992    }
2993
2994    SourceLocation getLBracketLoc() const {
2995      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2996             "Only valid on an array or array-range designator");
2997      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
2998    }
2999
3000    SourceLocation getRBracketLoc() const {
3001      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3002             "Only valid on an array or array-range designator");
3003      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
3004    }
3005
3006    SourceLocation getEllipsisLoc() const {
3007      assert(Kind == ArrayRangeDesignator &&
3008             "Only valid on an array-range designator");
3009      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
3010    }
3011
3012    unsigned getFirstExprIndex() const {
3013      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
3014             "Only valid on an array or array-range designator");
3015      return ArrayOrRange.Index;
3016    }
3017
3018    SourceLocation getStartLocation() const {
3019      if (Kind == FieldDesignator)
3020        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
3021      else
3022        return getLBracketLoc();
3023    }
3024  };
3025
3026  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
3027                                    unsigned NumDesignators,
3028                                    Expr **IndexExprs, unsigned NumIndexExprs,
3029                                    SourceLocation EqualOrColonLoc,
3030                                    bool GNUSyntax, Expr *Init);
3031
3032  static DesignatedInitExpr *CreateEmpty(ASTContext &C, unsigned NumIndexExprs);
3033
3034  /// @brief Returns the number of designators in this initializer.
3035  unsigned size() const { return NumDesignators; }
3036
3037  // Iterator access to the designators.
3038  typedef Designator* designators_iterator;
3039  designators_iterator designators_begin() { return Designators; }
3040  designators_iterator designators_end() {
3041    return Designators + NumDesignators;
3042  }
3043
3044  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
3045
3046  void setDesignators(ASTContext &C, const Designator *Desigs,
3047                      unsigned NumDesigs);
3048
3049  Expr *getArrayIndex(const Designator& D);
3050  Expr *getArrayRangeStart(const Designator& D);
3051  Expr *getArrayRangeEnd(const Designator& D);
3052
3053  /// @brief Retrieve the location of the '=' that precedes the
3054  /// initializer value itself, if present.
3055  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
3056  void setEqualOrColonLoc(SourceLocation L) { EqualOrColonLoc = L; }
3057
3058  /// @brief Determines whether this designated initializer used the
3059  /// deprecated GNU syntax for designated initializers.
3060  bool usesGNUSyntax() const { return GNUSyntax; }
3061  void setGNUSyntax(bool GNU) { GNUSyntax = GNU; }
3062
3063  /// @brief Retrieve the initializer value.
3064  Expr *getInit() const {
3065    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
3066  }
3067
3068  void setInit(Expr *init) {
3069    *child_begin() = init;
3070  }
3071
3072  /// \brief Retrieve the total number of subexpressions in this
3073  /// designated initializer expression, including the actual
3074  /// initialized value and any expressions that occur within array
3075  /// and array-range designators.
3076  unsigned getNumSubExprs() const { return NumSubExprs; }
3077
3078  Expr *getSubExpr(unsigned Idx) {
3079    assert(Idx < NumSubExprs && "Subscript out of range");
3080    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3081    Ptr += sizeof(DesignatedInitExpr);
3082    return reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx];
3083  }
3084
3085  void setSubExpr(unsigned Idx, Expr *E) {
3086    assert(Idx < NumSubExprs && "Subscript out of range");
3087    char* Ptr = static_cast<char*>(static_cast<void *>(this));
3088    Ptr += sizeof(DesignatedInitExpr);
3089    reinterpret_cast<Expr**>(reinterpret_cast<void**>(Ptr))[Idx] = E;
3090  }
3091
3092  /// \brief Replaces the designator at index @p Idx with the series
3093  /// of designators in [First, Last).
3094  void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First,
3095                        const Designator *Last);
3096
3097  virtual SourceRange getSourceRange() const;
3098
3099  static bool classof(const Stmt *T) {
3100    return T->getStmtClass() == DesignatedInitExprClass;
3101  }
3102  static bool classof(const DesignatedInitExpr *) { return true; }
3103
3104  // Iterators
3105  virtual child_iterator child_begin();
3106  virtual child_iterator child_end();
3107};
3108
3109/// \brief Represents an implicitly-generated value initialization of
3110/// an object of a given type.
3111///
3112/// Implicit value initializations occur within semantic initializer
3113/// list expressions (InitListExpr) as placeholders for subobject
3114/// initializations not explicitly specified by the user.
3115///
3116/// \see InitListExpr
3117class ImplicitValueInitExpr : public Expr {
3118public:
3119  explicit ImplicitValueInitExpr(QualType ty)
3120    : Expr(ImplicitValueInitExprClass, ty, false, false) { }
3121
3122  /// \brief Construct an empty implicit value initialization.
3123  explicit ImplicitValueInitExpr(EmptyShell Empty)
3124    : Expr(ImplicitValueInitExprClass, Empty) { }
3125
3126  static bool classof(const Stmt *T) {
3127    return T->getStmtClass() == ImplicitValueInitExprClass;
3128  }
3129  static bool classof(const ImplicitValueInitExpr *) { return true; }
3130
3131  virtual SourceRange getSourceRange() const {
3132    return SourceRange();
3133  }
3134
3135  // Iterators
3136  virtual child_iterator child_begin();
3137  virtual child_iterator child_end();
3138};
3139
3140
3141class ParenListExpr : public Expr {
3142  Stmt **Exprs;
3143  unsigned NumExprs;
3144  SourceLocation LParenLoc, RParenLoc;
3145
3146protected:
3147  virtual void DoDestroy(ASTContext& C);
3148
3149public:
3150  ParenListExpr(ASTContext& C, SourceLocation lparenloc, Expr **exprs,
3151                unsigned numexprs, SourceLocation rparenloc);
3152
3153  ~ParenListExpr() {}
3154
3155  /// \brief Build an empty paren list.
3156  //explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { }
3157
3158  unsigned getNumExprs() const { return NumExprs; }
3159
3160  const Expr* getExpr(unsigned Init) const {
3161    assert(Init < getNumExprs() && "Initializer access out of range!");
3162    return cast_or_null<Expr>(Exprs[Init]);
3163  }
3164
3165  Expr* getExpr(unsigned Init) {
3166    assert(Init < getNumExprs() && "Initializer access out of range!");
3167    return cast_or_null<Expr>(Exprs[Init]);
3168  }
3169
3170  Expr **getExprs() { return reinterpret_cast<Expr **>(Exprs); }
3171
3172  SourceLocation getLParenLoc() const { return LParenLoc; }
3173  SourceLocation getRParenLoc() const { return RParenLoc; }
3174
3175  virtual SourceRange getSourceRange() const {
3176    return SourceRange(LParenLoc, RParenLoc);
3177  }
3178  static bool classof(const Stmt *T) {
3179    return T->getStmtClass() == ParenListExprClass;
3180  }
3181  static bool classof(const ParenListExpr *) { return true; }
3182
3183  // Iterators
3184  virtual child_iterator child_begin();
3185  virtual child_iterator child_end();
3186};
3187
3188
3189//===----------------------------------------------------------------------===//
3190// Clang Extensions
3191//===----------------------------------------------------------------------===//
3192
3193
3194/// ExtVectorElementExpr - This represents access to specific elements of a
3195/// vector, and may occur on the left hand side or right hand side.  For example
3196/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
3197///
3198/// Note that the base may have either vector or pointer to vector type, just
3199/// like a struct field reference.
3200///
3201class ExtVectorElementExpr : public Expr {
3202  Stmt *Base;
3203  IdentifierInfo *Accessor;
3204  SourceLocation AccessorLoc;
3205public:
3206  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
3207                       SourceLocation loc)
3208    : Expr(ExtVectorElementExprClass, ty, base->isTypeDependent(),
3209           base->isValueDependent()),
3210      Base(base), Accessor(&accessor), AccessorLoc(loc) {}
3211
3212  /// \brief Build an empty vector element expression.
3213  explicit ExtVectorElementExpr(EmptyShell Empty)
3214    : Expr(ExtVectorElementExprClass, Empty) { }
3215
3216  const Expr *getBase() const { return cast<Expr>(Base); }
3217  Expr *getBase() { return cast<Expr>(Base); }
3218  void setBase(Expr *E) { Base = E; }
3219
3220  IdentifierInfo &getAccessor() const { return *Accessor; }
3221  void setAccessor(IdentifierInfo *II) { Accessor = II; }
3222
3223  SourceLocation getAccessorLoc() const { return AccessorLoc; }
3224  void setAccessorLoc(SourceLocation L) { AccessorLoc = L; }
3225
3226  /// getNumElements - Get the number of components being selected.
3227  unsigned getNumElements() const;
3228
3229  /// containsDuplicateElements - Return true if any element access is
3230  /// repeated.
3231  bool containsDuplicateElements() const;
3232
3233  /// getEncodedElementAccess - Encode the elements accessed into an llvm
3234  /// aggregate Constant of ConstantInt(s).
3235  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
3236
3237  virtual SourceRange getSourceRange() const {
3238    return SourceRange(getBase()->getLocStart(), AccessorLoc);
3239  }
3240
3241  /// isArrow - Return true if the base expression is a pointer to vector,
3242  /// return false if the base expression is a vector.
3243  bool isArrow() const;
3244
3245  static bool classof(const Stmt *T) {
3246    return T->getStmtClass() == ExtVectorElementExprClass;
3247  }
3248  static bool classof(const ExtVectorElementExpr *) { return true; }
3249
3250  // Iterators
3251  virtual child_iterator child_begin();
3252  virtual child_iterator child_end();
3253};
3254
3255
3256/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
3257/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
3258class BlockExpr : public Expr {
3259protected:
3260  BlockDecl *TheBlock;
3261  bool HasBlockDeclRefExprs;
3262public:
3263  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
3264    : Expr(BlockExprClass, ty, ty->isDependentType(), false),
3265      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
3266
3267  /// \brief Build an empty block expression.
3268  explicit BlockExpr(EmptyShell Empty) : Expr(BlockExprClass, Empty) { }
3269
3270  const BlockDecl *getBlockDecl() const { return TheBlock; }
3271  BlockDecl *getBlockDecl() { return TheBlock; }
3272  void setBlockDecl(BlockDecl *BD) { TheBlock = BD; }
3273
3274  // Convenience functions for probing the underlying BlockDecl.
3275  SourceLocation getCaretLocation() const;
3276  const Stmt *getBody() const;
3277  Stmt *getBody();
3278
3279  virtual SourceRange getSourceRange() const {
3280    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
3281  }
3282
3283  /// getFunctionType - Return the underlying function type for this block.
3284  const FunctionType *getFunctionType() const;
3285
3286  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
3287  /// inside of the block that reference values outside the block.
3288  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
3289  void setHasBlockDeclRefExprs(bool BDRE) { HasBlockDeclRefExprs = BDRE; }
3290
3291  static bool classof(const Stmt *T) {
3292    return T->getStmtClass() == BlockExprClass;
3293  }
3294  static bool classof(const BlockExpr *) { return true; }
3295
3296  // Iterators
3297  virtual child_iterator child_begin();
3298  virtual child_iterator child_end();
3299};
3300
3301/// BlockDeclRefExpr - A reference to a declared variable, function,
3302/// enum, etc.
3303class BlockDeclRefExpr : public Expr {
3304  ValueDecl *D;
3305  SourceLocation Loc;
3306  bool IsByRef : 1;
3307  bool ConstQualAdded : 1;
3308  Stmt *CopyConstructorVal;
3309public:
3310  // FIXME: Fix type/value dependence!
3311  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef,
3312                   bool constAdded = false,
3313                   Stmt *copyConstructorVal = 0)
3314  : Expr(BlockDeclRefExprClass, t, false, false), D(d), Loc(l), IsByRef(ByRef),
3315    ConstQualAdded(constAdded),  CopyConstructorVal(copyConstructorVal) {}
3316
3317  // \brief Build an empty reference to a declared variable in a
3318  // block.
3319  explicit BlockDeclRefExpr(EmptyShell Empty)
3320    : Expr(BlockDeclRefExprClass, Empty) { }
3321
3322  ValueDecl *getDecl() { return D; }
3323  const ValueDecl *getDecl() const { return D; }
3324  void setDecl(ValueDecl *VD) { D = VD; }
3325
3326  SourceLocation getLocation() const { return Loc; }
3327  void setLocation(SourceLocation L) { Loc = L; }
3328
3329  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
3330
3331  bool isByRef() const { return IsByRef; }
3332  void setByRef(bool BR) { IsByRef = BR; }
3333
3334  bool isConstQualAdded() const { return ConstQualAdded; }
3335  void setConstQualAdded(bool C) { ConstQualAdded = C; }
3336
3337  const Expr *getCopyConstructorExpr() const
3338    { return cast_or_null<Expr>(CopyConstructorVal); }
3339  Expr *getCopyConstructorExpr()
3340    { return cast_or_null<Expr>(CopyConstructorVal); }
3341  void setCopyConstructorExpr(Expr *E) { CopyConstructorVal = E; }
3342
3343  static bool classof(const Stmt *T) {
3344    return T->getStmtClass() == BlockDeclRefExprClass;
3345  }
3346  static bool classof(const BlockDeclRefExpr *) { return true; }
3347
3348  // Iterators
3349  virtual child_iterator child_begin();
3350  virtual child_iterator child_end();
3351};
3352
3353}  // end namespace clang
3354
3355#endif
3356