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