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