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