kdevplatform/language/duchain
#include <abstracttype.h>

Public Types | |
enum | { Identity = 1 } |
enum | CommonModifiers : quint32 { NoModifiers = 0, ConstModifier = 1 << 0, VolatileModifier = 1 << 1, TransientModifier = 1 << 2, NewModifier = 1 << 3, SealedModifier = 1 << 4, UnsafeModifier = 1 << 5, FixedModifier = 1 << 6, ShortModifier = 1 << 7, LongModifier = 1 << 8, LongLongModifier = 1 << 9, SignedModifier = 1 << 10, UnsignedModifier = 1 << 11, LanguageSpecificModifier = 1 << 12 } |
using | Data = AbstractTypeData |
using | Ptr = TypePtr< AbstractType > |
enum | WhichType : quint8 { TypeAbstract, TypeIntegral, TypePointer, TypeReference, TypeFunction, TypeStructure, TypeArray, TypeDelayed, TypeEnumeration, TypeEnumerator, TypeAlias, TypeUnsure } |
Public Member Functions | |
AbstractType () | |
AbstractType (AbstractTypeData &dd) | |
AbstractType (const AbstractType &rhs)=delete | |
virtual | ~AbstractType () |
void | accept (TypeVisitor *v) const |
int64_t | alignOf () const |
virtual AbstractType * | clone () const =0 |
virtual bool | equals (const AbstractType *rhs) const |
virtual void | exchangeTypes (TypeExchanger *exchanger) |
virtual uint | hash () const |
IndexedType | indexed () const |
void | makeDynamic () |
quint32 | modifiers () const |
AbstractType & | operator= (const AbstractType &rhs)=delete |
void | setAlignOf (int64_t alignedTo) |
void | setModifiers (quint32 modifiers) |
void | setSizeOf (int64_t sizeOf) |
int64_t | sizeOf () const |
virtual QString | toString () const |
virtual WhichType | whichType () const |
![]() | |
QSharedData () | |
QSharedData (const QSharedData &other) | |
Static Public Member Functions | |
static void | acceptType (AbstractType::Ptr type, TypeVisitor *v) |
template<class Type > | |
static Type::Data & | copyData (const typename Type::Data &rhs) |
template<class DataType > | |
static DataType & | copyDataDirectly (const DataType &rhs) |
template<class Type > | |
static Type::Data & | createData () |
Protected Member Functions | |
virtual void | accept0 (TypeVisitor *v) const =0 |
QString | toString (bool spaceOnLeft) const |
Protected Attributes | |
AbstractTypeData * | d_ptr |
Detailed Description
Base class for all types.
The AbstractType class is a base class from which all types derive. It features:
- mechanisms for visiting types
- toString() feature
- equivalence feature
- cloning of types, and
- hashing and indexing
efficient, persistent, and reference-counted storage of types using IndexedType
Type classes are created in a way that allows storing them in memory or on disk efficiently. They are classes which can store arbitrary lists immediately after their private data structures in memory (thus enabling them to be mmapped or memcopied), or being "dynamic" where you use exactly the same class and same access functions, but the list data is stored in a temporary KDevVarLengthArray from a central repository, until we save it back to the static memory-region again.
When creating an own (sub-) type, you must:
- Override equals(..), hash().
- The functions should fully distinguish all types, in regard to all stored information, and regarding their identity.
- This can be skipped if you're overriding a base-type which already incorporates all of your own types status within its equals/hash functions (eg. you don't add own data).
- Implement a copy-constructor in which you copy the data from the source using copyData<YourType>()
- Override the clone() function in which you use the copy-constructor to clone the type
- Add an enumerator "Identity" that contains an arbitrary unique identity value of the type
- Register your type in a source-file using REGISTER_TYPE(..),
- See also
- typeregister.h
- Add a typedef "Data", that contains the actual data of the type using the mechanisms described in appendedlist.h. That data type must follow the same inheritance chain as the type itself, so it must be based on the Data object of the base class. See AbstractTypeData.
- Use createData<YourType>() to create the data-object in a constructor (which you then reach to the parent constructor)
- Use TYPE_DECLARE_DATA(YourType) to declare the data access functions d_func and d_func_dynamic, and then use d_func()->.. and d_func_dynamic()->.. to access your type data
Create a constructor that only takes a reference to the type data, and passes it to the parent type
Every type can have only one other type as base-type, but it can have additional base-classes that are not a direct part of the type-system(
- See also
- IdentifiedType).
- appendedlist.h
Definition at line 87 of file abstracttype.h.
Member Typedef Documentation
◆ Data
Definition at line 299 of file abstracttype.h.
◆ Ptr
Definition at line 91 of file abstracttype.h.
Member Enumeration Documentation
◆ anonymous enum
anonymous enum |
Enumerator | |
---|---|
Identity |
Definition at line 236 of file abstracttype.h.
◆ CommonModifiers
enum KDevelop::AbstractType::CommonModifiers : quint32 |
An enumeration of common modifiers for data types.
If you have any language-specific modifiers that don't belong here, you can add them at/after LanguageSpecificModifier
- Warning
- Think twice what information you store into the type-system. The type-system should store information that is shared among many declarations, and attributes of specific Declarations like public/private should be stored in the Declarations themselves, not in the type-system.
Definition at line 102 of file abstracttype.h.
◆ WhichType
enum KDevelop::AbstractType::WhichType : quint8 |
Enumeration of major data types.
Definition at line 214 of file abstracttype.h.
Constructor & Destructor Documentation
◆ AbstractType() [1/3]
KDevelop::AbstractType::AbstractType | ( | ) |
Constructor.
Definition at line 91 of file abstracttype.cpp.
◆ AbstractType() [2/3]
|
explicit |
Constructor from data.
Definition at line 44 of file abstracttype.cpp.
◆ ~AbstractType()
|
virtual |
Destructor.
Definition at line 96 of file abstracttype.cpp.
◆ AbstractType() [3/3]
|
delete |
Member Function Documentation
◆ accept()
void KDevelop::AbstractType::accept | ( | TypeVisitor * | v | ) | const |
Visitor method.
Called by TypeVisitor to visit the type hierarchy. Do not reimplement this, reimplement accept0 instead.
- Parameters
-
v visitor which is calling this function.
Definition at line 104 of file abstracttype.cpp.
◆ accept0()
|
protectedpure virtual |
Visitor method, reimplement to allow visiting of types.
- Parameters
-
v visitor which is visiting.
Implemented in KDevelop::FunctionType, KDevelop::IntegralType, KDevelop::ReferenceType, KDevelop::ArrayType, KDevelop::PointerType, KDevelop::DelayedType, and KDevelop::UnsureType.
◆ acceptType()
|
static |
Convenience visitor method which can be called with a null type.
- Parameters
-
type type to visit, may be null. v visitor which is visiting the given type
Definition at line 112 of file abstracttype.cpp.
◆ alignOf()
int64_t KDevelop::AbstractType::alignOf | ( | ) | const |
- Returns
- The alignment in bytes or -1 if unknown.
Definition at line 69 of file abstracttype.cpp.
◆ clone()
|
pure virtual |
Should create a clone of the source-type, with as much data copied as possible without breaking the du-chain.
Implemented in KDevelop::FunctionType, KDevelop::IntegralType, KDevelop::ConstantIntegralType, KDevelop::ReferenceType, KDevelop::DelayedType, KDevelop::PointerType, KDevelop::UnsureType, and KDevelop::ArrayType.
◆ copyData()
|
inlinestatic |
Method to create copies of internal type data.
You must use this to create the internal data instances in copy constructors. It is needed, because it may need to allocate more memory for appended lists.
- Parameters
-
rhs data to copy
- Returns
- copy of the data
Definition at line 258 of file abstracttype.h.
◆ copyDataDirectly()
|
inlinestatic |
As above, but does not support copying data into a lower class(Should not be used while cloning)
Definition at line 275 of file abstracttype.h.
◆ createData()
|
inlinestatic |
Method to create internal data structures.
Use this in normal constructors.
- Returns
- the internal data structure
Definition at line 292 of file abstracttype.h.
◆ equals()
|
virtual |
Should return whether this type's content equals the given one Since this is used by the type-repository, it must compare ALL members of the data type.
Reimplemented in KDevelop::ConstantIntegralType, KDevelop::UnsureType, KDevelop::FunctionType, KDevelop::IntegralType, KDevelop::ReferenceType, KDevelop::DelayedType, KDevelop::PointerType, and KDevelop::ArrayType.
Definition at line 134 of file abstracttype.cpp.
◆ exchangeTypes()
|
virtual |
Should, like accept0, be implemented by all types that hold references to other types.
If this is called on one type, that type should call exchangeTypes(..) with all its referenced sub-types. The type itself does not recurse into the sub-types, that can be done by the exchanger itself if desired.
Reimplemented in KDevelop::FunctionType, KDevelop::ReferenceType, KDevelop::ArrayType, KDevelop::PointerType, and KDevelop::UnsureType.
Definition at line 125 of file abstracttype.cpp.
◆ hash()
|
virtual |
A hash-value that should have the following properties:
- When two types match on equals(), it should be same.
- When two types don't match on equals(), it should be different with a high probability.
Reimplemented in KDevelop::FunctionType, KDevelop::IntegralType, KDevelop::ConstantIntegralType, KDevelop::DelayedType, KDevelop::ReferenceType, KDevelop::ArrayType, KDevelop::UnsureType, and KDevelop::PointerType.
Definition at line 142 of file abstracttype.cpp.
◆ indexed()
IndexedType KDevelop::AbstractType::indexed | ( | ) | const |
This can also be called on zero types, those can then be reconstructed from the zero index.
Definition at line 129 of file abstracttype.cpp.
◆ makeDynamic()
void KDevelop::AbstractType::makeDynamic | ( | ) |
Must always be called before anything in the data pointer is changed! If it's not called beforehand, the type-repository gets corrupted.
Definition at line 32 of file abstracttype.cpp.
◆ modifiers()
quint32 KDevelop::AbstractType::modifiers | ( | ) | const |
Access the type modifiers.
- Returns
- the type's modifiers.
Definition at line 49 of file abstracttype.cpp.
◆ operator=()
|
delete |
◆ setAlignOf()
void KDevelop::AbstractType::setAlignOf | ( | int64_t | alignedTo | ) |
Set the alignment to given number of bytes.
The value must be non-negative power of 2 or -1 to represent unknown alignment.
Definition at line 78 of file abstracttype.cpp.
◆ setModifiers()
void KDevelop::AbstractType::setModifiers | ( | quint32 | modifiers | ) |
Set the type's modifiers.
- Parameters
-
modifiers modifiers of this type.
Definition at line 54 of file abstracttype.cpp.
◆ setSizeOf()
void KDevelop::AbstractType::setSizeOf | ( | int64_t | sizeOf | ) |
Set the size to given number of bytes.
Use -1 to represent unknown size.
Definition at line 64 of file abstracttype.cpp.
◆ sizeOf()
int64_t KDevelop::AbstractType::sizeOf | ( | ) | const |
- Returns
- The size in bytes or -1 if unknown.
Definition at line 59 of file abstracttype.cpp.
◆ toString() [1/2]
|
virtual |
Returns this type as a string, preferably the same as it is expressed in the code.
- Returns
- this type as a string
Reimplemented in KDevelop::FunctionType, KDevelop::IntegralType, KDevelop::ConstantIntegralType, KDevelop::ReferenceType, KDevelop::ArrayType, KDevelop::DelayedType, KDevelop::UnsureType, and KDevelop::PointerType.
Definition at line 148 of file abstracttype.cpp.
◆ toString() [2/2]
|
protected |
toString() function which can provide spaceOnLeft rather than on right if desired.
Definition at line 153 of file abstracttype.cpp.
◆ whichType()
|
virtual |
Determine which data type this abstract type represents.
- Returns
- the data type represented by this type.
Reimplemented in KDevelop::FunctionType, KDevelop::IntegralType, KDevelop::DelayedType, KDevelop::ReferenceType, KDevelop::ArrayType, KDevelop::UnsureType, and KDevelop::PointerType.
Definition at line 120 of file abstracttype.cpp.
Member Data Documentation
◆ d_ptr
|
protected |
Definition at line 312 of file abstracttype.h.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jan 21 2021 23:35:47 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.