Expr.h revision 673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76
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  /// \brief Construct an empty string literal.
585  static StringLiteral *CreateEmpty(ASTContext &C, unsigned NumStrs);
586
587  StringLiteral* Clone(ASTContext &C) const;
588  void Destroy(ASTContext &C);
589
590  const char *getStrData() const { return StrData; }
591  unsigned getByteLength() const { return ByteLength; }
592
593  /// \brief Sets the string data to the given string data.
594  void setStrData(ASTContext &C, const char *Str, unsigned Len);
595
596  bool isWide() const { return IsWide; }
597  void setWide(bool W) { IsWide = W; }
598
599  bool containsNonAsciiOrNull() const {
600    for (unsigned i = 0; i < getByteLength(); ++i)
601      if (!isascii(getStrData()[i]) || !getStrData()[i])
602        return true;
603    return false;
604  }
605  /// getNumConcatenated - Get the number of string literal tokens that were
606  /// concatenated in translation phase #6 to form this string literal.
607  unsigned getNumConcatenated() const { return NumConcatenated; }
608
609  SourceLocation getStrTokenLoc(unsigned TokNum) const {
610    assert(TokNum < NumConcatenated && "Invalid tok number");
611    return TokLocs[TokNum];
612  }
613  void setStrTokenLoc(unsigned TokNum, SourceLocation L) {
614    assert(TokNum < NumConcatenated && "Invalid tok number");
615    TokLocs[TokNum] = L;
616  }
617
618  typedef const SourceLocation *tokloc_iterator;
619  tokloc_iterator tokloc_begin() const { return TokLocs; }
620  tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; }
621
622  virtual SourceRange getSourceRange() const {
623    return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]);
624  }
625  static bool classof(const Stmt *T) {
626    return T->getStmtClass() == StringLiteralClass;
627  }
628  static bool classof(const StringLiteral *) { return true; }
629
630  // Iterators
631  virtual child_iterator child_begin();
632  virtual child_iterator child_end();
633
634  virtual void EmitImpl(llvm::Serializer& S) const;
635  static StringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
636};
637
638/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
639/// AST node is only formed if full location information is requested.
640class ParenExpr : public Expr {
641  SourceLocation L, R;
642  Stmt *Val;
643public:
644  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
645    : Expr(ParenExprClass, val->getType(),
646           val->isTypeDependent(), val->isValueDependent()),
647      L(l), R(r), Val(val) {}
648
649  /// \brief Construct an empty parenthesized expression.
650  explicit ParenExpr(EmptyShell Empty)
651    : Expr(ParenExprClass, Empty) { }
652
653  const Expr *getSubExpr() const { return cast<Expr>(Val); }
654  Expr *getSubExpr() { return cast<Expr>(Val); }
655  void setSubExpr(Expr *E) { Val = E; }
656
657  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
658
659  /// \brief Get the location of the left parentheses '('.
660  SourceLocation getLParen() const { return L; }
661  void setLParen(SourceLocation Loc) { L = Loc; }
662
663  /// \brief Get the location of the right parentheses ')'.
664  SourceLocation getRParen() const { return R; }
665  void setRParen(SourceLocation Loc) { R = Loc; }
666
667  static bool classof(const Stmt *T) {
668    return T->getStmtClass() == ParenExprClass;
669  }
670  static bool classof(const ParenExpr *) { return true; }
671
672  // Iterators
673  virtual child_iterator child_begin();
674  virtual child_iterator child_end();
675
676  virtual void EmitImpl(llvm::Serializer& S) const;
677  static ParenExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
678};
679
680
681/// UnaryOperator - This represents the unary-expression's (except sizeof and
682/// alignof), the postinc/postdec operators from postfix-expression, and various
683/// extensions.
684///
685/// Notes on various nodes:
686///
687/// Real/Imag - These return the real/imag part of a complex operand.  If
688///   applied to a non-complex value, the former returns its operand and the
689///   later returns zero in the type of the operand.
690///
691/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
692///   subexpression is a compound literal with the various MemberExpr and
693///   ArraySubscriptExpr's applied to it.
694///
695class UnaryOperator : public Expr {
696public:
697  // Note that additions to this should also update the StmtVisitor class.
698  enum Opcode {
699    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
700    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
701    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
702    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
703    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
704    Real, Imag,       // "__real expr"/"__imag expr" Extension.
705    Extension,        // __extension__ marker.
706    OffsetOf          // __builtin_offsetof
707  };
708private:
709  Stmt *Val;
710  Opcode Opc;
711  SourceLocation Loc;
712public:
713
714  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
715    : Expr(UnaryOperatorClass, type,
716           input->isTypeDependent() && opc != OffsetOf,
717           input->isValueDependent()),
718      Val(input), Opc(opc), Loc(l) {}
719
720  /// \brief Build an empty unary operator.
721  explicit UnaryOperator(EmptyShell Empty)
722    : Expr(UnaryOperatorClass, Empty), Opc(AddrOf) { }
723
724  Opcode getOpcode() const { return Opc; }
725  void setOpcode(Opcode O) { Opc = O; }
726
727  Expr *getSubExpr() const { return cast<Expr>(Val); }
728  void setSubExpr(Expr *E) { Val = E; }
729
730  /// getOperatorLoc - Return the location of the operator.
731  SourceLocation getOperatorLoc() const { return Loc; }
732  void setOperatorLoc(SourceLocation L) { Loc = L; }
733
734  /// isPostfix - Return true if this is a postfix operation, like x++.
735  static bool isPostfix(Opcode Op) {
736    return Op == PostInc || Op == PostDec;
737  }
738
739  /// isPostfix - Return true if this is a prefix operation, like --x.
740  static bool isPrefix(Opcode Op) {
741    return Op == PreInc || Op == PreDec;
742  }
743
744  bool isPrefix() const { return isPrefix(Opc); }
745  bool isPostfix() const { return isPostfix(Opc); }
746  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
747  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
748  bool isOffsetOfOp() const { return Opc == OffsetOf; }
749  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
750
751  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
752  /// corresponds to, e.g. "sizeof" or "[pre]++"
753  static const char *getOpcodeStr(Opcode Op);
754
755  /// \brief Retrieve the unary opcode that corresponds to the given
756  /// overloaded operator.
757  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix);
758
759  /// \brief Retrieve the overloaded operator kind that corresponds to
760  /// the given unary opcode.
761  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
762
763  virtual SourceRange getSourceRange() const {
764    if (isPostfix())
765      return SourceRange(Val->getLocStart(), Loc);
766    else
767      return SourceRange(Loc, Val->getLocEnd());
768  }
769  virtual SourceLocation getExprLoc() const { return Loc; }
770
771  static bool classof(const Stmt *T) {
772    return T->getStmtClass() == UnaryOperatorClass;
773  }
774  static bool classof(const UnaryOperator *) { return true; }
775
776  // Iterators
777  virtual child_iterator child_begin();
778  virtual child_iterator child_end();
779
780  virtual void EmitImpl(llvm::Serializer& S) const;
781  static UnaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
782};
783
784/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
785/// types and expressions.
786class SizeOfAlignOfExpr : public Expr {
787  bool isSizeof : 1;  // true if sizeof, false if alignof.
788  bool isType : 1;    // true if operand is a type, false if an expression
789  union {
790    void *Ty;
791    Stmt *Ex;
792  } Argument;
793  SourceLocation OpLoc, RParenLoc;
794public:
795  SizeOfAlignOfExpr(bool issizeof, QualType T,
796                    QualType resultType, SourceLocation op,
797                    SourceLocation rp) :
798      Expr(SizeOfAlignOfExprClass, resultType,
799           false, // Never type-dependent (C++ [temp.dep.expr]p3).
800           // Value-dependent if the argument is type-dependent.
801           T->isDependentType()),
802      isSizeof(issizeof), isType(true), OpLoc(op), RParenLoc(rp) {
803    Argument.Ty = T.getAsOpaquePtr();
804  }
805
806  SizeOfAlignOfExpr(bool issizeof, Expr *E,
807                    QualType resultType, SourceLocation op,
808                    SourceLocation rp) :
809      Expr(SizeOfAlignOfExprClass, resultType,
810           false, // Never type-dependent (C++ [temp.dep.expr]p3).
811           // Value-dependent if the argument is type-dependent.
812           E->isTypeDependent()),
813      isSizeof(issizeof), isType(false), OpLoc(op), RParenLoc(rp) {
814    Argument.Ex = E;
815  }
816
817  /// \brief Construct an empty sizeof/alignof expression.
818  explicit SizeOfAlignOfExpr(EmptyShell Empty)
819    : Expr(SizeOfAlignOfExprClass, Empty) { }
820
821  virtual void Destroy(ASTContext& C);
822
823  bool isSizeOf() const { return isSizeof; }
824  void setSizeof(bool S) { isSizeof = S; }
825
826  bool isArgumentType() const { return isType; }
827  QualType getArgumentType() const {
828    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
829    return QualType::getFromOpaquePtr(Argument.Ty);
830  }
831  Expr *getArgumentExpr() {
832    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
833    return static_cast<Expr*>(Argument.Ex);
834  }
835  const Expr *getArgumentExpr() const {
836    return const_cast<SizeOfAlignOfExpr*>(this)->getArgumentExpr();
837  }
838
839  void setArgument(Expr *E) { Argument.Ex = E; isType = false; }
840  void setArgument(QualType T) {
841    Argument.Ty = T.getAsOpaquePtr();
842    isType = true;
843  }
844
845  /// Gets the argument type, or the type of the argument expression, whichever
846  /// is appropriate.
847  QualType getTypeOfArgument() const {
848    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
849  }
850
851  SourceLocation getOperatorLoc() const { return OpLoc; }
852  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
853
854  SourceLocation getRParenLoc() const { return RParenLoc; }
855  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
856
857  virtual SourceRange getSourceRange() const {
858    return SourceRange(OpLoc, RParenLoc);
859  }
860
861  static bool classof(const Stmt *T) {
862    return T->getStmtClass() == SizeOfAlignOfExprClass;
863  }
864  static bool classof(const SizeOfAlignOfExpr *) { return true; }
865
866  // Iterators
867  virtual child_iterator child_begin();
868  virtual child_iterator child_end();
869
870  virtual void EmitImpl(llvm::Serializer& S) const;
871  static SizeOfAlignOfExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
872};
873
874//===----------------------------------------------------------------------===//
875// Postfix Operators.
876//===----------------------------------------------------------------------===//
877
878/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
879class ArraySubscriptExpr : public Expr {
880  enum { LHS, RHS, END_EXPR=2 };
881  Stmt* SubExprs[END_EXPR];
882  SourceLocation RBracketLoc;
883public:
884  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
885                     SourceLocation rbracketloc)
886  : Expr(ArraySubscriptExprClass, t,
887         lhs->isTypeDependent() || rhs->isTypeDependent(),
888         lhs->isValueDependent() || rhs->isValueDependent()),
889    RBracketLoc(rbracketloc) {
890    SubExprs[LHS] = lhs;
891    SubExprs[RHS] = rhs;
892  }
893
894  /// An array access can be written A[4] or 4[A] (both are equivalent).
895  /// - getBase() and getIdx() always present the normalized view: A[4].
896  ///    In this case getBase() returns "A" and getIdx() returns "4".
897  /// - getLHS() and getRHS() present the syntactic view. e.g. for
898  ///    4[A] getLHS() returns "4".
899  /// Note: Because vector element access is also written A[4] we must
900  /// predicate the format conversion in getBase and getIdx only on the
901  /// the type of the RHS, as it is possible for the LHS to be a vector of
902  /// integer type
903  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
904  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
905
906  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
907  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
908
909  Expr *getBase() {
910    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
911  }
912
913  const Expr *getBase() const {
914    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
915  }
916
917  Expr *getIdx() {
918    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
919  }
920
921  const Expr *getIdx() const {
922    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
923  }
924
925  virtual SourceRange getSourceRange() const {
926    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
927  }
928
929  SourceLocation getRBracketLoc() const { return RBracketLoc; }
930  virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); }
931
932  static bool classof(const Stmt *T) {
933    return T->getStmtClass() == ArraySubscriptExprClass;
934  }
935  static bool classof(const ArraySubscriptExpr *) { return true; }
936
937  // Iterators
938  virtual child_iterator child_begin();
939  virtual child_iterator child_end();
940
941  virtual void EmitImpl(llvm::Serializer& S) const;
942  static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
943};
944
945
946/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
947/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
948/// while its subclasses may represent alternative syntax that (semantically)
949/// results in a function call. For example, CXXOperatorCallExpr is
950/// a subclass for overloaded operator calls that use operator syntax, e.g.,
951/// "str1 + str2" to resolve to a function call.
952class CallExpr : public Expr {
953  enum { FN=0, ARGS_START=1 };
954  Stmt **SubExprs;
955  unsigned NumArgs;
956  SourceLocation RParenLoc;
957
958  // This version of the ctor is for deserialization.
959  CallExpr(StmtClass SC, Stmt** subexprs, unsigned numargs, QualType t,
960           SourceLocation rparenloc)
961  : Expr(SC,t), SubExprs(subexprs),
962    NumArgs(numargs), RParenLoc(rparenloc) {}
963
964protected:
965  // This version of the constructor is for derived classes.
966  CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, unsigned numargs,
967           QualType t, SourceLocation rparenloc);
968
969public:
970  CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, QualType t,
971           SourceLocation rparenloc);
972
973  ~CallExpr() {}
974
975  void Destroy(ASTContext& C);
976
977  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
978  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
979  void setCallee(Expr *F) { SubExprs[FN] = F; }
980
981  /// getNumArgs - Return the number of actual arguments to this call.
982  ///
983  unsigned getNumArgs() const { return NumArgs; }
984
985  /// getArg - Return the specified argument.
986  Expr *getArg(unsigned Arg) {
987    assert(Arg < NumArgs && "Arg access out of range!");
988    return cast<Expr>(SubExprs[Arg+ARGS_START]);
989  }
990  const Expr *getArg(unsigned Arg) const {
991    assert(Arg < NumArgs && "Arg access out of range!");
992    return cast<Expr>(SubExprs[Arg+ARGS_START]);
993  }
994
995  // FIXME: Why is this needed?  Why not just create the CallExpr with the
996  // corect number of arguments?  It makes the ASTs less brittle.
997  /// setArg - Set the specified argument.
998  void setArg(unsigned Arg, Expr *ArgExpr) {
999    assert(Arg < NumArgs && "Arg access out of range!");
1000    SubExprs[Arg+ARGS_START] = ArgExpr;
1001  }
1002
1003  // FIXME: It would be great to just get rid of this.  There is only one
1004  // callee of this method, and it probably could be refactored to not use
1005  // this method and instead just create a CallExpr with the right number of
1006  // arguments.
1007  /// setNumArgs - This changes the number of arguments present in this call.
1008  /// Any orphaned expressions are deleted by this, and any new operands are set
1009  /// to null.
1010  void setNumArgs(ASTContext& C, unsigned NumArgs);
1011
1012  typedef ExprIterator arg_iterator;
1013  typedef ConstExprIterator const_arg_iterator;
1014
1015  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
1016  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
1017  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
1018  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
1019
1020  /// getNumCommas - Return the number of commas that must have been present in
1021  /// this function call.
1022  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
1023
1024  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
1025  /// not, return 0.
1026  unsigned isBuiltinCall(ASTContext &Context) const;
1027
1028  SourceLocation getRParenLoc() const { return RParenLoc; }
1029
1030  virtual SourceRange getSourceRange() const {
1031    return SourceRange(getCallee()->getLocStart(), RParenLoc);
1032  }
1033
1034  static bool classof(const Stmt *T) {
1035    return T->getStmtClass() == CallExprClass ||
1036           T->getStmtClass() == CXXOperatorCallExprClass ||
1037           T->getStmtClass() == CXXMemberCallExprClass;
1038  }
1039  static bool classof(const CallExpr *) { return true; }
1040  static bool classof(const CXXOperatorCallExpr *) { return true; }
1041  static bool classof(const CXXMemberCallExpr *) { return true; }
1042
1043  // Iterators
1044  virtual child_iterator child_begin();
1045  virtual child_iterator child_end();
1046
1047  virtual void EmitImpl(llvm::Serializer& S) const;
1048  static CallExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C,
1049                              StmtClass SC);
1050};
1051
1052/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
1053///
1054class MemberExpr : public Expr {
1055  /// Base - the expression for the base pointer or structure references.  In
1056  /// X.F, this is "X".
1057  Stmt *Base;
1058
1059  /// MemberDecl - This is the decl being referenced by the field/member name.
1060  /// In X.F, this is the decl referenced by F.
1061  NamedDecl *MemberDecl;
1062
1063  /// MemberLoc - This is the location of the member name.
1064  SourceLocation MemberLoc;
1065
1066  /// IsArrow - True if this is "X->F", false if this is "X.F".
1067  bool IsArrow;
1068public:
1069  MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l,
1070             QualType ty)
1071    : Expr(MemberExprClass, ty),
1072      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
1073
1074  void setBase(Expr *E) { Base = E; }
1075  Expr *getBase() const { return cast<Expr>(Base); }
1076
1077  /// \brief Retrieve the member declaration to which this expression refers.
1078  ///
1079  /// The returned declaration will either be a FieldDecl or (in C++)
1080  /// a CXXMethodDecl.
1081  NamedDecl *getMemberDecl() const { return MemberDecl; }
1082  void setMemberDecl(NamedDecl *D) { MemberDecl = D; }
1083  bool isArrow() const { return IsArrow; }
1084
1085  /// getMemberLoc - Return the location of the "member", in X->F, it is the
1086  /// location of 'F'.
1087  SourceLocation getMemberLoc() const { return MemberLoc; }
1088
1089  virtual SourceRange getSourceRange() const {
1090    return SourceRange(getBase()->getLocStart(), MemberLoc);
1091  }
1092
1093  virtual SourceLocation getExprLoc() const { return MemberLoc; }
1094
1095  static bool classof(const Stmt *T) {
1096    return T->getStmtClass() == MemberExprClass;
1097  }
1098  static bool classof(const MemberExpr *) { return true; }
1099
1100  // Iterators
1101  virtual child_iterator child_begin();
1102  virtual child_iterator child_end();
1103
1104  virtual void EmitImpl(llvm::Serializer& S) const;
1105  static MemberExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1106};
1107
1108/// CompoundLiteralExpr - [C99 6.5.2.5]
1109///
1110class CompoundLiteralExpr : public Expr {
1111  /// LParenLoc - If non-null, this is the location of the left paren in a
1112  /// compound literal like "(int){4}".  This can be null if this is a
1113  /// synthesized compound expression.
1114  SourceLocation LParenLoc;
1115  Stmt *Init;
1116  bool FileScope;
1117public:
1118  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init,
1119                      bool fileScope)
1120    : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
1121      FileScope(fileScope) {}
1122
1123  const Expr *getInitializer() const { return cast<Expr>(Init); }
1124  Expr *getInitializer() { return cast<Expr>(Init); }
1125
1126  bool isFileScope() const { return FileScope; }
1127
1128  SourceLocation getLParenLoc() const { return LParenLoc; }
1129
1130  virtual SourceRange getSourceRange() const {
1131    // FIXME: Init should never be null.
1132    if (!Init)
1133      return SourceRange();
1134    if (LParenLoc.isInvalid())
1135      return Init->getSourceRange();
1136    return SourceRange(LParenLoc, Init->getLocEnd());
1137  }
1138
1139  static bool classof(const Stmt *T) {
1140    return T->getStmtClass() == CompoundLiteralExprClass;
1141  }
1142  static bool classof(const CompoundLiteralExpr *) { return true; }
1143
1144  // Iterators
1145  virtual child_iterator child_begin();
1146  virtual child_iterator child_end();
1147
1148  virtual void EmitImpl(llvm::Serializer& S) const;
1149  static CompoundLiteralExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1150};
1151
1152/// CastExpr - Base class for type casts, including both implicit
1153/// casts (ImplicitCastExpr) and explicit casts that have some
1154/// representation in the source code (ExplicitCastExpr's derived
1155/// classes).
1156class CastExpr : public Expr {
1157  Stmt *Op;
1158protected:
1159  CastExpr(StmtClass SC, QualType ty, Expr *op) :
1160    Expr(SC, ty,
1161         // Cast expressions are type-dependent if the type is
1162         // dependent (C++ [temp.dep.expr]p3).
1163         ty->isDependentType(),
1164         // Cast expressions are value-dependent if the type is
1165         // dependent or if the subexpression is value-dependent.
1166         ty->isDependentType() || (op && op->isValueDependent())),
1167    Op(op) {}
1168
1169  /// \brief Construct an empty cast.
1170  CastExpr(StmtClass SC, EmptyShell Empty)
1171    : Expr(SC, Empty) { }
1172
1173public:
1174  Expr *getSubExpr() { return cast<Expr>(Op); }
1175  const Expr *getSubExpr() const { return cast<Expr>(Op); }
1176  void setSubExpr(Expr *E) { Op = E; }
1177
1178  static bool classof(const Stmt *T) {
1179    StmtClass SC = T->getStmtClass();
1180    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
1181      return true;
1182
1183    if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass)
1184      return true;
1185
1186    return false;
1187  }
1188  static bool classof(const CastExpr *) { return true; }
1189
1190  // Iterators
1191  virtual child_iterator child_begin();
1192  virtual child_iterator child_end();
1193};
1194
1195/// ImplicitCastExpr - Allows us to explicitly represent implicit type
1196/// conversions, which have no direct representation in the original
1197/// source code. For example: converting T[]->T*, void f()->void
1198/// (*f)(), float->double, short->int, etc.
1199///
1200/// In C, implicit casts always produce rvalues. However, in C++, an
1201/// implicit cast whose result is being bound to a reference will be
1202/// an lvalue. For example:
1203///
1204/// @code
1205/// class Base { };
1206/// class Derived : public Base { };
1207/// void f(Derived d) {
1208///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
1209/// }
1210/// @endcode
1211class ImplicitCastExpr : public CastExpr {
1212  /// LvalueCast - Whether this cast produces an lvalue.
1213  bool LvalueCast;
1214
1215public:
1216  ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) :
1217    CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) { }
1218
1219  /// \brief Construct an empty implicit cast.
1220  explicit ImplicitCastExpr(EmptyShell Shell)
1221    : CastExpr(ImplicitCastExprClass, Shell) { }
1222
1223
1224  virtual SourceRange getSourceRange() const {
1225    return getSubExpr()->getSourceRange();
1226  }
1227
1228  /// isLvalueCast - Whether this cast produces an lvalue.
1229  bool isLvalueCast() const { return LvalueCast; }
1230
1231  /// setLvalueCast - Set whether this cast produces an lvalue.
1232  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1233
1234  static bool classof(const Stmt *T) {
1235    return T->getStmtClass() == ImplicitCastExprClass;
1236  }
1237  static bool classof(const ImplicitCastExpr *) { return true; }
1238
1239  virtual void EmitImpl(llvm::Serializer& S) const;
1240  static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1241};
1242
1243/// ExplicitCastExpr - An explicit cast written in the source
1244/// code.
1245///
1246/// This class is effectively an abstract class, because it provides
1247/// the basic representation of an explicitly-written cast without
1248/// specifying which kind of cast (C cast, functional cast, static
1249/// cast, etc.) was written; specific derived classes represent the
1250/// particular style of cast and its location information.
1251///
1252/// Unlike implicit casts, explicit cast nodes have two different
1253/// types: the type that was written into the source code, and the
1254/// actual type of the expression as determined by semantic
1255/// analysis. These types may differ slightly. For example, in C++ one
1256/// can cast to a reference type, which indicates that the resulting
1257/// expression will be an lvalue. The reference type, however, will
1258/// not be used as the type of the expression.
1259class ExplicitCastExpr : public CastExpr {
1260  /// TypeAsWritten - The type that this expression is casting to, as
1261  /// written in the source code.
1262  QualType TypeAsWritten;
1263
1264protected:
1265  ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy)
1266    : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {}
1267
1268  /// \brief Construct an empty explicit cast.
1269  ExplicitCastExpr(StmtClass SC, EmptyShell Shell)
1270    : CastExpr(SC, Shell) { }
1271
1272public:
1273  /// getTypeAsWritten - Returns the type that this expression is
1274  /// casting to, as written in the source code.
1275  QualType getTypeAsWritten() const { return TypeAsWritten; }
1276  void setTypeAsWritten(QualType T) { TypeAsWritten = T; }
1277
1278  static bool classof(const Stmt *T) {
1279    StmtClass SC = T->getStmtClass();
1280    if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass)
1281      return true;
1282    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
1283      return true;
1284
1285    return false;
1286  }
1287  static bool classof(const ExplicitCastExpr *) { return true; }
1288};
1289
1290/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
1291/// cast in C++ (C++ [expr.cast]), which uses the syntax
1292/// (Type)expr. For example: @c (int)f.
1293class CStyleCastExpr : public ExplicitCastExpr {
1294  SourceLocation LPLoc; // the location of the left paren
1295  SourceLocation RPLoc; // the location of the right paren
1296public:
1297  CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy,
1298                    SourceLocation l, SourceLocation r) :
1299    ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy),
1300    LPLoc(l), RPLoc(r) {}
1301
1302  /// \brief Construct an empty C-style explicit cast.
1303  explicit CStyleCastExpr(EmptyShell Shell)
1304    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
1305
1306  SourceLocation getLParenLoc() const { return LPLoc; }
1307  void setLParenLoc(SourceLocation L) { LPLoc = L; }
1308
1309  SourceLocation getRParenLoc() const { return RPLoc; }
1310  void setRParenLoc(SourceLocation L) { RPLoc = L; }
1311
1312  virtual SourceRange getSourceRange() const {
1313    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
1314  }
1315  static bool classof(const Stmt *T) {
1316    return T->getStmtClass() == CStyleCastExprClass;
1317  }
1318  static bool classof(const CStyleCastExpr *) { return true; }
1319
1320  virtual void EmitImpl(llvm::Serializer& S) const;
1321  static CStyleCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1322};
1323
1324/// \brief A builtin binary operation expression such as "x + y" or "x <= y".
1325///
1326/// This expression node kind describes a builtin binary operation,
1327/// such as "x + y" for integer values "x" and "y". The operands will
1328/// already have been converted to appropriate types (e.g., by
1329/// performing promotions or conversions).
1330///
1331/// In C++, where operators may be overloaded, a different kind of
1332/// expression node (CXXOperatorCallExpr) is used to express the
1333/// invocation of an overloaded operator with operator syntax. Within
1334/// a C++ template, whether BinaryOperator or CXXOperatorCallExpr is
1335/// used to store an expression "x + y" depends on the subexpressions
1336/// for x and y. If neither x or y is type-dependent, and the "+"
1337/// operator resolves to a built-in operation, BinaryOperator will be
1338/// used to express the computation (x and y may still be
1339/// value-dependent). If either x or y is type-dependent, or if the
1340/// "+" resolves to an overloaded operator, CXXOperatorCallExpr will
1341/// be used to express the computation.
1342class BinaryOperator : public Expr {
1343public:
1344  enum Opcode {
1345    // Operators listed in order of precedence.
1346    // Note that additions to this should also update the StmtVisitor class.
1347    PtrMemD, PtrMemI, // [C++ 5.5] Pointer-to-member operators.
1348    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
1349    Add, Sub,         // [C99 6.5.6] Additive operators.
1350    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
1351    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
1352    EQ, NE,           // [C99 6.5.9] Equality operators.
1353    And,              // [C99 6.5.10] Bitwise AND operator.
1354    Xor,              // [C99 6.5.11] Bitwise XOR operator.
1355    Or,               // [C99 6.5.12] Bitwise OR operator.
1356    LAnd,             // [C99 6.5.13] Logical AND operator.
1357    LOr,              // [C99 6.5.14] Logical OR operator.
1358    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
1359    DivAssign, RemAssign,
1360    AddAssign, SubAssign,
1361    ShlAssign, ShrAssign,
1362    AndAssign, XorAssign,
1363    OrAssign,
1364    Comma             // [C99 6.5.17] Comma operator.
1365  };
1366private:
1367  enum { LHS, RHS, END_EXPR };
1368  Stmt* SubExprs[END_EXPR];
1369  Opcode Opc;
1370  SourceLocation OpLoc;
1371public:
1372
1373  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
1374                 SourceLocation opLoc)
1375    : Expr(BinaryOperatorClass, ResTy,
1376           lhs->isTypeDependent() || rhs->isTypeDependent(),
1377           lhs->isValueDependent() || rhs->isValueDependent()),
1378      Opc(opc), OpLoc(opLoc) {
1379    SubExprs[LHS] = lhs;
1380    SubExprs[RHS] = rhs;
1381    assert(!isCompoundAssignmentOp() &&
1382           "Use ArithAssignBinaryOperator for compound assignments");
1383  }
1384
1385  /// \brief Construct an empty binary operator.
1386  explicit BinaryOperator(EmptyShell Empty)
1387    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
1388
1389  SourceLocation getOperatorLoc() const { return OpLoc; }
1390  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
1391
1392  Opcode getOpcode() const { return Opc; }
1393  void setOpcode(Opcode O) { Opc = O; }
1394
1395  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1396  void setLHS(Expr *E) { SubExprs[LHS] = E; }
1397  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1398  void setRHS(Expr *E) { SubExprs[RHS] = E; }
1399
1400  virtual SourceRange getSourceRange() const {
1401    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
1402  }
1403
1404  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1405  /// corresponds to, e.g. "<<=".
1406  static const char *getOpcodeStr(Opcode Op);
1407
1408  /// \brief Retrieve the binary opcode that corresponds to the given
1409  /// overloaded operator.
1410  static Opcode getOverloadedOpcode(OverloadedOperatorKind OO);
1411
1412  /// \brief Retrieve the overloaded operator kind that corresponds to
1413  /// the given binary opcode.
1414  static OverloadedOperatorKind getOverloadedOperator(Opcode Opc);
1415
1416  /// predicates to categorize the respective opcodes.
1417  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
1418  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
1419  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
1420  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
1421
1422  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
1423  bool isRelationalOp() const { return isRelationalOp(Opc); }
1424
1425  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
1426  bool isEqualityOp() const { return isEqualityOp(Opc); }
1427
1428  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
1429  bool isLogicalOp() const { return isLogicalOp(Opc); }
1430
1431  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
1432  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
1433  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
1434
1435  static bool classof(const Stmt *S) {
1436    return S->getStmtClass() == BinaryOperatorClass ||
1437           S->getStmtClass() == CompoundAssignOperatorClass;
1438  }
1439  static bool classof(const BinaryOperator *) { return true; }
1440
1441  // Iterators
1442  virtual child_iterator child_begin();
1443  virtual child_iterator child_end();
1444
1445  virtual void EmitImpl(llvm::Serializer& S) const;
1446  static BinaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1447
1448protected:
1449  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
1450                 SourceLocation oploc, bool dead)
1451    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
1452    SubExprs[LHS] = lhs;
1453    SubExprs[RHS] = rhs;
1454  }
1455};
1456
1457/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
1458/// track of the type the operation is performed in.  Due to the semantics of
1459/// these operators, the operands are promoted, the aritmetic performed, an
1460/// implicit conversion back to the result type done, then the assignment takes
1461/// place.  This captures the intermediate type which the computation is done
1462/// in.
1463class CompoundAssignOperator : public BinaryOperator {
1464  QualType ComputationLHSType;
1465  QualType ComputationResultType;
1466public:
1467  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
1468                         QualType ResType, QualType CompLHSType,
1469                         QualType CompResultType,
1470                         SourceLocation OpLoc)
1471    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
1472      ComputationLHSType(CompLHSType),
1473      ComputationResultType(CompResultType) {
1474    assert(isCompoundAssignmentOp() &&
1475           "Only should be used for compound assignments");
1476  }
1477
1478  // The two computation types are the type the LHS is converted
1479  // to for the computation and the type of the result; the two are
1480  // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
1481  QualType getComputationLHSType() const { return ComputationLHSType; }
1482  QualType getComputationResultType() const { return ComputationResultType; }
1483
1484  static bool classof(const CompoundAssignOperator *) { return true; }
1485  static bool classof(const Stmt *S) {
1486    return S->getStmtClass() == CompoundAssignOperatorClass;
1487  }
1488
1489  virtual void EmitImpl(llvm::Serializer& S) const;
1490  static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D,
1491                                            ASTContext& C);
1492};
1493
1494/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
1495/// GNU "missing LHS" extension is in use.
1496///
1497class ConditionalOperator : public Expr {
1498  enum { COND, LHS, RHS, END_EXPR };
1499  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1500public:
1501  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
1502    : Expr(ConditionalOperatorClass, t,
1503           // FIXME: the type of the conditional operator doesn't
1504           // depend on the type of the conditional, but the standard
1505           // seems to imply that it could. File a bug!
1506           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
1507           (cond->isValueDependent() ||
1508            (lhs && lhs->isValueDependent()) ||
1509            (rhs && rhs->isValueDependent()))) {
1510    SubExprs[COND] = cond;
1511    SubExprs[LHS] = lhs;
1512    SubExprs[RHS] = rhs;
1513  }
1514
1515  // getCond - Return the expression representing the condition for
1516  //  the ?: operator.
1517  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1518
1519  // getTrueExpr - Return the subexpression representing the value of the ?:
1520  //  expression if the condition evaluates to true.  In most cases this value
1521  //  will be the same as getLHS() except a GCC extension allows the left
1522  //  subexpression to be omitted, and instead of the condition be returned.
1523  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
1524  //  is only evaluated once.
1525  Expr *getTrueExpr() const {
1526    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
1527  }
1528
1529  // getTrueExpr - Return the subexpression representing the value of the ?:
1530  // expression if the condition evaluates to false. This is the same as getRHS.
1531  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
1532
1533  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
1534  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1535
1536  virtual SourceRange getSourceRange() const {
1537    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
1538  }
1539  static bool classof(const Stmt *T) {
1540    return T->getStmtClass() == ConditionalOperatorClass;
1541  }
1542  static bool classof(const ConditionalOperator *) { return true; }
1543
1544  // Iterators
1545  virtual child_iterator child_begin();
1546  virtual child_iterator child_end();
1547
1548  virtual void EmitImpl(llvm::Serializer& S) const;
1549  static ConditionalOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1550};
1551
1552/// AddrLabelExpr - The GNU address of label extension, representing &&label.
1553class AddrLabelExpr : public Expr {
1554  SourceLocation AmpAmpLoc, LabelLoc;
1555  LabelStmt *Label;
1556public:
1557  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
1558                QualType t)
1559    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
1560
1561  virtual SourceRange getSourceRange() const {
1562    return SourceRange(AmpAmpLoc, LabelLoc);
1563  }
1564
1565  LabelStmt *getLabel() const { return Label; }
1566
1567  static bool classof(const Stmt *T) {
1568    return T->getStmtClass() == AddrLabelExprClass;
1569  }
1570  static bool classof(const AddrLabelExpr *) { return true; }
1571
1572  // Iterators
1573  virtual child_iterator child_begin();
1574  virtual child_iterator child_end();
1575
1576  virtual void EmitImpl(llvm::Serializer& S) const;
1577  static AddrLabelExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1578};
1579
1580/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
1581/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
1582/// takes the value of the last subexpression.
1583class StmtExpr : public Expr {
1584  Stmt *SubStmt;
1585  SourceLocation LParenLoc, RParenLoc;
1586public:
1587  StmtExpr(CompoundStmt *substmt, QualType T,
1588           SourceLocation lp, SourceLocation rp) :
1589    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
1590
1591  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
1592  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
1593
1594  virtual SourceRange getSourceRange() const {
1595    return SourceRange(LParenLoc, RParenLoc);
1596  }
1597
1598  SourceLocation getLParenLoc() const { return LParenLoc; }
1599  SourceLocation getRParenLoc() const { return RParenLoc; }
1600
1601  static bool classof(const Stmt *T) {
1602    return T->getStmtClass() == StmtExprClass;
1603  }
1604  static bool classof(const StmtExpr *) { return true; }
1605
1606  // Iterators
1607  virtual child_iterator child_begin();
1608  virtual child_iterator child_end();
1609
1610  virtual void EmitImpl(llvm::Serializer& S) const;
1611  static StmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1612};
1613
1614/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
1615/// This AST node represents a function that returns 1 if two *types* (not
1616/// expressions) are compatible. The result of this built-in function can be
1617/// used in integer constant expressions.
1618class TypesCompatibleExpr : public Expr {
1619  QualType Type1;
1620  QualType Type2;
1621  SourceLocation BuiltinLoc, RParenLoc;
1622public:
1623  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
1624                      QualType t1, QualType t2, SourceLocation RP) :
1625    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1626    BuiltinLoc(BLoc), RParenLoc(RP) {}
1627
1628  QualType getArgType1() const { return Type1; }
1629  QualType getArgType2() const { return Type2; }
1630
1631  virtual SourceRange getSourceRange() const {
1632    return SourceRange(BuiltinLoc, RParenLoc);
1633  }
1634  static bool classof(const Stmt *T) {
1635    return T->getStmtClass() == TypesCompatibleExprClass;
1636  }
1637  static bool classof(const TypesCompatibleExpr *) { return true; }
1638
1639  // Iterators
1640  virtual child_iterator child_begin();
1641  virtual child_iterator child_end();
1642
1643  virtual void EmitImpl(llvm::Serializer& S) const;
1644  static TypesCompatibleExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1645};
1646
1647/// ShuffleVectorExpr - clang-specific builtin-in function
1648/// __builtin_shufflevector.
1649/// This AST node represents a operator that does a constant
1650/// shuffle, similar to LLVM's shufflevector instruction. It takes
1651/// two vectors and a variable number of constant indices,
1652/// and returns the appropriately shuffled vector.
1653class ShuffleVectorExpr : public Expr {
1654  SourceLocation BuiltinLoc, RParenLoc;
1655
1656  // SubExprs - the list of values passed to the __builtin_shufflevector
1657  // function. The first two are vectors, and the rest are constant
1658  // indices.  The number of values in this list is always
1659  // 2+the number of indices in the vector type.
1660  Stmt **SubExprs;
1661  unsigned NumExprs;
1662
1663public:
1664  ShuffleVectorExpr(Expr **args, unsigned nexpr,
1665                    QualType Type, SourceLocation BLoc,
1666                    SourceLocation RP) :
1667    Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc),
1668    RParenLoc(RP), NumExprs(nexpr) {
1669
1670    SubExprs = new Stmt*[nexpr];
1671    for (unsigned i = 0; i < nexpr; i++)
1672      SubExprs[i] = args[i];
1673  }
1674
1675  virtual SourceRange getSourceRange() const {
1676    return SourceRange(BuiltinLoc, RParenLoc);
1677  }
1678  static bool classof(const Stmt *T) {
1679    return T->getStmtClass() == ShuffleVectorExprClass;
1680  }
1681  static bool classof(const ShuffleVectorExpr *) { return true; }
1682
1683  ~ShuffleVectorExpr() {
1684    delete [] SubExprs;
1685  }
1686
1687  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1688  /// constant expression, the actual arguments passed in, and the function
1689  /// pointers.
1690  unsigned getNumSubExprs() const { return NumExprs; }
1691
1692  /// getExpr - Return the Expr at the specified index.
1693  Expr *getExpr(unsigned Index) {
1694    assert((Index < NumExprs) && "Arg access out of range!");
1695    return cast<Expr>(SubExprs[Index]);
1696  }
1697  const Expr *getExpr(unsigned Index) const {
1698    assert((Index < NumExprs) && "Arg access out of range!");
1699    return cast<Expr>(SubExprs[Index]);
1700  }
1701
1702  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
1703    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
1704    return getExpr(N+2)->getIntegerConstantExprValue(Ctx).getZExtValue();
1705  }
1706
1707  // Iterators
1708  virtual child_iterator child_begin();
1709  virtual child_iterator child_end();
1710
1711  virtual void EmitImpl(llvm::Serializer& S) const;
1712  static ShuffleVectorExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1713};
1714
1715/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
1716/// This AST node is similar to the conditional operator (?:) in C, with
1717/// the following exceptions:
1718/// - the test expression must be a integer constant expression.
1719/// - the expression returned acts like the chosen subexpression in every
1720///   visible way: the type is the same as that of the chosen subexpression,
1721///   and all predicates (whether it's an l-value, whether it's an integer
1722///   constant expression, etc.) return the same result as for the chosen
1723///   sub-expression.
1724class ChooseExpr : public Expr {
1725  enum { COND, LHS, RHS, END_EXPR };
1726  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1727  SourceLocation BuiltinLoc, RParenLoc;
1728public:
1729  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
1730             SourceLocation RP)
1731    : Expr(ChooseExprClass, t),
1732      BuiltinLoc(BLoc), RParenLoc(RP) {
1733      SubExprs[COND] = cond;
1734      SubExprs[LHS] = lhs;
1735      SubExprs[RHS] = rhs;
1736    }
1737
1738  /// isConditionTrue - Return whether the condition is true (i.e. not
1739  /// equal to zero).
1740  bool isConditionTrue(ASTContext &C) const;
1741
1742  /// getChosenSubExpr - Return the subexpression chosen according to the
1743  /// condition.
1744  Expr *getChosenSubExpr(ASTContext &C) const {
1745    return isConditionTrue(C) ? getLHS() : getRHS();
1746  }
1747
1748  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1749  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1750  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1751
1752  virtual SourceRange getSourceRange() const {
1753    return SourceRange(BuiltinLoc, RParenLoc);
1754  }
1755  static bool classof(const Stmt *T) {
1756    return T->getStmtClass() == ChooseExprClass;
1757  }
1758  static bool classof(const ChooseExpr *) { return true; }
1759
1760  // Iterators
1761  virtual child_iterator child_begin();
1762  virtual child_iterator child_end();
1763
1764  virtual void EmitImpl(llvm::Serializer& S) const;
1765  static ChooseExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1766};
1767
1768/// GNUNullExpr - Implements the GNU __null extension, which is a name
1769/// for a null pointer constant that has integral type (e.g., int or
1770/// long) and is the same size and alignment as a pointer. The __null
1771/// extension is typically only used by system headers, which define
1772/// NULL as __null in C++ rather than using 0 (which is an integer
1773/// that may not match the size of a pointer).
1774class GNUNullExpr : public Expr {
1775  /// TokenLoc - The location of the __null keyword.
1776  SourceLocation TokenLoc;
1777
1778public:
1779  GNUNullExpr(QualType Ty, SourceLocation Loc)
1780    : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
1781
1782  /// getTokenLocation - The location of the __null token.
1783  SourceLocation getTokenLocation() const { return TokenLoc; }
1784
1785  virtual SourceRange getSourceRange() const {
1786    return SourceRange(TokenLoc);
1787  }
1788  static bool classof(const Stmt *T) {
1789    return T->getStmtClass() == GNUNullExprClass;
1790  }
1791  static bool classof(const GNUNullExpr *) { return true; }
1792
1793  // Iterators
1794  virtual child_iterator child_begin();
1795  virtual child_iterator child_end();
1796
1797  virtual void EmitImpl(llvm::Serializer& S) const;
1798  static GNUNullExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1799};
1800
1801/// VAArgExpr, used for the builtin function __builtin_va_start.
1802class VAArgExpr : public Expr {
1803  Stmt *Val;
1804  SourceLocation BuiltinLoc, RParenLoc;
1805public:
1806  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
1807    : Expr(VAArgExprClass, t),
1808      Val(e),
1809      BuiltinLoc(BLoc),
1810      RParenLoc(RPLoc) { }
1811
1812  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1813  Expr *getSubExpr() { return cast<Expr>(Val); }
1814  virtual SourceRange getSourceRange() const {
1815    return SourceRange(BuiltinLoc, RParenLoc);
1816  }
1817  static bool classof(const Stmt *T) {
1818    return T->getStmtClass() == VAArgExprClass;
1819  }
1820  static bool classof(const VAArgExpr *) { return true; }
1821
1822  // Iterators
1823  virtual child_iterator child_begin();
1824  virtual child_iterator child_end();
1825
1826  virtual void EmitImpl(llvm::Serializer& S) const;
1827  static VAArgExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1828};
1829
1830/// @brief Describes an C or C++ initializer list.
1831///
1832/// InitListExpr describes an initializer list, which can be used to
1833/// initialize objects of different types, including
1834/// struct/class/union types, arrays, and vectors. For example:
1835///
1836/// @code
1837/// struct foo x = { 1, { 2, 3 } };
1838/// @endcode
1839///
1840/// Prior to semantic analysis, an initializer list will represent the
1841/// initializer list as written by the user, but will have the
1842/// placeholder type "void". This initializer list is called the
1843/// syntactic form of the initializer, and may contain C99 designated
1844/// initializers (represented as DesignatedInitExprs), initializations
1845/// of subobject members without explicit braces, and so on. Clients
1846/// interested in the original syntax of the initializer list should
1847/// use the syntactic form of the initializer list.
1848///
1849/// After semantic analysis, the initializer list will represent the
1850/// semantic form of the initializer, where the initializations of all
1851/// subobjects are made explicit with nested InitListExpr nodes and
1852/// C99 designators have been eliminated by placing the designated
1853/// initializations into the subobject they initialize. Additionally,
1854/// any "holes" in the initialization, where no initializer has been
1855/// specified for a particular subobject, will be replaced with
1856/// implicitly-generated ImplicitValueInitExpr expressions that
1857/// value-initialize the subobjects. Note, however, that the
1858/// initializer lists may still have fewer initializers than there are
1859/// elements to initialize within the object.
1860///
1861/// Given the semantic form of the initializer list, one can retrieve
1862/// the original syntactic form of that initializer list (if it
1863/// exists) using getSyntacticForm(). Since many initializer lists
1864/// have the same syntactic and semantic forms, getSyntacticForm() may
1865/// return NULL, indicating that the current initializer list also
1866/// serves as its syntactic form.
1867class InitListExpr : public Expr {
1868  std::vector<Stmt *> InitExprs;
1869  SourceLocation LBraceLoc, RBraceLoc;
1870
1871  /// Contains the initializer list that describes the syntactic form
1872  /// written in the source code.
1873  InitListExpr *SyntacticForm;
1874
1875  /// If this initializer list initializes a union, specifies which
1876  /// field within the union will be initialized.
1877  FieldDecl *UnionFieldInit;
1878
1879  /// Whether this initializer list originally had a GNU array-range
1880  /// designator in it. This is a temporary marker used by CodeGen.
1881  bool HadArrayRangeDesignator;
1882
1883public:
1884  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
1885               SourceLocation rbraceloc);
1886
1887  unsigned getNumInits() const { return InitExprs.size(); }
1888
1889  const Expr* getInit(unsigned Init) const {
1890    assert(Init < getNumInits() && "Initializer access out of range!");
1891    return cast_or_null<Expr>(InitExprs[Init]);
1892  }
1893
1894  Expr* getInit(unsigned Init) {
1895    assert(Init < getNumInits() && "Initializer access out of range!");
1896    return cast_or_null<Expr>(InitExprs[Init]);
1897  }
1898
1899  void setInit(unsigned Init, Expr *expr) {
1900    assert(Init < getNumInits() && "Initializer access out of range!");
1901    InitExprs[Init] = expr;
1902  }
1903
1904  /// \brief Reserve space for some number of initializers.
1905  void reserveInits(unsigned NumInits);
1906
1907  /// @brief Specify the number of initializers
1908  ///
1909  /// If there are more than @p NumInits initializers, the remaining
1910  /// initializers will be destroyed. If there are fewer than @p
1911  /// NumInits initializers, NULL expressions will be added for the
1912  /// unknown initializers.
1913  void resizeInits(ASTContext &Context, unsigned NumInits);
1914
1915  /// @brief Updates the initializer at index @p Init with the new
1916  /// expression @p expr, and returns the old expression at that
1917  /// location.
1918  ///
1919  /// When @p Init is out of range for this initializer list, the
1920  /// initializer list will be extended with NULL expressions to
1921  /// accomodate the new entry.
1922  Expr *updateInit(unsigned Init, Expr *expr);
1923
1924  /// \brief If this initializes a union, specifies which field in the
1925  /// union to initialize.
1926  ///
1927  /// Typically, this field is the first named field within the
1928  /// union. However, a designated initializer can specify the
1929  /// initialization of a different field within the union.
1930  FieldDecl *getInitializedFieldInUnion() { return UnionFieldInit; }
1931  void setInitializedFieldInUnion(FieldDecl *FD) { UnionFieldInit = FD; }
1932
1933  // Explicit InitListExpr's originate from source code (and have valid source
1934  // locations). Implicit InitListExpr's are created by the semantic analyzer.
1935  bool isExplicit() {
1936    return LBraceLoc.isValid() && RBraceLoc.isValid();
1937  }
1938
1939  void setRBraceLoc(SourceLocation Loc) { RBraceLoc = Loc; }
1940
1941  /// @brief Retrieve the initializer list that describes the
1942  /// syntactic form of the initializer.
1943  ///
1944  ///
1945  InitListExpr *getSyntacticForm() const { return SyntacticForm; }
1946  void setSyntacticForm(InitListExpr *Init) { SyntacticForm = Init; }
1947
1948  bool hadArrayRangeDesignator() const { return HadArrayRangeDesignator; }
1949  void sawArrayRangeDesignator() {
1950    HadArrayRangeDesignator = true;
1951  }
1952
1953  virtual SourceRange getSourceRange() const {
1954    return SourceRange(LBraceLoc, RBraceLoc);
1955  }
1956  static bool classof(const Stmt *T) {
1957    return T->getStmtClass() == InitListExprClass;
1958  }
1959  static bool classof(const InitListExpr *) { return true; }
1960
1961  // Iterators
1962  virtual child_iterator child_begin();
1963  virtual child_iterator child_end();
1964
1965  typedef std::vector<Stmt *>::iterator iterator;
1966  typedef std::vector<Stmt *>::reverse_iterator reverse_iterator;
1967
1968  iterator begin() { return InitExprs.begin(); }
1969  iterator end() { return InitExprs.end(); }
1970  reverse_iterator rbegin() { return InitExprs.rbegin(); }
1971  reverse_iterator rend() { return InitExprs.rend(); }
1972
1973  // Serailization.
1974  virtual void EmitImpl(llvm::Serializer& S) const;
1975  static InitListExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1976
1977private:
1978  // Used by serializer.
1979  InitListExpr() : Expr(InitListExprClass, QualType()) {}
1980};
1981
1982/// @brief Represents a C99 designated initializer expression.
1983///
1984/// A designated initializer expression (C99 6.7.8) contains one or
1985/// more designators (which can be field designators, array
1986/// designators, or GNU array-range designators) followed by an
1987/// expression that initializes the field or element(s) that the
1988/// designators refer to. For example, given:
1989///
1990/// @code
1991/// struct point {
1992///   double x;
1993///   double y;
1994/// };
1995/// struct point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
1996/// @endcode
1997///
1998/// The InitListExpr contains three DesignatedInitExprs, the first of
1999/// which covers @c [2].y=1.0. This DesignatedInitExpr will have two
2000/// designators, one array designator for @c [2] followed by one field
2001/// designator for @c .y. The initalization expression will be 1.0.
2002class DesignatedInitExpr : public Expr {
2003public:
2004  /// \brief Forward declaration of the Designator class.
2005  class Designator;
2006
2007private:
2008  /// The location of the '=' or ':' prior to the actual initializer
2009  /// expression.
2010  SourceLocation EqualOrColonLoc;
2011
2012  /// Whether this designated initializer used the GNU deprecated
2013  /// syntax rather than the C99 '=' syntax.
2014  bool GNUSyntax : 1;
2015
2016  /// The number of designators in this initializer expression.
2017  unsigned NumDesignators : 15;
2018
2019  /// \brief The designators in this designated initialization
2020  /// expression.
2021  Designator *Designators;
2022
2023  /// The number of subexpressions of this initializer expression,
2024  /// which contains both the initializer and any additional
2025  /// expressions used by array and array-range designators.
2026  unsigned NumSubExprs : 16;
2027
2028
2029  DesignatedInitExpr(QualType Ty, unsigned NumDesignators,
2030                     const Designator *Designators,
2031                     SourceLocation EqualOrColonLoc, bool GNUSyntax,
2032                     unsigned NumSubExprs);
2033
2034public:
2035  /// A field designator, e.g., ".x".
2036  struct FieldDesignator {
2037    /// Refers to the field that is being initialized. The low bit
2038    /// of this field determines whether this is actually a pointer
2039    /// to an IdentifierInfo (if 1) or a FieldDecl (if 0). When
2040    /// initially constructed, a field designator will store an
2041    /// IdentifierInfo*. After semantic analysis has resolved that
2042    /// name, the field designator will instead store a FieldDecl*.
2043    uintptr_t NameOrField;
2044
2045    /// The location of the '.' in the designated initializer.
2046    unsigned DotLoc;
2047
2048    /// The location of the field name in the designated initializer.
2049    unsigned FieldLoc;
2050  };
2051
2052  /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
2053  struct ArrayOrRangeDesignator {
2054    /// Location of the first index expression within the designated
2055    /// initializer expression's list of subexpressions.
2056    unsigned Index;
2057    /// The location of the '[' starting the array range designator.
2058    unsigned LBracketLoc;
2059    /// The location of the ellipsis separating the start and end
2060    /// indices. Only valid for GNU array-range designators.
2061    unsigned EllipsisLoc;
2062    /// The location of the ']' terminating the array range designator.
2063    unsigned RBracketLoc;
2064  };
2065
2066  /// @brief Represents a single C99 designator.
2067  ///
2068  /// @todo This class is infuriatingly similar to clang::Designator,
2069  /// but minor differences (storing indices vs. storing pointers)
2070  /// keep us from reusing it. Try harder, later, to rectify these
2071  /// differences.
2072  class Designator {
2073    /// @brief The kind of designator this describes.
2074    enum {
2075      FieldDesignator,
2076      ArrayDesignator,
2077      ArrayRangeDesignator
2078    } Kind;
2079
2080    union {
2081      /// A field designator, e.g., ".x".
2082      struct FieldDesignator Field;
2083      /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
2084      struct ArrayOrRangeDesignator ArrayOrRange;
2085    };
2086    friend class DesignatedInitExpr;
2087
2088  public:
2089    Designator() {}
2090
2091    /// @brief Initializes a field designator.
2092    Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
2093               SourceLocation FieldLoc)
2094      : Kind(FieldDesignator) {
2095      Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
2096      Field.DotLoc = DotLoc.getRawEncoding();
2097      Field.FieldLoc = FieldLoc.getRawEncoding();
2098    }
2099
2100    /// @brief Initializes an array designator.
2101    Designator(unsigned Index, SourceLocation LBracketLoc,
2102               SourceLocation RBracketLoc)
2103      : Kind(ArrayDesignator) {
2104      ArrayOrRange.Index = Index;
2105      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
2106      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
2107      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
2108    }
2109
2110    /// @brief Initializes a GNU array-range designator.
2111    Designator(unsigned Index, SourceLocation LBracketLoc,
2112               SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
2113      : Kind(ArrayRangeDesignator) {
2114      ArrayOrRange.Index = Index;
2115      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
2116      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
2117      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
2118    }
2119
2120    bool isFieldDesignator() const { return Kind == FieldDesignator; }
2121    bool isArrayDesignator() const { return Kind == ArrayDesignator; }
2122    bool isArrayRangeDesignator() const { return Kind == ArrayRangeDesignator; }
2123
2124    IdentifierInfo * getFieldName();
2125
2126    FieldDecl *getField() {
2127      assert(Kind == FieldDesignator && "Only valid on a field designator");
2128      if (Field.NameOrField & 0x01)
2129        return 0;
2130      else
2131        return reinterpret_cast<FieldDecl *>(Field.NameOrField);
2132    }
2133
2134    void setField(FieldDecl *FD) {
2135      assert(Kind == FieldDesignator && "Only valid on a field designator");
2136      Field.NameOrField = reinterpret_cast<uintptr_t>(FD);
2137    }
2138
2139    SourceLocation getDotLoc() const {
2140      assert(Kind == FieldDesignator && "Only valid on a field designator");
2141      return SourceLocation::getFromRawEncoding(Field.DotLoc);
2142    }
2143
2144    SourceLocation getFieldLoc() const {
2145      assert(Kind == FieldDesignator && "Only valid on a field designator");
2146      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
2147    }
2148
2149    SourceLocation getLBracketLoc() const {
2150      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2151             "Only valid on an array or array-range designator");
2152      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
2153    }
2154
2155    SourceLocation getRBracketLoc() const {
2156      assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
2157             "Only valid on an array or array-range designator");
2158      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
2159    }
2160
2161    SourceLocation getEllipsisLoc() const {
2162      assert(Kind == ArrayRangeDesignator &&
2163             "Only valid on an array-range designator");
2164      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
2165    }
2166
2167    SourceLocation getStartLocation() const {
2168      if (Kind == FieldDesignator)
2169        return getDotLoc().isInvalid()? getFieldLoc() : getDotLoc();
2170      else
2171        return getLBracketLoc();
2172    }
2173  };
2174
2175  static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators,
2176                                    unsigned NumDesignators,
2177                                    Expr **IndexExprs, unsigned NumIndexExprs,
2178                                    SourceLocation EqualOrColonLoc,
2179                                    bool GNUSyntax, Expr *Init);
2180
2181  /// @brief Returns the number of designators in this initializer.
2182  unsigned size() const { return NumDesignators; }
2183
2184  // Iterator access to the designators.
2185  typedef Designator* designators_iterator;
2186  designators_iterator designators_begin() { return Designators; }
2187  designators_iterator designators_end() {
2188    return Designators + NumDesignators;
2189  }
2190
2191  Designator *getDesignator(unsigned Idx) { return &designators_begin()[Idx]; }
2192
2193  Expr *getArrayIndex(const Designator& D);
2194  Expr *getArrayRangeStart(const Designator& D);
2195  Expr *getArrayRangeEnd(const Designator& D);
2196
2197  /// @brief Retrieve the location of the '=' that precedes the
2198  /// initializer value itself, if present.
2199  SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
2200
2201  /// @brief Determines whether this designated initializer used the
2202  /// deprecated GNU syntax for designated initializers.
2203  bool usesGNUSyntax() const { return GNUSyntax; }
2204
2205  /// @brief Retrieve the initializer value.
2206  Expr *getInit() const {
2207    return cast<Expr>(*const_cast<DesignatedInitExpr*>(this)->child_begin());
2208  }
2209
2210  void setInit(Expr *init) {
2211    *child_begin() = init;
2212  }
2213
2214  /// \brief Replaces the designator at index @p Idx with the series
2215  /// of designators in [First, Last).
2216  void ExpandDesignator(unsigned Idx, const Designator *First,
2217                        const Designator *Last);
2218
2219  virtual SourceRange getSourceRange() const;
2220
2221  virtual void Destroy(ASTContext &C);
2222
2223  static bool classof(const Stmt *T) {
2224    return T->getStmtClass() == DesignatedInitExprClass;
2225  }
2226  static bool classof(const DesignatedInitExpr *) { return true; }
2227
2228  // Iterators
2229  virtual child_iterator child_begin();
2230  virtual child_iterator child_end();
2231};
2232
2233/// \brief Represents an implicitly-generated value initialization of
2234/// an object of a given type.
2235///
2236/// Implicit value initializations occur within semantic initializer
2237/// list expressions (InitListExpr) as placeholders for subobject
2238/// initializations not explicitly specified by the user.
2239///
2240/// \see InitListExpr
2241class ImplicitValueInitExpr : public Expr {
2242public:
2243  explicit ImplicitValueInitExpr(QualType ty)
2244    : Expr(ImplicitValueInitExprClass, ty) { }
2245
2246  static bool classof(const Stmt *T) {
2247    return T->getStmtClass() == ImplicitValueInitExprClass;
2248  }
2249  static bool classof(const ImplicitValueInitExpr *) { return true; }
2250
2251  virtual SourceRange getSourceRange() const {
2252    return SourceRange();
2253  }
2254
2255  // Iterators
2256  virtual child_iterator child_begin();
2257  virtual child_iterator child_end();
2258};
2259
2260//===----------------------------------------------------------------------===//
2261// Clang Extensions
2262//===----------------------------------------------------------------------===//
2263
2264
2265/// ExtVectorElementExpr - This represents access to specific elements of a
2266/// vector, and may occur on the left hand side or right hand side.  For example
2267/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
2268///
2269/// Note that the base may have either vector or pointer to vector type, just
2270/// like a struct field reference.
2271///
2272class ExtVectorElementExpr : public Expr {
2273  Stmt *Base;
2274  IdentifierInfo &Accessor;
2275  SourceLocation AccessorLoc;
2276public:
2277  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
2278                       SourceLocation loc)
2279    : Expr(ExtVectorElementExprClass, ty),
2280      Base(base), Accessor(accessor), AccessorLoc(loc) {}
2281
2282  const Expr *getBase() const { return cast<Expr>(Base); }
2283  Expr *getBase() { return cast<Expr>(Base); }
2284
2285  IdentifierInfo &getAccessor() const { return Accessor; }
2286
2287  /// getNumElements - Get the number of components being selected.
2288  unsigned getNumElements() const;
2289
2290  /// containsDuplicateElements - Return true if any element access is
2291  /// repeated.
2292  bool containsDuplicateElements() const;
2293
2294  /// getEncodedElementAccess - Encode the elements accessed into an llvm
2295  /// aggregate Constant of ConstantInt(s).
2296  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
2297
2298  virtual SourceRange getSourceRange() const {
2299    return SourceRange(getBase()->getLocStart(), AccessorLoc);
2300  }
2301
2302  /// isArrow - Return true if the base expression is a pointer to vector,
2303  /// return false if the base expression is a vector.
2304  bool isArrow() const;
2305
2306  static bool classof(const Stmt *T) {
2307    return T->getStmtClass() == ExtVectorElementExprClass;
2308  }
2309  static bool classof(const ExtVectorElementExpr *) { return true; }
2310
2311  // Iterators
2312  virtual child_iterator child_begin();
2313  virtual child_iterator child_end();
2314
2315  virtual void EmitImpl(llvm::Serializer& S) const;
2316  static ExtVectorElementExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2317};
2318
2319
2320/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
2321/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
2322class BlockExpr : public Expr {
2323protected:
2324  BlockDecl *TheBlock;
2325  bool HasBlockDeclRefExprs;
2326public:
2327  BlockExpr(BlockDecl *BD, QualType ty, bool hasBlockDeclRefExprs)
2328    : Expr(BlockExprClass, ty),
2329      TheBlock(BD), HasBlockDeclRefExprs(hasBlockDeclRefExprs) {}
2330
2331  const BlockDecl *getBlockDecl() const { return TheBlock; }
2332  BlockDecl *getBlockDecl() { return TheBlock; }
2333
2334  // Convenience functions for probing the underlying BlockDecl.
2335  SourceLocation getCaretLocation() const;
2336  const Stmt *getBody() const;
2337  Stmt *getBody();
2338
2339  virtual SourceRange getSourceRange() const {
2340    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
2341  }
2342
2343  /// getFunctionType - Return the underlying function type for this block.
2344  const FunctionType *getFunctionType() const;
2345
2346  /// hasBlockDeclRefExprs - Return true iff the block has BlockDeclRefExpr
2347  /// contained inside.
2348  bool hasBlockDeclRefExprs() const { return HasBlockDeclRefExprs; }
2349
2350  static bool classof(const Stmt *T) {
2351    return T->getStmtClass() == BlockExprClass;
2352  }
2353  static bool classof(const BlockExpr *) { return true; }
2354
2355  // Iterators
2356  virtual child_iterator child_begin();
2357  virtual child_iterator child_end();
2358
2359  virtual void EmitImpl(llvm::Serializer& S) const;
2360  static BlockExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2361};
2362
2363/// BlockDeclRefExpr - A reference to a declared variable, function,
2364/// enum, etc.
2365class BlockDeclRefExpr : public Expr {
2366  ValueDecl *D;
2367  SourceLocation Loc;
2368  bool IsByRef;
2369public:
2370  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef) :
2371       Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef) {}
2372
2373  ValueDecl *getDecl() { return D; }
2374  const ValueDecl *getDecl() const { return D; }
2375  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
2376
2377  bool isByRef() const { return IsByRef; }
2378
2379  static bool classof(const Stmt *T) {
2380    return T->getStmtClass() == BlockDeclRefExprClass;
2381  }
2382  static bool classof(const BlockDeclRefExpr *) { return true; }
2383
2384  // Iterators
2385  virtual child_iterator child_begin();
2386  virtual child_iterator child_end();
2387
2388  virtual void EmitImpl(llvm::Serializer& S) const;
2389  static BlockDeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
2390};
2391
2392}  // end namespace clang
2393
2394#endif
2395