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