From: Antoine ELIAS Date: Wed, 20 May 2015 13:52:39 +0000 (+0200) Subject: fix putInPreviousScope on libraries X-Git-Tag: 6.0.0-alpha-1~258 X-Git-Url: http://gitweb.scilab.org/?p=scilab.git;a=commitdiff_plain;h=c9c25e8c365670ff0ed846041bc176c8ec85ab1e fix putInPreviousScope on libraries Change-Id: I986c737e90b212c3912314ecadc23972f630cdf5 --- diff --git a/scilab/modules/ast/includes/symbol/libraries.hxx b/scilab/modules/ast/includes/symbol/libraries.hxx index b2a2e5f..adcf868 100644 --- a/scilab/modules/ast/includes/symbol/libraries.hxx +++ b/scilab/modules/ast/includes/symbol/libraries.hxx @@ -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 diff --git a/scilab/modules/ast/src/cpp/symbol/context.cpp b/scilab/modules/ast/src/cpp/symbol/context.cpp index cccb7ab..c71f742 100644 --- a/scilab/modules/ast/src/cpp/symbol/context.cpp +++ b/scilab/modules/ast/src/cpp/symbol/context.cpp @@ -319,6 +319,11 @@ bool Context::putInPreviousScope(Variable* _var, types::InternalType* _pIT) } varStack.push(list); } + + if (_pIT->isLibrary()) + { + libraries.putInPreviousScope(_var->getSymbol(), _pIT->getAs(), m_iLevel - 1); + } return true; }