ExprCXX.h revision 2850784bda09416fc7e9d57f5baa36c9351c757c
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, 231 // typeid is never type-dependent (C++ [temp.dep.expr]p4) 232 false, 233 // typeid is value-dependent if the type or expression are dependent 234 (isTypeOp ? QualType::getFromOpaquePtr(op)->isDependentType() 235 : static_cast<Expr*>(op)->isValueDependent())), 236 isTypeOp(isTypeOp), Range(r) { 237 if (isTypeOp) 238 Operand.Ty = op; 239 else 240 // op was an Expr*, so cast it back to that to be safe 241 Operand.Ex = static_cast<Expr*>(op); 242 } 243 244 bool isTypeOperand() const { return isTypeOp; } 245 QualType getTypeOperand() const { 246 assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)"); 247 return QualType::getFromOpaquePtr(Operand.Ty); 248 } 249 Expr* getExprOperand() const { 250 assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)"); 251 return static_cast<Expr*>(Operand.Ex); 252 } 253 254 virtual SourceRange getSourceRange() const { 255 return Range; 256 } 257 static bool classof(const Stmt *T) { 258 return T->getStmtClass() == CXXTypeidExprClass; 259 } 260 static bool classof(const CXXTypeidExpr *) { return true; } 261 262 // Iterators 263 virtual child_iterator child_begin(); 264 virtual child_iterator child_end(); 265 266 virtual void EmitImpl(llvm::Serializer& S) const; 267 static CXXTypeidExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 268}; 269 270/// CXXThisExpr - Represents the "this" expression in C++, which is a 271/// pointer to the object on which the current member function is 272/// executing (C++ [expr.prim]p3). Example: 273/// 274/// @code 275/// class Foo { 276/// public: 277/// void bar(); 278/// void test() { this->bar(); } 279/// }; 280/// @endcode 281class CXXThisExpr : public Expr { 282 SourceLocation Loc; 283 284public: 285 CXXThisExpr(SourceLocation L, QualType Type) 286 : Expr(CXXThisExprClass, Type, 287 // 'this' is type-dependent if the class type of the enclosing 288 // member function is dependent (C++ [temp.dep.expr]p2) 289 Type->isDependentType(), Type->isDependentType()), 290 Loc(L) { } 291 292 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 293 294 static bool classof(const Stmt *T) { 295 return T->getStmtClass() == CXXThisExprClass; 296 } 297 static bool classof(const CXXThisExpr *) { return true; } 298 299 // Iterators 300 virtual child_iterator child_begin(); 301 virtual child_iterator child_end(); 302 303 virtual void EmitImpl(llvm::Serializer& S) const; 304 static CXXThisExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 305}; 306 307/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles 308/// 'throw' and 'throw' assignment-expression. When 309/// assignment-expression isn't present, Op will be null. 310/// 311class CXXThrowExpr : public Expr { 312 Stmt *Op; 313 SourceLocation ThrowLoc; 314public: 315 // Ty is the void type which is used as the result type of the 316 // exepression. The l is the location of the throw keyword. expr 317 // can by null, if the optional expression to throw isn't present. 318 CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) : 319 Expr(CXXThrowExprClass, Ty, false, false), Op(expr), ThrowLoc(l) {} 320 const Expr *getSubExpr() const { return cast_or_null<Expr>(Op); } 321 Expr *getSubExpr() { return cast_or_null<Expr>(Op); } 322 323 virtual SourceRange getSourceRange() const { 324 if (getSubExpr() == 0) 325 return SourceRange(ThrowLoc, ThrowLoc); 326 return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); 327 } 328 329 static bool classof(const Stmt *T) { 330 return T->getStmtClass() == CXXThrowExprClass; 331 } 332 static bool classof(const CXXThrowExpr *) { return true; } 333 334 // Iterators 335 virtual child_iterator child_begin(); 336 virtual child_iterator child_end(); 337}; 338 339/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a 340/// function call argument that was created from the corresponding 341/// parameter's default argument, when the call did not explicitly 342/// supply arguments for all of the parameters. 343class CXXDefaultArgExpr : public Expr { 344 ParmVarDecl *Param; 345public: 346 // Param is the parameter whose default argument is used by this 347 // expression. 348 explicit CXXDefaultArgExpr(ParmVarDecl *param) 349 : Expr(CXXDefaultArgExprClass, 350 param->hasUnparsedDefaultArg()? param->getType().getNonReferenceType() 351 : param->getDefaultArg()->getType()), 352 Param(param) { } 353 354 // Retrieve the parameter that the argument was created from. 355 const ParmVarDecl *getParam() const { return Param; } 356 ParmVarDecl *getParam() { return Param; } 357 358 // Retrieve the actual argument to the function call. 359 const Expr *getExpr() const { return Param->getDefaultArg(); } 360 Expr *getExpr() { return Param->getDefaultArg(); } 361 362 virtual SourceRange getSourceRange() const { 363 // Default argument expressions have no representation in the 364 // source, so they have an empty source range. 365 return SourceRange(); 366 } 367 368 static bool classof(const Stmt *T) { 369 return T->getStmtClass() == CXXDefaultArgExprClass; 370 } 371 static bool classof(const CXXDefaultArgExpr *) { return true; } 372 373 // Iterators 374 virtual child_iterator child_begin(); 375 virtual child_iterator child_end(); 376 377 // Serialization 378 virtual void EmitImpl(llvm::Serializer& S) const; 379 static CXXDefaultArgExpr* CreateImpl(llvm::Deserializer& D, 380 ASTContext& C); 381}; 382 383/// CXXFunctionalCastExpr - Represents an explicit C++ type conversion 384/// that uses "functional" notion (C++ [expr.type.conv]). Example: @c 385/// x = int(0.5); 386class CXXFunctionalCastExpr : public ExplicitCastExpr { 387 SourceLocation TyBeginLoc; 388 SourceLocation RParenLoc; 389public: 390 CXXFunctionalCastExpr(QualType ty, QualType writtenTy, 391 SourceLocation tyBeginLoc, Expr *castExpr, 392 SourceLocation rParenLoc) : 393 ExplicitCastExpr(CXXFunctionalCastExprClass, ty, castExpr, writtenTy), 394 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 395 396 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 397 SourceLocation getRParenLoc() const { return RParenLoc; } 398 399 virtual SourceRange getSourceRange() const { 400 return SourceRange(TyBeginLoc, RParenLoc); 401 } 402 static bool classof(const Stmt *T) { 403 return T->getStmtClass() == CXXFunctionalCastExprClass; 404 } 405 static bool classof(const CXXFunctionalCastExpr *) { return true; } 406 407 virtual void EmitImpl(llvm::Serializer& S) const; 408 static CXXFunctionalCastExpr * 409 CreateImpl(llvm::Deserializer& D, ASTContext& C); 410}; 411 412/// @brief Represents a C++ functional cast expression that builds a 413/// temporary object. 414/// 415/// This expression type represents a C++ "functional" cast 416/// (C++[expr.type.conv]) with N != 1 arguments that invokes a 417/// constructor to build a temporary object. If N == 0 but no 418/// constructor will be called (because the functional cast is 419/// performing a value-initialized an object whose class type has no 420/// user-declared constructors), CXXZeroInitValueExpr will represent 421/// the functional cast. Finally, with N == 1 arguments the functional 422/// cast expression will be represented by CXXFunctionalCastExpr. 423/// Example: 424/// @code 425/// struct X { X(int, float); } 426/// 427/// X create_X() { 428/// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr 429/// }; 430/// @endcode 431class CXXTemporaryObjectExpr : public Expr { 432 SourceLocation TyBeginLoc; 433 SourceLocation RParenLoc; 434 CXXConstructorDecl *Constructor; 435 Stmt **Args; 436 unsigned NumArgs; 437 438public: 439 CXXTemporaryObjectExpr(CXXConstructorDecl *Cons, QualType writtenTy, 440 SourceLocation tyBeginLoc, Expr **Args, 441 unsigned NumArgs, SourceLocation rParenLoc); 442 443 ~CXXTemporaryObjectExpr(); 444 445 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 446 SourceLocation getRParenLoc() const { return RParenLoc; } 447 448 typedef ExprIterator arg_iterator; 449 typedef ConstExprIterator const_arg_iterator; 450 451 arg_iterator arg_begin() { return Args; } 452 arg_iterator arg_end() { return Args + NumArgs; } 453 const_arg_iterator arg_begin() const { return Args; } 454 const_arg_iterator arg_end() const { return Args + NumArgs; } 455 456 virtual SourceRange getSourceRange() const { 457 return SourceRange(TyBeginLoc, RParenLoc); 458 } 459 static bool classof(const Stmt *T) { 460 return T->getStmtClass() == CXXTemporaryObjectExprClass; 461 } 462 static bool classof(const CXXTemporaryObjectExpr *) { return true; } 463 464 // Iterators 465 virtual child_iterator child_begin(); 466 virtual child_iterator child_end(); 467 468 virtual void EmitImpl(llvm::Serializer& S) const; 469 static CXXTemporaryObjectExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C); 470}; 471 472/// CXXZeroInitValueExpr - [C++ 5.2.3p2] 473/// Expression "T()" which creates a value-initialized rvalue of type 474/// T, which is either a non-class type or a class type without any 475/// user-defined constructors. 476/// 477class CXXZeroInitValueExpr : public Expr { 478 SourceLocation TyBeginLoc; 479 SourceLocation RParenLoc; 480 481public: 482 CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc, 483 SourceLocation rParenLoc ) : 484 Expr(CXXZeroInitValueExprClass, ty), 485 TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {} 486 487 SourceLocation getTypeBeginLoc() const { return TyBeginLoc; } 488 SourceLocation getRParenLoc() const { return RParenLoc; } 489 490 /// @brief Whether this initialization expression was 491 /// implicitly-generated. 492 bool isImplicit() const { 493 return TyBeginLoc.isInvalid() && RParenLoc.isInvalid(); 494 } 495 496 virtual SourceRange getSourceRange() const { 497 return SourceRange(TyBeginLoc, RParenLoc); 498 } 499 500 static bool classof(const Stmt *T) { 501 return T->getStmtClass() == CXXZeroInitValueExprClass; 502 } 503 static bool classof(const CXXZeroInitValueExpr *) { return true; } 504 505 // Iterators 506 virtual child_iterator child_begin(); 507 virtual child_iterator child_end(); 508 509 virtual void EmitImpl(llvm::Serializer& S) const; 510 static CXXZeroInitValueExpr * 511 CreateImpl(llvm::Deserializer& D, ASTContext& C); 512}; 513 514/// CXXConditionDeclExpr - Condition declaration of a if/switch/while/for 515/// statement, e.g: "if (int x = f()) {...}". 516/// The main difference with DeclRefExpr is that CXXConditionDeclExpr owns the 517/// decl that it references. 518/// 519class CXXConditionDeclExpr : public DeclRefExpr { 520public: 521 CXXConditionDeclExpr(SourceLocation startLoc, 522 SourceLocation eqLoc, VarDecl *var) 523 : DeclRefExpr(CXXConditionDeclExprClass, var, 524 var->getType().getNonReferenceType(), startLoc) {} 525 526 virtual void Destroy(ASTContext& Ctx); 527 528 SourceLocation getStartLoc() const { return getLocation(); } 529 530 VarDecl *getVarDecl() { return cast<VarDecl>(getDecl()); } 531 const VarDecl *getVarDecl() const { return cast<VarDecl>(getDecl()); } 532 533 virtual SourceRange getSourceRange() const { 534 return SourceRange(getStartLoc(), getVarDecl()->getInit()->getLocEnd()); 535 } 536 537 static bool classof(const Stmt *T) { 538 return T->getStmtClass() == CXXConditionDeclExprClass; 539 } 540 static bool classof(const CXXConditionDeclExpr *) { return true; } 541 542 // Iterators 543 virtual child_iterator child_begin(); 544 virtual child_iterator child_end(); 545 546 // FIXME: Implement these. 547 //virtual void EmitImpl(llvm::Serializer& S) const; 548 //static CXXConditionDeclExpr * 549 // CreateImpl(llvm::Deserializer& D, ASTContext& C); 550}; 551 552/// CXXNewExpr - A new expression for memory allocation and constructor calls, 553/// e.g: "new CXXNewExpr(foo)". 554class CXXNewExpr : public Expr { 555 // Was the usage ::new, i.e. is the global new to be used? 556 bool GlobalNew : 1; 557 // Was the form (type-id) used? Otherwise, it was new-type-id. 558 bool ParenTypeId : 1; 559 // Is there an initializer? If not, built-ins are uninitialized, else they're 560 // value-initialized. 561 bool Initializer : 1; 562 // Do we allocate an array? If so, the first SubExpr is the size expression. 563 bool Array : 1; 564 // The number of placement new arguments. 565 unsigned NumPlacementArgs : 14; 566 // The number of constructor arguments. This may be 1 even for non-class 567 // types; use the pseudo copy constructor. 568 unsigned NumConstructorArgs : 14; 569 // Contains an optional array size expression, any number of optional 570 // placement arguments, and any number of optional constructor arguments, 571 // in that order. 572 Stmt **SubExprs; 573 // Points to the allocation function used. 574 FunctionDecl *OperatorNew; 575 // Points to the deallocation function used in case of error. May be null. 576 FunctionDecl *OperatorDelete; 577 // Points to the constructor used. Cannot be null if AllocType is a record; 578 // it would still point at the default constructor (even an implicit one). 579 // Must be null for all other types. 580 CXXConstructorDecl *Constructor; 581 582 SourceLocation StartLoc; 583 SourceLocation EndLoc; 584 585 // Deserialization constructor 586 CXXNewExpr(QualType ty, bool globalNew, bool parenTypeId, bool initializer, 587 bool array, unsigned numPlaceArgs, unsigned numConsArgs, 588 Stmt **subExprs, FunctionDecl *operatorNew, 589 FunctionDecl *operatorDelete, CXXConstructorDecl *constructor, 590 SourceLocation startLoc, SourceLocation endLoc) 591 : Expr(CXXNewExprClass, ty, ty->isDependentType(), ty->isDependentType()), 592 GlobalNew(globalNew), ParenTypeId(parenTypeId), 593 Initializer(initializer), Array(array), NumPlacementArgs(numPlaceArgs), 594 NumConstructorArgs(numConsArgs), SubExprs(subExprs), 595 OperatorNew(operatorNew), OperatorDelete(operatorDelete), 596 Constructor(constructor), StartLoc(startLoc), EndLoc(endLoc) 597 { } 598public: 599 CXXNewExpr(bool globalNew, FunctionDecl *operatorNew, Expr **placementArgs, 600 unsigned numPlaceArgs, bool ParenTypeId, Expr *arraySize, 601 CXXConstructorDecl *constructor, bool initializer, 602 Expr **constructorArgs, unsigned numConsArgs, 603 FunctionDecl *operatorDelete, QualType ty, 604 SourceLocation startLoc, SourceLocation endLoc); 605 ~CXXNewExpr() { 606 delete[] SubExprs; 607 } 608 609 QualType getAllocatedType() const { 610 assert(getType()->isPointerType()); 611 return getType()->getAsPointerType()->getPointeeType(); 612 } 613 614 FunctionDecl *getOperatorNew() const { return OperatorNew; } 615 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 616 CXXConstructorDecl *getConstructor() const { return Constructor; } 617 618 bool isArray() const { return Array; } 619 Expr *getArraySize() { 620 return Array ? cast<Expr>(SubExprs[0]) : 0; 621 } 622 const Expr *getArraySize() const { 623 return Array ? cast<Expr>(SubExprs[0]) : 0; 624 } 625 626 unsigned getNumPlacementArgs() const { return NumPlacementArgs; } 627 Expr *getPlacementArg(unsigned i) { 628 assert(i < NumPlacementArgs && "Index out of range"); 629 return cast<Expr>(SubExprs[Array + i]); 630 } 631 const Expr *getPlacementArg(unsigned i) const { 632 assert(i < NumPlacementArgs && "Index out of range"); 633 return cast<Expr>(SubExprs[Array + i]); 634 } 635 636 bool isGlobalNew() const { return GlobalNew; } 637 bool isParenTypeId() const { return ParenTypeId; } 638 bool hasInitializer() const { return Initializer; } 639 640 unsigned getNumConstructorArgs() const { return NumConstructorArgs; } 641 Expr *getConstructorArg(unsigned i) { 642 assert(i < NumConstructorArgs && "Index out of range"); 643 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 644 } 645 const Expr *getConstructorArg(unsigned i) const { 646 assert(i < NumConstructorArgs && "Index out of range"); 647 return cast<Expr>(SubExprs[Array + NumPlacementArgs + i]); 648 } 649 650 typedef ExprIterator arg_iterator; 651 typedef ConstExprIterator const_arg_iterator; 652 653 arg_iterator placement_arg_begin() { 654 return SubExprs + Array; 655 } 656 arg_iterator placement_arg_end() { 657 return SubExprs + Array + getNumPlacementArgs(); 658 } 659 const_arg_iterator placement_arg_begin() const { 660 return SubExprs + Array; 661 } 662 const_arg_iterator placement_arg_end() const { 663 return SubExprs + Array + getNumPlacementArgs(); 664 } 665 666 arg_iterator constructor_arg_begin() { 667 return SubExprs + Array + getNumPlacementArgs(); 668 } 669 arg_iterator constructor_arg_end() { 670 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 671 } 672 const_arg_iterator constructor_arg_begin() const { 673 return SubExprs + Array + getNumPlacementArgs(); 674 } 675 const_arg_iterator constructor_arg_end() const { 676 return SubExprs + Array + getNumPlacementArgs() + getNumConstructorArgs(); 677 } 678 679 virtual SourceRange getSourceRange() const { 680 return SourceRange(StartLoc, EndLoc); 681 } 682 683 static bool classof(const Stmt *T) { 684 return T->getStmtClass() == CXXNewExprClass; 685 } 686 static bool classof(const CXXNewExpr *) { return true; } 687 688 // Iterators 689 virtual child_iterator child_begin(); 690 virtual child_iterator child_end(); 691 692 virtual void EmitImpl(llvm::Serializer& S) const; 693 static CXXNewExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 694}; 695 696/// CXXDeleteExpr - A delete expression for memory deallocation and destructor 697/// calls, e.g. "delete[] pArray". 698class CXXDeleteExpr : public Expr { 699 // Is this a forced global delete, i.e. "::delete"? 700 bool GlobalDelete : 1; 701 // Is this the array form of delete, i.e. "delete[]"? 702 bool ArrayForm : 1; 703 // Points to the operator delete overload that is used. Could be a member. 704 FunctionDecl *OperatorDelete; 705 // The pointer expression to be deleted. 706 Stmt *Argument; 707 // Location of the expression. 708 SourceLocation Loc; 709public: 710 CXXDeleteExpr(QualType ty, bool globalDelete, bool arrayForm, 711 FunctionDecl *operatorDelete, Expr *arg, SourceLocation loc) 712 : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete), 713 ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg), 714 Loc(loc) { } 715 716 bool isGlobalDelete() const { return GlobalDelete; } 717 bool isArrayForm() const { return ArrayForm; } 718 719 FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 720 721 Expr *getArgument() { return cast<Expr>(Argument); } 722 const Expr *getArgument() const { return cast<Expr>(Argument); } 723 724 virtual SourceRange getSourceRange() const { 725 return SourceRange(Loc, Argument->getLocEnd()); 726 } 727 728 static bool classof(const Stmt *T) { 729 return T->getStmtClass() == CXXDeleteExprClass; 730 } 731 static bool classof(const CXXDeleteExpr *) { return true; } 732 733 // Iterators 734 virtual child_iterator child_begin(); 735 virtual child_iterator child_end(); 736 737 virtual void EmitImpl(llvm::Serializer& S) const; 738 static CXXDeleteExpr * CreateImpl(llvm::Deserializer& D, ASTContext& C); 739}; 740 741/// \brief Represents the name of a function that has not been 742/// resolved to any declaration. 743/// 744/// Unresolved function names occur when a function name is 745/// encountered prior to an open parentheses ('(') in a C++ function 746/// call, and the function name itself did not resolve to a 747/// declaration. These function names can only be resolved when they 748/// form the postfix-expression of a function call, so that 749/// argument-dependent lookup finds declarations corresponding to 750/// these functions. 751 752/// @code 753/// template<typename T> void f(T x) { 754/// g(x); // g is an unresolved function name (that is also a dependent name) 755/// } 756/// @endcode 757class UnresolvedFunctionNameExpr : public Expr { 758 /// The name that was present in the source 759 DeclarationName Name; 760 761 /// The location of this name in the source code 762 SourceLocation Loc; 763 764public: 765 UnresolvedFunctionNameExpr(DeclarationName N, QualType T, SourceLocation L) 766 : Expr(UnresolvedFunctionNameExprClass, T, false, false), Name(N), Loc(L) { } 767 768 /// \brief Retrieves the name that occurred in the source code. 769 DeclarationName getName() const { return Name; } 770 771 /// getLocation - Retrieves the location in the source code where 772 /// the name occurred. 773 SourceLocation getLocation() const { return Loc; } 774 775 virtual SourceRange getSourceRange() const { return SourceRange(Loc); } 776 777 static bool classof(const Stmt *T) { 778 return T->getStmtClass() == UnresolvedFunctionNameExprClass; 779 } 780 static bool classof(const UnresolvedFunctionNameExpr *) { return true; } 781 782 // Iterators 783 virtual child_iterator child_begin(); 784 virtual child_iterator child_end(); 785 786 virtual void EmitImpl(llvm::Serializer& S) const; 787 static UnresolvedFunctionNameExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C); 788}; 789 790/// UnaryTypeTraitExpr - A GCC or MS unary type trait, as used in the 791/// implementation of TR1/C++0x type trait templates. 792/// Example: 793/// __is_pod(int) == true 794/// __is_enum(std::string) == false 795class UnaryTypeTraitExpr : public Expr { 796 /// UTT - The trait. 797 UnaryTypeTrait UTT; 798 799 /// Loc - The location of the type trait keyword. 800 SourceLocation Loc; 801 802 /// RParen - The location of the closing paren. 803 SourceLocation RParen; 804 805 /// QueriedType - The type we're testing. 806 QualType QueriedType; 807 808public: 809 UnaryTypeTraitExpr(SourceLocation loc, UnaryTypeTrait utt, QualType queried, 810 SourceLocation rparen, QualType ty) 811 : Expr(UnaryTypeTraitExprClass, ty, false, queried->isDependentType()), 812 UTT(utt), Loc(loc), RParen(rparen), QueriedType(queried) { } 813 814 virtual SourceRange getSourceRange() const { return SourceRange(Loc, RParen);} 815 816 UnaryTypeTrait getTrait() const { return UTT; } 817 818 QualType getQueriedType() const { return QueriedType; } 819 820 bool EvaluateTrait() const; 821 822 static bool classof(const Stmt *T) { 823 return T->getStmtClass() == UnaryTypeTraitExprClass; 824 } 825 static bool classof(const UnaryTypeTraitExpr *) { return true; } 826 827 // Iterators 828 virtual child_iterator child_begin(); 829 virtual child_iterator child_end(); 830 831 virtual void EmitImpl(llvm::Serializer& S) const; 832 static UnaryTypeTraitExpr *CreateImpl(llvm::Deserializer& D, ASTContext& C); 833}; 834 835/// QualifiedDeclRefExpr - A reference to a declared variable, 836/// function, enum, etc., that includes a qualification, e.g., 837/// "N::foo". 838class QualifiedDeclRefExpr : public DeclRefExpr { 839 /// NestedNameLoc - The location of the beginning of the 840 /// nested-name-specifier that qualifies this declaration. 841 SourceLocation NestedNameLoc; 842 843public: 844 QualifiedDeclRefExpr(NamedDecl *d, QualType t, SourceLocation l, bool TD, 845 bool VD, SourceLocation nnl) 846 : DeclRefExpr(QualifiedDeclRefExprClass, d, t, l, TD, VD), 847 NestedNameLoc(nnl) { } 848 849 virtual SourceRange getSourceRange() const { 850 return SourceRange(NestedNameLoc, getLocation()); 851 } 852 853 static bool classof(const Stmt *T) { 854 return T->getStmtClass() == QualifiedDeclRefExprClass; 855 } 856 static bool classof(const QualifiedDeclRefExpr *) { return true; } 857 858 virtual void EmitImpl(llvm::Serializer& S) const; 859 static QualifiedDeclRefExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); 860}; 861 862} // end namespace clang 863 864#endif 865