clang API Documentation
00001 //===-- DeclCXX.h - Classes for representing C++ declarations -*- C++ -*-=====// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the C++ Decl subclasses, other than those for 00011 // templates (in DeclTemplate.h) and friends (in DeclFriend.h). 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_CLANG_AST_DECLCXX_H 00016 #define LLVM_CLANG_AST_DECLCXX_H 00017 00018 #include "clang/AST/Expr.h" 00019 #include "clang/AST/ExprCXX.h" 00020 #include "clang/AST/Decl.h" 00021 #include "clang/AST/TypeLoc.h" 00022 #include "clang/AST/UnresolvedSet.h" 00023 #include "llvm/ADT/DenseMap.h" 00024 #include "llvm/ADT/PointerIntPair.h" 00025 #include "llvm/ADT/SmallPtrSet.h" 00026 #include "llvm/Support/Compiler.h" 00027 00028 namespace clang { 00029 00030 class ClassTemplateDecl; 00031 class ClassTemplateSpecializationDecl; 00032 class CXXBasePath; 00033 class CXXBasePaths; 00034 class CXXConstructorDecl; 00035 class CXXConversionDecl; 00036 class CXXDestructorDecl; 00037 class CXXMethodDecl; 00038 class CXXRecordDecl; 00039 class CXXMemberLookupCriteria; 00040 class CXXFinalOverriderMap; 00041 class CXXIndirectPrimaryBaseSet; 00042 class FriendDecl; 00043 class LambdaExpr; 00044 00045 /// \brief Represents any kind of function declaration, whether it is a 00046 /// concrete function or a function template. 00047 class AnyFunctionDecl { 00048 NamedDecl *Function; 00049 00050 AnyFunctionDecl(NamedDecl *ND) : Function(ND) { } 00051 00052 public: 00053 AnyFunctionDecl(FunctionDecl *FD) : Function(FD) { } 00054 AnyFunctionDecl(FunctionTemplateDecl *FTD); 00055 00056 /// \brief Implicily converts any function or function template into a 00057 /// named declaration. 00058 operator NamedDecl *() const { return Function; } 00059 00060 /// \brief Retrieve the underlying function or function template. 00061 NamedDecl *get() const { return Function; } 00062 00063 static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) { 00064 return AnyFunctionDecl(ND); 00065 } 00066 }; 00067 00068 } // end namespace clang 00069 00070 namespace llvm { 00071 /// Implement simplify_type for AnyFunctionDecl, so that we can dyn_cast from 00072 /// AnyFunctionDecl to any function or function template declaration. 00073 template<> struct simplify_type<const ::clang::AnyFunctionDecl> { 00074 typedef ::clang::NamedDecl* SimpleType; 00075 static SimpleType getSimplifiedValue(const ::clang::AnyFunctionDecl &Val) { 00076 return Val; 00077 } 00078 }; 00079 template<> struct simplify_type< ::clang::AnyFunctionDecl> 00080 : public simplify_type<const ::clang::AnyFunctionDecl> {}; 00081 00082 // Provide PointerLikeTypeTraits for non-cvr pointers. 00083 template<> 00084 class PointerLikeTypeTraits< ::clang::AnyFunctionDecl> { 00085 public: 00086 static inline void *getAsVoidPointer(::clang::AnyFunctionDecl F) { 00087 return F.get(); 00088 } 00089 static inline ::clang::AnyFunctionDecl getFromVoidPointer(void *P) { 00090 return ::clang::AnyFunctionDecl::getFromNamedDecl( 00091 static_cast< ::clang::NamedDecl*>(P)); 00092 } 00093 00094 enum { NumLowBitsAvailable = 2 }; 00095 }; 00096 00097 } // end namespace llvm 00098 00099 namespace clang { 00100 00101 /// AccessSpecDecl - An access specifier followed by colon ':'. 00102 /// 00103 /// An objects of this class represents sugar for the syntactic occurrence 00104 /// of an access specifier followed by a colon in the list of member 00105 /// specifiers of a C++ class definition. 00106 /// 00107 /// Note that they do not represent other uses of access specifiers, 00108 /// such as those occurring in a list of base specifiers. 00109 /// Also note that this class has nothing to do with so-called 00110 /// "access declarations" (C++98 11.3 [class.access.dcl]). 00111 class AccessSpecDecl : public Decl { 00112 virtual void anchor(); 00113 /// ColonLoc - The location of the ':'. 00114 SourceLocation ColonLoc; 00115 00116 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, 00117 SourceLocation ASLoc, SourceLocation ColonLoc) 00118 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { 00119 setAccess(AS); 00120 } 00121 AccessSpecDecl(EmptyShell Empty) 00122 : Decl(AccessSpec, Empty) { } 00123 public: 00124 /// getAccessSpecifierLoc - The location of the access specifier. 00125 SourceLocation getAccessSpecifierLoc() const { return getLocation(); } 00126 /// setAccessSpecifierLoc - Sets the location of the access specifier. 00127 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } 00128 00129 /// getColonLoc - The location of the colon following the access specifier. 00130 SourceLocation getColonLoc() const { return ColonLoc; } 00131 /// setColonLoc - Sets the location of the colon. 00132 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } 00133 00134 SourceRange getSourceRange() const LLVM_READONLY { 00135 return SourceRange(getAccessSpecifierLoc(), getColonLoc()); 00136 } 00137 00138 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, 00139 DeclContext *DC, SourceLocation ASLoc, 00140 SourceLocation ColonLoc) { 00141 return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); 00142 } 00143 static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); 00144 00145 // Implement isa/cast/dyncast/etc. 00146 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 00147 static bool classof(const AccessSpecDecl *D) { return true; } 00148 static bool classofKind(Kind K) { return K == AccessSpec; } 00149 }; 00150 00151 00152 /// CXXBaseSpecifier - A base class of a C++ class. 00153 /// 00154 /// Each CXXBaseSpecifier represents a single, direct base class (or 00155 /// struct) of a C++ class (or struct). It specifies the type of that 00156 /// base class, whether it is a virtual or non-virtual base, and what 00157 /// level of access (public, protected, private) is used for the 00158 /// derivation. For example: 00159 /// 00160 /// @code 00161 /// class A { }; 00162 /// class B { }; 00163 /// class C : public virtual A, protected B { }; 00164 /// @endcode 00165 /// 00166 /// In this code, C will have two CXXBaseSpecifiers, one for "public 00167 /// virtual A" and the other for "protected B". 00168 class CXXBaseSpecifier { 00169 /// Range - The source code range that covers the full base 00170 /// specifier, including the "virtual" (if present) and access 00171 /// specifier (if present). 00172 SourceRange Range; 00173 00174 /// \brief The source location of the ellipsis, if this is a pack 00175 /// expansion. 00176 SourceLocation EllipsisLoc; 00177 00178 /// Virtual - Whether this is a virtual base class or not. 00179 bool Virtual : 1; 00180 00181 /// BaseOfClass - Whether this is the base of a class (true) or of a 00182 /// struct (false). This determines the mapping from the access 00183 /// specifier as written in the source code to the access specifier 00184 /// used for semantic analysis. 00185 bool BaseOfClass : 1; 00186 00187 /// Access - Access specifier as written in the source code (which 00188 /// may be AS_none). The actual type of data stored here is an 00189 /// AccessSpecifier, but we use "unsigned" here to work around a 00190 /// VC++ bug. 00191 unsigned Access : 2; 00192 00193 /// InheritConstructors - Whether the class contains a using declaration 00194 /// to inherit the named class's constructors. 00195 bool InheritConstructors : 1; 00196 00197 /// BaseTypeInfo - The type of the base class. This will be a class or struct 00198 /// (or a typedef of such). The source code range does not include the 00199 /// "virtual" or access specifier. 00200 TypeSourceInfo *BaseTypeInfo; 00201 00202 public: 00203 CXXBaseSpecifier() { } 00204 00205 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, 00206 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) 00207 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), 00208 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) { } 00209 00210 /// getSourceRange - Retrieves the source range that contains the 00211 /// entire base specifier. 00212 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 00213 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } 00214 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 00215 00216 /// isVirtual - Determines whether the base class is a virtual base 00217 /// class (or not). 00218 bool isVirtual() const { return Virtual; } 00219 00220 /// \brief Determine whether this base class is a base of a class declared 00221 /// with the 'class' keyword (vs. one declared with the 'struct' keyword). 00222 bool isBaseOfClass() const { return BaseOfClass; } 00223 00224 /// \brief Determine whether this base specifier is a pack expansion. 00225 bool isPackExpansion() const { return EllipsisLoc.isValid(); } 00226 00227 /// \brief Determine whether this base class's constructors get inherited. 00228 bool getInheritConstructors() const { return InheritConstructors; } 00229 00230 /// \brief Set that this base class's constructors should be inherited. 00231 void setInheritConstructors(bool Inherit = true) { 00232 InheritConstructors = Inherit; 00233 } 00234 00235 /// \brief For a pack expansion, determine the location of the ellipsis. 00236 SourceLocation getEllipsisLoc() const { 00237 return EllipsisLoc; 00238 } 00239 00240 /// getAccessSpecifier - Returns the access specifier for this base 00241 /// specifier. This is the actual base specifier as used for 00242 /// semantic analysis, so the result can never be AS_none. To 00243 /// retrieve the access specifier as written in the source code, use 00244 /// getAccessSpecifierAsWritten(). 00245 AccessSpecifier getAccessSpecifier() const { 00246 if ((AccessSpecifier)Access == AS_none) 00247 return BaseOfClass? AS_private : AS_public; 00248 else 00249 return (AccessSpecifier)Access; 00250 } 00251 00252 /// getAccessSpecifierAsWritten - Retrieves the access specifier as 00253 /// written in the source code (which may mean that no access 00254 /// specifier was explicitly written). Use getAccessSpecifier() to 00255 /// retrieve the access specifier for use in semantic analysis. 00256 AccessSpecifier getAccessSpecifierAsWritten() const { 00257 return (AccessSpecifier)Access; 00258 } 00259 00260 /// getType - Retrieves the type of the base class. This type will 00261 /// always be an unqualified class type. 00262 QualType getType() const { return BaseTypeInfo->getType(); } 00263 00264 /// getTypeLoc - Retrieves the type and source location of the base class. 00265 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } 00266 }; 00267 00268 /// CXXRecordDecl - Represents a C++ struct/union/class. 00269 /// FIXME: This class will disappear once we've properly taught RecordDecl 00270 /// to deal with C++-specific things. 00271 class CXXRecordDecl : public RecordDecl { 00272 00273 friend void TagDecl::startDefinition(); 00274 00275 struct DefinitionData { 00276 DefinitionData(CXXRecordDecl *D); 00277 00278 /// UserDeclaredConstructor - True when this class has a 00279 /// user-declared constructor. 00280 bool UserDeclaredConstructor : 1; 00281 00282 /// UserDeclaredCopyConstructor - True when this class has a 00283 /// user-declared copy constructor. 00284 bool UserDeclaredCopyConstructor : 1; 00285 00286 /// UserDeclareMoveConstructor - True when this class has a 00287 /// user-declared move constructor. 00288 bool UserDeclaredMoveConstructor : 1; 00289 00290 /// UserDeclaredCopyAssignment - True when this class has a 00291 /// user-declared copy assignment operator. 00292 bool UserDeclaredCopyAssignment : 1; 00293 00294 /// UserDeclareMoveAssignment - True when this class has a 00295 /// user-declared move assignment. 00296 bool UserDeclaredMoveAssignment : 1; 00297 00298 /// UserDeclaredDestructor - True when this class has a 00299 /// user-declared destructor. 00300 bool UserDeclaredDestructor : 1; 00301 00302 /// Aggregate - True when this class is an aggregate. 00303 bool Aggregate : 1; 00304 00305 /// PlainOldData - True when this class is a POD-type. 00306 bool PlainOldData : 1; 00307 00308 /// Empty - true when this class is empty for traits purposes, 00309 /// i.e. has no data members other than 0-width bit-fields, has no 00310 /// virtual function/base, and doesn't inherit from a non-empty 00311 /// class. Doesn't take union-ness into account. 00312 bool Empty : 1; 00313 00314 /// Polymorphic - True when this class is polymorphic, i.e. has at 00315 /// least one virtual member or derives from a polymorphic class. 00316 bool Polymorphic : 1; 00317 00318 /// Abstract - True when this class is abstract, i.e. has at least 00319 /// one pure virtual function, (that can come from a base class). 00320 bool Abstract : 1; 00321 00322 /// IsStandardLayout - True when this class has standard layout. 00323 /// 00324 /// C++0x [class]p7. A standard-layout class is a class that: 00325 /// * has no non-static data members of type non-standard-layout class (or 00326 /// array of such types) or reference, 00327 /// * has no virtual functions (10.3) and no virtual base classes (10.1), 00328 /// * has the same access control (Clause 11) for all non-static data 00329 /// members 00330 /// * has no non-standard-layout base classes, 00331 /// * either has no non-static data members in the most derived class and at 00332 /// most one base class with non-static data members, or has no base 00333 /// classes with non-static data members, and 00334 /// * has no base classes of the same type as the first non-static data 00335 /// member. 00336 bool IsStandardLayout : 1; 00337 00338 /// HasNoNonEmptyBases - True when there are no non-empty base classes. 00339 /// 00340 /// This is a helper bit of state used to implement IsStandardLayout more 00341 /// efficiently. 00342 bool HasNoNonEmptyBases : 1; 00343 00344 /// HasPrivateFields - True when there are private non-static data members. 00345 bool HasPrivateFields : 1; 00346 00347 /// HasProtectedFields - True when there are protected non-static data 00348 /// members. 00349 bool HasProtectedFields : 1; 00350 00351 /// HasPublicFields - True when there are private non-static data members. 00352 bool HasPublicFields : 1; 00353 00354 /// \brief True if this class (or any subobject) has mutable fields. 00355 bool HasMutableFields : 1; 00356 00357 /// \brief True if there no non-field members declared by the user. 00358 bool HasOnlyCMembers : 1; 00359 00360 /// \brief True if any field has an in-class initializer. 00361 bool HasInClassInitializer : 1; 00362 00363 /// HasTrivialDefaultConstructor - True when, if this class has a default 00364 /// constructor, this default constructor is trivial. 00365 /// 00366 /// C++0x [class.ctor]p5 00367 /// A default constructor is trivial if it is not user-provided and if 00368 /// -- its class has no virtual functions and no virtual base classes, 00369 /// and 00370 /// -- no non-static data member of its class has a 00371 /// brace-or-equal-initializer, and 00372 /// -- all the direct base classes of its class have trivial 00373 /// default constructors, and 00374 /// -- for all the nonstatic data members of its class that are of class 00375 /// type (or array thereof), each such class has a trivial 00376 /// default constructor. 00377 bool HasTrivialDefaultConstructor : 1; 00378 00379 /// HasConstexprNonCopyMoveConstructor - True when this class has at least 00380 /// one user-declared constexpr constructor which is neither the copy nor 00381 /// move constructor. 00382 bool HasConstexprNonCopyMoveConstructor : 1; 00383 00384 /// DefaultedDefaultConstructorIsConstexpr - True if a defaulted default 00385 /// constructor for this class would be constexpr. 00386 bool DefaultedDefaultConstructorIsConstexpr : 1; 00387 00388 /// DefaultedCopyConstructorIsConstexpr - True if a defaulted copy 00389 /// constructor for this class would be constexpr. 00390 bool DefaultedCopyConstructorIsConstexpr : 1; 00391 00392 /// DefaultedMoveConstructorIsConstexpr - True if a defaulted move 00393 /// constructor for this class would be constexpr. 00394 bool DefaultedMoveConstructorIsConstexpr : 1; 00395 00396 /// HasConstexprDefaultConstructor - True if this class has a constexpr 00397 /// default constructor (either user-declared or implicitly declared). 00398 bool HasConstexprDefaultConstructor : 1; 00399 00400 /// HasConstexprCopyConstructor - True if this class has a constexpr copy 00401 /// constructor (either user-declared or implicitly declared). 00402 bool HasConstexprCopyConstructor : 1; 00403 00404 /// HasConstexprMoveConstructor - True if this class has a constexpr move 00405 /// constructor (either user-declared or implicitly declared). 00406 bool HasConstexprMoveConstructor : 1; 00407 00408 /// HasTrivialCopyConstructor - True when this class has a trivial copy 00409 /// constructor. 00410 /// 00411 /// C++0x [class.copy]p13: 00412 /// A copy/move constructor for class X is trivial if it is neither 00413 /// user-provided and if 00414 /// -- class X has no virtual functions and no virtual base classes, and 00415 /// -- the constructor selected to copy/move each direct base class 00416 /// subobject is trivial, and 00417 /// -- for each non-static data member of X that is of class type (or an 00418 /// array thereof), the constructor selected to copy/move that member 00419 /// is trivial; 00420 /// otherwise the copy/move constructor is non-trivial. 00421 bool HasTrivialCopyConstructor : 1; 00422 00423 /// HasTrivialMoveConstructor - True when this class has a trivial move 00424 /// constructor. 00425 /// 00426 /// C++0x [class.copy]p13: 00427 /// A copy/move constructor for class X is trivial if it is neither 00428 /// user-provided and if 00429 /// -- class X has no virtual functions and no virtual base classes, and 00430 /// -- the constructor selected to copy/move each direct base class 00431 /// subobject is trivial, and 00432 /// -- for each non-static data member of X that is of class type (or an 00433 /// array thereof), the constructor selected to copy/move that member 00434 /// is trivial; 00435 /// otherwise the copy/move constructor is non-trivial. 00436 bool HasTrivialMoveConstructor : 1; 00437 00438 /// HasTrivialCopyAssignment - True when this class has a trivial copy 00439 /// assignment operator. 00440 /// 00441 /// C++0x [class.copy]p27: 00442 /// A copy/move assignment operator for class X is trivial if it is 00443 /// neither user-provided nor deleted and if 00444 /// -- class X has no virtual functions and no virtual base classes, and 00445 /// -- the assignment operator selected to copy/move each direct base 00446 /// class subobject is trivial, and 00447 /// -- for each non-static data member of X that is of class type (or an 00448 /// array thereof), the assignment operator selected to copy/move 00449 /// that member is trivial; 00450 /// otherwise the copy/move assignment operator is non-trivial. 00451 bool HasTrivialCopyAssignment : 1; 00452 00453 /// HasTrivialMoveAssignment - True when this class has a trivial move 00454 /// assignment operator. 00455 /// 00456 /// C++0x [class.copy]p27: 00457 /// A copy/move assignment operator for class X is trivial if it is 00458 /// neither user-provided nor deleted and if 00459 /// -- class X has no virtual functions and no virtual base classes, and 00460 /// -- the assignment operator selected to copy/move each direct base 00461 /// class subobject is trivial, and 00462 /// -- for each non-static data member of X that is of class type (or an 00463 /// array thereof), the assignment operator selected to copy/move 00464 /// that member is trivial; 00465 /// otherwise the copy/move assignment operator is non-trivial. 00466 bool HasTrivialMoveAssignment : 1; 00467 00468 /// HasTrivialDestructor - True when this class has a trivial destructor. 00469 /// 00470 /// C++ [class.dtor]p3. A destructor is trivial if it is an 00471 /// implicitly-declared destructor and if: 00472 /// * all of the direct base classes of its class have trivial destructors 00473 /// and 00474 /// * for all of the non-static data members of its class that are of class 00475 /// type (or array thereof), each such class has a trivial destructor. 00476 bool HasTrivialDestructor : 1; 00477 00478 /// HasIrrelevantDestructor - True when this class has a destructor with no 00479 /// semantic effect. 00480 bool HasIrrelevantDestructor : 1; 00481 00482 /// HasNonLiteralTypeFieldsOrBases - True when this class contains at least 00483 /// one non-static data member or base class of non-literal or volatile 00484 /// type. 00485 bool HasNonLiteralTypeFieldsOrBases : 1; 00486 00487 /// ComputedVisibleConversions - True when visible conversion functions are 00488 /// already computed and are available. 00489 bool ComputedVisibleConversions : 1; 00490 00491 /// \brief Whether we have a C++0x user-provided default constructor (not 00492 /// explicitly deleted or defaulted). 00493 bool UserProvidedDefaultConstructor : 1; 00494 00495 /// \brief Whether we have already declared the default constructor. 00496 bool DeclaredDefaultConstructor : 1; 00497 00498 /// \brief Whether we have already declared the copy constructor. 00499 bool DeclaredCopyConstructor : 1; 00500 00501 /// \brief Whether we have already declared the move constructor. 00502 bool DeclaredMoveConstructor : 1; 00503 00504 /// \brief Whether we have already declared the copy-assignment operator. 00505 bool DeclaredCopyAssignment : 1; 00506 00507 /// \brief Whether we have already declared the move-assignment operator. 00508 bool DeclaredMoveAssignment : 1; 00509 00510 /// \brief Whether we have already declared a destructor within the class. 00511 bool DeclaredDestructor : 1; 00512 00513 /// \brief Whether an implicit move constructor was attempted to be declared 00514 /// but would have been deleted. 00515 bool FailedImplicitMoveConstructor : 1; 00516 00517 /// \brief Whether an implicit move assignment operator was attempted to be 00518 /// declared but would have been deleted. 00519 bool FailedImplicitMoveAssignment : 1; 00520 00521 /// \brief Whether this class describes a C++ lambda. 00522 bool IsLambda : 1; 00523 00524 /// NumBases - The number of base class specifiers in Bases. 00525 unsigned NumBases; 00526 00527 /// NumVBases - The number of virtual base class specifiers in VBases. 00528 unsigned NumVBases; 00529 00530 /// Bases - Base classes of this class. 00531 /// FIXME: This is wasted space for a union. 00532 LazyCXXBaseSpecifiersPtr Bases; 00533 00534 /// VBases - direct and indirect virtual base classes of this class. 00535 LazyCXXBaseSpecifiersPtr VBases; 00536 00537 /// Conversions - Overload set containing the conversion functions 00538 /// of this C++ class (but not its inherited conversion 00539 /// functions). Each of the entries in this overload set is a 00540 /// CXXConversionDecl. 00541 UnresolvedSet<4> Conversions; 00542 00543 /// VisibleConversions - Overload set containing the conversion 00544 /// functions of this C++ class and all those inherited conversion 00545 /// functions that are visible in this class. Each of the entries 00546 /// in this overload set is a CXXConversionDecl or a 00547 /// FunctionTemplateDecl. 00548 UnresolvedSet<4> VisibleConversions; 00549 00550 /// Definition - The declaration which defines this record. 00551 CXXRecordDecl *Definition; 00552 00553 /// FirstFriend - The first friend declaration in this class, or 00554 /// null if there aren't any. This is actually currently stored 00555 /// in reverse order. 00556 FriendDecl *FirstFriend; 00557 00558 /// \brief Retrieve the set of direct base classes. 00559 CXXBaseSpecifier *getBases() const { 00560 return Bases.get(Definition->getASTContext().getExternalSource()); 00561 } 00562 00563 /// \brief Retrieve the set of virtual base classes. 00564 CXXBaseSpecifier *getVBases() const { 00565 return VBases.get(Definition->getASTContext().getExternalSource()); 00566 } 00567 } *DefinitionData; 00568 00569 /// \brief Describes a C++ closure type (generated by a lambda expression). 00570 struct LambdaDefinitionData : public DefinitionData { 00571 typedef LambdaExpr::Capture Capture; 00572 00573 LambdaDefinitionData(CXXRecordDecl *D, bool Dependent) 00574 : DefinitionData(D), Dependent(Dependent), NumCaptures(0), 00575 NumExplicitCaptures(0), ManglingNumber(0), ContextDecl(0), Captures(0) 00576 { 00577 IsLambda = true; 00578 } 00579 00580 /// \brief Whether this lambda is known to be dependent, even if its 00581 /// context isn't dependent. 00582 /// 00583 /// A lambda with a non-dependent context can be dependent if it occurs 00584 /// within the default argument of a function template, because the 00585 /// lambda will have been created with the enclosing context as its 00586 /// declaration context, rather than function. This is an unfortunate 00587 /// artifact of having to parse the default arguments before 00588 unsigned Dependent : 1; 00589 00590 /// \brief The number of captures in this lambda. 00591 unsigned NumCaptures : 16; 00592 00593 /// \brief The number of explicit captures in this lambda. 00594 unsigned NumExplicitCaptures : 15; 00595 00596 /// \brief The number used to indicate this lambda expression for name 00597 /// mangling in the Itanium C++ ABI. 00598 unsigned ManglingNumber; 00599 00600 /// \brief The declaration that provides context for this lambda, if the 00601 /// actual DeclContext does not suffice. This is used for lambdas that 00602 /// occur within default arguments of function parameters within the class 00603 /// or within a data member initializer. 00604 Decl *ContextDecl; 00605 00606 /// \brief The list of captures, both explicit and implicit, for this 00607 /// lambda. 00608 Capture *Captures; 00609 }; 00610 00611 struct DefinitionData &data() { 00612 assert(DefinitionData && "queried property of class with no definition"); 00613 return *DefinitionData; 00614 } 00615 00616 const struct DefinitionData &data() const { 00617 assert(DefinitionData && "queried property of class with no definition"); 00618 return *DefinitionData; 00619 } 00620 00621 struct LambdaDefinitionData &getLambdaData() const { 00622 assert(DefinitionData && "queried property of lambda with no definition"); 00623 assert(DefinitionData->IsLambda && 00624 "queried lambda property of non-lambda class"); 00625 return static_cast<LambdaDefinitionData &>(*DefinitionData); 00626 } 00627 00628 /// \brief The template or declaration that this declaration 00629 /// describes or was instantiated from, respectively. 00630 /// 00631 /// For non-templates, this value will be NULL. For record 00632 /// declarations that describe a class template, this will be a 00633 /// pointer to a ClassTemplateDecl. For member 00634 /// classes of class template specializations, this will be the 00635 /// MemberSpecializationInfo referring to the member class that was 00636 /// instantiated or specialized. 00637 llvm::PointerUnion<ClassTemplateDecl*, MemberSpecializationInfo*> 00638 TemplateOrInstantiation; 00639 00640 friend class DeclContext; 00641 friend class LambdaExpr; 00642 00643 /// \brief Notify the class that member has been added. 00644 /// 00645 /// This routine helps maintain information about the class based on which 00646 /// members have been added. It will be invoked by DeclContext::addDecl() 00647 /// whenever a member is added to this record. 00648 void addedMember(Decl *D); 00649 00650 void markedVirtualFunctionPure(); 00651 friend void FunctionDecl::setPure(bool); 00652 00653 friend class ASTNodeImporter; 00654 00655 protected: 00656 CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, 00657 SourceLocation StartLoc, SourceLocation IdLoc, 00658 IdentifierInfo *Id, CXXRecordDecl *PrevDecl); 00659 00660 public: 00661 /// base_class_iterator - Iterator that traverses the base classes 00662 /// of a class. 00663 typedef CXXBaseSpecifier* base_class_iterator; 00664 00665 /// base_class_const_iterator - Iterator that traverses the base 00666 /// classes of a class. 00667 typedef const CXXBaseSpecifier* base_class_const_iterator; 00668 00669 /// reverse_base_class_iterator = Iterator that traverses the base classes 00670 /// of a class in reverse order. 00671 typedef std::reverse_iterator<base_class_iterator> 00672 reverse_base_class_iterator; 00673 00674 /// reverse_base_class_iterator = Iterator that traverses the base classes 00675 /// of a class in reverse order. 00676 typedef std::reverse_iterator<base_class_const_iterator> 00677 reverse_base_class_const_iterator; 00678 00679 virtual CXXRecordDecl *getCanonicalDecl() { 00680 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 00681 } 00682 virtual const CXXRecordDecl *getCanonicalDecl() const { 00683 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); 00684 } 00685 00686 const CXXRecordDecl *getPreviousDecl() const { 00687 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDecl()); 00688 } 00689 CXXRecordDecl *getPreviousDecl() { 00690 return cast_or_null<CXXRecordDecl>(RecordDecl::getPreviousDecl()); 00691 } 00692 00693 const CXXRecordDecl *getMostRecentDecl() const { 00694 return cast_or_null<CXXRecordDecl>(RecordDecl::getMostRecentDecl()); 00695 } 00696 CXXRecordDecl *getMostRecentDecl() { 00697 return cast_or_null<CXXRecordDecl>(RecordDecl::getMostRecentDecl()); 00698 } 00699 00700 CXXRecordDecl *getDefinition() const { 00701 if (!DefinitionData) return 0; 00702 return data().Definition; 00703 } 00704 00705 bool hasDefinition() const { return DefinitionData != 0; } 00706 00707 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, 00708 SourceLocation StartLoc, SourceLocation IdLoc, 00709 IdentifierInfo *Id, CXXRecordDecl* PrevDecl=0, 00710 bool DelayTypeCreation = false); 00711 static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC, 00712 SourceLocation Loc, bool DependentLambda); 00713 static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); 00714 00715 bool isDynamicClass() const { 00716 return data().Polymorphic || data().NumVBases != 0; 00717 } 00718 00719 /// setBases - Sets the base classes of this struct or class. 00720 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); 00721 00722 /// getNumBases - Retrieves the number of base classes of this 00723 /// class. 00724 unsigned getNumBases() const { return data().NumBases; } 00725 00726 base_class_iterator bases_begin() { return data().getBases(); } 00727 base_class_const_iterator bases_begin() const { return data().getBases(); } 00728 base_class_iterator bases_end() { return bases_begin() + data().NumBases; } 00729 base_class_const_iterator bases_end() const { 00730 return bases_begin() + data().NumBases; 00731 } 00732 reverse_base_class_iterator bases_rbegin() { 00733 return reverse_base_class_iterator(bases_end()); 00734 } 00735 reverse_base_class_const_iterator bases_rbegin() const { 00736 return reverse_base_class_const_iterator(bases_end()); 00737 } 00738 reverse_base_class_iterator bases_rend() { 00739 return reverse_base_class_iterator(bases_begin()); 00740 } 00741 reverse_base_class_const_iterator bases_rend() const { 00742 return reverse_base_class_const_iterator(bases_begin()); 00743 } 00744 00745 /// getNumVBases - Retrieves the number of virtual base classes of this 00746 /// class. 00747 unsigned getNumVBases() const { return data().NumVBases; } 00748 00749 base_class_iterator vbases_begin() { return data().getVBases(); } 00750 base_class_const_iterator vbases_begin() const { return data().getVBases(); } 00751 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } 00752 base_class_const_iterator vbases_end() const { 00753 return vbases_begin() + data().NumVBases; 00754 } 00755 reverse_base_class_iterator vbases_rbegin() { 00756 return reverse_base_class_iterator(vbases_end()); 00757 } 00758 reverse_base_class_const_iterator vbases_rbegin() const { 00759 return reverse_base_class_const_iterator(vbases_end()); 00760 } 00761 reverse_base_class_iterator vbases_rend() { 00762 return reverse_base_class_iterator(vbases_begin()); 00763 } 00764 reverse_base_class_const_iterator vbases_rend() const { 00765 return reverse_base_class_const_iterator(vbases_begin()); 00766 } 00767 00768 /// \brief Determine whether this class has any dependent base classes. 00769 bool hasAnyDependentBases() const; 00770 00771 /// Iterator access to method members. The method iterator visits 00772 /// all method members of the class, including non-instance methods, 00773 /// special methods, etc. 00774 typedef specific_decl_iterator<CXXMethodDecl> method_iterator; 00775 00776 /// method_begin - Method begin iterator. Iterates in the order the methods 00777 /// were declared. 00778 method_iterator method_begin() const { 00779 return method_iterator(decls_begin()); 00780 } 00781 /// method_end - Method end iterator. 00782 method_iterator method_end() const { 00783 return method_iterator(decls_end()); 00784 } 00785 00786 /// Iterator access to constructor members. 00787 typedef specific_decl_iterator<CXXConstructorDecl> ctor_iterator; 00788 00789 ctor_iterator ctor_begin() const { 00790 return ctor_iterator(decls_begin()); 00791 } 00792 ctor_iterator ctor_end() const { 00793 return ctor_iterator(decls_end()); 00794 } 00795 00796 /// An iterator over friend declarations. All of these are defined 00797 /// in DeclFriend.h. 00798 class friend_iterator; 00799 friend_iterator friend_begin() const; 00800 friend_iterator friend_end() const; 00801 void pushFriendDecl(FriendDecl *FD); 00802 00803 /// Determines whether this record has any friends. 00804 bool hasFriends() const { 00805 return data().FirstFriend != 0; 00806 } 00807 00808 /// \brief Determine if we need to declare a default constructor for 00809 /// this class. 00810 /// 00811 /// This value is used for lazy creation of default constructors. 00812 bool needsImplicitDefaultConstructor() const { 00813 return !data().UserDeclaredConstructor && 00814 !data().DeclaredDefaultConstructor; 00815 } 00816 00817 /// hasDeclaredDefaultConstructor - Whether this class's default constructor 00818 /// has been declared (either explicitly or implicitly). 00819 bool hasDeclaredDefaultConstructor() const { 00820 return data().DeclaredDefaultConstructor; 00821 } 00822 00823 /// hasConstCopyConstructor - Determines whether this class has a 00824 /// copy constructor that accepts a const-qualified argument. 00825 bool hasConstCopyConstructor() const; 00826 00827 /// getCopyConstructor - Returns the copy constructor for this class 00828 CXXConstructorDecl *getCopyConstructor(unsigned TypeQuals) const; 00829 00830 /// getMoveConstructor - Returns the move constructor for this class 00831 CXXConstructorDecl *getMoveConstructor() const; 00832 00833 /// \brief Retrieve the copy-assignment operator for this class, if available. 00834 /// 00835 /// This routine attempts to find the copy-assignment operator for this 00836 /// class, using a simplistic form of overload resolution. 00837 /// 00838 /// \param ArgIsConst Whether the argument to the copy-assignment operator 00839 /// is const-qualified. 00840 /// 00841 /// \returns The copy-assignment operator that can be invoked, or NULL if 00842 /// a unique copy-assignment operator could not be found. 00843 CXXMethodDecl *getCopyAssignmentOperator(bool ArgIsConst) const; 00844 00845 /// getMoveAssignmentOperator - Returns the move assignment operator for this 00846 /// class 00847 CXXMethodDecl *getMoveAssignmentOperator() const; 00848 00849 /// hasUserDeclaredConstructor - Whether this class has any 00850 /// user-declared constructors. When true, a default constructor 00851 /// will not be implicitly declared. 00852 bool hasUserDeclaredConstructor() const { 00853 return data().UserDeclaredConstructor; 00854 } 00855 00856 /// hasUserProvidedDefaultconstructor - Whether this class has a 00857 /// user-provided default constructor per C++0x. 00858 bool hasUserProvidedDefaultConstructor() const { 00859 return data().UserProvidedDefaultConstructor; 00860 } 00861 00862 /// hasUserDeclaredCopyConstructor - Whether this class has a 00863 /// user-declared copy constructor. When false, a copy constructor 00864 /// will be implicitly declared. 00865 bool hasUserDeclaredCopyConstructor() const { 00866 return data().UserDeclaredCopyConstructor; 00867 } 00868 00869 /// \brief Determine whether this class has had its copy constructor 00870 /// declared, either via the user or via an implicit declaration. 00871 /// 00872 /// This value is used for lazy creation of copy constructors. 00873 bool hasDeclaredCopyConstructor() const { 00874 return data().DeclaredCopyConstructor; 00875 } 00876 00877 /// hasUserDeclaredMoveOperation - Whether this class has a user- 00878 /// declared move constructor or assignment operator. When false, a 00879 /// move constructor and assignment operator may be implicitly declared. 00880 bool hasUserDeclaredMoveOperation() const { 00881 return data().UserDeclaredMoveConstructor || 00882 data().UserDeclaredMoveAssignment; 00883 } 00884 00885 /// \brief Determine whether this class has had a move constructor 00886 /// declared by the user. 00887 bool hasUserDeclaredMoveConstructor() const { 00888 return data().UserDeclaredMoveConstructor; 00889 } 00890 00891 /// \brief Determine whether this class has had a move constructor 00892 /// declared. 00893 bool hasDeclaredMoveConstructor() const { 00894 return data().DeclaredMoveConstructor; 00895 } 00896 00897 /// \brief Determine whether implicit move constructor generation for this 00898 /// class has failed before. 00899 bool hasFailedImplicitMoveConstructor() const { 00900 return data().FailedImplicitMoveConstructor; 00901 } 00902 00903 /// \brief Set whether implicit move constructor generation for this class 00904 /// has failed before. 00905 void setFailedImplicitMoveConstructor(bool Failed = true) { 00906 data().FailedImplicitMoveConstructor = Failed; 00907 } 00908 00909 /// \brief Determine whether this class should get an implicit move 00910 /// constructor or if any existing special member function inhibits this. 00911 /// 00912 /// Covers all bullets of C++0x [class.copy]p9 except the last, that the 00913 /// constructor wouldn't be deleted, which is only looked up from a cached 00914 /// result. 00915 bool needsImplicitMoveConstructor() const { 00916 return !hasFailedImplicitMoveConstructor() && 00917 !hasDeclaredMoveConstructor() && 00918 !hasUserDeclaredCopyConstructor() && 00919 !hasUserDeclaredCopyAssignment() && 00920 !hasUserDeclaredMoveAssignment() && 00921 !hasUserDeclaredDestructor(); 00922 } 00923 00924 /// hasUserDeclaredCopyAssignment - Whether this class has a 00925 /// user-declared copy assignment operator. When false, a copy 00926 /// assigment operator will be implicitly declared. 00927 bool hasUserDeclaredCopyAssignment() const { 00928 return data().UserDeclaredCopyAssignment; 00929 } 00930 00931 /// \brief Determine whether this class has had its copy assignment operator 00932 /// declared, either via the user or via an implicit declaration. 00933 /// 00934 /// This value is used for lazy creation of copy assignment operators. 00935 bool hasDeclaredCopyAssignment() const { 00936 return data().DeclaredCopyAssignment; 00937 } 00938 00939 /// \brief Determine whether this class has had a move assignment 00940 /// declared by the user. 00941 bool hasUserDeclaredMoveAssignment() const { 00942 return data().UserDeclaredMoveAssignment; 00943 } 00944 00945 /// hasDeclaredMoveAssignment - Whether this class has a 00946 /// declared move assignment operator. 00947 bool hasDeclaredMoveAssignment() const { 00948 return data().DeclaredMoveAssignment; 00949 } 00950 00951 /// \brief Determine whether implicit move assignment generation for this 00952 /// class has failed before. 00953 bool hasFailedImplicitMoveAssignment() const { 00954 return data().FailedImplicitMoveAssignment; 00955 } 00956 00957 /// \brief Set whether implicit move assignment generation for this class 00958 /// has failed before. 00959 void setFailedImplicitMoveAssignment(bool Failed = true) { 00960 data().FailedImplicitMoveAssignment = Failed; 00961 } 00962 00963 /// \brief Determine whether this class should get an implicit move 00964 /// assignment operator or if any existing special member function inhibits 00965 /// this. 00966 /// 00967 /// Covers all bullets of C++0x [class.copy]p20 except the last, that the 00968 /// constructor wouldn't be deleted. 00969 bool needsImplicitMoveAssignment() const { 00970 return !hasFailedImplicitMoveAssignment() && 00971 !hasDeclaredMoveAssignment() && 00972 !hasUserDeclaredCopyConstructor() && 00973 !hasUserDeclaredCopyAssignment() && 00974 !hasUserDeclaredMoveConstructor() && 00975 !hasUserDeclaredDestructor(); 00976 } 00977 00978 /// hasUserDeclaredDestructor - Whether this class has a 00979 /// user-declared destructor. When false, a destructor will be 00980 /// implicitly declared. 00981 bool hasUserDeclaredDestructor() const { 00982 return data().UserDeclaredDestructor; 00983 } 00984 00985 /// \brief Determine whether this class has had its destructor declared, 00986 /// either via the user or via an implicit declaration. 00987 /// 00988 /// This value is used for lazy creation of destructors. 00989 bool hasDeclaredDestructor() const { return data().DeclaredDestructor; } 00990 00991 /// \brief Determine whether this class describes a lambda function object. 00992 bool isLambda() const { return hasDefinition() && data().IsLambda; } 00993 00994 /// \brief For a closure type, retrieve the mapping from captured 00995 /// variables and this to the non-static data members that store the 00996 /// values or references of the captures. 00997 /// 00998 /// \param Captures Will be populated with the mapping from captured 00999 /// variables to the corresponding fields. 01000 /// 01001 /// \param ThisCapture Will be set to the field declaration for the 01002 /// 'this' capture. 01003 void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, 01004 FieldDecl *&ThisCapture) const; 01005 01006 typedef const LambdaExpr::Capture* capture_const_iterator; 01007 capture_const_iterator captures_begin() const { 01008 return isLambda() ? getLambdaData().Captures : NULL; 01009 } 01010 capture_const_iterator captures_end() const { 01011 return isLambda() ? captures_begin() + getLambdaData().NumCaptures : NULL; 01012 } 01013 01014 /// getConversions - Retrieve the overload set containing all of the 01015 /// conversion functions in this class. 01016 UnresolvedSetImpl *getConversionFunctions() { 01017 return &data().Conversions; 01018 } 01019 const UnresolvedSetImpl *getConversionFunctions() const { 01020 return &data().Conversions; 01021 } 01022 01023 typedef UnresolvedSetImpl::iterator conversion_iterator; 01024 conversion_iterator conversion_begin() const { 01025 return getConversionFunctions()->begin(); 01026 } 01027 conversion_iterator conversion_end() const { 01028 return getConversionFunctions()->end(); 01029 } 01030 01031 /// Removes a conversion function from this class. The conversion 01032 /// function must currently be a member of this class. Furthermore, 01033 /// this class must currently be in the process of being defined. 01034 void removeConversion(const NamedDecl *Old); 01035 01036 /// getVisibleConversionFunctions - get all conversion functions visible 01037 /// in current class; including conversion function templates. 01038 const UnresolvedSetImpl *getVisibleConversionFunctions(); 01039 01040 /// isAggregate - Whether this class is an aggregate (C++ 01041 /// [dcl.init.aggr]), which is a class with no user-declared 01042 /// constructors, no private or protected non-static data members, 01043 /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). 01044 bool isAggregate() const { return data().Aggregate; } 01045 01046 /// hasInClassInitializer - Whether this class has any in-class initializers 01047 /// for non-static data members. 01048 bool hasInClassInitializer() const { return data().HasInClassInitializer; } 01049 01050 /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class 01051 /// that is an aggregate that has no non-static non-POD data members, no 01052 /// reference data members, no user-defined copy assignment operator and no 01053 /// user-defined destructor. 01054 bool isPOD() const { return data().PlainOldData; } 01055 01056 /// \brief True if this class is C-like, without C++-specific features, e.g. 01057 /// it contains only public fields, no bases, tag kind is not 'class', etc. 01058 bool isCLike() const; 01059 01060 /// isEmpty - Whether this class is empty (C++0x [meta.unary.prop]), which 01061 /// means it has a virtual function, virtual base, data member (other than 01062 /// 0-width bit-field) or inherits from a non-empty class. Does NOT include 01063 /// a check for union-ness. 01064 bool isEmpty() const { return data().Empty; } 01065 01066 /// isPolymorphic - Whether this class is polymorphic (C++ [class.virtual]), 01067 /// which means that the class contains or inherits a virtual function. 01068 bool isPolymorphic() const { return data().Polymorphic; } 01069 01070 /// isAbstract - Whether this class is abstract (C++ [class.abstract]), 01071 /// which means that the class contains or inherits a pure virtual function. 01072 bool isAbstract() const { return data().Abstract; } 01073 01074 /// isStandardLayout - Whether this class has standard layout 01075 /// (C++ [class]p7) 01076 bool isStandardLayout() const { return data().IsStandardLayout; } 01077 01078 /// \brief Whether this class, or any of its class subobjects, contains a 01079 /// mutable field. 01080 bool hasMutableFields() const { return data().HasMutableFields; } 01081 01082 /// hasTrivialDefaultConstructor - Whether this class has a trivial default 01083 /// constructor (C++11 [class.ctor]p5). 01084 bool hasTrivialDefaultConstructor() const { 01085 return data().HasTrivialDefaultConstructor && 01086 (!data().UserDeclaredConstructor || 01087 data().DeclaredDefaultConstructor); 01088 } 01089 01090 /// hasConstexprNonCopyMoveConstructor - Whether this class has at least one 01091 /// constexpr constructor other than the copy or move constructors. 01092 bool hasConstexprNonCopyMoveConstructor() const { 01093 return data().HasConstexprNonCopyMoveConstructor || 01094 (!hasUserDeclaredConstructor() && 01095 defaultedDefaultConstructorIsConstexpr()); 01096 } 01097 01098 /// defaultedDefaultConstructorIsConstexpr - Whether a defaulted default 01099 /// constructor for this class would be constexpr. 01100 bool defaultedDefaultConstructorIsConstexpr() const { 01101 return data().DefaultedDefaultConstructorIsConstexpr && 01102 (!isUnion() || hasInClassInitializer()); 01103 } 01104 01105 /// defaultedCopyConstructorIsConstexpr - Whether a defaulted copy 01106 /// constructor for this class would be constexpr. 01107 bool defaultedCopyConstructorIsConstexpr() const { 01108 return data().DefaultedCopyConstructorIsConstexpr; 01109 } 01110 01111 /// defaultedMoveConstructorIsConstexpr - Whether a defaulted move 01112 /// constructor for this class would be constexpr. 01113 bool defaultedMoveConstructorIsConstexpr() const { 01114 return data().DefaultedMoveConstructorIsConstexpr; 01115 } 01116 01117 /// hasConstexprDefaultConstructor - Whether this class has a constexpr 01118 /// default constructor. 01119 bool hasConstexprDefaultConstructor() const { 01120 return data().HasConstexprDefaultConstructor || 01121 (!data().UserDeclaredConstructor && 01122 defaultedDefaultConstructorIsConstexpr() && isLiteral()); 01123 } 01124 01125 /// hasConstexprCopyConstructor - Whether this class has a constexpr copy 01126 /// constructor. 01127 bool hasConstexprCopyConstructor() const { 01128 return data().HasConstexprCopyConstructor || 01129 (!data().DeclaredCopyConstructor && 01130 data().DefaultedCopyConstructorIsConstexpr && isLiteral()); 01131 } 01132 01133 /// hasConstexprMoveConstructor - Whether this class has a constexpr move 01134 /// constructor. 01135 bool hasConstexprMoveConstructor() const { 01136 return data().HasConstexprMoveConstructor || 01137 (needsImplicitMoveConstructor() && 01138 data().DefaultedMoveConstructorIsConstexpr && isLiteral()); 01139 } 01140 01141 // hasTrivialCopyConstructor - Whether this class has a trivial copy 01142 // constructor (C++ [class.copy]p6, C++0x [class.copy]p13) 01143 bool hasTrivialCopyConstructor() const { 01144 return data().HasTrivialCopyConstructor; 01145 } 01146 01147 // hasTrivialMoveConstructor - Whether this class has a trivial move 01148 // constructor (C++0x [class.copy]p13) 01149 bool hasTrivialMoveConstructor() const { 01150 return data().HasTrivialMoveConstructor; 01151 } 01152 01153 // hasTrivialCopyAssignment - Whether this class has a trivial copy 01154 // assignment operator (C++ [class.copy]p11, C++0x [class.copy]p27) 01155 bool hasTrivialCopyAssignment() const { 01156 return data().HasTrivialCopyAssignment; 01157 } 01158 01159 // hasTrivialMoveAssignment - Whether this class has a trivial move 01160 // assignment operator (C++0x [class.copy]p27) 01161 bool hasTrivialMoveAssignment() const { 01162 return data().HasTrivialMoveAssignment; 01163 } 01164 01165 // hasTrivialDestructor - Whether this class has a trivial destructor 01166 // (C++ [class.dtor]p3) 01167 bool hasTrivialDestructor() const { return data().HasTrivialDestructor; } 01168 01169 // hasIrrelevantDestructor - Whether this class has a destructor which has no 01170 // semantic effect. Any such destructor will be trivial, public, defaulted 01171 // and not deleted, and will call only irrelevant destructors. 01172 bool hasIrrelevantDestructor() const { 01173 return data().HasIrrelevantDestructor; 01174 } 01175 01176 // hasNonLiteralTypeFieldsOrBases - Whether this class has a non-literal or 01177 // volatile type non-static data member or base class. 01178 bool hasNonLiteralTypeFieldsOrBases() const { 01179 return data().HasNonLiteralTypeFieldsOrBases; 01180 } 01181 01182 // isTriviallyCopyable - Whether this class is considered trivially copyable 01183 // (C++0x [class]p6). 01184 bool isTriviallyCopyable() const; 01185 01186 // isTrivial - Whether this class is considered trivial 01187 // 01188 // C++0x [class]p6 01189 // A trivial class is a class that has a trivial default constructor and 01190 // is trivially copiable. 01191 bool isTrivial() const { 01192 return isTriviallyCopyable() && hasTrivialDefaultConstructor(); 01193 } 01194 01195 // isLiteral - Whether this class is a literal type. 01196 // 01197 // C++11 [basic.types]p10 01198 // A class type that has all the following properties: 01199 // -- it has a trivial destructor 01200 // -- every constructor call and full-expression in the 01201 // brace-or-equal-intializers for non-static data members (if any) is 01202 // a constant expression. 01203 // -- it is an aggregate type or has at least one constexpr constructor or 01204 // constructor template that is not a copy or move constructor, and 01205 // -- all of its non-static data members and base classes are of literal 01206 // types 01207 // 01208 // We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by 01209 // treating types with trivial default constructors as literal types. 01210 bool isLiteral() const { 01211 return hasTrivialDestructor() && 01212 (isAggregate() || hasConstexprNonCopyMoveConstructor() || 01213 hasTrivialDefaultConstructor()) && 01214 !hasNonLiteralTypeFieldsOrBases(); 01215 } 01216 01217 /// \brief If this record is an instantiation of a member class, 01218 /// retrieves the member class from which it was instantiated. 01219 /// 01220 /// This routine will return non-NULL for (non-templated) member 01221 /// classes of class templates. For example, given: 01222 /// 01223 /// \code 01224 /// template<typename T> 01225 /// struct X { 01226 /// struct A { }; 01227 /// }; 01228 /// \endcode 01229 /// 01230 /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl 01231 /// whose parent is the class template specialization X<int>. For 01232 /// this declaration, getInstantiatedFromMemberClass() will return 01233 /// the CXXRecordDecl X<T>::A. When a complete definition of 01234 /// X<int>::A is required, it will be instantiated from the 01235 /// declaration returned by getInstantiatedFromMemberClass(). 01236 CXXRecordDecl *getInstantiatedFromMemberClass() const; 01237 01238 /// \brief If this class is an instantiation of a member class of a 01239 /// class template specialization, retrieves the member specialization 01240 /// information. 01241 MemberSpecializationInfo *getMemberSpecializationInfo() const; 01242 01243 /// \brief Specify that this record is an instantiation of the 01244 /// member class RD. 01245 void setInstantiationOfMemberClass(CXXRecordDecl *RD, 01246 TemplateSpecializationKind TSK); 01247 01248 /// \brief Retrieves the class template that is described by this 01249 /// class declaration. 01250 /// 01251 /// Every class template is represented as a ClassTemplateDecl and a 01252 /// CXXRecordDecl. The former contains template properties (such as 01253 /// the template parameter lists) while the latter contains the 01254 /// actual description of the template's 01255 /// contents. ClassTemplateDecl::getTemplatedDecl() retrieves the 01256 /// CXXRecordDecl that from a ClassTemplateDecl, while 01257 /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from 01258 /// a CXXRecordDecl. 01259 ClassTemplateDecl *getDescribedClassTemplate() const { 01260 return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>(); 01261 } 01262 01263 void setDescribedClassTemplate(ClassTemplateDecl *Template) { 01264 TemplateOrInstantiation = Template; 01265 } 01266 01267 /// \brief Determine whether this particular class is a specialization or 01268 /// instantiation of a class template or member class of a class template, 01269 /// and how it was instantiated or specialized. 01270 TemplateSpecializationKind getTemplateSpecializationKind() const; 01271 01272 /// \brief Set the kind of specialization or template instantiation this is. 01273 void setTemplateSpecializationKind(TemplateSpecializationKind TSK); 01274 01275 /// getDestructor - Returns the destructor decl for this class. 01276 CXXDestructorDecl *getDestructor() const; 01277 01278 /// isLocalClass - If the class is a local class [class.local], returns 01279 /// the enclosing function declaration. 01280 const FunctionDecl *isLocalClass() const { 01281 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) 01282 return RD->isLocalClass(); 01283 01284 return dyn_cast<FunctionDecl>(getDeclContext()); 01285 } 01286 01287 /// \brief Determine whether this class is derived from the class \p Base. 01288 /// 01289 /// This routine only determines whether this class is derived from \p Base, 01290 /// but does not account for factors that may make a Derived -> Base class 01291 /// ill-formed, such as private/protected inheritance or multiple, ambiguous 01292 /// base class subobjects. 01293 /// 01294 /// \param Base the base class we are searching for. 01295 /// 01296 /// \returns true if this class is derived from Base, false otherwise. 01297 bool isDerivedFrom(const CXXRecordDecl *Base) const; 01298 01299 /// \brief Determine whether this class is derived from the type \p Base. 01300 /// 01301 /// This routine only determines whether this class is derived from \p Base, 01302 /// but does not account for factors that may make a Derived -> Base class 01303 /// ill-formed, such as private/protected inheritance or multiple, ambiguous 01304 /// base class subobjects. 01305 /// 01306 /// \param Base the base class we are searching for. 01307 /// 01308 /// \param Paths will contain the paths taken from the current class to the 01309 /// given \p Base class. 01310 /// 01311 /// \returns true if this class is derived from Base, false otherwise. 01312 /// 01313 /// \todo add a separate paramaeter to configure IsDerivedFrom, rather than 01314 /// tangling input and output in \p Paths 01315 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; 01316 01317 /// \brief Determine whether this class is virtually derived from 01318 /// the class \p Base. 01319 /// 01320 /// This routine only determines whether this class is virtually 01321 /// derived from \p Base, but does not account for factors that may 01322 /// make a Derived -> Base class ill-formed, such as 01323 /// private/protected inheritance or multiple, ambiguous base class 01324 /// subobjects. 01325 /// 01326 /// \param Base the base class we are searching for. 01327 /// 01328 /// \returns true if this class is virtually derived from Base, 01329 /// false otherwise. 01330 bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const; 01331 01332 /// \brief Determine whether this class is provably not derived from 01333 /// the type \p Base. 01334 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; 01335 01336 /// \brief Function type used by forallBases() as a callback. 01337 /// 01338 /// \param Base the definition of the base class 01339 /// 01340 /// \returns true if this base matched the search criteria 01341 typedef bool ForallBasesCallback(const CXXRecordDecl *BaseDefinition, 01342 void *UserData); 01343 01344 /// \brief Determines if the given callback holds for all the direct 01345 /// or indirect base classes of this type. 01346 /// 01347 /// The class itself does not count as a base class. This routine 01348 /// returns false if the class has non-computable base classes. 01349 /// 01350 /// \param AllowShortCircuit if false, forces the callback to be called 01351 /// for every base class, even if a dependent or non-matching base was 01352 /// found. 01353 bool forallBases(ForallBasesCallback *BaseMatches, void *UserData, 01354 bool AllowShortCircuit = true) const; 01355 01356 /// \brief Function type used by lookupInBases() to determine whether a 01357 /// specific base class subobject matches the lookup criteria. 01358 /// 01359 /// \param Specifier the base-class specifier that describes the inheritance 01360 /// from the base class we are trying to match. 01361 /// 01362 /// \param Path the current path, from the most-derived class down to the 01363 /// base named by the \p Specifier. 01364 /// 01365 /// \param UserData a single pointer to user-specified data, provided to 01366 /// lookupInBases(). 01367 /// 01368 /// \returns true if this base matched the search criteria, false otherwise. 01369 typedef bool BaseMatchesCallback(const CXXBaseSpecifier *Specifier, 01370 CXXBasePath &Path, 01371 void *UserData); 01372 01373 /// \brief Look for entities within the base classes of this C++ class, 01374 /// transitively searching all base class subobjects. 01375 /// 01376 /// This routine uses the callback function \p BaseMatches to find base 01377 /// classes meeting some search criteria, walking all base class subobjects 01378 /// and populating the given \p Paths structure with the paths through the 01379 /// inheritance hierarchy that resulted in a match. On a successful search, 01380 /// the \p Paths structure can be queried to retrieve the matching paths and 01381 /// to determine if there were any ambiguities. 01382 /// 01383 /// \param BaseMatches callback function used to determine whether a given 01384 /// base matches the user-defined search criteria. 01385 /// 01386 /// \param UserData user data pointer that will be provided to \p BaseMatches. 01387 /// 01388 /// \param Paths used to record the paths from this class to its base class 01389 /// subobjects that match the search criteria. 01390 /// 01391 /// \returns true if there exists any path from this class to a base class 01392 /// subobject that matches the search criteria. 01393 bool lookupInBases(BaseMatchesCallback *BaseMatches, void *UserData, 01394 CXXBasePaths &Paths) const; 01395 01396 /// \brief Base-class lookup callback that determines whether the given 01397 /// base class specifier refers to a specific class declaration. 01398 /// 01399 /// This callback can be used with \c lookupInBases() to determine whether 01400 /// a given derived class has is a base class subobject of a particular type. 01401 /// The user data pointer should refer to the canonical CXXRecordDecl of the 01402 /// base class that we are searching for. 01403 static bool FindBaseClass(const CXXBaseSpecifier *Specifier, 01404 CXXBasePath &Path, void *BaseRecord); 01405 01406 /// \brief Base-class lookup callback that determines whether the 01407 /// given base class specifier refers to a specific class 01408 /// declaration and describes virtual derivation. 01409 /// 01410 /// This callback can be used with \c lookupInBases() to determine 01411 /// whether a given derived class has is a virtual base class 01412 /// subobject of a particular type. The user data pointer should 01413 /// refer to the canonical CXXRecordDecl of the base class that we 01414 /// are searching for. 01415 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, 01416 CXXBasePath &Path, void *BaseRecord); 01417 01418 /// \brief Base-class lookup callback that determines whether there exists 01419 /// a tag with the given name. 01420 /// 01421 /// This callback can be used with \c lookupInBases() to find tag members 01422 /// of the given name within a C++ class hierarchy. The user data pointer 01423 /// is an opaque \c DeclarationName pointer. 01424 static bool FindTagMember(const CXXBaseSpecifier *Specifier, 01425 CXXBasePath &Path, void *Name); 01426 01427 /// \brief Base-class lookup callback that determines whether there exists 01428 /// a member with the given name. 01429 /// 01430 /// This callback can be used with \c lookupInBases() to find members 01431 /// of the given name within a C++ class hierarchy. The user data pointer 01432 /// is an opaque \c DeclarationName pointer. 01433 static bool FindOrdinaryMember(const CXXBaseSpecifier *Specifier, 01434 CXXBasePath &Path, void *Name); 01435 01436 /// \brief Base-class lookup callback that determines whether there exists 01437 /// a member with the given name that can be used in a nested-name-specifier. 01438 /// 01439 /// This callback can be used with \c lookupInBases() to find membes of 01440 /// the given name within a C++ class hierarchy that can occur within 01441 /// nested-name-specifiers. 01442 static bool FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, 01443 CXXBasePath &Path, 01444 void *UserData); 01445 01446 /// \brief Retrieve the final overriders for each virtual member 01447 /// function in the class hierarchy where this class is the 01448 /// most-derived class in the class hierarchy. 01449 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; 01450 01451 /// \brief Get the indirect primary bases for this class. 01452 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; 01453 01454 /// viewInheritance - Renders and displays an inheritance diagram 01455 /// for this C++ class and all of its base classes (transitively) using 01456 /// GraphViz. 01457 void viewInheritance(ASTContext& Context) const; 01458 01459 /// MergeAccess - Calculates the access of a decl that is reached 01460 /// along a path. 01461 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, 01462 AccessSpecifier DeclAccess) { 01463 assert(DeclAccess != AS_none); 01464 if (DeclAccess == AS_private) return AS_none; 01465 return (PathAccess > DeclAccess ? PathAccess : DeclAccess); 01466 } 01467 01468 /// \brief Indicates that the definition of this class is now complete. 01469 virtual void completeDefinition(); 01470 01471 /// \brief Indicates that the definition of this class is now complete, 01472 /// and provides a final overrider map to help determine 01473 /// 01474 /// \param FinalOverriders The final overrider map for this class, which can 01475 /// be provided as an optimization for abstract-class checking. If NULL, 01476 /// final overriders will be computed if they are needed to complete the 01477 /// definition. 01478 void completeDefinition(CXXFinalOverriderMap *FinalOverriders); 01479 01480 /// \brief Determine whether this class may end up being abstract, even though 01481 /// it is not yet known to be abstract. 01482 /// 01483 /// \returns true if this class is not known to be abstract but has any 01484 /// base classes that are abstract. In this case, \c completeDefinition() 01485 /// will need to compute final overriders to determine whether the class is 01486 /// actually abstract. 01487 bool mayBeAbstract() const; 01488 01489 /// \brief If this is the closure type of a lambda expression, retrieve the 01490 /// number to be used for name mangling in the Itanium C++ ABI. 01491 /// 01492 /// Zero indicates that this closure type has internal linkage, so the 01493 /// mangling number does not matter, while a non-zero value indicates which 01494 /// lambda expression this is in this particular context. 01495 unsigned getLambdaManglingNumber() const { 01496 assert(isLambda() && "Not a lambda closure type!"); 01497 return getLambdaData().ManglingNumber; 01498 } 01499 01500 /// \brief Retrieve the declaration that provides additional context for a 01501 /// lambda, when the normal declaration context is not specific enough. 01502 /// 01503 /// Certain contexts (default arguments of in-class function parameters and 01504 /// the initializers of data members) have separate name mangling rules for 01505 /// lambdas within the Itanium C++ ABI. For these cases, this routine provides 01506 /// the declaration in which the lambda occurs, e.g., the function parameter 01507 /// or the non-static data member. Otherwise, it returns NULL to imply that 01508 /// the declaration context suffices. 01509 Decl *getLambdaContextDecl() const { 01510 assert(isLambda() && "Not a lambda closure type!"); 01511 return getLambdaData().ContextDecl; 01512 } 01513 01514 /// \brief Set the mangling number and context declaration for a lambda 01515 /// class. 01516 void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl) { 01517 getLambdaData().ManglingNumber = ManglingNumber; 01518 getLambdaData().ContextDecl = ContextDecl; 01519 } 01520 01521 /// \brief Determine whether this lambda expression was known to be dependent 01522 /// at the time it was created, even if its context does not appear to be 01523 /// dependent. 01524 /// 01525 /// This flag is a workaround for an issue with parsing, where default 01526 /// arguments are parsed before their enclosing function declarations have 01527 /// been created. This means that any lambda expressions within those 01528 /// default arguments will have as their DeclContext the context enclosing 01529 /// the function declaration, which may be non-dependent even when the 01530 /// function declaration itself is dependent. This flag indicates when we 01531 /// know that the lambda is dependent despite that. 01532 bool isDependentLambda() const { 01533 return isLambda() && getLambdaData().Dependent; 01534 } 01535 01536 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 01537 static bool classofKind(Kind K) { 01538 return K >= firstCXXRecord && K <= lastCXXRecord; 01539 } 01540 static bool classof(const CXXRecordDecl *D) { return true; } 01541 static bool classof(const ClassTemplateSpecializationDecl *D) { 01542 return true; 01543 } 01544 01545 friend class ASTDeclReader; 01546 friend class ASTDeclWriter; 01547 friend class ASTReader; 01548 friend class ASTWriter; 01549 }; 01550 01551 /// CXXMethodDecl - Represents a static or instance method of a 01552 /// struct/union/class. 01553 class CXXMethodDecl : public FunctionDecl { 01554 virtual void anchor(); 01555 protected: 01556 CXXMethodDecl(Kind DK, CXXRecordDecl *RD, SourceLocation StartLoc, 01557 const DeclarationNameInfo &NameInfo, 01558 QualType T, TypeSourceInfo *TInfo, 01559 bool isStatic, StorageClass SCAsWritten, bool isInline, 01560 bool isConstexpr, SourceLocation EndLocation) 01561 : FunctionDecl(DK, RD, StartLoc, NameInfo, T, TInfo, 01562 (isStatic ? SC_Static : SC_None), 01563 SCAsWritten, isInline, isConstexpr) { 01564 if (EndLocation.isValid()) 01565 setRangeEnd(EndLocation); 01566 } 01567 01568 public: 01569 static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, 01570 SourceLocation StartLoc, 01571 const DeclarationNameInfo &NameInfo, 01572 QualType T, TypeSourceInfo *TInfo, 01573 bool isStatic, 01574 StorageClass SCAsWritten, 01575 bool isInline, 01576 bool isConstexpr, 01577 SourceLocation EndLocation); 01578 01579 static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); 01580 01581 bool isStatic() const { return getStorageClass() == SC_Static; } 01582 bool isInstance() const { return !isStatic(); } 01583 01584 bool isVirtual() const { 01585 CXXMethodDecl *CD = 01586 cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl()); 01587 01588 if (CD->isVirtualAsWritten()) 01589 return true; 01590 01591 return (CD->begin_overridden_methods() != CD->end_overridden_methods()); 01592 } 01593 01594 /// \brief Determine whether this is a usual deallocation function 01595 /// (C++ [basic.stc.dynamic.deallocation]p2), which is an overloaded 01596 /// delete or delete[] operator with a particular signature. 01597 bool isUsualDeallocationFunction() const; 01598 01599 /// \brief Determine whether this is a copy-assignment operator, regardless 01600 /// of whether it was declared implicitly or explicitly. 01601 bool isCopyAssignmentOperator() const; 01602 01603 /// \brief Determine whether this is a move assignment operator. 01604 bool isMoveAssignmentOperator() const; 01605 01606 const CXXMethodDecl *getCanonicalDecl() const { 01607 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 01608 } 01609 CXXMethodDecl *getCanonicalDecl() { 01610 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); 01611 } 01612 01613 /// isUserProvided - True if it is either an implicit constructor or 01614 /// if it was defaulted or deleted on first declaration. 01615 bool isUserProvided() const { 01616 return !(isDeleted() || getCanonicalDecl()->isDefaulted()); 01617 } 01618 01619 /// 01620 void addOverriddenMethod(const CXXMethodDecl *MD); 01621 01622 typedef const CXXMethodDecl *const* method_iterator; 01623 01624 method_iterator begin_overridden_methods() const; 01625 method_iterator end_overridden_methods() const; 01626 unsigned size_overridden_methods() const; 01627 01628 /// getParent - Returns the parent of this method declaration, which 01629 /// is the class in which this method is defined. 01630 const CXXRecordDecl *getParent() const { 01631 return cast<CXXRecordDecl>(FunctionDecl::getParent()); 01632 } 01633 01634 /// getParent - Returns the parent of this method declaration, which 01635 /// is the class in which this method is defined. 01636 CXXRecordDecl *getParent() { 01637 return const_cast<CXXRecordDecl *>( 01638 cast<CXXRecordDecl>(FunctionDecl::getParent())); 01639 } 01640 01641 /// getThisType - Returns the type of 'this' pointer. 01642 /// Should only be called for instance methods. 01643 QualType getThisType(ASTContext &C) const; 01644 01645 unsigned getTypeQualifiers() const { 01646 return getType()->getAs<FunctionProtoType>()->getTypeQuals(); 01647 } 01648 01649 /// \brief Retrieve the ref-qualifier associated with this method. 01650 /// 01651 /// In the following example, \c f() has an lvalue ref-qualifier, \c g() 01652 /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. 01653 /// \code 01654 /// struct X { 01655 /// void f() &; 01656 /// void g() &&; 01657 /// void h(); 01658 /// }; 01659 /// \endcode 01660 RefQualifierKind getRefQualifier() const { 01661 return getType()->getAs<FunctionProtoType>()->getRefQualifier(); 01662 } 01663 01664 bool hasInlineBody() const; 01665 01666 /// \brief Determine whether this is a lambda closure type's static member 01667 /// function that is used for the result of the lambda's conversion to 01668 /// function pointer (for a lambda with no captures). 01669 /// 01670 /// The function itself, if used, will have a placeholder body that will be 01671 /// supplied by IR generation to either forward to the function call operator 01672 /// or clone the function call operator. 01673 bool isLambdaStaticInvoker() const; 01674 01675 // Implement isa/cast/dyncast/etc. 01676 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 01677 static bool classof(const CXXMethodDecl *D) { return true; } 01678 static bool classofKind(Kind K) { 01679 return K >= firstCXXMethod && K <= lastCXXMethod; 01680 } 01681 }; 01682 01683 /// CXXCtorInitializer - Represents a C++ base or member 01684 /// initializer, which is part of a constructor initializer that 01685 /// initializes one non-static member variable or one base class. For 01686 /// example, in the following, both 'A(a)' and 'f(3.14159)' are member 01687 /// initializers: 01688 /// 01689 /// @code 01690 /// class A { }; 01691 /// class B : public A { 01692 /// float f; 01693 /// public: 01694 /// B(A& a) : A(a), f(3.14159) { } 01695 /// }; 01696 /// @endcode 01697 class CXXCtorInitializer { 01698 /// \brief Either the base class name/delegating constructor type (stored as 01699 /// a TypeSourceInfo*), an normal field (FieldDecl), or an anonymous field 01700 /// (IndirectFieldDecl*) being initialized. 01701 llvm::PointerUnion3<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> 01702 Initializee; 01703 01704 /// \brief The source location for the field name or, for a base initializer 01705 /// pack expansion, the location of the ellipsis. In the case of a delegating 01706 /// constructor, it will still include the type's source location as the 01707 /// Initializee points to the CXXConstructorDecl (to allow loop detection). 01708 SourceLocation MemberOrEllipsisLocation; 01709 01710 /// \brief The argument used to initialize the base or member, which may 01711 /// end up constructing an object (when multiple arguments are involved). 01712 /// If 0, this is a field initializer, and the in-class member initializer 01713 /// will be used. 01714 Stmt *Init; 01715 01716 /// LParenLoc - Location of the left paren of the ctor-initializer. 01717 SourceLocation LParenLoc; 01718 01719 /// RParenLoc - Location of the right paren of the ctor-initializer. 01720 SourceLocation RParenLoc; 01721 01722 /// \brief If the initializee is a type, whether that type makes this 01723 /// a delegating initialization. 01724 bool IsDelegating : 1; 01725 01726 /// IsVirtual - If the initializer is a base initializer, this keeps track 01727 /// of whether the base is virtual or not. 01728 bool IsVirtual : 1; 01729 01730 /// IsWritten - Whether or not the initializer is explicitly written 01731 /// in the sources. 01732 bool IsWritten : 1; 01733 01734 /// SourceOrderOrNumArrayIndices - If IsWritten is true, then this 01735 /// number keeps track of the textual order of this initializer in the 01736 /// original sources, counting from 0; otherwise, if IsWritten is false, 01737 /// it stores the number of array index variables stored after this 01738 /// object in memory. 01739 unsigned SourceOrderOrNumArrayIndices : 13; 01740 01741 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, 01742 SourceLocation MemberLoc, SourceLocation L, Expr *Init, 01743 SourceLocation R, VarDecl **Indices, unsigned NumIndices); 01744 01745 public: 01746 /// CXXCtorInitializer - Creates a new base-class initializer. 01747 explicit 01748 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, 01749 SourceLocation L, Expr *Init, SourceLocation R, 01750 SourceLocation EllipsisLoc); 01751 01752 /// CXXCtorInitializer - Creates a new member initializer. 01753 explicit 01754 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, 01755 SourceLocation MemberLoc, SourceLocation L, Expr *Init, 01756 SourceLocation R); 01757 01758 /// CXXCtorInitializer - Creates a new anonymous field initializer. 01759 explicit 01760 CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, 01761 SourceLocation MemberLoc, SourceLocation L, Expr *Init, 01762 SourceLocation R); 01763 01764 /// CXXCtorInitializer - Creates a new delegating Initializer. 01765 explicit 01766 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, 01767 SourceLocation L, Expr *Init, SourceLocation R); 01768 01769 /// \brief Creates a new member initializer that optionally contains 01770 /// array indices used to describe an elementwise initialization. 01771 static CXXCtorInitializer *Create(ASTContext &Context, FieldDecl *Member, 01772 SourceLocation MemberLoc, SourceLocation L, 01773 Expr *Init, SourceLocation R, 01774 VarDecl **Indices, unsigned NumIndices); 01775 01776 /// isBaseInitializer - Returns true when this initializer is 01777 /// initializing a base class. 01778 bool isBaseInitializer() const { 01779 return Initializee.is<TypeSourceInfo*>() && !IsDelegating; 01780 } 01781 01782 /// isMemberInitializer - Returns true when this initializer is 01783 /// initializing a non-static data member. 01784 bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } 01785 01786 bool isAnyMemberInitializer() const { 01787 return isMemberInitializer() || isIndirectMemberInitializer(); 01788 } 01789 01790 bool isIndirectMemberInitializer() const { 01791 return Initializee.is<IndirectFieldDecl*>(); 01792 } 01793 01794 /// isInClassMemberInitializer - Returns true when this initializer is an 01795 /// implicit ctor initializer generated for a field with an initializer 01796 /// defined on the member declaration. 01797 bool isInClassMemberInitializer() const { 01798 return !Init; 01799 } 01800 01801 /// isDelegatingInitializer - Returns true when this initializer is creating 01802 /// a delegating constructor. 01803 bool isDelegatingInitializer() const { 01804 return Initializee.is<TypeSourceInfo*>() && IsDelegating; 01805 } 01806 01807 /// \brief Determine whether this initializer is a pack expansion. 01808 bool isPackExpansion() const { 01809 return isBaseInitializer() && MemberOrEllipsisLocation.isValid(); 01810 } 01811 01812 // \brief For a pack expansion, returns the location of the ellipsis. 01813 SourceLocation getEllipsisLoc() const { 01814 assert(isPackExpansion() && "Initializer is not a pack expansion"); 01815 return MemberOrEllipsisLocation; 01816 } 01817 01818 /// If this is a base class initializer, returns the type of the 01819 /// base class with location information. Otherwise, returns an NULL 01820 /// type location. 01821 TypeLoc getBaseClassLoc() const; 01822 01823 /// If this is a base class initializer, returns the type of the base class. 01824 /// Otherwise, returns NULL. 01825 const Type *getBaseClass() const; 01826 01827 /// Returns whether the base is virtual or not. 01828 bool isBaseVirtual() const { 01829 assert(isBaseInitializer() && "Must call this on base initializer!"); 01830 01831 return IsVirtual; 01832 } 01833 01834 /// \brief Returns the declarator information for a base class or delegating 01835 /// initializer. 01836 TypeSourceInfo *getTypeSourceInfo() const { 01837 return Initializee.dyn_cast<TypeSourceInfo *>(); 01838 } 01839 01840 /// getMember - If this is a member initializer, returns the 01841 /// declaration of the non-static data member being 01842 /// initialized. Otherwise, returns NULL. 01843 FieldDecl *getMember() const { 01844 if (isMemberInitializer()) 01845 return Initializee.get<FieldDecl*>(); 01846 return 0; 01847 } 01848 FieldDecl *getAnyMember() const { 01849 if (isMemberInitializer()) 01850 return Initializee.get<FieldDecl*>(); 01851 if (isIndirectMemberInitializer()) 01852 return Initializee.get<IndirectFieldDecl*>()->getAnonField(); 01853 return 0; 01854 } 01855 01856 IndirectFieldDecl *getIndirectMember() const { 01857 if (isIndirectMemberInitializer()) 01858 return Initializee.get<IndirectFieldDecl*>(); 01859 return 0; 01860 } 01861 01862 SourceLocation getMemberLocation() const { 01863 return MemberOrEllipsisLocation; 01864 } 01865 01866 /// \brief Determine the source location of the initializer. 01867 SourceLocation getSourceLocation() const; 01868 01869 /// \brief Determine the source range covering the entire initializer. 01870 SourceRange getSourceRange() const LLVM_READONLY; 01871 01872 /// isWritten - Returns true if this initializer is explicitly written 01873 /// in the source code. 01874 bool isWritten() const { return IsWritten; } 01875 01876 /// \brief Return the source position of the initializer, counting from 0. 01877 /// If the initializer was implicit, -1 is returned. 01878 int getSourceOrder() const { 01879 return IsWritten ? static_cast<int>(SourceOrderOrNumArrayIndices) : -1; 01880 } 01881 01882 /// \brief Set the source order of this initializer. This method can only 01883 /// be called once for each initializer; it cannot be called on an 01884 /// initializer having a positive number of (implicit) array indices. 01885 void setSourceOrder(int pos) { 01886 assert(!IsWritten && 01887 "calling twice setSourceOrder() on the same initializer"); 01888 assert(SourceOrderOrNumArrayIndices == 0 && 01889 "setSourceOrder() used when there are implicit array indices"); 01890 assert(pos >= 0 && 01891 "setSourceOrder() used to make an initializer implicit"); 01892 IsWritten = true; 01893 SourceOrderOrNumArrayIndices = static_cast<unsigned>(pos); 01894 } 01895 01896 SourceLocation getLParenLoc() const { return LParenLoc; } 01897 SourceLocation getRParenLoc() const { return RParenLoc; } 01898 01899 /// \brief Determine the number of implicit array indices used while 01900 /// described an array member initialization. 01901 unsigned getNumArrayIndices() const { 01902 return IsWritten ? 0 : SourceOrderOrNumArrayIndices; 01903 } 01904 01905 /// \brief Retrieve a particular array index variable used to 01906 /// describe an array member initialization. 01907 VarDecl *getArrayIndex(unsigned I) { 01908 assert(I < getNumArrayIndices() && "Out of bounds member array index"); 01909 return reinterpret_cast<VarDecl **>(this + 1)[I]; 01910 } 01911 const VarDecl *getArrayIndex(unsigned I) const { 01912 assert(I < getNumArrayIndices() && "Out of bounds member array index"); 01913 return reinterpret_cast<const VarDecl * const *>(this + 1)[I]; 01914 } 01915 void setArrayIndex(unsigned I, VarDecl *Index) { 01916 assert(I < getNumArrayIndices() && "Out of bounds member array index"); 01917 reinterpret_cast<VarDecl **>(this + 1)[I] = Index; 01918 } 01919 ArrayRef<VarDecl *> getArrayIndexes() { 01920 assert(getNumArrayIndices() != 0 && "Getting indexes for non-array init"); 01921 return ArrayRef<VarDecl *>(reinterpret_cast<VarDecl **>(this + 1), 01922 getNumArrayIndices()); 01923 } 01924 01925 /// \brief Get the initializer. This is 0 if this is an in-class initializer 01926 /// for a non-static data member which has not yet been parsed. 01927 Expr *getInit() const { 01928 if (!Init) 01929 return getAnyMember()->getInClassInitializer(); 01930 01931 return static_cast<Expr*>(Init); 01932 } 01933 }; 01934 01935 /// CXXConstructorDecl - Represents a C++ constructor within a 01936 /// class. For example: 01937 /// 01938 /// @code 01939 /// class X { 01940 /// public: 01941 /// explicit X(int); // represented by a CXXConstructorDecl. 01942 /// }; 01943 /// @endcode 01944 class CXXConstructorDecl : public CXXMethodDecl { 01945 virtual void anchor(); 01946 /// IsExplicitSpecified - Whether this constructor declaration has the 01947 /// 'explicit' keyword specified. 01948 bool IsExplicitSpecified : 1; 01949 01950 /// ImplicitlyDefined - Whether this constructor was implicitly 01951 /// defined by the compiler. When false, the constructor was defined 01952 /// by the user. In C++03, this flag will have the same value as 01953 /// Implicit. In C++0x, however, a constructor that is 01954 /// explicitly defaulted (i.e., defined with " = default") will have 01955 /// @c !Implicit && ImplicitlyDefined. 01956 bool ImplicitlyDefined : 1; 01957 01958 /// Support for base and member initializers. 01959 /// CtorInitializers - The arguments used to initialize the base 01960 /// or member. 01961 CXXCtorInitializer **CtorInitializers; 01962 unsigned NumCtorInitializers; 01963 01964 CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 01965 const DeclarationNameInfo &NameInfo, 01966 QualType T, TypeSourceInfo *TInfo, 01967 bool isExplicitSpecified, bool isInline, 01968 bool isImplicitlyDeclared, bool isConstexpr) 01969 : CXXMethodDecl(CXXConstructor, RD, StartLoc, NameInfo, T, TInfo, false, 01970 SC_None, isInline, isConstexpr, SourceLocation()), 01971 IsExplicitSpecified(isExplicitSpecified), ImplicitlyDefined(false), 01972 CtorInitializers(0), NumCtorInitializers(0) { 01973 setImplicit(isImplicitlyDeclared); 01974 } 01975 01976 public: 01977 static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID); 01978 static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 01979 SourceLocation StartLoc, 01980 const DeclarationNameInfo &NameInfo, 01981 QualType T, TypeSourceInfo *TInfo, 01982 bool isExplicit, 01983 bool isInline, bool isImplicitlyDeclared, 01984 bool isConstexpr); 01985 01986 /// isExplicitSpecified - Whether this constructor declaration has the 01987 /// 'explicit' keyword specified. 01988 bool isExplicitSpecified() const { return IsExplicitSpecified; } 01989 01990 /// isExplicit - Whether this constructor was marked "explicit" or not. 01991 bool isExplicit() const { 01992 return cast<CXXConstructorDecl>(getFirstDeclaration()) 01993 ->isExplicitSpecified(); 01994 } 01995 01996 /// isImplicitlyDefined - Whether this constructor was implicitly 01997 /// defined. If false, then this constructor was defined by the 01998 /// user. This operation can only be invoked if the constructor has 01999 /// already been defined. 02000 bool isImplicitlyDefined() const { 02001 assert(isThisDeclarationADefinition() && 02002 "Can only get the implicit-definition flag once the " 02003 "constructor has been defined"); 02004 return ImplicitlyDefined; 02005 } 02006 02007 /// setImplicitlyDefined - Set whether this constructor was 02008 /// implicitly defined or not. 02009 void setImplicitlyDefined(bool ID) { 02010 assert(isThisDeclarationADefinition() && 02011 "Can only set the implicit-definition flag once the constructor " 02012 "has been defined"); 02013 ImplicitlyDefined = ID; 02014 } 02015 02016 /// init_iterator - Iterates through the member/base initializer list. 02017 typedef CXXCtorInitializer **init_iterator; 02018 02019 /// init_const_iterator - Iterates through the memberbase initializer list. 02020 typedef CXXCtorInitializer * const * init_const_iterator; 02021 02022 /// init_begin() - Retrieve an iterator to the first initializer. 02023 init_iterator init_begin() { return CtorInitializers; } 02024 /// begin() - Retrieve an iterator to the first initializer. 02025 init_const_iterator init_begin() const { return CtorInitializers; } 02026 02027 /// init_end() - Retrieve an iterator past the last initializer. 02028 init_iterator init_end() { 02029 return CtorInitializers + NumCtorInitializers; 02030 } 02031 /// end() - Retrieve an iterator past the last initializer. 02032 init_const_iterator init_end() const { 02033 return CtorInitializers + NumCtorInitializers; 02034 } 02035 02036 typedef std::reverse_iterator<init_iterator> init_reverse_iterator; 02037 typedef std::reverse_iterator<init_const_iterator> 02038 init_const_reverse_iterator; 02039 02040 init_reverse_iterator init_rbegin() { 02041 return init_reverse_iterator(init_end()); 02042 } 02043 init_const_reverse_iterator init_rbegin() const { 02044 return init_const_reverse_iterator(init_end()); 02045 } 02046 02047 init_reverse_iterator init_rend() { 02048 return init_reverse_iterator(init_begin()); 02049 } 02050 init_const_reverse_iterator init_rend() const { 02051 return init_const_reverse_iterator(init_begin()); 02052 } 02053 02054 /// getNumArgs - Determine the number of arguments used to 02055 /// initialize the member or base. 02056 unsigned getNumCtorInitializers() const { 02057 return NumCtorInitializers; 02058 } 02059 02060 void setNumCtorInitializers(unsigned numCtorInitializers) { 02061 NumCtorInitializers = numCtorInitializers; 02062 } 02063 02064 void setCtorInitializers(CXXCtorInitializer ** initializers) { 02065 CtorInitializers = initializers; 02066 } 02067 02068 /// isDelegatingConstructor - Whether this constructor is a 02069 /// delegating constructor 02070 bool isDelegatingConstructor() const { 02071 return (getNumCtorInitializers() == 1) && 02072 CtorInitializers[0]->isDelegatingInitializer(); 02073 } 02074 02075 /// getTargetConstructor - When this constructor delegates to 02076 /// another, retrieve the target 02077 CXXConstructorDecl *getTargetConstructor() const; 02078 02079 /// isDefaultConstructor - Whether this constructor is a default 02080 /// constructor (C++ [class.ctor]p5), which can be used to 02081 /// default-initialize a class of this type. 02082 bool isDefaultConstructor() const; 02083 02084 /// isCopyConstructor - Whether this constructor is a copy 02085 /// constructor (C++ [class.copy]p2, which can be used to copy the 02086 /// class. @p TypeQuals will be set to the qualifiers on the 02087 /// argument type. For example, @p TypeQuals would be set to @c 02088 /// QualType::Const for the following copy constructor: 02089 /// 02090 /// @code 02091 /// class X { 02092 /// public: 02093 /// X(const X&); 02094 /// }; 02095 /// @endcode 02096 bool isCopyConstructor(unsigned &TypeQuals) const; 02097 02098 /// isCopyConstructor - Whether this constructor is a copy 02099 /// constructor (C++ [class.copy]p2, which can be used to copy the 02100 /// class. 02101 bool isCopyConstructor() const { 02102 unsigned TypeQuals = 0; 02103 return isCopyConstructor(TypeQuals); 02104 } 02105 02106 /// \brief Determine whether this constructor is a move constructor 02107 /// (C++0x [class.copy]p3), which can be used to move values of the class. 02108 /// 02109 /// \param TypeQuals If this constructor is a move constructor, will be set 02110 /// to the type qualifiers on the referent of the first parameter's type. 02111 bool isMoveConstructor(unsigned &TypeQuals) const; 02112 02113 /// \brief Determine whether this constructor is a move constructor 02114 /// (C++0x [class.copy]p3), which can be used to move values of the class. 02115 bool isMoveConstructor() const { 02116 unsigned TypeQuals = 0; 02117 return isMoveConstructor(TypeQuals); 02118 } 02119 02120 /// \brief Determine whether this is a copy or move constructor. 02121 /// 02122 /// \param TypeQuals Will be set to the type qualifiers on the reference 02123 /// parameter, if in fact this is a copy or move constructor. 02124 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; 02125 02126 /// \brief Determine whether this a copy or move constructor. 02127 bool isCopyOrMoveConstructor() const { 02128 unsigned Quals; 02129 return isCopyOrMoveConstructor(Quals); 02130 } 02131 02132 /// isConvertingConstructor - Whether this constructor is a 02133 /// converting constructor (C++ [class.conv.ctor]), which can be 02134 /// used for user-defined conversions. 02135 bool isConvertingConstructor(bool AllowExplicit) const; 02136 02137 /// \brief Determine whether this is a member template specialization that 02138 /// would copy the object to itself. Such constructors are never used to copy 02139 /// an object. 02140 bool isSpecializationCopyingObject() const; 02141 02142 /// \brief Get the constructor that this inheriting constructor is based on. 02143 const CXXConstructorDecl *getInheritedConstructor() const; 02144 02145 /// \brief Set the constructor that this inheriting constructor is based on. 02146 void setInheritedConstructor(const CXXConstructorDecl *BaseCtor); 02147 02148 const CXXConstructorDecl *getCanonicalDecl() const { 02149 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); 02150 } 02151 CXXConstructorDecl *getCanonicalDecl() { 02152 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); 02153 } 02154 02155 // Implement isa/cast/dyncast/etc. 02156 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02157 static bool classof(const CXXConstructorDecl *D) { return true; } 02158 static bool classofKind(Kind K) { return K == CXXConstructor; } 02159 02160 friend class ASTDeclReader; 02161 friend class ASTDeclWriter; 02162 }; 02163 02164 /// CXXDestructorDecl - Represents a C++ destructor within a 02165 /// class. For example: 02166 /// 02167 /// @code 02168 /// class X { 02169 /// public: 02170 /// ~X(); // represented by a CXXDestructorDecl. 02171 /// }; 02172 /// @endcode 02173 class CXXDestructorDecl : public CXXMethodDecl { 02174 virtual void anchor(); 02175 /// ImplicitlyDefined - Whether this destructor was implicitly 02176 /// defined by the compiler. When false, the destructor was defined 02177 /// by the user. In C++03, this flag will have the same value as 02178 /// Implicit. In C++0x, however, a destructor that is 02179 /// explicitly defaulted (i.e., defined with " = default") will have 02180 /// @c !Implicit && ImplicitlyDefined. 02181 bool ImplicitlyDefined : 1; 02182 02183 FunctionDecl *OperatorDelete; 02184 02185 CXXDestructorDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 02186 const DeclarationNameInfo &NameInfo, 02187 QualType T, TypeSourceInfo *TInfo, 02188 bool isInline, bool isImplicitlyDeclared) 02189 : CXXMethodDecl(CXXDestructor, RD, StartLoc, NameInfo, T, TInfo, false, 02190 SC_None, isInline, /*isConstexpr=*/false, SourceLocation()), 02191 ImplicitlyDefined(false), OperatorDelete(0) { 02192 setImplicit(isImplicitlyDeclared); 02193 } 02194 02195 public: 02196 static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, 02197 SourceLocation StartLoc, 02198 const DeclarationNameInfo &NameInfo, 02199 QualType T, TypeSourceInfo* TInfo, 02200 bool isInline, 02201 bool isImplicitlyDeclared); 02202 static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); 02203 02204 /// isImplicitlyDefined - Whether this destructor was implicitly 02205 /// defined. If false, then this destructor was defined by the 02206 /// user. This operation can only be invoked if the destructor has 02207 /// already been defined. 02208 bool isImplicitlyDefined() const { 02209 assert(isThisDeclarationADefinition() && 02210 "Can only get the implicit-definition flag once the destructor has " 02211 "been defined"); 02212 return ImplicitlyDefined; 02213 } 02214 02215 /// setImplicitlyDefined - Set whether this destructor was 02216 /// implicitly defined or not. 02217 void setImplicitlyDefined(bool ID) { 02218 assert(isThisDeclarationADefinition() && 02219 "Can only set the implicit-definition flag once the destructor has " 02220 "been defined"); 02221 ImplicitlyDefined = ID; 02222 } 02223 02224 void setOperatorDelete(FunctionDecl *OD) { OperatorDelete = OD; } 02225 const FunctionDecl *getOperatorDelete() const { return OperatorDelete; } 02226 02227 // Implement isa/cast/dyncast/etc. 02228 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02229 static bool classof(const CXXDestructorDecl *D) { return true; } 02230 static bool classofKind(Kind K) { return K == CXXDestructor; } 02231 02232 friend class ASTDeclReader; 02233 friend class ASTDeclWriter; 02234 }; 02235 02236 /// CXXConversionDecl - Represents a C++ conversion function within a 02237 /// class. For example: 02238 /// 02239 /// @code 02240 /// class X { 02241 /// public: 02242 /// operator bool(); 02243 /// }; 02244 /// @endcode 02245 class CXXConversionDecl : public CXXMethodDecl { 02246 virtual void anchor(); 02247 /// IsExplicitSpecified - Whether this conversion function declaration is 02248 /// marked "explicit", meaning that it can only be applied when the user 02249 /// explicitly wrote a cast. This is a C++0x feature. 02250 bool IsExplicitSpecified : 1; 02251 02252 CXXConversionDecl(CXXRecordDecl *RD, SourceLocation StartLoc, 02253 const DeclarationNameInfo &NameInfo, 02254 QualType T, TypeSourceInfo *TInfo, 02255 bool isInline, bool isExplicitSpecified, 02256 bool isConstexpr, SourceLocation EndLocation) 02257 : CXXMethodDecl(CXXConversion, RD, StartLoc, NameInfo, T, TInfo, false, 02258 SC_None, isInline, isConstexpr, EndLocation), 02259 IsExplicitSpecified(isExplicitSpecified) { } 02260 02261 public: 02262 static CXXConversionDecl *Create(ASTContext &C, CXXRecordDecl *RD, 02263 SourceLocation StartLoc, 02264 const DeclarationNameInfo &NameInfo, 02265 QualType T, TypeSourceInfo *TInfo, 02266 bool isInline, bool isExplicit, 02267 bool isConstexpr, 02268 SourceLocation EndLocation); 02269 static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); 02270 02271 /// IsExplicitSpecified - Whether this conversion function declaration is 02272 /// marked "explicit", meaning that it can only be applied when the user 02273 /// explicitly wrote a cast. This is a C++0x feature. 02274 bool isExplicitSpecified() const { return IsExplicitSpecified; } 02275 02276 /// isExplicit - Whether this is an explicit conversion operator 02277 /// (C++0x only). Explicit conversion operators are only considered 02278 /// when the user has explicitly written a cast. 02279 bool isExplicit() const { 02280 return cast<CXXConversionDecl>(getFirstDeclaration()) 02281 ->isExplicitSpecified(); 02282 } 02283 02284 /// getConversionType - Returns the type that this conversion 02285 /// function is converting to. 02286 QualType getConversionType() const { 02287 return getType()->getAs<FunctionType>()->getResultType(); 02288 } 02289 02290 /// \brief Determine whether this conversion function is a conversion from 02291 /// a lambda closure type to a block pointer. 02292 bool isLambdaToBlockPointerConversion() const; 02293 02294 // Implement isa/cast/dyncast/etc. 02295 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02296 static bool classof(const CXXConversionDecl *D) { return true; } 02297 static bool classofKind(Kind K) { return K == CXXConversion; } 02298 02299 friend class ASTDeclReader; 02300 friend class ASTDeclWriter; 02301 }; 02302 02303 /// LinkageSpecDecl - This represents a linkage specification. For example: 02304 /// extern "C" void foo(); 02305 /// 02306 class LinkageSpecDecl : public Decl, public DeclContext { 02307 virtual void anchor(); 02308 public: 02309 /// LanguageIDs - Used to represent the language in a linkage 02310 /// specification. The values are part of the serialization abi for 02311 /// ASTs and cannot be changed without altering that abi. To help 02312 /// ensure a stable abi for this, we choose the DW_LANG_ encodings 02313 /// from the dwarf standard. 02314 enum LanguageIDs { 02315 lang_c = /* DW_LANG_C */ 0x0002, 02316 lang_cxx = /* DW_LANG_C_plus_plus */ 0x0004 02317 }; 02318 private: 02319 /// Language - The language for this linkage specification. 02320 LanguageIDs Language; 02321 /// ExternLoc - The source location for the extern keyword. 02322 SourceLocation ExternLoc; 02323 /// RBraceLoc - The source location for the right brace (if valid). 02324 SourceLocation RBraceLoc; 02325 02326 LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, 02327 SourceLocation LangLoc, LanguageIDs lang, 02328 SourceLocation RBLoc) 02329 : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec), 02330 Language(lang), ExternLoc(ExternLoc), RBraceLoc(RBLoc) { } 02331 02332 public: 02333 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, 02334 SourceLocation ExternLoc, 02335 SourceLocation LangLoc, LanguageIDs Lang, 02336 SourceLocation RBraceLoc = SourceLocation()); 02337 static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); 02338 02339 /// \brief Return the language specified by this linkage specification. 02340 LanguageIDs getLanguage() const { return Language; } 02341 /// \brief Set the language specified by this linkage specification. 02342 void setLanguage(LanguageIDs L) { Language = L; } 02343 02344 /// \brief Determines whether this linkage specification had braces in 02345 /// its syntactic form. 02346 bool hasBraces() const { return RBraceLoc.isValid(); } 02347 02348 SourceLocation getExternLoc() const { return ExternLoc; } 02349 SourceLocation getRBraceLoc() const { return RBraceLoc; } 02350 void setExternLoc(SourceLocation L) { ExternLoc = L; } 02351 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; } 02352 02353 SourceLocation getLocEnd() const LLVM_READONLY { 02354 if (hasBraces()) 02355 return getRBraceLoc(); 02356 // No braces: get the end location of the (only) declaration in context 02357 // (if present). 02358 return decls_empty() ? getLocation() : decls_begin()->getLocEnd(); 02359 } 02360 02361 SourceRange getSourceRange() const LLVM_READONLY { 02362 return SourceRange(ExternLoc, getLocEnd()); 02363 } 02364 02365 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02366 static bool classof(const LinkageSpecDecl *D) { return true; } 02367 static bool classofKind(Kind K) { return K == LinkageSpec; } 02368 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { 02369 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); 02370 } 02371 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { 02372 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); 02373 } 02374 }; 02375 02376 /// UsingDirectiveDecl - Represents C++ using-directive. For example: 02377 /// 02378 /// using namespace std; 02379 /// 02380 // NB: UsingDirectiveDecl should be Decl not NamedDecl, but we provide 02381 // artificial names for all using-directives in order to store 02382 // them in DeclContext effectively. 02383 class UsingDirectiveDecl : public NamedDecl { 02384 virtual void anchor(); 02385 /// \brief The location of the "using" keyword. 02386 SourceLocation UsingLoc; 02387 02388 /// SourceLocation - Location of 'namespace' token. 02389 SourceLocation NamespaceLoc; 02390 02391 /// \brief The nested-name-specifier that precedes the namespace. 02392 NestedNameSpecifierLoc QualifierLoc; 02393 02394 /// NominatedNamespace - Namespace nominated by using-directive. 02395 NamedDecl *NominatedNamespace; 02396 02397 /// Enclosing context containing both using-directive and nominated 02398 /// namespace. 02399 DeclContext *CommonAncestor; 02400 02401 /// getUsingDirectiveName - Returns special DeclarationName used by 02402 /// using-directives. This is only used by DeclContext for storing 02403 /// UsingDirectiveDecls in its lookup structure. 02404 static DeclarationName getName() { 02405 return DeclarationName::getUsingDirectiveName(); 02406 } 02407 02408 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, 02409 SourceLocation NamespcLoc, 02410 NestedNameSpecifierLoc QualifierLoc, 02411 SourceLocation IdentLoc, 02412 NamedDecl *Nominated, 02413 DeclContext *CommonAncestor) 02414 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), 02415 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), 02416 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) { } 02417 02418 public: 02419 /// \brief Retrieve the nested-name-specifier that qualifies the 02420 /// name of the namespace, with source-location information. 02421 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 02422 02423 /// \brief Retrieve the nested-name-specifier that qualifies the 02424 /// name of the namespace. 02425 NestedNameSpecifier *getQualifier() const { 02426 return QualifierLoc.getNestedNameSpecifier(); 02427 } 02428 02429 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } 02430 const NamedDecl *getNominatedNamespaceAsWritten() const { 02431 return NominatedNamespace; 02432 } 02433 02434 /// getNominatedNamespace - Returns namespace nominated by using-directive. 02435 NamespaceDecl *getNominatedNamespace(); 02436 02437 const NamespaceDecl *getNominatedNamespace() const { 02438 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); 02439 } 02440 02441 /// \brief Returns the common ancestor context of this using-directive and 02442 /// its nominated namespace. 02443 DeclContext *getCommonAncestor() { return CommonAncestor; } 02444 const DeclContext *getCommonAncestor() const { return CommonAncestor; } 02445 02446 /// \brief Return the location of the "using" keyword. 02447 SourceLocation getUsingLoc() const { return UsingLoc; } 02448 02449 // FIXME: Could omit 'Key' in name. 02450 /// getNamespaceKeyLocation - Returns location of namespace keyword. 02451 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } 02452 02453 /// getIdentLocation - Returns location of identifier. 02454 SourceLocation getIdentLocation() const { return getLocation(); } 02455 02456 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, 02457 SourceLocation UsingLoc, 02458 SourceLocation NamespaceLoc, 02459 NestedNameSpecifierLoc QualifierLoc, 02460 SourceLocation IdentLoc, 02461 NamedDecl *Nominated, 02462 DeclContext *CommonAncestor); 02463 static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID); 02464 02465 SourceRange getSourceRange() const LLVM_READONLY { 02466 return SourceRange(UsingLoc, getLocation()); 02467 } 02468 02469 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02470 static bool classof(const UsingDirectiveDecl *D) { return true; } 02471 static bool classofKind(Kind K) { return K == UsingDirective; } 02472 02473 // Friend for getUsingDirectiveName. 02474 friend class DeclContext; 02475 02476 friend class ASTDeclReader; 02477 }; 02478 02479 /// NamespaceAliasDecl - Represents a C++ namespace alias. For example: 02480 /// 02481 /// @code 02482 /// namespace Foo = Bar; 02483 /// @endcode 02484 class NamespaceAliasDecl : public NamedDecl { 02485 virtual void anchor(); 02486 02487 /// \brief The location of the "namespace" keyword. 02488 SourceLocation NamespaceLoc; 02489 02490 /// IdentLoc - Location of namespace identifier. Accessed by TargetNameLoc. 02491 SourceLocation IdentLoc; 02492 02493 /// \brief The nested-name-specifier that precedes the namespace. 02494 NestedNameSpecifierLoc QualifierLoc; 02495 02496 /// Namespace - The Decl that this alias points to. Can either be a 02497 /// NamespaceDecl or a NamespaceAliasDecl. 02498 NamedDecl *Namespace; 02499 02500 NamespaceAliasDecl(DeclContext *DC, SourceLocation NamespaceLoc, 02501 SourceLocation AliasLoc, IdentifierInfo *Alias, 02502 NestedNameSpecifierLoc QualifierLoc, 02503 SourceLocation IdentLoc, NamedDecl *Namespace) 02504 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), 02505 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), 02506 QualifierLoc(QualifierLoc), Namespace(Namespace) { } 02507 02508 friend class ASTDeclReader; 02509 02510 public: 02511 /// \brief Retrieve the nested-name-specifier that qualifies the 02512 /// name of the namespace, with source-location information. 02513 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 02514 02515 /// \brief Retrieve the nested-name-specifier that qualifies the 02516 /// name of the namespace. 02517 NestedNameSpecifier *getQualifier() const { 02518 return QualifierLoc.getNestedNameSpecifier(); 02519 } 02520 02521 /// \brief Retrieve the namespace declaration aliased by this directive. 02522 NamespaceDecl *getNamespace() { 02523 if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) 02524 return AD->getNamespace(); 02525 02526 return cast<NamespaceDecl>(Namespace); 02527 } 02528 02529 const NamespaceDecl *getNamespace() const { 02530 return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); 02531 } 02532 02533 /// Returns the location of the alias name, i.e. 'foo' in 02534 /// "namespace foo = ns::bar;". 02535 SourceLocation getAliasLoc() const { return getLocation(); } 02536 02537 /// Returns the location of the 'namespace' keyword. 02538 SourceLocation getNamespaceLoc() const { return NamespaceLoc; } 02539 02540 /// Returns the location of the identifier in the named namespace. 02541 SourceLocation getTargetNameLoc() const { return IdentLoc; } 02542 02543 /// \brief Retrieve the namespace that this alias refers to, which 02544 /// may either be a NamespaceDecl or a NamespaceAliasDecl. 02545 NamedDecl *getAliasedNamespace() const { return Namespace; } 02546 02547 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, 02548 SourceLocation NamespaceLoc, 02549 SourceLocation AliasLoc, 02550 IdentifierInfo *Alias, 02551 NestedNameSpecifierLoc QualifierLoc, 02552 SourceLocation IdentLoc, 02553 NamedDecl *Namespace); 02554 02555 static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); 02556 02557 virtual SourceRange getSourceRange() const LLVM_READONLY { 02558 return SourceRange(NamespaceLoc, IdentLoc); 02559 } 02560 02561 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02562 static bool classof(const NamespaceAliasDecl *D) { return true; } 02563 static bool classofKind(Kind K) { return K == NamespaceAlias; } 02564 }; 02565 02566 /// UsingShadowDecl - Represents a shadow declaration introduced into 02567 /// a scope by a (resolved) using declaration. For example, 02568 /// 02569 /// namespace A { 02570 /// void foo(); 02571 /// } 02572 /// namespace B { 02573 /// using A::foo(); // <- a UsingDecl 02574 /// // Also creates a UsingShadowDecl for A::foo in B 02575 /// } 02576 /// 02577 class UsingShadowDecl : public NamedDecl { 02578 virtual void anchor(); 02579 02580 /// The referenced declaration. 02581 NamedDecl *Underlying; 02582 02583 /// \brief The using declaration which introduced this decl or the next using 02584 /// shadow declaration contained in the aforementioned using declaration. 02585 NamedDecl *UsingOrNextShadow; 02586 friend class UsingDecl; 02587 02588 UsingShadowDecl(DeclContext *DC, SourceLocation Loc, UsingDecl *Using, 02589 NamedDecl *Target) 02590 : NamedDecl(UsingShadow, DC, Loc, DeclarationName()), 02591 Underlying(Target), 02592 UsingOrNextShadow(reinterpret_cast<NamedDecl *>(Using)) { 02593 if (Target) { 02594 setDeclName(Target->getDeclName()); 02595 IdentifierNamespace = Target->getIdentifierNamespace(); 02596 } 02597 setImplicit(); 02598 } 02599 02600 public: 02601 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, 02602 SourceLocation Loc, UsingDecl *Using, 02603 NamedDecl *Target) { 02604 return new (C) UsingShadowDecl(DC, Loc, Using, Target); 02605 } 02606 02607 static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); 02608 02609 /// \brief Gets the underlying declaration which has been brought into the 02610 /// local scope. 02611 NamedDecl *getTargetDecl() const { return Underlying; } 02612 02613 /// \brief Sets the underlying declaration which has been brought into the 02614 /// local scope. 02615 void setTargetDecl(NamedDecl* ND) { 02616 assert(ND && "Target decl is null!"); 02617 Underlying = ND; 02618 IdentifierNamespace = ND->getIdentifierNamespace(); 02619 } 02620 02621 /// \brief Gets the using declaration to which this declaration is tied. 02622 UsingDecl *getUsingDecl() const; 02623 02624 /// \brief The next using shadow declaration contained in the shadow decl 02625 /// chain of the using declaration which introduced this decl. 02626 UsingShadowDecl *getNextUsingShadowDecl() const { 02627 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); 02628 } 02629 02630 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02631 static bool classof(const UsingShadowDecl *D) { return true; } 02632 static bool classofKind(Kind K) { return K == Decl::UsingShadow; } 02633 02634 friend class ASTDeclReader; 02635 friend class ASTDeclWriter; 02636 }; 02637 02638 /// UsingDecl - Represents a C++ using-declaration. For example: 02639 /// using someNameSpace::someIdentifier; 02640 class UsingDecl : public NamedDecl { 02641 virtual void anchor(); 02642 02643 /// \brief The source location of the "using" location itself. 02644 SourceLocation UsingLocation; 02645 02646 /// \brief The nested-name-specifier that precedes the name. 02647 NestedNameSpecifierLoc QualifierLoc; 02648 02649 /// DNLoc - Provides source/type location info for the 02650 /// declaration name embedded in the ValueDecl base class. 02651 DeclarationNameLoc DNLoc; 02652 02653 /// \brief The first shadow declaration of the shadow decl chain associated 02654 /// with this using declaration. The bool member of the pair store whether 02655 /// this decl has the 'typename' keyword. 02656 llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow; 02657 02658 UsingDecl(DeclContext *DC, SourceLocation UL, 02659 NestedNameSpecifierLoc QualifierLoc, 02660 const DeclarationNameInfo &NameInfo, bool IsTypeNameArg) 02661 : NamedDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), 02662 UsingLocation(UL), QualifierLoc(QualifierLoc), 02663 DNLoc(NameInfo.getInfo()), FirstUsingShadow(0, IsTypeNameArg) { 02664 } 02665 02666 public: 02667 /// \brief Returns the source location of the "using" keyword. 02668 SourceLocation getUsingLocation() const { return UsingLocation; } 02669 02670 /// \brief Set the source location of the 'using' keyword. 02671 void setUsingLocation(SourceLocation L) { UsingLocation = L; } 02672 02673 /// \brief Retrieve the nested-name-specifier that qualifies the name, 02674 /// with source-location information. 02675 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 02676 02677 /// \brief Retrieve the nested-name-specifier that qualifies the name. 02678 NestedNameSpecifier *getQualifier() const { 02679 return QualifierLoc.getNestedNameSpecifier(); 02680 } 02681 02682 DeclarationNameInfo getNameInfo() const { 02683 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); 02684 } 02685 02686 /// \brief Return true if the using declaration has 'typename'. 02687 bool isTypeName() const { return FirstUsingShadow.getInt(); } 02688 02689 /// \brief Sets whether the using declaration has 'typename'. 02690 void setTypeName(bool TN) { FirstUsingShadow.setInt(TN); } 02691 02692 /// \brief Iterates through the using shadow declarations assosiated with 02693 /// this using declaration. 02694 class shadow_iterator { 02695 /// \brief The current using shadow declaration. 02696 UsingShadowDecl *Current; 02697 02698 public: 02699 typedef UsingShadowDecl* value_type; 02700 typedef UsingShadowDecl* reference; 02701 typedef UsingShadowDecl* pointer; 02702 typedef std::forward_iterator_tag iterator_category; 02703 typedef std::ptrdiff_t difference_type; 02704 02705 shadow_iterator() : Current(0) { } 02706 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) { } 02707 02708 reference operator*() const { return Current; } 02709 pointer operator->() const { return Current; } 02710 02711 shadow_iterator& operator++() { 02712 Current = Current->getNextUsingShadowDecl(); 02713 return *this; 02714 } 02715 02716 shadow_iterator operator++(int) { 02717 shadow_iterator tmp(*this); 02718 ++(*this); 02719 return tmp; 02720 } 02721 02722 friend bool operator==(shadow_iterator x, shadow_iterator y) { 02723 return x.Current == y.Current; 02724 } 02725 friend bool operator!=(shadow_iterator x, shadow_iterator y) { 02726 return x.Current != y.Current; 02727 } 02728 }; 02729 02730 shadow_iterator shadow_begin() const { 02731 return shadow_iterator(FirstUsingShadow.getPointer()); 02732 } 02733 shadow_iterator shadow_end() const { return shadow_iterator(); } 02734 02735 /// \brief Return the number of shadowed declarations associated with this 02736 /// using declaration. 02737 unsigned shadow_size() const { 02738 return std::distance(shadow_begin(), shadow_end()); 02739 } 02740 02741 void addShadowDecl(UsingShadowDecl *S); 02742 void removeShadowDecl(UsingShadowDecl *S); 02743 02744 static UsingDecl *Create(ASTContext &C, DeclContext *DC, 02745 SourceLocation UsingL, 02746 NestedNameSpecifierLoc QualifierLoc, 02747 const DeclarationNameInfo &NameInfo, 02748 bool IsTypeNameArg); 02749 02750 static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID); 02751 02752 SourceRange getSourceRange() const LLVM_READONLY { 02753 return SourceRange(UsingLocation, getNameInfo().getEndLoc()); 02754 } 02755 02756 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02757 static bool classof(const UsingDecl *D) { return true; } 02758 static bool classofKind(Kind K) { return K == Using; } 02759 02760 friend class ASTDeclReader; 02761 friend class ASTDeclWriter; 02762 }; 02763 02764 /// UnresolvedUsingValueDecl - Represents a dependent using 02765 /// declaration which was not marked with 'typename'. Unlike 02766 /// non-dependent using declarations, these *only* bring through 02767 /// non-types; otherwise they would break two-phase lookup. 02768 /// 02769 /// template <class T> class A : public Base<T> { 02770 /// using Base<T>::foo; 02771 /// }; 02772 class UnresolvedUsingValueDecl : public ValueDecl { 02773 virtual void anchor(); 02774 02775 /// \brief The source location of the 'using' keyword 02776 SourceLocation UsingLocation; 02777 02778 /// \brief The nested-name-specifier that precedes the name. 02779 NestedNameSpecifierLoc QualifierLoc; 02780 02781 /// DNLoc - Provides source/type location info for the 02782 /// declaration name embedded in the ValueDecl base class. 02783 DeclarationNameLoc DNLoc; 02784 02785 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, 02786 SourceLocation UsingLoc, 02787 NestedNameSpecifierLoc QualifierLoc, 02788 const DeclarationNameInfo &NameInfo) 02789 : ValueDecl(UnresolvedUsingValue, DC, 02790 NameInfo.getLoc(), NameInfo.getName(), Ty), 02791 UsingLocation(UsingLoc), QualifierLoc(QualifierLoc), 02792 DNLoc(NameInfo.getInfo()) 02793 { } 02794 02795 public: 02796 /// \brief Returns the source location of the 'using' keyword. 02797 SourceLocation getUsingLoc() const { return UsingLocation; } 02798 02799 /// \brief Set the source location of the 'using' keyword. 02800 void setUsingLoc(SourceLocation L) { UsingLocation = L; } 02801 02802 /// \brief Retrieve the nested-name-specifier that qualifies the name, 02803 /// with source-location information. 02804 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 02805 02806 /// \brief Retrieve the nested-name-specifier that qualifies the name. 02807 NestedNameSpecifier *getQualifier() const { 02808 return QualifierLoc.getNestedNameSpecifier(); 02809 } 02810 02811 DeclarationNameInfo getNameInfo() const { 02812 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); 02813 } 02814 02815 static UnresolvedUsingValueDecl * 02816 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 02817 NestedNameSpecifierLoc QualifierLoc, 02818 const DeclarationNameInfo &NameInfo); 02819 02820 static UnresolvedUsingValueDecl * 02821 CreateDeserialized(ASTContext &C, unsigned ID); 02822 02823 SourceRange getSourceRange() const LLVM_READONLY { 02824 return SourceRange(UsingLocation, getNameInfo().getEndLoc()); 02825 } 02826 02827 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02828 static bool classof(const UnresolvedUsingValueDecl *D) { return true; } 02829 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } 02830 02831 friend class ASTDeclReader; 02832 friend class ASTDeclWriter; 02833 }; 02834 02835 /// UnresolvedUsingTypenameDecl - Represents a dependent using 02836 /// declaration which was marked with 'typename'. 02837 /// 02838 /// template <class T> class A : public Base<T> { 02839 /// using typename Base<T>::foo; 02840 /// }; 02841 /// 02842 /// The type associated with a unresolved using typename decl is 02843 /// currently always a typename type. 02844 class UnresolvedUsingTypenameDecl : public TypeDecl { 02845 virtual void anchor(); 02846 02847 /// \brief The source location of the 'using' keyword 02848 SourceLocation UsingLocation; 02849 02850 /// \brief The source location of the 'typename' keyword 02851 SourceLocation TypenameLocation; 02852 02853 /// \brief The nested-name-specifier that precedes the name. 02854 NestedNameSpecifierLoc QualifierLoc; 02855 02856 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, 02857 SourceLocation TypenameLoc, 02858 NestedNameSpecifierLoc QualifierLoc, 02859 SourceLocation TargetNameLoc, 02860 IdentifierInfo *TargetName) 02861 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, 02862 UsingLoc), 02863 TypenameLocation(TypenameLoc), QualifierLoc(QualifierLoc) { } 02864 02865 friend class ASTDeclReader; 02866 02867 public: 02868 /// \brief Returns the source location of the 'using' keyword. 02869 SourceLocation getUsingLoc() const { return getLocStart(); } 02870 02871 /// \brief Returns the source location of the 'typename' keyword. 02872 SourceLocation getTypenameLoc() const { return TypenameLocation; } 02873 02874 /// \brief Retrieve the nested-name-specifier that qualifies the name, 02875 /// with source-location information. 02876 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } 02877 02878 /// \brief Retrieve the nested-name-specifier that qualifies the name. 02879 NestedNameSpecifier *getQualifier() const { 02880 return QualifierLoc.getNestedNameSpecifier(); 02881 } 02882 02883 static UnresolvedUsingTypenameDecl * 02884 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, 02885 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, 02886 SourceLocation TargetNameLoc, DeclarationName TargetName); 02887 02888 static UnresolvedUsingTypenameDecl * 02889 CreateDeserialized(ASTContext &C, unsigned ID); 02890 02891 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02892 static bool classof(const UnresolvedUsingTypenameDecl *D) { return true; } 02893 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } 02894 }; 02895 02896 /// StaticAssertDecl - Represents a C++0x static_assert declaration. 02897 class StaticAssertDecl : public Decl { 02898 virtual void anchor(); 02899 Expr *AssertExpr; 02900 StringLiteral *Message; 02901 SourceLocation RParenLoc; 02902 02903 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, 02904 Expr *assertexpr, StringLiteral *message, 02905 SourceLocation RParenLoc) 02906 : Decl(StaticAssert, DC, StaticAssertLoc), AssertExpr(assertexpr), 02907 Message(message), RParenLoc(RParenLoc) { } 02908 02909 public: 02910 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, 02911 SourceLocation StaticAssertLoc, 02912 Expr *AssertExpr, StringLiteral *Message, 02913 SourceLocation RParenLoc); 02914 static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); 02915 02916 Expr *getAssertExpr() { return AssertExpr; } 02917 const Expr *getAssertExpr() const { return AssertExpr; } 02918 02919 StringLiteral *getMessage() { return Message; } 02920 const StringLiteral *getMessage() const { return Message; } 02921 02922 SourceLocation getRParenLoc() const { return RParenLoc; } 02923 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 02924 02925 SourceRange getSourceRange() const LLVM_READONLY { 02926 return SourceRange(getLocation(), getRParenLoc()); 02927 } 02928 02929 static bool classof(const Decl *D) { return classofKind(D->getKind()); } 02930 static bool classof(StaticAssertDecl *D) { return true; } 02931 static bool classofKind(Kind K) { return K == StaticAssert; } 02932 02933 friend class ASTDeclReader; 02934 }; 02935 02936 /// Insertion operator for diagnostics. This allows sending AccessSpecifier's 02937 /// into a diagnostic with <<. 02938 const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 02939 AccessSpecifier AS); 02940 02941 const PartialDiagnostic &operator<<(const PartialDiagnostic &DB, 02942 AccessSpecifier AS); 02943 02944 } // end namespace clang 02945 02946 #endif