Expr.h revision eb14fe839ec24c2ca14e5f094be147a34e3d3339
1402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===//
2402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
3402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//                     The LLVM Compiler Infrastructure
4402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
5402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll// This file was developed by Chris Lattner and is distributed under
6402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll// the University of Illinois Open Source License. See LICENSE.TXT for details.
7402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
8402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//===----------------------------------------------------------------------===//
9402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
10402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//  This file defines the Expr interface and subclasses.
11402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//
12402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//===----------------------------------------------------------------------===//
13402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
14402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#ifndef LLVM_CLANG_AST_EXPR_H
15402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#define LLVM_CLANG_AST_EXPR_H
16402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
17402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include "clang/AST/Stmt.h"
18402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include "clang/AST/Type.h"
19402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include "clang/AST/Decl.h"
20402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll#include "llvm/ADT/APSInt.h"
21402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
22402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollnamespace clang {
23402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  class IdentifierInfo;
24402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  class Decl;
25402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  class ASTContext;
26402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
27402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/// Expr - This represents one expression.  Note that Expr's are subclasses of
28402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/// Stmt.  This allows an expression to be transparently used any place a Stmt
29402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/// is required.
30402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll///
31402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollclass Expr : public Stmt {
32402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  QualType TR;
33402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollprotected:
34402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  Expr(StmtClass SC, QualType T) : Stmt(SC), TR(T) {}
35402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  ~Expr() {}
36402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic:
37402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  QualType getType() const { return TR; }
38402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  void setType(QualType t) { TR = t; }
39402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
40402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// SourceLocation tokens are not useful in isolation - they are low level
41402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// value objects created/interpreted by SourceManager. We assume AST
42402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// clients will have a pointer to the respective SourceManager.
43402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  virtual SourceRange getSourceRange() const = 0;
44402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  SourceLocation getLocStart() const { return getSourceRange().Begin(); }
45402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  SourceLocation getLocEnd() const { return getSourceRange().End(); }
46402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
47402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// getExprLoc - Return the preferred location for the arrow when diagnosing
48402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// a problem with a generic expression.
49402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  virtual SourceLocation getExprLoc() const { return getLocStart(); }
50402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
51402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// hasLocalSideEffect - Return true if this immediate expression has side
52402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// effects, not counting any sub-expressions.
53402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  bool hasLocalSideEffect() const;
54402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
55402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or
56402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// incomplete type other than void. Nonarray expressions that can be lvalues:
57402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  ///  - name, where name must be a variable
58402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  ///  - e[i]
59402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  ///  - (e), where e must be an lvalue
60402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  ///  - e.name, where e must be an lvalue
61402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  ///  - e->name
62402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  ///  - *e, the type of e cannot be a function type
63402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  ///  - string-constant
64402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  ///  - reference type [C++ [expr]]
65402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  ///
66402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  enum isLvalueResult {
67402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    LV_Valid,
68402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    LV_NotObjectType,
69402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    LV_IncompleteVoidType,
70402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    LV_DuplicateVectorComponents,
71402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    LV_InvalidExpression
72402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  };
73402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  isLvalueResult isLvalue() const;
74402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
75402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
76402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// does not have an incomplete type, does not have a const-qualified type,
77402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// and if it is a structure or union, does not have any member (including,
78402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// recursively, any member or element of all contained aggregates or unions)
79402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// with a const-qualified type.
80402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  enum isModifiableLvalueResult {
81402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    MLV_Valid,
82402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    MLV_NotObjectType,
83402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    MLV_IncompleteVoidType,
84402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    MLV_DuplicateVectorComponents,
85402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    MLV_InvalidExpression,
86402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    MLV_IncompleteType,
87402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    MLV_ConstQualified,
88402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    MLV_ArrayType
89402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  };
90402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  isModifiableLvalueResult isModifiableLvalue() const;
91402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
92402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  bool isNullPointerConstant(ASTContext &Ctx) const;
93402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
94402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// isIntegerConstantExpr - Return true if this expression is a valid integer
95402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// constant expression, and, if so, return its value in Result.  If not a
96402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// valid i-c-e, return false and fill in Loc (if specified) with the location
97402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  /// of the invalid expression.
98402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
99402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll                             SourceLocation *Loc = 0,
100402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll                             bool isEvaluated = true) const;
101402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const {
102402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    llvm::APSInt X(32);
103402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return isIntegerConstantExpr(X, Ctx, Loc);
104402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  }
105402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
106402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  static bool classof(const Stmt *T) {
107402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return T->getStmtClass() >= firstExprConstant &&
108402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll           T->getStmtClass() <= lastExprConstant;
109402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  }
110402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  static bool classof(const Expr *) { return true; }
111402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll};
112402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
113402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//===----------------------------------------------------------------------===//
114402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll// Primary Expressions.
115402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll//===----------------------------------------------------------------------===//
116402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
117402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function,
118402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/// enum, etc.
119402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollclass DeclRefExpr : public Expr {
120402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  Decl *D; // a ValueDecl or EnumConstantDecl
121402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  SourceLocation Loc;
122402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic:
123402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  DeclRefExpr(Decl *d, QualType t, SourceLocation l) :
124402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    Expr(DeclRefExprClass, t), D(d), Loc(l) {}
125402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
126402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  Decl *getDecl() { return D; }
127402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  const Decl *getDecl() const { return D; }
128402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
129402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
130402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
131402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  static bool classof(const Stmt *T) {
132402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return T->getStmtClass() == DeclRefExprClass;
133402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  }
134402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  static bool classof(const DeclRefExpr *) { return true; }
135402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
136402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  // Iterators
137402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  virtual child_iterator child_begin();
138402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  virtual child_iterator child_end();
139402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll};
140402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
141402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/// PreDefinedExpr - [C99 6.4.2.2] - A pre-defined identifier such as __func__.
142402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollclass PreDefinedExpr : public Expr {
143402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic:
144402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  enum IdentType {
145402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    Func,
146402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    Function,
147402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    PrettyFunction
148402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  };
149402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
150402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollprivate:
151402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  SourceLocation Loc;
152402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  IdentType Type;
153402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic:
154402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  PreDefinedExpr(SourceLocation l, QualType type, IdentType IT)
155402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    : Expr(PreDefinedExprClass, type), Loc(l), Type(IT) {}
156402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
157402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  IdentType getIdentType() const { return Type; }
158402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
159402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
160402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
161402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  static bool classof(const Stmt *T) {
162402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return T->getStmtClass() == PreDefinedExprClass;
163402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  }
164402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  static bool classof(const PreDefinedExpr *) { return true; }
165402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
166402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  // Iterators
167402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  virtual child_iterator child_begin();
168402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  virtual child_iterator child_end();
169402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll};
170402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
171402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollclass IntegerLiteral : public Expr {
172402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  llvm::APInt Value;
173402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  SourceLocation Loc;
174402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic:
175402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
176402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  // or UnsignedLongLongTy
177402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l)
178402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    : Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
179402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
180402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  }
181402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  const llvm::APInt &getValue() const { return Value; }
182402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
183402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
184402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll  static bool classof(const Stmt *T) {
185402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    return T->getStmtClass() == IntegerLiteralClass;
186  }
187  static bool classof(const IntegerLiteral *) { return true; }
188
189  // Iterators
190  virtual child_iterator child_begin();
191  virtual child_iterator child_end();
192};
193
194class CharacterLiteral : public Expr {
195  unsigned Value;
196  SourceLocation Loc;
197public:
198  // type should be IntTy
199  CharacterLiteral(unsigned value, QualType type, SourceLocation l)
200    : Expr(CharacterLiteralClass, type), Value(value), Loc(l) {
201  }
202  SourceLocation getLoc() const { return Loc; }
203
204  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
205
206  unsigned getValue() const { return Value; }
207
208  static bool classof(const Stmt *T) {
209    return T->getStmtClass() == CharacterLiteralClass;
210  }
211  static bool classof(const CharacterLiteral *) { return true; }
212
213  // Iterators
214  virtual child_iterator child_begin();
215  virtual child_iterator child_end();
216};
217
218class FloatingLiteral : public Expr {
219  float Value; // FIXME
220  SourceLocation Loc;
221public:
222  FloatingLiteral(float value, QualType type, SourceLocation l)
223    : Expr(FloatingLiteralClass, type), Value(value), Loc(l) {}
224
225  float getValue() const { return Value; }
226
227  virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
228
229  static bool classof(const Stmt *T) {
230    return T->getStmtClass() == FloatingLiteralClass;
231  }
232  static bool classof(const FloatingLiteral *) { return true; }
233
234  // Iterators
235  virtual child_iterator child_begin();
236  virtual child_iterator child_end();
237};
238
239/// StringLiteral - This represents a string literal expression, e.g. "foo"
240/// or L"bar" (wide strings).  The actual string is returned by getStrData()
241/// is NOT null-terminated, and the length of the string is determined by
242/// calling getByteLength().
243class StringLiteral : public Expr {
244  const char *StrData;
245  unsigned ByteLength;
246  bool IsWide;
247  // if the StringLiteral was composed using token pasting, both locations
248  // are needed. If not (the common case), firstTokLoc == lastTokLoc.
249  // FIXME: if space becomes an issue, we should create a sub-class.
250  SourceLocation firstTokLoc, lastTokLoc;
251public:
252  StringLiteral(const char *strData, unsigned byteLength, bool Wide,
253                QualType t, SourceLocation b, SourceLocation e);
254  virtual ~StringLiteral();
255
256  const char *getStrData() const { return StrData; }
257  unsigned getByteLength() const { return ByteLength; }
258  bool isWide() const { return IsWide; }
259
260  virtual SourceRange getSourceRange() const {
261    return SourceRange(firstTokLoc,lastTokLoc);
262  }
263  static bool classof(const Stmt *T) {
264    return T->getStmtClass() == StringLiteralClass;
265  }
266  static bool classof(const StringLiteral *) { return true; }
267
268  // Iterators
269  virtual child_iterator child_begin();
270  virtual child_iterator child_end();
271};
272
273/// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This
274/// AST node is only formed if full location information is requested.
275class ParenExpr : public Expr {
276  SourceLocation L, R;
277  Expr *Val;
278public:
279  ParenExpr(SourceLocation l, SourceLocation r, Expr *val)
280    : Expr(ParenExprClass, val->getType()), L(l), R(r), Val(val) {}
281
282  const Expr *getSubExpr() const { return Val; }
283  Expr *getSubExpr() { return Val; }
284  SourceRange getSourceRange() const { return SourceRange(L, R); }
285
286  static bool classof(const Stmt *T) {
287    return T->getStmtClass() == ParenExprClass;
288  }
289  static bool classof(const ParenExpr *) { return true; }
290
291  // Iterators
292  virtual child_iterator child_begin();
293  virtual child_iterator child_end();
294};
295
296
297/// UnaryOperator - This represents the unary-expression's (except sizeof of
298/// types), the postinc/postdec operators from postfix-expression, and various
299/// extensions.
300///
301/// Notes on various nodes:
302///
303/// Real/Imag - These return the real/imag part of a complex operand.  If
304///   applied to a non-complex value, the former returns its operand and the
305///   later returns zero in the type of the operand.
306///
307class UnaryOperator : public Expr {
308public:
309  // Note that additions to this should also update the StmtVisitor class.
310  enum Opcode {
311    PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators
312    PreInc, PreDec,   // [C99 6.5.3.1] Prefix increment and decrement operators.
313    AddrOf, Deref,    // [C99 6.5.3.2] Address and indirection operators.
314    Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
315    Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
316    SizeOf, AlignOf,  // [C99 6.5.3.4] Sizeof (expr, not type) operator.
317    Real, Imag,       // "__real expr"/"__imag expr" Extension.
318    Extension         // __extension__ marker.
319  };
320private:
321  Expr *Val;
322  Opcode Opc;
323  SourceLocation Loc;
324public:
325
326  UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
327    : Expr(UnaryOperatorClass, type), Val(input), Opc(opc), Loc(l) {}
328
329  Opcode getOpcode() const { return Opc; }
330  Expr *getSubExpr() const { return Val; }
331
332  /// getOperatorLoc - Return the location of the operator.
333  SourceLocation getOperatorLoc() const { return Loc; }
334
335  /// isPostfix - Return true if this is a postfix operation, like x++.
336  static bool isPostfix(Opcode Op);
337
338  bool isPostfix() const { return isPostfix(Opc); }
339  bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
340  bool isSizeOfAlignOfOp() const { return Opc == SizeOf || Opc == AlignOf; }
341  static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
342
343  /// getDecl - a recursive routine that derives the base decl for an
344  /// expression. For example, it will return the declaration for "s" from
345  /// the following complex expression "s.zz[2].bb.vv".
346  static bool isAddressable(Expr *e);
347
348  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
349  /// corresponds to, e.g. "sizeof" or "[pre]++"
350  static const char *getOpcodeStr(Opcode Op);
351
352  virtual SourceRange getSourceRange() const {
353    if (isPostfix())
354      return SourceRange(Val->getLocStart(), Loc);
355    else
356      return SourceRange(Loc, Val->getLocEnd());
357  }
358  virtual SourceLocation getExprLoc() const { return Loc; }
359
360  static bool classof(const Stmt *T) {
361    return T->getStmtClass() == UnaryOperatorClass;
362  }
363  static bool classof(const UnaryOperator *) { return true; }
364
365  // Iterators
366  virtual child_iterator child_begin();
367  virtual child_iterator child_end();
368};
369
370/// SizeOfAlignOfTypeExpr - [C99 6.5.3.4] - This is only for sizeof/alignof of
371/// *types*.  sizeof(expr) is handled by UnaryOperator.
372class SizeOfAlignOfTypeExpr : public Expr {
373  bool isSizeof;  // true if sizeof, false if alignof.
374  QualType Ty;
375  SourceLocation OpLoc, RParenLoc;
376public:
377  SizeOfAlignOfTypeExpr(bool issizeof, QualType argType, QualType resultType,
378                        SourceLocation op, SourceLocation rp) :
379    Expr(SizeOfAlignOfTypeExprClass, resultType),
380    isSizeof(issizeof), Ty(argType), OpLoc(op), RParenLoc(rp) {}
381
382  bool isSizeOf() const { return isSizeof; }
383  QualType getArgumentType() const { return Ty; }
384
385  SourceLocation getOperatorLoc() const { return OpLoc; }
386  SourceRange getSourceRange() const { return SourceRange(OpLoc, RParenLoc); }
387
388  static bool classof(const Stmt *T) {
389    return T->getStmtClass() == SizeOfAlignOfTypeExprClass;
390  }
391  static bool classof(const SizeOfAlignOfTypeExpr *) { return true; }
392
393  // Iterators
394  virtual child_iterator child_begin();
395  virtual child_iterator child_end();
396};
397
398//===----------------------------------------------------------------------===//
399// Postfix Operators.
400//===----------------------------------------------------------------------===//
401
402/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
403class ArraySubscriptExpr : public Expr {
404  enum { LHS, RHS, END_EXPR=2 };
405  Expr* SubExprs[END_EXPR];
406  SourceLocation RBracketLoc;
407public:
408  ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
409                     SourceLocation rbracketloc) :
410    Expr(ArraySubscriptExprClass, t),
411    RBracketLoc(rbracketloc) {
412      SubExprs[LHS] = lhs;
413      SubExprs[RHS] = rhs;
414    }
415
416  /// An array access can be written A[4] or 4[A] (both are equivalent).
417  /// - getBase() and getIdx() always present the normalized view: A[4].
418  ///    In this case getBase() returns "A" and getIdx() returns "4".
419  /// - getLHS() and getRHS() present the syntactic view. e.g. for
420  ///    4[A] getLHS() returns "4".
421
422  Expr *getLHS() { return SubExprs[LHS]; }
423  const Expr *getLHS() const { return SubExprs[LHS]; }
424
425  Expr *getRHS() { return SubExprs[RHS]; }
426  const Expr *getRHS() const { return SubExprs[RHS]; }
427
428  Expr *getBase() {
429    return (getLHS()->getType()->isIntegerType()) ? getRHS() : getLHS();
430  }
431
432  const Expr *getBase() const {
433    return (getLHS()->getType()->isIntegerType()) ? getRHS() : getLHS();
434  }
435
436  Expr *getIdx() {
437    return (getLHS()->getType()->isIntegerType()) ? getLHS() : getRHS();
438  }
439
440  const Expr *getIdx() const {
441    return (getLHS()->getType()->isIntegerType()) ? getLHS() : getRHS();
442  }
443
444
445  SourceRange getSourceRange() const {
446    return SourceRange(getLHS()->getLocStart(), RBracketLoc);
447  }
448  virtual SourceLocation getExprLoc() const { return RBracketLoc; }
449
450  static bool classof(const Stmt *T) {
451    return T->getStmtClass() == ArraySubscriptExprClass;
452  }
453  static bool classof(const ArraySubscriptExpr *) { return true; }
454
455  // Iterators
456  virtual child_iterator child_begin();
457  virtual child_iterator child_end();
458};
459
460
461/// CallExpr - [C99 6.5.2.2] Function Calls.
462///
463class CallExpr : public Expr {
464  enum { FN=0, ARGS_START=1 };
465  Expr **SubExprs;
466  unsigned NumArgs;
467  SourceLocation RParenLoc;
468public:
469  CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
470           SourceLocation rparenloc);
471  ~CallExpr() {
472    delete [] SubExprs;
473  }
474
475  const Expr *getCallee() const { return SubExprs[FN]; }
476  Expr *getCallee() { return SubExprs[FN]; }
477
478  /// getNumArgs - Return the number of actual arguments to this call.
479  ///
480  unsigned getNumArgs() const { return NumArgs; }
481
482  /// getArg - Return the specified argument.
483  Expr *getArg(unsigned Arg) {
484    assert(Arg < NumArgs && "Arg access out of range!");
485    return SubExprs[Arg+ARGS_START];
486  }
487  const Expr *getArg(unsigned Arg) const {
488    assert(Arg < NumArgs && "Arg access out of range!");
489    return SubExprs[Arg+ARGS_START];
490  }
491
492  /// getNumCommas - Return the number of commas that must have been present in
493  /// this function call.
494  unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
495
496  bool isBuiltinClassifyType(llvm::APSInt &Result) const;
497
498  SourceRange getSourceRange() const {
499    return SourceRange(getCallee()->getLocStart(), RParenLoc);
500  }
501
502  static bool classof(const Stmt *T) {
503    return T->getStmtClass() == CallExprClass;
504  }
505  static bool classof(const CallExpr *) { return true; }
506
507  // Iterators
508  virtual child_iterator child_begin();
509  virtual child_iterator child_end();
510};
511
512/// MemberExpr - [C99 6.5.2.3] Structure and Union Members.
513///
514class MemberExpr : public Expr {
515  Expr *Base;
516  FieldDecl *MemberDecl;
517  SourceLocation MemberLoc;
518  bool IsArrow;      // True if this is "X->F", false if this is "X.F".
519public:
520  MemberExpr(Expr *base, bool isarrow, FieldDecl *memberdecl, SourceLocation l)
521    : Expr(MemberExprClass, memberdecl->getType()),
522      Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {}
523
524  Expr *getBase() const { return Base; }
525  FieldDecl *getMemberDecl() const { return MemberDecl; }
526  bool isArrow() const { return IsArrow; }
527
528  virtual SourceRange getSourceRange() const {
529    return SourceRange(getBase()->getLocStart(), MemberLoc);
530  }
531  virtual SourceLocation getExprLoc() const { return MemberLoc; }
532
533  static bool classof(const Stmt *T) {
534    return T->getStmtClass() == MemberExprClass;
535  }
536  static bool classof(const MemberExpr *) { return true; }
537
538  // Iterators
539  virtual child_iterator child_begin();
540  virtual child_iterator child_end();
541};
542
543/// OCUVectorElementExpr - This represents access to specific elements of a
544/// vector, and may occur on the left hand side or right hand side.  For example
545/// the following is legal:  "V.xy = V.zw" if V is a 4 element ocu vector.
546///
547class OCUVectorElementExpr : public Expr {
548  Expr *Base;
549  IdentifierInfo &Accessor;
550  SourceLocation AccessorLoc;
551public:
552  enum ElementType {
553    Point,   // xywz
554    Color,   // rgba
555    Texture  // stpq
556  };
557  OCUVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor,
558                       SourceLocation loc)
559    : Expr(OCUVectorElementExprClass, ty),
560      Base(base), Accessor(accessor), AccessorLoc(loc) {}
561
562  const Expr *getBase() const { return Base; }
563  Expr *getBase() { return Base; }
564
565  IdentifierInfo &getAccessor() const { return Accessor; }
566
567  /// getNumElements - Get the number of components being selected.
568  unsigned getNumElements() const;
569
570  /// getElementType - Determine whether the components of this access are
571  /// "point" "color" or "texture" elements.
572  ElementType getElementType() const;
573
574  /// containsDuplicateElements - Return true if any element access is
575  /// repeated.
576  bool containsDuplicateElements() const;
577
578  /// getEncodedElementAccess - Encode the elements accessed into a bit vector.
579  /// The encoding currently uses 2-bit bitfields, but clients should use the
580  /// accessors below to access them.
581  ///
582  unsigned getEncodedElementAccess() const;
583
584  /// getAccessedFieldNo - Given an encoded value and a result number, return
585  /// the input field number being accessed.
586  static unsigned getAccessedFieldNo(unsigned Idx, unsigned EncodedVal) {
587    return (EncodedVal >> (Idx*2)) & 3;
588  }
589
590  virtual SourceRange getSourceRange() const {
591    return SourceRange(getBase()->getLocStart(), AccessorLoc);
592  }
593  static bool classof(const Stmt *T) {
594    return T->getStmtClass() == OCUVectorElementExprClass;
595  }
596  static bool classof(const OCUVectorElementExpr *) { return true; }
597
598  // Iterators
599  virtual child_iterator child_begin();
600  virtual child_iterator child_end();
601};
602
603/// CompoundLiteralExpr - [C99 6.5.2.5]
604///
605class CompoundLiteralExpr : public Expr {
606  Expr *Init;
607public:
608  CompoundLiteralExpr(QualType ty, Expr *init) :
609    Expr(CompoundLiteralExprClass, ty), Init(init) {}
610
611  const Expr *getInitializer() const { return Init; }
612  Expr *getInitializer() { return Init; }
613
614  virtual SourceRange getSourceRange() const { return Init->getSourceRange(); }
615
616  static bool classof(const Stmt *T) {
617    return T->getStmtClass() == CompoundLiteralExprClass;
618  }
619  static bool classof(const CompoundLiteralExpr *) { return true; }
620
621  // Iterators
622  virtual child_iterator child_begin();
623  virtual child_iterator child_end();
624};
625
626/// ImplicitCastExpr - Allows us to explicitly represent implicit type
627/// conversions. For example: converting T[]->T*, void f()->void (*f)(),
628/// float->double, short->int, etc.
629///
630class ImplicitCastExpr : public Expr {
631  Expr *Op;
632public:
633  ImplicitCastExpr(QualType ty, Expr *op) :
634    Expr(ImplicitCastExprClass, ty), Op(op) {}
635
636  Expr *getSubExpr() { return Op; }
637  const Expr *getSubExpr() const { return Op; }
638
639  virtual SourceRange getSourceRange() const { return Op->getSourceRange(); }
640
641  static bool classof(const Stmt *T) {
642    return T->getStmtClass() == ImplicitCastExprClass;
643  }
644  static bool classof(const ImplicitCastExpr *) { return true; }
645
646  // Iterators
647  virtual child_iterator child_begin();
648  virtual child_iterator child_end();
649};
650
651/// CastExpr - [C99 6.5.4] Cast Operators.
652///
653class CastExpr : public Expr {
654  Expr *Op;
655  SourceLocation Loc; // the location of the left paren
656public:
657  CastExpr(QualType ty, Expr *op, SourceLocation l) :
658    Expr(CastExprClass, ty), Op(op), Loc(l) {}
659
660  SourceLocation getLParenLoc() const { return Loc; }
661
662  Expr *getSubExpr() const { return Op; }
663
664  virtual SourceRange getSourceRange() const {
665    return SourceRange(Loc, getSubExpr()->getSourceRange().End());
666  }
667  static bool classof(const Stmt *T) {
668    return T->getStmtClass() == CastExprClass;
669  }
670  static bool classof(const CastExpr *) { return true; }
671
672  // Iterators
673  virtual child_iterator child_begin();
674  virtual child_iterator child_end();
675};
676
677class BinaryOperator : public Expr {
678public:
679  enum Opcode {
680    // Operators listed in order of precedence.
681    // Note that additions to this should also update the StmtVisitor class.
682    Mul, Div, Rem,    // [C99 6.5.5] Multiplicative operators.
683    Add, Sub,         // [C99 6.5.6] Additive operators.
684    Shl, Shr,         // [C99 6.5.7] Bitwise shift operators.
685    LT, GT, LE, GE,   // [C99 6.5.8] Relational operators.
686    EQ, NE,           // [C99 6.5.9] Equality operators.
687    And,              // [C99 6.5.10] Bitwise AND operator.
688    Xor,              // [C99 6.5.11] Bitwise XOR operator.
689    Or,               // [C99 6.5.12] Bitwise OR operator.
690    LAnd,             // [C99 6.5.13] Logical AND operator.
691    LOr,              // [C99 6.5.14] Logical OR operator.
692    Assign, MulAssign,// [C99 6.5.16] Assignment operators.
693    DivAssign, RemAssign,
694    AddAssign, SubAssign,
695    ShlAssign, ShrAssign,
696    AndAssign, XorAssign,
697    OrAssign,
698    Comma             // [C99 6.5.17] Comma operator.
699  };
700
701  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy)
702    : Expr(BinaryOperatorClass, ResTy), Opc(opc) {
703    SubExprs[LHS] = lhs;
704    SubExprs[RHS] = rhs;
705    assert(!isCompoundAssignmentOp() &&
706           "Use ArithAssignBinaryOperator for compound assignments");
707  }
708
709  Opcode getOpcode() const { return Opc; }
710  Expr *getLHS() const { return SubExprs[LHS]; }
711  Expr *getRHS() const { return SubExprs[RHS]; }
712  virtual SourceRange getSourceRange() const {
713    return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
714  }
715
716  /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
717  /// corresponds to, e.g. "<<=".
718  static const char *getOpcodeStr(Opcode Op);
719
720  /// predicates to categorize the respective opcodes.
721  bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; }
722  bool isAdditiveOp() const { return Opc == Add || Opc == Sub; }
723  bool isShiftOp() const { return Opc == Shl || Opc == Shr; }
724  bool isBitwiseOp() const { return Opc >= And && Opc <= Or; }
725  bool isRelationalOp() const { return Opc >= LT && Opc <= GE; }
726  bool isEqualityOp() const { return Opc == EQ || Opc == NE; }
727  bool isLogicalOp() const { return Opc == LAnd || Opc == LOr; }
728  bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; }
729  bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;}
730  bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; }
731
732  static bool classof(const Stmt *S) {
733    return S->getStmtClass() == BinaryOperatorClass ||
734           S->getStmtClass() == CompoundAssignOperatorClass;
735  }
736  static bool classof(const BinaryOperator *) { return true; }
737
738  // Iterators
739  virtual child_iterator child_begin();
740  virtual child_iterator child_end();
741
742private:
743  enum { LHS, RHS, END_EXPR };
744  Expr* SubExprs[END_EXPR];
745  Opcode Opc;
746
747protected:
748  BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, bool dead)
749    : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc) {
750    SubExprs[LHS] = lhs;
751    SubExprs[RHS] = rhs;
752  }
753};
754
755/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
756/// track of the type the operation is performed in.  Due to the semantics of
757/// these operators, the operands are promoted, the aritmetic performed, an
758/// implicit conversion back to the result type done, then the assignment takes
759/// place.  This captures the intermediate type which the computation is done
760/// in.
761class CompoundAssignOperator : public BinaryOperator {
762  QualType ComputationType;
763public:
764  CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc,
765                         QualType ResType, QualType CompType)
766    : BinaryOperator(lhs, rhs, opc, ResType, true), ComputationType(CompType) {
767    assert(isCompoundAssignmentOp() &&
768           "Only should be used for compound assignments");
769  }
770
771  QualType getComputationType() const { return ComputationType; }
772
773  static bool classof(const CompoundAssignOperator *) { return true; }
774  static bool classof(const Stmt *S) {
775    return S->getStmtClass() == CompoundAssignOperatorClass;
776  }
777};
778
779/// ConditionalOperator - The ?: operator.  Note that LHS may be null when the
780/// GNU "missing LHS" extension is in use.
781///
782class ConditionalOperator : public Expr {
783  enum { COND, LHS, RHS, END_EXPR };
784  Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
785public:
786  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
787    : Expr(ConditionalOperatorClass, t) {
788    SubExprs[COND] = cond;
789    SubExprs[LHS] = lhs;
790    SubExprs[RHS] = rhs;
791  }
792
793  Expr *getCond() const { return SubExprs[COND]; }
794  Expr *getLHS() const { return SubExprs[LHS]; }
795  Expr *getRHS() const { return SubExprs[RHS]; }
796
797  virtual SourceRange getSourceRange() const {
798    return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
799  }
800  static bool classof(const Stmt *T) {
801    return T->getStmtClass() == ConditionalOperatorClass;
802  }
803  static bool classof(const ConditionalOperator *) { return true; }
804
805  // Iterators
806  virtual child_iterator child_begin();
807  virtual child_iterator child_end();
808};
809
810/// AddrLabelExpr - The GNU address of label extension, representing &&label.
811class AddrLabelExpr : public Expr {
812  SourceLocation AmpAmpLoc, LabelLoc;
813  LabelStmt *Label;
814public:
815  AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L,
816                QualType t)
817    : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {}
818
819  virtual SourceRange getSourceRange() const {
820    return SourceRange(AmpAmpLoc, LabelLoc);
821  }
822
823  LabelStmt *getLabel() const { return Label; }
824
825  static bool classof(const Stmt *T) {
826    return T->getStmtClass() == AddrLabelExprClass;
827  }
828  static bool classof(const AddrLabelExpr *) { return true; }
829
830  // Iterators
831  virtual child_iterator child_begin();
832  virtual child_iterator child_end();
833};
834
835/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
836/// The StmtExpr contains a single CompoundStmt node, which it evaluates and
837/// takes the value of the last subexpression.
838class StmtExpr : public Expr {
839  CompoundStmt *SubStmt;
840  SourceLocation LParenLoc, RParenLoc;
841public:
842  StmtExpr(CompoundStmt *substmt, QualType T,
843           SourceLocation lp, SourceLocation rp) :
844    Expr(StmtExprClass, T), SubStmt(substmt),  LParenLoc(lp), RParenLoc(rp) { }
845
846  CompoundStmt *getSubStmt() { return SubStmt; }
847  const CompoundStmt *getSubStmt() const { return SubStmt; }
848
849  virtual SourceRange getSourceRange() const {
850    return SourceRange(LParenLoc, RParenLoc);
851  }
852
853  static bool classof(const Stmt *T) {
854    return T->getStmtClass() == StmtExprClass;
855  }
856  static bool classof(const StmtExpr *) { return true; }
857
858  // Iterators
859  virtual child_iterator child_begin();
860  virtual child_iterator child_end();
861};
862
863/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p.
864/// This AST node represents a function that returns 1 if two *types* (not
865/// expressions) are compatible. The result of this built-in function can be
866/// used in integer constant expressions.
867class TypesCompatibleExpr : public Expr {
868  QualType Type1;
869  QualType Type2;
870  SourceLocation BuiltinLoc, RParenLoc;
871public:
872  TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc,
873                      QualType t1, QualType t2, SourceLocation RP) :
874    Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2),
875    BuiltinLoc(BLoc), RParenLoc(RP) {}
876
877  QualType getArgType1() const { return Type1; }
878  QualType getArgType2() const { return Type2; }
879
880  int typesAreCompatible() const { return Type::typesAreCompatible(Type1,Type2); }
881
882  virtual SourceRange getSourceRange() const {
883    return SourceRange(BuiltinLoc, RParenLoc);
884  }
885  static bool classof(const Stmt *T) {
886    return T->getStmtClass() == TypesCompatibleExprClass;
887  }
888  static bool classof(const TypesCompatibleExpr *) { return true; }
889
890  // Iterators
891  virtual child_iterator child_begin();
892  virtual child_iterator child_end();
893};
894
895/// ChooseExpr - GNU builtin-in function __builtin_choose_expr.
896/// This AST node is similar to the conditional operator (?:) in C, with
897/// the following exceptions:
898/// - the test expression much be a constant expression.
899/// - the expression returned has it's type unaltered by promotion rules.
900/// - does not evaluate the expression that was not chosen.
901class ChooseExpr : public Expr {
902  enum { COND, LHS, RHS, END_EXPR };
903  Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
904  SourceLocation BuiltinLoc, RParenLoc;
905public:
906  ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t,
907             SourceLocation RP)
908    : Expr(ChooseExprClass, t),
909      BuiltinLoc(BLoc), RParenLoc(RP) {
910      SubExprs[COND] = cond;
911      SubExprs[LHS] = lhs;
912      SubExprs[RHS] = rhs;
913    }
914
915  Expr *getCond() const { return SubExprs[COND]; }
916  Expr *getLHS() const { return SubExprs[LHS]; }
917  Expr *getRHS() const { return SubExprs[RHS]; }
918
919  virtual SourceRange getSourceRange() const {
920    return SourceRange(BuiltinLoc, RParenLoc);
921  }
922  static bool classof(const Stmt *T) {
923    return T->getStmtClass() == ChooseExprClass;
924  }
925  static bool classof(const ChooseExpr *) { return true; }
926
927  // Iterators
928  virtual child_iterator child_begin();
929  virtual child_iterator child_end();
930};
931
932/// ObjCStringLiteral, used for Objective-C string literals
933/// i.e. @"foo".
934class ObjCStringLiteral : public Expr {
935  StringLiteral *String;
936public:
937  ObjCStringLiteral(StringLiteral *SL, QualType T)
938    : Expr(ObjCStringLiteralClass, T), String(SL) {}
939
940  StringLiteral* getString() { return String; }
941
942  const StringLiteral* getString() const { return String; }
943
944  virtual SourceRange getSourceRange() const {
945    return String->getSourceRange();
946  }
947
948  static bool classof(const Stmt *T) {
949    return T->getStmtClass() == ObjCStringLiteralClass;
950  }
951  static bool classof(const ObjCStringLiteral *) { return true; }
952
953  // Iterators
954  virtual child_iterator child_begin();
955  virtual child_iterator child_end();
956};
957
958/// ObjCEncodeExpr, used for @encode in Objective-C.
959class ObjCEncodeExpr : public Expr {
960  QualType EncType;
961  SourceLocation EncLoc, RParenLoc;
962public:
963  ObjCEncodeExpr(QualType T, QualType ET,
964                 SourceLocation enc, SourceLocation rp)
965    : Expr(ObjCEncodeExprClass, T), EncType(ET), EncLoc(enc), RParenLoc(rp) {}
966
967  SourceRange getSourceRange() const { return SourceRange(EncLoc, RParenLoc); }
968
969  QualType getEncodedType() const { return EncType; }
970
971  static bool classof(const Stmt *T) {
972    return T->getStmtClass() == ObjCEncodeExprClass;
973  }
974  static bool classof(const ObjCEncodeExpr *) { return true; }
975
976  // Iterators
977  virtual child_iterator child_begin();
978  virtual child_iterator child_end();
979};
980
981}  // end namespace clang
982
983#endif
984