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