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

List:       kde-commits
Subject:    [kdev-go] duchain: Import anonymous function arguments into body context.
From:       Pavel Petrushkov <onehundredof () gmail ! com>
Date:       2014-09-30 19:59:23
Message-ID: E1XZ3Zz-0000tY-24 () scm ! kde ! org
[Download RAW message or body]

Git commit 6bfad90ef106eb2ba42530df19a09ef4b37fadb5 by Pavel Petrushkov.
Committed on 30/09/2014 at 23:46.
Pushed by pavelp into branch 'master'.

Import anonymous function arguments into body context.

M  +22   -0    duchain/builders/typebuilder.cpp
M  +1    -1    duchain/builders/typebuilder.h
M  +5    -12   duchain/expressionvisitor.cpp
M  +0    -1    duchain/expressionvisitor.h
M  +1    -0    duchain/tests/testduchain.cpp

http://commits.kde.org/kdev-go/6bfad90ef106eb2ba42530df19a09ef4b37fadb5

diff --git a/duchain/builders/typebuilder.cpp b/duchain/builders/typebuilder.cpp
index 1008f88..1d4a9e6 100644
--- a/duchain/builders/typebuilder.cpp
+++ b/duchain/builders/typebuilder.cpp
@@ -429,4 +429,26 @@ void TypeBuilder::addArgumentHelper(go::GoFunctionType::Ptr \
function, AbstractTy  }
 }
 
+//TODO call this from DeclarationBuilder::visitFunctionDecl
+void TypeBuilder::buildFunction(SignatureAst* node, BlockAst* block)
+{
+    go::GoFunctionDeclaration* decl = parseSignature(node, true);
+    AbstractType::Ptr type = lastType();
+    if(block)
+    {
+        DUContext* bodyContext = openContext(block, \
DUContext::ContextType::Function); +        {//import parameters into body context
+            DUChainWriteLocker lock;
+            if(decl->internalContext())
+                currentContext()->addImportedParentContext(decl->internalContext());
+            if(decl->returnArgsContext())
+                currentContext()->addImportedParentContext(decl->returnArgsContext());
 +        }
+        visitBlock(block);
+        closeContext(); //wrapper context
+        injectType(type);
+    }
+}
+
+
 }
\ No newline at end of file
diff --git a/duchain/builders/typebuilder.h b/duchain/builders/typebuilder.h
index 1c03729..4074760 100644
--- a/duchain/builders/typebuilder.h
+++ b/duchain/builders/typebuilder.h
@@ -54,7 +54,7 @@ public:
     /**
      * A shortcut for ExpressionVisitor to build function type
      **/
-    void buildFunction(go::SignatureAst* node) { parseSignature(node, true); }
+    void buildFunction(go::SignatureAst* node, go::BlockAst* block=0);
 
     /**
      * Used by external classes like ExpressionVisitor after building a type.
diff --git a/duchain/expressionvisitor.cpp b/duchain/expressionvisitor.cpp
index 2cc9ba9..d54d31a 100644
--- a/duchain/expressionvisitor.cpp
+++ b/duchain/expressionvisitor.cpp
@@ -390,15 +390,6 @@ void ExpressionVisitor::visitMapType(MapTypeAst* node)
     }
 }
 
-void ExpressionVisitor::visitSignature(SignatureAst* node)
-{
-    if(m_builder)
-    {
-        m_builder->buildFunction(node);
-        pushType(m_builder->getLastType());
-    }
-}
-
 void ExpressionVisitor::visitPointerType(PointerTypeAst* node)
 {
     if(m_builder)
@@ -453,9 +444,11 @@ void \
ExpressionVisitor::handleLiteralsAndConversions(PrimaryExprAst* node)  \
visitMapType(node->mapType);  else if(node->signature)
     {
-        if(node->body && m_builder)
-            m_builder->visitBlock(node->body);
-        visitSignature(node->signature);
+        if(m_builder)
+        {
+            m_builder->buildFunction(node->signature, node->body);
+            pushType(m_builder->getLastType());
+        }
     }
     else if(node->pointerType)
         visitPointerType(node->pointerType);
diff --git a/duchain/expressionvisitor.h b/duchain/expressionvisitor.h
index ddfdf21..a765aa5 100644
--- a/duchain/expressionvisitor.h
+++ b/duchain/expressionvisitor.h
@@ -44,7 +44,6 @@ public:
     virtual void visitTypeName(go::TypeNameAst* node);
     virtual void visitStructType(go::StructTypeAst* node);
     virtual void visitMapType(go::MapTypeAst* node);
-    virtual void visitSignature(go::SignatureAst* node);
     virtual void visitPointerType(go::PointerTypeAst* node);
     virtual void visitInterfaceType(go::InterfaceTypeAst* node);
     virtual void visitChanType(go::ChanTypeAst* node);
diff --git a/duchain/tests/testduchain.cpp b/duchain/tests/testduchain.cpp
index 784de24..e171611 100644
--- a/duchain/tests/testduchain.cpp
+++ b/duchain/tests/testduchain.cpp
@@ -477,6 +477,7 @@ void TestDuchain::test_literals_data()
     QTest::newRow("map type conversion access") << "(map[int]rune)(f)[0]" << "rune";
     QTest::newRow("func type literal") << "func() int { return 0; }" << "function () \
                int";
     QTest::newRow("func type literal 2") << "func(a, b mytype) (b bool) { c := 2; \
return true; }" << "function (main::mytype, main::mytype) bool"; +    \
QTest::newRow("func type literal 3") << "func() int { var b int; }" << "function () \
                int";
     QTest::newRow("func type conversion") << "(func())(main) " << "function () ";
     QTest::newRow("func type conversion 2") << "func() (i int)(main) " << "function \
                () int";
     QTest::newRow("func type call") << "func(f []int) float64 {} ( []int{1, 2} )" << \
"float64";


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

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