1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/*
SPDX-FileCopyrightText: 2007-2009 David Nolden <david.nolden.kdevelop@art-master.de>
SPDX-License-Identifier: LGPL-2.0-only
*/
#ifndef KDEVPLATFORM_INSTANTIATIONINFORMATION_H
#define KDEVPLATFORM_INSTANTIATIONINFORMATION_H
#include <language/languageexport.h>
#include "types/abstracttype.h"
#include "types/indexedtype.h"
#include "appendedlist.h"
#include <serialization/referencecounting.h>
namespace KDevelop {
class IndexedInstantiationInformation;
class InstantiationInformation;
class QualifiedIdentifier;
KDEVPLATFORMLANGUAGE_EXPORT DECLARE_LIST_MEMBER_HASH(InstantiationInformation, templateParameters, IndexedType)
/**
* @note Move constructor and move assignment operator are deliberately not implemented for
* IndexedInstantiationInformation. The move operations are tricky to implement correctly and more
* efficiently in practice than the copy operations. swap() could be specialized for this class,
* but it would never be called in practice. See a similar note for class IndexedString.
*/
class KDEVPLATFORMLANGUAGE_EXPORT IndexedInstantiationInformation
: public ReferenceCountManager
{
public:
IndexedInstantiationInformation() noexcept = default;
explicit IndexedInstantiationInformation(uint index);
IndexedInstantiationInformation(const IndexedInstantiationInformation& rhs) noexcept;
IndexedInstantiationInformation& operator=(const IndexedInstantiationInformation& rhs) noexcept;
~IndexedInstantiationInformation();
const InstantiationInformation& information() const;
uint hash() const
{
return m_index * 73;
}
//Is always zero for the empty information
uint index() const
{
return m_index;
}
bool operator==(const IndexedInstantiationInformation& rhs) const
{
return m_index == rhs.m_index;
}
//Returns true if one of the values represented by this information is non-default
bool isValid() const;
private:
uint m_index = 0;
};
class KDEVPLATFORMLANGUAGE_EXPORT InstantiationInformation
{
public:
InstantiationInformation();
///@todo include some information for instantiation only with default parameters
InstantiationInformation(const InstantiationInformation& rhs, bool dynamic = true);
~InstantiationInformation();
InstantiationInformation& operator=(const InstantiationInformation& rhs);
bool operator==(const InstantiationInformation& rhs) const;
uint hash() const;
bool isValid() const
{
return previousInstantiationInformation.index() || templateParametersSize();
}
bool persistent() const
{
return ( bool )m_refCount;
}
/**
* Applies this instantiation information to the given QualifiedIdentifier.
*
* The template parameters of the qualified identifier will be marked as expressions,
* thus the qualified identifier is not "clean".
*
* Should only be used for displaying.
*
* This only adds template-parameters in places where none are known yet.
*/
QualifiedIdentifier applyToIdentifier(const QualifiedIdentifier& id) const;
/**
* @param local If this is true, only the template-parameters of this scope are printed,
* but not the parent ones
*/
QString toString(bool local = false) const;
/**
* This must always be used to add new parameters.
*
* @warning Never use @c templateParametersList() directly.
*/
void addTemplateParameter(const AbstractType::Ptr& type);
/**
* Instantiation-information for the surrounding context(see IndexedInstantiationInformation).
*/
IndexedInstantiationInformation previousInstantiationInformation;
START_APPENDED_LISTS(InstantiationInformation)
static uint classSize()
{
return sizeof(InstantiationInformation);
}
short unsigned int itemSize() const
{
return dynamicSize();
}
/**
* templateParameters contains the template-parameters used for the instantiation
*/
APPENDED_LIST_FIRST(InstantiationInformation, IndexedType, templateParameters);
END_APPENDED_LISTS(InstantiationInformation, templateParameters);
IndexedInstantiationInformation indexed() const;
private:
friend class IndexedInstantiationInformation;
friend struct ItemRepositoryReferenceCounting;
uint m_refCount;
};
inline uint qHash(const IndexedInstantiationInformation& info)
{
return info.hash();
}
inline uint qHash(const InstantiationInformation& info)
{
return info.hash();
}
}
Q_DECLARE_TYPEINFO(KDevelop::IndexedInstantiationInformation, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(KDevelop::InstantiationInformation, Q_MOVABLE_TYPE);
#endif // KDEVPLATFORM_INSTANTIATIONINFORMATION_H
|