• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

language/duchain

KDevelop::Declaration

KDevelop::Declaration Class Reference

Represents a single declaration in a definition-use chain. More...

#include <declaration.h>

Inheritance diagram for KDevelop::Declaration:
Inheritance graph
[legend]

List of all members.

Public Types

enum  { Identity = 7 }
enum  AccessPolicy { Public, Protected, Private, DefaultAccess }
enum  Kind {
  Type, Instance, NamespaceAlias, Alias,
  Namespace, Import
}

Public Member Functions

 Declaration (DeclarationData &dd)
 Declaration (const Declaration &rhs)
 Declaration (const SimpleRange &range, DUContext *parentContext)
virtual ~Declaration ()
AbstractType::Ptr abstractType () const
virtual void activateSpecialization ()
virtual uint additionalIdentity () const
void allocateOwnIndex ()
void clearOwnIndex ()
Declaration * clone () const
QByteArray comment () const
DUContext * context () const
bool equalQualifiedIdentifier (const Declaration *rhs) const
virtual DeclarationId id (bool forceDirect=false) const
Identifier identifier () const
IndexedIdentifier indexedIdentifier () const
IndexedType indexedType () const
virtual bool inDUChain () const
bool inSymbolTable () const
DUContext * internalContext () const
bool isAnonymous () const
bool isDefinition () const
bool isFinal () 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
bool operator== (const Declaration &other) const
uint ownIndex () const
QualifiedIdentifier qualifiedIdentifier () const
virtual void setAbstractType (AbstractType::Ptr type)
void setComment (const QString &str)
void setComment (const QByteArray &str)
void setContext (DUContext *context, bool anonymous=false)
void setDeclarationIsDefinition (bool dd)
void setFinal (bool final)
void setIdentifier (const Identifier &identifier)
void setInSymbolTable (bool inSymbolTable)
void setInternalContext (DUContext *context)
void setIsTypeAlias (bool typeAlias)
void setKind (Kind kind)
template<class T >
void setType (TypePtr< T > type)
QList< KTextEditor::SmartRange * > smartUses () const
virtual
IndexedInstantiationInformation 
specialization () const
virtual Declaration * specialize (IndexedInstantiationInformation specialization, const TopDUContext *topContext, int upDistance=0)
const ForwardDeclaration * toForwardDeclaration () const
ForwardDeclaration * toForwardDeclaration ()
virtual TopDUContext * topContext () const
virtual QString toString () const
template<class T >
TypePtr< T > type () const
QMap< IndexedString, QList
< SimpleRange > > 
uses () const

Protected Member Functions

 Declaration (DeclarationData &dd, const SimpleRange &range)

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 61 of file declaration.h.


Member Enumeration Documentation

enum KDevelop::Declaration::AccessPolicy

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 65 of file declaration.h.

enum KDevelop::Declaration::Kind

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.

Definition at line 72 of file declaration.h.


Constructor & Destructor Documentation

KDevelop::Declaration::Declaration ( const SimpleRange &  range,
DUContext *  parentContext 
)

Constructor.

If parentContext is in the symbol table, the declaration will automatically be added into the symbol table.

Parameters:
url url of the document where this occurred
range range of the alias declaration's identifier
parentContext context in which this declaration occurred

Definition at line 104 of file declaration.cpp.

KDevelop::Declaration::Declaration ( const Declaration &  rhs  ) 

Copy-constructor for cloning.

Definition at line 122 of file declaration.cpp.

KDevelop::Declaration::~Declaration (  )  [virtual]

Destructor.

Definition at line 145 of file declaration.cpp.

KDevelop::Declaration::Declaration ( DeclarationData &  dd  ) 

Uses the given data.

Definition at line 130 of file declaration.cpp.

KDevelop::Declaration::Declaration ( DeclarationData &  dd,
const SimpleRange &  range 
) [protected]

Constructor for copy constructors in subclasses.

