Expr.h revision c74840329eeee429d9527cf2f3694a74accd1603
1e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes//===--- Expr.h - Classes for representing expressions ----------*- C++ -*-===// 2e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes// 3b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian Paul// The LLVM Compiler Infrastructure 4e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes// 5b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian Paul// This file is distributed under the University of Illinois Open Source 6e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes// License. See LICENSE.TXT for details. 7e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes// 8e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes//===----------------------------------------------------------------------===// 9e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes// 10e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes// This file defines the Expr interface and subclasses. 11e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes// 12e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes//===----------------------------------------------------------------------===// 13e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 14e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#ifndef LLVM_CLANG_AST_EXPR_H 15e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#define LLVM_CLANG_AST_EXPR_H 16e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 17e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "clang/AST/Stmt.h" 18e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "clang/AST/Type.h" 19e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "clang/AST/Decl.h" 20e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "clang/AST/DeclObjC.h" 21e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "clang/Basic/IdentifierTable.h" 22e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "llvm/ADT/APSInt.h" 23e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes#include "llvm/ADT/APFloat.h" 24e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 2505a4b37707d2c598ea68c05d07a3d65bcbf5a076Brian Paulnamespace clang { 26e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes class IdentifierInfo; 27e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes class Selector; 28bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul class Decl; 29bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul class ASTContext; 30bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul 31bbd287103dad776d8a45c87c4e51fbc26d9b80d5Brian Paul/// Expr - This represents one expression. Note that Expr's are subclasses of 32e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// Stmt. This allows an expression to be transparently used any place a Stmt 33e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// is required. 34e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// 35e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesclass Expr : public Stmt { 36e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes QualType TR; 37e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesprotected: 38e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes Expr(StmtClass SC, QualType T) : Stmt(SC), TR(T) {} 39462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihanepublic: 40462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane QualType getType() const { return TR; } 41462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane void setType(QualType t) { TR = t; } 42462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane 43462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane /// SourceLocation tokens are not useful in isolation - they are low level 4481a22ef53953d950052c7bd5a282e96107a25f24Brian Paul /// value objects created/interpreted by SourceManager. We assume AST 45e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// clients will have a pointer to the respective SourceManager. 46e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual SourceRange getSourceRange() const = 0; 47e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 48e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// getExprLoc - Return the preferred location for the arrow when diagnosing 49e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// a problem with a generic expression. 50e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual SourceLocation getExprLoc() const { return getLocStart(); } 51e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 52e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// hasLocalSideEffect - Return true if this immediate expression has side 53e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// effects, not counting any sub-expressions. 544e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul bool hasLocalSideEffect() const; 55e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 56e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or 57e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// incomplete type other than void. Nonarray expressions that can be lvalues: 58e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// - name, where name must be a variable 594e9676fb13f60ecdbc247b120031f18cd3febcb0Brian Paul /// - e[i] 60e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// - (e), where e must be an lvalue 61e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// - e.name, where e must be an lvalue 62e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// - e->name 63e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// - *e, the type of e cannot be a function type 64e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// - string-constant 65e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// - reference type [C++ [expr]] 66e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// 67e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes enum isLvalueResult { 68e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes LV_Valid, 69e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes LV_NotObjectType, 70b4922b533155cc139ebafb111502bb55d2ad2ccfEric Anholt LV_IncompleteVoidType, 71b4922b533155cc139ebafb111502bb55d2ad2ccfEric Anholt LV_DuplicateVectorComponents, 72e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes LV_InvalidExpression 73e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes }; 74e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes isLvalueResult isLvalue() const; 75e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 76e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 77e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// does not have an incomplete type, does not have a const-qualified type, 78e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// and if it is a structure or union, does not have any member (including, 79e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// recursively, any member or element of all contained aggregates or unions) 80e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// with a const-qualified type. 81e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes enum isModifiableLvalueResult { 82e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MLV_Valid, 83e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MLV_NotObjectType, 84e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MLV_IncompleteVoidType, 85e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MLV_DuplicateVectorComponents, 86e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MLV_InvalidExpression, 87e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MLV_IncompleteType, 88e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MLV_ConstQualified, 89e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes MLV_ArrayType 90e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes }; 91b4922b533155cc139ebafb111502bb55d2ad2ccfEric Anholt isModifiableLvalueResult isModifiableLvalue() const; 92b4922b533155cc139ebafb111502bb55d2ad2ccfEric Anholt 93b4922b533155cc139ebafb111502bb55d2ad2ccfEric Anholt bool isNullPointerConstant(ASTContext &Ctx) const; 94b4922b533155cc139ebafb111502bb55d2ad2ccfEric Anholt 95e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// isIntegerConstantExpr - Return true if this expression is a valid integer 96e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// constant expression, and, if so, return its value in Result. If not a 97e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// valid i-c-e, return false and fill in Loc (if specified) with the location 98e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// of the invalid expression. 99e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes bool isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 100e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes SourceLocation *Loc = 0, 101e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes bool isEvaluated = true) const; 102e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const { 103e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes llvm::APSInt X(32); 104e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return isIntegerConstantExpr(X, Ctx, Loc); 105e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 106e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// isConstantExpr - Return true if this expression is a valid constant expr. 107e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const; 108e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 109e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// hasGlobalStorage - Return true if this expression has static storage 110e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// duration. This means that the address of this expression is a link-time 111e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// constant. 112e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes bool hasGlobalStorage() const; 113e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 114e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// IgnoreParens - Ignore parentheses. If this Expr is a ParenExpr, return 115e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// its subexpression. If that subexpression is also a ParenExpr, 116e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// then this method recursively returns its subexpression, and so forth. 117e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// Otherwise, the method returns the current Expr. 118e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes Expr* IgnoreParens(); 119e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 120e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 121e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// or CastExprs or ImplicitCastExprs, returning their operand. 122e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes Expr *IgnoreParenCasts(); 123e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 124e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const Expr* IgnoreParens() const { 125e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return const_cast<Expr*>(this)->IgnoreParens(); 126e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 127e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const Expr *IgnoreParenCasts() const { 128126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul return const_cast<Expr*>(this)->IgnoreParenCasts(); 129126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul } 130e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 131e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const Stmt *T) { 132e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return T->getStmtClass() >= firstExprConstant && 133e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes T->getStmtClass() <= lastExprConstant; 134e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 135e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const Expr *) { return true; } 136e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 137e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static inline Expr* Create(llvm::Deserializer& D) { 138e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return cast<Expr>(Stmt::Create(D)); 139e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 140e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 141e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 142e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes//===----------------------------------------------------------------------===// 143e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes// Primary Expressions. 144e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes//===----------------------------------------------------------------------===// 145126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul 146126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul/// DeclRefExpr - [C99 6.5.1p2] - A reference to a declared variable, function, 147126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul/// enum, etc. 148126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paulclass DeclRefExpr : public Expr { 149e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ValueDecl *D; 150e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes SourceLocation Loc; 151e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughespublic: 152e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes DeclRefExpr(ValueDecl *d, QualType t, SourceLocation l) : 153e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes Expr(DeclRefExprClass, t), D(d), Loc(l) {} 154e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 155e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ValueDecl *getDecl() { return D; } 156e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const ValueDecl *getDecl() const { return D; } 157e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 158e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 159e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 160e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const Stmt *T) { 161e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return T->getStmtClass() == DeclRefExprClass; 162e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 163126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul static bool classof(const DeclRefExpr *) { return true; } 164126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul 165e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // Iterators 166e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_begin(); 167e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_end(); 168e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 169e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual void EmitImpl(llvm::Serializer& S) const; 170e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static DeclRefExpr* CreateImpl(llvm::Deserializer& D); 171e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 172e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 173126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul/// PreDefinedExpr - [C99 6.4.2.2] - A pre-defined identifier such as __func__. 174126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paulclass PreDefinedExpr : public Expr { 175126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paulpublic: 176e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes enum IdentType { 177e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes Func, 178e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes Function, 179e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes PrettyFunction 180e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes }; 181e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 182e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesprivate: 183e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes SourceLocation Loc; 184e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes IdentType Type; 185e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughespublic: 186e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes PreDefinedExpr(SourceLocation l, QualType type, IdentType IT) 187e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes : Expr(PreDefinedExprClass, type), Loc(l), Type(IT) {} 188e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 189e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes IdentType getIdentType() const { return Type; } 190e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 191e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 192e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 193e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const Stmt *T) { 194e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return T->getStmtClass() == PreDefinedExprClass; 195e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 196e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const PreDefinedExpr *) { return true; } 197e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 198e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // Iterators 199e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_begin(); 200e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_end(); 201e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 202e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual void EmitImpl(llvm::Serializer& S) const; 203e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static PreDefinedExpr* CreateImpl(llvm::Deserializer& D); 204e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 205e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 206b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian Paulclass IntegerLiteral : public Expr { 207b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian Paul llvm::APInt Value; 208b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian Paul SourceLocation Loc; 209b8f29f29eb611c92d43aaf8ffcd2d9743b3af967Brian Paulpublic: 210e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy, 211b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul // or UnsignedLongLongTy 212b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul IntegerLiteral(const llvm::APInt &V, QualType type, SourceLocation l) 213b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul : Expr(IntegerLiteralClass, type), Value(V), Loc(l) { 214b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul assert(type->isIntegerType() && "Illegal type in IntegerLiteral"); 215b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul } 216b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul const llvm::APInt &getValue() const { return Value; } 217b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 218b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul 219b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul static bool classof(const Stmt *T) { 220b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul return T->getStmtClass() == IntegerLiteralClass; 221b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul } 222b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul static bool classof(const IntegerLiteral *) { return true; } 223b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul 224b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul // Iterators 225b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul virtual child_iterator child_begin(); 226b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul virtual child_iterator child_end(); 227b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul 228b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul virtual void EmitImpl(llvm::Serializer& S) const; 229e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static IntegerLiteral* CreateImpl(llvm::Deserializer& D); 230e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 231e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 232e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesclass CharacterLiteral : public Expr { 233e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes unsigned Value; 234e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes SourceLocation Loc; 235e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughespublic: 236e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // type should be IntTy 237e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes CharacterLiteral(unsigned value, QualType type, SourceLocation l) 238e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes : Expr(CharacterLiteralClass, type), Value(value), Loc(l) { 239126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul } 240e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes SourceLocation getLoc() const { return Loc; } 241e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 242e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 243e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 244e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes unsigned getValue() const { return Value; } 245e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 246e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const Stmt *T) { 247e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return T->getStmtClass() == CharacterLiteralClass; 248e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 249e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const CharacterLiteral *) { return true; } 250e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 251e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // Iterators 252e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_begin(); 253e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_end(); 254e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 255e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual void EmitImpl(llvm::Serializer& S) const; 256e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static CharacterLiteral* CreateImpl(llvm::Deserializer& D); 257e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 258e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 259e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesclass FloatingLiteral : public Expr { 260e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes llvm::APFloat Value; 261e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes bool IsExact : 1; 262e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes SourceLocation Loc; 263e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughespublic: 264e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes FloatingLiteral(const llvm::APFloat &V, bool* isexact, 265e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes QualType Type, SourceLocation L) 266e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {} 267e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 268e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const llvm::APFloat &getValue() const { return Value; } 269e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 270e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes bool isExact() const { return IsExact; } 271e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 272e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// getValueAsDouble - This returns the value as an inaccurate double. Note 273e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// that this may cause loss of precision, but is useful for debugging dumps 274e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes /// etc. 275e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes double getValueAsDouble() const { 276e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // FIXME: We need something for long double here. 27751faca127005c41277df76bc8eafc8fd64ca0673Brian Paul if (cast<BuiltinType>(getType())->getKind() == BuiltinType::Float) 278e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return Value.convertToFloat(); 279126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul else 280e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return Value.convertToDouble(); 281e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 282e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 283126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 284e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 285e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const Stmt *T) { 286e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return T->getStmtClass() == FloatingLiteralClass; 287126696caf7c2ab66420ab60a2c363613b88bacb4Brian Paul } 288e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const FloatingLiteral *) { return true; } 289e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 290e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // Iterators 291298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg virtual child_iterator child_begin(); 292298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg virtual child_iterator child_end(); 293e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 294e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual void EmitImpl(llvm::Serializer& S) const; 295e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static FloatingLiteral* CreateImpl(llvm::Deserializer& D); 296298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg}; 297298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg 298e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// ImaginaryLiteral - We support imaginary integer and floating point literals, 299e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// like "1.0i". We represent these as a wrapper around FloatingLiteral and 300e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// IntegerLiteral classes. Instances of this class always have a Complex type 301e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// whose element type matches the subexpression. 302b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul/// 303b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paulclass ImaginaryLiteral : public Expr { 304b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul Expr *Val; 305b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paulpublic: 306b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul ImaginaryLiteral(Expr *val, QualType Ty) 307b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul : Expr(ImaginaryLiteralClass, Ty), Val(val) {} 308b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul 309b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul const Expr *getSubExpr() const { return Val; } 310298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg Expr *getSubExpr() { return Val; } 311b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul 312b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } 313b89a731ff297dec597e3a4be1abf94e97d9b0e44Brian Paul static bool classof(const Stmt *T) { 314e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return T->getStmtClass() == ImaginaryLiteralClass; 315e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 316e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const ImaginaryLiteral *) { return true; } 317e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 318e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // Iterators 319e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_begin(); 320e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_end(); 321e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 322e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual void EmitImpl(llvm::Serializer& S) const; 323e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static ImaginaryLiteral* CreateImpl(llvm::Deserializer& D); 324e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 325e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 326e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// StringLiteral - This represents a string literal expression, e.g. "foo" 327298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg/// or L"bar" (wide strings). The actual string is returned by getStrData() 328298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg/// is NOT null-terminated, and the length of the string is determined by 329e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// calling getByteLength(). The C type for a string is always a 330298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg/// ConstantArrayType. 331e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesclass StringLiteral : public Expr { 332e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const char *StrData; 333298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg unsigned ByteLength; 334e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes bool IsWide; 335e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // if the StringLiteral was composed using token pasting, both locations 336298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg // are needed. If not (the common case), firstTokLoc == lastTokLoc. 337e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // FIXME: if space becomes an issue, we should create a sub-class. 338e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes SourceLocation firstTokLoc, lastTokLoc; 339298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsbergpublic: 340e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes StringLiteral(const char *strData, unsigned byteLength, bool Wide, 341e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes QualType t, SourceLocation b, SourceLocation e); 342e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual ~StringLiteral(); 343e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 344e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes const char *getStrData() const { return StrData; } 345e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes unsigned getByteLength() const { return ByteLength; } 346e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes bool isWide() const { return IsWide; } 347e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 348e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual SourceRange getSourceRange() const { 349e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return SourceRange(firstTokLoc,lastTokLoc); 350e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 351e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const Stmt *T) { 352e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return T->getStmtClass() == StringLiteralClass; 353e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 354e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const StringLiteral *) { return true; } 355e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 356e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // Iterators 357e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_begin(); 3589167d04dea5b66e07cb0f133295d56367868e19cBrian Paul virtual child_iterator child_end(); 359e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 360e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual void EmitImpl(llvm::Serializer& S) const; 361e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static StringLiteral* CreateImpl(llvm::Deserializer& D); 362e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes}; 363e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 364e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// ParenExpr - This represents a parethesized expression, e.g. "(1)". This 365298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg/// AST node is only formed if full location information is requested. 366e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesclass ParenExpr : public Expr { 367298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg SourceLocation L, R; 368e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes Expr *Val; 369e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughespublic: 370e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes ParenExpr(SourceLocation l, SourceLocation r, Expr *val) 371e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes : Expr(ParenExprClass, val->getType()), L(l), R(r), Val(val) {} 372e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 373298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg const Expr *getSubExpr() const { return Val; } 374e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes Expr *getSubExpr() { return Val; } 375298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg SourceRange getSourceRange() const { return SourceRange(L, R); } 376e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 377298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg static bool classof(const Stmt *T) { 378e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes return T->getStmtClass() == ParenExprClass; 379e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes } 380e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static bool classof(const ParenExpr *) { return true; } 381e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 382e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // Iterators 383e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_begin(); 384e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual child_iterator child_end(); 385e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 386e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes virtual void EmitImpl(llvm::Serializer& S) const; 387e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes static ParenExpr* CreateImpl(llvm::Deserializer& D); 388298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg}; 389e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes 390ae0cd811892d55bee12afed88fd12bb2611517d3Vinson Lee 391e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// UnaryOperator - This represents the unary-expression's (except sizeof of 392e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// types), the postinc/postdec operators from postfix-expression, and various 393e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// extensions. 394298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg/// 395e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// Notes on various nodes: 396e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// 397e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// Real/Imag - These return the real/imag part of a complex operand. If 398e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// applied to a non-complex value, the former returns its operand and the 399298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg/// later returns zero in the type of the operand. 400e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// 401e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose 402e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// subexpression is a compound literal with the various MemberExpr and 403e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes/// ArraySubscriptExpr's applied to it. 404298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg/// 405e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughesclass UnaryOperator : public Expr { 406e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughespublic: 407e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes // Note that additions to this should also update the StmtVisitor class. 408e7e38a47a8dd567fd5a848cbef09b14018fb2fe0Gareth Hughes enum Opcode { 40981a22ef53953d950052c7bd5a282e96107a25f24Brian Paul PostInc, PostDec, // [C99 6.5.2.4] Postfix increment and decrement operators 410 PreInc, PreDec, // [C99 6.5.3.1] Prefix increment and decrement operators. 411 AddrOf, Deref, // [C99 6.5.3.2] Address and indirection operators. 412 Plus, Minus, // [C99 6.5.3.3] Unary arithmetic operators. 413 Not, LNot, // [C99 6.5.3.3] Unary arithmetic operators. 414 SizeOf, AlignOf, // [C99 6.5.3.4] Sizeof (expr, not type) operator. 415 Real, Imag, // "__real expr"/"__imag expr" Extension. 416 Extension, // __extension__ marker. 417 OffsetOf // __builtin_offsetof 418 }; 419private: 420 Expr *Val; 421 Opcode Opc; 422 SourceLocation Loc; 423public: 424 425 UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l) 426 : Expr(UnaryOperatorClass, type), Val(input), Opc(opc), Loc(l) {} 427 428 Opcode getOpcode() const { return Opc; } 429 Expr *getSubExpr() const { return Val; } 430 431 /// getOperatorLoc - Return the location of the operator. 432 SourceLocation getOperatorLoc() const { return Loc; } 433 434 /// isPostfix - Return true if this is a postfix operation, like x++. 435 static bool isPostfix(Opcode Op); 436 437 bool isPostfix() const { return isPostfix(Opc); } 438 bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; } 439 bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; } 440 bool isSizeOfAlignOfOp() const { return Opc == SizeOf || Opc == AlignOf; } 441 bool isOffsetOfOp() const { return Opc == OffsetOf; } 442 static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; } 443 444 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 445 /// corresponds to, e.g. "sizeof" or "[pre]++" 446 static const char *getOpcodeStr(Opcode Op); 447 448 virtual SourceRange getSourceRange() const { 449 if (isPostfix()) 450 return SourceRange(Val->getLocStart(), Loc); 451 else 452 return SourceRange(Loc, Val->getLocEnd()); 453 } 454 virtual SourceLocation getExprLoc() const { return Loc; } 455 456 static bool classof(const Stmt *T) { 457 return T->getStmtClass() == UnaryOperatorClass; 458 } 459 static bool classof(const UnaryOperator *) { return true; } 460 461 int64_t evaluateOffsetOf(ASTContext& C) const; 462 463 // Iterators 464 virtual child_iterator child_begin(); 465 virtual child_iterator child_end(); 466 467 virtual void EmitImpl(llvm::Serializer& S) const; 468 static UnaryOperator* CreateImpl(llvm::Deserializer& D); 469}; 470 471/// SizeOfAlignOfTypeExpr - [C99 6.5.3.4] - This is only for sizeof/alignof of 472/// *types*. sizeof(expr) is handled by UnaryOperator. 473class SizeOfAlignOfTypeExpr : public Expr { 474 bool isSizeof; // true if sizeof, false if alignof. 475 QualType Ty; 476 SourceLocation OpLoc, RParenLoc; 477public: 478 SizeOfAlignOfTypeExpr(bool issizeof, QualType argType, QualType resultType, 479 SourceLocation op, SourceLocation rp) : 480 Expr(SizeOfAlignOfTypeExprClass, resultType), 481 isSizeof(issizeof), Ty(argType), OpLoc(op), RParenLoc(rp) {} 482 483 bool isSizeOf() const { return isSizeof; } 484 QualType getArgumentType() const { return Ty; } 485 486 SourceLocation getOperatorLoc() const { return OpLoc; } 487 SourceRange getSourceRange() const { return SourceRange(OpLoc, RParenLoc); } 488 489 static bool classof(const Stmt *T) { 490 return T->getStmtClass() == SizeOfAlignOfTypeExprClass; 491 } 492 static bool classof(const SizeOfAlignOfTypeExpr *) { return true; } 493 494 // Iterators 495 virtual child_iterator child_begin(); 496 virtual child_iterator child_end(); 497 498 virtual void EmitImpl(llvm::Serializer& S) const; 499 static SizeOfAlignOfTypeExpr* CreateImpl(llvm::Deserializer& D); 500}; 501 502//===----------------------------------------------------------------------===// 503// Postfix Operators. 504//===----------------------------------------------------------------------===// 505 506/// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting. 507class ArraySubscriptExpr : public Expr { 508 enum { LHS, RHS, END_EXPR=2 }; 509 Expr* SubExprs[END_EXPR]; 510 SourceLocation RBracketLoc; 511public: 512 ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t, 513 SourceLocation rbracketloc) 514 : Expr(ArraySubscriptExprClass, t), RBracketLoc(rbracketloc) { 515 SubExprs[LHS] = lhs; 516 SubExprs[RHS] = rhs; 517 } 518 519 /// An array access can be written A[4] or 4[A] (both are equivalent). 520 /// - getBase() and getIdx() always present the normalized view: A[4]. 521 /// In this case getBase() returns "A" and getIdx() returns "4". 522 /// - getLHS() and getRHS() present the syntactic view. e.g. for 523 /// 4[A] getLHS() returns "4". 524 /// Note: Because vector element access is also written A[4] we must 525 /// predicate the format conversion in getBase and getIdx only on the 526 /// the type of the RHS, as it is possible for the LHS to be a vector of 527 /// integer type 528 Expr *getLHS() { return SubExprs[LHS]; } 529 const Expr *getLHS() const { return SubExprs[LHS]; } 530 531 Expr *getRHS() { return SubExprs[RHS]; } 532 const Expr *getRHS() const { return SubExprs[RHS]; } 533 534 Expr *getBase() { 535 return (getRHS()->getType()->isIntegerType()) ? getLHS() : getRHS(); 536 } 537 538 const Expr *getBase() const { 539 return (getRHS()->getType()->isIntegerType()) ? getLHS() : getRHS(); 540 } 541 542 Expr *getIdx() { 543 return (getRHS()->getType()->isIntegerType()) ? getRHS() : getLHS(); 544 } 545 546 const Expr *getIdx() const { 547 return (getRHS()->getType()->isIntegerType()) ? getRHS() : getLHS(); 548 } 549 550 551 SourceRange getSourceRange() const { 552 return SourceRange(getLHS()->getLocStart(), RBracketLoc); 553 } 554 virtual SourceLocation getExprLoc() const { return RBracketLoc; } 555 556 static bool classof(const Stmt *T) { 557 return T->getStmtClass() == ArraySubscriptExprClass; 558 } 559 static bool classof(const ArraySubscriptExpr *) { return true; } 560 561 // Iterators 562 virtual child_iterator child_begin(); 563 virtual child_iterator child_end(); 564 565 virtual void EmitImpl(llvm::Serializer& S) const; 566 static ArraySubscriptExpr* CreateImpl(llvm::Deserializer& D); 567}; 568 569 570/// CallExpr - [C99 6.5.2.2] Function Calls. 571/// 572class CallExpr : public Expr { 573 enum { FN=0, ARGS_START=1 }; 574 Expr **SubExprs; 575 unsigned NumArgs; 576 SourceLocation RParenLoc; 577 578 // This version of the ctor is for deserialization. 579 CallExpr(Expr** subexprs, unsigned numargs, QualType t, 580 SourceLocation rparenloc) 581 : Expr(CallExprClass,t), SubExprs(subexprs), 582 NumArgs(numargs), RParenLoc(rparenloc) {} 583 584public: 585 CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t, 586 SourceLocation rparenloc); 587 ~CallExpr() { 588 delete [] SubExprs; 589 } 590 591 const Expr *getCallee() const { return SubExprs[FN]; } 592 Expr *getCallee() { return SubExprs[FN]; } 593 void setCallee(Expr *F) { SubExprs[FN] = F; } 594 595 /// getNumArgs - Return the number of actual arguments to this call. 596 /// 597 unsigned getNumArgs() const { return NumArgs; } 598 599 /// getArg - Return the specified argument. 600 Expr *getArg(unsigned Arg) { 601 assert(Arg < NumArgs && "Arg access out of range!"); 602 return SubExprs[Arg+ARGS_START]; 603 } 604 const Expr *getArg(unsigned Arg) const { 605 assert(Arg < NumArgs && "Arg access out of range!"); 606 return SubExprs[Arg+ARGS_START]; 607 } 608 /// setArg - Set the specified argument. 609 void setArg(unsigned Arg, Expr *ArgExpr) { 610 assert(Arg < NumArgs && "Arg access out of range!"); 611 SubExprs[Arg+ARGS_START] = ArgExpr; 612 } 613 614 /// setNumArgs - This changes the number of arguments present in this call. 615 /// Any orphaned expressions are deleted by this, and any new operands are set 616 /// to null. 617 void setNumArgs(unsigned NumArgs); 618 619 typedef Expr **arg_iterator; 620 typedef Expr * const *arg_const_iterator; 621 arg_iterator arg_begin() { return SubExprs+ARGS_START; } 622 arg_iterator arg_end() { return SubExprs+ARGS_START+getNumArgs(); } 623 arg_const_iterator arg_begin() const { return SubExprs+ARGS_START; } 624 arg_const_iterator arg_end() const { return SubExprs+ARGS_START+getNumArgs(); } 625 626 627 /// getNumCommas - Return the number of commas that must have been present in 628 /// this function call. 629 unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; } 630 631 bool isBuiltinClassifyType(llvm::APSInt &Result) const; 632 633 /// isBuiltinConstantExpr - Return true if this built-in call is constant. 634 bool isBuiltinConstantExpr() const; 635 636 SourceLocation getRParenLoc() const { return RParenLoc; } 637 SourceRange getSourceRange() const { 638 return SourceRange(getCallee()->getLocStart(), RParenLoc); 639 } 640 641 static bool classof(const Stmt *T) { 642 return T->getStmtClass() == CallExprClass; 643 } 644 static bool classof(const CallExpr *) { return true; } 645 646 // Iterators 647 virtual child_iterator child_begin(); 648 virtual child_iterator child_end(); 649 650 virtual void EmitImpl(llvm::Serializer& S) const; 651 static CallExpr* CreateImpl(llvm::Deserializer& D); 652}; 653 654/// MemberExpr - [C99 6.5.2.3] Structure and Union Members. 655/// 656class MemberExpr : public Expr { 657 Expr *Base; 658 FieldDecl *MemberDecl; 659 SourceLocation MemberLoc; 660 bool IsArrow; // True if this is "X->F", false if this is "X.F". 661public: 662 MemberExpr(Expr *base, bool isarrow, FieldDecl *memberdecl, SourceLocation l, 663 QualType ty) 664 : Expr(MemberExprClass, ty), 665 Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow) {} 666 667 Expr *getBase() const { return Base; } 668 FieldDecl *getMemberDecl() const { return MemberDecl; } 669 bool isArrow() const { return IsArrow; } 670 671 virtual SourceRange getSourceRange() const { 672 return SourceRange(getBase()->getLocStart(), MemberLoc); 673 } 674 virtual SourceLocation getExprLoc() const { return MemberLoc; } 675 676 static bool classof(const Stmt *T) { 677 return T->getStmtClass() == MemberExprClass; 678 } 679 static bool classof(const MemberExpr *) { return true; } 680 681 // Iterators 682 virtual child_iterator child_begin(); 683 virtual child_iterator child_end(); 684 685 virtual void EmitImpl(llvm::Serializer& S) const; 686 static MemberExpr* CreateImpl(llvm::Deserializer& D); 687}; 688 689/// OCUVectorElementExpr - This represents access to specific elements of a 690/// vector, and may occur on the left hand side or right hand side. For example 691/// the following is legal: "V.xy = V.zw" if V is a 4 element ocu vector. 692/// 693class OCUVectorElementExpr : public Expr { 694 Expr *Base; 695 IdentifierInfo &Accessor; 696 SourceLocation AccessorLoc; 697public: 698 enum ElementType { 699 Point, // xywz 700 Color, // rgba 701 Texture // stpq 702 }; 703 OCUVectorElementExpr(QualType ty, Expr *base, IdentifierInfo &accessor, 704 SourceLocation loc) 705 : Expr(OCUVectorElementExprClass, ty), 706 Base(base), Accessor(accessor), AccessorLoc(loc) {} 707 708 const Expr *getBase() const { return Base; } 709 Expr *getBase() { return Base; } 710 711 IdentifierInfo &getAccessor() const { return Accessor; } 712 713 /// getNumElements - Get the number of components being selected. 714 unsigned getNumElements() const; 715 716 /// getElementType - Determine whether the components of this access are 717 /// "point" "color" or "texture" elements. 718 ElementType getElementType() const; 719 720 /// containsDuplicateElements - Return true if any element access is 721 /// repeated. 722 bool containsDuplicateElements() const; 723 724 /// getEncodedElementAccess - Encode the elements accessed into a bit vector. 725 /// The encoding currently uses 2-bit bitfields, but clients should use the 726 /// accessors below to access them. 727 /// 728 unsigned getEncodedElementAccess() const; 729 730 /// getAccessedFieldNo - Given an encoded value and a result number, return 731 /// the input field number being accessed. 732 static unsigned getAccessedFieldNo(unsigned Idx, unsigned EncodedVal) { 733 return (EncodedVal >> (Idx*2)) & 3; 734 } 735 736 virtual SourceRange getSourceRange() const { 737 return SourceRange(getBase()->getLocStart(), AccessorLoc); 738 } 739 static bool classof(const Stmt *T) { 740 return T->getStmtClass() == OCUVectorElementExprClass; 741 } 742 static bool classof(const OCUVectorElementExpr *) { return true; } 743 744 // Iterators 745 virtual child_iterator child_begin(); 746 virtual child_iterator child_end(); 747}; 748 749/// CompoundLiteralExpr - [C99 6.5.2.5] 750/// 751class CompoundLiteralExpr : public Expr { 752 /// LParenLoc - If non-null, this is the location of the left paren in a 753 /// compound literal like "(int){4}". This can be null if this is a 754 /// synthesized compound expression. 755 SourceLocation LParenLoc; 756 Expr *Init; 757 bool FileScope; 758public: 759 CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init, bool fileScope) : 760 Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init), FileScope(fileScope) {} 761 762 const Expr *getInitializer() const { return Init; } 763 Expr *getInitializer() { return Init; } 764 765 bool isFileScope() const { return FileScope; } 766 767 SourceLocation getLParenLoc() const { return LParenLoc; } 768 769 virtual SourceRange getSourceRange() const { 770 // FIXME: Init should never be null. 771 if (!Init) 772 return SourceRange(); 773 if (LParenLoc.isInvalid()) 774 return Init->getSourceRange(); 775 return SourceRange(LParenLoc, Init->getLocEnd()); 776 } 777 778 static bool classof(const Stmt *T) { 779 return T->getStmtClass() == CompoundLiteralExprClass; 780 } 781 static bool classof(const CompoundLiteralExpr *) { return true; } 782 783 // Iterators 784 virtual child_iterator child_begin(); 785 virtual child_iterator child_end(); 786 787 virtual void EmitImpl(llvm::Serializer& S) const; 788 static CompoundLiteralExpr* CreateImpl(llvm::Deserializer& D); 789}; 790 791/// ImplicitCastExpr - Allows us to explicitly represent implicit type 792/// conversions. For example: converting T[]->T*, void f()->void (*f)(), 793/// float->double, short->int, etc. 794/// 795class ImplicitCastExpr : public Expr { 796 Expr *Op; 797public: 798 ImplicitCastExpr(QualType ty, Expr *op) : 799 Expr(ImplicitCastExprClass, ty), Op(op) {} 800 801 Expr *getSubExpr() { return Op; } 802 const Expr *getSubExpr() const { return Op; } 803 804 virtual SourceRange getSourceRange() const { return Op->getSourceRange(); } 805 806 static bool classof(const Stmt *T) { 807 return T->getStmtClass() == ImplicitCastExprClass; 808 } 809 static bool classof(const ImplicitCastExpr *) { return true; } 810 811 // Iterators 812 virtual child_iterator child_begin(); 813 virtual child_iterator child_end(); 814 815 virtual void EmitImpl(llvm::Serializer& S) const; 816 static ImplicitCastExpr* CreateImpl(llvm::Deserializer& D); 817}; 818 819/// CastExpr - [C99 6.5.4] Cast Operators. 820/// 821class CastExpr : public Expr { 822 Expr *Op; 823 SourceLocation Loc; // the location of the left paren 824public: 825 CastExpr(QualType ty, Expr *op, SourceLocation l) : 826 Expr(CastExprClass, ty), Op(op), Loc(l) {} 827 828 SourceLocation getLParenLoc() const { return Loc; } 829 830 Expr *getSubExpr() const { return Op; } 831 832 virtual SourceRange getSourceRange() const { 833 return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); 834 } 835 static bool classof(const Stmt *T) { 836 return T->getStmtClass() == CastExprClass; 837 } 838 static bool classof(const CastExpr *) { return true; } 839 840 // Iterators 841 virtual child_iterator child_begin(); 842 virtual child_iterator child_end(); 843 844 virtual void EmitImpl(llvm::Serializer& S) const; 845 static CastExpr* CreateImpl(llvm::Deserializer& D); 846}; 847 848class BinaryOperator : public Expr { 849public: 850 enum Opcode { 851 // Operators listed in order of precedence. 852 // Note that additions to this should also update the StmtVisitor class. 853 Mul, Div, Rem, // [C99 6.5.5] Multiplicative operators. 854 Add, Sub, // [C99 6.5.6] Additive operators. 855 Shl, Shr, // [C99 6.5.7] Bitwise shift operators. 856 LT, GT, LE, GE, // [C99 6.5.8] Relational operators. 857 EQ, NE, // [C99 6.5.9] Equality operators. 858 And, // [C99 6.5.10] Bitwise AND operator. 859 Xor, // [C99 6.5.11] Bitwise XOR operator. 860 Or, // [C99 6.5.12] Bitwise OR operator. 861 LAnd, // [C99 6.5.13] Logical AND operator. 862 LOr, // [C99 6.5.14] Logical OR operator. 863 Assign, MulAssign,// [C99 6.5.16] Assignment operators. 864 DivAssign, RemAssign, 865 AddAssign, SubAssign, 866 ShlAssign, ShrAssign, 867 AndAssign, XorAssign, 868 OrAssign, 869 Comma // [C99 6.5.17] Comma operator. 870 }; 871private: 872 enum { LHS, RHS, END_EXPR }; 873 Expr* SubExprs[END_EXPR]; 874 Opcode Opc; 875 SourceLocation OpLoc; 876public: 877 878 BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 879 SourceLocation opLoc) 880 : Expr(BinaryOperatorClass, ResTy), Opc(opc), OpLoc(opLoc) { 881 SubExprs[LHS] = lhs; 882 SubExprs[RHS] = rhs; 883 assert(!isCompoundAssignmentOp() && 884 "Use ArithAssignBinaryOperator for compound assignments"); 885 } 886 887 SourceLocation getOperatorLoc() const { return OpLoc; } 888 Opcode getOpcode() const { return Opc; } 889 Expr *getLHS() const { return SubExprs[LHS]; } 890 Expr *getRHS() const { return SubExprs[RHS]; } 891 virtual SourceRange getSourceRange() const { 892 return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); 893 } 894 895 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 896 /// corresponds to, e.g. "<<=". 897 static const char *getOpcodeStr(Opcode Op); 898 899 /// predicates to categorize the respective opcodes. 900 bool isMultiplicativeOp() const { return Opc >= Mul && Opc <= Rem; } 901 bool isAdditiveOp() const { return Opc == Add || Opc == Sub; } 902 bool isShiftOp() const { return Opc == Shl || Opc == Shr; } 903 bool isBitwiseOp() const { return Opc >= And && Opc <= Or; } 904 bool isRelationalOp() const { return Opc >= LT && Opc <= GE; } 905 bool isEqualityOp() const { return Opc == EQ || Opc == NE; } 906 bool isLogicalOp() const { return Opc == LAnd || Opc == LOr; } 907 bool isAssignmentOp() const { return Opc >= Assign && Opc <= OrAssign; } 908 bool isCompoundAssignmentOp() const { return Opc > Assign && Opc <= OrAssign;} 909 bool isShiftAssignOp() const { return Opc == ShlAssign || Opc == ShrAssign; } 910 911 static bool classof(const Stmt *S) { 912 return S->getStmtClass() == BinaryOperatorClass || 913 S->getStmtClass() == CompoundAssignOperatorClass; 914 } 915 static bool classof(const BinaryOperator *) { return true; } 916 917 // Iterators 918 virtual child_iterator child_begin(); 919 virtual child_iterator child_end(); 920 921 virtual void EmitImpl(llvm::Serializer& S) const; 922 static BinaryOperator* CreateImpl(llvm::Deserializer& D); 923 924protected: 925 BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, 926 SourceLocation oploc, bool dead) 927 : Expr(CompoundAssignOperatorClass, ResTy), Opc(opc), OpLoc(oploc) { 928 SubExprs[LHS] = lhs; 929 SubExprs[RHS] = rhs; 930 } 931}; 932 933/// CompoundAssignOperator - For compound assignments (e.g. +=), we keep 934/// track of the type the operation is performed in. Due to the semantics of 935/// these operators, the operands are promoted, the aritmetic performed, an 936/// implicit conversion back to the result type done, then the assignment takes 937/// place. This captures the intermediate type which the computation is done 938/// in. 939class CompoundAssignOperator : public BinaryOperator { 940 QualType ComputationType; 941public: 942 CompoundAssignOperator(Expr *lhs, Expr *rhs, Opcode opc, 943 QualType ResType, QualType CompType, 944 SourceLocation OpLoc) 945 : BinaryOperator(lhs, rhs, opc, ResType, OpLoc, true), 946 ComputationType(CompType) { 947 assert(isCompoundAssignmentOp() && 948 "Only should be used for compound assignments"); 949 } 950 951 QualType getComputationType() const { return ComputationType; } 952 953 static bool classof(const CompoundAssignOperator *) { return true; } 954 static bool classof(const Stmt *S) { 955 return S->getStmtClass() == CompoundAssignOperatorClass; 956 } 957 958 virtual void EmitImpl(llvm::Serializer& S) const; 959 static CompoundAssignOperator* CreateImpl(llvm::Deserializer& D); 960}; 961 962/// ConditionalOperator - The ?: operator. Note that LHS may be null when the 963/// GNU "missing LHS" extension is in use. 964/// 965class ConditionalOperator : public Expr { 966 enum { COND, LHS, RHS, END_EXPR }; 967 Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 968public: 969 ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t) 970 : Expr(ConditionalOperatorClass, t) { 971 SubExprs[COND] = cond; 972 SubExprs[LHS] = lhs; 973 SubExprs[RHS] = rhs; 974 } 975 976 // getCond - Return the expression representing the condition for 977 // the ?: operator. 978 Expr *getCond() const { return SubExprs[COND]; } 979 980 // getTrueExpr - Return the subexpression representing the value of the ?: 981 // expression if the condition evaluates to true. In most cases this value 982 // will be the same as getLHS() except a GCC extension allows the left 983 // subexpression to be omitted, and instead of the condition be returned. 984 // e.g: x ?: y is shorthand for x ? x : y, except that the expression "x" 985 // is only evaluated once. 986 Expr *getTrueExpr() const { 987 return SubExprs[LHS] ? SubExprs[COND] : SubExprs[LHS]; 988 } 989 990 // getTrueExpr - Return the subexpression representing the value of the ?: 991 // expression if the condition evaluates to false. This is the same as getRHS. 992 Expr *getFalseExpr() const { return SubExprs[RHS]; } 993 994 Expr *getLHS() const { return SubExprs[LHS]; } 995 Expr *getRHS() const { return SubExprs[RHS]; } 996 997 virtual SourceRange getSourceRange() const { 998 return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); 999 } 1000 static bool classof(const Stmt *T) { 1001 return T->getStmtClass() == ConditionalOperatorClass; 1002 } 1003 static bool classof(const ConditionalOperator *) { return true; } 1004 1005 // Iterators 1006 virtual child_iterator child_begin(); 1007 virtual child_iterator child_end(); 1008 1009 virtual void EmitImpl(llvm::Serializer& S) const; 1010 static ConditionalOperator* CreateImpl(llvm::Deserializer& D); 1011}; 1012 1013/// AddrLabelExpr - The GNU address of label extension, representing &&label. 1014class AddrLabelExpr : public Expr { 1015 SourceLocation AmpAmpLoc, LabelLoc; 1016 LabelStmt *Label; 1017public: 1018 AddrLabelExpr(SourceLocation AALoc, SourceLocation LLoc, LabelStmt *L, 1019 QualType t) 1020 : Expr(AddrLabelExprClass, t), AmpAmpLoc(AALoc), LabelLoc(LLoc), Label(L) {} 1021 1022 virtual SourceRange getSourceRange() const { 1023 return SourceRange(AmpAmpLoc, LabelLoc); 1024 } 1025 1026 LabelStmt *getLabel() const { return Label; } 1027 1028 static bool classof(const Stmt *T) { 1029 return T->getStmtClass() == AddrLabelExprClass; 1030 } 1031 static bool classof(const AddrLabelExpr *) { return true; } 1032 1033 // Iterators 1034 virtual child_iterator child_begin(); 1035 virtual child_iterator child_end(); 1036 1037 virtual void EmitImpl(llvm::Serializer& S) const; 1038 static AddrLabelExpr* CreateImpl(llvm::Deserializer& D); 1039}; 1040 1041/// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). 1042/// The StmtExpr contains a single CompoundStmt node, which it evaluates and 1043/// takes the value of the last subexpression. 1044class StmtExpr : public Expr { 1045 CompoundStmt *SubStmt; 1046 SourceLocation LParenLoc, RParenLoc; 1047public: 1048 StmtExpr(CompoundStmt *substmt, QualType T, 1049 SourceLocation lp, SourceLocation rp) : 1050 Expr(StmtExprClass, T), SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { } 1051 1052 CompoundStmt *getSubStmt() { return SubStmt; } 1053 const CompoundStmt *getSubStmt() const { return SubStmt; } 1054 1055 virtual SourceRange getSourceRange() const { 1056 return SourceRange(LParenLoc, RParenLoc); 1057 } 1058 1059 static bool classof(const Stmt *T) { 1060 return T->getStmtClass() == StmtExprClass; 1061 } 1062 static bool classof(const StmtExpr *) { return true; } 1063 1064 // Iterators 1065 virtual child_iterator child_begin(); 1066 virtual child_iterator child_end(); 1067 1068 virtual void EmitImpl(llvm::Serializer& S) const; 1069 static StmtExpr* CreateImpl(llvm::Deserializer& D); 1070}; 1071 1072/// TypesCompatibleExpr - GNU builtin-in function __builtin_type_compatible_p. 1073/// This AST node represents a function that returns 1 if two *types* (not 1074/// expressions) are compatible. The result of this built-in function can be 1075/// used in integer constant expressions. 1076class TypesCompatibleExpr : public Expr { 1077 QualType Type1; 1078 QualType Type2; 1079 SourceLocation BuiltinLoc, RParenLoc; 1080public: 1081 TypesCompatibleExpr(QualType ReturnType, SourceLocation BLoc, 1082 QualType t1, QualType t2, SourceLocation RP) : 1083 Expr(TypesCompatibleExprClass, ReturnType), Type1(t1), Type2(t2), 1084 BuiltinLoc(BLoc), RParenLoc(RP) {} 1085 1086 QualType getArgType1() const { return Type1; } 1087 QualType getArgType2() const { return Type2; } 1088 1089 virtual SourceRange getSourceRange() const { 1090 return SourceRange(BuiltinLoc, RParenLoc); 1091 } 1092 static bool classof(const Stmt *T) { 1093 return T->getStmtClass() == TypesCompatibleExprClass; 1094 } 1095 static bool classof(const TypesCompatibleExpr *) { return true; } 1096 1097 // Iterators 1098 virtual child_iterator child_begin(); 1099 virtual child_iterator child_end(); 1100}; 1101 1102/// ChooseExpr - GNU builtin-in function __builtin_choose_expr. 1103/// This AST node is similar to the conditional operator (?:) in C, with 1104/// the following exceptions: 1105/// - the test expression much be a constant expression. 1106/// - the expression returned has it's type unaltered by promotion rules. 1107/// - does not evaluate the expression that was not chosen. 1108class ChooseExpr : public Expr { 1109 enum { COND, LHS, RHS, END_EXPR }; 1110 Expr* SubExprs[END_EXPR]; // Left/Middle/Right hand sides. 1111 SourceLocation BuiltinLoc, RParenLoc; 1112public: 1113 ChooseExpr(SourceLocation BLoc, Expr *cond, Expr *lhs, Expr *rhs, QualType t, 1114 SourceLocation RP) 1115 : Expr(ChooseExprClass, t), 1116 BuiltinLoc(BLoc), RParenLoc(RP) { 1117 SubExprs[COND] = cond; 1118 SubExprs[LHS] = lhs; 1119 SubExprs[RHS] = rhs; 1120 } 1121 1122 /// isConditionTrue - Return true if the condition is true. This is always 1123 /// statically knowable for a well-formed choosexpr. 1124 bool isConditionTrue(ASTContext &C) const; 1125 1126 Expr *getCond() const { return SubExprs[COND]; } 1127 Expr *getLHS() const { return SubExprs[LHS]; } 1128 Expr *getRHS() const { return SubExprs[RHS]; } 1129 1130 virtual SourceRange getSourceRange() const { 1131 return SourceRange(BuiltinLoc, RParenLoc); 1132 } 1133 static bool classof(const Stmt *T) { 1134 return T->getStmtClass() == ChooseExprClass; 1135 } 1136 static bool classof(const ChooseExpr *) { return true; } 1137 1138 // Iterators 1139 virtual child_iterator child_begin(); 1140 virtual child_iterator child_end(); 1141}; 1142 1143/// OverloadExpr - Clang builtin function __builtin_overload. 1144/// This AST node provides a way to overload functions in C. 1145/// 1146/// The first argument is required to be a constant expression, for the number 1147/// of arguments passed to each candidate function. 1148/// 1149/// The next N arguments, where N is the value of the constant expression, 1150/// are the values to be passed as arguments. 1151/// 1152/// The rest of the arguments are values of pointer to function type, which 1153/// are the candidate functions for overloading. 1154/// 1155/// The result is a equivalent to a CallExpr taking N arguments to the 1156/// candidate function whose parameter types match the types of the N arguments. 1157/// 1158/// example: float Z = __builtin_overload(2, X, Y, modf, mod, modl); 1159/// If X and Y are long doubles, Z will assigned the result of modl(X, Y); 1160/// If X and Y are floats, Z will be assigned the result of modf(X, Y); 1161class OverloadExpr : public Expr { 1162 // SubExprs - the list of values passed to the __builtin_overload function. 1163 // SubExpr[0] is a constant expression 1164 // SubExpr[1-N] are the parameters to pass to the matching function call 1165 // SubExpr[N-...] are the candidate functions, of type pointer to function. 1166 Expr **SubExprs; 1167 1168 // NumExprs - the size of the SubExprs array 1169 unsigned NumExprs; 1170 1171 // The index of the matching candidate function 1172 unsigned FnIndex; 1173 1174 SourceLocation BuiltinLoc; 1175 SourceLocation RParenLoc; 1176public: 1177 OverloadExpr(Expr **args, unsigned nexprs, unsigned idx, QualType t, 1178 SourceLocation bloc, SourceLocation rploc) 1179 : Expr(OverloadExprClass, t), NumExprs(nexprs), FnIndex(idx), 1180 BuiltinLoc(bloc), RParenLoc(rploc) { 1181 SubExprs = new Expr*[nexprs]; 1182 for (unsigned i = 0; i != nexprs; ++i) 1183 SubExprs[i] = args[i]; 1184 } 1185 ~OverloadExpr() { 1186 delete [] SubExprs; 1187 } 1188 1189 /// arg_begin - Return a pointer to the list of arguments that will be passed 1190 /// to the matching candidate function, skipping over the initial constant 1191 /// expression. 1192 typedef Expr * const *arg_const_iterator; 1193 arg_const_iterator arg_begin() const { return SubExprs+1; } 1194 1195 /// getNumArgs - Return the number of arguments to pass to the candidate 1196 /// functions. 1197 unsigned getNumArgs(ASTContext &Ctx) const { 1198 llvm::APSInt constEval(32); 1199 (void) SubExprs[0]->isIntegerConstantExpr(constEval, Ctx); 1200 return constEval.getZExtValue(); 1201 } 1202 1203 /// getNumSubExprs - Return the size of the SubExprs array. This includes the 1204 /// constant expression, the actual arguments passed in, and the function 1205 /// pointers. 1206 unsigned getNumSubExprs() const { return NumExprs; } 1207 1208 /// getExpr - Return the Expr at the specified index. 1209 Expr *getExpr(unsigned Index) { 1210 assert((Index < NumExprs) && "Arg access out of range!"); 1211 return SubExprs[Index]; 1212 } 1213 1214 /// getFn - Return the matching candidate function for this OverloadExpr. 1215 Expr *getFn() const { return SubExprs[FnIndex]; } 1216 1217 virtual SourceRange getSourceRange() const { 1218 return SourceRange(BuiltinLoc, RParenLoc); 1219 } 1220 static bool classof(const Stmt *T) { 1221 return T->getStmtClass() == OverloadExprClass; 1222 } 1223 static bool classof(const OverloadExpr *) { return true; } 1224 1225 // Iterators 1226 virtual child_iterator child_begin(); 1227 virtual child_iterator child_end(); 1228}; 1229 1230/// VAArgExpr, used for the builtin function __builtin_va_start. 1231class VAArgExpr : public Expr { 1232 Expr *Val; 1233 SourceLocation BuiltinLoc, RParenLoc; 1234public: 1235 VAArgExpr(SourceLocation BLoc, Expr* e, QualType t, SourceLocation RPLoc) 1236 : Expr(VAArgExprClass, t), 1237 Val(e), 1238 BuiltinLoc(BLoc), 1239 RParenLoc(RPLoc) { } 1240 1241 const Expr *getSubExpr() const { return Val; } 1242 Expr *getSubExpr() { return Val; } 1243 virtual SourceRange getSourceRange() const { 1244 return SourceRange(BuiltinLoc, RParenLoc); 1245 } 1246 static bool classof(const Stmt *T) { 1247 return T->getStmtClass() == VAArgExprClass; 1248 } 1249 static bool classof(const VAArgExpr *) { return true; } 1250 1251 // Iterators 1252 virtual child_iterator child_begin(); 1253 virtual child_iterator child_end(); 1254}; 1255 1256/// InitListExpr - used for struct and array initializers, such as: 1257/// struct foo x = { 1, { 2, 3 } }; 1258/// 1259/// Because C is somewhat loose with braces, the AST does not necessarily 1260/// directly model the C source. Instead, the semantic analyzer aims to make 1261/// the InitListExprs match up with the type of the decl being initialized. We 1262/// have the following exceptions: 1263/// 1264/// 1. Elements at the end of the list may be dropped from the initializer. 1265/// These elements are defined to be initialized to zero. For example: 1266/// int x[20] = { 1 }; 1267/// 2. Initializers may have excess initializers which are to be ignored by the 1268/// compiler. For example: 1269/// int x[1] = { 1, 2 }; 1270/// 3. Redundant InitListExprs may be present around scalar elements. These 1271/// always have a single element whose type is the same as the InitListExpr. 1272/// this can only happen for Type::isScalarType() types. 1273/// int x = { 1 }; int y[2] = { {1}, {2} }; 1274/// 1275class InitListExpr : public Expr { 1276 Expr **InitExprs; 1277 unsigned NumInits; 1278 SourceLocation LBraceLoc, RBraceLoc; 1279public: 1280 InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits, 1281 SourceLocation rbraceloc); 1282 ~InitListExpr() { 1283 delete [] InitExprs; 1284 } 1285 1286 unsigned getNumInits() const { return NumInits; } 1287 1288 const Expr* getInit(unsigned Init) const { 1289 assert(Init < NumInits && "Initializer access out of range!"); 1290 return InitExprs[Init]; 1291 } 1292 1293 Expr* getInit(unsigned Init) { 1294 assert(Init < NumInits && "Initializer access out of range!"); 1295 return InitExprs[Init]; 1296 } 1297 1298 void setInit(unsigned Init, Expr *expr) { 1299 assert(Init < NumInits && "Initializer access out of range!"); 1300 InitExprs[Init] = expr; 1301 } 1302 1303 virtual SourceRange getSourceRange() const { 1304 return SourceRange(LBraceLoc, RBraceLoc); 1305 } 1306 static bool classof(const Stmt *T) { 1307 return T->getStmtClass() == InitListExprClass; 1308 } 1309 static bool classof(const InitListExpr *) { return true; } 1310 1311 // Iterators 1312 virtual child_iterator child_begin(); 1313 virtual child_iterator child_end(); 1314 1315 virtual void EmitImpl(llvm::Serializer& S) const; 1316 static InitListExpr* CreateImpl(llvm::Deserializer& D); 1317 1318private: 1319 // Used by serializer. 1320 InitListExpr() : Expr(InitListExprClass, QualType()), 1321 InitExprs(NULL), NumInits(0) {} 1322}; 1323 1324/// ObjCStringLiteral, used for Objective-C string literals 1325/// i.e. @"foo". 1326class ObjCStringLiteral : public Expr { 1327 StringLiteral *String; 1328 SourceLocation AtLoc; 1329public: 1330 ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L) 1331 : Expr(ObjCStringLiteralClass, T), String(SL), AtLoc(L) {} 1332 1333 StringLiteral* getString() { return String; } 1334 1335 const StringLiteral* getString() const { return String; } 1336 1337 SourceLocation getAtLoc() const { return AtLoc; } 1338 1339 virtual SourceRange getSourceRange() const { 1340 return SourceRange(AtLoc, String->getLocEnd()); 1341 } 1342 1343 static bool classof(const Stmt *T) { 1344 return T->getStmtClass() == ObjCStringLiteralClass; 1345 } 1346 static bool classof(const ObjCStringLiteral *) { return true; } 1347 1348 // Iterators 1349 virtual child_iterator child_begin(); 1350 virtual child_iterator child_end(); 1351 1352 virtual void EmitImpl(llvm::Serializer& S) const; 1353 static ObjCStringLiteral* CreateImpl(llvm::Deserializer& D); 1354}; 1355 1356/// ObjCEncodeExpr, used for @encode in Objective-C. 1357class ObjCEncodeExpr : public Expr { 1358 QualType EncType; 1359 SourceLocation AtLoc, RParenLoc; 1360public: 1361 ObjCEncodeExpr(QualType T, QualType ET, 1362 SourceLocation at, SourceLocation rp) 1363 : Expr(ObjCEncodeExprClass, T), EncType(ET), AtLoc(at), RParenLoc(rp) {} 1364 1365 SourceLocation getAtLoc() const { return AtLoc; } 1366 SourceLocation getRParenLoc() const { return RParenLoc; } 1367 1368 SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); } 1369 1370 QualType getEncodedType() const { return EncType; } 1371 1372 static bool classof(const Stmt *T) { 1373 return T->getStmtClass() == ObjCEncodeExprClass; 1374 } 1375 static bool classof(const ObjCEncodeExpr *) { return true; } 1376 1377 // Iterators 1378 virtual child_iterator child_begin(); 1379 virtual child_iterator child_end(); 1380 1381 virtual void EmitImpl(llvm::Serializer& S) const; 1382 static ObjCEncodeExpr* CreateImpl(llvm::Deserializer& D); 1383}; 1384 1385/// ObjCSelectorExpr used for @selector in Objective-C. 1386class ObjCSelectorExpr : public Expr { 1387 Selector SelName; 1388 SourceLocation AtLoc, RParenLoc; 1389public: 1390 ObjCSelectorExpr(QualType T, Selector selInfo, 1391 SourceLocation at, SourceLocation rp) 1392 : Expr(ObjCSelectorExprClass, T), SelName(selInfo), 1393 AtLoc(at), RParenLoc(rp) {} 1394 1395 const Selector &getSelector() const { return SelName; } 1396 Selector &getSelector() { return SelName; } 1397 1398 SourceLocation getAtLoc() const { return AtLoc; } 1399 SourceLocation getRParenLoc() const { return RParenLoc; } 1400 SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); } 1401 1402 /// getNumArgs - Return the number of actual arguments to this call. 1403 unsigned getNumArgs() const { return SelName.getNumArgs(); } 1404 1405 static bool classof(const Stmt *T) { 1406 return T->getStmtClass() == ObjCSelectorExprClass; 1407 } 1408 static bool classof(const ObjCSelectorExpr *) { return true; } 1409 1410 // Iterators 1411 virtual child_iterator child_begin(); 1412 virtual child_iterator child_end(); 1413 1414 virtual void EmitImpl(llvm::Serializer& S) const; 1415 static ObjCSelectorExpr* CreateImpl(llvm::Deserializer& D); 1416}; 1417 1418/// ObjCProtocolExpr used for protocol in Objective-C. 1419class ObjCProtocolExpr : public Expr { 1420 ObjCProtocolDecl *Protocol; 1421 SourceLocation AtLoc, RParenLoc; 1422public: 1423 ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol, 1424 SourceLocation at, SourceLocation rp) 1425 : Expr(ObjCProtocolExprClass, T), Protocol(protocol), 1426 AtLoc(at), RParenLoc(rp) {} 1427 1428 ObjCProtocolDecl *getProtocol() const { return Protocol; } 1429 1430 SourceLocation getAtLoc() const { return AtLoc; } 1431 SourceLocation getRParenLoc() const { return RParenLoc; } 1432 SourceRange getSourceRange() const { return SourceRange(AtLoc, RParenLoc); } 1433 1434 static bool classof(const Stmt *T) { 1435 return T->getStmtClass() == ObjCProtocolExprClass; 1436 } 1437 static bool classof(const ObjCProtocolExpr *) { return true; } 1438 1439 // Iterators 1440 virtual child_iterator child_begin(); 1441 virtual child_iterator child_end(); 1442}; 1443 1444/// ObjCIvarRefExpr - A reference to an ObjC instance variable. 1445class ObjCIvarRefExpr : public Expr { 1446 class ObjCIvarDecl *D; 1447 SourceLocation Loc; 1448 Expr *Base; 1449 bool IsArrow:1; // True if this is "X->F", false if this is "X.F". 1450 bool IsFreeIvar:1; // True if ivar reference has no base (self assumed). 1451 1452public: 1453 ObjCIvarRefExpr(ObjCIvarDecl *d, QualType t, SourceLocation l, Expr *base=0, 1454 bool arrow = false, bool freeIvar = false) : 1455 Expr(ObjCIvarRefExprClass, t), D(d), Loc(l), Base(base), IsArrow(arrow), 1456 IsFreeIvar(freeIvar) {} 1457 1458 ObjCIvarDecl *getDecl() { return D; } 1459 const ObjCIvarDecl *getDecl() const { return D; } 1460 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 1461 Expr *const getBase() const { return Base; } 1462 void setBase(Expr * base) { Base = base; } 1463 const bool isArrow() const { return IsArrow; } 1464 const bool isFreeIvar() const { return IsFreeIvar; } 1465 1466 SourceLocation getLocation() const { return Loc; } 1467 1468 static bool classof(const Stmt *T) { 1469 return T->getStmtClass() == ObjCIvarRefExprClass; 1470 } 1471 static bool classof(const ObjCIvarRefExpr *) { return true; } 1472 1473 // Iterators 1474 virtual child_iterator child_begin(); 1475 virtual child_iterator child_end(); 1476 1477 virtual void EmitImpl(llvm::Serializer& S) const; 1478 static ObjCIvarRefExpr* CreateImpl(llvm::Deserializer& D); 1479}; 1480 1481class ObjCMessageExpr : public Expr { 1482 enum { RECEIVER=0, ARGS_START=1 }; 1483 1484 Expr **SubExprs; 1485 1486 unsigned NumArgs; 1487 1488 // A unigue name for this message. 1489 Selector SelName; 1490 1491 // A method prototype for this message (optional). 1492 // FIXME: Since method decls contain the selector, and most messages have a 1493 // prototype, consider devising a scheme for unifying SelName/MethodProto. 1494 ObjCMethodDecl *MethodProto; 1495 1496 IdentifierInfo *ClassName; // optional - 0 for instance messages. 1497 1498 SourceLocation LBracloc, RBracloc; 1499public: 1500 // constructor for class messages. 1501 // FIXME: clsName should be typed to ObjCInterfaceType 1502 ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo, 1503 QualType retType, ObjCMethodDecl *methDecl, 1504 SourceLocation LBrac, SourceLocation RBrac, 1505 Expr **ArgExprs, unsigned NumArgs); 1506 // constructor for instance messages. 1507 ObjCMessageExpr(Expr *receiver, Selector selInfo, 1508 QualType retType, ObjCMethodDecl *methDecl, 1509 SourceLocation LBrac, SourceLocation RBrac, 1510 Expr **ArgExprs, unsigned NumArgs); 1511 ~ObjCMessageExpr() { 1512 delete [] SubExprs; 1513 } 1514 1515 const Expr *getReceiver() const { return SubExprs[RECEIVER]; } 1516 Expr *getReceiver() { return SubExprs[RECEIVER]; } 1517 1518 Selector getSelector() const { return SelName; } 1519 Selector &getSelector() { return SelName; } 1520 1521 const ObjCMethodDecl *getMethodDecl() const { return MethodProto; } 1522 ObjCMethodDecl *getMethodDecl() { return MethodProto; } 1523 1524 const IdentifierInfo *getClassName() const { return ClassName; } 1525 IdentifierInfo *getClassName() { return ClassName; } 1526 1527 /// getNumArgs - Return the number of actual arguments to this call. 1528 unsigned getNumArgs() const { return NumArgs; } 1529 1530/// getArg - Return the specified argument. 1531 Expr *getArg(unsigned Arg) { 1532 assert(Arg < NumArgs && "Arg access out of range!"); 1533 return SubExprs[Arg+ARGS_START]; 1534 } 1535 const Expr *getArg(unsigned Arg) const { 1536 assert(Arg < NumArgs && "Arg access out of range!"); 1537 return SubExprs[Arg+ARGS_START]; 1538 } 1539 /// setArg - Set the specified argument. 1540 void setArg(unsigned Arg, Expr *ArgExpr) { 1541 assert(Arg < NumArgs && "Arg access out of range!"); 1542 SubExprs[Arg+ARGS_START] = ArgExpr; 1543 } 1544 SourceRange getSourceRange() const { return SourceRange(LBracloc, RBracloc); } 1545 1546 static bool classof(const Stmt *T) { 1547 return T->getStmtClass() == ObjCMessageExprClass; 1548 } 1549 static bool classof(const ObjCMessageExpr *) { return true; } 1550 1551 // Iterators 1552 virtual child_iterator child_begin(); 1553 virtual child_iterator child_end(); 1554 1555 typedef Expr** arg_iterator; 1556 typedef const Expr* const* const_arg_iterator; 1557 1558 arg_iterator arg_begin() { return &SubExprs[ARGS_START]; } 1559 arg_iterator arg_end() { return arg_begin() + NumArgs; } 1560 const_arg_iterator arg_begin() const { return &SubExprs[ARGS_START]; } 1561 const_arg_iterator arg_end() const { return arg_begin() + NumArgs; } 1562}; 1563 1564} // end namespace clang 1565 1566#endif 1567