Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 8622095d authored by David Nolden's avatar David Nolden

Remove EnvironmentManager code and move the matching/update-testing...

Remove EnvironmentManager code and move the matching/update-testing functionility directly into EnvironmentFile.
Remove some unneeded files.
parent 47f940c3
......@@ -25,7 +25,6 @@ set(kdevcppduchain_LIB_SRCS
cpptypes.cpp
dumptypes.cpp
environmentmanager.cpp
cachemanager.cpp
hashedstringset.cpp
cppduchain.cpp
templateparameterdeclaration.cpp
......
/***************************************************************************
Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "cachemanager.h"
#include <kdebug.h>
void CacheNode::access() const {
if( m_manager )
m_manager->access( this );
}
void CacheManager::remove( const CacheNode* node ) {
m_set.erase( node );
}
void CacheManager::add( const CacheNode* node ) {
m_set.insert( node );
}
CacheNode::CacheNode( Manager* manager ) : m_manager( manager ), m_value(manager ? manager->currentMax() : 0) { //initialize m_value with the current maximum, so the new node has a chance even in a cache full of high-rated nodes
if( m_manager )
m_manager->add( this );
}
CacheNode::~CacheNode() {
if( m_manager )
m_manager->remove( this );
}
CacheManager::CacheManager( int maxNodes ) : m_currentFrame(1), m_maxNodes( maxNodes ), m_currentMax(1) {
}
CacheManager::~CacheManager() {
}
void CacheManager::restart( uint normalizeby ) {
m_currentFrame = 1;
m_currentMax = 1;
SetType oldSet = m_set;
m_set = SetType();
for( SetType::iterator it = oldSet.begin(); it != oldSet.end(); ++it ) {
uint newValue = (*it)->value() / ( normalizeby / 1000 );
if( newValue > m_currentMax ) m_currentMax = newValue;
(*it)->setValue( newValue ); ///This way not all information is discarded
m_set.insert( *it );
}
}
void CacheManager::access( const CacheNode* node ) {
static const uint limit = (std::numeric_limits<uint>::max() / 3)*2;
m_set.erase( node );
node->setValue( m_currentMax+1 );
m_set.insert( node );
if( node->value() > m_currentMax )
m_currentMax = node->value();
if( node->value() > limit )
restart( node->value() );
}
void CacheManager::setMaxNodes ( int maxNodes ) {
m_maxNodes = maxNodes;
increaseFrame();
}
void CacheManager::increaseFrame() {
m_currentFrame ++;
if( m_set.size() > (std::size_t) m_maxNodes ) {
//kdDebug( 9007 ) << "CacheManager: Have" << m_set.size() << "nodes, maximum is" << m_maxNodes << ", erasing." << endl;
int mustErase = m_set.size() - m_maxNodes;
while( !m_set.empty() && mustErase != 0 ) {
--mustErase;
SetType::iterator it = m_set.begin();
erase( *it );
}
//kdDebug( 9007 ) << "CacheManager: Have" << m_set.size() << "nodes after erasing." << endl;
}
}
void CacheManager::saveMemory() {
int maxNodes = m_maxNodes;
setMaxNodes( m_set.size() / 2 );
setMaxNodes( maxNodes );
}
/***************************************************************************
Copyright 2006 David Nolden <david.nolden.kdevelop@art-master.de>
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef CACHEMANAGER_H
#define CACHEMANAGER_H
#include <cstdlib>
#include <set>
#include <limits>
#include <QtCore/qglobal.h>
class CacheManager;
/**
* CacheManager manages an arbitrary count of cached nodes, like for example preprocessed files.
* It decides what nodes can be removed and what nodes are still needed.
*
* */
class CacheNode {
typedef CacheManager Manager;
public:
CacheNode( Manager* manager );
virtual ~CacheNode();
void access() const;
inline uint value() const {
return m_value;
}
inline void setValue( const uint v ) const {
m_value = v;
}
inline void addValue( const uint diff ) const {
m_value += diff;
}
private:
Manager* m_manager;
mutable uint m_value; //This value stands for the priority of the node(higher is better)
};
class CacheNodeCompare {
public:
bool operator() ( const CacheNode* lhs, const CacheNode* rhs ) const {
if( lhs->value() != rhs->value() )
return lhs->value() < rhs->value();
else
return lhs < rhs; //To be able to identify nodes precisely
}
};
class CacheManager {
typedef std::set< const CacheNode*, CacheNodeCompare > SetType;
public:
CacheManager( int maxNodes = 1000 );
virtual ~CacheManager();
///Can be used from outside to set the maximum count of nodes to keep.
void setMaxNodes ( int maxNodes );
///Must be called on a regular basis to make clear that time has moved on(for example whenever a file was parsed)
void increaseFrame();
///Can be used on a regular basis(time-triggered) to save memory: The default-implementation removes the less important half of all cache-nodes
virtual void saveMemory();
///This triggered function should erase the given node.
virtual void erase( const CacheNode* node ) = 0;
private:
int currentMax() const {
return m_currentMax;
}
void access( const CacheNode* node );
void restart( uint normalizeby );
friend class CacheNode;
void remove( const CacheNode* node );
void add( const CacheNode* node );
int m_currentFrame;
int m_maxNodes;
uint m_currentMax;
SetType m_set;
};
#endif
......@@ -39,7 +39,6 @@
#include <iproblem.h>
#include "cppduchainexport.h"
#include "cachemanager.h"
#include "setrepository.h"
#include "parser/rpp/macrorepository.h"
......@@ -144,7 +143,7 @@ typedef Utils::LazySet<rpp::pp_macro, MacroIndexConversion> LazyMacroSet;
class EnvironmentManager;
class MacroSet;
class KDEVCPPDUCHAIN_EXPORT EnvironmentFile : public CacheNode, public KDevelop::ParsingEnvironmentFile {
class KDEVCPPDUCHAIN_EXPORT EnvironmentFile : public KDevelop::ParsingEnvironmentFile {
public:
///@todo Respect changing include-paths: Check if the included files are still the same(maybe new files are found that were not found before)
EnvironmentFile( const KDevelop::IndexedString& url, EnvironmentManager* manager );
......@@ -230,6 +229,10 @@ class KDEVCPPDUCHAIN_EXPORT EnvironmentFile : public CacheNode, public KDevelop:
void setContentStartLine(int line);
int contentStartLine() const;
virtual bool matchEnvironment(const KDevelop::ParsingEnvironment* environment) const;
virtual bool needsUpdate() const;
private:
virtual int type() const;
......@@ -267,7 +270,7 @@ struct KDEVCPPDUCHAIN_EXPORT EnvironmentFilePointerCompare {
}
};
class KDEVCPPDUCHAIN_EXPORT EnvironmentManager : public CacheManager, public KDevelop::ParsingEnvironmentManager {
class KDEVCPPDUCHAIN_EXPORT EnvironmentManager {
public:
static MacroDataRepository macroDataRepository;
......@@ -276,42 +279,11 @@ class KDEVCPPDUCHAIN_EXPORT EnvironmentManager : public CacheManager, public KDe
//Set-repository that contains the macro-sets
static Utils::BasicSetRepository macroSetRepository;
EnvironmentManager();
virtual ~EnvironmentManager();
//Overridden from ParsingEnvironmentManager
virtual void clear();
///Add a new file to the manager
virtual void addFile( KDevelop::ParsingEnvironmentFile* file );
///Remove a file from the manager
virtual void removeFile( KDevelop::ParsingEnvironmentFile* file );
///Returns true if the file itself, or any of its dependencies was modified.
virtual bool needsUpdate( const KDevelop::ParsingEnvironmentFile* file ) const;
///See the comment about simplified matching at the top
void setSimplifiedMatching(bool simplified);
bool isSimplifiedMatching() const;
/**
* Search for the availability of a file parsed in a given environment
* */
virtual KDevelop::ParsingEnvironmentFile* find( const KDevelop::IndexedString& url, const KDevelop::ParsingEnvironment* environment, KDevelop::ParsingEnvironmentFileAcceptor* accepter );
private:
virtual int type() const;
virtual void erase( const CacheNode* node );
///Returns zero if no fitting file is available for the given Environment
EnvironmentFilePointer lexedFile( const KDevelop::IndexedString& fileName, const rpp::Environment* environment, KDevelop::ParsingEnvironmentFileAcceptor* accepter );
void addEnvironmentFile( const EnvironmentFilePointer& file );
void removeEnvironmentFile( const EnvironmentFilePointer& file );
//typedef __gnu_cxx::hash_multimap<KDevelop::IndexedString, EnvironmentFilePointer> EnvironmentFileMap;
typedef std::multimap<KDevelop::IndexedString, EnvironmentFilePointer> EnvironmentFileMap;
EnvironmentFileMap m_files;
static void setSimplifiedMatching(bool simplified);
static bool isSimplifiedMatching();
bool m_simplifiedMatching;
static bool m_simplifiedMatching;
};
}
......
......@@ -144,12 +144,7 @@ CppLanguageSupport::CppLanguageSupport( QObject* parent, const QVariantList& /*a
m_cc = new KDevelop::CodeCompletion( this, new CppCodeCompletionModel(0), name() );
m_standardMacros = new Cpp::LazyMacroSet( &Cpp::EnvironmentManager::macroSetRepository );
m_standardIncludePaths = new QStringList;
m_environmentManager = new Cpp::EnvironmentManager;
m_environmentManager->setSimplifiedMatching(true); ///@todo Make simplified matching optional. Before that, make it work.
{
DUChainWriteLocker l(DUChain::lock());
DUChain::self()->addParsingEnvironmentManager(m_environmentManager);
}
Cpp::EnvironmentManager::setSimplifiedMatching(true); ///@todo Make simplified matching optional.
m_includeResolver = new CppTools::IncludePathResolver;
// Retrieve the standard include paths & macro definitions for this machine.
......@@ -386,15 +381,9 @@ CppLanguageSupport::~CppLanguageSupport()
// Remove any documents waiting to be parsed from the background paser.
core()->languageController()->backgroundParser()->clear(this);
// Remove the corresponding parsing environment from the DUChain.
{
DUChainWriteLocker l(DUChain::lock());
DUChain::self()->removeParsingEnvironmentManager(m_environmentManager);
}
delete m_standardMacros;
delete m_standardIncludePaths;
delete m_environmentManager;
delete m_includeResolver;
#ifdef DEBUG_UI_LOCKUP
delete m_blockTester;
......@@ -750,10 +739,6 @@ KDevelop::ILanguage *CppLanguageSupport::language()
return core()->languageController()->language(name());
}
Cpp::EnvironmentManager* CppLanguageSupport::environmentManager() const {
return m_environmentManager;
}
TopDUContext* CppLanguageSupport::standardContext(const KUrl& url, bool allowProxyContext)
{
DUChainReadLocker lock(DUChain::lock());
......@@ -1003,7 +988,7 @@ QWidget* CppLanguageSupport::specialLanguageObjectNavigationWidget(const KUrl& u
bool CppLanguageSupport::needsUpdate(const Cpp::EnvironmentFilePointer& file, const KUrl& localPath, const KUrl::List& includePaths) const
{
if(m_environmentManager->needsUpdate(file.data()))
if(file->needsUpdate())
return true;
///@todo somehow this check should also go into EnvironmentManager
......
......@@ -108,8 +108,6 @@ public:
const Cpp::LazyMacroSet& standardMacros() const;
Cpp::EnvironmentManager* environmentManager() const;
///Thread-safe
bool needsUpdate(const Cpp::EnvironmentFilePointer& file, const KUrl& localPath, const KUrl::List& includePaths ) const;
......@@ -157,7 +155,6 @@ private:
CppHighlighting *m_highlights;
KDevelop::CodeCompletion *m_cc;
Cpp::EnvironmentManager* m_environmentManager;
Cpp::LazyMacroSet *m_standardMacros;
QStringList *m_standardIncludePaths;
CppTools::IncludePathResolver *m_includeResolver;
......
......@@ -104,7 +104,7 @@ void PreprocessJob::run()
{
KDevelop::DUChainReadLocker readLock(KDevelop::DUChain::lock());
if(CppLanguageSupport::self()->environmentManager()->isSimplifiedMatching()) {
if(Cpp::EnvironmentManager::isSimplifiedMatching()) {
//Make sure that proxy-contexts and content-contexts never have the same identity, even if they have the same content.
m_firstEnvironmentFile->setIdentityOffset(1); //Mark the first environment-file as the proxy
IndexedString u = parentJob()->document();
......@@ -474,7 +474,7 @@ rpp::Stream* PreprocessJob::sourceNeeded(QString& _fileName, IncludeType type, i
bool PreprocessJob::checkAbort()
{
if(!CppLanguageSupport::self() || !CppLanguageSupport::self()->environmentManager()) {
if(!CppLanguageSupport::self()) {
kDebug(9007) << "Environment-manager disappeared" ;
return true;
}
......
......@@ -680,12 +680,6 @@ void TestCppCodeCompletion::testMacroExpansionRanges() {
}
void TestCppCodeCompletion::testEnvironmentMatching() {
Cpp::EnvironmentManager* environmentManager = new Cpp::EnvironmentManager;
{
DUChainWriteLocker l(DUChain::lock());
DUChain::self()->addParsingEnvironmentManager(environmentManager);
}
{
addInclude("deep2.h", "#ifdef WANT_DEEP\nint x;\n#undef WANT_DEEP\n#endif\n");
addInclude("deep1.h", "#define WANT_DEEP\n#include \"deep2.h\"\n");
......@@ -829,9 +823,6 @@ void TestCppCodeCompletion::testEnvironmentMatching() {
// QCOMPARE(top3->importedParentContexts().count(), 2);
QCOMPARE(top1->importedParentContexts()[0], top2->importedParentContexts()[1]);*/
DUChainWriteLocker lock(DUChain::lock());
DUChain::self()->removeParsingEnvironmentManager(environmentManager);
}
void TestCppCodeCompletion::testPreprocessor() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment