ExprCXX.h revision 1a49af9681c350fef58e677f85ccb9a77e8e9d0a
1//===--- ExprCXX.h - Classes for representing expressions -------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Expr interface and subclasses for C++ expressions. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_EXPRCXX_H 15#define LLVM_CLANG_AST_EXPRCXX_H 16 17#include "clang/Basic/TypeTraits.h" 18#include "clang/AST/Expr.h" 19#include "clang/AST/Decl.h" 20 21namespace clang { 22 23 class CXXConstructorDecl; 24 25//===--------------------------------------------------------------------===// 26// C++ Expressions. 27//===--------------------------------------------------------------------===// 28 29/// CXXOperatorCallExpr - Represents a call to an overloaded operator 30/// written using operator syntax, e.g., "x + y" or "*p". While 31/// semantically equivalent to a normal call, this AST node provides 32/// better information about the syntactic representation of the call. 33class CXXOperatorCallExpr : public CallExpr { 34public: 35 CXXOperatorCallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t, 36 SourceLocation operatorloc) 37 : CallExpr(CXXOperatorCallExprClass, fn, args, numargs, t, operatorloc) { } 38 39 /// getOperator - Returns the kind of overloaded operator that this 40 /// expression refers to. 41 OverloadedOperatorKind getOperator() const; 42 43 /// getOperatorLoc - Returns the location of the operator symbol in 44 /// the expression. When @c getOperator()==OO_Call, this is the 45 /// location of the right parentheses; when @c 46 /// getOperator()==OO_Subscript, this is the location of the right 47 /// bracket. 48 SourceLocation getOperatorLoc() const { return getRParenLoc(); } 49 50 virtual SourceRange getSourceRange() const; 51 52 static bool classof(const Stmt *T) { 53 return T->getStmtClass() == CXXOperatorCallExprClass; 54 } 55 static bool classof(const CXXOperatorCallExpr *) { return true; } 56}; 57 58/// CXXMemberCallExpr - Represents a call to a member function that 59/// may be written either with member call syntax (e.g., "obj.func()" 60/// or "objptr->func()") or with normal function-call syntax 61/// ("func()") within a member function that ends up calling a member 62/// function. The callee in either case is a MemberExpr that contains 63/// both the object argument and the member function, while the 64/// arguments are the arguments within the parentheses (not including 65/// the object argument). 66class CXXMemberCallExpr : public CallExpr { 67public: 68 CXXMemberCallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t, 69 SourceLocation rparenloc) 70 : CallExpr(CXXMemberCallExprClass, fn, args, numargs, t, rparenloc) { } 71 72 /// getImplicitObjectArgument - Retrieves the implicit object 73 /// argument for the member call. For example, in "x.f(5)", this 74 /// operation would return "x". 75 Expr *getImplicitObjectArgument(); 76 77 static bool classof(const Stmt *T) { 78 return T->getStmtClass() == CXXMemberCallExprClass; 79 } 80 static bool classof(const CXXMemberCallExpr *) { return true; } 81}; 82 83/// CXXNamedCastExpr - Abstract class common to all of the C++ "named" 84/// casts, @c static_cast, @c dynamic_cast, @c reinterpret_cast, or @c 85/// const_cast. 86/// 87/// This abstract class is inherited by all of the classes 88/// representing "named" casts, e.g., CXXStaticCastExpr, 89/// CXXDynamicCastExpr, CXXReinterpretCastExpr, and CXXConstCastExpr. 90class CXXNamedCastExpr : public ExplicitCastExpr { 91private: 92 SourceLocation Loc; // the location of the casting op 93 94protected: 95 CXXNamedCastExpr(StmtClass SC, QualType ty, Expr *op, QualType writtenTy, 96 SourceLocation l) 97 : ExplicitCastExpr(SC, ty, op, writtenTy), Loc(l) {} 98 99public: 100 const char *getCastName() const; 101 102 virtual SourceRange getSourceRange() const { 103 return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); 104 } 105 static bool classof(const Stmt *T) { 106 switch (T->getStmtClass()) { 107 case CXXNamedCastExprClass: 108 case CXXStaticCastExprClass: 109 case CXXDynamicCastExprClass: 110 case CXXReinterpretCastExprClass: 111 case CXXConstCastExprClass: 112 return true; 113 default: 114 return false; 115 } 116 } 117 static bool classof(const CXXNamedCastExpr *) { return true; } 118 119 virtual void EmitImpl(llvm::Serializer& S) const; 120 static CXXNamedCastExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C, 121 StmtClass SC); 122}; 123 124/// CXXStaticCastExpr - A C++ @c static_cast expression (C++ [expr.static.cast]). 125/// 126/// This expression node represents a C++ static cast, e.g., 127/// @c static_cast<int>(1.0). 128class CXXStaticCastExpr : public CXXNamedCastExpr { 129public: 130 CXXStaticCastExpr(QualType ty, Expr *op, QualType writtenTy, SourceLocation l) 131 : CXXNamedCastExpr(CXXStaticCastExprClass, ty, op, writtenTy, l) {} 132 133 static bool classof(const Stmt *T) { 134 return T->getStmtClass() == CXXStaticCastExprClass; 135 } 136 static bool classof(const CXXStaticCastExpr *) { return true; } 137}; 138 139/// CXXDynamicCastExpr - A C++ @c dynamic_cast expression 140/// (C++ [expr.dynamic.cast]), which may perform a run-time check to 141/// determine how to perform the type cast. 142/// 143/// This expression node represents a dynamic cast, e.g., 144/// @c dynamic_cast<Derived*>(BasePtr). 145class CXXDynamicCastExpr : public CXXNamedCastExpr { 146public: 147 CXXDynamicCastExpr(QualType ty, Expr *op, QualType writtenTy, SourceLocation l) 148 : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, op, writtenTy, l) {} 149 150 static bool classof(const Stmt *T) { 151 return T->getStmtClass() == CXXDynamicCastExprClass; 152 } 153 static bool classof(const CXXDynamicCastExpr *) { return true; } 154}; 155 156/// CXXReinterpretCastExpr - A C++ @c reinterpret_cast expression (C++ 157/// [expr.reinterpret.cast]), which provides a differently-typed view 158/// of a value but performs no actual work at run time. 159/// 160/// This expression node represents a reinterpret cast, e.g., 161/// @c reinterpret_cast<int>(VoidPtr). 162class CXXReinterpretCastExpr : public CXXNamedCastExpr { 163public: 164 CXXReinterpretCastExpr(QualType ty, Expr *op, QualType writtenTy, 165 SourceLocation l) 166 : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, op, writtenTy, l) {} 167 168 static bool classof(const Stmt *T) { 169 return T->getStmtClass() == CXXReinterpretCastExprClass; 170 } 171 static bool classof(const CXXReinterpretCastExpr *) { return true; } 172}; 173 174/// CXXConstCastExpr - A C++ @c const_cast expression (C++ [expr.const.cast]), 175/// which can remove type qualifiers but does not change the underlying value. 176/// 177/// This expression node represents a const cast, e.g., 178/// @c const_cast<char*>(PtrToConstChar). 179class CXXConstCastExpr : public CXXNamedCastExpr { 180public: 181 CXXConstCastExpr(QualType ty, Expr *op, QualType writtenTy, 182 SourceLocation l) 183 : CXXNamedCastExpr(CXXConstCastExprClass, ty, op, writtenTy, l) {} 184 185 static bool classof(const Stmt *T) { 186 return T->getStmtClass() == CXXConstCastExprClass; 187 } 188 static bool classof(const CXXConstCastExpr *) { return true; } 189}; 190 191/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. 192/// 193class CXXBoolLiteralExpr : public Expr { 194 bool Value; 195 SourceLocation Loc; 196public: 197 CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : 198 Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {} 199 200 bool getValue() const { return Value; } 201 202 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 203 204 static bool classof(const Stmt *T) { 205 return T->getStmtClass() == CXXBoolLiteralExprClass; 206 } 207 static bool classof(const CXXBoolLiteralExpr *) { return true; } 208 209 // Iterators 210 virtual child_iterator child_begin(); 211 virtual child_iterator child_end(); 212}; 213 214/// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets 215/// the type_info that corresponds to the supplied type, or the (possibly 216/// dynamic) type of the supplied expression. 217/// 218/// This represents code like @c typeid(int) or @c typeid(*objPtr) 219class CXXTypeidExpr : public Expr { 220private: 221 bool isTypeOp : 1; 222 union { 223 void *Ty; 224 Stmt *Ex; 225 } Operand; 226 SourceRange Range; 227 228public: 229 CXXTypeidExpr(bool isTypeOp, void *op, QualType Ty, const SourceRange r) : 230 Expr(CXXTypeidExprClass, Ty), isTypeOp(isTypeOp), Range(r) { 231 if (isTypeOp) 232 Operand.Ty = op; 233 else 234 // op was an Expr*, so cast it back to that to be safe 235 Operand.Ex = static_cast<Stmt*>(op); 236 } 237 238 bool isTypeOperand() const { return isTypeOp; } 239 QualType getTypeOperand() const { 240 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 241 return QualType::getFromOpaquePtr(Operand.Ty); 242 } 243 Expr* getExprOperand() const { 244 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 245 return static_cast<Expr*>(Operand.Ex); 246 } 247 248 virtual SourceRange getSourceRange() const { 249 return Range; 250 } 251 static bool classof(const Stmt *T) { 252 return T->getStmtClass() == CXXTypeidExprClass; 253 } 254 static bool classof(const CXXTypeidExpr *) { return true; } 255 256 // Iterators 257 virtual child_iterator child_begin(); 258 virtual child_iterator child_end(); 259 260 virtual void EmitImpl(llvm::Serializer& S) const; 261 static CXXTypeidExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 262}; 263 264/// CXXThisExpr - Represents the "this" expression in C++, which is a 265/// pointer to the object on which the current member function is 266/// executing (C++ [expr.prim]p3). Example: 267/// 268/// @code 269/// class Foo { 270/// public: 271/// void bar(); 272/// void test() { this->bar(); } 273/// }; 274/// @endcode 275class CXXThisExpr : public Expr { 276 SourceLocation Loc; 277 278public: 279 CXXThisExpr(SourceLocation L, QualType Type) 280 : Expr(CXXThisExprClass, Type), Loc(L) { } 281 282 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 283 284 static bool classof(const Stmt *T) { 285 return T->getStmtClass() == CXXThisExprClass; 286 } 287 static bool classof(const CXXThisExpr *) { return true; } 288 289 // Iterators 290 virtual child_iterator child_begin(); 291 virtual child_iterator child_end(); 292 293 virtual void EmitImpl(llvm::Serializer& S) const; 294 static CXXThisExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 295}; 296 297/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 298/// 'throw' and 'throw' assignment-expression. When 299/// assignment-expression isn't present, Op will be null. 300/// 301class CXXThrowExpr : public Expr { 302 Stmt *Op; 303 SourceLocation ThrowLoc; 304public: 305 // Ty is the void type which is used as the result type of the 306 // exepression. The l is the location of the throw keyword. expr 307 // can by null, if the optional expression to throw isn't present. 308 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) : 309 Expr(CXXThrowExprClass, Ty), Op(expr), ThrowLoc(l) {} 310 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 311 Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 312 313 virtual SourceRange getSourceRange() const { 314 if (getSubExpr() == 0) 315 return SourceRange(ThrowLoc, ThrowLoc); 316 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 317 } 318 319 static bool classof(const Stmt *T) { 320 return T->getStmtClass() == CXXThrowExprClass; 321 } 322 static bool classof(const CXXThrowExpr *) { return true; } 323 324 // Iterators 325 virtual child_iterator child_begin(); 326 virtual child_iterator child_end(); 327}; 328 329/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 330/// function call argument that was created from the corresponding 331/// parameter's default argument, when the call did not explicitly 332/// supply arguments for all of the parameters. 333class CXXDefaultArgExpr : public Expr { 334 ParmVarDecl *Param; 335public: 336 // Param is the parameter whose default argument is used by this 337 // expression. 338 explicit CXXDefaultArgExpr(ParmVarDecl *param) 339 : Expr(CXXDefaultArgExprClass, 340 param->hasUnparsedDefaultArg()? param->getType().getNonReferenceType() 341 : param->getDefaultArg()->getType()), 342 Param(param) { } 343 344 // Retrieve the parameter that the argument was created from. 345 const ParmVarDecl *getParam() const { return Param; } 346 ParmVarDecl *getParam() { return Param; } 347 348 // Retrieve the actual argument to the function call. 349 const Expr *getExpr() const { return Param->getDefaultArg(); } 350 Expr *getExpr() { return Param->getDefaultArg(); } 351 352 virtual SourceRange getSourceRange() const { 353 // Default argument expressions have no representation in the 354 // source, so they have an empty source range. 355 return SourceRange(); 356 } 357 358 static bool classof(const Stmt *T) { 359 return T->getStmtClass() == CXXDefaultArgExprClass; 360 } 361 static bool classof(const CXXDefaultArgExpr *) { return true; } 362 363 // Iterators 364 virtual child_iterator child_begin(); 365 virtual child_iterator child_end(); 366 367 // Serialization 368 virtual void EmitImpl(llvm::Serializer& S) const; 369 static CXXDefaultArgExpr* CreateImpl(llvm::Deserializer& D, 370 ASTContext& C); 371}; 372 373/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 374/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 375/// x = int(0.5); 376class CXXFunctionalCastExpr : public ExplicitCastExpr { 377 SourceLocation TyBeginLoc; 378 SourceLocation RParenLoc; 379public: 380 CXXFunctionalCastExpr(QualType ty, QualType writtenTy, 381 SourceLocation tyBeginLoc, Expr *castExpr, 382 SourceLocation rParenLoc) : 383 ExplicitCastExpr(CXXFunctionalCastExprClass, ty, castExpr, writtenTy), 384 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 385 386 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 387 SourceLocation getRParenLoc() const { return RParenLoc; } 388 389 virtual SourceRange getSourceRange() const { 390 return SourceRange(TyBeginLoc, RParenLoc); 391 } 392 static bool classof(const Stmt *T) { 393 return T->getStmtClass() == CXXFunctionalCastExprClass; 394 } 395 static bool classof(const CXXFunctionalCastExpr *) { return true; } 396 397 virtual void EmitImpl(llvm::Serializer& S) const; 398 static CXXFunctionalCastExpr * 399 CreateImpl(llvm::Deserializer& D, ASTContext& C); 400}; 401 402/// CXXZeroInitValueExpr - [C++ 5.2.3p2] 403/// Expression "T()" which creates a value-initialized Rvalue of non-class 404/// type T. 405/// 406class CXXZeroInitValueExpr : public Expr { 407 SourceLocation TyBeginLoc; 408 SourceLocation RParenLoc; 409 410public: 411 CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc, 412 SourceLocation rParenLoc ) : 413 Expr(CXXZeroInitValueExprClass, ty), 414 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 415 416 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 417 SourceLocation getRParenLoc() const { return RParenLoc; } 418 419 virtual SourceRange getSourceRange() const { 420 return SourceRange(TyBeginLoc, RParenLoc); 421 } 422 423 static bool classof(const Stmt *T) { 424 return T->getStmtClass() == CXXZeroInitValueExprClass; 425 } 426 static bool classof(const CXXZeroInitValueExpr *) { return true; } 427 428 // Iterators 429 virtual child_iterator child_begin(); 430 virtual child_iterator child_end(); 431 432 virtual void EmitImpl(llvm::Serializer& S) const; 433 static CXXZeroInitValueExpr * 434 CreateImpl(llvm::Deserializer& D, ASTContext& C); 435}; 436 437/// CXXConditionDeclExpr - Condition declaration of a if/switch/while/for 438/// statement, e.g: "if (int x = f()) {...}". 439/// The main difference with DeclRefExpr is that CXXConditionDeclExpr owns the 440/// decl that it references. 441/// 442class CXXConditionDeclExpr : public DeclRefExpr { 443public: 444 CXXConditionDeclExpr(SourceLocation startLoc, 445 SourceLocation eqLoc, VarDecl *var) 446 : DeclRefExpr(CXXConditionDeclExprClass, var, 447 var->getType().getNonReferenceType(), startLoc) {} 448 449 virtual void Destroy(ASTContext& Ctx); 450 451 SourceLocation getStartLoc() const { return getLocation(); } 452 453 VarDecl *getVarDecl() { return cast<VarDecl>(getDecl()); } 454 const VarDecl *getVarDecl() const { return cast<VarDecl>(getDecl()); } 455 456 virtual SourceRange getSourceRange() const { 457 return SourceRange(getStartLoc(), getVarDecl()->getInit()->getLocEnd()); 458 } 459 460 static bool classof(const Stmt *T) { 461 return T->getStmtClass() == CXXConditionDeclExprClass; 462 } 463 static bool classof(const CXXConditionDeclExpr *) { return true; } 464 465 // Iterators 466 virtual child_iterator child_begin(); 467 virtual child_iterator child_end(); 468 469 // FIXME: Implement these. 470 //virtual void EmitImpl(llvm::Serializer& S) const; 471 //static CXXConditionDeclExpr * 472 // CreateImpl(llvm::Deserializer& D, ASTContext& C); 473}; 474 475/// CXXNewExpr - A new expression for memory allocation and constructor calls, 476/// e.g: "new CXXNewExpr(foo)". 477class CXXNewExpr : public Expr { 478 // Was the usage ::new, i.e. is the global new to be used? 479 bool GlobalNew : 1; 480 // Was the form (type-id) used? Otherwise, it was new-type-id. 481 bool ParenTypeId : 1; 482 // Is there an initializer? If not, built-ins are uninitialized, else they're 483 // value-initialized. 484 bool Initializer : 1; 485 // Do we allocate an array? If so, the first SubExpr is the size expression. 486 bool Array : 1; 487 // The number of placement new arguments. 488 unsigned NumPlacementArgs : 14; 489 // The number of constructor arguments. This may be 1 even for non-class 490 // types; use the pseudo copy constructor. 491 unsigned NumConstructorArgs : 14; 492 // Contains an optional array size expression, any number of optional 493 // placement arguments, and any number of optional constructor arguments, 494 // in that order. 495 Stmt **SubExprs; 496 // Points to the allocation function used. 497 FunctionDecl *OperatorNew; 498 // Points to the deallocation function used in case of error. May be null. 499 FunctionDecl *OperatorDelete; 500 // Points to the constructor used. Cannot be null if AllocType is a record; 501 // it would still point at the default constructor (even an implicit one). 502 // Must be null for all other types. 503 CXXConstructorDecl *Constructor; 504 505 SourceLocation StartLoc; 506 SourceLocation EndLoc; 507 508 // Deserialization constructor 509 CXXNewExpr(QualType ty, bool globalNew, bool parenTypeId, bool initializer, 510 bool array, unsigned numPlaceArgs, unsigned numConsArgs, 511 Stmt **subExprs, FunctionDecl *operatorNew, 512 FunctionDecl *operatorDelete, CXXConstructorDecl *constructor, 513 SourceLocation startLoc, SourceLocation endLoc) 514 : Expr(CXXNewExprClass, ty), GlobalNew(globalNew), ParenTypeId(parenTypeId), 515 Initializer(initializer), Array(array), NumPlacementArgs(numPlaceArgs), 516 NumConstructorArgs(numConsArgs), SubExprs(subExprs), 517 OperatorNew(operatorNew), OperatorDelete(operatorDelete), 518 Constructor(constructor), StartLoc(startLoc), EndLoc(endLoc) 519 { } 520public: 521 CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, Expr **placementArgs, 522 unsigned numPlaceArgs, bool ParenTypeId, Expr *arraySize, 523 CXXConstructorDecl *constructor, bool initializer, 524 Expr **constructorArgs, unsigned numConsArgs, 525 FunctionDecl *operatorDelete, QualType ty, 526 SourceLocation startLoc, SourceLocation endLoc); 527 ~CXXNewExpr() { 528 delete[] SubExprs; 529 } 530 531 QualType getAllocatedType() const { 532 assert(getType()->isPointerType()); 533 return getType()->getAsPointerType()->getPointeeType(); 534 } 535 536 FunctionDecl *getOperatorNew() const { return OperatorNew; } 537 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 538 CXXConstructorDecl *getConstructor() const { return Constructor; } 539 540 bool isArray() const { return Array; } 541 Expr *getArraySize() { 542 return Array ? cast<Expr>(SubExprs[0]) : 0; 543 } 544 const Expr *getArraySize() const { 545 return Array ? cast<Expr>(SubExprs[0]) : 0; 546 } 547 548 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 549 Expr *getPlacementArg(unsigned i) { 550 assert(i < NumPlacementArgs && "Index out of range"); 551 return cast<Expr>(SubExprs[Array + i]); 552 } 553 const Expr *getPlacementArg(unsigned i) const { 554 assert(i < NumPlacementArgs && "Index out of range"); 555 return cast<Expr>(SubExprs[Array + i]); 556 } 557 558 bool isGlobalNew() const { return GlobalNew; } 559 bool isParenTypeId() const { return ParenTypeId; } 560 bool hasInitializer() const { return Initializer; } 561 562 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 563 Expr *getConstructorArg(unsigned i) { 564 assert(i < NumConstructorArgs && "Index out of range"); 565 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 566 } 567 const Expr *getConstructorArg(unsigned i) const { 568 assert(i < NumConstructorArgs && "Index out of range"); 569 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 570 } 571 572 typedef ExprIterator arg_iterator; 573 typedef ConstExprIterator const_arg_iterator; 574 575 arg_iterator placement_arg_begin() { 576 return SubExprs + Array; 577 } 578 arg_iterator placement_arg_end() { 579 return SubExprs + Array + getNumPlacementArgs(); 580 } 581 const_arg_iterator placement_arg_begin() const { 582 return SubExprs + Array; 583 } 584 const_arg_iterator placement_arg_end() const { 585 return SubExprs + Array + getNumPlacementArgs(); 586 } 587 588 arg_iterator constructor_arg_begin() { 589 return SubExprs + Array + getNumPlacementArgs(); 590 } 591 arg_iterator constructor_arg_end() { 592 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 593 } 594 const_arg_iterator constructor_arg_begin() const { 595 return SubExprs + Array + getNumPlacementArgs(); 596 } 597 const_arg_iterator constructor_arg_end() const { 598 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 599 } 600 601 virtual SourceRange getSourceRange() const { 602 return SourceRange(StartLoc, EndLoc); 603 } 604 605 static bool classof(const Stmt *T) { 606 return T->getStmtClass() == CXXNewExprClass; 607 } 608 static bool classof(const CXXNewExpr *) { return true; } 609 610 // Iterators 611 virtual child_iterator child_begin(); 612 virtual child_iterator child_end(); 613 614 virtual void EmitImpl(llvm::Serializer& S) const; 615 static CXXNewExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 616}; 617 618/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 619/// calls, e.g. "delete[] pArray". 620class CXXDeleteExpr : public Expr { 621 // Is this a forced global delete, i.e. "::delete"? 622 bool GlobalDelete : 1; 623 // Is this the array form of delete, i.e. "delete[]"? 624 bool ArrayForm : 1; 625 // Points to the operator delete overload that is used. Could be a member. 626 FunctionDecl *OperatorDelete; 627 // The pointer expression to be deleted. 628 Stmt *Argument; 629 // Location of the expression. 630 SourceLocation Loc; 631public: 632 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 633 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 634 : Expr(CXXDeleteExprClass, ty), GlobalDelete(globalDelete), 635 ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg), 636 Loc(loc) { } 637 638 bool isGlobalDelete() const { return GlobalDelete; } 639 bool isArrayForm() const { return ArrayForm; } 640 641 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 642 643 Expr *getArgument() { return cast<Expr>(Argument); } 644 const Expr *getArgument() const { return cast<Expr>(Argument); } 645 646 virtual SourceRange getSourceRange() const { 647 return SourceRange(Loc, Argument->getLocEnd()); 648 } 649 650 static bool classof(const Stmt *T) { 651 return T->getStmtClass() == CXXDeleteExprClass; 652 } 653 static bool classof(const CXXDeleteExpr *) { return true; } 654 655 // Iterators 656 virtual child_iterator child_begin(); 657 virtual child_iterator child_end(); 658 659 virtual void EmitImpl(llvm::Serializer& S) const; 660 static CXXDeleteExpr * CreateImpl(llvm::Deserializer& D, ASTContext& C); 661}; 662 663/// CXXDependentNameExpr - Represents a dependent name in C++ for 664/// which we could not locate any definition. These names can only 665/// occur as in the example below, with an unqualified call to a 666/// function name whose arguments are dependent. 667/// @code 668/// template<typename T> void f(T x) { 669/// g(x); // g is a dependent name. 670/// } 671/// @endcode 672class CXXDependentNameExpr : public Expr { 673 /// Name - The name that was present in the source code. 674 IdentifierInfo *Name; 675 676 /// Loc - The location 677 SourceLocation Loc; 678 679public: 680 CXXDependentNameExpr(IdentifierInfo *N, QualType T, SourceLocation L) 681 : Expr(CXXDependentNameExprClass, T, true, true), Name(N), Loc(L) { } 682 683 /// getName - Retrieves the name that occurred in the source code. 684 IdentifierInfo *getName() const { return Name; } 685 686 /// getLocation - Retrieves the location in the source code where 687 /// the name occurred. 688 SourceLocation getLocation() const { return Loc; } 689 690 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 691 692 static bool classof(const Stmt *T) { 693 return T->getStmtClass() == CXXDependentNameExprClass; 694 } 695 static bool classof(const CXXDependentNameExpr *) { return true; } 696 697 // Iterators 698 virtual child_iterator child_begin(); 699 virtual child_iterator child_end(); 700 701 virtual void EmitImpl(llvm::Serializer& S) const; 702 static CXXDependentNameExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C); 703}; 704 705/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 706/// implementation of TR1/C++0x type trait templates. 707/// Example: 708/// __is_pod(int) == true 709/// __is_enum(std::string) == false 710class UnaryTypeTraitExpr : public Expr { 711 /// UTT - The trait. 712 UnaryTypeTrait UTT; 713 714 /// Loc - The location of the type trait keyword. 715 SourceLocation Loc; 716 717 /// RParen - The location of the closing paren. 718 SourceLocation RParen; 719 720 /// QueriedType - The type we're testing. 721 QualType QueriedType; 722 723public: 724 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried, 725 SourceLocation rparen, QualType ty) 726 : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()), 727 UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { } 728 729 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 730 731 UnaryTypeTrait getTrait() const { return UTT; } 732 733 QualType getQueriedType() const { return QueriedType; } 734 735 bool Evaluate() const; 736 737 static bool classof(const Stmt *T) { 738 return T->getStmtClass() == UnaryTypeTraitExprClass; 739 } 740 static bool classof(const UnaryTypeTraitExpr *) { return true; } 741 742 // Iterators 743 virtual child_iterator child_begin(); 744 virtual child_iterator child_end(); 745 746 virtual void EmitImpl(llvm::Serializer& S) const; 747 static UnaryTypeTraitExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C); 748}; 749 750/// QualifiedDeclRefExpr - A reference to a declared variable, 751/// function, enum, etc., that includes a qualification, e.g., 752/// "N::foo". 753class QualifiedDeclRefExpr : public DeclRefExpr { 754 /// NestedNameLoc - The location of the beginning of the 755 /// nested-name-specifier that qualifies this declaration. 756 SourceLocation NestedNameLoc; 757 758public: 759 QualifiedDeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, 760 bool VD, SourceLocation nnl) 761 : DeclRefExpr(QualifiedDeclRefExprClass, d, t, l, TD, VD), 762 NestedNameLoc(nnl) { } 763 764 virtual SourceRange getSourceRange() const { 765 return SourceRange(NestedNameLoc, getLocation()); 766 } 767 768 static bool classof(const Stmt *T) { 769 return T->getStmtClass() == QualifiedDeclRefExprClass; 770 } 771 static bool classof(const QualifiedDeclRefExpr *) { return true; } 772 773 virtual void EmitImpl(llvm::Serializer& S) const; 774 static QualifiedDeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 775}; 776 777} // end namespace clang 778 779#endif 780