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