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

language/duchain

KDevelop::TopDUContext

KDevelop::TopDUContext Class Reference

The top context in a definition-use chain for one source file. More...

#include <topducontext.h>

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

List of all members.

Classes

class  Cache
 The cache allows speeding up repeated searches. More...
struct  DeclarationChecker

Public Types

enum  { Identity = 4 }
enum  Features {
  VisibleDeclarationsAndContexts = 0, AllDeclarationsAndContexts = 2, AllDeclarationsContextsAndUses = 4 + AllDeclarationsAndContexts, AllDeclarationsContextsAndUsesForRecursive = 8 + AllDeclarationsContextsAndUses,
  AST = 16, AllDeclarationsContextsUsesAndAST = AllDeclarationsContextsAndUses | AST, ForceUpdate = 32, ForceUpdateRecursive = ForceUpdate | 64
}
enum  Flags { NoFlags = 0, UpdatingContext = 1, LastFlag = 2 }
typedef Utils::StorableSet
< IndexedTopDUContext,
IndexedTopDUContextIndexConversion,
RecursiveImportRepository,
true > 
IndexedRecursiveImports

Public Member Functions

 TopDUContext (TopDUContext *shareDataFrom, ParsingEnvironmentFile *file=0)
 TopDUContext (TopDUContextData &data)
 TopDUContext (const IndexedString &url, const SimpleRange &range, ParsingEnvironmentFile *file=0)
virtual void addImportedParentContext (DUContext *context, const SimpleCursor &position=SimpleCursor(), bool anonymous=false, bool temporary=false)
virtual void addImportedParentContexts (const QList< QPair< TopDUContext *, SimpleCursor > > &contexts, bool temporary=false)
void addProblem (const ProblemPointer &problem)
KSharedPtr< IAstContainer > ast () const
void clearAst ()
virtual void clearImportedParentContexts ()
void clearProblems ()
void clearUsedDeclarationIndices ()
void deleteSelf ()
bool deleting () const
Features features () const
virtual bool findDeclarationsInternal (const SearchItem::PtrList &identifiers, const SimpleCursor &position, const AbstractType::Ptr &dataType, DeclarationList &ret, const TopDUContext *source, SearchFlags flags, uint depth) const
Flags flags () const
virtual QVector< Import > importedParentContexts () const
virtual QVector< DUContext * > importers () const
virtual SimpleCursor importPosition (const DUContext *target) const
virtual bool imports (const DUContext *origin, const SimpleCursor &position) const
IndexedTopDUContext indexed () const
int indexForUsedDeclaration (Declaration *declaration, bool create=true)
virtual bool inDUChain () const
bool isOnDisk () const
virtual QList< DUContext * > loadedImporters () const
uint ownIndex () const
KSharedPtr
< ParsingEnvironmentFile > 
parsingEnvironmentFile () const
QList< ProblemPointer > problems () const
const IndexedRecursiveImports & recursiveImportIndices () const
virtual void removeImportedParentContext (DUContext *context)
virtual void removeImportedParentContexts (const QList< TopDUContext * > &contexts)
void setAst (KSharedPtr< IAstContainer > ast)
void setFeatures (Features)
void setFlags (Flags f)
void setInDuChain (bool)
TopDUContext * sharedDataOwner () const
TopDUContext * topContext () const
void updateImportsCache ()
IndexedString url () const
Declaration * usedDeclarationForIndex (unsigned int declarationIndex) const
bool usingImportsCache () const

Protected Member Functions

template<class Acceptor >
bool applyAliases (const AliasChainElement *backPointer, const SearchItem::Ptr &identifier, Acceptor &acceptor, const SimpleCursor &position, bool canBeNamespace, ApplyAliasesBuddyInfo *buddy, uint recursionDepth) const
template<class Acceptor >
void applyAliases (const SearchItem::PtrList &identifiers, Acceptor &accept, const SimpleCursor &position, bool canBeNamespace) const
virtual void findContextsInternal (ContextType contextType, const SearchItem::PtrList &identifiers, const SimpleCursor &position, QList< DUContext * > &ret, const TopDUContext *source, SearchFlags flags=NoSearchFlags) const
bool importsPrivate (const DUContext *origin, const SimpleCursor &position) const
void rebuildDynamicData (DUContext *parent, uint ownIndex)
void rebuildDynamicImportStructure ()
void setParsingEnvironmentFile (ParsingEnvironmentFile *)

Protected Attributes

class TopDUContextDynamicData * m_dynamicData
TopDUContextLocalPrivate * m_local

Detailed Description

The top context in a definition-use chain for one source file.

Implements SymbolTable lookups and locking for the chain.

Contexts and Classes can only be found through TopDUContext if they are in the symbol table.

