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