Expr.h revision db600c330a37b1c3ab4533310729910ee188f900
1//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the Expr interface and subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_EXPR_H
15#define LLVM_CLANG_AST_EXPR_H
16
17#include "clang/AST/APValue.h"
18#include "clang/AST/Stmt.h"
19#include "clang/AST/Type.h"
20#include "llvm/ADT/APSInt.h"
21#include "llvm/ADT/APFloat.h"
22#include "llvm/ADT/SmallVector.h"
23#include <vector>
24
25namespace clang {
26  class ASTContext;
27  class APValue;
28  class Decl;
29  class IdentifierInfo;
30  class ParmVarDecl;
31  class NamedDecl;
32  class ValueDecl;
33  class BlockDecl;
34  class CXXOperatorCallExpr;
35  class CXXMemberCallExpr;
36
37/// Expr - This represents one expression.  Note that Expr's are subclasses of
38/// Stmt.  This allows an expression to be transparently used any place a Stmt
39/// is required.
40///
41class Expr : public Stmt {
42  QualType TR;
43
44  /// TypeDependent - Whether this expression is type-dependent
45  /// (C++ [temp.dep.expr]).
46  bool TypeDependent : 1;
47
48  /// ValueDependent - Whether this expression is value-dependent
49  /// (C++ [temp.dep.constexpr]).
50  bool ValueDependent : 1;
51
52protected:
53  // FIXME: Eventually, this constructor should go away and we should
54  // require every subclass to provide type/value-dependence
55  // information.
56  Expr(StmtClass SC, QualType T)
57    : Stmt(SC), TypeDependent(false), ValueDependent(false) {
58    setType(T);
59  }
60
61  Expr(StmtClass SC, QualType T, bool TD, bool VD)
62    : Stmt(SC), TypeDependent(TD), ValueDependent(VD) {
63    setType(T);
64  }
65
66  /// \brief Construct an empty expression.
67  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
68
69public:
70  QualType getType() const { return TR; }
71  void setType(QualType t) {
72    // In C++, the type of an expression is always adjusted so that it
73    // will not have reference type an expression will never have
74    // reference type (C++ [expr]p6). Use
75    // QualType::getNonReferenceType() to retrieve the non-reference
76    // type. Additionally, inspect Expr::isLvalue to determine whether
77    // an expression that is adjusted in this manner should be
78    // considered an lvalue.
79    assert((TR.isNull() || !TR->isReferenceType()) &&
80           "Expressions can't have reference type");
81
82    TR = t;
83  }
84
85  /// isValueDependent - Determines whether this expression is
86  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
87  /// array bound of "Chars" in the following example is
88  /// value-dependent.
89  /// @code
90  /// template<int Size, char (&Chars)[Size]> struct meta_string;
91  /// @endcode
92  bool isValueDependent() const { return ValueDependent; }
93
94  /// \brief Set whether this expression is value-dependent or not.
95  void setValueDependent(bool VD) { ValueDependent = VD; }
96
97  /// isTypeDependent - Determines whether this expression is
98  /// type-dependent (C++ [temp.dep.expr]), which means that its type
99  /// could change from one template instantiation to the next. For
100  /// example, the expressions "x" and "x + y" are type-dependent in
101  /// the following code, but "y" is not type-dependent:
102  /// @code
103  /// template<typename T>
104  /// void add(T x, int y) {
105  ///   x + y;
106  /// }
107  /// @endcode
108  bool isTypeDependent() const { return TypeDependent; }
109
110  /// \brief Set whether this expression is type-dependent or not.
111  void setTypeDependent(bool TD) { TypeDependent = TD; }
112
113  /// SourceLocation tokens are not useful in isolation - they are low level
114  /// value objects created/interpreted by SourceManager. We assume AST
115  /// clients will have a pointer to the respective SourceManager.
116  virtual SourceRange getSourceRange() const = 0;
117
118  /// getExprLoc - Return the preferred location for the arrow when diagnosing
119  /// a problem with a generic expression.
120  virtual SourceLocation getExprLoc() const { return getLocStart(); }
121
122  /// isUnusedResultAWarning - Return true if this immediate expression should
123  /// be warned about if the result is unused.  If so, fill in Loc and Ranges
124  /// with location to warn on and the source range[s] to report with the
125  /// warning.
126  bool isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
127                              SourceRange &R2) const;
128
129  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
130  /// incomplete type other than void. Nonarray expressions that can be lvalues:
131  ///  - name, where name must be a variable
132  ///  - e[i]
133  ///  - (e), where e must be an lvalue
134  ///  - e.name, where e must be an lvalue
135  ///  - e->name
136  ///  - *e, the type of e cannot be a function type
137  ///  - string-constant
138  ///  - reference type [C++ [expr]]
139  ///
140  enum isLvalueResult {
141    LV_Valid,
142    LV_NotObjectType,
143    LV_IncompleteVoidType,
144    LV_DuplicateVectorComponents,
145    LV_InvalidExpression,
146    LV_MemberFunction
147  };
148  isLvalueResult isLvalue(ASTContext &Ctx) const;
149
150  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
151  /// does not have an incomplete type, does not have a const-qualified type,
152  /// and if it is a structure or union, does not have any member (including,
153  /// recursively, any member or element of all contained aggregates or unions)
154  /// with a const-qualified type.
155  ///
156  /// \param Loc [in] [out] - A source location which *may* be filled
157  /// in with the location of the expression making this a
158  /// non-modifiable lvalue, if specified.
159  enum isModifiableLvalueResult {
160    MLV_Valid,
161    MLV_NotObjectType,
162    MLV_IncompleteVoidType,
163    MLV_DuplicateVectorComponents,
164    MLV_InvalidExpression,
165    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
166    MLV_IncompleteType,
167    MLV_ConstQualified,
168    MLV_ArrayType,
169    MLV_NotBlockQualified,
170    MLV_ReadonlyProperty,
171    MLV_NoSetterProperty,
172    MLV_MemberFunction
173  };
174  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx,
175                                              SourceLocation *Loc = 0) const;
176
177  bool isBitField();
178
179  /// getIntegerConstantExprValue() - Return the value of an integer
180  /// constant expression. The expression must be a valid integer
181  /// constant expression as determined by isIntegerConstantExpr.
182  llvm::APSInt getIntegerConstantExprValue(ASTContext &Ctx) const {
183    llvm::APSInt X;
184    bool success = isIntegerConstantExpr(X, Ctx);
185    success = success;
186    assert(success && "Illegal argument to getIntegerConstantExpr");
187    return X;
188  }
189
190  /// isIntegerConstantExpr - Return true if this expression is a valid integer
191  /// constant expression, and, if so, return its value in Result.  If not a
192  /// valid i-c-e, return false and fill in Loc (if specified) with the location
193  /// of the invalid expression.
194  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
195                             SourceLocation *Loc = 0,
196                             bool isEvaluated = true) const;
197  bool isIntegerConstantExprInternal(llvm::APSInt &Result, ASTContext &Ctx,
198                             SourceLocation *Loc = 0,
199                             bool isEvaluated = true) const;
200  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
201    llvm::APSInt X;
202    return isIntegerConstantExpr(X, Ctx, Loc);
203  }
204  /// isConstantInitializer - Returns true if this expression is a constant
205  /// initializer, which can be emitted at compile-time.
206  bool isConstantInitializer(ASTContext &Ctx) const;
207
208  /// EvalResult is a struct with detailed info about an evaluated expression.
209  struct EvalResult {
210    /// Val - This is the value the expression can be folded to.
211    APValue Val;
212
213    /// HasSideEffects - Whether the evaluated expression has side effects.
214    /// For example, (f() && 0) can be folded, but it still has side effects.
215    bool HasSideEffects;
216
217    /// Diag - If the expression is unfoldable, then Diag contains a note
218    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
219    /// position for the error, and DiagExpr is the expression that caused
220    /// the error.
221    /// If the expression is foldable, but not an integer constant expression,
222    /// Diag contains a note diagnostic that describes why it isn't an integer
223    /// constant expression. If the expression *is* an integer constant
224    /// expression, then Diag will be zero.
225    unsigned Diag;
226    const Expr *DiagExpr;
227    SourceLocation DiagLoc;
228
229    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
230  };
231
232  /// Evaluate - Return true if this is a constant which we can fold using
233  /// any crazy technique (that has nothing to do with language standards) that
234  /// we want to.  If this function returns true, it returns the folded constant
235  /// in Result.
236  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
237
238  /// isEvaluatable - Call Evaluate to see if this expression can be constant
239  /// folded, but discard the result.
240  bool isEvaluatable(ASTContext &Ctx) const;
241
242  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
243  /// must be called on an expression that constant folds to an integer.
244  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
245
246  /// EvaluateAsLValue - Evaluate an expression to see if it's a valid LValue.
247  bool EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const;
248
249  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
250  /// integer constant expression with the value zero, or if this is one that is
251  /// cast to void*.
252  bool isNullPointerConstant(ASTContext &Ctx) const;
253
254  /// hasGlobalStorage - Return true if this expression has static storage
255  /// duration.  This means that the address of this expression is a link-time
256  /// constant.
257  bool hasGlobalStorage() const;
258
259  /// isOBJCGCCandidate - Return true if this expression may be used in a read/
260  /// write barrier.
261  bool isOBJCGCCandidate() const;
262
263  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
264  ///  its subexpression.  If that subexpression is also a ParenExpr,
265  ///  then this method recursively returns its subexpression, and so forth.
266  ///  Otherwise, the method returns the current Expr.
267  Expr* IgnoreParens();
268
269  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
270  /// or CastExprs, returning their operand.
271  Expr *IgnoreParenCasts();
272
273  /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
274  /// value (including ptr->int casts of the same size).  Strip off any
275  /// ParenExpr or CastExprs, returning their operand.
276  Expr *IgnoreParenNoopCasts(ASTContext &Ctx);
277
278  const Expr* IgnoreParens() const {
279    return const_cast<Expr*>(this)->IgnoreParens();
280  }
281  const Expr *IgnoreParenCasts() const {
282    return const_cast<Expr*>(this)->IgnoreParenCasts();
283  }
284  const Expr *IgnoreParenNoopCasts(ASTContext &Ctx) const {
285    return const_cast<Expr*>(this)->IgnoreParenNoopCasts(Ctx);
286  }
287
288  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
289  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
290
291  static bool classof(const Stmt *T) {
292    return T->getStmtClass() >= firstExprConstant &&
293           T->getStmtClass() <= lastExprConstant;
294  }
295  static bool classof(const Expr *) { return true; }
296
297  static inline Expr* Create(llvm::Deserializer& D, ASTContext& C) {
298    return cast<Expr>(Stmt::Create(D, C));
299  }
300};
301
302
303//===----------------------------------------------------------------------===//
304// Primary Expressions.
305//===----------------------------------------------------------------------===//
306
307/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
308/// enum, etc.
309class DeclRefExpr : public Expr {
310  NamedDecl *D;
311  SourceLocation Loc;
312
313protected:
314  // FIXME: Eventually, this constructor will go away and all subclasses
315  // will have to provide the type- and value-dependent flags.
316  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) :
317    Expr(SC, t), D(d), Loc(l) {}
318
319  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD,
320              bool VD) :
321    Expr(SC, t, TD, VD), D(d), Loc(l) {}
322
323public:
324  // FIXME: Eventually, this constructor will go away and all clients
325  // will have to provide the type- and value-dependent flags.
326  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) :
327    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
328
329  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) :
330    Expr(DeclRefExprClass, t, TD, VD), D(d), Loc(l) {}
331
332  /// \brief Construct an empty declaration reference expression.
333  explicit DeclRefExpr(EmptyShell Empty)
334    : Expr(DeclRefExprClass, Empty) { }
335
336  NamedDecl *getDecl() { return D; }
337  const NamedDecl *getDecl() const { return D; }
338  void setDecl(NamedDecl *NewD) { D = NewD; }
339
340  SourceLocation getLocation() const { return Loc; }
341  void setLocation(SourceLocation L) { Loc = L; }
342  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
343
344  static bool classof(const Stmt *T) {
345    return T->getStmtClass() == DeclRefExprClass ||
346           T->getStmtClass() == CXXConditionDeclExprClass ||
347           T->getStmtClass() == QualifiedDeclRefExprClass;
348  }
349  static bool classof(const DeclRefExpr *) { return true; }
350
351  // Iterators
352  virtual child_iterator child_begin();
353  virtual child_iterator child_end();
354
355  virtual void EmitImpl(llvm::Serializer& S) const;
356  static DeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
357};
358
359/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
360class PredefinedExpr : public Expr {
361public:
362  enum IdentType {
363    Func,
364    Function,
365    PrettyFunction
366  };
367
368private:
369  SourceLocation Loc;
370  IdentType Type;
371public:
372  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
373    : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {}
374
375  /// \brief Construct an empty predefined expression.
376  explicit PredefinedExpr(EmptyShell Empty)
377    : Expr(PredefinedExprClass, Empty) { }
378
379  IdentType getIdentType() const { return Type; }
380  void setIdentType(IdentType IT) { Type = IT; }
381
382  SourceLocation getLocation() const { return Loc; }
383  void setLocation(SourceLocation L) { Loc = L; }
384
385  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
386
387  static bool classof(const Stmt *T) {
388    return T->getStmtClass() == PredefinedExprClass;
389  }
390  static bool classof(const PredefinedExpr *) { return true; }
391
392  // Iterators
393  virtual child_iterator child_begin();
394  virtual child_iterator child_end();
395
396  virtual void EmitImpl(llvm::Serializer& S) const;
397  static PredefinedExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
398};
399
400class IntegerLiteral : public Expr {
401  llvm::APInt Value;
402  SourceLocation Loc;
403public:
404  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
405  // or UnsignedLongLongTy
406  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
407    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
408    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
409  }
410
411  /// \brief Construct an empty integer literal.
412  explicit IntegerLiteral(EmptyShell Empty)
413    : Expr(IntegerLiteralClass, Empty) { }
414
415  IntegerLiteral* Clone(ASTContext &C) const;
416
417  const llvm::APInt &getValue() const { return Value; }
418  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
419
420  /// \brief Retrieve the location of the literal.
421  SourceLocation getLocation() const { return Loc; }
422
423  void setValue(const llvm::APInt &Val) { Value = Val; }
424  void setLocation(SourceLocation Location) { Loc = Location; }
425
426  static bool classof(const Stmt *T) {
427    return T->getStmtClass() == IntegerLiteralClass;
428  }
429  static bool classof(const IntegerLiteral *) { return true; }
430
431  // Iterators
432  virtual child_iterator child_begin();
433  virtual child_iterator child_end();
434
435  virtual void EmitImpl(llvm::Serializer& S) const;
436  static IntegerLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
437};
438
439class CharacterLiteral : public Expr {
440  unsigned Value;
441  SourceLocation Loc;
442  bool IsWide;
443public:
444  // type should be IntTy
445  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
446    : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) {
447  }
448
449  /// \brief Construct an empty character literal.
450  CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { }
451
452  SourceLocation getLoc() const { return Loc; }
453  bool isWide() const { return IsWide; }
454
455  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
456
457  unsigned getValue() const { return Value; }
458
459  void setLocation(SourceLocation Location) { Loc = Location; }
460  void setWide(bool W) { IsWide = W; }
461  void setValue(unsigned Val) { Value = Val; }
462
463  static bool classof(const Stmt *T) {
464    return T->getStmtClass() == CharacterLiteralClass;
465  }
466  static bool classof(const CharacterLiteral *) { return true; }
467
468  // Iterators
469  virtual child_iterator child_begin();
470  virtual child_iterator child_end();
471
472  virtual void EmitImpl(llvm::Serializer& S) const;
473  static CharacterLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
474};
475
476class FloatingLiteral : public Expr {
477  llvm::APFloat Value;
478  bool IsExact : 1;
479  SourceLocation Loc;
480public:
481  FloatingLiteral(const llvm::APFloat &V, bool* isexact,
482                  QualType Type, SourceLocation L)
483    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {}
484
485  /// \brief Construct an empty floating-point literal.
486  FloatingLiteral(EmptyShell Empty)
487    : Expr(FloatingLiteralClass, Empty), Value(0.0) { }
488
489  const llvm::APFloat &getValue() const { return Value; }
490  void setValue(const llvm::APFloat &Val) { Value = Val; }
491
492  bool isExact() const { return IsExact; }
493  void setExact(bool E) { IsExact = E; }
494
495  /// getValueAsApproximateDouble - This returns the value as an inaccurate
496  /// double.  Note that this may cause loss of precision, but is useful for
497  /// debugging dumps, etc.
498  double getValueAsApproximateDouble() const;
499
500  SourceLocation getLocation() const { return Loc; }
501  void setLocation(SourceLocation L) { Loc = L; }
502
503  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
504
505  static bool classof(const Stmt *T) {
506    return T->getStmtClass() == FloatingLiteralClass;
507  }
508  static bool classof(const FloatingLiteral *) { return true; }
509
510  // Iterators
511  virtual child_iterator child_begin();
512  virtual child_iterator child_end();
513
514  virtual void EmitImpl(llvm::Serializer& S) const;
515  static FloatingLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
516};
517
518/// ImaginaryLiteral - We support imaginary integer and floating point literals,
519/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
520/// IntegerLiteral classes.  Instances of this class always have a Complex type
521/// whose element type matches the subexpression.
522///
523class ImaginaryLiteral : public Expr {
524  Stmt *Val;
525public:
526  ImaginaryLiteral(Expr *val, QualType Ty)
527    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
528
529  const Expr *getSubExpr() const { return cast<Expr>(Val); }
530  Expr *getSubExpr() { return cast<Expr>(Val); }
531
532  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
533  static bool classof(const Stmt *T) {
534    return T->getStmtClass() == ImaginaryLiteralClass;
535  }
536  static bool classof(const ImaginaryLiteral *) { return true; }
537
538  // Iterators
539  virtual child_iterator child_begin();
540  virtual child_iterator child_end();
541
542  virtual void EmitImpl(llvm::Serializer& S) const;
543  static ImaginaryLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
544};
545
546/// StringLiteral - This represents a string literal expression, e.g. "foo"
547/// or L"bar" (wide strings).  The actual string is returned by getStrData()
548/// is NOT null-terminated, and the length of the string is determined by
549/// calling getByteLength().  The C type for a string is always a
550/// ConstantArrayType.  In C++, the char type is const qualified, in C it is
551/// not.
552///
553/// Note that strings in C can be formed by concatenation of multiple string
554/// literal pptokens in translation phase #6.  This keeps track of the locations
555/// of each of these pieces.
556///
557/// Strings in C can also be truncated and extended by assigning into arrays,
558/// e.g. with constructs like:
559///   char X[2] = "foobar";
560/// In this case, getByteLength() will return 6, but the string literal will
561/// have type "char[2]".
562class StringLiteral : public Expr {
563  const char *StrData;
564  unsigned ByteLength;
565  bool IsWide;
566  unsigned NumConcatenated;
567  SourceLocation TokLocs[1];
568
569  StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {}
570public:
571  /// This is the "fully general" constructor that allows representation of
572  /// strings formed from multiple concatenated tokens.
573  static StringLiteral *Create(ASTContext &C, const char *StrData,
574                               unsigned ByteLength, bool Wide, QualType Ty,
575                               const SourceLocation *Loc, unsigned NumStrs);
576
577  /// Simple constructor for string literals made from one token.
578  static StringLiteral *Create(ASTContext &C, const char *StrData,
579                               unsigned ByteLength,
580                               bool Wide, QualType Ty, SourceLocation Loc) {
581    return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
582  }
583
584  StringLiteral* Clone(ASTContext &C) const;
585  void Destroy(ASTContext &C);
586
587  const char *getStrData() const { return StrData; }
588  unsigned getByteLength() const { return ByteLength; }
589  bool isWide() const { return IsWide; }
590  bool containsNonAsciiOrNull() const {
591    for (unsigned i = 0; i < getByteLength(); ++i)
592      if (!isascii(getStrData()[i]) || !getStrData()[i])
593        return true;
594    return false;
595  }
596  /// getNumConcatenated - Get the number of string literal tokens that were
597  /// concatenated in translation phase #6 to form this string literal.
598  unsigned getNumConcatenated() const { return NumConcatenated; }
599
600  SourceLocation getStrTokenLoc(unsigned TokNum) const {
601    assert(TokNum < NumConcatenated && "Invalid tok number");
602    return TokLocs[TokNum];
603  }
604
605  typedef const SourceLocation *tokloc_iterator;
606  tokloc_iterator tokloc_begin() const { return TokLocs; }
607  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
608
609  virtual SourceRange getSourceRange() const {
610    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
611  }
612  static bool classof(const Stmt *T) {
613    return T->getStmtClass() == StringLiteralClass;
614  }
615  static bool classof(const StringLiteral *) { return true; }
616
617  // Iterators
618  virtual child_iterator child_begin();
619  virtual child_iterator child_end();
620
621  virtual void EmitImpl(llvm::Serializer& S) const;
622  static StringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
623};
624
625/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
626/// AST node is only formed if full location information is requested.
627class ParenExpr : public Expr {
628  SourceLocation L, R;
629  Stmt *Val;
630public:
631  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
632    : Expr(ParenExprClass, val->getType(),
633           val->isTypeDependent(), val->isValueDependent()),
634      L(l), R(r), Val(val) {}
635
636  /// \brief Construct an empty parenthesized expression.
637  explicit ParenExpr(EmptyShell Empty)
638    : Expr(ParenExprClass, Empty) { }
639
640  const Expr *getSubExpr() const { return cast<Expr>(Val); }
641  Expr *getSubExpr() { return cast<Expr>(Val); }
642  void setSubExpr(Expr *E) { Val = E; }
643
644  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
645
646  /// \brief Get the location of the left parentheses '('.
647  SourceLocation getLParen() const { return L; }
648  void setLParen(SourceLocation Loc) { L = Loc; }
649
650  /// \brief Get the location of the right parentheses ')'.
651  SourceLocation getRParen() const { return R; }
652  void setRParen(SourceLocation Loc) { R = Loc; }
653
654  static bool classof(const Stmt *T) {
655    return T->getStmtClass() == ParenExprClass;
656  }
657  static bool classof(const ParenExpr *) { return true; }
658
659  // Iterators
660  virtual child_iterator child_begin();
661  virtual child_iterator child_end();
662
663  virtual void EmitImpl(llvm::Serializer& S) const;
664  static ParenExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
665};
666
667
668/// UnaryOperator - This represents the unary-expression's (except sizeof and
669/// alignof), the postinc/postdec operators from postfix-expression, and various
670/// extensions.
671///
672/// Notes on various nodes:
673///
674/// Real/Imag - These return the real/imag part of a complex operand.  If
675///   applied to a non-complex value, the former returns its operand and the
676///   later returns zero in the type of the operand.
677///
678/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
679///   subexpression is a compound literal with the various MemberExpr and
680///   ArraySubscriptExpr's applied to it.
681///
682class UnaryOperator : public Expr {
683public:
684  // Note that additions to this should also update the StmtVisitor class.
685  enum Opcode {
686    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
687    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
688    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
689    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
690    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
691    Real, Imag,       // "__real expr"/"__imag expr" Extension.
692    Extension,        // __extension__ marker.
693    OffsetOf          // __builtin_offsetof
694  };
695private:
696  Stmt *Val;
697  Opcode Opc;
698  SourceLocation Loc;
699public:
700
701  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
702    : Expr(UnaryOperatorClass, type,
703           input->isTypeDependent() && opc != OffsetOf,
704           input->isValueDependent()),
705      Val(input), Opc(opc), Loc(l) {}
706
707  Opcode getOpcode() const { return Opc; }
708  Expr *getSubExpr() const { return cast<Expr>(Val); }
709
710  /// getOperatorLoc - Return the location of the operator.
711  SourceLocation getOperatorLoc() const { return Loc; }
712
713  /// isPostfix - Return true if this is a postfix operation, like x++.
714  static bool isPostfix(Opcode Op) {
715    return Op == PostInc || Op == PostDec;
716  }
717
718  /// isPostfix - Return true if this is a prefix operation, like --x.
719  static bool isPrefix(Opcode Op) {
720    return Op == PreInc || Op == PreDec;
721  }
722
723  bool isPrefix() const { return isPrefix(Opc); }
724  bool isPostfix() const { return isPostfix(Opc); }
725  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
726  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
727  bool isOffsetOfOp() const { return Opc == OffsetOf; }
728  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
729
730  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
731  /// corresponds to, e.g. "sizeof" or "[pre]++"
732  static const char *getOpcodeStr(Opcode Op);
733
734  /// \brief Retrieve the unary opcode that corresponds to the given
735  /// overloaded operator.
736  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
737
738  /// \brief Retrieve the overloaded operator kind that corresponds to
739  /// the given unary opcode.
740  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
741
742  virtual SourceRange getSourceRange() const {
743    if (isPostfix())
744      return SourceRange(Val->getLocStart(), Loc);
745    else
746      return SourceRange(Loc, Val->getLocEnd());
747  }
748  virtual SourceLocation getExprLoc() const { return Loc; }
749
750  static bool classof(const Stmt *T) {
751    return T->getStmtClass() == UnaryOperatorClass;
752  }
753  static bool classof(const UnaryOperator *) { return true; }
754
755  // Iterators
756  virtual child_iterator child_begin();
757  virtual child_iterator child_end();
758
759  virtual void EmitImpl(llvm::Serializer& S) const;
760  static UnaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
761};
762
763/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
764/// types and expressions.
765class SizeOfAlignOfExpr : public Expr {
766  bool isSizeof : 1;  // true if sizeof, false if alignof.
767  bool isType : 1;    // true if operand is a type, false if an expression
768  union {
769    void *Ty;
770    Stmt *Ex;
771  } Argument;
772  SourceLocation OpLoc, RParenLoc;
773public:
774  SizeOfAlignOfExpr(bool issizeof, QualType T,
775                    QualType resultType, SourceLocation op,
776                    SourceLocation rp) :
777      Expr(SizeOfAlignOfExprClass, resultType,
778           false, // Never type-dependent (C++ [temp.dep.expr]p3).
779           // Value-dependent if the argument is type-dependent.
780           T->isDependentType()),
781      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
782    Argument.Ty = T.getAsOpaquePtr();
783  }
784
785  SizeOfAlignOfExpr(bool issizeof, Expr *E,
786                    QualType resultType, SourceLocation op,
787                    SourceLocation rp) :
788      Expr(SizeOfAlignOfExprClass, resultType,
789           false, // Never type-dependent (C++ [temp.dep.expr]p3).
790           // Value-dependent if the argument is type-dependent.
791           E->isTypeDependent()),
792      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
793    Argument.Ex = E;
794  }
795
796  virtual void Destroy(ASTContext& C);
797
798  bool isSizeOf() const { return isSizeof; }
799  bool isArgumentType() const { return isType; }
800  QualType getArgumentType() const {
801    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
802    return QualType::getFromOpaquePtr(Argument.Ty);
803  }
804  Expr *getArgumentExpr() {
805    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
806    return static_cast<Expr*>(Argument.Ex);
807  }
808  const Expr *getArgumentExpr() const {
809    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
810  }
811
812  /// Gets the argument type, or the type of the argument expression, whichever
813  /// is appropriate.
814  QualType getTypeOfArgument() const {
815    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
816  }
817
818  SourceLocation getOperatorLoc() const { return OpLoc; }
819
820  virtual SourceRange getSourceRange() const {
821    return SourceRange(OpLoc, RParenLoc);
822  }
823
824  static bool classof(const Stmt *T) {
825    return T->getStmtClass() == SizeOfAlignOfExprClass;
826  }
827  static bool classof(const SizeOfAlignOfExpr *) { return true; }
828
829  // Iterators
830  virtual child_iterator child_begin();
831  virtual child_iterator child_end();
832
833  virtual void EmitImpl(llvm::Serializer& S) const;
834  static SizeOfAlignOfExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
835};
836
837//===----------------------------------------------------------------------===//
838// Postfix Operators.
839//===----------------------------------------------------------------------===//
840
841/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
842class ArraySubscriptExpr : public Expr {
843  enum { LHS, RHS, END_EXPR=2 };
844  Stmt* SubExprs[END_EXPR];
845  SourceLocation RBracketLoc;
846public:
847  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
848                     SourceLocation rbracketloc)
849  : Expr(ArraySubscriptExprClass, t,
850         lhs->isTypeDependent() || rhs->isTypeDependent(),
851         lhs->isValueDependent() || rhs->isValueDependent()),
852    RBracketLoc(rbracketloc) {
853    SubExprs[LHS] = lhs;
854    SubExprs[RHS] = rhs;
855  }
856
857  /// An array access can be written A[4] or 4[A] (both are equivalent).
858  /// - getBase() and getIdx() always present the normalized view: A[4].
859  ///    In this case getBase() returns "A" and getIdx() returns "4".
860  /// - getLHS() and getRHS() present the syntactic view. e.g. for
861  ///    4[A] getLHS() returns "4".
862  /// Note: Because vector element access is also written A[4] we must
863  /// predicate the format conversion in getBase and getIdx only on the
864  /// the type of the RHS, as it is possible for the LHS to be a vector of
865  /// integer type
866  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
867  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
868
869  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
870  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
871
872  Expr *getBase() {
873    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
874  }
875
876  const Expr *getBase() const {
877    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
878  }
879
880  Expr *getIdx() {
881    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
882  }
883
884  const Expr *getIdx() const {
885    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
886  }
887
888  virtual SourceRange getSourceRange() const {
889    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
890  }
891
892  SourceLocation getRBracketLoc() const { return RBracketLoc; }
893  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
894
895  static bool classof(const Stmt *T) {
896    return T->getStmtClass() == ArraySubscriptExprClass;
897  }
898  static bool classof(const ArraySubscriptExpr *) { return true; }
899
900  // Iterators
901  virtual child_iterator child_begin();
902  virtual child_iterator child_end();
903
904  virtual void EmitImpl(llvm::Serializer& S) const;
905  static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
906};
907
908
909/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
910/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
911/// while its subclasses may represent alternative syntax that (semantically)
912/// results in a function call. For example, CXXOperatorCallExpr is
913/// a subclass for overloaded operator calls that use operator syntax, e.g.,
914/// "str1 + str2" to resolve to a function call.
915class CallExpr : public Expr {
916  enum { FN=0, ARGS_START=1 };
917  Stmt **SubExprs;
918  unsigned NumArgs;
919  SourceLocation RParenLoc;
920
921  // This version of the ctor is for deserialization.
922  CallExpr(StmtClass SC, Stmt** subexprs, unsigned numargs, QualType t,
923           SourceLocation rparenloc)
924  : Expr(SC,t), SubExprs(subexprs),
925    NumArgs(numargs), RParenLoc(rparenloc) {}
926
927protected:
928  // This version of the constructor is for derived classes.
929  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
930           QualType t, SourceLocation rparenloc);
931
932public:
933  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
934           SourceLocation rparenloc);
935
936  ~CallExpr() {}
937
938  void Destroy(ASTContext& C);
939
940  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
941  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
942  void setCallee(Expr *F) { SubExprs[FN] = F; }
943
944  /// getNumArgs - Return the number of actual arguments to this call.
945  ///
946  unsigned getNumArgs() const { return NumArgs; }
947
948  /// getArg - Return the specified argument.
949  Expr *getArg(unsigned Arg) {
950    assert(Arg < NumArgs && "Arg access out of range!");
951    return cast<Expr>(SubExprs[Arg+ARGS_START]);
952  }
953  const Expr *getArg(unsigned Arg) const {
954    assert(Arg < NumArgs && "Arg access out of range!");
955    return cast<Expr>(SubExprs[Arg+ARGS_START]);
956  }
957
958  // FIXME: Why is this needed?  Why not just create the CallExpr with the
959  // corect number of arguments?  It makes the ASTs less brittle.
960  /// setArg - Set the specified argument.
961  void setArg(unsigned Arg, Expr *ArgExpr) {
962    assert(Arg < NumArgs && "Arg access out of range!");
963    SubExprs[Arg+ARGS_START] = ArgExpr;
964  }
965
966  // FIXME: It would be great to just get rid of this.  There is only one
967  // callee of this method, and it probably could be refactored to not use
968  // this method and instead just create a CallExpr with the right number of
969  // arguments.
970  /// setNumArgs - This changes the number of arguments present in this call.
971  /// Any orphaned expressions are deleted by this, and any new operands are set
972  /// to null.
973  void setNumArgs(ASTContext& C, unsigned NumArgs);
974
975  typedef ExprIterator arg_iterator;
976  typedef ConstExprIterator const_arg_iterator;
977
978  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
979  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
980  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
981  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
982
983  /// getNumCommas - Return the number of commas that must have been present in
984  /// this function call.
985  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
986
987  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
988  /// not, return 0.
989  unsigned isBuiltinCall(ASTContext &Context) const;
990
991  SourceLocation getRParenLoc() const { return RParenLoc; }
992
993  virtual SourceRange getSourceRange() const {
994    return SourceRange(getCallee()->getLocStart(), RParenLoc);
995  }
996
997  static bool classof(const Stmt *T) {
998    return T->getStmtClass() == CallExprClass ||
999           T->getStmtClass() == CXXOperatorCallExprClass ||
1000           T->getStmtClass() == CXXMemberCallExprClass;
1001  }
1002  static bool classof(const CallExpr *) { return true; }
1003  static bool classof(const CXXOperatorCallExpr *) { return true; }
1004  static bool classof(const CXXMemberCallExpr *) { return true; }
1005
1006  // Iterators
1007  virtual child_iterator child_begin();
1008  virtual child_iterator child_end();
1009
1010  virtual void EmitImpl(llvm::Serializer& S) const;
1011  static CallExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C,
1012                              StmtClass SC);
1013};
1014
1015/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
1016///
1017class MemberExpr : public Expr {
1018  /// Base - the expression for the base pointer or structure references.  In
1019  /// X.F, this is "X".
1020  Stmt *Base;
1021
1022  /// MemberDecl - This is the decl being referenced by the field/member name.
1023  /// In X.F, this is the decl referenced by F.
1024  NamedDecl *MemberDecl;
1025
1026  /// MemberLoc - This is the location of the member name.
1027  SourceLocation MemberLoc;
1028
1029  /// IsArrow - True if this is "X->F", false if this is "X.F".
1030  bool IsArrow;
1031public:
1032  MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l,
1033             QualType ty)
1034    : Expr(MemberExprClass, ty),
1035      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
1036
1037  void setBase(Expr *E) { Base = E; }
1038  Expr *getBase() const { return cast<Expr>(Base); }
1039
1040  /// \brief Retrieve the member declaration to which this expression refers.
1041  ///
1042  /// The returned declaration will either be a FieldDecl or (in C++)
1043  /// a CXXMethodDecl.
1044  NamedDecl *getMemberDecl() const { return MemberDecl; }
1045  void setMemberDecl(NamedDecl *D) { MemberDecl = D; }
1046  bool isArrow() const { return IsArrow; }
1047
1048  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1049  /// location of 'F'.
1050  SourceLocation getMemberLoc() const { return MemberLoc; }
1051
1052  virtual SourceRange getSourceRange() const {
1053    return SourceRange(getBase()->getLocStart(), MemberLoc);
1054  }
1055
1056  virtual SourceLocation getExprLoc() const { return MemberLoc; }
1057
1058  static bool classof(const Stmt *T) {
1059    return T->getStmtClass() == MemberExprClass;
1060  }
1061  static bool classof(const MemberExpr *) { return true; }
1062
1063  // Iterators
1064  virtual child_iterator child_begin();
1065  virtual child_iterator child_end();
1066
1067  virtual void EmitImpl(llvm::Serializer& S) const;
1068  static MemberExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1069};
1070
1071/// CompoundLiteralExpr - [C99 6.5.2.5]
1072///
1073class CompoundLiteralExpr : public Expr {
1074  /// LParenLoc - If non-null, this is the location of the left paren in a
1075  /// compound literal like "(int){4}".  This can be null if this is a
1076  /// synthesized compound expression.
1077  SourceLocation LParenLoc;
1078  Stmt *Init;
1079  bool FileScope;
1080public:
1081  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init,
1082                      bool fileScope)
1083    : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
1084      FileScope(fileScope) {}
1085
1086  const Expr *getInitializer() const { return cast<Expr>(Init); }
1087  Expr *getInitializer() { return cast<Expr>(Init); }
1088
1089  bool isFileScope() const { return FileScope; }
1090
1091  SourceLocation getLParenLoc() const { return LParenLoc; }
1092
1093  virtual SourceRange getSourceRange() const {
1094    // FIXME: Init should never be null.
1095    if (!Init)
1096      return SourceRange();
1097    if (LParenLoc.isInvalid())
1098      return Init->getSourceRange();
1099    return SourceRange(LParenLoc, Init->getLocEnd());
1100  }
1101
1102  static bool classof(const Stmt *T) {
1103    return T->getStmtClass() == CompoundLiteralExprClass;
1104  }
1105  static bool classof(const CompoundLiteralExpr *) { return true; }
1106
1107  // Iterators
1108  virtual child_iterator child_begin();
1109  virtual child_iterator child_end();
1110
1111  virtual void EmitImpl(llvm::Serializer& S) const;
1112  static CompoundLiteralExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1113};
1114
1115/// CastExpr - Base class for type casts, including both implicit
1116/// casts (ImplicitCastExpr) and explicit casts that have some
1117/// representation in the source code (ExplicitCastExpr's derived
1118/// classes).
1119class CastExpr : public Expr {
1120  Stmt *Op;
1121protected:
1122  CastExpr(StmtClass SC, QualType ty, Expr *op) :
1123    Expr(SC, ty,
1124         // Cast expressions are type-dependent if the type is
1125         // dependent (C++ [temp.dep.expr]p3).
1126         ty->isDependentType(),
1127         // Cast expressions are value-dependent if the type is
1128         // dependent or if the subexpression is value-dependent.
1129         ty->isDependentType() || (op && op->isValueDependent())),
1130    Op(op) {}
1131
1132  /// \brief Construct an empty cast.
1133  CastExpr(StmtClass SC, EmptyShell Empty)
1134    : Expr(SC, Empty) { }
1135
1136public:
1137  Expr *getSubExpr() { return cast<Expr>(Op); }
1138  const Expr *getSubExpr() const { return cast<Expr>(Op); }
1139  void setSubExpr(Expr *E) { Op = E; }
1140
1141  static bool classof(const Stmt *T) {
1142    StmtClass SC = T->getStmtClass();
1143    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
1144      return true;
1145
1146    if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass)
1147      return true;
1148
1149    return false;
1150  }
1151  static bool classof(const CastExpr *) { return true; }
1152
1153  // Iterators
1154  virtual child_iterator child_begin();
1155  virtual child_iterator child_end();
1156};
1157
1158/// ImplicitCastExpr - Allows us to explicitly represent implicit type
1159/// conversions, which have no direct representation in the original
1160/// source code. For example: converting T[]->T*, void f()->void
1161/// (*f)(), float->double, short->int, etc.
1162///
1163/// In C, implicit casts always produce rvalues. However, in C++, an
1164/// implicit cast whose result is being bound to a reference will be
1165/// an lvalue. For example:
1166///
1167/// @code
1168/// class Base { };
1169/// class Derived : public Base { };
1170/// void f(Derived d) {
1171///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1172/// }
1173/// @endcode
1174class ImplicitCastExpr : public CastExpr {
1175  /// LvalueCast - Whether this cast produces an lvalue.
1176  bool LvalueCast;
1177
1178public:
1179  ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) :
1180    CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) { }
1181
1182  /// \brief Construct an empty implicit cast.
1183  explicit ImplicitCastExpr(EmptyShell Shell)
1184    : CastExpr(ImplicitCastExprClass, Shell) { }
1185
1186
1187  virtual SourceRange getSourceRange() const {
1188    return getSubExpr()->getSourceRange();
1189  }
1190
1191  /// isLvalueCast - Whether this cast produces an lvalue.
1192  bool isLvalueCast() const { return LvalueCast; }
1193
1194  /// setLvalueCast - Set whether this cast produces an lvalue.
1195  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1196
1197  static bool classof(const Stmt *T) {
1198    return T->getStmtClass() == ImplicitCastExprClass;
1199  }
1200  static bool classof(const ImplicitCastExpr *) { return true; }
1201
1202  virtual void EmitImpl(llvm::Serializer& S) const;
1203  static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1204};
1205
1206/// ExplicitCastExpr - An explicit cast written in the source
1207/// code.
1208///
1209/// This class is effectively an abstract class, because it provides
1210/// the basic representation of an explicitly-written cast without
1211/// specifying which kind of cast (C cast, functional cast, static
1212/// cast, etc.) was written; specific derived classes represent the
1213/// particular style of cast and its location information.
1214///
1215/// Unlike implicit casts, explicit cast nodes have two different
1216/// types: the type that was written into the source code, and the
1217/// actual type of the expression as determined by semantic
1218/// analysis. These types may differ slightly. For example, in C++ one
1219/// can cast to a reference type, which indicates that the resulting
1220/// expression will be an lvalue. The reference type, however, will
1221/// not be used as the type of the expression.
1222class ExplicitCastExpr : public CastExpr {
1223  /// TypeAsWritten - The type that this expression is casting to, as
1224  /// written in the source code.
1225  QualType TypeAsWritten;
1226
1227protected:
1228  ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy)
1229    : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {}
1230
1231  /// \brief Construct an empty explicit cast.
1232  ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
1233    : CastExpr(SC, Shell) { }
1234
1235public:
1236  /// getTypeAsWritten - Returns the type that this expression is
1237  /// casting to, as written in the source code.
1238  QualType getTypeAsWritten() const { return TypeAsWritten; }
1239  void setTypeAsWritten(QualType T) { TypeAsWritten = T; }
1240
1241  static bool classof(const Stmt *T) {
1242    StmtClass SC = T->getStmtClass();
1243    if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass)
1244      return true;
1245    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
1246      return true;
1247
1248    return false;
1249  }
1250  static bool classof(const ExplicitCastExpr *) { return true; }
1251};
1252
1253/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
1254/// cast in C++ (C++ [expr.cast]), which uses the syntax
1255/// (Type)expr. For example: @c (int)f.
1256class CStyleCastExpr : public ExplicitCastExpr {
1257  SourceLocation LPLoc; // the location of the left paren
1258  SourceLocation RPLoc; // the location of the right paren
1259public:
1260  CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy,
1261                    SourceLocation l, SourceLocation r) :
1262    ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy),
1263    LPLoc(l), RPLoc(r) {}
1264
1265  /// \brief Construct an empty C-style explicit cast.
1266  explicit CStyleCastExpr(EmptyShell Shell)
1267    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
1268
1269  SourceLocation getLParenLoc() const { return LPLoc; }
1270  void setLParenLoc(SourceLocation L) { LPLoc = L; }
1271
1272  SourceLocation getRParenLoc() const { return RPLoc; }
1273  void setRParenLoc(SourceLocation L) { RPLoc = L; }
1274
1275  virtual SourceRange getSourceRange() const {
1276    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
1277  }
1278  static bool classof(const Stmt *T) {
1279    return T->getStmtClass() == CStyleCastExprClass;
1280  }
1281  static bool classof(const CStyleCastExpr *) { return true; }
1282
1283  virtual void EmitImpl(llvm::Serializer& S) const;
1284  static CStyleCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1285};
1286
1287/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
1288///
1289/// This expression node kind describes a builtin binary operation,
1290/// such as "x + y" for integer values "x" and "y". The operands will
1291/// already have been converted to appropriate types (e.g., by
1292/// performing promotions or conversions).
1293///
1294/// In C++, where operators may be overloaded, a different kind of
1295/// expression node (CXXOperatorCallExpr) is used to express the
1296/// invocation of an overloaded operator with operator syntax. Within
1297/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
1298/// used to store an expression "x + y" depends on the subexpressions
1299/// for x and y. If neither x or y is type-dependent, and the "+"
1300/// operator resolves to a built-in operation, BinaryOperator will be
1301/// used to express the computation (x and y may still be
1302/// value-dependent). If either x or y is type-dependent, or if the
1303/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
1304/// be used to express the computation.
1305class BinaryOperator : public Expr {
1306public:
1307  enum Opcode {
1308    // Operators listed in order of precedence.
1309    // Note that additions to this should also update the StmtVisitor class.
1310    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
1311    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
1312    Add, Sub,         // [C99 6.5.6] Additive operators.
1313    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
1314    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
1315    EQ, NE,           // [C99 6.5.9] Equality operators.
1316    And,              // [C99 6.5.10] Bitwise AND operator.
1317    Xor,              // [C99 6.5.11] Bitwise XOR operator.
1318    Or,               // [C99 6.5.12] Bitwise OR operator.
1319    LAnd,             // [C99 6.5.13] Logical AND operator.
1320    LOr,              // [C99 6.5.14] Logical OR operator.
1321    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
1322    DivAssign, RemAssign,
1323    AddAssign, SubAssign,
1324    ShlAssign, ShrAssign,
1325    AndAssign, XorAssign,
1326    OrAssign,
1327    Comma             // [C99 6.5.17] Comma operator.
1328  };
1329private:
1330  enum { LHS, RHS, END_EXPR };
1331  Stmt* SubExprs[END_EXPR];
1332  Opcode Opc;
1333  SourceLocation OpLoc;
1334public:
1335
1336  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
1337                 SourceLocation opLoc)
1338    : Expr(BinaryOperatorClass, ResTy,
1339           lhs->isTypeDependent() || rhs->isTypeDependent(),
1340           lhs->isValueDependent() || rhs->isValueDependent()),
1341      Opc(opc), OpLoc(opLoc) {
1342    SubExprs[LHS] = lhs;
1343    SubExprs[RHS] = rhs;
1344    assert(!isCompoundAssignmentOp() &&
1345           "Use ArithAssignBinaryOperator for compound assignments");
1346  }
1347
1348  /// \brief Construct an empty binary operator.
1349  explicit BinaryOperator(EmptyShell Empty)
1350    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
1351
1352  SourceLocation getOperatorLoc() const { return OpLoc; }
1353  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1354
1355  Opcode getOpcode() const { return Opc; }
1356  void setOpcode(Opcode O) { Opc = O; }
1357
1358  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1359  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1360  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1361  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1362
1363  virtual SourceRange getSourceRange() const {
1364    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
1365  }
1366
1367  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1368  /// corresponds to, e.g. "<<=".
1369  static const char *getOpcodeStr(Opcode Op);
1370
1371  /// \brief Retrieve the binary opcode that corresponds to the given
1372  /// overloaded operator.
1373  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
1374
1375  /// \brief Retrieve the overloaded operator kind that corresponds to
1376  /// the given binary opcode.
1377  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1378
1379  /// predicates to categorize the respective opcodes.
1380  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
1381  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
1382  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
1383  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
1384
1385  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
1386  bool isRelationalOp() const { return isRelationalOp(Opc); }
1387
1388  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
1389  bool isEqualityOp() const { return isEqualityOp(Opc); }
1390
1391  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
1392  bool isLogicalOp() const { return isLogicalOp(Opc); }
1393
1394  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
1395  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
1396  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
1397
1398  static bool classof(const Stmt *S) {
1399    return S->getStmtClass() == BinaryOperatorClass ||
1400           S->getStmtClass() == CompoundAssignOperatorClass;
1401  }
1402  static bool classof(const BinaryOperator *) { return true; }
1403
1404  // Iterators
1405  virtual child_iterator child_begin();
1406  virtual child_iterator child_end();
1407
1408  virtual void EmitImpl(llvm::Serializer& S) const;
1409  static BinaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1410
1411protected:
1412  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
1413                 SourceLocation oploc, bool dead)
1414    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
1415    SubExprs[LHS] = lhs;
1416    SubExprs[RHS] = rhs;
1417  }
1418};
1419
1420/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
1421/// track of the type the operation is performed in.  Due to the semantics of
1422/// these operators, the operands are promoted, the aritmetic performed, an
1423/// implicit conversion back to the result type done, then the assignment takes
1424/// place.  This captures the intermediate type which the computation is done
1425/// in.
1426class CompoundAssignOperator : public BinaryOperator {
1427  QualType ComputationLHSType;
1428  QualType ComputationResultType;
1429public:
1430  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
1431                         QualType ResType, QualType CompLHSType,
1432                         QualType CompResultType,
1433                         SourceLocation OpLoc)
1434    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
1435      ComputationLHSType(CompLHSType),
1436      ComputationResultType(CompResultType) {
1437    assert(isCompoundAssignmentOp() &&
1438           "Only should be used for compound assignments");
1439  }
1440
1441  // The two computation types are the type the LHS is converted
1442  // to for the computation and the type of the result; the two are
1443  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
1444  QualType getComputationLHSType() const { return ComputationLHSType; }
1445  QualType getComputationResultType() const { return ComputationResultType; }
1446
1447  static bool classof(const CompoundAssignOperator *) { return true; }
1448  static bool classof(const Stmt *S) {
1449    return S->getStmtClass() == CompoundAssignOperatorClass;
1450  }
1451
1452  virtual void EmitImpl(llvm::Serializer& S) const;
1453  static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D,
1454                                            ASTContext& C);
1455};
1456
1457/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
1458/// GNU "missing LHS" extension is in use.
1459///
1460class ConditionalOperator : public Expr {
1461  enum { COND, LHS, RHS, END_EXPR };
1462  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1463public:
1464  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
1465    : Expr(ConditionalOperatorClass, t,
1466           // FIXME: the type of the conditional operator doesn't
1467           // depend on the type of the conditional, but the standard
1468           // seems to imply that it could. File a bug!
1469           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
1470           (cond->isValueDependent() ||
1471            (lhs && lhs->isValueDependent()) ||
1472            (rhs && rhs->isValueDependent()))) {
1473    SubExprs[COND] = cond;
1474    SubExprs[LHS] = lhs;
1475    SubExprs[RHS] = rhs;
1476  }
1477
1478  // getCond - Return the expression representing the condition for
1479  //  the ?: operator.
1480  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1481
1482  // getTrueExpr - Return the subexpression representing the value of the ?:
1483  //  expression if the condition evaluates to true.  In most cases this value
1484  //  will be the same as getLHS() except a GCC extension allows the left
1485  //  subexpression to be omitted, and instead of the condition be returned.
1486  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
1487  //  is only evaluated once.
1488  Expr *getTrueExpr() const {
1489    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
1490  }
1491
1492  // getTrueExpr - Return the subexpression representing the value of the ?:
1493  // expression if the condition evaluates to false. This is the same as getRHS.
1494  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
1495
1496  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
1497  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1498
1499  virtual SourceRange getSourceRange() const {
1500    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
1501  }
1502  static bool classof(const Stmt *T) {
1503    return T->getStmtClass() == ConditionalOperatorClass;
1504  }
1505  static bool classof(const ConditionalOperator *) { return true; }
1506
1507  // Iterators
1508  virtual child_iterator child_begin();
1509  virtual child_iterator child_end();
1510
1511  virtual void EmitImpl(llvm::Serializer& S) const;
1512  static ConditionalOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1513};
1514
1515/// AddrLabelExpr - The GNU address of label extension, representing &&label.
1516class AddrLabelExpr : public Expr {
1517  SourceLocation AmpAmpLoc, LabelLoc;
1518  LabelStmt *Label;
1519public:
1520  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
1521                QualType t)
1522    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
1523
1524  virtual SourceRange getSourceRange() const {
1525    return SourceRange(AmpAmpLoc, LabelLoc);
1526  }
1527
1528  LabelStmt *getLabel() const { return Label; }
1529
1530  static bool classof(const Stmt *T) {
1531    return T->getStmtClass() == AddrLabelExprClass;
1532  }
1533  static bool classof(const AddrLabelExpr *) { return true; }
1534
1535  // Iterators
1536  virtual child_iterator child_begin();
1537  virtual child_iterator child_end();
1538
1539  virtual void EmitImpl(llvm::Serializer& S) const;
1540  static AddrLabelExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1541};
1542
1543/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
1544/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
1545/// takes the value of the last subexpression.
1546class StmtExpr : public Expr {
1547  Stmt *SubStmt;
1548  SourceLocation LParenLoc, RParenLoc;
1549public:
1550  StmtExpr(CompoundStmt *substmt, QualType T,
1551           SourceLocation lp, SourceLocation rp) :
1552    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
1553
1554  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
1555  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
1556
1557  virtual SourceRange getSourceRange() const {
1558    return SourceRange(LParenLoc, RParenLoc);
1559  }
1560
1561  SourceLocation getLParenLoc() const { return LParenLoc; }
1562  SourceLocation getRParenLoc() const { return RParenLoc; }
1563
1564  static bool classof(const Stmt *T) {
1565    return T->getStmtClass() == StmtExprClass;
1566  }
1567  static bool classof(const StmtExpr *) { return true; }
1568
1569  // Iterators
1570  virtual child_iterator child_begin();
1571  virtual child_iterator child_end();
1572
1573  virtual void EmitImpl(llvm::Serializer& S) const;
1574  static StmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1575};
1576
1577/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
1578/// This AST node represents a function that returns 1 if two *types* (not
1579/// expressions) are compatible. The result of this built-in function can be
1580/// used in integer constant expressions.
1581class TypesCompatibleExpr : public Expr {
1582  QualType Type1;
1583  QualType Type2;
1584  SourceLocation BuiltinLoc, RParenLoc;
1585public:
1586  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
1587                      QualType t1, QualType t2, SourceLocation RP) :
1588    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1589    BuiltinLoc(BLoc), RParenLoc(RP) {}
1590
1591  QualType getArgType1() const { return Type1; }
1592  QualType getArgType2() const { return Type2; }
1593
1594  virtual SourceRange getSourceRange() const {
1595    return SourceRange(BuiltinLoc, RParenLoc);
1596  }
1597  static bool classof(const Stmt *T) {
1598    return T->getStmtClass() == TypesCompatibleExprClass;
1599  }
1600  static bool classof(const TypesCompatibleExpr *) { return true; }
1601
1602  // Iterators
1603  virtual child_iterator child_begin();
1604  virtual child_iterator child_end();
1605
1606  virtual void EmitImpl(llvm::Serializer& S) const;
1607  static TypesCompatibleExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1608};
1609
1610/// ShuffleVectorExpr - clang-specific builtin-in function
1611/// __builtin_shufflevector.
1612/// This AST node represents a operator that does a constant
1613/// shuffle, similar to LLVM's shufflevector instruction. It takes
1614/// two vectors and a variable number of constant indices,
1615/// and returns the appropriately shuffled vector.
1616class ShuffleVectorExpr : public Expr {
1617  SourceLocation BuiltinLoc, RParenLoc;
1618
1619  // SubExprs - the list of values passed to the __builtin_shufflevector
1620  // function. The first two are vectors, and the rest are constant
1621  // indices.  The number of values in this list is always
1622  // 2+the number of indices in the vector type.
1623  Stmt **SubExprs;
1624  unsigned NumExprs;
1625
1626public:
1627  ShuffleVectorExpr(Expr **args, unsigned nexpr,
1628                    QualType Type, SourceLocation BLoc,
1629                    SourceLocation RP) :
1630    Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc),
1631    RParenLoc(RP), NumExprs(nexpr) {
1632
1633    SubExprs = new Stmt*[nexpr];
1634    for (unsigned i = 0; i < nexpr; i++)
1635      SubExprs[i] = args[i];
1636  }
1637
1638  virtual SourceRange getSourceRange() const {
1639    return SourceRange(BuiltinLoc, RParenLoc);
1640  }
1641  static bool classof(const Stmt *T) {
1642    return T->getStmtClass() == ShuffleVectorExprClass;
1643  }
1644  static bool classof(const ShuffleVectorExpr *) { return true; }
1645
1646  ~ShuffleVectorExpr() {
1647    delete [] SubExprs;
1648  }
1649
1650  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1651  /// constant expression, the actual arguments passed in, and the function
1652  /// pointers.
1653  unsigned getNumSubExprs() const { return NumExprs; }
1654
1655  /// getExpr - Return the Expr at the specified index.
1656  Expr *getExpr(unsigned Index) {
1657    assert((Index < NumExprs) && "Arg access out of range!");
1658    return cast<Expr>(SubExprs[Index]);
1659  }
1660  const Expr *getExpr(unsigned Index) const {
1661    assert((Index < NumExprs) && "Arg access out of range!");
1662    return cast<Expr>(SubExprs[Index]);
1663  }
1664
1665  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
1666    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
1667    return getExpr(N+2)->getIntegerConstantExprValue(Ctx).getZExtValue();
1668  }
1669
1670  // Iterators
1671  virtual child_iterator child_begin();
1672  virtual child_iterator child_end();
1673
1674  virtual void EmitImpl(llvm::Serializer& S) const;
1675  static ShuffleVectorExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1676};
1677
1678/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
1679/// This AST node is similar to the conditional operator (?:) in C, with
1680/// the following exceptions:
1681/// - the test expression must be a integer constant expression.
1682/// - the expression returned acts like the chosen subexpression in every
1683///   visible way: the type is the same as that of the chosen subexpression,
1684///   and all predicates (whether it's an l-value, whether it's an integer
1685///   constant expression, etc.) return the same result as for the chosen
1686///   sub-expression.
1687class ChooseExpr : public Expr {
1688  enum { COND, LHS, RHS, END_EXPR };
1689  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1690  SourceLocation BuiltinLoc, RParenLoc;
1691public:
1692  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
1693             SourceLocation RP)
1694    : Expr(ChooseExprClass, t),
1695      BuiltinLoc(BLoc), RParenLoc(RP) {
1696      SubExprs[COND] = cond;
1697      SubExprs[LHS] = lhs;
1698      SubExprs[RHS] = rhs;
1699    }
1700
1701  /// isConditionTrue - Return whether the condition is true (i.e. not
1702  /// equal to zero).
1703  bool isConditionTrue(ASTContext &C) const;
1704
1705  /// getChosenSubExpr - Return the subexpression chosen according to the
1706  /// condition.
1707  Expr *getChosenSubExpr(ASTContext &C) const {
1708    return isConditionTrue(C) ? getLHS() : getRHS();
1709  }
1710
1711  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1712  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1713  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1714
1715  virtual SourceRange getSourceRange() const {
1716    return SourceRange(BuiltinLoc, RParenLoc);
1717  }
1718  static bool classof(const Stmt *T) {
1719    return T->getStmtClass() == ChooseExprClass;
1720  }
1721  static bool classof(const ChooseExpr *) { return true; }
1722
1723  // Iterators
1724  virtual child_iterator child_begin();
1725  virtual child_iterator child_end();
1726
1727  virtual void EmitImpl(llvm::Serializer& S) const;
1728  static ChooseExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1729};
1730
1731/// GNUNullExpr - Implements the GNU __null extension, which is a name
1732/// for a null pointer constant that has integral type (e.g., int or
1733/// long) and is the same size and alignment as a pointer. The __null
1734/// extension is typically only used by system headers, which define
1735/// NULL as __null in C++ rather than using 0 (which is an integer
1736/// that may not match the size of a pointer).
1737class GNUNullExpr : public Expr {
1738  /// TokenLoc - The location of the __null keyword.
1739  SourceLocation TokenLoc;
1740
1741public:
1742  GNUNullExpr(QualType Ty, SourceLocation Loc)
1743    : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
1744
1745  /// getTokenLocation - The location of the __null token.
1746  SourceLocation getTokenLocation() const { return TokenLoc; }
1747
1748  virtual SourceRange getSourceRange() const {
1749    return SourceRange(TokenLoc);
1750  }
1751  static bool classof(const Stmt *T) {
1752    return T->getStmtClass() == GNUNullExprClass;
1753  }
1754  static bool classof(const GNUNullExpr *) { return true; }
1755
1756  // Iterators
1757  virtual child_iterator child_begin();
1758  virtual child_iterator child_end();
1759
1760  virtual void EmitImpl(llvm::Serializer& S) const;
1761  static GNUNullExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1762};
1763
1764/// VAArgExpr, used for the builtin function __builtin_va_start.
1765class VAArgExpr : public Expr {
1766  Stmt *Val;
1767  SourceLocation BuiltinLoc, RParenLoc;
1768public:
1769  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
1770    : Expr(VAArgExprClass, t),
1771      Val(e),
1772      BuiltinLoc(BLoc),
1773      RParenLoc(RPLoc) { }
1774
1775  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1776  Expr *getSubExpr() { return cast<Expr>(Val); }
1777  virtual SourceRange getSourceRange() const {
1778    return SourceRange(BuiltinLoc, RParenLoc);
1779  }
1780  static bool classof(const Stmt *T) {
1781    return T->getStmtClass() == VAArgExprClass;
1782  }
1783  static bool classof(const VAArgExpr *) { return true; }
1784
1785  // Iterators
1786  virtual child_iterator child_begin();
1787  virtual child_iterator child_end();
1788
1789  virtual void EmitImpl(llvm::Serializer& S) const;
1790  static VAArgExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1791};
1792
1793/// @brief Describes an C or C++ initializer list.
1794///
1795/// InitListExpr describes an initializer list, which can be used to
1796/// initialize objects of different types, including
1797/// struct/class/union types, arrays, and vectors. For example:
1798///
1799/// @code
1800/// struct foo x = { 1, { 2, 3 } };
1801/// @endcode
1802///
1803/// Prior to semantic analysis, an initializer list will represent the
1804/// initializer list as written by the user, but will have the
1805/// placeholder type "void". This initializer list is called the
1806/// syntactic form of the initializer, and may contain C99 designated
1807/// initializers (represented as DesignatedInitExprs), initializations
1808/// of subobject members without explicit braces, and so on. Clients
1809/// interested in the original syntax of the initializer list should
1810/// use the syntactic form of the initializer list.
1811///
1812/// After semantic analysis, the initializer list will represent the
1813/// semantic form of the initializer, where the initializations of all
1814/// subobjects are made explicit with nested InitListExpr nodes and
1815/// C99 designators have been eliminated by placing the designated
1816/// initializations into the subobject they initialize. Additionally,
1817/// any "holes" in the initialization, where no initializer has been
1818/// specified for a particular subobject, will be replaced with
1819/// implicitly-generated ImplicitValueInitExpr expressions that
1820/// value-initialize the subobjects. Note, however, that the
1821/// initializer lists may still have fewer initializers than there are
1822/// elements to initialize within the object.
1823///
1824/// Given the semantic form of the initializer list, one can retrieve
1825/// the original syntactic form of that initializer list (if it
1826/// exists) using getSyntacticForm(). Since many initializer lists
1827/// have the same syntactic and semantic forms, getSyntacticForm() may
1828/// return NULL, indicating that the current initializer list also
1829/// serves as its syntactic form.
1830class InitListExpr : public Expr {
1831  std::vector<Stmt *> InitExprs;
1832  SourceLocation LBraceLoc, RBraceLoc;
1833
1834  /// Contains the initializer list that describes the syntactic form
1835  /// written in the source code.
1836  InitListExpr *SyntacticForm;
1837
1838  /// If this initializer list initializes a union, specifies which
1839  /// field within the union will be initialized.
1840  FieldDecl *UnionFieldInit;
1841
1842  /// Whether this initializer list originally had a GNU array-range
1843  /// designator in it. This is a temporary marker used by CodeGen.
1844  bool HadArrayRangeDesignator;
1845
1846public:
1847  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
1848               SourceLocation rbraceloc);
1849
1850  unsigned getNumInits() const { return InitExprs.size(); }
1851
1852  const Expr* getInit(unsigned Init) const {
1853    assert(Init < getNumInits() && "Initializer access out of range!");
1854    return cast_or_null<Expr>(InitExprs[Init]);
1855  }
1856
1857  Expr* getInit(unsigned Init) {
1858    assert(Init < getNumInits() && "Initializer access out of range!");
1859    return cast_or_null<Expr>(InitExprs[Init]);
1860  }
1861
1862  void setInit(unsigned Init, Expr *expr) {
1863    assert(Init < getNumInits() && "Initializer access out of range!");
1864    InitExprs[Init] = expr;
1865  }
1866
1867  /// \brief Reserve space for some number of initializers.
1868  void reserveInits(unsigned NumInits);
1869
1870  /// @brief Specify the number of initializers
1871  ///
1872  /// If there are more than @p NumInits initializers, the remaining
1873  /// initializers will be destroyed. If there are fewer than @p
1874  /// NumInits initializers, NULL expressions will be added for the
1875  /// unknown initializers.
1876  void resizeInits(ASTContext &Context, unsigned NumInits);
1877
1878  /// @brief Updates the initializer at index @p Init with the new
1879  /// expression @p expr, and returns the old expression at that
1880  /// location.
1881  ///
1882  /// When @p Init is out of range for this initializer list, the
1883  /// initializer list will be extended with NULL expressions to
1884  /// accomodate the new entry.
1885  Expr *updateInit(unsigned Init, Expr *expr);
1886
1887  /// \brief If this initializes a union, specifies which field in the
1888  /// union to initialize.
1889  ///
1890  /// Typically, this field is the first named field within the
1891  /// union. However, a designated initializer can specify the
1892  /// initialization of a different field within the union.
1893  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
1894  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
1895
1896  // Explicit InitListExpr's originate from source code (and have valid source
1897  // locations). Implicit InitListExpr's are created by the semantic analyzer.
1898  bool isExplicit() {
1899    return LBraceLoc.isValid() && RBraceLoc.isValid();
1900  }
1901
1902  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
1903
1904  /// @brief Retrieve the initializer list that describes the
1905  /// syntactic form of the initializer.
1906  ///
1907  ///
1908  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
1909  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
1910
1911  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
1912  void sawArrayRangeDesignator() {
1913    HadArrayRangeDesignator = true;
1914  }
1915
1916  virtual SourceRange getSourceRange() const {
1917    return SourceRange(LBraceLoc, RBraceLoc);
1918  }
1919  static bool classof(const Stmt *T) {
1920    return T->getStmtClass() == InitListExprClass;
1921  }
1922  static bool classof(const InitListExpr *) { return true; }
1923
1924  // Iterators
1925  virtual child_iterator child_begin();
1926  virtual child_iterator child_end();
1927
1928  typedef std::vector<Stmt *>::iterator iterator;
1929  typedef std::vector<Stmt *>::reverse_iterator reverse_iterator;
1930
1931  iterator begin() { return InitExprs.begin(); }
1932  iterator end() { return InitExprs.end(); }
1933  reverse_iterator rbegin() { return InitExprs.rbegin(); }
1934  reverse_iterator rend() { return InitExprs.rend(); }
1935
1936  // Serailization.
1937  virtual void EmitImpl(llvm::Serializer& S) const;
1938  static InitListExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1939
1940private:
1941  // Used by serializer.
1942  InitListExpr() : Expr(InitListExprClass, QualType()) {}
1943};
1944
1945/// @brief Represents a C99 designated initializer expression.
1946///
1947/// A designated initializer expression (C99 6.7.8) contains one or
1948/// more designators (which can be field designators, array
1949/// designators, or GNU array-range designators) followed by an
1950/// expression that initializes the field or element(s) that the
1951/// designators refer to. For example, given:
1952///
1953/// @code
1954/// struct point {
1955///   double x;
1956///   double y;
1957/// };
1958/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
1959/// @endcode
1960///
1961/// The InitListExpr contains three DesignatedInitExprs, the first of
1962/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
1963/// designators, one array designator for @c [2] followed by one field
1964/// designator for @c .y. The initalization expression will be 1.0.
1965class DesignatedInitExpr : public Expr {
1966  /// The location of the '=' or ':' prior to the actual initializer
1967  /// expression.
1968  SourceLocation EqualOrColonLoc;
1969
1970  /// Whether this designated initializer used the GNU deprecated
1971  /// syntax rather than the C99 '=' syntax.
1972  bool GNUSyntax : 1;
1973
1974  /// The number of designators in this initializer expression.
1975  unsigned NumDesignators : 15;
1976
1977  /// The number of subexpressions of this initializer expression,
1978  /// which contains both the initializer and any additional
1979  /// expressions used by array and array-range designators.
1980  unsigned NumSubExprs : 16;
1981
1982  DesignatedInitExpr(QualType Ty, unsigned NumDesignators,
1983                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
1984                     unsigned NumSubExprs)
1985    : Expr(DesignatedInitExprClass, Ty),
1986      EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
1987      NumDesignators(NumDesignators), NumSubExprs(NumSubExprs) { }
1988
1989public:
1990  /// A field designator, e.g., ".x".
1991  struct FieldDesignator {
1992    /// Refers to the field that is being initialized. The low bit
1993    /// of this field determines whether this is actually a pointer
1994    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
1995    /// initially constructed, a field designator will store an
1996    /// IdentifierInfo*. After semantic analysis has resolved that
1997    /// name, the field designator will instead store a FieldDecl*.
1998    uintptr_t NameOrField;
1999
2000    /// The location of the '.' in the designated initializer.
2001    unsigned DotLoc;
2002
2003    /// The location of the field name in the designated initializer.
2004    unsigned FieldLoc;
2005  };
2006
2007  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
2008  struct ArrayOrRangeDesignator {
2009    /// Location of the first index expression within the designated
2010    /// initializer expression's list of subexpressions.
2011    unsigned Index;
2012    /// The location of the '[' starting the array range designator.
2013    unsigned LBracketLoc;
2014    /// The location of the ellipsis separating the start and end
2015    /// indices. Only valid for GNU array-range designators.
2016    unsigned EllipsisLoc;
2017    /// The location of the ']' terminating the array range designator.
2018    unsigned RBracketLoc;
2019  };
2020
2021  /// @brief Represents a single C99 designator.
2022  ///
2023  /// @todo This class is infuriatingly similar to clang::Designator,
2024  /// but minor differences (storing indices vs. storing pointers)
2025  /// keep us from reusing it. Try harder, later, to rectify these
2026  /// differences.
2027  class Designator {
2028    /// @brief The kind of designator this describes.
2029    enum {
2030      FieldDesignator,
2031      ArrayDesignator,
2032      ArrayRangeDesignator
2033    } Kind;
2034
2035    union {
2036      /// A field designator, e.g., ".x".
2037      struct FieldDesignator Field;
2038      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
2039      struct ArrayOrRangeDesignator ArrayOrRange;
2040    };
2041    friend class DesignatedInitExpr;
2042
2043  public:
2044    /// @brief Initializes a field designator.
2045    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
2046               SourceLocation FieldLoc)
2047      : Kind(FieldDesignator) {
2048      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
2049      Field.DotLoc = DotLoc.getRawEncoding();
2050      Field.FieldLoc = FieldLoc.getRawEncoding();
2051    }
2052
2053    /// @brief Initializes an array designator.
2054    Designator(unsigned Index, SourceLocation LBracketLoc,
2055               SourceLocation RBracketLoc)
2056      : Kind(ArrayDesignator) {
2057      ArrayOrRange.Index = Index;
2058      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
2059      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
2060      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
2061    }
2062
2063    /// @brief Initializes a GNU array-range designator.
2064    Designator(unsigned Index, SourceLocation LBracketLoc,
2065               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
2066      : Kind(ArrayRangeDesignator) {
2067      ArrayOrRange.Index = Index;
2068      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
2069      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
2070      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
2071    }
2072
2073    bool isFieldDesignator() const { return Kind == FieldDesignator; }
2074    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
2075    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
2076
2077    IdentifierInfo * getFieldName();
2078
2079    FieldDecl *getField() {
2080      assert(Kind == FieldDesignator && "Only valid on a field designator");
2081      if (Field.NameOrField & 0x01)
2082        return 0;
2083      else
2084        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
2085    }
2086
2087    void setField(FieldDecl *FD) {
2088      assert(Kind == FieldDesignator && "Only valid on a field designator");
2089      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
2090    }
2091
2092    SourceLocation getDotLoc() const {
2093      assert(Kind == FieldDesignator && "Only valid on a field designator");
2094      return SourceLocation::getFromRawEncoding(Field.DotLoc);
2095    }
2096
2097    SourceLocation getFieldLoc() const {
2098      assert(Kind == FieldDesignator && "Only valid on a field designator");
2099      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
2100    }
2101
2102    SourceLocation getLBracketLoc() const {
2103      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2104             "Only valid on an array or array-range designator");
2105      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
2106    }
2107
2108    SourceLocation getRBracketLoc() const {
2109      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2110             "Only valid on an array or array-range designator");
2111      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
2112    }
2113
2114    SourceLocation getEllipsisLoc() const {
2115      assert(Kind == ArrayRangeDesignator &&
2116             "Only valid on an array-range designator");
2117      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
2118    }
2119
2120    SourceLocation getStartLocation() const {
2121      if (Kind == FieldDesignator)
2122        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
2123      else
2124        return getLBracketLoc();
2125    }
2126  };
2127
2128  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
2129                                    unsigned NumDesignators,
2130                                    Expr **IndexExprs, unsigned NumIndexExprs,
2131                                    SourceLocation EqualOrColonLoc,
2132                                    bool GNUSyntax, Expr *Init);
2133
2134  /// @brief Returns the number of designators in this initializer.
2135  unsigned size() const { return NumDesignators; }
2136
2137  // Iterator access to the designators.
2138  typedef Designator* designators_iterator;
2139  designators_iterator designators_begin();
2140  designators_iterator designators_end();
2141
2142  Expr *getArrayIndex(const Designator& D);
2143  Expr *getArrayRangeStart(const Designator& D);
2144  Expr *getArrayRangeEnd(const Designator& D);
2145
2146  /// @brief Retrieve the location of the '=' that precedes the
2147  /// initializer value itself, if present.
2148  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
2149
2150  /// @brief Determines whether this designated initializer used the
2151  /// deprecated GNU syntax for designated initializers.
2152  bool usesGNUSyntax() const { return GNUSyntax; }
2153
2154  /// @brief Retrieve the initializer value.
2155  Expr *getInit() const {
2156    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
2157  }
2158
2159  void setInit(Expr *init) {
2160    *child_begin() = init;
2161  }
2162
2163  virtual SourceRange getSourceRange() const;
2164
2165  static bool classof(const Stmt *T) {
2166    return T->getStmtClass() == DesignatedInitExprClass;
2167  }
2168  static bool classof(const DesignatedInitExpr *) { return true; }
2169
2170  // Iterators
2171  virtual child_iterator child_begin();
2172  virtual child_iterator child_end();
2173};
2174
2175/// \brief Represents an implicitly-generated value initialization of
2176/// an object of a given type.
2177///
2178/// Implicit value initializations occur within semantic initializer
2179/// list expressions (InitListExpr) as placeholders for subobject
2180/// initializations not explicitly specified by the user.
2181///
2182/// \see InitListExpr
2183class ImplicitValueInitExpr : public Expr {
2184public:
2185  explicit ImplicitValueInitExpr(QualType ty)
2186    : Expr(ImplicitValueInitExprClass, ty) { }
2187
2188  static bool classof(const Stmt *T) {
2189    return T->getStmtClass() == ImplicitValueInitExprClass;
2190  }
2191  static bool classof(const ImplicitValueInitExpr *) { return true; }
2192
2193  virtual SourceRange getSourceRange() const {
2194    return SourceRange();
2195  }
2196
2197  // Iterators
2198  virtual child_iterator child_begin();
2199  virtual child_iterator child_end();
2200};
2201
2202//===----------------------------------------------------------------------===//
2203// Clang Extensions
2204//===----------------------------------------------------------------------===//
2205
2206
2207/// ExtVectorElementExpr - This represents access to specific elements of a
2208/// vector, and may occur on the left hand side or right hand side.  For example
2209/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
2210///
2211/// Note that the base may have either vector or pointer to vector type, just
2212/// like a struct field reference.
2213///
2214class ExtVectorElementExpr : public Expr {
2215  Stmt *Base;
2216  IdentifierInfo &Accessor;
2217  SourceLocation AccessorLoc;
2218public:
2219  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
2220                       SourceLocation loc)
2221    : Expr(ExtVectorElementExprClass, ty),
2222      Base(base), Accessor(accessor), AccessorLoc(loc) {}
2223
2224  const Expr *getBase() const { return cast<Expr>(Base); }
2225  Expr *getBase() { return cast<Expr>(Base); }
2226
2227  IdentifierInfo &getAccessor() const { return Accessor; }
2228
2229  /// getNumElements - Get the number of components being selected.
2230  unsigned getNumElements() const;
2231
2232  /// containsDuplicateElements - Return true if any element access is
2233  /// repeated.
2234  bool containsDuplicateElements() const;
2235
2236  /// getEncodedElementAccess - Encode the elements accessed into an llvm
2237  /// aggregate Constant of ConstantInt(s).
2238  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
2239
2240  virtual SourceRange getSourceRange() const {
2241    return SourceRange(getBase()->getLocStart(), AccessorLoc);
2242  }
2243
2244  /// isArrow - Return true if the base expression is a pointer to vector,
2245  /// return false if the base expression is a vector.
2246  bool isArrow() const;
2247
2248  static bool classof(const Stmt *T) {
2249    return T->getStmtClass() == ExtVectorElementExprClass;
2250  }
2251  static bool classof(const ExtVectorElementExpr *) { return true; }
2252
2253  // Iterators
2254  virtual child_iterator child_begin();
2255  virtual child_iterator child_end();
2256
2257  virtual void EmitImpl(llvm::Serializer& S) const;
2258  static ExtVectorElementExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2259};
2260
2261
2262/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
2263/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
2264class BlockExpr : public Expr {
2265protected:
2266  BlockDecl *TheBlock;
2267  bool HasBlockDeclRefExprs;
2268public:
2269  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
2270    : Expr(BlockExprClass, ty),
2271      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
2272
2273  const BlockDecl *getBlockDecl() const { return TheBlock; }
2274  BlockDecl *getBlockDecl() { return TheBlock; }
2275
2276  // Convenience functions for probing the underlying BlockDecl.
2277  SourceLocation getCaretLocation() const;
2278  const Stmt *getBody() const;
2279  Stmt *getBody();
2280
2281  virtual SourceRange getSourceRange() const {
2282    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
2283  }
2284
2285  /// getFunctionType - Return the underlying function type for this block.
2286  const FunctionType *getFunctionType() const;
2287
2288  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
2289  /// contained inside.
2290  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
2291
2292  static bool classof(const Stmt *T) {
2293    return T->getStmtClass() == BlockExprClass;
2294  }
2295  static bool classof(const BlockExpr *) { return true; }
2296
2297  // Iterators
2298  virtual child_iterator child_begin();
2299  virtual child_iterator child_end();
2300
2301  virtual void EmitImpl(llvm::Serializer& S) const;
2302  static BlockExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2303};
2304
2305/// BlockDeclRefExpr - A reference to a declared variable, function,
2306/// enum, etc.
2307class BlockDeclRefExpr : public Expr {
2308  ValueDecl *D;
2309  SourceLocation Loc;
2310  bool IsByRef;
2311public:
2312  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef) :
2313       Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef) {}
2314
2315  ValueDecl *getDecl() { return D; }
2316  const ValueDecl *getDecl() const { return D; }
2317  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
2318
2319  bool isByRef() const { return IsByRef; }
2320
2321  static bool classof(const Stmt *T) {
2322    return T->getStmtClass() == BlockDeclRefExprClass;
2323  }
2324  static bool classof(const BlockDeclRefExpr *) { return true; }
2325
2326  // Iterators
2327  virtual child_iterator child_begin();
2328  virtual child_iterator child_end();
2329
2330  virtual void EmitImpl(llvm::Serializer& S) const;
2331  static BlockDeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2332};
2333
2334}  // end namespace clang
2335
2336#endif
2337