See also:
DUContext::setInSymbolTable, Declaration::setInSymbolTable
Todo:
move the registration with DUChain here
Warning:
When you delete a top-context, delete it using TopDUContext::deleteSelf(), else you will leak memory

Definition at line 113 of file topducontext.h.


Member Enumeration Documentation

anonymous enum

Returns the trace of imports from this context top the given target.

The positions in the returned trace may be invalid. This is more efficient then the version below, because the trace doesn't need to be copiedMore convenient version of the above

Definition at line 201 of file topducontext.h.

enum KDevelop::TopDUContext::Features
Enumerator:
AllDeclarationsContextsAndUsesForRecursive 

When this flag is set, also _all_ recursive imports have to be computed with AllDeclarationsContextsAndUses This flag can not be set on a context, it is only used as a parameter to several updating functions.

When you set it on a top-context, its flag will be AllDeclarationsContextsAndUses.

Definition at line 213 of file topducontext.h.

enum KDevelop::TopDUContext::Flags
Enumerator:
UpdatingContext 

Can be used by language parts to mark contexts they currently update(for their internal usage).

LastFlag 

You can define own language-dependent flags behind this flag.

Definition at line 205 of file topducontext.h.


Constructor & Destructor Documentation

KDevelop::TopDUContext::TopDUContext ( TopDUContext *  shareDataFrom,
ParsingEnvironmentFile *  file = 0 
) [explicit]

This creates a top-context that shares most of its data with.

Parameters:
sharedDataFrom. The given context must be the owner of the data (it must not have been created with this constructor).

When creating a context like this, all the data is shared among the context, except: parsingEnvironmentFile, ownIndex, problems, imports and importers.

When you change any other attributes(including duchain data etc.), that data is changed within all contexts that also share the data of the given one.

Special thing to consider: The imported contexts will be merged with the imported contexts of the data owner, and the problems will be merged with the problems of the data owner. When one of these things changes in the data owner, it will automatically also change in this context.

Warning:
When creating context with shared data, the shared ones always have to be deleted before the owner is deleted.

Todo:
this is incompatible with data-sharing, remove that option again.

Definition at line 821 of file topducontext.cpp.


Member Function Documentation

void KDevelop::TopDUContext::addImportedParentContext ( DUContext *  context,
const SimpleCursor &  position = SimpleCursor(),
bool  anonymous = false,
bool  temporary = false 
) [virtual]
Parameters:
temporary If this is true, importers of this context will not be notified of the new imports. This greatly increases performance while removing the context, but creates in inconsistent import-structure. Therefore it is only suitable for temporary imports. These imports will not be visible from contexts that import this one. When this top-context does not own its private data, the import is added locally only to this context, not into the shared data.

Definition at line 1395 of file topducontext.cpp.

void KDevelop::TopDUContext::addImportedParentContexts ( const QList< QPair< TopDUContext *, SimpleCursor > > &  contexts,
bool  temporary = false 
) [virtual]

Use this for mass-adding of imported contexts, it is faster than adding them individually.

Parameters:
temporary If this is true, importers of this context will not be notified of the new imports. This greatly increases performance while removing the context, but creates in inconsistent import-structure. Therefore it is only suitable for temporary imports. These imports will not be visible from contexts that import this one. When this top-context does not own its private data, the import is added locally only to this context, not into the shared data.

Definition at line 1418 of file topducontext.cpp.

void KDevelop::TopDUContext::addProblem ( const ProblemPointer &  problem  ) 

Add a parsing-problem to this context.

Definition at line 1320 of file topducontext.cpp.

template<class Acceptor >
bool KDevelop::TopDUContext::applyAliases ( const AliasChainElement *  backPointer,
const SearchItem::Ptr &  identifier,
Acceptor &  accept,
const SimpleCursor &  position,
bool  canBeNamespace,
ApplyAliasesBuddyInfo *  buddy,
uint  recursionDepth 
) const [inline, protected]
Todo:
Implement a cache so at least the global import checks don't need to be done repeatedly. The cache should be thread-local, using DUChainPointer for the hashed items, and when an item was deleted, it should be discarded

Todo:
explicitlyGlobal if the first identifier los global
Todo:
check iso c++ if using-directives should be respected on top-level when explicitly global
Todo:
this is bad for a very big repository(the chains should be walked for the top-context instead)

Definition at line 1019 of file topducontext.cpp.

template<class Acceptor >
void KDevelop::TopDUContext::applyAliases ( const SearchItem::PtrList &  identifiers,
Acceptor &  accept,
const SimpleCursor &  position,
bool  canBeNamespace 
) const [inline, protected]

Does the same as DUContext::updateAliases, except that it uses the symbol-store, and processes the whole identifier.

Parameters:
canBeNamespace whether the searched identifier may be a namespace. If this is true, namespace-aliasing is applied to the last elements of the identifiers.

