ExprCXX.h revision c87a282e7b80c055088fc51bdbe8fc73da64d4f8
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(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 36 QualType t, SourceLocation operatorloc) 37 : CallExpr(C, 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(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 69 QualType t, SourceLocation rparenloc) 70 : CallExpr(C, 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/// @brief Represents a C++ functional cast expression that builds a 403/// temporary object. 404/// 405/// This expression type represents a C++ "functional" cast 406/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 407/// constructor to build a temporary object. If N == 0 but no 408/// constructor will be called (because the functional cast is 409/// performing a value-initialized an object whose class type has no 410/// user-declared constructors), CXXZeroInitValueExpr will represent 411/// the functional cast. Finally, with N == 1 arguments the functional 412/// cast expression will be represented by CXXFunctionalCastExpr. 413/// Example: 414/// @code 415/// struct X { X(int, float); } 416/// 417/// X create_X() { 418/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 419/// }; 420/// @endcode 421class CXXTemporaryObjectExpr : public Expr { 422 SourceLocation TyBeginLoc; 423 SourceLocation RParenLoc; 424 CXXConstructorDecl *Constructor; 425 Stmt **Args; 426 unsigned NumArgs; 427 428public: 429 CXXTemporaryObjectExpr(CXXConstructorDecl *Cons, QualType writtenTy, 430 SourceLocation tyBeginLoc, Expr **Args, 431 unsigned NumArgs, SourceLocation rParenLoc); 432 433 ~CXXTemporaryObjectExpr(); 434 435 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 436 SourceLocation getRParenLoc() const { return RParenLoc; } 437 438 typedef ExprIterator arg_iterator; 439 typedef ConstExprIterator const_arg_iterator; 440 441 arg_iterator arg_begin() { return Args; } 442 arg_iterator arg_end() { return Args + NumArgs; } 443 const_arg_iterator arg_begin() const { return Args; } 444 const_arg_iterator arg_end() const { return Args + NumArgs; } 445 446 virtual SourceRange getSourceRange() const { 447 return SourceRange(TyBeginLoc, RParenLoc); 448 } 449 static bool classof(const Stmt *T) { 450 return T->getStmtClass() == CXXTemporaryObjectExprClass; 451 } 452 static bool classof(const CXXTemporaryObjectExpr *) { return true; } 453 454 // Iterators 455 virtual child_iterator child_begin(); 456 virtual child_iterator child_end(); 457 458 virtual void EmitImpl(llvm::Serializer& S) const; 459 static CXXTemporaryObjectExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C); 460}; 461 462/// CXXZeroInitValueExpr - [C++ 5.2.3p2] 463/// Expression "T()" which creates a value-initialized rvalue of type 464/// T, which is either a non-class type or a class type without any 465/// user-defined constructors. 466/// 467class CXXZeroInitValueExpr : public Expr { 468 SourceLocation TyBeginLoc; 469 SourceLocation RParenLoc; 470 471public: 472 CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc, 473 SourceLocation rParenLoc ) : 474 Expr(CXXZeroInitValueExprClass, ty), 475 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 476 477 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 478 SourceLocation getRParenLoc() const { return RParenLoc; } 479 480 /// @brief Whether this initialization expression was 481 /// implicitly-generated. 482 bool isImplicit() const { 483 return TyBeginLoc.isInvalid() && RParenLoc.isInvalid(); 484 } 485 486 virtual SourceRange getSourceRange() const { 487 return SourceRange(TyBeginLoc, RParenLoc); 488 } 489 490 static bool classof(const Stmt *T) { 491 return T->getStmtClass() == CXXZeroInitValueExprClass; 492 } 493 static bool classof(const CXXZeroInitValueExpr *) { return true; } 494 495 // Iterators 496 virtual child_iterator child_begin(); 497 virtual child_iterator child_end(); 498 499 virtual void EmitImpl(llvm::Serializer& S) const; 500 static CXXZeroInitValueExpr * 501 CreateImpl(llvm::Deserializer& D, ASTContext& C); 502}; 503 504/// CXXConditionDeclExpr - Condition declaration of a if/switch/while/for 505/// statement, e.g: "if (int x = f()) {...}". 506/// The main difference with DeclRefExpr is that CXXConditionDeclExpr owns the 507/// decl that it references. 508/// 509class CXXConditionDeclExpr : public DeclRefExpr { 510public: 511 CXXConditionDeclExpr(SourceLocation startLoc, 512 SourceLocation eqLoc, VarDecl *var) 513 : DeclRefExpr(CXXConditionDeclExprClass, var, 514 var->getType().getNonReferenceType(), startLoc) {} 515 516 virtual void Destroy(ASTContext& Ctx); 517 518 SourceLocation getStartLoc() const { return getLocation(); } 519 520 VarDecl *getVarDecl() { return cast<VarDecl>(getDecl()); } 521 const VarDecl *getVarDecl() const { return cast<VarDecl>(getDecl()); } 522 523 virtual SourceRange getSourceRange() const { 524 return SourceRange(getStartLoc(), getVarDecl()->getInit()->getLocEnd()); 525 } 526 527 static bool classof(const Stmt *T) { 528 return T->getStmtClass() == CXXConditionDeclExprClass; 529 } 530 static bool classof(const CXXConditionDeclExpr *) { return true; } 531 532 // Iterators 533 virtual child_iterator child_begin(); 534 virtual child_iterator child_end(); 535 536 // FIXME: Implement these. 537 //virtual void EmitImpl(llvm::Serializer& S) const; 538 //static CXXConditionDeclExpr * 539 // CreateImpl(llvm::Deserializer& D, ASTContext& C); 540}; 541 542/// CXXNewExpr - A new expression for memory allocation and constructor calls, 543/// e.g: "new CXXNewExpr(foo)". 544class CXXNewExpr : public Expr { 545 // Was the usage ::new, i.e. is the global new to be used? 546 bool GlobalNew : 1; 547 // Was the form (type-id) used? Otherwise, it was new-type-id. 548 bool ParenTypeId : 1; 549 // Is there an initializer? If not, built-ins are uninitialized, else they're 550 // value-initialized. 551 bool Initializer : 1; 552 // Do we allocate an array? If so, the first SubExpr is the size expression. 553 bool Array : 1; 554 // The number of placement new arguments. 555 unsigned NumPlacementArgs : 14; 556 // The number of constructor arguments. This may be 1 even for non-class 557 // types; use the pseudo copy constructor. 558 unsigned NumConstructorArgs : 14; 559 // Contains an optional array size expression, any number of optional 560 // placement arguments, and any number of optional constructor arguments, 561 // in that order. 562 Stmt **SubExprs; 563 // Points to the allocation function used. 564 FunctionDecl *OperatorNew; 565 // Points to the deallocation function used in case of error. May be null. 566 FunctionDecl *OperatorDelete; 567 // Points to the constructor used. Cannot be null if AllocType is a record; 568 // it would still point at the default constructor (even an implicit one). 569 // Must be null for all other types. 570 CXXConstructorDecl *Constructor; 571 572 SourceLocation StartLoc; 573 SourceLocation EndLoc; 574 575 // Deserialization constructor 576 CXXNewExpr(QualType ty, bool globalNew, bool parenTypeId, bool initializer, 577 bool array, unsigned numPlaceArgs, unsigned numConsArgs, 578 Stmt **subExprs, FunctionDecl *operatorNew, 579 FunctionDecl *operatorDelete, CXXConstructorDecl *constructor, 580 SourceLocation startLoc, SourceLocation endLoc) 581 : Expr(CXXNewExprClass, ty), GlobalNew(globalNew), ParenTypeId(parenTypeId), 582 Initializer(initializer), Array(array), NumPlacementArgs(numPlaceArgs), 583 NumConstructorArgs(numConsArgs), SubExprs(subExprs), 584 OperatorNew(operatorNew), OperatorDelete(operatorDelete), 585 Constructor(constructor), StartLoc(startLoc), EndLoc(endLoc) 586 { } 587public: 588 CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, Expr **placementArgs, 589 unsigned numPlaceArgs, bool ParenTypeId, Expr *arraySize, 590 CXXConstructorDecl *constructor, bool initializer, 591 Expr **constructorArgs, unsigned numConsArgs, 592 FunctionDecl *operatorDelete, QualType ty, 593 SourceLocation startLoc, SourceLocation endLoc); 594 ~CXXNewExpr() { 595 delete[] SubExprs; 596 } 597 598 QualType getAllocatedType() const { 599 assert(getType()->isPointerType()); 600 return getType()->getAsPointerType()->getPointeeType(); 601 } 602 603 FunctionDecl *getOperatorNew() const { return OperatorNew; } 604 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 605 CXXConstructorDecl *getConstructor() const { return Constructor; } 606 607 bool isArray() const { return Array; } 608 Expr *getArraySize() { 609 return Array ? cast<Expr>(SubExprs[0]) : 0; 610 } 611 const Expr *getArraySize() const { 612 return Array ? cast<Expr>(SubExprs[0]) : 0; 613 } 614 615 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 616 Expr *getPlacementArg(unsigned i) { 617 assert(i < NumPlacementArgs && "Index out of range"); 618 return cast<Expr>(SubExprs[Array + i]); 619 } 620 const Expr *getPlacementArg(unsigned i) const { 621 assert(i < NumPlacementArgs && "Index out of range"); 622 return cast<Expr>(SubExprs[Array + i]); 623 } 624 625 bool isGlobalNew() const { return GlobalNew; } 626 bool isParenTypeId() const { return ParenTypeId; } 627 bool hasInitializer() const { return Initializer; } 628 629 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 630 Expr *getConstructorArg(unsigned i) { 631 assert(i < NumConstructorArgs && "Index out of range"); 632 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 633 } 634 const Expr *getConstructorArg(unsigned i) const { 635 assert(i < NumConstructorArgs && "Index out of range"); 636 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 637 } 638 639 typedef ExprIterator arg_iterator; 640 typedef ConstExprIterator const_arg_iterator; 641 642 arg_iterator placement_arg_begin() { 643 return SubExprs + Array; 644 } 645 arg_iterator placement_arg_end() { 646 return SubExprs + Array + getNumPlacementArgs(); 647 } 648 const_arg_iterator placement_arg_begin() const { 649 return SubExprs + Array; 650 } 651 const_arg_iterator placement_arg_end() const { 652 return SubExprs + Array + getNumPlacementArgs(); 653 } 654 655 arg_iterator constructor_arg_begin() { 656 return SubExprs + Array + getNumPlacementArgs(); 657 } 658 arg_iterator constructor_arg_end() { 659 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 660 } 661 const_arg_iterator constructor_arg_begin() const { 662 return SubExprs + Array + getNumPlacementArgs(); 663 } 664 const_arg_iterator constructor_arg_end() const { 665 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 666 } 667 668 virtual SourceRange getSourceRange() const { 669 return SourceRange(StartLoc, EndLoc); 670 } 671 672 static bool classof(const Stmt *T) { 673 return T->getStmtClass() == CXXNewExprClass; 674 } 675 static bool classof(const CXXNewExpr *) { return true; } 676 677 // Iterators 678 virtual child_iterator child_begin(); 679 virtual child_iterator child_end(); 680 681 virtual void EmitImpl(llvm::Serializer& S) const; 682 static CXXNewExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 683}; 684 685/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 686/// calls, e.g. "delete[] pArray". 687class CXXDeleteExpr : public Expr { 688 // Is this a forced global delete, i.e. "::delete"? 689 bool GlobalDelete : 1; 690 // Is this the array form of delete, i.e. "delete[]"? 691 bool ArrayForm : 1; 692 // Points to the operator delete overload that is used. Could be a member. 693 FunctionDecl *OperatorDelete; 694 // The pointer expression to be deleted. 695 Stmt *Argument; 696 // Location of the expression. 697 SourceLocation Loc; 698public: 699 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 700 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 701 : Expr(CXXDeleteExprClass, ty), GlobalDelete(globalDelete), 702 ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg), 703 Loc(loc) { } 704 705 bool isGlobalDelete() const { return GlobalDelete; } 706 bool isArrayForm() const { return ArrayForm; } 707 708 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 709 710 Expr *getArgument() { return cast<Expr>(Argument); } 711 const Expr *getArgument() const { return cast<Expr>(Argument); } 712 713 virtual SourceRange getSourceRange() const { 714 return SourceRange(Loc, Argument->getLocEnd()); 715 } 716 717 static bool classof(const Stmt *T) { 718 return T->getStmtClass() == CXXDeleteExprClass; 719 } 720 static bool classof(const CXXDeleteExpr *) { return true; } 721 722 // Iterators 723 virtual child_iterator child_begin(); 724 virtual child_iterator child_end(); 725 726 virtual void EmitImpl(llvm::Serializer& S) const; 727 static CXXDeleteExpr * CreateImpl(llvm::Deserializer& D, ASTContext& C); 728}; 729 730/// \brief Represents the name of a function that has not been 731/// resolved to any declaration. 732/// 733/// Unresolved function names occur when a function name is 734/// encountered prior to an open parentheses ('(') in a C++ function 735/// call, and the function name itself did not resolve to a 736/// declaration. These function names can only be resolved when they 737/// form the postfix-expression of a function call, so that 738/// argument-dependent lookup finds declarations corresponding to 739/// these functions. 740 741/// @code 742/// template<typename T> void f(T x) { 743/// g(x); // g is an unresolved function name (that is also a dependent name) 744/// } 745/// @endcode 746class UnresolvedFunctionNameExpr : public Expr { 747 /// The name that was present in the source 748 DeclarationName Name; 749 750 /// The location of this name in the source code 751 SourceLocation Loc; 752 753public: 754 UnresolvedFunctionNameExpr(DeclarationName N, QualType T, SourceLocation L) 755 : Expr(UnresolvedFunctionNameExprClass, T, false, false), Name(N), Loc(L) { } 756 757 /// \brief Retrieves the name that occurred in the source code. 758 DeclarationName getName() const { return Name; } 759 760 /// getLocation - Retrieves the location in the source code where 761 /// the name occurred. 762 SourceLocation getLocation() const { return Loc; } 763 764 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 765 766 static bool classof(const Stmt *T) { 767 return T->getStmtClass() == UnresolvedFunctionNameExprClass; 768 } 769 static bool classof(const UnresolvedFunctionNameExpr *) { return true; } 770 771 // Iterators 772 virtual child_iterator child_begin(); 773 virtual child_iterator child_end(); 774 775 virtual void EmitImpl(llvm::Serializer& S) const; 776 static UnresolvedFunctionNameExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C); 777}; 778 779/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 780/// implementation of TR1/C++0x type trait templates. 781/// Example: 782/// __is_pod(int) == true 783/// __is_enum(std::string) == false 784class UnaryTypeTraitExpr : public Expr { 785 /// UTT - The trait. 786 UnaryTypeTrait UTT; 787 788 /// Loc - The location of the type trait keyword. 789 SourceLocation Loc; 790 791 /// RParen - The location of the closing paren. 792 SourceLocation RParen; 793 794 /// QueriedType - The type we're testing. 795 QualType QueriedType; 796 797public: 798 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried, 799 SourceLocation rparen, QualType ty) 800 : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()), 801 UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { } 802 803 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 804 805 UnaryTypeTrait getTrait() const { return UTT; } 806 807 QualType getQueriedType() const { return QueriedType; } 808 809 bool EvaluateTrait() const; 810 811 static bool classof(const Stmt *T) { 812 return T->getStmtClass() == UnaryTypeTraitExprClass; 813 } 814 static bool classof(const UnaryTypeTraitExpr *) { return true; } 815 816 // Iterators 817 virtual child_iterator child_begin(); 818 virtual child_iterator child_end(); 819 820 virtual void EmitImpl(llvm::Serializer& S) const; 821 static UnaryTypeTraitExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C); 822}; 823 824/// QualifiedDeclRefExpr - A reference to a declared variable, 825/// function, enum, etc., that includes a qualification, e.g., 826/// "N::foo". 827class QualifiedDeclRefExpr : public DeclRefExpr { 828 /// NestedNameLoc - The location of the beginning of the 829 /// nested-name-specifier that qualifies this declaration. 830 SourceLocation NestedNameLoc; 831 832public: 833 QualifiedDeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, 834 bool VD, SourceLocation nnl) 835 : DeclRefExpr(QualifiedDeclRefExprClass, d, t, l, TD, VD), 836 NestedNameLoc(nnl) { } 837 838 virtual SourceRange getSourceRange() const { 839 return SourceRange(NestedNameLoc, getLocation()); 840 } 841 842 static bool classof(const Stmt *T) { 843 return T->getStmtClass() == QualifiedDeclRefExprClass; 844 } 845 static bool classof(const QualifiedDeclRefExpr *) { return true; } 846 847 virtual void EmitImpl(llvm::Serializer& S) const; 848 static QualifiedDeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 849}; 850 851} // end namespace clang 852 853#endif 854