[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdev-ruby] duchain/builders: Fixing weird issues when declaring classes
From:       Miquel_Sabaté <mikisabate () gmail ! com>
Date:       2012-02-29 22:34:07
Message-ID: 20120229223407.4CC48A60A9 () git ! kde ! org
[Download RAW message or body]

Git commit b89baa1c17d2d35bf07b31899b911a7cf9a1616e by Miquel Sabaté.
Committed on 29/02/2012 at 22:38.
Pushed by mssola into branch 'master'.

Fixing weird issues when declaring classes

M  +6    -9    duchain/builders/contextbuilder.cpp
M  +26   -5    duchain/builders/declarationbuilder.cpp

http://commits.kde.org/kdev-ruby/b89baa1c17d2d35bf07b31899b911a7cf9a1616e

diff --git a/duchain/builders/contextbuilder.cpp b/duchain/builders/contextbuilder.cpp
index 679c2f7..e892149 100644
--- a/duchain/builders/contextbuilder.cpp
+++ b/duchain/builders/contextbuilder.cpp
@@ -159,10 +159,8 @@ void ContextBuilder::visitModuleStatement(RubyAst *node)
 // TODO : what about singleton classes?
 void ContextBuilder::visitClassStatement(RubyAst *node)
 {
-    openContextForClassDefinition(node);
-    RubyAstVisitor::visitClassStatement(node);
-    closeContext();
-    debug() << "Closing class: " << getName(node);
+    node->tree = node->tree->l;
+    visitBody(node);
 }
 
 void ContextBuilder::visitMethodStatement(RubyAst *node)
@@ -217,14 +215,13 @@ void ContextBuilder::addImportedContexts()
 
 void ContextBuilder::openContextForClassDefinition(RubyAst *node)
 {
+    DUChainWriteLocker wlock(DUChain::lock());
     RangeInRevision range = editorFindRange(node, node);
     KDevelop::QualifiedIdentifier className(getName(node));
 
-    {
-        DUChainWriteLocker wlock(DUChain::lock());
-        openContext(node, range, DUContext::Class, className);
-        currentContext()->setLocalScopeIdentifier(className);
-    }
+    openContext(node, range, DUContext::Class, className);
+    currentContext()->setLocalScopeIdentifier(className);
+    wlock.unlock();
     addImportedContexts();
 }
 
diff --git a/duchain/builders/declarationbuilder.cpp b/duchain/builders/declarationbuilder.cpp
index 18c5b0d..24750d0 100644
--- a/duchain/builders/declarationbuilder.cpp
+++ b/duchain/builders/declarationbuilder.cpp
@@ -66,14 +66,35 @@ void DeclarationBuilder::startVisiting(RubyAst* node)
 
 void DeclarationBuilder::visitClassStatement(RubyAst *node)
 {
+    DUChainWriteLocker lock(DUChain::lock());
+    RangeInRevision range = getNameRange(node);
+    QualifiedIdentifier id = identifierForNode(new NameAst(node));
+
     setComment(getComment(node));
-    openClassDeclaration(node, true);
-    RubyAstVisitor::visitClassStatement(node);
+    ClassDeclaration *decl = openDeclaration<ClassDeclaration>(id, range);
+    decl->setKind(KDevelop::Declaration::Type);
+    decl->clearBaseClasses();
+    decl->setClassType(ClassDeclarationData::Class);
 
-    {
-        DUChainWriteLocker wlock(DUChain::lock());
-        closeContext();
+    Node *aux = node->tree;
+    node->tree = node->tree->cond;
+    if (node->tree) {
+        /* TODO: base class */
     }
+    node->tree = aux;
+
+    StructureType::Ptr type = StructureType::Ptr(new StructureType());
+    type->setDeclaration(decl);
+    decl->setType(type);
+    openType(type);
+
+    openContextForClassDefinition(node);
+    decl->setInternalContext(currentContext());
+    lock.unlock();
+    DeclarationBuilderBase::visitClassStatement(node);
+    lock.lock();
+    closeContext();
+
     closeType();
     closeDeclaration();
 }

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic