Commit f69eb420 authored by David Nolden's avatar David Nolden

Adapt to changes in kdevplatform

parent 84bc9d77
......@@ -45,8 +45,8 @@ KDevelop::DUContext* getArgumentContext(KDevelop::Declaration* decl) {
if( internal->type() == DUContext::Function )
return internal;
foreach( DUContext::Import ctx, internal->importedParentContexts() ) {
if( ctx.context )
if( ctx.context->type() == DUContext::Function )
if( ctx.context.data() )
if( ctx.context.data()->type() == DUContext::Function )
return ctx.context.data();
}
return 0;
......@@ -63,7 +63,7 @@ KDEVCPPDUCHAIN_EXPORT QList<KDevelop::Declaration*> findLocalDeclarations( KDev
QVector<DUContext::Import> bases = context->importedParentContexts();
for( QVector<DUContext::Import>::const_iterator it = bases.begin(); it != bases.end(); ++it ) {
if( it->context )
if( it->context.data() )
ret += findLocalDeclarations( (*it).context.data(), identifier, topContext );
}
return ret;
......
......@@ -77,8 +77,8 @@ DUContext* getTemplateContext(Declaration* decl) {
if( !internal )
return 0;
foreach( DUContext::Import ctx, internal->importedParentContexts() ) {
if( ctx.context )
if( ctx.context->type() == DUContext::Template )
if( ctx.context.data() )
if( ctx.context.data()->type() == DUContext::Template )
return ctx.context.data();
}
return 0;
......@@ -322,7 +322,7 @@ Type hasTemplateContext( const QList<Type>& contexts ) {
template<class Type>
Type hasTemplateContext( const QVector<Type>& contexts ) {
foreach( const Type& context, contexts )
if( context.context && context.context->type() == KDevelop::DUContext::Template )
if( context.context.data() && context.context.data()->type() == KDevelop::DUContext::Template )
return context;
return Type(0);
......
......@@ -818,21 +818,24 @@ private:
void addDeclarationsFromContext(DUContext* ctx, QString indent = "", bool first = true) {
//m_currentText += indent + ctx->localScopeIdentifier().toString() + "{<br />";
QVector<DUContext*>::const_iterator childIterator = ctx->childContexts().begin();
QVector<Declaration*>::const_iterator declarationIterator = ctx->localDeclarations().begin();
QVector<DUContext*> children = ctx->childContexts();
QVector<Declaration*> declarations = ctx->localDeclarations();
QVector<DUContext*>::const_iterator childIterator = children.begin();
QVector<Declaration*>::const_iterator declarationIterator = declarations.begin();
while(childIterator != ctx->childContexts().end() || declarationIterator != ctx->localDeclarations().end()) {
while(childIterator != children.end() || declarationIterator != declarations.end()) {
//Show declarations/contexts in the order they appear in the file
int currentDeclarationLine = -1;
int currentContextLine = -1;
if(declarationIterator != ctx->localDeclarations().end())
if(declarationIterator != declarations.end())
currentDeclarationLine = (*declarationIterator)->range().textRange().start().line();
if(childIterator != ctx->childContexts().end())
if(childIterator != children.end())
currentDeclarationLine = (*childIterator)->range().textRange().start().line();
if((currentDeclarationLine <= currentContextLine || currentContextLine == -1 || childIterator == ctx->childContexts().end()) && declarationIterator != ctx->localDeclarations().end() )
if((currentDeclarationLine <= currentContextLine || currentContextLine == -1 || childIterator == children.end()) && declarationIterator != declarations.end() )
{
if(!(*declarationIterator)->qualifiedIdentifier().toString().isEmpty() && !(*declarationIterator)->range().isEmpty() && !(*declarationIterator)->isForwardDeclaration()) {
//Show the declaration
......
......@@ -428,8 +428,8 @@ DUContext* getTemplateContext(Declaration* decl)
if( !internal )
return 0;
foreach( DUContext::Import ctx, internal->importedParentContexts() ) {
if( ctx.context )
if( ctx.context->type() == DUContext::Template )
if( ctx.context.data() )
if( ctx.context.data()->type() == DUContext::Template )
return ctx.context.data();
}
return 0;
......@@ -558,15 +558,15 @@ CppDUContext<KDevelop::DUContext>* instantiateDeclarationAndContext( KDevelop::D
///Find the template-parameter context, and recurse into it, so we can replace the template parameters
foreach( DUContext::Import importedContext, context->importedParentContexts() )
{
if( !importedContext.context)
if( !importedContext.context.data())
continue;
///For functions, the Template-context is one level deeper(it is imported by the function-context) so also copy the function-context
if( importedContext.context->type() == KDevelop::DUContext::Template || importedContext.context->type() == KDevelop::DUContext::Function )
if( importedContext.context.data()->type() == KDevelop::DUContext::Template || importedContext.context.data()->type() == KDevelop::DUContext::Function )
{
DUContext* ctx = instantiateDeclarationAndContext( parentContext, source, importedContext.context.data(), templateArguments, 0, 0);
contextCopy->addImportedParentContext( ctx, SimpleCursor(), true );
if( instantiatedDeclaration && importedContext.context->type() == KDevelop::DUContext::Template ) {
if( instantiatedDeclaration && importedContext.context.data()->type() == KDevelop::DUContext::Template ) {
TemplateDeclaration* tempDecl = dynamic_cast<TemplateDeclaration*>(instantiatedDeclaration);
if( instantiatedDeclaration )
tempDecl->setTemplateParameterContext( ctx );
......
......@@ -70,6 +70,15 @@ using namespace Utils;
QTEST_MAIN(TestDUChain)
void release(TopDUContext* top)
{
//KDevelop::EditorIntegrator::releaseTopRange(top->textRangePtr());
TopDUContextPointer tp(top);
DUChain::self()->removeDocumentChain(static_cast<TopDUContext*>(top)->identity());
Q_ASSERT(!tp);
}
namespace QTest {
template<>
char* toString(const Cursor& cursor)
......@@ -1727,13 +1736,13 @@ void TestDUChain::testTemplates() {
QVERIFY(instanceDefClassA->context() == defClassA->context());
QVERIFY(instanceDefClassA->internalContext()->importedParentContexts().size() == 1);
QVERIFY(defClassA->internalContext()->importedParentContexts().size() == 1);
QCOMPARE(instanceDefClassA->internalContext()->importedParentContexts().front().context->type(), DUContext::Template);
QVERIFY(defClassA->internalContext()->importedParentContexts().front().context != instanceDefClassA->internalContext()->importedParentContexts().front().context); //The template-context has been instantiated
QCOMPARE(instanceDefClassA->internalContext()->importedParentContexts().front().context.data()->type(), DUContext::Template);
QVERIFY(defClassA->internalContext()->importedParentContexts().front().context.data() != instanceDefClassA->internalContext()->importedParentContexts().front().context.data()); //The template-context has been instantiated
//Make sure the first template-parameter has been resolved to class B
QCOMPARE( instanceDefClassA->internalContext()->importedParentContexts()[0].context->localDeclarations()[0]->abstractType()->indexed(), defClassB->abstractType()->indexed() );
QCOMPARE( instanceDefClassA->internalContext()->importedParentContexts()[0].context.data()->localDeclarations()[0]->abstractType()->indexed(), defClassB->abstractType()->indexed() );
//Make sure the second template-parameter has been resolved to class C
QCOMPARE( instanceDefClassA->internalContext()->importedParentContexts()[0].context->localDeclarations()[1]->abstractType()->indexed(), defClassC->abstractType()->indexed() );
QCOMPARE( instanceDefClassA->internalContext()->importedParentContexts()[0].context.data()->localDeclarations()[1]->abstractType()->indexed(), defClassC->abstractType()->indexed() );
QualifiedIdentifier ident2(ident);
ident2.push(Identifier("Template1"));
......@@ -1993,26 +2002,33 @@ struct TestContext {
static int number = 0;
++number;
DUChainWriteLocker lock(DUChain::lock());
m_context = new TopDUContext(IndexedString(QString("%1").arg(number)), SimpleRange());
m_context = new TopDUContext(IndexedString(QString("/test1/%1").arg(number)), SimpleRange());
DUChain::self()->addDocumentChain(IdentifiedFile(IndexedString(QString("/test1/%1").arg(number))), m_context);
Q_ASSERT(IndexedDUContext(m_context).context() == m_context);
}
~TestContext() {
unImport(imports);
DUChainWriteLocker lock(DUChain::lock());
m_context->deleteSelf();
release(m_context);//->deleteSelf();
}
void verify(QList<TestContext*> allContexts) {
QCOMPARE(m_context->importedParentContexts().count(), imports.count());
{
DUChainReadLocker lock(DUChain::lock());
QCOMPARE(m_context->importedParentContexts().count(), imports.count());
}
//Compute a closure of all children, and verify that they are imported.
QSet<TestContext*> collected;
collectImports(collected);
collected.remove(this);
DUChainReadLocker lock(DUChain::lock());
foreach(TestContext* context, collected)
QVERIFY(m_context->imports(context->m_context, SimpleCursor::invalid()));
//Verify that no other contexts are imported
DUChainReadLocker lock(DUChain::lock());
foreach(TestContext* context, allContexts)
if(context != this)
QVERIFY(collected.contains(context) || !m_context->imports(context->m_context, SimpleCursor::invalid()));
......@@ -2675,15 +2691,6 @@ void TestDUChain::testIndexedStrings() {
kDebug() << a << "successful tests";
}
void TestDUChain::release(TopDUContext* top)
{
//KDevelop::EditorIntegrator::releaseTopRange(top->textRangePtr());
TopDUContextPointer tp(top);
DUChain::self()->removeDocumentChain(static_cast<TopDUContext*>(top)->identity());
Q_ASSERT(!tp);
}
TopDUContext* TestDUChain::parse(const QByteArray& unit, DumpAreas dump)
{
if (dump)
......
......@@ -126,8 +126,6 @@ public:
private:
KDevelop::TopDUContext* parse(const QByteArray& unit, DumpAreas dump = static_cast<DumpAreas>(DumpAST | DumpDUChain | DumpType));
void release(KDevelop::TopDUContext* top);
// Parser
Control control;
Cpp::DumpChain cppDumper;
......
......@@ -65,10 +65,10 @@ bool isTemplateDependent(Declaration* decl) {
while( ctx && ctx->type() != DUContext::Global && ctx->type() != DUContext::Namespace ) {
//Check if there is an imported template-context, which has an unresolved template-parameter
foreach( DUContext::Import importedCtx, ctx->importedParentContexts() ) {
if( !importedCtx.context )
if( !importedCtx.context.data() )
continue;
if( importedCtx.context->type() == DUContext::Template ) {
foreach( Declaration* paramDecl, importedCtx.context->localDeclarations() ) {
if( importedCtx.context.data()->type() == DUContext::Template ) {
foreach( Declaration* paramDecl, importedCtx.context.data()->localDeclarations() ) {
CppTemplateParameterType::Ptr templateParamType = paramDecl->abstractType().cast<CppTemplateParameterType>();
if( templateParamType )
return true;
......
......@@ -64,7 +64,7 @@ protected:
virtual void visitTemplateParameter(TemplateParameterAST *);
virtual void createTypeForDeclarator(DeclaratorAST *node);
virtual void closeTypeForDeclarator(DeclaratorAST *node);
bool m_declarationHasInitDeclarators; //Is set when processing the type-specifiers within SimpleDeclarationASTs, to change the behavior for elaborated type-specifiers.
///Returns whether a type was opened
......
......@@ -353,7 +353,7 @@ void CppHighlighting::highlightDUChain(DUContext* context, QHash<Declaration*, u
//Merge the colors from the function arguments
foreach( DUContext::Import imported, context->importedParentContexts() ) {
if(!imported.context || (imported.context->type() != DUContext::Other && imported.context->type() != DUContext::Function))
if(!imported.context.data() || (imported.context.data()->type() != DUContext::Other && imported.context.data()->type() != DUContext::Function))
continue;
//For now it's enough simply copying them, because we only pass on colors within function bodies.
if (m_functionColorsForDeclarations.contains(imported.context))
......@@ -407,8 +407,8 @@ void CppHighlighting::highlightDUChain(DUContext* context, QHash<Declaration*, u
foreach (DUContext* child, context->childContexts())
highlightDUChain(child, colorsForDeclarations, declarationsForColors );
if(context->type() == DUContext::Other || context->type() == DUContext::Function) {
m_functionColorsForDeclarations[DUContextPointer(context)] = colorsForDeclarations;
m_functionDeclarationsForColors[DUContextPointer(context)] = declarationsForColors;
m_functionColorsForDeclarations[IndexedDUContext(context)] = colorsForDeclarations;
m_functionDeclarationsForColors[IndexedDUContext(context)] = declarationsForColors;
}
}
......
......@@ -27,7 +27,7 @@
#include <QHash>
#include <QModelIndex>
#include <vector>
#include <duchain/duchainpointer.h>
#include <duchain/ducontext.h>
#include <ktexteditor/attribute.h>
......@@ -128,8 +128,8 @@ class CppHighlighting : public QObject, public KDevelop::ICodeHighlighting
mutable QHash<KDevelop::DUContext*, KDevelop::Declaration*> m_contextClasses;
//Here the colors of function context are stored until they are merged into the function body
mutable QMap<KDevelop::DUContextPointer, QHash<KDevelop::Declaration*, uint> > m_functionColorsForDeclarations;
mutable QMap<KDevelop::DUContextPointer, ColorMap> m_functionDeclarationsForColors;
mutable QMap<KDevelop::IndexedDUContext, QHash<KDevelop::Declaration*, uint> > m_functionColorsForDeclarations;
mutable QMap<KDevelop::IndexedDUContext, ColorMap> m_functionDeclarationsForColors;
//Should be used to enable/disable the colorization of local variables and their uses
bool m_localColorization;
......
......@@ -865,7 +865,7 @@ QPair<TopDUContextPointer, SimpleRange> CppLanguageSupport::importedContextForPo
if(word.startsWith("#include")) {
//It's an #include, find out which file was included at the given line
foreach(DUContext::Import imported, ctx->importedParentContexts()) {
if(imported.context) {
if(imported.context.data()) {
if(ctx->importPosition(imported.context.data()).line == wordRange.start.line) {
if(TopDUContext* importedTop = dynamic_cast<TopDUContext*>(imported.context.data()))
return qMakePair(TopDUContextPointer(importedTop), wordRange);
......
......@@ -66,7 +66,7 @@ using namespace KDevelop;
bool importsContext(const QVector<DUContext::Import>& contexts, const DUContext* context) {
foreach(DUContext::Import listCtx, contexts)
if(listCtx.context && listCtx.context->imports(context))
if(listCtx.context.data() && listCtx.context.data()->imports(context))
return true;
return false;
}
......@@ -481,9 +481,9 @@ void CPPInternalParseJob::run()
QVector<DUContext::Import> imports = contentContext->importedParentContexts();
foreach(DUContext::Import ctx, imports) {
if(ctx.context.data() && !encounteredIncludeUrls.contains(IndexedString(ctx.context->url().str()))) { ///@todo prevent conversion
if(ctx.context.data() && !encounteredIncludeUrls.contains(IndexedString(ctx.context.data()->url().str()))) { ///@todo prevent conversion
contentContext->removeImportedParentContext(ctx.context.data());
kDebug( 9007 ) << "removing not encountered import " << ctx.context->url().str();
kDebug( 9007 ) << "removing not encountered import " << ctx.context.data()->url().str();
}
}
}
......
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