playground/devtools/kdevelop4-extra-plugins/python
Andreas Pakulat
apaku at gmx.de
Sun Feb 17 10:48:39 UTC 2008
SVN commit 776062 by apaku:
Align the context builder with the code in the C++ support, I'm wondering
wether some of this could be factored out and put into DUChain? David I'm
seeing a lot of code duplication happening (although there are some details
differing).
CCMAIL:kdevelop-devel at kdevelop.org
Along the way also remove the extra includes and use #include <language/duchain/foo.h> instead.
M +7 -6 CMakeLists.txt
M +56 -34 duchain/contextbuilder.cpp
M +11 -13 duchain/contextbuilder.h
M +7 -8 duchain/dumpchain.cpp
M +2 -2 duchain/pythoneditorintegrator.cpp
M +1 -1 duchain/pythoneditorintegrator.h
M +6 -6 pythonhighlighting.cpp
M +1 -1 pythonhighlighting.h
M +7 -7 pythonlanguagesupport.cpp
M +2 -3 pythonlanguagesupport.h
M +6 -7 pythonparsejob.cpp
M +2 -2 pythonparsejob.h
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/CMakeLists.txt #776061:776062
@@ -7,16 +7,17 @@
find_package(KDevPlatform REQUIRED)
+# ${KDEVPLATFORM_INCLUDE_DIR}/language/interfaces
+# ${KDEVPLATFORM_INCLUDE_DIR}/interfaces
+# ${KDEVPLATFORM_INCLUDE_DIR}/language
+# ${KDEVPLATFORM_INCLUDE_DIR}/editor
+# ${KDEVPLATFORM_INCLUDE_DIR}/language/backgroundparser
+# ${KDEVPLATFORM_INCLUDE_DIR}/language/duchain
include_directories(
- ${KDEVPLATFORM_INCLUDE_DIR}/language/interfaces
- ${KDEVPLATFORM_INCLUDE_DIR}/interfaces
- ${KDEVPLATFORM_INCLUDE_DIR}/language
- ${KDEVPLATFORM_INCLUDE_DIR}/editor
- ${KDEVPLATFORM_INCLUDE_DIR}/language/backgroundparser
+ ${KDEVPLATFORM_INCLUDE_DIR}
${KDE4_INCLUDES}
${KDE4_INCLUDE_DIR}/threadweaver
${CMAKE_CURRENT_BINARY_DIR}
- ${KDEVPLATFORM_INCLUDE_DIR}/language/duchain
${CMAKE_SOURCE_DIR}/duchain
${CMAKE_SOURCE_DIR}/parser
)
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/duchain/contextbuilder.cpp #776061:776062
@@ -21,18 +21,17 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
*****************************************************************************/
#include <contextbuilder.h>
-#include <duchain.h>
-#include <duchainlock.h>
-#include <parsesession.h>
-#include <topducontext.h>
-#include "pythoneditorintegrator.h"
-#include "dumpchain.h"
-#include <parsingenvironment.h>
+#include <language/duchain/duchain.h>
+#include <language/duchain/duchainlock.h>
+#include <language/duchain/topducontext.h>
+#include <language/duchain/parsingenvironment.h>
#include <ktexteditor/smartrange.h>
#include <ktexteditor/smartinterface.h>
#include <ktexteditor/document.h>
-#include <smartconverter.h>
-#include <symboltable.h>
+#include <language/duchain/smartconverter.h>
+#include <language/duchain/symboltable.h>
+#include "pythoneditorintegrator.h"
+#include "dumpchain.h"
using namespace KDevelop;
@@ -42,27 +41,23 @@
{
-ContextBuilder::ContextBuilder( const KUrl &url )
+ContextBuilder::ContextBuilder()
: m_editor( new EditorIntegrator )
- , m_url( url )
, m_ownsEditorIntegrator( true )
, m_compilingContexts( false )
, m_recompiling( false )
, m_lastContext( 0 )
{
- kDebug() << "*********Building Contexts for*******" << m_url;
}
-ContextBuilder::ContextBuilder( EditorIntegrator* editor, const KUrl &url )
+ContextBuilder::ContextBuilder( EditorIntegrator* editor )
: m_editor( editor )
- , m_url( url )
, m_ownsEditorIntegrator( false )
, m_compilingContexts( false )
, m_recompiling( false )
, m_lastContext( 0 )
{
- kDebug() << "*********Building Contexts for********" << m_url;
}
@@ -72,24 +67,34 @@
delete m_editor;
}
-TopDUContext* ContextBuilder::buildContexts( Ast* node )
+TopDUContext* ContextBuilder::buildContexts( const KUrl& url, Ast* node, const TopDUContextPointer& updateContext )
{
m_compilingContexts = true;
- m_editor->setCurrentUrl( KDevelop::HashedString( m_url.prettyUrl() ) );
+ m_editor->setCurrentUrl( KDevelop::HashedString( url.prettyUrl() ) );
TopDUContext* topLevelContext = 0;
{
DUChainWriteLocker lock( DUChain::lock() );
- topLevelContext = DUChain::self()->chainForDocument( m_url );
+ topLevelContext = updateContext.data();
if ( topLevelContext && !topLevelContext->smartRange() && m_editor->smart() )
{
lock.unlock();
- SmartConverter conv( m_editor, 0 );
- conv.convertDUChain( topLevelContext );
+ smartenContext( topLevelContext );
lock.lock();
+ topLevelContext = updateContext.data();
}
+ if ( topLevelContext && topLevelContext->smartRange() )
+ {
+ if ( topLevelContext->smartRange()->parentRange() )
+ {
+ //Top range must not have a parent, else something is wrong with the structure
+ kDebug() << *topLevelContext->smartRange() << "has a parent" << *topLevelContext->smartRange()->parentRange();
+ Q_ASSERT( false );
+ }
+ }
+
if ( topLevelContext )
{
kDebug() << "ContextBuilder::buildContexts: recompiling";
@@ -112,7 +117,7 @@
topLevelContext = new TopDUContext( m_editor->currentUrl(), m_editor->currentDocument() ? SimpleRange( m_editor->currentDocument()->documentRange() ) : SimpleRange( SimpleCursor( 0, 0 ), SimpleCursor( INT_MAX, INT_MAX ) ) );
topLevelContext->setSmartRange( m_editor->topRange( EditorIntegrator::DefinitionUseChain ) , DocumentRangeObject::Own );
topLevelContext->setType( DUContext::Global );
- DUChain::self()->addDocumentChain( IdentifiedFile( m_url, 0 ), topLevelContext );
+ DUChain::self()->addDocumentChain( IdentifiedFile( url, 0 ), topLevelContext );
}
setEncountered( topLevelContext );
@@ -122,10 +127,13 @@
supportBuild( node );
+ if ( m_editor->currentDocument() && m_editor->smart() && topLevelContext->range().textRange() != m_editor->currentDocument()->documentRange() )
{
- // allDeclarations always returned Zero as it looks for the Total Number Of definitions, as Depicted here.
- // Currently it simply dispalys the localdeclarations in the topcontext,
- // def a():\n\tpass\ndef b():\n\tpass returns 2 Declarations.
+ kDebug() << "WARNING: top level context has wrong size:" << topLevelContext->range().textRange() << "should be:" << m_editor->currentDocument()->documentRange();
+ topLevelContext->setRange( m_editor->currentDocument()->documentRange() );
+ }
+
+ {
DUChainReadLocker lock( DUChain::lock() );
//foreach(DUContext* context, topLevelContext->childContexts());
kDebug() << "built top-level context with" << topLevelContext->localDeclarations().count() << "declarations," << topLevelContext->localDefinitions().count() << " Definitions and" << topLevelContext->childContexts().size() << "Child-Contexts";
@@ -137,8 +145,7 @@
}
foreach( DUContext* contexts, topLevelContext->childContexts() )
-
- kDebug() << "CHILD:" << contexts->scopeIdentifier( true ) << "Parent:" << ( dynamic_cast<TopDUContext*>( contexts->parentContext() ) ? "top-context" : "" );
+ kDebug() << "CHILD:" << contexts->scopeIdentifier( true ) << "Parent:" << ( dynamic_cast<TopDUContext*>( contexts->parentContext() ) ? "top-context" : "" );
}
m_compilingContexts = false;
@@ -147,8 +154,8 @@
KDevelop::DUContext* ContextBuilder::buildSubContexts( const KUrl& url, Ast *node, KDevelop::DUContext* parent )
{
- m_compilingContexts = true;
- m_recompiling = false;
+// m_compilingContexts = true;
+// m_recompiling = false;
m_editor->setCurrentUrl( HashedString( url.prettyUrl() ) );
node->context = parent;
{
@@ -173,10 +180,15 @@
void ContextBuilder::supportBuild( Ast *node, DUContext* context )
{
- if ( !node->context )
+ if( !context )
{
- kDebug() << "No Context Found matching with the node";
+ context = node->context;
}
+
+ if( TopDUContext* topLevelContext = dynamic_cast<TopDUContext*>( context ) )
+ {
+ smartenContext( topLevelContext );
+ }
openContext( context ? context : node->context );
@@ -207,11 +219,12 @@
DUChainReadLocker lock( DUChain::lock() );
QList<DUContext*> classContexts = currentContext()->findContexts( DUContext::Class, QualifiedIdentifier( classast->context->localScopeIdentifier() ) );
- if ( classContexts.count() == 1 )
+ if ( classContexts.count() != 1 )
{
m_importedParentContexts.append( classContexts.first() );
}
- else if ( classContexts.count() > 1 )
+
+ if ( classContexts.count() > 1 )
{
kWarning() << "Multiple class contexts for" << classast->className->identifier << classast->context->localScopeIdentifier() << "shouldn't happen!";
foreach( DUContext* classContext, classContexts )
@@ -466,8 +479,8 @@
for ( it = node->elseIfBodies.begin(); it != end; ++it )
{
- visitNode(( *it ).first );
- openContextForStatementList(( *it ).second );
+ visitNode( ( *it ).first );
+ openContextForStatementList( ( *it ).second );
}
openContextForStatementList( node->elseBody );
@@ -498,4 +511,13 @@
return m_nextContextStack.top();
}
+void ContextBuilder::smartenContext( TopDUContext* topLevelContext )
+{
+ if ( topLevelContext && !topLevelContext->smartRange() && m_editor->smart() )
+ {
+ SmartConverter conv( m_editor, 0 );
+ conv.convertDUChain( topLevelContext );
+ }
}
+
+}
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/duchain/contextbuilder.h #776061:776062
@@ -28,21 +28,18 @@
#include <QSet>
#include <QHash>
#include <QList>
-#include <identifier.h>
-#include <ducontext.h>
+#include <language/duchain/identifier.h>
+#include <language/duchain/duchainpointer.h>
+#include <language/duchain/ducontext.h>
#include <ksharedptr.h>
#include "pythonduchainexport.h"
namespace KDevelop
{
-
class DUChain;
-
-class KDevelop::DUChainBase;
-
+class DUChainBase;
class DUContext;
-
class TopDUContext;
}
@@ -55,13 +52,16 @@
{
public:
- ContextBuilder( const KUrl &url );
- ContextBuilder( EditorIntegrator* editor, const KUrl &url );
+ ContextBuilder();
+ ContextBuilder( EditorIntegrator* editor );
virtual ~ContextBuilder();
- KDevelop::TopDUContext* buildContexts( Ast* node );
- KDevelop::DUContext* buildSubContexts( const KUrl& url, Ast *node, KDevelop::DUContext* parent = 0 );
+ KDevelop::TopDUContext* buildContexts( const KUrl& url, Ast* node, const KDevelop::TopDUContextPointer& updateContext = KDevelop::TopDUContextPointer() );
+ KDevelop::DUContext* buildSubContexts( const KUrl& url, Ast* node, KDevelop::DUContext* parent = 0 );
void supportBuild( Ast *node, KDevelop::DUContext* context = 0 );
+
+protected:
+ void smartenContext( KDevelop::TopDUContext* topLevelContext );
KDevelop::DUContext* currentContext();
void setEncountered( KDevelop::DUChainBase* item );
@@ -93,7 +93,6 @@
virtual void visitTry( TryAst* node );
void addImportedContexts();
-private:
template <typename T> void visitNodeList( const QList<T*>& l )
{
typename QList<T*>::ConstIterator it, end = l.end();
@@ -106,7 +105,6 @@
protected:
EditorIntegrator* m_editor;
- KUrl m_url;
bool m_ownsEditorIntegrator: 1;
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/duchain/dumpchain.cpp #776061:776062
@@ -22,15 +22,14 @@
*****************************************************************************/
#include "dumpchain.h"
#include "pythoneditorintegrator.h"
-#include "parsesession.h"
-#include <identifiedtype.h>
-#include <ducontext.h>
-#include <topducontext.h>
-#include <declaration.h>
-#include <definition.h>
-#include <duchainpointer.h>
-#include <use.h>
+#include <language/duchain/identifiedtype.h>
+#include <language/duchain/ducontext.h>
+#include <language/duchain/topducontext.h>
+#include <language/duchain/declaration.h>
+#include <language/duchain/definition.h>
+#include <language/duchain/duchainpointer.h>
+#include <language/duchain/use.h>
using namespace KDevelop;
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/duchain/pythoneditorintegrator.cpp #776061:776062
@@ -25,8 +25,8 @@
#include <ktexteditor/smartrange.h>
#include <ktexteditor/smartinterface.h>
-#include <documentrange.h>
-#include <documentrangeobject.h>
+#include <editor/documentrange.h>
+#include <editor/documentrangeobject.h>
#include "ast.h"
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/duchain/pythoneditorintegrator.h #776061:776062
@@ -23,7 +23,7 @@
#ifndef PYTHONEDITORINTEGRATOR_H
#define PYTHONEDITORINTEGRATOR_H
-#include <editorintegrator.h>
+#include <editor/editorintegrator.h>
#include "pythonduchainexport.h"
namespace Python
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/pythonhighlighting.cpp #776061:776062
@@ -24,12 +24,12 @@
#include <ktexteditor/smartrange.h>
-#include <topducontext.h>
-#include <declaration.h>
-#include <definition.h>
-#include <use.h>
-#include <duchain.h>
-#include <duchainlock.h>
+#include <language/duchain/topducontext.h>
+#include <language/duchain/declaration.h>
+#include <language/duchain/definition.h>
+#include <language/duchain/use.h>
+#include <language/duchain/duchain.h>
+#include <language/duchain/duchainlock.h>
using namespace KTextEditor;
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/pythonhighlighting.h #776061:776062
@@ -28,7 +28,7 @@
#include <QModelIndex>
#include <ktexteditor/attribute.h>
-#include <icodehighlighting.h>
+#include <language/interfaces/icodehighlighting.h>
namespace KTextEditor
{
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/pythonlanguagesupport.cpp #776061:776062
@@ -34,13 +34,13 @@
#include <QExtensionFactory>
-#include <icore.h>
-#include <ilanguagecontroller.h>
-#include <iplugincontroller.h>
-#include <ilanguage.h>
-#include <idocument.h>
-#include <backgroundparser.h>
-#include <idocumentcontroller.h>
+#include <interfaces/icore.h>
+#include <interfaces/ilanguagecontroller.h>
+#include <interfaces/iplugincontroller.h>
+#include <interfaces/ilanguage.h>
+#include <interfaces/idocument.h>
+#include <language/backgroundparser/backgroundparser.h>
+#include <interfaces/idocumentcontroller.h>
#include "pythonparsejob.h"
#include "pythonhighlighting.h"
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/pythonlanguagesupport.h #776061:776062
@@ -25,8 +25,8 @@
#ifndef KDEVPYTHONLANGUAGESUPPORT_H
#define KDEVPYTHONLANGUAGESUPPORT_H
-#include <iplugin.h>
-#include <ilanguagesupport.h>
+#include <interfaces/iplugin.h>
+#include <language/interfaces/ilanguagesupport.h>
#include <QtCore/QVariant>
namespace KDevelop
@@ -72,4 +72,3 @@
#endif
-// kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on; auto-insert-doxygen on
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/pythonparsejob.cpp #776061:776062
@@ -30,11 +30,10 @@
#include <kdebug.h>
#include <klocale.h>
-#include <duchainlock.h>
-#include <parsejob.h>
-#include <duchain.h>
-#include <topducontext.h>
-#include <dumpdotgraph.h>
+#include <language/duchain/duchainlock.h>
+#include <language/duchain/duchain.h>
+#include <language/duchain/topducontext.h>
+#include <language/duchain/dumpdotgraph.h>
#include "pythonhighlighting.h"
#include "dumpchain.h"
@@ -132,8 +131,8 @@
AstPrinter printer;
printer.visitCode( m_ast );
// DeclarationBuilder declarationBuilder(m_session,m_url);
- ContextBuilder builder( m_url );
- m_duContext = builder.buildContexts( m_ast );
+ ContextBuilder builder;
+ m_duContext = builder.buildContexts( m_url, m_ast );
// m_duContext = declarationBuilder.buildDeclarations(m_AST);
kDebug() << "----Parsing Succeded---***";//TODO: bind declarations to the code model
--- trunk/playground/devtools/kdevelop4-extra-plugins/python/pythonparsejob.h #776061:776062
@@ -24,7 +24,7 @@
#ifndef PARSEJOB_H
#define PARSEJOB_H
-#include <parsejob.h>
+#include <language/backgroundparser/parsejob.h>
#include "ast.h"
#include <QStringList>
@@ -32,7 +32,7 @@
#include <ksharedptr.h>
#include <ktexteditor/range.h>
-#include <duchainpointer.h>
+#include <language/duchain/duchainpointer.h>
namespace KDevelop
More information about the KDevelop-devel
mailing list