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