fix putInPreviousScope on libraries 98/16498/1
Antoine ELIAS [Wed, 20 May 2015 13:52:39 +0000 (15:52 +0200)]
Change-Id: I986c737e90b212c3912314ecadc23972f630cdf5

scilab/modules/ast/includes/symbol/libraries.hxx
scilab/modules/ast/src/cpp/symbol/context.cpp

index b2a2e5f..adcf868 100644 (file)
@@ -61,6 +61,11 @@ struct Library
         }
     }
 
+    void put(ScopedLibrary* pSL)
+    {
+        stack.push(pSL);
+    }
+
     types::MacroFile* get(const Symbol& _keyMacro) const
     {
         if (empty() == false)
@@ -133,6 +138,31 @@ struct Libraries
         lib->put(_pLib, _iLevel);
     }
 
+    bool putInPreviousScope(const Symbol& _keyLib, types::Library* _pLib, int _iLevel)
+    {
+        Library* lib = getOrCreate(_keyLib);
+
+        if (lib->empty())
+        {
+            lib->put(_pLib, _iLevel);
+        }
+        else if (lib->top()->m_iLevel > _iLevel)
+        {
+            ScopedLibrary* pLib = lib->top();
+            lib->pop();
+            putInPreviousScope(_keyLib, _pLib, _iLevel);
+            //decresef ref before, increase it in put
+            //pVar->m_pIT->DecreaseRef();
+            lib->put(pLib->m_pLib, pLib->m_iLevel);
+        }
+        else
+        {
+            lib->put(_pLib, _iLevel);
+        }
+
+        return true;
+    }
+
     types::InternalType* get(const Symbol& _key, int _iLevel)
     {
         //does _key is a lib name
index cccb7ab..c71f742 100644 (file)
@@ -319,6 +319,11 @@ bool Context::putInPreviousScope(Variable* _var, types::InternalType* _pIT)
         }
         varStack.push(list);
     }
+
+    if (_pIT->isLibrary())
+    {
+        libraries.putInPreviousScope(_var->getSymbol(), _pIT->getAs<types::Library>(), m_iLevel - 1);
+    }
     return true;
 }