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