Definition at line 1217 of file topducontext.cpp.

KSharedPtr< IAstContainer > KDevelop::TopDUContext::ast (  )  const

Returns the AST Container, that contains the AST created during parsing.

This is only created if you request the AST feature for parsing. It may be discarded at any time. Every update without the AST feature will discard it. The actual contents is language-specific.

Todo:
Figure out logic to get rid of AST when it is not needed/useful

Definition at line 1556 of file topducontext.cpp.

void KDevelop::TopDUContext::clearAst ( void   ) 

Utility function to clear the AST Container.

Definition at line 1561 of file topducontext.cpp.

void KDevelop::TopDUContext::clearImportedParentContexts (  )  [virtual]

When this top-context does not own its private data, only the local imports of this context are removed, not those from the shared data.

Reimplemented from KDevelop::DUContext.

Definition at line 1371 of file topducontext.cpp.

void KDevelop::TopDUContext::clearProblems (  ) 

Clear the list of problems.

Definition at line 1326 of file topducontext.cpp.

void KDevelop::TopDUContext::clearUsedDeclarationIndices (  ) 

You can use this before you rebuild all uses.

This does not affect any uses directly, it only invalidates the mapping of declarationIndices to Declarations.

usedDeclarationForIndex(..) must not be called until the use has gotten a new index through indexForUsedDeclaration(..).

Definition at line 1456 of file topducontext.cpp.

void KDevelop::TopDUContext::deleteSelf (  ) 

Call this to destroy a top-context.

Definition at line 845 of file topducontext.cpp.

bool KDevelop::TopDUContext::deleting (  )  const

Returns true if this object is being deleted, otherwise false.

Todo:
remove d_func()->m_deleting, not used any more

Definition at line 1305 of file topducontext.cpp.

void KDevelop::TopDUContext::findContextsInternal ( ContextType  contextType,
const SearchItem::PtrList &  identifiers,
const SimpleCursor &  position,
QList< DUContext * > &  ret,
const TopDUContext *  source,
SearchFlags  flags = NoSearchFlags 
) const [protected, virtual]

The actual scopes are found within applyAliases, and each complete qualified identifier is given to FindContextsAcceptor. That stores the found declaration to the output.

Definition at line 1284 of file topducontext.cpp.

bool KDevelop::TopDUContext::findDeclarationsInternal ( const SearchItem::PtrList &  identifiers,
const SimpleCursor &  position,
const AbstractType::Ptr &  dataType,
DeclarationList &  ret,
const TopDUContext *  source,
SearchFlags  flags,
uint  depth 
) const [virtual]

The actual scopes are found within applyAliases, and each complete qualified identifier is given to FindDeclarationsAcceptor. That stores the found declaration to the output.

Definition at line 973 of file topducontext.cpp.

TopDUContext::Flags KDevelop::TopDUContext::flags (  )  const

Use flags to mark top-contexts for special behavior.

Any flags above LastFlag may be used for language-specific stuff.

Definition at line 1443 of file topducontext.cpp.

QVector< DUContext::Import > KDevelop::TopDUContext::importedParentContexts (  )  const [virtual]

Returns the list of imported parent contexts for this context.

Warning:
The list may contain objects that are not valid any more(data() returns zero),
See also:
addImportedParentContext)
Warning:
The import structure may contain loops if this is a TopDUContext, so be careful when traversing the tree. Expensive.

Reimplemented from KDevelop::DUContext.

Definition at line 1344 of file topducontext.cpp.

QVector< DUContext * > KDevelop::TopDUContext::importers (  )  const [virtual]

Returns the list of contexts importing this context.

Very expensive, since the importers top-contexts need to be loaded.

Reimplemented from KDevelop::DUContext.

Definition at line 1332 of file topducontext.cpp.

bool KDevelop::TopDUContext::imports ( const DUContext *  origin,
const SimpleCursor &  position 
) const [virtual]

Determine if this chain imports another chain recursively.

This uses the imports-cache for speedup if it is available, thus it is not necessarily 100% correct if the cache is not up-to-date.

Note:
you must be holding a read but not a write chain lock when you access this function.

Definition at line 1350 of file topducontext.cpp.

IndexedTopDUContext KDevelop::TopDUContext::indexed (  )  const

Returns an indexed representation of this top-context. Indexed representations stay valid even if the top-context is unloaded.

Definition at line 797 of file topducontext.cpp.

int KDevelop::TopDUContext::indexForUsedDeclaration ( Declaration *  declaration,
bool  create = true 
)

Retrieves or creates a local index that is to be used for referencing the given.

Parameters:
declaration in local uses. Also registers this context as a user of the declaration.
create If this is false, only already registered indices will be returned. If the declaration is not registered, std::numeric_limits<int>::max() is returned

