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