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