File indexing completed on 2024-05-12 04:37:56
0001 /* 0002 SPDX-FileCopyrightText: 2008 David Nolden <david.nolden@kdevelop.org> 0003 SPDX-FileCopyrightText: 2009 Lior Mualem <lior.m.kde@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #ifndef KDEVPLATFORM_CLASSDECLARATION_H 0009 #define KDEVPLATFORM_CLASSDECLARATION_H 0010 0011 #include <language/duchain/declaration.h> 0012 #include <language/duchain/declarationdata.h> 0013 #include <language/duchain/classmemberdeclarationdata.h> 0014 #include <language/duchain/classmemberdeclaration.h> 0015 0016 namespace KDevelop { 0017 class DUContext; 0018 class TopDUContext; 0019 } 0020 0021 namespace KDevelop { 0022 struct KDEVPLATFORMLANGUAGE_EXPORT BaseClassInstance 0023 { 0024 KDevelop::IndexedType baseClass; //May either be StructureType, or DelayedType 0025 KDevelop::Declaration::AccessPolicy access; 0026 bool virtualInheritance; 0027 }; 0028 0029 KDEVPLATFORMLANGUAGE_EXPORT DECLARE_LIST_MEMBER_HASH(ClassDeclarationData, baseClasses, BaseClassInstance) 0030 0031 class KDEVPLATFORMLANGUAGE_EXPORT ClassDeclarationData 0032 : public KDevelop::ClassMemberDeclarationData 0033 { 0034 public: 0035 enum ClassType { 0036 Class, 0037 Struct, 0038 Union, 0039 Interface, 0040 Trait 0041 }; 0042 0043 enum ClassModifier { 0044 Final, 0045 Abstract, 0046 None 0047 }; 0048 0049 ClassDeclarationData() 0050 : m_classType(Class) 0051 , m_classModifier(None) 0052 { 0053 initializeAppendedLists(); 0054 } 0055 0056 ~ClassDeclarationData() 0057 { 0058 freeAppendedLists(); 0059 } 0060 0061 ClassDeclarationData(const ClassDeclarationData& rhs) 0062 : KDevelop::ClassMemberDeclarationData(rhs) 0063 { 0064 initializeAppendedLists(); 0065 copyListsFrom(rhs); 0066 m_classType = rhs.m_classType; 0067 m_classModifier = rhs.m_classModifier; 0068 } 0069 0070 ClassDeclarationData& operator=(const ClassDeclarationData& rhs) = delete; 0071 0072 /// Type of the class (struct, class, etc.) 0073 ClassType m_classType; 0074 /// Modifier of the class (final, abstract, etc.) 0075 ClassModifier m_classModifier; 0076 0077 START_APPENDED_LISTS_BASE(ClassDeclarationData, KDevelop::ClassMemberDeclarationData); 0078 APPENDED_LIST_FIRST(ClassDeclarationData, BaseClassInstance, baseClasses); 0079 END_APPENDED_LISTS(ClassDeclarationData, baseClasses); 0080 }; 0081 0082 /** 0083 * Represents a single template-parameter definition 0084 */ 0085 class KDEVPLATFORMLANGUAGE_EXPORT ClassDeclaration 0086 : public KDevelop::ClassMemberDeclaration 0087 { 0088 public: 0089 ClassDeclaration(const ClassDeclaration& rhs); 0090 explicit ClassDeclaration(ClassDeclarationData& data); 0091 ClassDeclaration(const KDevelop::RangeInRevision& range, KDevelop::DUContext* context); 0092 ClassDeclaration(ClassDeclarationData& data, const KDevelop::RangeInRevision& range, KDevelop::DUContext* context); 0093 ~ClassDeclaration() override; 0094 0095 void clearBaseClasses(); 0096 ///Count of base-classes 0097 uint baseClassesSize() const; 0098 ///The types this class is based on 0099 const BaseClassInstance* baseClasses() const; 0100 void addBaseClass(const BaseClassInstance& klass); 0101 //Replaces the n'th base-class with the given one. The replaced base-class must have existed. 0102 void replaceBaseClass(uint n, const BaseClassInstance& klass); 0103 0104 /**Returns whether base is a public base-class of this class 0105 * @param baseConversionLevels If nonzero, this will count the distance of the classes. 0106 * */ 0107 bool isPublicBaseClass(ClassDeclaration* base, const KDevelop::TopDUContext* topContext, 0108 int* baseConversionLevels = nullptr) const; 0109 0110 QString toString() const override; 0111 0112 void setClassType(ClassDeclarationData::ClassType type); 0113 0114 ClassDeclarationData::ClassType classType() const; 0115 0116 void setClassModifier(ClassDeclarationData::ClassModifier modifier); 0117 0118 ClassDeclarationData::ClassModifier classModifier() const; 0119 0120 enum { 0121 Identity = 17 0122 }; 0123 0124 private: 0125 KDevelop::Declaration* clonePrivate() const override; 0126 DUCHAIN_DECLARE_DATA(ClassDeclaration) 0127 }; 0128 } 0129 0130 Q_DECLARE_TYPEINFO(KDevelop::BaseClassInstance, Q_MOVABLE_TYPE); 0131 0132 #endif // KDEVPLATFORM_CLASSDECLARATION_H