Fixed problem with "raw" statements, and many small adjustments · scummos/kdevelop-python@d348b22 · GitHub
Skip to content

Commit d348b22

Browse files
committed
Fixed problem with "raw" statements, and many small adjustments
1 parent f2c6dc9 commit d348b22

15 files changed

Lines changed: 87 additions & 8 deletions

‎codecompletion/pythoncodecompletioncontext.cpp‎

Lines changed: 6 additions & 0 deletions

‎codecompletion/pythoncodecompletionmodel.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* This file is part of KDevelop
3+
* Copyright 2010 Sven Brauch <svenbrauch@googlemail.com>
4+
* Licensed under the GNU GPL
5+
* */
6+
17
#include "pythoncodecompletionmodel.h"
28
#include "pythoncodecompletionworker.h"
39
#include "ktexteditor/view.h"

‎codecompletion/pythoncodecompletionworker.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* This file is part of KDevelop
3+
* Copyright 2010 Sven Brauch <svenbrauch@googlemail.com>
4+
* Licensed under the GNU GPL
5+
* */
6+
17
#include "pythoncodecompletionworker.h"
28
#include "pythoncodecompletionmodel.h"
39
#include "pythoncodecompletioncontext.h"

‎duchain/contextbuilder.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ void ContextBuilder::visitImport(ImportAst* node)
200200
else {
201201
DUChainWriteLocker lock(DUChain::lock());
202202
TopDUContext* moduleChain = DUChain::self()->chainForDocument(KUrl(moduleFilePath));
203-
currentContext()->addImportedParentContext(moduleChain);
203+
contextsForModules.insert(name->name->value, TopDUContextPointer(moduleChain));
204+
kDebug() << "Added " << name->name->value << " to the module chain map";
205+
// currentContext()->addImportedParentContext(moduleChain);
204206
}
205207
}
206208
Python::AstDefaultVisitor::visitImport(node);

‎duchain/contextbuilder.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ using namespace KDevelop;
3636