The duchain must be write-locked if create is true, else it must at least be read-locked.

Todo:
Make m_usedDeclarationIds sorted, and find the decl. using binary search

Definition at line 1476 of file topducontext.cpp.

bool KDevelop::TopDUContext::inDUChain (  )  const [virtual]

Returns true if this object is registered in the du-chain. If it is not, all sub-objects(context, declarations, etc.) can be changed.

Returns true if this object is registered in the du-chain. If it is not, all sub-objects(context, declarations, etc.).

Reimplemented from KDevelop::DUContext.

Definition at line 1434 of file topducontext.cpp.

bool KDevelop::TopDUContext::isOnDisk (  )  const

Whether this top-context has a stored version on disk.

Todo:
Change this to releasingToDisk, and only enable it while saving a top-context to disk.

Definition at line 1451 of file topducontext.cpp.

QList< DUContext * > KDevelop::TopDUContext::loadedImporters (  )  const [virtual]

Returns all currently loade importers.

Definition at line 1338 of file topducontext.cpp.

KSharedPtr< ParsingEnvironmentFile > KDevelop::TopDUContext::parsingEnvironmentFile (  )  const
See also:
ParsingEnvironmentFile May return zero if no file was set.

Definition at line 829 of file topducontext.cpp.

QList< ProblemPointer > KDevelop::TopDUContext::problems (  )  const

Returns a list of all problems encountered while parsing this top-context.

Does not include the problems of imported contexts.

Definition at line 1311 of file topducontext.cpp.

void KDevelop::TopDUContext::rebuildDynamicData ( DUContext *  parent,
uint  ownIndex 
) [protected, virtual]

Called after loading to rebuild the dynamic data. If this is a context, this should recursively work on all sub-contexts.

Reimplemented from KDevelop::DUChainBase.

Definition at line 791 of file topducontext.cpp.

const TopDUContext::IndexedRecursiveImports & KDevelop::TopDUContext::recursiveImportIndices (  )  const

Returns the set of all recursively imported top-contexts.

If import-caching is used, this returns the cached set. The list also contains this context itself. This set is used to determine declaration-visibility from within this top-context.

Definition at line 655 of file topducontext.cpp.

void KDevelop::TopDUContext::removeImportedParentContext ( DUContext *  context  )  [virtual]

When this top-context does not own its private data, the import is removed locally only from this context, not from the shared data.

Definition at line 1411 of file topducontext.cpp.

void KDevelop::TopDUContext::removeImportedParentContexts ( const QList< TopDUContext * > &  contexts  )  [virtual]

Use this for mass-removing of imported contexts, it is faster than removing them individually.

When this top-context does not own its private data, the import is removed locally only from this context, not from the shared data.

Definition at line 1425 of file topducontext.cpp.

void KDevelop::TopDUContext::setAst ( KSharedPtr< IAstContainer >  ast  ) 

Sets the AST Container.

Definition at line 1550 of file topducontext.cpp.

void KDevelop::TopDUContext::setFeatures ( Features  features  ) 

Set the features of this top-context. These features are ignored: AST, ForceUpdate, and ForeceUpdateRecursive.

Definition at line 864 of file topducontext.cpp.

void KDevelop::TopDUContext::setInDuChain ( bool  b  ) 

This flag is only used by DUChain, never change it from outside.

Definition at line 1439 of file topducontext.cpp.

TopDUContext * KDevelop::TopDUContext::sharedDataOwner (  )  const

If this top-context uses the data from another top-context, this returns that one.

Definition at line 1295 of file topducontext.cpp.

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

Find the top context.

Reimplemented from KDevelop::DUContext.

Definition at line 1300 of file topducontext.cpp.

void KDevelop::TopDUContext::updateImportsCache (  ) 

Updates the cache of recursive imports.

When you call this, from that moment on the set returned by recursiveImportIndices() is fixed, until you call it again to update them. If your language has a very complex often-changing import-structure, like for example in the case of C++, it is recommended to call this during while parsing, instead of using the expensive builtin implicit mechanism. Note that if you use caching, you _must_ call this before you see any visibility-effect after adding imports.

Using import-caching has another big advantage: A top-context can be loaded without loading all its imports.

Note: This is relatively expensive since it requires loading all imported contexts.

When this is called, the top-context must already be registered in the duchain.

Definition at line 713 of file topducontext.cpp.

Declaration * KDevelop::TopDUContext::usedDeclarationForIndex ( unsigned int  declarationIndex  )  const

Tries to retrieve the used declaration.

Parameters:
declarationIndex 
context must be the context where the use happened

Definition at line 1464 of file topducontext.cpp.


The documentation for this class was generated from the following files:
  • topducontext.h
  • topducontext.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