Expr.h revision 83233a4b7c2bc7b531ffa3b33fdd1cd8138373b6
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 <vector>
24
25namespace clang {
26  class ASTContext;
27  class APValue;
28  class Decl;
29  class IdentifierInfo;
30  class ParmVarDecl;
31  class NamedDecl;
32  class ValueDecl;
33  class BlockDecl;
34  class CXXOperatorCallExpr;
35  class CXXMemberCallExpr;
36
37/// Expr - This represents one expression.  Note that Expr's are subclasses of
38/// Stmt.  This allows an expression to be transparently used any place a Stmt
39/// is required.
40///
41class Expr : public Stmt {
42  QualType TR;
43
44  /// TypeDependent - Whether this expression is type-dependent
45  /// (C++ [temp.dep.expr]).
46  bool TypeDependent : 1;
47
48  /// ValueDependent - Whether this expression is value-dependent
49  /// (C++ [temp.dep.constexpr]).
50  bool ValueDependent : 1;
51
52  /// Implicit - Whether this expression was implicitly created by the
53  /// implementation, rather than written explicitly by the user.
54  bool Implicit : 1;
55
56protected:
57  // FIXME: Eventually, this constructor should go away and we should
58  // require every subclass to provide type/value-dependence
59  // information.
60  Expr(StmtClass SC, QualType T)
61    : Stmt(SC), TypeDependent(false), ValueDependent(false), Implicit(false) {
62    setType(T);
63  }
64
65  Expr(StmtClass SC, QualType T, bool TD, bool VD)
66    : Stmt(SC), TypeDependent(TD), ValueDependent(VD), Implicit(false) {
67    setType(T);
68  }
69
70public:
71  QualType getType() const { return TR; }
72  void setType(QualType t) {
73    // In C++, the type of an expression is always adjusted so that it
74    // will not have reference type an expression will never have
75    // reference type (C++ [expr]p6). Use
76    // QualType::getNonReferenceType() to retrieve the non-reference
77    // type. Additionally, inspect Expr::isLvalue to determine whether
78    // an expression that is adjusted in this manner should be
79    // considered an lvalue.
80    assert((TR.isNull() || !TR->isReferenceType()) &&
81           "Expressions can't have reference type");
82
83    TR = t;
84  }
85
86  /// isValueDependent - Determines whether this expression is
87  /// value-dependent (C++ [temp.dep.constexpr]). For example, the
88  /// array bound of "Chars" in the following example is
89  /// value-dependent.
90  /// @code
91  /// template<int Size, char (&Chars)[Size]> struct meta_string;
92  /// @endcode
93  bool isValueDependent() const { return ValueDependent; }
94
95  /// isTypeDependent - Determines whether this expression is
96  /// type-dependent (C++ [temp.dep.expr]), which means that its type
97  /// could change from one template instantiation to the next. For
98  /// example, the expressions "x" and "x + y" are type-dependent in
99  /// the following code, but "y" is not type-dependent:
100  /// @code
101  /// template<typename T>
102  /// void add(T x, int y) {
103  ///   x + y;
104  /// }
105  /// @endcode
106  bool isTypeDependent() const { return TypeDependent; }
107
108  /// isImplicit - Determines whether this expression was implicitly
109  /// created by the implementation to express the semantics of an
110  /// implicit operation, such as an implicit conversion or implicit
111  /// reference to "this". When false, this expression was written
112  /// directly in the source code.
113  bool isImplicit() const { return Implicit; }
114  void setImplicit(bool I = true) { Implicit = I; }
115
116  /// SourceLocation tokens are not useful in isolation - they are low level
117  /// value objects created/interpreted by SourceManager. We assume AST
118  /// clients will have a pointer to the respective SourceManager.
119  virtual SourceRange getSourceRange() const = 0;
120
121  /// getExprLoc - Return the preferred location for the arrow when diagnosing
122  /// a problem with a generic expression.
123  virtual SourceLocation getExprLoc() const { return getLocStart(); }
124
125  /// hasLocalSideEffect - Return true if this immediate expression has side
126  /// effects, not counting any sub-expressions.
127  bool hasLocalSideEffect() const;
128
129  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
130  /// incomplete type other than void. Nonarray expressions that can be lvalues:
131  ///  - name, where name must be a variable
132  ///  - e[i]
133  ///  - (e), where e must be an lvalue
134  ///  - e.name, where e must be an lvalue
135  ///  - e->name
136  ///  - *e, the type of e cannot be a function type
137  ///  - string-constant
138  ///  - reference type [C++ [expr]]
139  ///
140  enum isLvalueResult {
141    LV_Valid,
142    LV_NotObjectType,
143    LV_IncompleteVoidType,
144    LV_DuplicateVectorComponents,
145    LV_InvalidExpression,
146    LV_MemberFunction
147  };
148  isLvalueResult isLvalue(ASTContext &Ctx) const;
149
150  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
151  /// does not have an incomplete type, does not have a const-qualified type,
152  /// and if it is a structure or union, does not have any member (including,
153  /// recursively, any member or element of all contained aggregates or unions)
154  /// with a const-qualified type.
155  enum isModifiableLvalueResult {
156    MLV_Valid,
157    MLV_NotObjectType,
158    MLV_IncompleteVoidType,
159    MLV_DuplicateVectorComponents,
160    MLV_InvalidExpression,
161    MLV_LValueCast,           // Specialized form of MLV_InvalidExpression.
162    MLV_IncompleteType,
163    MLV_ConstQualified,
164    MLV_ArrayType,
165    MLV_NotBlockQualified,
166    MLV_ReadonlyProperty,
167    MLV_NoSetterProperty,
168    MLV_MemberFunction
169  };
170  isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx) const;
171
172  bool isBitField();
173
174  /// getIntegerConstantExprValue() - Return the value of an integer
175  /// constant expression. The expression must be a valid integer
176  /// constant expression as determined by isIntegerConstantExpr.
177  llvm::APSInt getIntegerConstantExprValue(ASTContext &Ctx) const {
178    llvm::APSInt X;
179    bool success = isIntegerConstantExpr(X, Ctx);
180    success = success;
181    assert(success && "Illegal argument to getIntegerConstantExpr");
182    return X;
183  }
184
185  /// isIntegerConstantExpr - Return true if this expression is a valid integer
186  /// constant expression, and, if so, return its value in Result.  If not a
187  /// valid i-c-e, return false and fill in Loc (if specified) with the location
188  /// of the invalid expression.
189  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
190                             SourceLocation *Loc = 0,
191                             bool isEvaluated = true) const;
192  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
193    llvm::APSInt X;
194    return isIntegerConstantExpr(X, Ctx, Loc);
195  }
196  /// isConstantExpr - Return true if this expression is a valid constant expr.
197  bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const;
198
199  /// EvalResult is a struct with detailed info about an evaluated expression.
200  struct EvalResult {
201    /// Val - This is the scalar value the expression can be folded to.
202    APValue Val;
203
204    /// HasSideEffects - Whether the evaluated expression has side effects.
205    /// For example, (f() && 0) can be folded, but it still has side effects.
206    bool HasSideEffects;
207
208    /// Diag - If the expression is unfoldable, then Diag contains a note
209    /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret
210    /// position for the error, and DiagExpr is the expression that caused
211    /// the error.
212    /// If the expression is foldable, but not an integer constant expression,
213    /// Diag contains a note diagnostic that describes why it isn't an integer
214    /// constant expression. If the expression *is* an integer constant
215    /// expression, then Diag will be zero.
216    unsigned Diag;
217    const Expr *DiagExpr;
218    SourceLocation DiagLoc;
219
220    EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {}
221  };
222
223  /// Evaluate - Return true if this is a constant which we can fold using
224  /// any crazy technique (that has nothing to do with language standards) that
225  /// we want to.  If this function returns true, it returns the folded constant
226  /// in Result.
227  bool Evaluate(EvalResult &Result, ASTContext &Ctx) const;
228
229  /// isEvaluatable - Call Evaluate to see if this expression can be constant
230  /// folded, but discard the result.
231  bool isEvaluatable(ASTContext &Ctx) const;
232
233  /// EvaluateAsInt - Call Evaluate and return the folded integer. This
234  /// must be called on an expression that constant folds to an integer.
235  llvm::APSInt EvaluateAsInt(ASTContext &Ctx) const;
236
237  /// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
238  /// integer constant expression with the value zero, or if this is one that is
239  /// cast to void*.
240  bool isNullPointerConstant(ASTContext &Ctx) const;
241
242  /// hasGlobalStorage - Return true if this expression has static storage
243  /// duration.  This means that the address of this expression is a link-time
244  /// constant.
245  bool hasGlobalStorage() const;
246
247  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
248  ///  its subexpression.  If that subexpression is also a ParenExpr,
249  ///  then this method recursively returns its subexpression, and so forth.
250  ///  Otherwise, the method returns the current Expr.
251  Expr* IgnoreParens();
252
253  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
254  /// or CastExprs, returning their operand.
255  Expr *IgnoreParenCasts();
256
257  const Expr* IgnoreParens() const {
258    return const_cast<Expr*>(this)->IgnoreParens();
259  }
260  const Expr *IgnoreParenCasts() const {
261    return const_cast<Expr*>(this)->IgnoreParenCasts();
262  }
263
264  static bool hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs);
265  static bool hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs);
266
267  static bool classof(const Stmt *T) {
268    return T->getStmtClass() >= firstExprConstant &&
269           T->getStmtClass() <= lastExprConstant;
270  }
271  static bool classof(const Expr *) { return true; }
272
273  static inline Expr* Create(llvm::Deserializer& D, ASTContext& C) {
274    return cast<Expr>(Stmt::Create(D, C));
275  }
276};
277
278
279//===----------------------------------------------------------------------===//
280// Primary Expressions.
281//===----------------------------------------------------------------------===//
282
283/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
284/// enum, etc.
285class DeclRefExpr : public Expr {
286  NamedDecl *D;
287  SourceLocation Loc;
288
289protected:
290  // FIXME: Eventually, this constructor will go away and all subclasses
291  // will have to provide the type- and value-dependent flags.
292  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l) :
293    Expr(SC, t), D(d), Loc(l) {}
294
295  DeclRefExpr(StmtClass SC, NamedDecl *d, QualType t, SourceLocation l, bool TD,
296              bool VD) :
297    Expr(SC, t, TD, VD), D(d), Loc(l) {}
298
299public:
300  // FIXME: Eventually, this constructor will go away and all clients
301  // will have to provide the type- and value-dependent flags.
302  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l) :
303    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
304
305  DeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, bool VD) :
306    Expr(DeclRefExprClass, t, TD, VD), D(d), Loc(l) {}
307
308  NamedDecl *getDecl() { return D; }
309  const NamedDecl *getDecl() const { return D; }
310  void setDecl(NamedDecl *NewD) { D = NewD; }
311
312  SourceLocation getLocation() const { return Loc; }
313  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
314
315  static bool classof(const Stmt *T) {
316    return T->getStmtClass() == DeclRefExprClass ||
317           T->getStmtClass() == CXXConditionDeclExprClass ||
318           T->getStmtClass() == QualifiedDeclRefExprClass;
319  }
320  static bool classof(const DeclRefExpr *) { return true; }
321
322  // Iterators
323  virtual child_iterator child_begin();
324  virtual child_iterator child_end();
325
326  virtual void EmitImpl(llvm::Serializer& S) const;
327  static DeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
328};
329
330/// PredefinedExpr - [C99 6.4.2.2] - A predefined identifier such as __func__.
331class PredefinedExpr : public Expr {
332public:
333  enum IdentType {
334    Func,
335    Function,
336    PrettyFunction
337  };
338
339private:
340  SourceLocation Loc;
341  IdentType Type;
342public:
343  PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
344    : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {}
345
346  IdentType getIdentType() const { return Type; }
347
348  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
349
350  static bool classof(const Stmt *T) {
351    return T->getStmtClass() == PredefinedExprClass;
352  }
353  static bool classof(const PredefinedExpr *) { return true; }
354
355  // Iterators
356  virtual child_iterator child_begin();
357  virtual child_iterator child_end();
358
359  virtual void EmitImpl(llvm::Serializer& S) const;
360  static PredefinedExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
361};
362
363class IntegerLiteral : public Expr {
364  llvm::APInt Value;
365  SourceLocation Loc;
366public:
367  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
368  // or UnsignedLongLongTy
369  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
370    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
371    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
372  }
373  const llvm::APInt &getValue() const { return Value; }
374  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
375
376  static bool classof(const Stmt *T) {
377    return T->getStmtClass() == IntegerLiteralClass;
378  }
379  static bool classof(const IntegerLiteral *) { return true; }
380
381  // Iterators
382  virtual child_iterator child_begin();
383  virtual child_iterator child_end();
384
385  virtual void EmitImpl(llvm::Serializer& S) const;
386  static IntegerLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
387};
388
389class CharacterLiteral : public Expr {
390  unsigned Value;
391  SourceLocation Loc;
392  bool IsWide;
393public:
394  // type should be IntTy
395  CharacterLiteral(unsigned value, bool iswide, QualType type, SourceLocation l)
396    : Expr(CharacterLiteralClass, type), Value(value), Loc(l), IsWide(iswide) {
397  }
398  SourceLocation getLoc() const { return Loc; }
399  bool isWide() const { return IsWide; }
400
401  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
402
403  unsigned getValue() const { return Value; }
404
405  static bool classof(const Stmt *T) {
406    return T->getStmtClass() == CharacterLiteralClass;
407  }
408  static bool classof(const CharacterLiteral *) { return true; }
409
410  // Iterators
411  virtual child_iterator child_begin();
412  virtual child_iterator child_end();
413
414  virtual void EmitImpl(llvm::Serializer& S) const;
415  static CharacterLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
416};
417
418class FloatingLiteral : public Expr {
419  llvm::APFloat Value;
420  bool IsExact : 1;
421  SourceLocation Loc;
422public:
423  FloatingLiteral(const llvm::APFloat &V, bool* isexact,
424                  QualType Type, SourceLocation L)
425    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {}
426
427  const llvm::APFloat &getValue() const { return Value; }
428
429  bool isExact() const { return IsExact; }
430
431  /// getValueAsApproximateDouble - This returns the value as an inaccurate
432  /// double.  Note that this may cause loss of precision, but is useful for
433  /// debugging dumps, etc.
434  double getValueAsApproximateDouble() const;
435
436  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
437
438  static bool classof(const Stmt *T) {
439    return T->getStmtClass() == FloatingLiteralClass;
440  }
441  static bool classof(const FloatingLiteral *) { return true; }
442
443  // Iterators
444  virtual child_iterator child_begin();
445  virtual child_iterator child_end();
446
447  virtual void EmitImpl(llvm::Serializer& S) const;
448  static FloatingLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
449};
450
451/// ImaginaryLiteral - We support imaginary integer and floating point literals,
452/// like "1.0i".  We represent these as a wrapper around FloatingLiteral and
453/// IntegerLiteral classes.  Instances of this class always have a Complex type
454/// whose element type matches the subexpression.
455///
456class ImaginaryLiteral : public Expr {
457  Stmt *Val;
458public:
459  ImaginaryLiteral(Expr *val, QualType Ty)
460    : Expr(ImaginaryLiteralClass, Ty), Val(val) {}
461
462  const Expr *getSubExpr() const { return cast<Expr>(Val); }
463  Expr *getSubExpr() { return cast<Expr>(Val); }
464
465  virtual SourceRange getSourceRange() const { return Val->getSourceRange(); }
466  static bool classof(const Stmt *T) {
467    return T->getStmtClass() == ImaginaryLiteralClass;
468  }
469  static bool classof(const ImaginaryLiteral *) { return true; }
470
471  // Iterators
472  virtual child_iterator child_begin();
473  virtual child_iterator child_end();
474
475  virtual void EmitImpl(llvm::Serializer& S) const;
476  static ImaginaryLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
477};
478
479/// StringLiteral - This represents a string literal expression, e.g. "foo"
480/// or L"bar" (wide strings).  The actual string is returned by getStrData()
481/// is NOT null-terminated, and the length of the string is determined by
482/// calling getByteLength().  The C type for a string is always a
483/// ConstantArrayType.
484class StringLiteral : public Expr {
485  const char *StrData;
486  unsigned ByteLength;
487  bool IsWide;
488  // if the StringLiteral was composed using token pasting, both locations
489  // are needed. If not (the common case), firstTokLoc == lastTokLoc.
490  // FIXME: if space becomes an issue, we should create a sub-class.
491  SourceLocation firstTokLoc, lastTokLoc;
492public:
493  StringLiteral(const char *strData, unsigned byteLength, bool Wide,
494                QualType t, SourceLocation b, SourceLocation e);
495  virtual ~StringLiteral();
496
497  const char *getStrData() const { return StrData; }
498  unsigned getByteLength() const { return ByteLength; }
499  bool isWide() const { return IsWide; }
500
501  virtual SourceRange getSourceRange() const {
502    return SourceRange(firstTokLoc,lastTokLoc);
503  }
504  static bool classof(const Stmt *T) {
505    return T->getStmtClass() == StringLiteralClass;
506  }
507  static bool classof(const StringLiteral *) { return true; }
508
509  // Iterators
510  virtual child_iterator child_begin();
511  virtual child_iterator child_end();
512
513  virtual void EmitImpl(llvm::Serializer& S) const;
514  static StringLiteral* CreateImpl(llvm::Deserializer& D, ASTContext& C);
515};
516
517/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
518/// AST node is only formed if full location information is requested.
519class ParenExpr : public Expr {
520  SourceLocation L, R;
521  Stmt *Val;
522public:
523  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
524    : Expr(ParenExprClass, val->getType(),
525           val->isTypeDependent(), val->isValueDependent()),
526      L(l), R(r), Val(val) {}
527
528  const Expr *getSubExpr() const { return cast<Expr>(Val); }
529  Expr *getSubExpr() { return cast<Expr>(Val); }
530  virtual SourceRange getSourceRange() const { return SourceRange(L, R); }
531
532  static bool classof(const Stmt *T) {
533    return T->getStmtClass() == ParenExprClass;
534  }
535  static bool classof(const ParenExpr *) { return true; }
536
537  // Iterators
538  virtual child_iterator child_begin();
539  virtual child_iterator child_end();
540
541  virtual void EmitImpl(llvm::Serializer& S) const;
542  static ParenExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
543};
544
545
546/// UnaryOperator - This represents the unary-expression's (except sizeof and
547/// alignof), the postinc/postdec operators from postfix-expression, and various
548/// extensions.
549///
550/// Notes on various nodes:
551///
552/// Real/Imag - These return the real/imag part of a complex operand.  If
553///   applied to a non-complex value, the former returns its operand and the
554///   later returns zero in the type of the operand.
555///
556/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
557///   subexpression is a compound literal with the various MemberExpr and
558///   ArraySubscriptExpr's applied to it.
559///
560class UnaryOperator : public Expr {
561public:
562  // Note that additions to this should also update the StmtVisitor class.
563  enum Opcode {
564    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
565    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
566    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
567    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
568    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
569    Real, Imag,       // "__real expr"/"__imag expr" Extension.
570    Extension,        // __extension__ marker.
571    OffsetOf          // __builtin_offsetof
572  };
573private:
574  Stmt *Val;
575  Opcode Opc;
576  SourceLocation Loc;
577public:
578
579  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
580    : Expr(UnaryOperatorClass, type,
581           input->isTypeDependent() && opc != OffsetOf,
582           input->isValueDependent()),
583      Val(input), Opc(opc), Loc(l) {}
584
585  Opcode getOpcode() const { return Opc; }
586  Expr *getSubExpr() const { return cast<Expr>(Val); }
587
588  /// getOperatorLoc - Return the location of the operator.
589  SourceLocation getOperatorLoc() const { return Loc; }
590
591  /// isPostfix - Return true if this is a postfix operation, like x++.
592  static bool isPostfix(Opcode Op);
593
594  /// isPostfix - Return true if this is a prefix operation, like --x.
595  static bool isPrefix(Opcode Op);
596
597  bool isPrefix() const { return isPrefix(Opc); }
598  bool isPostfix() const { return isPostfix(Opc); }
599  bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
600  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
601  bool isOffsetOfOp() const { return Opc == OffsetOf; }
602  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
603
604  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
605  /// corresponds to, e.g. "sizeof" or "[pre]++"
606  static const char *getOpcodeStr(Opcode Op);
607
608  virtual SourceRange getSourceRange() const {
609    if (isPostfix())
610      return SourceRange(Val->getLocStart(), Loc);
611    else
612      return SourceRange(Loc, Val->getLocEnd());
613  }
614  virtual SourceLocation getExprLoc() const { return Loc; }
615
616  static bool classof(const Stmt *T) {
617    return T->getStmtClass() == UnaryOperatorClass;
618  }
619  static bool classof(const UnaryOperator *) { return true; }
620
621  int64_t evaluateOffsetOf(ASTContext& C) const;
622
623  // Iterators
624  virtual child_iterator child_begin();
625  virtual child_iterator child_end();
626
627  virtual void EmitImpl(llvm::Serializer& S) const;
628  static UnaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
629};
630
631/// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
632/// types and expressions.
633class SizeOfAlignOfExpr : public Expr {
634  bool isSizeof : 1;  // true if sizeof, false if alignof.
635  bool isType : 1;    // true if operand is a type, false if an expression
636  union {
637    void *Ty;
638    Stmt *Ex;
639  } Argument;
640  SourceLocation OpLoc, RParenLoc;
641public:
642  SizeOfAlignOfExpr(bool issizeof, bool istype, void *argument,
643                    QualType resultType, SourceLocation op,
644                    SourceLocation rp) :
645      Expr(SizeOfAlignOfExprClass, resultType), isSizeof(issizeof),
646      isType(istype), OpLoc(op), RParenLoc(rp) {
647    if (isType)
648      Argument.Ty = argument;
649    else
650      // argument was an Expr*, so cast it back to that to be safe
651      Argument.Ex = static_cast<Expr*>(argument);
652  }
653
654  virtual void Destroy(ASTContext& C);
655
656  bool isSizeOf() const { return isSizeof; }
657  bool isArgumentType() const { return isType; }
658  QualType getArgumentType() const {
659    assert(isArgumentType() && "calling getArgumentType() when arg is expr");
660    return QualType::getFromOpaquePtr(Argument.Ty);
661  }
662  Expr* getArgumentExpr() const {
663    assert(!isArgumentType() && "calling getArgumentExpr() when arg is type");
664    return static_cast<Expr*>(Argument.Ex);
665  }
666  /// Gets the argument type, or the type of the argument expression, whichever
667  /// is appropriate.
668  QualType getTypeOfArgument() const {
669    return isArgumentType() ? getArgumentType() : getArgumentExpr()->getType();
670  }
671
672  SourceLocation getOperatorLoc() const { return OpLoc; }
673
674  virtual SourceRange getSourceRange() const {
675    return SourceRange(OpLoc, RParenLoc);
676  }
677
678  static bool classof(const Stmt *T) {
679    return T->getStmtClass() == SizeOfAlignOfExprClass;
680  }
681  static bool classof(const SizeOfAlignOfExpr *) { return true; }
682
683  // Iterators
684  virtual child_iterator child_begin();
685  virtual child_iterator child_end();
686
687  virtual void EmitImpl(llvm::Serializer& S) const;
688  static SizeOfAlignOfExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
689};
690
691//===----------------------------------------------------------------------===//
692// Postfix Operators.
693//===----------------------------------------------------------------------===//
694
695/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
696class ArraySubscriptExpr : public Expr {
697  enum { LHS, RHS, END_EXPR=2 };
698  Stmt* SubExprs[END_EXPR];
699  SourceLocation RBracketLoc;
700public:
701  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
702                     SourceLocation rbracketloc)
703  : Expr(ArraySubscriptExprClass, t), RBracketLoc(rbracketloc) {
704    SubExprs[LHS] = lhs;
705    SubExprs[RHS] = rhs;
706  }
707
708  /// An array access can be written A[4] or 4[A] (both are equivalent).
709  /// - getBase() and getIdx() always present the normalized view: A[4].
710  ///    In this case getBase() returns "A" and getIdx() returns "4".
711  /// - getLHS() and getRHS() present the syntactic view. e.g. for
712  ///    4[A] getLHS() returns "4".
713  /// Note: Because vector element access is also written A[4] we must
714  /// predicate the format conversion in getBase and getIdx only on the
715  /// the type of the RHS, as it is possible for the LHS to be a vector of
716  /// integer type
717  Expr *getLHS() { return cast<Expr>(SubExprs[LHS]); }
718  const Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
719
720  Expr *getRHS() { return cast<Expr>(SubExprs[RHS]); }
721  const Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
722
723  Expr *getBase() {
724    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
725  }
726
727  const Expr *getBase() const {
728    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS());
729  }
730
731  Expr *getIdx() {
732    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
733  }
734
735  const Expr *getIdx() const {
736    return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS());
737  }
738
739  virtual SourceRange getSourceRange() const {
740    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
741  }
742
743  virtual SourceLocation getExprLoc() const { return RBracketLoc; }
744
745  static bool classof(const Stmt *T) {
746    return T->getStmtClass() == ArraySubscriptExprClass;
747  }
748  static bool classof(const ArraySubscriptExpr *) { return true; }
749
750  // Iterators
751  virtual child_iterator child_begin();
752  virtual child_iterator child_end();
753
754  virtual void EmitImpl(llvm::Serializer& S) const;
755  static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
756};
757
758
759/// CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
760/// CallExpr itself represents a normal function call, e.g., "f(x, 2)",
761/// while its subclasses may represent alternative syntax that (semantically)
762/// results in a function call. For example, CXXOperatorCallExpr is
763/// a subclass for overloaded operator calls that use operator syntax, e.g.,
764/// "str1 + str2" to resolve to a function call.
765class CallExpr : public Expr {
766  enum { FN=0, ARGS_START=1 };
767  Stmt **SubExprs;
768  unsigned NumArgs;
769  SourceLocation RParenLoc;
770
771  // This version of the ctor is for deserialization.
772  CallExpr(StmtClass SC, Stmt** subexprs, unsigned numargs, QualType t,
773           SourceLocation rparenloc)
774  : Expr(SC,t), SubExprs(subexprs),
775    NumArgs(numargs), RParenLoc(rparenloc) {}
776
777protected:
778  // This version of the constructor is for derived classes.
779  CallExpr(StmtClass SC, Expr *fn, Expr **args, unsigned numargs, QualType t,
780           SourceLocation rparenloc);
781
782public:
783  CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
784           SourceLocation rparenloc);
785  ~CallExpr() {
786    delete [] SubExprs;
787  }
788
789  const Expr *getCallee() const { return cast<Expr>(SubExprs[FN]); }
790  Expr *getCallee() { return cast<Expr>(SubExprs[FN]); }
791  void setCallee(Expr *F) { SubExprs[FN] = F; }
792
793  /// getNumArgs - Return the number of actual arguments to this call.
794  ///
795  unsigned getNumArgs() const { return NumArgs; }
796
797  /// getArg - Return the specified argument.
798  Expr *getArg(unsigned Arg) {
799    assert(Arg < NumArgs && "Arg access out of range!");
800    return cast<Expr>(SubExprs[Arg+ARGS_START]);
801  }
802  const Expr *getArg(unsigned Arg) const {
803    assert(Arg < NumArgs && "Arg access out of range!");
804    return cast<Expr>(SubExprs[Arg+ARGS_START]);
805  }
806  /// setArg - Set the specified argument.
807  void setArg(unsigned Arg, Expr *ArgExpr) {
808    assert(Arg < NumArgs && "Arg access out of range!");
809    SubExprs[Arg+ARGS_START] = ArgExpr;
810  }
811
812  /// setNumArgs - This changes the number of arguments present in this call.
813  /// Any orphaned expressions are deleted by this, and any new operands are set
814  /// to null.
815  void setNumArgs(unsigned NumArgs);
816
817  typedef ExprIterator arg_iterator;
818  typedef ConstExprIterator const_arg_iterator;
819
820  arg_iterator arg_begin() { return SubExprs+ARGS_START; }
821  arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); }
822  const_arg_iterator arg_begin() const { return SubExprs+ARGS_START; }
823  const_arg_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs();}
824
825  /// getNumCommas - Return the number of commas that must have been present in
826  /// this function call.
827  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
828
829  /// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
830  /// not, return 0.
831  unsigned isBuiltinCall() const;
832
833  SourceLocation getRParenLoc() const { return RParenLoc; }
834
835  virtual SourceRange getSourceRange() const {
836    return SourceRange(getCallee()->getLocStart(), RParenLoc);
837  }
838
839  static bool classof(const Stmt *T) {
840    return T->getStmtClass() == CallExprClass ||
841           T->getStmtClass() == CXXOperatorCallExprClass ||
842           T->getStmtClass() == CXXMemberCallExprClass;
843  }
844  static bool classof(const CallExpr *) { return true; }
845  static bool classof(const CXXOperatorCallExpr *) { return true; }
846  static bool classof(const CXXMemberCallExpr *) { return true; }
847
848  // Iterators
849  virtual child_iterator child_begin();
850  virtual child_iterator child_end();
851
852  virtual void EmitImpl(llvm::Serializer& S) const;
853  static CallExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C,
854                              StmtClass SC);
855};
856
857/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.
858///
859class MemberExpr : public Expr {
860  Stmt *Base;
861  NamedDecl *MemberDecl;
862  SourceLocation MemberLoc;
863  bool IsArrow;      // True if this is "X->F", false if this is "X.F".
864public:
865  MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl, SourceLocation l,
866             QualType ty)
867    : Expr(MemberExprClass, ty),
868      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
869
870  void setBase(Expr *E) { Base = E; }
871  Expr *getBase() const { return cast<Expr>(Base); }
872  NamedDecl *getMemberDecl() const { return MemberDecl; }
873  void setMemberDecl(NamedDecl *D) { MemberDecl = D; }
874  bool isArrow() const { return IsArrow; }
875
876  virtual SourceRange getSourceRange() const {
877    return SourceRange(getBase()->getLocStart(), MemberLoc);
878  }
879
880  virtual SourceLocation getExprLoc() const { return MemberLoc; }
881
882  static bool classof(const Stmt *T) {
883    return T->getStmtClass() == MemberExprClass;
884  }
885  static bool classof(const MemberExpr *) { return true; }
886
887  // Iterators
888  virtual child_iterator child_begin();
889  virtual child_iterator child_end();
890
891  virtual void EmitImpl(llvm::Serializer& S) const;
892  static MemberExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
893};
894
895/// CompoundLiteralExpr - [C99 6.5.2.5]
896///
897class CompoundLiteralExpr : public Expr {
898  /// LParenLoc - If non-null, this is the location of the left paren in a
899  /// compound literal like "(int){4}".  This can be null if this is a
900  /// synthesized compound expression.
901  SourceLocation LParenLoc;
902  Stmt *Init;
903  bool FileScope;
904public:
905  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init,
906                      bool fileScope)
907    : Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init),
908      FileScope(fileScope) {}
909
910  const Expr *getInitializer() const { return cast<Expr>(Init); }
911  Expr *getInitializer() { return cast<Expr>(Init); }
912
913  bool isFileScope() const { return FileScope; }
914
915  SourceLocation getLParenLoc() const { return LParenLoc; }
916
917  virtual SourceRange getSourceRange() const {
918    // FIXME: Init should never be null.
919    if (!Init)
920      return SourceRange();
921    if (LParenLoc.isInvalid())
922      return Init->getSourceRange();
923    return SourceRange(LParenLoc, Init->getLocEnd());
924  }
925
926  static bool classof(const Stmt *T) {
927    return T->getStmtClass() == CompoundLiteralExprClass;
928  }
929  static bool classof(const CompoundLiteralExpr *) { return true; }
930
931  // Iterators
932  virtual child_iterator child_begin();
933  virtual child_iterator child_end();
934
935  virtual void EmitImpl(llvm::Serializer& S) const;
936  static CompoundLiteralExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
937};
938
939/// CastExpr - Base class for type casts, including both implicit
940/// casts (ImplicitCastExpr) and explicit casts that have some
941/// representation in the source code (ExplicitCastExpr's derived
942/// classes).
943class CastExpr : public Expr {
944  Stmt *Op;
945protected:
946  CastExpr(StmtClass SC, QualType ty, Expr *op) :
947    Expr(SC, ty,
948         // Cast expressions are type-dependent if the type is
949         // dependent (C++ [temp.dep.expr]p3).
950         ty->isDependentType(),
951         // Cast expressions are value-dependent if the type is
952         // dependent or if the subexpression is value-dependent.
953         ty->isDependentType() || (op && op->isValueDependent())),
954    Op(op) {}
955
956public:
957  Expr *getSubExpr() { return cast<Expr>(Op); }
958  const Expr *getSubExpr() const { return cast<Expr>(Op); }
959
960  static bool classof(const Stmt *T) {
961    StmtClass SC = T->getStmtClass();
962    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
963      return true;
964
965    if (SC >= ImplicitCastExprClass && SC <= CStyleCastExprClass)
966      return true;
967
968    return false;
969  }
970  static bool classof(const CastExpr *) { return true; }
971
972  // Iterators
973  virtual child_iterator child_begin();
974  virtual child_iterator child_end();
975};
976
977/// ImplicitCastExpr - Allows us to explicitly represent implicit type
978/// conversions, which have no direct representation in the original
979/// source code. For example: converting T[]->T*, void f()->void
980/// (*f)(), float->double, short->int, etc.
981///
982/// In C, implicit casts always produce rvalues. However, in C++, an
983/// implicit cast whose result is being bound to a reference will be
984/// an lvalue. For example:
985///
986/// @code
987/// class Base { };
988/// class Derived : public Base { };
989/// void f(Derived d) {
990///   Base& b = d; // initializer is an ImplicitCastExpr to an lvalue of type Base
991/// }
992/// @endcode
993class ImplicitCastExpr : public CastExpr {
994  /// LvalueCast - Whether this cast produces an lvalue.
995  bool LvalueCast;
996
997public:
998  ImplicitCastExpr(QualType ty, Expr *op, bool Lvalue) :
999    CastExpr(ImplicitCastExprClass, ty, op), LvalueCast(Lvalue) {
1000    setImplicit(true);
1001  }
1002
1003  virtual SourceRange getSourceRange() const {
1004    return getSubExpr()->getSourceRange();
1005  }
1006
1007  /// isLvalueCast - Whether this cast produces an lvalue.
1008  bool isLvalueCast() const { return LvalueCast; }
1009
1010  /// setLvalueCast - Set whether this cast produces an lvalue.
1011  void setLvalueCast(bool Lvalue) { LvalueCast = Lvalue; }
1012
1013  static bool classof(const Stmt *T) {
1014    return T->getStmtClass() == ImplicitCastExprClass;
1015  }
1016  static bool classof(const ImplicitCastExpr *) { return true; }
1017
1018  virtual void EmitImpl(llvm::Serializer& S) const;
1019  static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1020};
1021
1022/// ExplicitCastExpr - An explicit cast written in the source
1023/// code.
1024///
1025/// This class is effectively an abstract class, because it provides
1026/// the basic representation of an explicitly-written cast without
1027/// specifying which kind of cast (C cast, functional cast, static
1028/// cast, etc.) was written; specific derived classes represent the
1029/// particular style of cast and its location information.
1030///
1031/// Unlike implicit casts, explicit cast nodes have two different
1032/// types: the type that was written into the source code, and the
1033/// actual type of the expression as determined by semantic
1034/// analysis. These types may differ slightly. For example, in C++ one
1035/// can cast to a reference type, which indicates that the resulting
1036/// expression will be an lvalue. The reference type, however, will
1037/// not be used as the type of the expression.
1038class ExplicitCastExpr : public CastExpr {
1039  /// TypeAsWritten - The type that this expression is casting to, as
1040  /// written in the source code.
1041  QualType TypeAsWritten;
1042
1043protected:
1044  ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy)
1045    : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {}
1046
1047public:
1048  /// getTypeAsWritten - Returns the type that this expression is
1049  /// casting to, as written in the source code.
1050  QualType getTypeAsWritten() const { return TypeAsWritten; }
1051
1052  static bool classof(const Stmt *T) {
1053    StmtClass SC = T->getStmtClass();
1054    if (SC >= ExplicitCastExprClass && SC <= CStyleCastExprClass)
1055      return true;
1056    if (SC >= CXXNamedCastExprClass && SC <= CXXFunctionalCastExprClass)
1057      return true;
1058
1059    return false;
1060  }
1061  static bool classof(const ExplicitCastExpr *) { return true; }
1062};
1063
1064/// CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style
1065/// cast in C++ (C++ [expr.cast]), which uses the syntax
1066/// (Type)expr. For example: @c (int)f.
1067class CStyleCastExpr : public ExplicitCastExpr {
1068  SourceLocation LPLoc; // the location of the left paren
1069  SourceLocation RPLoc; // the location of the right paren
1070public:
1071  CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy,
1072                    SourceLocation l, SourceLocation r) :
1073    ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy),
1074    LPLoc(l), RPLoc(r) {}
1075
1076  SourceLocation getLParenLoc() const { return LPLoc; }
1077  SourceLocation getRParenLoc() const { return RPLoc; }
1078
1079  virtual SourceRange getSourceRange() const {
1080    return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
1081  }
1082  static bool classof(const Stmt *T) {
1083    return T->getStmtClass() == CStyleCastExprClass;
1084  }
1085  static bool classof(const CStyleCastExpr *) { return true; }
1086
1087  virtual void EmitImpl(llvm::Serializer& S) const;
1088  static CStyleCastExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1089};
1090
1091class BinaryOperator : public Expr {
1092public:
1093  enum Opcode {
1094    // Operators listed in order of precedence.
1095    // Note that additions to this should also update the StmtVisitor class.
1096    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
1097    Add, Sub,         // [C99 6.5.6] Additive operators.
1098    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
1099    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
1100    EQ, NE,           // [C99 6.5.9] Equality operators.
1101    And,              // [C99 6.5.10] Bitwise AND operator.
1102    Xor,              // [C99 6.5.11] Bitwise XOR operator.
1103    Or,               // [C99 6.5.12] Bitwise OR operator.
1104    LAnd,             // [C99 6.5.13] Logical AND operator.
1105    LOr,              // [C99 6.5.14] Logical OR operator.
1106    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
1107    DivAssign, RemAssign,
1108    AddAssign, SubAssign,
1109    ShlAssign, ShrAssign,
1110    AndAssign, XorAssign,
1111    OrAssign,
1112    Comma             // [C99 6.5.17] Comma operator.
1113  };
1114private:
1115  enum { LHS, RHS, END_EXPR };
1116  Stmt* SubExprs[END_EXPR];
1117  Opcode Opc;
1118  SourceLocation OpLoc;
1119public:
1120
1121  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
1122                 SourceLocation opLoc)
1123    : Expr(BinaryOperatorClass, ResTy,
1124           lhs->isTypeDependent() || rhs->isTypeDependent(),
1125           lhs->isValueDependent() || rhs->isValueDependent()),
1126      Opc(opc), OpLoc(opLoc) {
1127    SubExprs[LHS] = lhs;
1128    SubExprs[RHS] = rhs;
1129    assert(!isCompoundAssignmentOp() &&
1130           "Use ArithAssignBinaryOperator for compound assignments");
1131  }
1132
1133  SourceLocation getOperatorLoc() const { return OpLoc; }
1134  Opcode getOpcode() const { return Opc; }
1135  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1136  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1137  virtual SourceRange getSourceRange() const {
1138    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
1139  }
1140
1141  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1142  /// corresponds to, e.g. "<<=".
1143  static const char *getOpcodeStr(Opcode Op);
1144
1145  /// predicates to categorize the respective opcodes.
1146  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
1147  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
1148  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
1149  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
1150
1151  static bool isRelationalOp(Opcode Opc) { return Opc >= LT && Opc <= GE; }
1152  bool isRelationalOp() const { return isRelationalOp(Opc); }
1153
1154  static bool isEqualityOp(Opcode Opc) { return Opc == EQ || Opc == NE; }
1155  bool isEqualityOp() const { return isEqualityOp(Opc); }
1156
1157  static bool isLogicalOp(Opcode Opc) { return Opc == LAnd || Opc == LOr; }
1158  bool isLogicalOp() const { return isLogicalOp(Opc); }
1159
1160  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
1161  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
1162  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
1163
1164  static bool classof(const Stmt *S) {
1165    return S->getStmtClass() == BinaryOperatorClass ||
1166           S->getStmtClass() == CompoundAssignOperatorClass;
1167  }
1168  static bool classof(const BinaryOperator *) { return true; }
1169
1170  // Iterators
1171  virtual child_iterator child_begin();
1172  virtual child_iterator child_end();
1173
1174  virtual void EmitImpl(llvm::Serializer& S) const;
1175  static BinaryOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1176
1177protected:
1178  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
1179                 SourceLocation oploc, bool dead)
1180    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) {
1181    SubExprs[LHS] = lhs;
1182    SubExprs[RHS] = rhs;
1183  }
1184};
1185
1186/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
1187/// track of the type the operation is performed in.  Due to the semantics of
1188/// these operators, the operands are promoted, the aritmetic performed, an
1189/// implicit conversion back to the result type done, then the assignment takes
1190/// place.  This captures the intermediate type which the computation is done
1191/// in.
1192class CompoundAssignOperator : public BinaryOperator {
1193  QualType ComputationType;
1194public:
1195  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
1196                         QualType ResType, QualType CompType,
1197                         SourceLocation OpLoc)
1198    : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true),
1199      ComputationType(CompType) {
1200    assert(isCompoundAssignmentOp() &&
1201           "Only should be used for compound assignments");
1202  }
1203
1204  QualType getComputationType() const { return ComputationType; }
1205
1206  static bool classof(const CompoundAssignOperator *) { return true; }
1207  static bool classof(const Stmt *S) {
1208    return S->getStmtClass() == CompoundAssignOperatorClass;
1209  }
1210
1211  virtual void EmitImpl(llvm::Serializer& S) const;
1212  static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D,
1213                                            ASTContext& C);
1214};
1215
1216/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
1217/// GNU "missing LHS" extension is in use.
1218///
1219class ConditionalOperator : public Expr {
1220  enum { COND, LHS, RHS, END_EXPR };
1221  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1222public:
1223  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
1224    : Expr(ConditionalOperatorClass, t,
1225           // FIXME: the type of the conditional operator doesn't
1226           // depend on the type of the conditional, but the standard
1227           // seems to imply that it could. File a bug!
1228           ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
1229           (cond->isValueDependent() ||
1230            (lhs && lhs->isValueDependent()) ||
1231            (rhs && rhs->isValueDependent()))) {
1232    SubExprs[COND] = cond;
1233    SubExprs[LHS] = lhs;
1234    SubExprs[RHS] = rhs;
1235  }
1236
1237  // getCond - Return the expression representing the condition for
1238  //  the ?: operator.
1239  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1240
1241  // getTrueExpr - Return the subexpression representing the value of the ?:
1242  //  expression if the condition evaluates to true.  In most cases this value
1243  //  will be the same as getLHS() except a GCC extension allows the left
1244  //  subexpression to be omitted, and instead of the condition be returned.
1245  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
1246  //  is only evaluated once.
1247  Expr *getTrueExpr() const {
1248    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
1249  }
1250
1251  // getTrueExpr - Return the subexpression representing the value of the ?:
1252  // expression if the condition evaluates to false. This is the same as getRHS.
1253  Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
1254
1255  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
1256  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1257
1258  virtual SourceRange getSourceRange() const {
1259    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
1260  }
1261  static bool classof(const Stmt *T) {
1262    return T->getStmtClass() == ConditionalOperatorClass;
1263  }
1264  static bool classof(const ConditionalOperator *) { return true; }
1265
1266  // Iterators
1267  virtual child_iterator child_begin();
1268  virtual child_iterator child_end();
1269
1270  virtual void EmitImpl(llvm::Serializer& S) const;
1271  static ConditionalOperator* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1272};
1273
1274/// AddrLabelExpr - The GNU address of label extension, representing &&label.
1275class AddrLabelExpr : public Expr {
1276  SourceLocation AmpAmpLoc, LabelLoc;
1277  LabelStmt *Label;
1278public:
1279  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
1280                QualType t)
1281    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
1282
1283  virtual SourceRange getSourceRange() const {
1284    return SourceRange(AmpAmpLoc, LabelLoc);
1285  }
1286
1287  LabelStmt *getLabel() const { return Label; }
1288
1289  static bool classof(const Stmt *T) {
1290    return T->getStmtClass() == AddrLabelExprClass;
1291  }
1292  static bool classof(const AddrLabelExpr *) { return true; }
1293
1294  // Iterators
1295  virtual child_iterator child_begin();
1296  virtual child_iterator child_end();
1297
1298  virtual void EmitImpl(llvm::Serializer& S) const;
1299  static AddrLabelExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1300};
1301
1302/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
1303/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
1304/// takes the value of the last subexpression.
1305class StmtExpr : public Expr {
1306  Stmt *SubStmt;
1307  SourceLocation LParenLoc, RParenLoc;
1308public:
1309  StmtExpr(CompoundStmt *substmt, QualType T,
1310           SourceLocation lp, SourceLocation rp) :
1311    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
1312
1313  CompoundStmt *getSubStmt() { return cast<CompoundStmt>(SubStmt); }
1314  const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); }
1315
1316  virtual SourceRange getSourceRange() const {
1317    return SourceRange(LParenLoc, RParenLoc);
1318  }
1319
1320  static bool classof(const Stmt *T) {
1321    return T->getStmtClass() == StmtExprClass;
1322  }
1323  static bool classof(const StmtExpr *) { return true; }
1324
1325  // Iterators
1326  virtual child_iterator child_begin();
1327  virtual child_iterator child_end();
1328
1329  virtual void EmitImpl(llvm::Serializer& S) const;
1330  static StmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1331};
1332
1333/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
1334/// This AST node represents a function that returns 1 if two *types* (not
1335/// expressions) are compatible. The result of this built-in function can be
1336/// used in integer constant expressions.
1337class TypesCompatibleExpr : public Expr {
1338  QualType Type1;
1339  QualType Type2;
1340  SourceLocation BuiltinLoc, RParenLoc;
1341public:
1342  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
1343                      QualType t1, QualType t2, SourceLocation RP) :
1344    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
1345    BuiltinLoc(BLoc), RParenLoc(RP) {}
1346
1347  QualType getArgType1() const { return Type1; }
1348  QualType getArgType2() const { return Type2; }
1349
1350  virtual SourceRange getSourceRange() const {
1351    return SourceRange(BuiltinLoc, RParenLoc);
1352  }
1353  static bool classof(const Stmt *T) {
1354    return T->getStmtClass() == TypesCompatibleExprClass;
1355  }
1356  static bool classof(const TypesCompatibleExpr *) { return true; }
1357
1358  // Iterators
1359  virtual child_iterator child_begin();
1360  virtual child_iterator child_end();
1361
1362  virtual void EmitImpl(llvm::Serializer& S) const;
1363  static TypesCompatibleExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1364};
1365
1366/// ShuffleVectorExpr - clang-specific builtin-in function
1367/// __builtin_shufflevector.
1368/// This AST node represents a operator that does a constant
1369/// shuffle, similar to LLVM's shufflevector instruction. It takes
1370/// two vectors and a variable number of constant indices,
1371/// and returns the appropriately shuffled vector.
1372class ShuffleVectorExpr : public Expr {
1373  SourceLocation BuiltinLoc, RParenLoc;
1374
1375  // SubExprs - the list of values passed to the __builtin_shufflevector
1376  // function. The first two are vectors, and the rest are constant
1377  // indices.  The number of values in this list is always
1378  // 2+the number of indices in the vector type.
1379  Stmt **SubExprs;
1380  unsigned NumExprs;
1381
1382public:
1383  ShuffleVectorExpr(Expr **args, unsigned nexpr,
1384                    QualType Type, SourceLocation BLoc,
1385                    SourceLocation RP) :
1386    Expr(ShuffleVectorExprClass, Type), BuiltinLoc(BLoc),
1387    RParenLoc(RP), NumExprs(nexpr) {
1388
1389    SubExprs = new Stmt*[nexpr];
1390    for (unsigned i = 0; i < nexpr; i++)
1391      SubExprs[i] = args[i];
1392  }
1393
1394  virtual SourceRange getSourceRange() const {
1395    return SourceRange(BuiltinLoc, RParenLoc);
1396  }
1397  static bool classof(const Stmt *T) {
1398    return T->getStmtClass() == ShuffleVectorExprClass;
1399  }
1400  static bool classof(const ShuffleVectorExpr *) { return true; }
1401
1402  ~ShuffleVectorExpr() {
1403    delete [] SubExprs;
1404  }
1405
1406  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1407  /// constant expression, the actual arguments passed in, and the function
1408  /// pointers.
1409  unsigned getNumSubExprs() const { return NumExprs; }
1410
1411  /// getExpr - Return the Expr at the specified index.
1412  Expr *getExpr(unsigned Index) {
1413    assert((Index < NumExprs) && "Arg access out of range!");
1414    return cast<Expr>(SubExprs[Index]);
1415  }
1416  const Expr *getExpr(unsigned Index) const {
1417    assert((Index < NumExprs) && "Arg access out of range!");
1418    return cast<Expr>(SubExprs[Index]);
1419  }
1420
1421  unsigned getShuffleMaskIdx(ASTContext &Ctx, unsigned N) {
1422    assert((N < NumExprs - 2) && "Shuffle idx out of range!");
1423    return getExpr(N+2)->getIntegerConstantExprValue(Ctx).getZExtValue();
1424  }
1425
1426  // Iterators
1427  virtual child_iterator child_begin();
1428  virtual child_iterator child_end();
1429
1430  virtual void EmitImpl(llvm::Serializer& S) const;
1431  static ShuffleVectorExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1432};
1433
1434/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
1435/// This AST node is similar to the conditional operator (?:) in C, with
1436/// the following exceptions:
1437/// - the test expression must be a constant expression.
1438/// - the expression returned has it's type unaltered by promotion rules.
1439/// - does not evaluate the expression that was not chosen.
1440class ChooseExpr : public Expr {
1441  enum { COND, LHS, RHS, END_EXPR };
1442  Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
1443  SourceLocation BuiltinLoc, RParenLoc;
1444public:
1445  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
1446             SourceLocation RP)
1447    : Expr(ChooseExprClass, t),
1448      BuiltinLoc(BLoc), RParenLoc(RP) {
1449      SubExprs[COND] = cond;
1450      SubExprs[LHS] = lhs;
1451      SubExprs[RHS] = rhs;
1452    }
1453
1454  /// isConditionTrue - Return true if the condition is true.  This is always
1455  /// statically knowable for a well-formed choosexpr.
1456  bool isConditionTrue(ASTContext &C) const;
1457
1458  Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
1459  Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
1460  Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
1461
1462  virtual SourceRange getSourceRange() const {
1463    return SourceRange(BuiltinLoc, RParenLoc);
1464  }
1465  static bool classof(const Stmt *T) {
1466    return T->getStmtClass() == ChooseExprClass;
1467  }
1468  static bool classof(const ChooseExpr *) { return true; }
1469
1470  // Iterators
1471  virtual child_iterator child_begin();
1472  virtual child_iterator child_end();
1473
1474  virtual void EmitImpl(llvm::Serializer& S) const;
1475  static ChooseExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1476};
1477
1478/// GNUNullExpr - Implements the GNU __null extension, which is a name
1479/// for a null pointer constant that has integral type (e.g., int or
1480/// long) and is the same size and alignment as a pointer. The __null
1481/// extension is typically only used by system headers, which define
1482/// NULL as __null in C++ rather than using 0 (which is an integer
1483/// that may not match the size of a pointer).
1484class GNUNullExpr : public Expr {
1485  /// TokenLoc - The location of the __null keyword.
1486  SourceLocation TokenLoc;
1487
1488public:
1489  GNUNullExpr(QualType Ty, SourceLocation Loc)
1490    : Expr(GNUNullExprClass, Ty), TokenLoc(Loc) { }
1491
1492  /// getTokenLocation - The location of the __null token.
1493  SourceLocation getTokenLocation() const { return TokenLoc; }
1494
1495  virtual SourceRange getSourceRange() const {
1496    return SourceRange(TokenLoc);
1497  }
1498  static bool classof(const Stmt *T) {
1499    return T->getStmtClass() == GNUNullExprClass;
1500  }
1501  static bool classof(const GNUNullExpr *) { return true; }
1502
1503  // Iterators
1504  virtual child_iterator child_begin();
1505  virtual child_iterator child_end();
1506
1507  virtual void EmitImpl(llvm::Serializer& S) const;
1508  static GNUNullExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1509};
1510
1511/// OverloadExpr - Clang builtin function __builtin_overload.
1512/// This AST node provides a way to overload functions in C.
1513///
1514/// The first argument is required to be a constant expression, for the number
1515/// of arguments passed to each candidate function.
1516///
1517/// The next N arguments, where N is the value of the constant expression,
1518/// are the values to be passed as arguments.
1519///
1520/// The rest of the arguments are values of pointer to function type, which
1521/// are the candidate functions for overloading.
1522///
1523/// The result is a equivalent to a CallExpr taking N arguments to the
1524/// candidate function whose parameter types match the types of the N arguments.
1525///
1526/// example: float Z = __builtin_overload(2, X, Y, modf, mod, modl);
1527/// If X and Y are long doubles, Z will assigned the result of modl(X, Y);
1528/// If X and Y are floats, Z will be assigned the result of modf(X, Y);
1529class OverloadExpr : public Expr {
1530  // SubExprs - the list of values passed to the __builtin_overload function.
1531  // SubExpr[0] is a constant expression
1532  // SubExpr[1-N] are the parameters to pass to the matching function call
1533  // SubExpr[N-...] are the candidate functions, of type pointer to function.
1534  Stmt **SubExprs;
1535
1536  // NumExprs - the size of the SubExprs array
1537  unsigned NumExprs;
1538
1539  // The index of the matching candidate function
1540  unsigned FnIndex;
1541
1542  SourceLocation BuiltinLoc;
1543  SourceLocation RParenLoc;
1544public:
1545  OverloadExpr(Expr **args, unsigned nexprs, unsigned idx, QualType t,
1546               SourceLocation bloc, SourceLocation rploc)
1547    : Expr(OverloadExprClass, t), NumExprs(nexprs), FnIndex(idx),
1548      BuiltinLoc(bloc), RParenLoc(rploc) {
1549    SubExprs = new Stmt*[nexprs];
1550    for (unsigned i = 0; i != nexprs; ++i)
1551      SubExprs[i] = args[i];
1552  }
1553  ~OverloadExpr() {
1554    delete [] SubExprs;
1555  }
1556
1557  /// arg_begin - Return a pointer to the list of arguments that will be passed
1558  /// to the matching candidate function, skipping over the initial constant
1559  /// expression.
1560  typedef ConstExprIterator const_arg_iterator;
1561  const_arg_iterator arg_begin() const { return &SubExprs[0]+1; }
1562  const_arg_iterator arg_end(ASTContext& Ctx) const {
1563    return &SubExprs[0]+1+getNumArgs(Ctx);
1564  }
1565
1566  /// getNumArgs - Return the number of arguments to pass to the candidate
1567  /// functions.
1568  unsigned getNumArgs(ASTContext &Ctx) const {
1569    return getExpr(0)->getIntegerConstantExprValue(Ctx).getZExtValue();
1570  }
1571
1572  /// getNumSubExprs - Return the size of the SubExprs array.  This includes the
1573  /// constant expression, the actual arguments passed in, and the function
1574  /// pointers.
1575  unsigned getNumSubExprs() const { return NumExprs; }
1576
1577  /// getExpr - Return the Expr at the specified index.
1578  Expr *getExpr(unsigned Index) const {
1579    assert((Index < NumExprs) && "Arg access out of range!");
1580    return cast<Expr>(SubExprs[Index]);
1581  }
1582
1583  /// getFn - Return the matching candidate function for this OverloadExpr.
1584  Expr *getFn() const { return cast<Expr>(SubExprs[FnIndex]); }
1585
1586  virtual SourceRange getSourceRange() const {
1587    return SourceRange(BuiltinLoc, RParenLoc);
1588  }
1589  static bool classof(const Stmt *T) {
1590    return T->getStmtClass() == OverloadExprClass;
1591  }
1592  static bool classof(const OverloadExpr *) { return true; }
1593
1594  // Iterators
1595  virtual child_iterator child_begin();
1596  virtual child_iterator child_end();
1597
1598  virtual void EmitImpl(llvm::Serializer& S) const;
1599  static OverloadExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1600};
1601
1602/// VAArgExpr, used for the builtin function __builtin_va_start.
1603class VAArgExpr : public Expr {
1604  Stmt *Val;
1605  SourceLocation BuiltinLoc, RParenLoc;
1606public:
1607  VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc)
1608    : Expr(VAArgExprClass, t),
1609      Val(e),
1610      BuiltinLoc(BLoc),
1611      RParenLoc(RPLoc) { }
1612
1613  const Expr *getSubExpr() const { return cast<Expr>(Val); }
1614  Expr *getSubExpr() { return cast<Expr>(Val); }
1615  virtual SourceRange getSourceRange() const {
1616    return SourceRange(BuiltinLoc, RParenLoc);
1617  }
1618  static bool classof(const Stmt *T) {
1619    return T->getStmtClass() == VAArgExprClass;
1620  }
1621  static bool classof(const VAArgExpr *) { return true; }
1622
1623  // Iterators
1624  virtual child_iterator child_begin();
1625  virtual child_iterator child_end();
1626
1627  virtual void EmitImpl(llvm::Serializer& S) const;
1628  static VAArgExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1629};
1630
1631/// InitListExpr - used for struct and array initializers, such as:
1632///    struct foo x = { 1, { 2, 3 } };
1633///
1634/// Because C is somewhat loose with braces, the AST does not necessarily
1635/// directly model the C source.  Instead, the semantic analyzer aims to make
1636/// the InitListExprs match up with the type of the decl being initialized.  We
1637/// have the following exceptions:
1638///
1639///  1. Elements at the end of the list may be dropped from the initializer.
1640///     These elements are defined to be initialized to zero.  For example:
1641///         int x[20] = { 1 };
1642///  2. Initializers may have excess initializers which are to be ignored by the
1643///     compiler.  For example:
1644///         int x[1] = { 1, 2 };
1645///  3. Redundant InitListExprs may be present around scalar elements.  These
1646///     always have a single element whose type is the same as the InitListExpr.
1647///     this can only happen for Type::isScalarType() types.
1648///         int x = { 1 };  int y[2] = { {1}, {2} };
1649///
1650class InitListExpr : public Expr {
1651  std::vector<Stmt *> InitExprs;
1652  SourceLocation LBraceLoc, RBraceLoc;
1653
1654  /// HadDesignators - Return true if there were any designators in this
1655  /// init list expr.  FIXME: this should be replaced by storing the designators
1656  /// somehow and updating codegen.
1657  bool HadDesignators;
1658public:
1659  InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
1660               SourceLocation rbraceloc, bool HadDesignators);
1661
1662  unsigned getNumInits() const { return InitExprs.size(); }
1663  bool hadDesignators() const { return HadDesignators; }
1664
1665  const Expr* getInit(unsigned Init) const {
1666    assert(Init < getNumInits() && "Initializer access out of range!");
1667    return cast<Expr>(InitExprs[Init]);
1668  }
1669
1670  Expr* getInit(unsigned Init) {
1671    assert(Init < getNumInits() && "Initializer access out of range!");
1672    return cast<Expr>(InitExprs[Init]);
1673  }
1674
1675  void setInit(unsigned Init, Expr *expr) {
1676    assert(Init < getNumInits() && "Initializer access out of range!");
1677    InitExprs[Init] = expr;
1678  }
1679
1680  // Dynamic removal/addition (for constructing implicit InitExpr's).
1681  void removeInit(unsigned Init) {
1682    InitExprs.erase(InitExprs.begin()+Init);
1683  }
1684  void addInit(unsigned Init, Expr *expr) {
1685    InitExprs.insert(InitExprs.begin()+Init, expr);
1686  }
1687
1688  // Explicit InitListExpr's originate from source code (and have valid source
1689  // locations). Implicit InitListExpr's are created by the semantic analyzer.
1690  bool isExplicit() { return !isImplicit(); }
1691
1692  virtual SourceRange getSourceRange() const {
1693    return SourceRange(LBraceLoc, RBraceLoc);
1694  }
1695  static bool classof(const Stmt *T) {
1696    return T->getStmtClass() == InitListExprClass;
1697  }
1698  static bool classof(const InitListExpr *) { return true; }
1699
1700  // Iterators
1701  virtual child_iterator child_begin();
1702  virtual child_iterator child_end();
1703
1704  typedef std::vector<Stmt *>::iterator iterator;
1705  typedef std::vector<Stmt *>::reverse_iterator reverse_iterator;
1706
1707  iterator begin() { return InitExprs.begin(); }
1708  iterator end() { return InitExprs.end(); }
1709  reverse_iterator rbegin() { return InitExprs.rbegin(); }
1710  reverse_iterator rend() { return InitExprs.rend(); }
1711
1712  // Serailization.
1713  virtual void EmitImpl(llvm::Serializer& S) const;
1714  static InitListExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1715
1716private:
1717  // Used by serializer.
1718  InitListExpr() : Expr(InitListExprClass, QualType()) {}
1719};
1720
1721//===----------------------------------------------------------------------===//
1722// Clang Extensions
1723//===----------------------------------------------------------------------===//
1724
1725
1726/// ExtVectorElementExpr - This represents access to specific elements of a
1727/// vector, and may occur on the left hand side or right hand side.  For example
1728/// the following is legal:  "V.xy = V.zw" if V is a 4 element extended vector.
1729///
1730class ExtVectorElementExpr : public Expr {
1731  Stmt *Base;
1732  IdentifierInfo &Accessor;
1733  SourceLocation AccessorLoc;
1734public:
1735  ExtVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
1736                       SourceLocation loc)
1737    : Expr(ExtVectorElementExprClass, ty),
1738      Base(base), Accessor(accessor), AccessorLoc(loc) {}
1739
1740  const Expr *getBase() const { return cast<Expr>(Base); }
1741  Expr *getBase() { return cast<Expr>(Base); }
1742
1743  IdentifierInfo &getAccessor() const { return Accessor; }
1744
1745  /// getNumElements - Get the number of components being selected.
1746  unsigned getNumElements() const;
1747
1748  /// containsDuplicateElements - Return true if any element access is
1749  /// repeated.
1750  bool containsDuplicateElements() const;
1751
1752  /// getEncodedElementAccess - Encode the elements accessed into an llvm
1753  /// aggregate Constant of ConstantInt(s).
1754  void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
1755
1756  virtual SourceRange getSourceRange() const {
1757    return SourceRange(getBase()->getLocStart(), AccessorLoc);
1758  }
1759
1760  static bool classof(const Stmt *T) {
1761    return T->getStmtClass() == ExtVectorElementExprClass;
1762  }
1763  static bool classof(const ExtVectorElementExpr *) { return true; }
1764
1765  // Iterators
1766  virtual child_iterator child_begin();
1767  virtual child_iterator child_end();
1768
1769  virtual void EmitImpl(llvm::Serializer& S) const;
1770  static ExtVectorElementExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1771};
1772
1773
1774/// BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
1775/// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
1776class BlockExpr : public Expr {
1777protected:
1778  BlockDecl *TheBlock;
1779public:
1780  BlockExpr(BlockDecl *BD, QualType ty) : Expr(BlockExprClass, ty),
1781            TheBlock(BD) {}
1782
1783  BlockDecl *getBlockDecl() { return TheBlock; }
1784
1785  // Convenience functions for probing the underlying BlockDecl.
1786  SourceLocation getCaretLocation() const;
1787  const Stmt *getBody() const;
1788  Stmt *getBody();
1789
1790  virtual SourceRange getSourceRange() const {
1791    return SourceRange(getCaretLocation(), getBody()->getLocEnd());
1792  }
1793
1794  /// getFunctionType - Return the underlying function type for this block.
1795  const FunctionType *getFunctionType() const;
1796
1797  static bool classof(const Stmt *T) {
1798    return T->getStmtClass() == BlockExprClass;
1799  }
1800  static bool classof(const BlockExpr *) { return true; }
1801
1802  // Iterators
1803  virtual child_iterator child_begin();
1804  virtual child_iterator child_end();
1805
1806  virtual void EmitImpl(llvm::Serializer& S) const;
1807  static BlockExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1808};
1809
1810/// BlockDeclRefExpr - A reference to a declared variable, function,
1811/// enum, etc.
1812class BlockDeclRefExpr : public Expr {
1813  ValueDecl *D;
1814  SourceLocation Loc;
1815  bool IsByRef;
1816public:
1817  BlockDeclRefExpr(ValueDecl *d, QualType t, SourceLocation l, bool ByRef) :
1818       Expr(BlockDeclRefExprClass, t), D(d), Loc(l), IsByRef(ByRef) {}
1819
1820  ValueDecl *getDecl() { return D; }
1821  const ValueDecl *getDecl() const { return D; }
1822  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
1823
1824  bool isByRef() const { return IsByRef; }
1825
1826  static bool classof(const Stmt *T) {
1827    return T->getStmtClass() == BlockDeclRefExprClass;
1828  }
1829  static bool classof(const BlockDeclRefExpr *) { return true; }
1830
1831  // Iterators
1832  virtual child_iterator child_begin();
1833  virtual child_iterator child_end();
1834
1835  virtual void EmitImpl(llvm::Serializer& S) const;
1836  static BlockDeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
1837};
1838
1839}  // end namespace clang
1840
1841#endif
1842