diff options
Diffstat (limited to 'include/clang/AST/DeclCXX.h')
-rw-r--r-- | include/clang/AST/DeclCXX.h | 193 |
1 files changed, 101 insertions, 92 deletions
diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 7f3ec4c..851e310 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -41,6 +41,7 @@ class CXXFinalOverriderMap; class CXXIndirectPrimaryBaseSet; class FriendDecl; class LambdaExpr; +class UsingDecl; /// \brief Represents any kind of function declaration, whether it is a /// concrete function or a function template. @@ -98,7 +99,7 @@ namespace llvm { namespace clang { -/// AccessSpecDecl - An access specifier followed by colon ':'. +/// @brief Represents an access specifier followed by colon ':'. /// /// An objects of this class represents sugar for the syntactic occurrence /// of an access specifier followed by a colon in the list of member @@ -110,7 +111,7 @@ namespace clang { /// "access declarations" (C++98 11.3 [class.access.dcl]). class AccessSpecDecl : public Decl { virtual void anchor(); - /// ColonLoc - The location of the ':'. + /// \brief The location of the ':'. SourceLocation ColonLoc; AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, @@ -121,14 +122,14 @@ class AccessSpecDecl : public Decl { AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) { } public: - /// getAccessSpecifierLoc - The location of the access specifier. + /// \brief The location of the access specifier. SourceLocation getAccessSpecifierLoc() const { return getLocation(); } - /// setAccessSpecifierLoc - Sets the location of the access specifier. + /// \brief Sets the location of the access specifier. void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } - /// getColonLoc - The location of the colon following the access specifier. + /// \brief The location of the colon following the access specifier. SourceLocation getColonLoc() const { return ColonLoc; } - /// setColonLoc - Sets the location of the colon. + /// \brief Sets the location of the colon. void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } SourceRange getSourceRange() const LLVM_READONLY { @@ -149,7 +150,7 @@ public: }; -/// CXXBaseSpecifier - A base class of a C++ class. +/// \brief Represents a base class of a C++ class. /// /// Each CXXBaseSpecifier represents a single, direct base class (or /// struct) of a C++ class (or struct). It specifies the type of that @@ -175,7 +176,7 @@ class CXXBaseSpecifier { /// expansion. SourceLocation EllipsisLoc; - /// Virtual - Whether this is a virtual base class or not. + /// \brief Whether this is a virtual base class or not. bool Virtual : 1; /// BaseOfClass - Whether this is the base of a class (true) or of a @@ -357,6 +358,9 @@ class CXXRecordDecl : public RecordDecl { /// \brief True if there no non-field members declared by the user. bool HasOnlyCMembers : 1; + /// \brief True if any field has an in-class initializer. + bool HasInClassInitializer : 1; + /// HasTrivialDefaultConstructor - True when, if this class has a default /// constructor, this default constructor is trivial. /// @@ -382,26 +386,10 @@ class CXXRecordDecl : public RecordDecl { /// constructor for this class would be constexpr. bool DefaultedDefaultConstructorIsConstexpr : 1; - /// DefaultedCopyConstructorIsConstexpr - True if a defaulted copy - /// constructor for this class would be constexpr. - bool DefaultedCopyConstructorIsConstexpr : 1; - - /// DefaultedMoveConstructorIsConstexpr - True if a defaulted move - /// constructor for this class would be constexpr. - bool DefaultedMoveConstructorIsConstexpr : 1; - /// HasConstexprDefaultConstructor - True if this class has a constexpr /// default constructor (either user-declared or implicitly declared). bool HasConstexprDefaultConstructor : 1; - /// HasConstexprCopyConstructor - True if this class has a constexpr copy - /// constructor (either user-declared or implicitly declared). - bool HasConstexprCopyConstructor : 1; - - /// HasConstexprMoveConstructor - True if this class has a constexpr move - /// constructor (either user-declared or implicitly declared). - bool HasConstexprMoveConstructor : 1; - /// HasTrivialCopyConstructor - True when this class has a trivial copy /// constructor. /// @@ -554,13 +542,21 @@ class CXXRecordDecl : public RecordDecl { /// \brief Retrieve the set of direct base classes. CXXBaseSpecifier *getBases() const { - return Bases.get(Definition->getASTContext().getExternalSource()); + if (!Bases.isOffset()) + return Bases.get(0); + return getBasesSlowCase(); } /// \brief Retrieve the set of virtual base classes. CXXBaseSpecifier *getVBases() const { - return VBases.get(Definition->getASTContext().getExternalSource()); + if (!VBases.isOffset()) + return VBases.get(0); + return getVBasesSlowCase(); } + + private: + CXXBaseSpecifier *getBasesSlowCase() const; + CXXBaseSpecifier *getVBasesSlowCase() const; } *DefinitionData; /// \brief Describes a C++ closure type (generated by a lambda expression). @@ -647,6 +643,9 @@ class CXXRecordDecl : public RecordDecl { void markedVirtualFunctionPure(); friend void FunctionDecl::setPure(bool); + void markedConstructorConstexpr(CXXConstructorDecl *CD); + friend void FunctionDecl::setConstexpr(bool); + friend class ASTNodeImporter; protected: @@ -1040,6 +1039,10 @@ public: /// no base classes, and no virtual functions (C++ [dcl.init.aggr]p1). bool isAggregate() const { return data().Aggregate; } + /// hasInClassInitializer - Whether this class has any in-class initializers + /// for non-static data members. + bool hasInClassInitializer() const { return data().HasInClassInitializer; } + /// isPOD - Whether this class is a POD-type (C++ [class]p4), which is a class /// that is an aggregate that has no non-static non-POD data members, no /// reference data members, no user-defined copy assignment operator and no @@ -1091,19 +1094,8 @@ public: /// defaultedDefaultConstructorIsConstexpr - Whether a defaulted default /// constructor for this class would be constexpr. bool defaultedDefaultConstructorIsConstexpr() const { - return data().DefaultedDefaultConstructorIsConstexpr; - } - - /// defaultedCopyConstructorIsConstexpr - Whether a defaulted copy - /// constructor for this class would be constexpr. - bool defaultedCopyConstructorIsConstexpr() const { - return data().DefaultedCopyConstructorIsConstexpr; - } - - /// defaultedMoveConstructorIsConstexpr - Whether a defaulted move - /// constructor for this class would be constexpr. - bool defaultedMoveConstructorIsConstexpr() const { - return data().DefaultedMoveConstructorIsConstexpr; + return data().DefaultedDefaultConstructorIsConstexpr && + (!isUnion() || hasInClassInitializer()); } /// hasConstexprDefaultConstructor - Whether this class has a constexpr @@ -1111,23 +1103,7 @@ public: bool hasConstexprDefaultConstructor() const { return data().HasConstexprDefaultConstructor || (!data().UserDeclaredConstructor && - data().DefaultedDefaultConstructorIsConstexpr && isLiteral()); - } - - /// hasConstexprCopyConstructor - Whether this class has a constexpr copy - /// constructor. - bool hasConstexprCopyConstructor() const { - return data().HasConstexprCopyConstructor || - (!data().DeclaredCopyConstructor && - data().DefaultedCopyConstructorIsConstexpr && isLiteral()); - } - - /// hasConstexprMoveConstructor - Whether this class has a constexpr move - /// constructor. - bool hasConstexprMoveConstructor() const { - return data().HasConstexprMoveConstructor || - (needsImplicitMoveConstructor() && - data().DefaultedMoveConstructorIsConstexpr && isLiteral()); + defaultedDefaultConstructorIsConstexpr()); } // hasTrivialCopyConstructor - Whether this class has a trivial copy @@ -1212,12 +1188,12 @@ public: /// This routine will return non-NULL for (non-templated) member /// classes of class templates. For example, given: /// - /// \code + /// @code /// template<typename T> /// struct X { /// struct A { }; /// }; - /// \endcode + /// @endcode /// /// The declaration for X<int>::A is a (non-templated) CXXRecordDecl /// whose parent is the class template specialization X<int>. For @@ -1319,7 +1295,7 @@ public: /// /// \returns true if this class is virtually derived from Base, /// false otherwise. - bool isVirtuallyDerivedFrom(CXXRecordDecl *Base) const; + bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const; /// \brief Determine whether this class is provably not derived from /// the type \p Base. @@ -1573,6 +1549,9 @@ public: bool isStatic() const { return getStorageClass() == SC_Static; } bool isInstance() const { return !isStatic(); } + bool isConst() { return getType()->castAs<FunctionType>()->isConst(); } + bool isVolatile() { return getType()->castAs<FunctionType>()->isVolatile(); } + bool isVirtual() const { CXXMethodDecl *CD = cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl()); @@ -1602,8 +1581,8 @@ public: return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); } - /// isUserProvided - True if it is either an implicit constructor or - /// if it was defaulted or deleted on first declaration. + /// isUserProvided - True if this method is user-declared and was not + /// deleted or defaulted on its first declaration. bool isUserProvided() const { return !(isDeleted() || getCanonicalDecl()->isDefaulted()); } @@ -1642,13 +1621,13 @@ public: /// /// In the following example, \c f() has an lvalue ref-qualifier, \c g() /// has an rvalue ref-qualifier, and \c h() has no ref-qualifier. - /// \code + /// @code /// struct X { /// void f() &; /// void g() &&; /// void h(); /// }; - /// \endcode + /// @endcode RefQualifierKind getRefQualifier() const { return getType()->getAs<FunctionProtoType>()->getRefQualifier(); } @@ -1663,7 +1642,20 @@ public: /// supplied by IR generation to either forward to the function call operator /// or clone the function call operator. bool isLambdaStaticInvoker() const; - + + /// \brief Find the method in RD that corresponds to this one. + /// + /// Find if RD or one of the classes it inherits from override this method. + /// If so, return it. RD is assumed to be a base class of the class defining + /// this method (or be the class itself). + CXXMethodDecl * + getCorrespondingMethodInClass(const CXXRecordDecl *RD); + + const CXXMethodDecl * + getCorrespondingMethodInClass(const CXXRecordDecl *RD) const { + return const_cast<CXXMethodDecl*>(this)->getCorrespondingMethodInClass(RD); + } + // Implement isa/cast/dyncast/etc. static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const CXXMethodDecl *D) { return true; } @@ -2468,7 +2460,9 @@ public: friend class ASTDeclReader; }; -/// NamespaceAliasDecl - Represents a C++ namespace alias. For example: +/// \brief Represents a C++ namespace alias. +/// +/// For example: /// /// @code /// namespace Foo = Bar; @@ -2555,17 +2549,19 @@ public: static bool classofKind(Kind K) { return K == NamespaceAlias; } }; -/// UsingShadowDecl - Represents a shadow declaration introduced into -/// a scope by a (resolved) using declaration. For example, +/// \brief Represents a shadow declaration introduced into a scope by a +/// (resolved) using declaration. /// +/// For example, +/// @code /// namespace A { /// void foo(); /// } /// namespace B { -/// using A::foo(); // <- a UsingDecl -/// // Also creates a UsingShadowDecl for A::foo in B +/// using A::foo; // <- a UsingDecl +/// // Also creates a UsingShadowDecl for A::foo() in B /// } -/// +/// @endcode class UsingShadowDecl : public NamedDecl { virtual void anchor(); @@ -2627,8 +2623,12 @@ public: friend class ASTDeclWriter; }; -/// UsingDecl - Represents a C++ using-declaration. For example: +/// \brief Represents a C++ using-declaration. +/// +/// For example: +/// @code /// using someNameSpace::someIdentifier; +/// @endcode class UsingDecl : public NamedDecl { virtual void anchor(); @@ -2643,8 +2643,10 @@ class UsingDecl : public NamedDecl { DeclarationNameLoc DNLoc; /// \brief The first shadow declaration of the shadow decl chain associated - /// with this using declaration. The bool member of the pair store whether - /// this decl has the 'typename' keyword. + /// with this using declaration. + /// + /// The bool member of the pair store whether this decl has the \c typename + /// keyword. llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow; UsingDecl(DeclContext *DC, SourceLocation UL, @@ -2753,14 +2755,17 @@ public: friend class ASTDeclWriter; }; -/// UnresolvedUsingValueDecl - Represents a dependent using -/// declaration which was not marked with 'typename'. Unlike -/// non-dependent using declarations, these *only* bring through +/// \brief Represents a dependent using declaration which was not marked with +/// \c typename. +/// +/// Unlike non-dependent using declarations, these *only* bring through /// non-types; otherwise they would break two-phase lookup. /// -/// template <class T> class A : public Base<T> { +/// @code +/// template \<class T> class A : public Base<T> { /// using Base<T>::foo; /// }; +/// @endcode class UnresolvedUsingValueDecl : public ValueDecl { virtual void anchor(); @@ -2824,14 +2829,16 @@ public: friend class ASTDeclWriter; }; -/// UnresolvedUsingTypenameDecl - Represents a dependent using -/// declaration which was marked with 'typename'. +/// @brief Represents a dependent using declaration which was marked with +/// \c typename. /// -/// template <class T> class A : public Base<T> { +/// @code +/// template \<class T> class A : public Base<T> { /// using typename Base<T>::foo; /// }; +/// @endcode /// -/// The type associated with a unresolved using typename decl is +/// The type associated with an unresolved using typename decl is /// currently always a typename type. class UnresolvedUsingTypenameDecl : public TypeDecl { virtual void anchor(); @@ -2885,34 +2892,36 @@ public: static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } }; -/// StaticAssertDecl - Represents a C++0x static_assert declaration. +/// \brief Represents a C++11 static_assert declaration. class StaticAssertDecl : public Decl { virtual void anchor(); - Expr *AssertExpr; + llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed; StringLiteral *Message; SourceLocation RParenLoc; StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, - Expr *assertexpr, StringLiteral *message, - SourceLocation RParenLoc) - : Decl(StaticAssert, DC, StaticAssertLoc), AssertExpr(assertexpr), - Message(message), RParenLoc(RParenLoc) { } + Expr *AssertExpr, StringLiteral *Message, + SourceLocation RParenLoc, bool Failed) + : Decl(StaticAssert, DC, StaticAssertLoc), + AssertExprAndFailed(AssertExpr, Failed), Message(Message), + RParenLoc(RParenLoc) { } public: static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation StaticAssertLoc, Expr *AssertExpr, StringLiteral *Message, - SourceLocation RParenLoc); + SourceLocation RParenLoc, bool Failed); static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); - Expr *getAssertExpr() { return AssertExpr; } - const Expr *getAssertExpr() const { return AssertExpr; } + Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); } + const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); } StringLiteral *getMessage() { return Message; } const StringLiteral *getMessage() const { return Message; } + bool isFailed() const { return AssertExprAndFailed.getInt(); } + SourceLocation getRParenLoc() const { return RParenLoc; } - void setRParenLoc(SourceLocation L) { RParenLoc = L; } SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(getLocation(), getRParenLoc()); @@ -2925,7 +2934,7 @@ public: friend class ASTDeclReader; }; -/// Insertion operator for diagnostics. This allows sending AccessSpecifier's +/// Insertion operator for diagnostics. This allows sending an AccessSpecifier /// into a diagnostic with <<. const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, AccessSpecifier AS); |