Fixed various bugs. Can now start to implement population functions · scummos/kdevelop-python@27b03c0 · GitHub
Skip to content

Commit 27b03c0

Browse files
committed
Fixed various bugs. Can now start to implement population functions
1 parent 6487af3 commit 27b03c0

13 files changed

Lines changed: 267 additions & 166 deletions

‎duchain/contextbuilder.cpp‎

Lines changed: 33 additions & 34 deletions

‎duchain/contextbuilder.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Python
4040
class PythonEditorIntegrator;
4141
class ParseSession;
4242

43-
typedef KDevelop::AbstractContextBuilder<Ast, IdentifierAst> ContextBuilderBase;
43+
typedef KDevelop::AbstractContextBuilder<Ast, Identifier> ContextBuilderBase;
4444

4545
class KDEVPYTHONDUCHAIN_EXPORT ContextBuilder: public ContextBuilderBase, public Python::AstDefaultVisitor
4646
{
@@ -55,7 +55,7 @@ class KDEVPYTHONDUCHAIN_EXPORT ContextBuilder: public ContextBuilderBase, public
5555
virtual void setContextOnNode( Ast* node, KDevelop::DUContext* context );
5656
virtual KDevelop::DUContext* contextFromNode( Ast* node );
5757
virtual KDevelop::RangeInRevision editorFindRange( Ast* fromNode, Ast* toNode );
58-
virtual KDevelop::QualifiedIdentifier identifierForNode( IdentifierAst* node );
58+
virtual KDevelop::QualifiedIdentifier identifierForNode( Identifier* node );
5959

6060
void addImportedContexts();
6161

@@ -65,7 +65,6 @@ class KDEVPYTHONDUCHAIN_EXPORT ContextBuilder: public ContextBuilderBase, public
6565
virtual void visitWith( WithAst* node );
6666
virtual void visitWhile( WhileAst* node );
6767
virtual void visitIf( IfAst* node );
68-
virtual void visitTry( TryAst* node );
6968

7069
PythonEditorIntegrator *m_editor;
7170

‎duchain/declarationbuilder.cpp‎

Lines changed: 67 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,6 @@ DeclarationBuilder:: ~DeclarationBuilder()
6767
{
6868
}
6969

70-
// This is not used anywhere and causes build errors, so... bye.
71-
/*
72-
template<class DeclarationType>
73-
DeclarationType* DeclarationBuilder::specialDeclaration( KTextEditor::SmartRange* smartRange,
74-
const KDevelop::SimpleRange& range )
75-
{
76-
DeclarationType* ret = new DeclarationType( m_editor->currentUrl(), range, currentContext() );
77-
ret->setSmartRange( smartRange );
78-
return ret;
79-
}
80-
81-
template<class DeclarationType>
82-
DeclarationType* DeclarationBuilder::specialDeclaration( KTextEditor::SmartRange* smartRange,
83-
const KDevelop::SimpleRange& range,
84-
int scope )
85-
{
86-
DeclarationType* ret = new DeclarationType( m_editor->currentUrl(), range, currentContext() );
87-
ret->setSmartRange( smartRange );
88-
return ret;
89-
}
90-
*/
91-
9270
void DeclarationBuilder::closeDeclaration()
9371
{
9472
if ( lastContext() )
@@ -102,47 +80,47 @@ void DeclarationBuilder::closeDeclaration()
10280
DeclarationBuilderBase::closeDeclaration();
10381
}
10482

105-
void DeclarationBuilder::visitIdentifierTarget(IdentifierTargetAst* node)
106-
{
107-
Python::AstDefaultVisitor::visitIdentifierTarget(node);
108-
109-
QList<Declaration*> existingLocalDeclarations;
110-
111-
{
112-
DUChainWriteLocker lock( DUChain::lock() );
113-
RangeInRevision range = editorFindRange(node, node);
114-
CursorInRevision stopSearching = range.start;
115-
QualifiedIdentifier id = identifierForNode(node->identifier);
116-
existingLocalDeclarations = currentContext()->findLocalDeclarations(id.last(), stopSearching);
117-
}
118-
119-
if ( ! existingLocalDeclarations.length() ) {
120-
Declaration *dec = openDeclaration<Declaration>( node->identifier, node);
121-
closeDeclaration();
122-
{
123-
DUChainWriteLocker lock(DUChain::lock());
124-
dec->setType(IntegralType::Ptr(new IntegralType(IntegralType::TypeMixed)));
125-
}
126-
}
127-
else {
128-
kDebug() << "Declaration does already exist, not updating" << node->identifier->identifier.toAscii();
129-
}
130-
}
83+
// void DeclarationBuilder::visitIdentifierTarget(IdentifierTargetAst* node)
84+
// {
85+
// Python::AstDefaultVisitor::visitIdentifierTarget(node);
86+
//
87+
// QList<Declaration*> existingLocalDeclarations;
88+
//
89+
// {
90+
// DUChainWriteLocker lock( DUChain::lock() );
91+
// RangeInRevision range = editorFindRange(node, node);
92+
// CursorInRevision stopSearching = range.start;
93+
// QualifiedIdentifier id = identifierForNode(node->identifier);
94+
// existingLocalDeclarations = currentContext()->findLocalDeclarations(id.last(), stopSearching);
95+
// }
96+
//
97+
// if ( ! existingLocalDeclarations.length() ) {
98+
// Declaration *dec = openDeclaration<Declaration>( node->identifier, node);
99+
// closeDeclaration();
100+
// {
101+
// DUChainWriteLocker lock(DUChain::lock());
102+
// dec->setType(IntegralType::Ptr(new IntegralType(IntegralType::TypeMixed)));
103+
// }
104+
// }
105+
// else {
106+
// kDebug() << "Declaration does already exist, not updating" << node->identifier->identifier.toAscii();
107+
// }
108+
// }
131109

132110

133111
void DeclarationBuilder::visitClassDefinition( ClassDefinitionAst* node )
134112
{
135113
kDebug() << "opening class definition";
136114
ContextBuilder::visitClassDefinition( node );
137-
openDeclaration<Declaration>( node->className, node );
115+
openDeclaration<Declaration>( node->name, node );
138116
eventuallyAssignInternalContext();
139117
closeDeclaration();
140118
}
141119

142120
void DeclarationBuilder::visitFunctionDefinition( FunctionDefinitionAst* node )
143121
{
144122
kDebug() << "opening function definition";
145-
FunctionDeclaration* dec = openDeclaration<FunctionDeclaration>( node->functionName, node );
123+
FunctionDeclaration* dec = openDeclaration<FunctionDeclaration>( node->name, node );
146124

147125
FunctionType::Ptr type(new FunctionType);
148126

@@ -165,45 +143,46 @@ void DeclarationBuilder::visitLambda( LambdaAst* node )
165143
// closeDeclaration();
166144
}
167145

168-
void DeclarationBuilder::visitDefaultParameter( DefaultParameterAst* node )
146+
void DeclarationBuilder::visitArguments( ArgumentsAst* node )
169147
{
170-
ContextBuilder::visitDefaultParameter( node );
171-
// AbstractFunctionDeclaration* function = currentDeclaration<AbstractFunctionDeclaration>();
172-
AbstractFunctionDeclaration* function = dynamic_cast<AbstractFunctionDeclaration*>(currentDeclaration());
173-
174-
if( function )
175-
{
176-
if( node->value )
177-
{
178-
//Not sure what to do here, C++ simply adds the source code as default parameter, but that doesn't sound sane...
179-
}
180-
//simple case, we have an identifier parameter
181-
if( node->name->astType == Ast::IdentifierParameterPartAst )
182-
{
183-
function->addDefaultParameter(IndexedString("foo"));
184-
kDebug() << function->defaultParametersSize();
185-
186-
Q_ASSERT(hasCurrentType());
187-
FunctionType::Ptr type = currentType<FunctionType>();
188-
Q_ASSERT(type);
189-
190-
kDebug() << type->toString();
191-
192-
// create a variable definition
193-
IdentifierParameterPartAst* identifierNode = dynamic_cast<IdentifierParameterPartAst*>(node->name);
194-
Declaration* dec = openDeclaration<Declaration>( identifierNode->name, node);
195-
{
196-
DUChainWriteLocker lock(DUChain::lock());
197-
dec->setType(IntegralType::Ptr(new IntegralType(IntegralType::TypeMixed)));
198-
type->addArgument(dec->abstractType());
199-
}
200-
closeDeclaration();
201-
202-
} else if( node->name->astType == Ast::ListParameterPartAst )
203-
{
204-
//complex case, a sublist, what to do??
205-
}
206-
}
148+
AstDefaultVisitor::visitArguments(node);
149+
// ContextBuilder::visitDefaultParameter( node );
150+
// // AbstractFunctionDeclaration* function = currentDeclaration<AbstractFunctionDeclaration>();
151+
// AbstractFunctionDeclaration* function = dynamic_cast<AbstractFunctionDeclaration*>(currentDeclaration());
152+
//
153+
// if( function )
154+
// {
155+
// if( node->value )
156+
// {
157+
// //Not sure what to do here, C++ simply adds the source code as default parameter, but that doesn't sound sane...
158+
// }
159+
// //simple case, we have an identifier parameter
160+
// if( node->name->astType == Ast::IdentifierParameterPartAst )
161+
// {
162+
// function->addDefaultParameter(IndexedString("foo"));
163+
// kDebug() << function->defaultParametersSize();
164+
//
165+
// Q_ASSERT(hasCurrentType());
166+
// FunctionType::Ptr type = currentType<FunctionType>();
167+
// Q_ASSERT(type);
168+
//
169+
// kDebug() << type->toString();
170+
//
171+
// // create a variable definition
172+
// IdentifierParameterPartAst* identifierNode = dynamic_cast<IdentifierParameterPartAst*>(node->name);
173+
// Declaration* dec = openDeclaration<Declaration>( identifierNode->name, node);
174+
// {
175+
// DUChainWriteLocker lock(DUChain::lock());
176+
// dec->setType(IntegralType::Ptr(new IntegralType(IntegralType::TypeMixed)));
177+
// type->addArgument(dec->abstractType());
178+
// }
179+
// closeDeclaration();
180+
//
181+
// } else if( node->name->astType == Ast::ListParameterPartAst )
182+
// {
183+
// //complex case, a sublist, what to do??
184+
// }
185+
// }
207186
}
208187

209188
}

‎duchain/declarationbuilder.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
namespace Python
3434
{
3535

36-
typedef KDevelop::AbstractDeclarationBuilder<Ast, IdentifierAst, TypeBuilder> DeclarationBuilderBase;
36+
typedef KDevelop::AbstractDeclarationBuilder<Ast, Identifier, TypeBuilder> DeclarationBuilderBase;
3737

3838
class KDEVPYTHONDUCHAIN_EXPORT DeclarationBuilder: public DeclarationBuilderBase
3939
{
@@ -47,10 +47,10 @@ class KDEVPYTHONDUCHAIN_EXPORT DeclarationBuilder: public DeclarationBuilderBase
4747

4848
virtual void visitClassDefinition( ClassDefinitionAst* node );
4949
virtual void visitFunctionDefinition( FunctionDefinitionAst* node );
50-
virtual void visitDefaultParameter( DefaultParameterAst* node );
50+
virtual void visitArguments( ArgumentsAst* node );
5151
virtual void visitLambda( LambdaAst* node );
5252

53-
virtual void visitIdentifierTarget( IdentifierTargetAst * node );
53+
// virtual void visitIdentifierTarget( IdentifierTargetAst * node );
5454

5555
private:
5656
/*

‎duchain/typebuilder.h‎

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)