Parameters:
dd data to copy.
url document url in which this object is located.
range text range which this object covers.

Definition at line 137 of file declaration.cpp.


Member Function Documentation

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 300 of file declaration.cpp.

void KDevelop::Declaration::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 585 of file declaration.cpp.

uint KDevelop::Declaration::additionalIdentity (  )  const [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 696 of file declaration.cpp.

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 425 of file declaration.cpp.

void KDevelop::Declaration::clearOwnIndex (  ) 

Clear the index for this declaration in the top context that was allocated with allocateOwnIndex().

Definition at line 409 of file declaration.cpp.

Declaration * KDevelop::Declaration::clone (  )  const

Returns a clone of this declaration, with the difference that:

  • context will be 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 680 of file declaration.cpp.

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 185 of file declaration.cpp.

DUContext * KDevelop::Declaration::context (  )  const

Access the parent context of this declaration.

Returns:
the parent context of this declaration.

Definition at line 349 of file declaration.cpp.

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 701 of file declaration.cpp.

DeclarationId KDevelop::Declaration::id ( bool  forceDirect = false  )  const [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

Definition at line 594 of file declaration.cpp.

Identifier KDevelop::Declaration::identifier (  )  const

Access this declaration's identifier.

Returns:
this declaration's identifier.

Definition at line 205 of file declaration.cpp.

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 211 of file declaration.cpp.

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-comparsion.

Returns:
the declaration's type.

Definition at line 295 of file declaration.cpp.

bool KDevelop::Declaration::inDUChain (  )  const [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 94 of file declaration.cpp.

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 603 of file declaration.cpp.

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

Definition at line 492 of file declaration.cpp.

bool KDevelop::Declaration::isAnonymous (  )  const

Whether this declaration has been inserted anonymously into its parent-context.

Definition at line 355 of file declaration.cpp.

bool KDevelop::Declaration::isDefinition (  )  const

Access whether this declaration is also a definition.

Returns:
true if this declaration is also a definition, otherwise false.

Definition at line 542 of file declaration.cpp.

bool KDevelop::Declaration::isFinal (  )  const

Access whether the declaration is final, ie, it can only be written to once [Java].

Definition at line 560 of file declaration.cpp.

bool KDevelop::Declaration::isForwardDeclaration (  )  const [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 686 of file declaration.cpp.

bool KDevelop::Declaration::isFunctionDeclaration (  )  const [virtual]

Determine whether this declaration is a function declaration.

Returns:
true if this is a function declaration, otherwise returns false.

Definition at line 691 of file declaration.cpp.

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 571 of file declaration.cpp.

Declaration::Kind KDevelop::Declaration::kind (  )  const

Returns the kind of this declaration.

See also:
Kind

Definition at line 83 of file declaration.cpp.

Declaration * KDevelop::Declaration::logicalDeclaration ( const TopDUContext *  topContext  ) 

Definition at line 453 of file declaration.cpp.

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 442 of file declaration.cpp.

DUContext * KDevelop::Declaration::logicalInternalContext ( const TopDUContext *  topContext  )  const [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 464 of file declaration.cpp.

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 528 of file declaration.cpp.

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 116 of file declaration.cpp.

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 326 of file declaration.cpp.

void KDevelop::Declaration::setAbstractType ( AbstractType::Ptr  type  )  [virtual]

Set this declaration's type.

Parameters:
type this declaration's new type.

Reimplemented in KDevelop::AliasDeclaration, and KDevelop::NamespaceAliasDeclaration.

Definition at line 306 of file declaration.cpp.

void KDevelop::Declaration::setComment ( const QString &  str  ) 

Sets the comment for this declaration.

Definition at line 201 of file declaration.cpp.

void KDevelop::Declaration::setComment ( const QByteArray &  str  ) 

Sets the comment for this declaration.

Should be utf-8 encoded.

Definition at line 193 of file declaration.cpp.

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.

Todo:
re-enable. In C++ support we need a short window to put visible declarations into template contexts

Definition at line 360 of file declaration.cpp.

void KDevelop::Declaration::setDeclarationIsDefinition ( bool  dd  ) 

Set whether this declaration is also a definition.

Parameters:
dd set to true if this declaration is also a definition, otherwise false.

Definition at line 550 of file declaration.cpp.

void KDevelop::Declaration::setFinal ( bool  final  ) 

Set whether the declaration is final.

Parameters:
final true if the declaration is final, otherwise false.

Definition at line 565 of file declaration.cpp.

void KDevelop::Declaration::setIdentifier ( const Identifier &  identifier  ) 

Set this declaration's identifier.

Parameters:
identifier this declaration's new identifier

Definition at line 278 of file declaration.cpp.

void KDevelop::Declaration::setInSymbolTable ( bool  inSymbolTable  ) 

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.

Definition at line 640 of file declaration.cpp.

void KDevelop::Declaration::setInternalContext ( DUContext *  context  ) 

Set the internal context for this declaration.

Parameters:
context the internal context

Definition at line 498 of file declaration.cpp.

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 576 of file declaration.cpp.

void KDevelop::Declaration::setKind ( Kind  kind  ) 

Set the kind.

Parameters:
kind new kind

Definition at line 88 of file declaration.cpp.

template<class T >
void KDevelop::Declaration::setType ( TypePtr< T >  type  )  [inline]

Set this declaration's type.

Parameters:
type the type to assign.

Definition at line 230 of file declaration.h.

QList< KTextEditor::SmartRange * > KDevelop::Declaration::smartUses (  )  const

Collects the smart-ranges for all uses.

Uses that do not have smart ranges are not represented in the result.

Definition at line 710 of file declaration.cpp.

Declaration * KDevelop::Declaration::specialize ( IndexedInstantiationInformation  specialization,
const TopDUContext *  topContext,
int  upDistance = 0 
) [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 to search from
upDistance upwards distance in the context-structure of the given specialization-info. This allows specializing children.

Definition at line 321 of file declaration.cpp.

const ForwardDeclaration * KDevelop::Declaration::toForwardDeclaration (  )  const

Returns this declaration as a forward declaration, if it is one.

Returns:
this declaration as a forward declaration if it is one, otherwise null.

Definition at line 666 of file declaration.cpp.

ForwardDeclaration * KDevelop::Declaration::toForwardDeclaration (  ) 

Returns this declaration as a forward declaration, if it is one.

Returns:
this declaration as a forward declaration if it is one, otherwise null.

Definition at line 661 of file declaration.cpp.

TopDUContext * KDevelop::Declaration::topContext (  )  const [virtual]

Determine the top context to which this object belongs.

Reimplemented from KDevelop::DUChainBase.

Definition at line 671 of file declaration.cpp.

QString KDevelop::Declaration::toString (  )  const [virtual]

Determine this declaration as a string.

Returns:
this declaration as a string.

Reimplemented in KDevelop::AliasDeclaration, KDevelop::ClassDeclaration, KDevelop::ForwardDeclaration, and KDevelop::NamespaceAliasDeclaration.

Definition at line 535 of file declaration.cpp.

template<class T >
TypePtr<T> KDevelop::Declaration::type (  )  const [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 215 of file declaration.h.

QMap< IndexedString, QList< SimpleRange > > KDevelop::Declaration::uses (  )  const

Returns a list of pairs: An url of a file, paired together with all use-ranges of this declaration in that file.

Todo:
The following two are convenience-functions. Think whether they should stay here, or be moved out.

The uses are unique, no 2 uses are returend that have the same range within the same file.

This is a non-trivial operation.

Definition at line 736 of file declaration.cpp.


The documentation for this class was generated from the following files:
  • declaration.h
  • declaration.cpp

language/duchain

Skip menu "language/duchain"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal