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

Public Types | |
enum | { Identity = 7 } |
enum | AccessPolicy : quint8 { Public, Protected, Private, DefaultAccess } |
enum | Kind : quint8 { Type, Instance, NamespaceAlias, Alias, Namespace, Import, Macro } |
![]() | |
enum | { Identity = 1 } |
Public Member Functions | |
Declaration (const Declaration &rhs) | |
Declaration (const RangeInRevision &range, DUContext *parentContext) | |
Declaration (DeclarationData &dd) | |
~Declaration () override | |
AbstractType::Ptr | abstractType () const |
virtual void | activateSpecialization () |
virtual uint | additionalIdentity () const |
void | allocateOwnIndex () |
bool | alwaysForceDirect () const |
void | clearOwnIndex () |
Declaration * | clone () const |
QByteArray | comment () const |
DUContext * | context () const |
bool | equalQualifiedIdentifier (const Declaration *rhs) const |
bool | hasUses () const |
virtual DeclarationId | id (bool forceDirect=false) const |
Identifier | identifier () const |
const IndexedIdentifier & | indexedIdentifier () const |
IndexedType | indexedType () const |
virtual bool | inDUChain () const |
bool | inSymbolTable () const |
DUContext * | internalContext () const |
bool | isAnonymous () const |
bool | isAutoDeclaration () const |
bool | isDefinition () const |
bool | isDeprecated () const |
bool | isExplicitlyDeleted () const |
bool | isExplicitlyTyped () const |
virtual bool | isForwardDeclaration () const |
virtual bool | isFunctionDeclaration () const |
bool | isTypeAlias () const |
Kind | kind () const |
Declaration * | logicalDeclaration (const TopDUContext *topContext) |
const Declaration * | logicalDeclaration (const TopDUContext *topContext) const |
virtual DUContext * | logicalInternalContext (const TopDUContext *topContext) const |
Declaration & | operator= (const Declaration &rhs)=delete |
bool | operator== (const Declaration &other) const |
uint | ownIndex () const |
QualifiedIdentifier | qualifiedIdentifier () const |
virtual void | setAbstractType (AbstractType::Ptr type) |
void | setAlwaysForceDirect (bool direct) |
void | setAutoDeclaration (bool _auto) |
void | setComment (const QByteArray &str) |
void | setComment (const QString &str) |
void | setContext (DUContext *context, bool anonymous=false) |
void | setDeclarationIsDefinition (bool dd) |
void | setDeprecated (bool deprecated) |
void | setExplicitlyDeleted (bool deleted) |
void | setExplicitlyTyped (bool explicitlyTyped) |
void | setIdentifier (const Identifier &identifier) |
virtual void | setInSymbolTable (bool inSymbolTable) |
void | setInternalContext (DUContext *context) |
void | setIsTypeAlias (bool typeAlias) |
void | setKind (Kind kind) |
template<class T > | |
void | setType (TypePtr< T > type) |
virtual IndexedInstantiationInformation | specialization () const |
virtual Declaration * | specialize (const IndexedInstantiationInformation &specialization, const TopDUContext *topContext, int upDistance=0) |
TopDUContext * | topContext () const override |
virtual QString | toString () const |
template<class T > | |
TypePtr< T > | type () const |
QMap< IndexedString, QVector< RangeInRevision > > | uses () const |
QMap< IndexedString, QVector< KTextEditor::Range > > | usesCurrentRevision () const |
![]() | |
DUChainBase (const RangeInRevision &range) | |
DUChainBase (DUChainBaseData &dd) | |
virtual | ~DUChainBase () |
PersistentMovingRange::Ptr | createRangeMoving () const |
void | makeDynamic () |
DUChainBase & | operator= (const DUChainBase &rhs)=delete |
RangeInRevision | range () const |
KTextEditor::Range | rangeInCurrentRevision () const |
virtual void | setData (DUChainBaseData *, bool constructorCalled=true) |
void | setRange (const RangeInRevision &range) |
KTextEditor::Cursor | transformFromLocalRevision (const CursorInRevision &cursor) const |
KTextEditor::Range | transformFromLocalRevision (const RangeInRevision &range) const |
CursorInRevision | transformToLocalRevision (const KTextEditor::Cursor &cursor) const |
RangeInRevision | transformToLocalRevision (const KTextEditor::Range &range) const |
virtual IndexedString | url () const |
const QExplicitlySharedDataPointer< DUChainPointerData > & | weakPointer () const |
Protected Member Functions | |
Declaration (DeclarationData &dd, const RangeInRevision &range) | |
bool | persistentlyDestroying () const |
![]() | |
DUChainBase (DUChainBase &rhs) | |
DUChainBase (DUChainBaseData &dd, const RangeInRevision &range) | |
Additional Inherited Members | |
![]() | |
DUChainBaseData * | d_ptr |
Detailed Description
Represents a single declaration in a definition-use chain.
- Note
- A du-context can be freely edited as long as it's parent-context is zero. In the moment the parent-context is set, the context may only be edited when it is allowed to edited it's top-level context (
- See also
- TopLevelContext::inDUChain())
Definition at line 51 of file declaration.h.
Member Enumeration Documentation
◆ anonymous enum
anonymous enum |
Enumerator | |
---|---|
Identity |
Definition at line 542 of file declaration.h.
◆ AccessPolicy
enum KDevelop::Declaration::AccessPolicy : quint8 |
Access types.
Enumerator | |
---|---|
Public | a public declaration |
Protected | a protected declaration |
Private | a private declaration |
DefaultAccess | a declaration with default access; in java, only package-level access. |
Definition at line 56 of file declaration.h.
◆ Kind
enum KDevelop::Declaration::Kind : quint8 |
Enumeration of the types of declarations.
Enumerator | |
---|---|
Type | A type is declared, like a class-declaration or function-declaration, or a typedef("class MyClass {};") |
Instance | An instance of a type is declared("MyClass m;") |
NamespaceAlias | This is a namespace-alias. You can safely cast this object to NamespaceAliasDeclaration. |
Alias | This is an alias-declaration. You can safely cast this object to AliasDeclaration. |
Namespace | Declaration of a namespace. |
Import | Declaration marks the Import of a file. |
Macro | Declaration of a macro such as "#define FOO 1". |
Definition at line 63 of file declaration.h.
Constructor & Destructor Documentation
◆ Declaration() [1/4]
KDevelop::Declaration::Declaration | ( | const RangeInRevision & | range, |
DUContext * | parentContext | ||
) |
Constructor.
If parentContext is in the symbol table, the declaration will automatically be added into the symbol table.
- Parameters
-
range range of the alias declaration's identifier parentContext context in which this declaration occurred
Definition at line 102 of file declaration.cpp.
◆ Declaration() [2/4]
KDevelop::Declaration::Declaration | ( | const Declaration & | rhs | ) |
Copy-constructor for cloning.
Definition at line 120 of file declaration.cpp.
◆ ~Declaration()
|
override |
Destructor.
Definition at line 140 of file declaration.cpp.
◆ Declaration() [3/4]
|
explicit |
Uses the given data.
Definition at line 125 of file declaration.cpp.
◆ Declaration() [4/4]
|
protected |
Constructor for copy constructors in subclasses.
- Parameters
-
dd data to copy. range text range which this object covers.
Definition at line 129 of file declaration.cpp.
Member Function Documentation
◆ abstractType()
AbstractType::Ptr KDevelop::Declaration::abstractType | ( | ) | const |
Access this declaration's type.
- Note
- You should not compare or permanently store instances of AbstractType::Ptr. Use IndexedType instead.
- Returns
- this declaration's type, or null if none has been assigned.
Definition at line 243 of file declaration.cpp.
◆ activateSpecialization()
|
virtual |
Signalized that among multiple possible specializations, this one should be used in the UI from now on.
Currently mainly used in C++ for template support. The default-implementation registers the current specialization of this declaration to SpecializationStore if it is nonzero.
Definition at line 555 of file declaration.cpp.
◆ additionalIdentity()
|
virtual |
This hash-value should differentiate between multiple different declarations that have the same qualifiedIdentifier, but should have a different identity, and thus own Definitions and own Uses assigned.
Affected by function-arguments, whether this is a template-declaration, etc..
Definition at line 660 of file declaration.cpp.
◆ allocateOwnIndex()
void KDevelop::Declaration::allocateOwnIndex | ( | ) |
Create an index to this declaration from the topContext().
Needed to be able to retrieve ownIndex().
- Todo:
- Fix multithreading stuff with template instantiation, preferably using some internal mutexes
Definition at line 354 of file declaration.cpp.
◆ alwaysForceDirect()
bool KDevelop::Declaration::alwaysForceDirect | ( | ) | const |
Determine whether this declaration must always be direct.
Definition at line 507 of file declaration.cpp.
◆ clearOwnIndex()
void KDevelop::Declaration::clearOwnIndex | ( | ) |
Clear the index for this declaration in the top context that was allocated with allocateOwnIndex().
Definition at line 338 of file declaration.cpp.
◆ clone()
Declaration * KDevelop::Declaration::clone | ( | ) | const |
Returns a clone of this declaration, with the difference that the returned declaration has no context set, i.e.
context()
returns zero.
The declaration will not be registered anywhere, so you must care about its deletion.
This declaration's text-range will be referenced from the clone, so the clone must not live longer than the original.
Definition at line 643 of file declaration.cpp.
◆ comment()
QByteArray KDevelop::Declaration::comment | ( | ) | const |
Returns the comment associated to this declaration in the source-code, or an invalid string if there is none.
Stored in utf-8 encoding.
Definition at line 177 of file declaration.cpp.
◆ context()
DUContext * KDevelop::Declaration::context | ( | ) | const |
Access the parent context of this declaration.
- Returns
- the parent context of this declaration.
Definition at line 279 of file declaration.cpp.
◆ equalQualifiedIdentifier()
bool KDevelop::Declaration::equalQualifiedIdentifier | ( | const Declaration * | rhs | ) | const |
Compares the qualified identifier of this declaration with the other one, without needing to compute it.
This is more efficient than comparing the results of qualifiedIdentifier().
- Parameters
-
rhs declaration to compare identifiers with
- Returns
- true if the identifiers are equal, otherwise false.
Definition at line 665 of file declaration.cpp.
◆ hasUses()
bool KDevelop::Declaration::hasUses | ( | ) | const |
Determines whether the declaration has any uses or not.
Cheaper than calling uses().
Definition at line 742 of file declaration.cpp.
◆ id()
|
virtual |
- See also
- DeclarationId
- Parameters
-
forceDirect When this is true, the DeclarationId is force to be direct, and can be resolved without a symbol-table and top-context. The same goes for Declarations that have alwaysForceDirect()
set to true.
Definition at line 564 of file declaration.cpp.
◆ identifier()
Identifier KDevelop::Declaration::identifier | ( | ) | const |
Access this declaration's identifier.
- Returns
- this declaration's identifier.
Definition at line 204 of file declaration.cpp.
◆ indexedIdentifier()
const IndexedIdentifier & KDevelop::Declaration::indexedIdentifier | ( | ) | const |
Access this declaration's identifier.
- Returns
- this declaration's identifier in indexed form. This is faster than identifier(), because it equals the internal representation. Use this for example to do equality-comparison.
Definition at line 210 of file declaration.cpp.
◆ indexedType()
IndexedType KDevelop::Declaration::indexedType | ( | ) | const |
Return an indexed form of this declaration's type.
Should be preferred, this is the fastest way, and the correct way for doing equality-comparison.
- Returns
- the declaration's type.
Definition at line 238 of file declaration.cpp.
◆ inDUChain()
|
virtual |
Determine whether this declaration is accessible through the du-chain.
If it is, it cannot be edited without holding the du-chain write lock.
- See also
- DUChain::lock()
- DUChainWriteLocker
- Returns
- true if the Declaration is already inserted into a duchain.
Definition at line 91 of file declaration.cpp.
◆ inSymbolTable()
bool KDevelop::Declaration::inSymbolTable | ( | ) | const |
Access whether this declaration is in the symbol table.
- Returns
- true if this declaration is in the symbol table, otherwise false.
Definition at line 573 of file declaration.cpp.
◆ internalContext()
DUContext * KDevelop::Declaration::internalContext | ( | ) | const |
Retrieve the context that is opened by this declaration, if one exists.
For example, a class will have a declaration which is contained within the context in which it is declared, and a new context will be created to hold class members. This function returns that context. The declaration has to be part of the same top-context.
- Returns
- the internal context for this declaration or, if none exists, nullptr
Definition at line 425 of file declaration.cpp.
◆ isAnonymous()
bool KDevelop::Declaration::isAnonymous | ( | ) | const |
Whether this declaration has been inserted anonymously into its parent-context.
Definition at line 285 of file declaration.cpp.
◆ isAutoDeclaration()
bool KDevelop::Declaration::isAutoDeclaration | ( | ) | const |
Determine whether this declaration is implicitly created or not.
Definition at line 487 of file declaration.cpp.
◆ isDefinition()
bool KDevelop::Declaration::isDefinition | ( | ) | const |
Determine whether this declaration is also a definition.
- Returns
- true if this declaration is also a definition, otherwise false.
Definition at line 472 of file declaration.cpp.
◆ isDeprecated()
bool KDevelop::Declaration::isDeprecated | ( | ) | const |
Determine whether the declaration is deprecated.
Definition at line 497 of file declaration.cpp.
◆ isExplicitlyDeleted()
bool KDevelop::Declaration::isExplicitlyDeleted | ( | ) | const |
Determine whether this declaration is "explicitly deleted" or not.
Definition at line 517 of file declaration.cpp.
◆ isExplicitlyTyped()
bool KDevelop::Declaration::isExplicitlyTyped | ( | ) | const |
Determine whether this declaration is explicitly typed.
Definition at line 527 of file declaration.cpp.
◆ isForwardDeclaration()
|
virtual |
Determine whether this declaration is a forward declaration.
- Returns
- true if this is a forward declaration, otherwise returns false.
Reimplemented in KDevelop::ForwardDeclaration.
Definition at line 650 of file declaration.cpp.
◆ isFunctionDeclaration()
|
virtual |
Determine whether this declaration is a function declaration.
- Returns
- true if this is a function declaration, otherwise returns false.
Definition at line 655 of file declaration.cpp.
◆ isTypeAlias()
bool KDevelop::Declaration::isTypeAlias | ( | ) | const |
Determine if this declaration is a type-alias (in c++ typedef).
- Returns
- true if the declaration is a type alias, otherwise false.
- Todo:
- see whether it would be useful to create an own TypeAliasDeclaration sub-class for this
Definition at line 538 of file declaration.cpp.
◆ kind()
Declaration::Kind KDevelop::Declaration::kind | ( | ) | const |
◆ logicalDeclaration() [1/2]
Declaration * KDevelop::Declaration::logicalDeclaration | ( | const TopDUContext * | topContext | ) |
Definition at line 384 of file declaration.cpp.
◆ logicalDeclaration() [2/2]
const Declaration * KDevelop::Declaration::logicalDeclaration | ( | const TopDUContext * | topContext | ) | const |
This is a convenience function to determine the resolved declaration, if this is a forward declaration.
Otherwise, it just returns this declaration.
- Parameters
-
topContext Context within which to search for the resolved declaration.
- Returns
- the resolved declaration if one was found, otherwise this declaration.
Definition at line 372 of file declaration.cpp.
◆ logicalInternalContext()
|
virtual |
Determine the logical internal context for the resolved form of this declaration.
- If this declaration has a definition, and the definition is resolved, it returns the internal context of the definition.
- If this declaration is a forward-declaration, the forward-declaration is resolved, it returns the internal context of the resolved declaration.
- If this is a type-alias, it returns the internal context of the actual type.
- Otherwise, it returns the same as internalContext().
- Parameters
-
topContext Needed to resolve forward-declarations.
- Returns
- the resolved internal context, as described above
If this is a type-alias, return the internal context of the actual type.
Reimplemented in KDevelop::ForwardDeclaration.
Definition at line 396 of file declaration.cpp.
◆ operator=()
|
delete |
◆ operator==()
bool KDevelop::Declaration::operator== | ( | const Declaration & | other | ) | const |
Equivalence operator.
- Parameters
-
other Other declaration to compare.
- Returns
- true if the declarations are equal, otherwise false.
Definition at line 459 of file declaration.cpp.
◆ ownIndex()
uint KDevelop::Declaration::ownIndex | ( | ) | const |
Returns an index that uniquely identifies this declaration within its surrounding top-context.
That index can be passed to TopDUContext::declarationFromIndex(index)
to get the declaration. This is only valid when the declaration is not a specialization (specialization()
returns 0), and if it is not anonymous in its context.
- Note
- for this to be valid, allocateOwnIndex() must have been called first.
- the highest big of the index is always zero!
- Returns
- the index of the declaration within its TopDUContext.
Definition at line 114 of file declaration.cpp.
◆ persistentlyDestroying()
|
protected |
Returns true if this declaration is being currently destroyed persistently, which means that it should eventually deregister itself from persistent storage facilities.
Only call this from destructors.
Definition at line 134 of file declaration.cpp.
◆ qualifiedIdentifier()
QualifiedIdentifier KDevelop::Declaration::qualifiedIdentifier | ( | ) | const |
Determine the global qualified identifier of this declaration.
- Note
- This function is expensive, equalQualifiedIdentifier() is preferred if you just want to compare equality.
Definition at line 267 of file declaration.cpp.
◆ setAbstractType()
|
virtual |
Set this declaration's type.
- Parameters
-
type this declaration's new type.
Reimplemented in KDevelop::AliasDeclaration, and KDevelop::NamespaceAliasDeclaration.
Definition at line 249 of file declaration.cpp.
◆ setAlwaysForceDirect()
void KDevelop::Declaration::setAlwaysForceDirect | ( | bool | direct | ) |
Changes whether this declaration must be direct in all cases or not.
By default this is set to false.
- Parameters
-
direct true to force direct, false otherwise.
Definition at line 512 of file declaration.cpp.
◆ setAutoDeclaration()
void KDevelop::Declaration::setAutoDeclaration | ( | bool | _auto | ) |
Changes whether this declaration is "implicitly created".
An implicit declaration is not declared in the class context, but written somewhere else outside.
Declarations are by default not implicitly declared.
- Parameters
-
_auto true for implicit, false for default behaviour
Definition at line 492 of file declaration.cpp.
◆ setComment() [1/2]
void KDevelop::Declaration::setComment | ( | const QByteArray & | str | ) |
Sets the comment for this declaration.
- Note
- Should be utf-8 encoded.
Definition at line 186 of file declaration.cpp.
◆ setComment() [2/2]
void KDevelop::Declaration::setComment | ( | const QString & | str | ) |
Sets the comment for this declaration.
Definition at line 199 of file declaration.cpp.
◆ setContext()
void KDevelop::Declaration::setContext | ( | DUContext * | context, |
bool | anonymous = false |
||
) |
Set the context in which this declaration occurs.
When setContext() is called, this declaration is inserted into the given context. You only need to be able to write this declaration. You do not need write-privileges for the context, because addDeclaration(..) works separately to that.
If the given context is not in the symbol-table, or if the declaration is inserted anonymously, or if the context is zero, this declaration is removed from the symbol-table. Else it is added to the symbol table with the new scope. See TopDUContext for information about the symbol table.
- Parameters
-
context New context which contains this declaration. The context must have a top-context if it is not zero. anonymous If this is set, this declaration will be added anonymously into the parent-context. This way it can never be found through any of the context's functions, and will not be deleted when the context is deleted, so it must be deleted from elsewhere.
Definition at line 290 of file declaration.cpp.
◆ setDeclarationIsDefinition()
void KDevelop::Declaration::setDeclarationIsDefinition | ( | bool | dd | ) |
Set whether this declaration is also a definition.
- Parameters
-
dd set this to true if this declaration is also a definition, otherwise false.
Definition at line 480 of file declaration.cpp.
◆ setDeprecated()
void KDevelop::Declaration::setDeprecated | ( | bool | deprecated | ) |
Set whether the declaration is deprecated.
- Parameters
-
deprecated true if the declaration is deprecated, otherwise false.
Definition at line 502 of file declaration.cpp.
◆ setExplicitlyDeleted()
void KDevelop::Declaration::setExplicitlyDeleted | ( | bool | deleted | ) |
Changes whether this declaration is "explicitly deleted", i.e.
not implicitly declared or accessible.
- Parameters
-
deleted true for deleted, false for default behaviour
Definition at line 522 of file declaration.cpp.
◆ setExplicitlyTyped()
void KDevelop::Declaration::setExplicitlyTyped | ( | bool | explicitlyTyped | ) |
Changes whether this declaration is explicitly typed.
Explicitly typed declaration has the type written as part of the declaration. The opposite, implicitly typed declaration, has the type deduced by the compiler.
E.g. in C++ variable declarations are explicitly typed unless the "auto" keyword is used.
- Parameters
-
explicitlyTyped true for explicitly typed, false for implicitly typed
Definition at line 532 of file declaration.cpp.
◆ setIdentifier()
void KDevelop::Declaration::setIdentifier | ( | const Identifier & | identifier | ) |
Set this declaration's identifier.
- Parameters
-
identifier this declaration's new identifier
Definition at line 225 of file declaration.cpp.
◆ setInSymbolTable()
|
virtual |
Adds or removes this declaration to/from the symbol table.
- Parameters
-
inSymbolTable true to add this declaration to the symbol table, false to remove it.
Reimplemented in KDevelop::NamespaceAliasDeclaration.
Definition at line 614 of file declaration.cpp.
◆ setInternalContext()
void KDevelop::Declaration::setInternalContext | ( | DUContext * | context | ) |
Set the internal context for this declaration.
- Parameters
-
context the internal context
Definition at line 431 of file declaration.cpp.
◆ setIsTypeAlias()
void KDevelop::Declaration::setIsTypeAlias | ( | bool | typeAlias | ) |
Set whether this declaration is a type alias.
- Parameters
-
typeAlias true if the declaration is a type alias, otherwise false.
Definition at line 544 of file declaration.cpp.
◆ setKind()
void KDevelop::Declaration::setKind | ( | Kind | kind | ) |
◆ setType()
|
inline |
Set this declaration's type.
- Parameters
-
type the type to assign.
Definition at line 321 of file declaration.h.
◆ specialization()
|
virtual |
TODO document.
Definition at line 550 of file declaration.cpp.
◆ specialize()
|
virtual |
Retrieve the declaration which is specialized with the given specialization index as seen from topContext.
- Parameters
-
specialization the specialization index (see DeclarationId) topContext the top context representing the perspective from which to specialize. if topContext
is zero, only already existing specializations are returned, and if none exists, zero is returned.upDistance upwards distance in the context-structure of the given specialization-info. This allows specializing children.
Definition at line 259 of file declaration.cpp.
◆ topContext()
|
overridevirtual |
Determine the top context to which this object belongs.
- Todo:
- Move the reference to the top-context right into this class, as it's common to all inheriters
Reimplemented from KDevelop::DUChainBase.
Definition at line 633 of file declaration.cpp.
◆ toString()
|
virtual |
Determine this declaration as a string.
- Returns
- this declaration as a string.
Reimplemented in KDevelop::ClassDeclaration, KDevelop::AliasDeclaration, KDevelop::NamespaceAliasDeclaration, and KDevelop::ForwardDeclaration.
Definition at line 466 of file declaration.cpp.
◆ type()
|
inline |
Convenience function to return this declaration's type dynamically casted to T.
- Returns
- this declaration's type as T, or null if there is no type or it is not of type T.
Definition at line 305 of file declaration.h.
◆ uses()
Returns a map of files to use-ranges.
The key of the returned map is an url of a file. The value is a list with all use-ranges of this declaration in that file.
- Note
- The ranges are in the documents local revision, use
DUChainUtils::transformFromRevision
orusesCurrentRevision()
- The uses are unique, no 2 uses are returned that have the same range within the same file.
- This is a non-trivial operation and hence expensive.
Definition at line 675 of file declaration.cpp.
◆ usesCurrentRevision()
QMap< IndexedString, QVector< KTextEditor::Range > > KDevelop::Declaration::usesCurrentRevision | ( | ) | const |
Returns a map of files to use-ranges.
The key of the returned map is an url of a file. The value is a list with all use-ranges of this declaration in that file.
- Note
- The uses are unique, no 2 uses are returned that have the same range within the same file.
- Warning
- This must be called only from within the foreground, or with the foreground lock locked.
- Note
- This is a non-trivial operation and hence expensive.
Definition at line 760 of file declaration.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jan 19 2021 23:36:34 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.