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