File indexing completed on 2024-06-16 04:23:17

0001 /*
0002     SPDX-FileCopyrightText: 2006 Roberto Raggi <roberto@kdevelop.org>
0003     SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org>
0004     SPDX-FileCopyrightText: 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 
0009 #ifndef KDEVPLATFORM_TYPESYSTEMDATA_H
0010 #define KDEVPLATFORM_TYPESYSTEMDATA_H
0011 
0012 #include "../appendedlist.h"
0013 #include "indexedtype.h"
0014 #include "delayedtype.h"
0015 #include "identifiedtype.h"
0016 #include "integraltype.h"
0017 
0018 namespace KDevelop {
0019 KDEVPLATFORMLANGUAGE_EXPORT DECLARE_LIST_MEMBER_HASH(FunctionTypeData, m_arguments, IndexedType)
0020 
0021 /**
0022  * Private data structure for AbstractType.
0023  *
0024  * Inherit from this for custom type private data.
0025  *
0026  * Within your inherited data types, you can use the mechanisms described in appendedlist.h
0027  *
0028  * You must explicitly implement the copy constructor, see appendedlist.h for more information on copying dynamic data.
0029  * When calling initializeAppendedLists() as described there, you should always use m_dynamic as parameter.
0030  */
0031 class KDEVPLATFORMLANGUAGE_EXPORT AbstractTypeData
0032 {
0033 public:
0034     /// Constructor.
0035     AbstractTypeData();
0036     /**
0037      * Copy constructor.
0038      *
0039      * While cloning, the dynamic/constant attribute alternates(The copy of dynamic data is constant, and the copy of constant data is dynamic)
0040      * This means that when copying dynamic data, the size of the allocated buffer must be big enough to hold the appended lists.
0041      * the AbstractType::copyData function cares about that.
0042      *
0043      * \param rhs data to copy.
0044      */
0045     AbstractTypeData(const AbstractTypeData& rhs);
0046     /// Destructor.
0047     ~AbstractTypeData();
0048 
0049     AbstractTypeData& operator=(const AbstractTypeData&) = delete;
0050 
0051     /**
0052      * Internal setup for the data structure.
0053      *
0054      * This must be called from actual class that belongs to this data(not parent classes), and the class must have the
0055      * "Identity" enumerator with a unique identity. Do NOT call this in copy-constructors!
0056      */
0057     template <class T>
0058     void setTypeClassId()
0059     {
0060         static_assert(T::Identity < std::numeric_limits<decltype(typeClassId)>::max(), "TypeClass ID out of bounds");
0061         typeClassId = T::Identity;
0062     }
0063 
0064     /// Stores sizeOf in bytes or -1 if unknown.
0065     int64_t m_sizeOf = -1;
0066 
0067     /**
0068      * Since alignOf must be integral power of 2, we only need to store the power.
0069      * The max value (63) represents unknown alignment.
0070      */
0071     unsigned m_alignOfExponent : 6;
0072     static constexpr unsigned MaxAlignOfExponent = 63;
0073 
0074     /// Type modifier flags
0075     quint32 m_modifiers = AbstractType::NoModifiers;
0076 
0077     /// Reference-count for this type within the repository. Not used for comparison or hashes.
0078     uint refCount = 0;
0079 
0080     /// Remember which type this data was created for. \sa setTypeClassId()
0081     quint16 typeClassId;
0082 
0083     /// Remember whether this type is in a TypeRepository. Not used for comparison or hashes.
0084     bool inRepository : 1;
0085 
0086     APPENDED_LISTS_STUB(AbstractTypeData)
0087 
0088     /// Returns the pure data size of this class(not including anything dynamic).
0089     uint classSize() const;
0090 
0091     /// Returns the complete size of this item in memory, including derived class data and derived class appended list data
0092     unsigned int itemSize() const;
0093 
0094     /// Expensive
0095     unsigned int hash() const;
0096 
0097     void freeDynamicData()
0098     {
0099     }
0100 };
0101 
0102 /// Private data structure for IntegralType
0103 class KDEVPLATFORMLANGUAGE_EXPORT IntegralTypeData
0104     : public AbstractTypeData
0105 {
0106 public:
0107     /// Constructor
0108     IntegralTypeData();
0109     /// Copy constructor. \param rhs data to copy
0110     IntegralTypeData(const IntegralTypeData& rhs);
0111     IntegralTypeData& operator=(const IntegralTypeData& rhs) = delete;
0112     ~IntegralTypeData() = default;
0113     /// Data type
0114     uint m_dataType = IntegralType::TypeNone;
0115 };
0116 
0117 /// Private data structure for PointerType
0118 class KDEVPLATFORMLANGUAGE_EXPORT PointerTypeData
0119     : public AbstractTypeData
0120 {
0121 public:
0122     /// Constructor
0123     PointerTypeData();
0124     /// Copy constructor. \param rhs data to copy
0125     PointerTypeData(const PointerTypeData& rhs);
0126     ~PointerTypeData() = default;
0127     PointerTypeData& operator=(const PointerTypeData& rhs) = delete;
0128     /// Type of data at which the pointer points
0129     IndexedType m_baseType;
0130 };
0131 
0132 /// Private data structure for ReferenceType
0133 class KDEVPLATFORMLANGUAGE_EXPORT ReferenceTypeData
0134     : public AbstractTypeData
0135 {
0136 public:
0137     /// Constructor
0138     ReferenceTypeData();
0139     /// Copy constructor. \param rhs data to copy
0140     ReferenceTypeData(const ReferenceTypeData& rhs);
0141     ~ReferenceTypeData() = default;
0142     ReferenceTypeData& operator=(const ReferenceTypeData& rhs) = delete;
0143     /// Type of data which is referenced
0144     IndexedType m_baseType;
0145     /// True if this is an rvalue-reference, false for lvalue-references
0146     bool m_isRValue : 1;
0147 };
0148 
0149 KDEVPLATFORMLANGUAGE_EXPORT DECLARE_LIST_MEMBER_HASH(FunctionTypeData, m_arguments, IndexedType)
0150 
0151 /// Private data structure for FunctionType
0152 class KDEVPLATFORMLANGUAGE_EXPORT FunctionTypeData
0153     : public AbstractTypeData
0154 {
0155 public:
0156     /// Constructor
0157     FunctionTypeData();
0158     /// Copy constructor. \param rhs data to copy
0159     FunctionTypeData(const FunctionTypeData& rhs);
0160     /// Destructor
0161     ~FunctionTypeData();
0162 
0163     /// Function return type
0164     IndexedType m_returnType;
0165 
0166     START_APPENDED_LISTS_BASE(FunctionTypeData, AbstractTypeData);
0167 
0168     APPENDED_LIST_FIRST(FunctionTypeData, IndexedType, m_arguments);
0169 
0170     END_APPENDED_LISTS(FunctionTypeData, m_arguments);
0171 
0172 private:
0173     void operator=(const FunctionTypeData& rhs);
0174 };
0175 
0176 /// Private data structure for ReferenceType
0177 class KDEVPLATFORMLANGUAGE_EXPORT TypeAliasTypeData
0178     :  public MergeIdentifiedType<AbstractType>::Data
0179 {
0180 public:
0181     /// Type of data which is typedeffed
0182     IndexedType m_type;
0183 };
0184 
0185 /// Private data structure for StructureType
0186 class KDEVPLATFORMLANGUAGE_EXPORT StructureTypeData
0187     : public MergeIdentifiedType<AbstractType>::Data
0188 {
0189 public:
0190     /// Constructor
0191     StructureTypeData();
0192     /// Copy constructor. \param rhs data to copy
0193     StructureTypeData(const StructureTypeData& rhs);
0194     ~StructureTypeData() = default;
0195     /// Whether the type is closed yet
0196     StructureTypeData& operator=(const StructureTypeData& rhs) = delete;
0197 };
0198 
0199 /// Private data structure for ArrayType
0200 class KDEVPLATFORMLANGUAGE_EXPORT ArrayTypeData
0201     : public AbstractTypeData
0202 {
0203 public:
0204     /// Constructor
0205     ArrayTypeData();
0206     /// Copy constructor. \param rhs data to copy
0207     ArrayTypeData(const ArrayTypeData& rhs);
0208     ~ArrayTypeData() = default;
0209     ArrayTypeData& operator=(const ArrayTypeData& rhs) = delete;
0210     /// Dimension of the array
0211     int m_dimension = 0;
0212     /// Element type of the array
0213     IndexedType m_elementType;
0214 };
0215 
0216 /// Private data structure for DelayedType
0217 class KDEVPLATFORMLANGUAGE_EXPORT DelayedTypeData
0218     : public AbstractTypeData
0219 {
0220 public:
0221     /// Constructor
0222     DelayedTypeData();
0223     /// Copy constructor. \param rhs data to copy
0224     DelayedTypeData(const DelayedTypeData& rhs);
0225     ~DelayedTypeData() = default;
0226     DelayedTypeData& operator=(const DelayedTypeData& rhs) = delete;
0227     /// Identifier of the delayed type
0228     IndexedTypeIdentifier m_identifier;
0229     /// Type of delay in resolving the type
0230     DelayedType::Kind m_kind = DelayedType::Delayed;
0231 };
0232 
0233 /// Private data structure for ConstantIntegralType
0234 struct ConstantIntegralTypeData
0235     : public IntegralTypeData
0236 {
0237     /// Constructor
0238     ConstantIntegralTypeData();
0239     /// Constant integer value
0240     qint64 m_value = 0;
0241 };
0242 }
0243 #endif