/*****************************************************************************
* Copyright (c) 2007 Piyush verma *
* *
* Permission is hereby granted, free of charge, to any person obtaining *
* a copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to *
* the following conditions: *
* *
* The above copyright notice and this permission notice shall be *
* included in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE *
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION *
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION *
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
*****************************************************************************/
#include "usebuilder.h"
#include "pythoneditorintegrator.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "ast.h"
using namespace KTextEditor;
using namespace KDevelop;
namespace Python {
UseBuilder::UseBuilder (PythonEditorIntegrator* editor) : m_editor(editor)
{
}
// void UseBuilder::buildUses(Ast *node)
// {
// supportBuild(node);
// // if (TopDUContext* top = dynamic_cast(m_session->getNode(node)))
// // top->setHasUses(true);
// }
void UseBuilder::visitName(NameAst* node)
{
DUChainWriteLocker lock(DUChain::lock());
DUContext* current = currentContext();
QList declarations = currentContext()->findDeclarations(identifierForNode(node->identifier), editorFindRange(node, node).end);
Declaration* declaration;
if ( declarations.length() ) declaration = declarations.last();
else declaration = 0;
Q_ASSERT(node->identifier);
Q_ASSERT(node->hasUsefulRangeInformation); // TODO remove this!
kDebug() << " Registeriung use for " << node->identifier->value << " at " << node->identifier->startLine << ":" << node->identifier->endCol << "->" << node->identifier->endLine << ":" << node->identifier->endCol + 1 << "with dec" << declaration;
UseBuilderBase::newUse(node, RangeInRevision(node->identifier->startLine, node->identifier->startCol, node->identifier->endLine, node->identifier->endCol + 1), declaration); // +1 for whatever reason
}
// void UseBuilder::visitIdentifier(Identifier* node)
// {
// DUChainWriteLocker lock( DUChain::lock() );
// QualifiedIdentifier id = identifierForNode(node);
// RangeInRevision range = editorFindRange(node, node);
// CursorInRevision until = range.start;
// QList allDeclarations = currentContext()->findDeclarations(id, until);
//
// kDebug() << " >> scanning " << node->value;
// kDebug() << " > searching for declaration until" << until.line << ":" << until.column << "; " << allDeclarations.length() << "Declarations found";
//
// Declaration *globalDeclaration = 0;
// foreach ( Declaration* dec, allDeclarations ) {
// if ( dec->context() == dec->topContext() ) {
// kDebug() << "There's already a global declaration for" << node->value;
// globalDeclaration = dec;
// }
// }
//
// // if there's a local declaration, use the last one of those
// if ( allDeclarations.length() && allDeclarations.last()->context() != allDeclarations.last()->topContext() ) {
// kDebug() << " ++ Created a use of local declaration for node" << node->value;
// UseBuilderBase::newUse(node, allDeclarations.last());
// }
// // otherwise, use the global one.
// // Note that the following is not allowed by python: a=3; def foo(): print a; a=7
// else if ( globalDeclaration ) {
// kDebug() << " ++ Created a use of global declaration for node" << node->value;
// UseBuilderBase::newUse(node, globalDeclaration);
// }
// }
// void UseBuilder::visitIdentifierTarget(IdentifierTargetAst* node)
// {
// kDebug() << "Target variable identifier: " << node->identifier->identifier.toAscii();
// UseBuilderBase::visitIdentifierTarget(node);
// }
void UseBuilder::openContext(DUContext * newContext)
{
UseBuilderBase::openContext(newContext);
m_nextUseStack.push(0);
}
void UseBuilder::closeContext()
{
UseBuilderBase::closeContext();
m_nextUseStack.pop();
}
ParseSession *UseBuilder::parseSession() const
{
return m_session;
}
}
// kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on; auto-insert-doxygen on