3737
namespace Python
3838
{
39+
40+
typedef QPair<QString, TopDUContextPointer> moduleContextTuple;
3941

4042
class PythonEditorIntegrator;
4143
class ParseSession;
@@ -71,6 +73,8 @@ class KDEVPYTHONDUCHAIN_EXPORT ContextBuilder: public ContextBuilderBase, public
7173
virtual void visitCode(CodeAst* node);
7274
virtual void visitImport(ImportAst* node);
7375
virtual void visitImportFrom(ImportFromAst* node);
76+
77+
QMap<QString, TopDUContextPointer> contextsForModules;
7478

7579
static PythonEditorIntegrator* m_editor;
7680

‎duchain/declarationbuilder.cpp‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*****************************************************************************
22
* Copyright (c) 2007 Piyush verma <piyush.verma@gmail.com> *
3-
* Copyright 2007 Andreas Pakulat <apaku@gmx.de> *
3+
* Copyright 2007 Andreas Pakulat <apaku@gmx.de> *
4+
* Copyright 2010 Sven Brauch <svenbrauch@googlemail.com> *
45
* *
56
* Permission is hereby granted, free of charge, to any person obtaining *
67
* a copy of this software and associated documentation files (the *
@@ -39,6 +40,8 @@
3940
#include <language/duchain/types/unsuretype.h>
4041
#include <language/duchain/builders/abstracttypebuilder.h>
4142

43+
#include "contextbuilder.h"
44+
4245
#include "pythoneditorintegrator.h"
4346
#include "QtGlobal"
4447

@@ -115,9 +118,16 @@ Declaration* DeclarationBuilder::visitVariableDeclaration(Identifier* node, Ast*
115118
dec->setType(IntegralType::Ptr(new IntegralType(IntegralType::TypeMixed)));
116119
}
117120
else kDebug() << "Not updating existing declaration for " << node->value;
121+
// dec->setType<>();
118122
return dec;
119123
}
120124

125+
void DeclarationBuilder::visitExceptionHandler(ExceptionHandlerAst* node)
126+
{
127+
if ( node->name ) visitVariableDeclaration(node->name); // except Error as <vardecl>
128+
Python::AstDefaultVisitor::visitExceptionHandler(node);
129+
}
130+
121131
void DeclarationBuilder::visitFor(ForAst* node)
122132
{
123133
if ( node->target->astType == Ast::NameAstType ) visitVariableDeclaration(node->target);
@@ -131,10 +141,14 @@ void DeclarationBuilder::visitFor(ForAst* node)
131141

132142
void DeclarationBuilder::visitImport(ImportAst* node)
133143
{
134-
Python::AstDefaultVisitor::visitImport(node);
144+
Python::ContextBuilder::visitImport(node);
135145
foreach ( AliasAst* name, node->names ) {
146+
TopDUContextPointer contextptr = contextsForModules.value(name->asName ? name->asName->identifier->value : name->name->value);
147+
kDebug() << "Chain for document: " << contextptr;
148+
m_importContextsForImportStatement.push(contextptr);
136149
if ( name->asName ) visitVariableDeclaration(name->asName);
137150
else visitVariableDeclaration(name->name);
151+
m_importContextsForImportStatement.clear();
138152
}
139153
}
140154

@@ -230,6 +244,17 @@ void DeclarationBuilder::visitLambda( LambdaAst* node )
230244
// closeDeclaration();
231245
}
232246

247+
void DeclarationBuilder::visitCall(CallAst* node)
248+
{
249+
foreach ( ExpressionAst* currentArgument, node->arguments ) {
250+
NameAst* realArgument = dynamic_cast<NameAst*>(currentArgument);
251+
if ( realArgument ) {
252+
visitVariableDeclaration(realArgument); // some_func(<arg1>, <arg2>)
253+
}
254+
}
255+
Python::AstDefaultVisitor::visitCall(node);
256+
}
257+
233258
void DeclarationBuilder::visitArguments( ArgumentsAst* node )
234259
{
235260
AbstractFunctionDeclaration* function = dynamic_cast<AbstractFunctionDeclaration*>(currentDeclaration());

‎duchain/declarationbuilder.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
namespace Python
3434
{
35+
36+
typedef QPair<QString, TopDUContextPointer> moduleContextTuple;
3537

3638
typedef KDevelop::AbstractDeclarationBuilder<Ast, Identifier, TypeBuilder> DeclarationBuilderBase;
3739

@@ -53,10 +55,14 @@ class KDEVPYTHONDUCHAIN_EXPORT DeclarationBuilder: public DeclarationBuilderBase
5355
virtual void visitImport(ImportAst* node);
5456
virtual void visitImportFrom(ImportFromAst* node);
5557
virtual void visitArguments(ArgumentsAst* node);
58+
virtual void visitExceptionHandler(ExceptionHandlerAst* node);
59+
virtual void visitCall(CallAst* node);
5660

5761
Declaration* visitVariableDeclaration(Ast* node);
5862
Declaration* visitVariableDeclaration(Identifier* node, Ast* originalAst = 0);
5963

64+
QStack<TopDUContextPointer> m_importContextsForImportStatement;
65+
6066
// virtual void visitIdentifierTarget( IdentifierTargetAst * node );
6167

6268
private:

‎parser/ast.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class KDEVPYTHONPARSER_EXPORT Identifier : public Ast {
200200
class KDEVPYTHONPARSER_EXPORT CodeAst : public Ast {
201201
public:
202202
CodeAst();
203-
QList<StatementAst*> body;
203+
QList<Ast*> body;
204204
};
205205

206206
/** Statement classes **/

‎parser/astbuilder.cpp‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ AssignmentAst* AstBuilder::populateAssignmentAst(Ast* ast, const Python::stringD
431431
CodeAst* AstBuilder::populateCodeAst(Ast* ast, const Python::stringDictionary& currentAttributes)
432432
{
433433
CodeAst* currentNode = dynamic_cast<CodeAst*>(ast);
434-
currentNode->body = resolveNodeList<StatementAst>(currentAttributes.value("NRLST_body"));
434+
currentNode->body = resolveNodeList<Ast>(currentAttributes.value("NRLST_body"));
435435
return currentNode;
436436
}
437437

@@ -745,6 +745,13 @@ KeywordAst* AstBuilder::populateKeywordAst(Ast* ast, const Python::stringDiction
745745
return currentNode;
746746
}
747747

748+
ExpressionAst* AstBuilder::populateExpressionAst(Ast* ast, const stringDictionary& currentAttributes)
749+
{
750+
ExpressionAst* currentNode = dynamic_cast<ExpressionAst*>(ast);
751+
currentNode->value = resolveNode<ExpressionAst>(currentAttributes.value("NR_value"));
752+
return currentNode;
753+
}
754+
748755
void AstBuilder::populateAst()
749756
{
750757
Ast* currentAbstractNode;
@@ -829,7 +836,7 @@ void AstBuilder::populateAst()
829836
case Ast::ComprehensionAstType: currentAbstractNode = populateComprehensionAst(currentAbstractNode, currentAttributes); break;
830837
case Ast::ExceptionHandlerAstType: currentAbstractNode = populateExceptionHandlerAst(currentAbstractNode, currentAttributes); break;
831838
case Ast::AliasAstType: currentAbstractNode = populateAliasAst(currentAbstractNode, currentAttributes); break;
832-
case Ast::ExpressionAstType: break; // ok
839+
case Ast::ExpressionAstType: currentAbstractNode = populateExpressionAst(currentAbstractNode, currentAttributes); break;
833840
case Ast::StatementAstType: break; // ok
834841
default: kWarning() << "Unsupported AST type: " << currentAbstractNode->astType; break;
835842
}

‎parser/astbuilder.h‎

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)