where : value returned was inverted. 81/12681/6
Cedric Delamarre [Thu, 26 Sep 2013 13:58:01 +0000 (15:58 +0200)]
last call was not removed after pause/abort.

function fun()
    [a,b]=where();
    pause
endfunction

fun()
// then abort
[line, fun] = where()

test_run("elementary_functions","IsAScalar",["no_check_error_output" ]);
test_run("core","where",["no_check_error_output" ]);

// restart scilab and copy/past the unit test of where

Change-Id: I41da3fe77d339648f59b993afab5056941fabb4a

scilab/modules/ast/includes/run_CallExp.hxx
scilab/modules/ast/includes/runvisitor.hxx
scilab/modules/core/sci_gateway/cpp/sci_where.cpp
scilab/modules/core/src/cpp/runner.cpp
scilab/modules/system_env/includes/configvariable.hxx
scilab/modules/system_env/src/cpp/configvariable.cpp
scilab/modules/types/includes/callable.hxx
scilab/modules/types/includes/macrofile.hxx
scilab/modules/types/src/cpp/macro.cpp
scilab/modules/types/src/cpp/macrofile.cpp

index 516a333..2bf9de5 100644 (file)
@@ -121,7 +121,7 @@ void visitprivate(const CallExp &e)
             //update verbose";" flag
             ConfigVariable::setVerbose(e.is_verbose());
             // add line and function name in where
-            ConfigVariable::where_begin((int)e.location_get().first_line, pCall->getName());
+            ConfigVariable::where_begin(((int)e.location_get().first_line - ConfigVariable::getMacroFirstLines()) + 1, pCall->getName());
             //call function
             types::Function::ReturnValue Ret = pCall->call(in, opt, iRetCount, out, this);
             // remove the last call from where
index c7e8857..a833341 100644 (file)
@@ -1814,6 +1814,7 @@ public :
         //types::Macro macro(VarList, RetList, (SeqExp&)e.body_get());
         types::Macro *pMacro = new types::Macro(e.name_get().name_get(), *pVarList, *pRetList,
                                                 static_cast<SeqExp&>(*exp), L"script");
+        pMacro->setFirstLine(e.location_get().first_line);
         symbol::Context::getInstance()->AddMacro(pMacro);
     }
     /** \} */
index db0fbd1..9794e4d 100644 (file)
@@ -49,15 +49,15 @@ types::Function::ReturnValue sci_where(types::typed_list &in, int _iRetCount, ty
     types::String* pStrNames = new types::String(lWhereAmI.size() - 1, 1);
 
     it = lWhereAmI.begin();
-    pStrNames->set(0, it->second.c_str());
+    pDblLines->set(0, (double)it->first);
     it++;
     for (int i = 0; it != lWhereAmI.end(); it++, i++)
     {
-        pDblLines->set(i, (double)(it->first));
-        pStrNames->set(i + 1, it->second.c_str());
+        pDblLines->set(i + 1, (double)(it->first));
+        pStrNames->set(i, it->second.c_str());
     }
 
-    pDblLines->set(lWhereAmI.size() - 1, (double)(lWhereAmI.back().first));
+    pStrNames->set(lWhereAmI.size() - 1, lWhereAmI.front().second.c_str());
 
     out.push_back(pDblLines);
     out.push_back(pStrNames);
index 66ee878..5e55916 100644 (file)
@@ -39,6 +39,8 @@ void *Runner::launch(void *args)
     }
     catch (ScilabException se)
     {
+        // remove the last call from where in case pause/abort
+        ConfigVariable::where_end();
         scilabErrorW(se.GetErrorMessage().c_str());
     }
 
index f67dae1..2cbd80c 100644 (file)
@@ -347,11 +347,16 @@ public :
     // where
 private :
     static std::list< std::pair<int, std::wstring> > m_Where;
+    static std::list<int> m_FirstMacroLine;
 public :
     static void where_begin(int _iLineNum, std::wstring _wstName);
     static void where_end();
     static std::list< std::pair<int, std::wstring> >& getWhere();
 
+    static void macroFirstLine_begin(int _iLine);
+    static void macroFirstLine_end();
+    static int getMacroFirstLines();
+
     //module called with variable by reference
 private :
     static std::list<std::wstring> m_ReferenceModules;
@@ -360,7 +365,6 @@ public :
     static void addReferenceModule(std::wstring _module);
     static void removeReferenceModule(std::wstring _module);
     static std::list<std::wstring> getReferenceModules();
-
 };
 
 #endif /* !__CONFIGVARIABLE_HXX__ */
index 4adfd14..57f8199 100644 (file)
@@ -964,20 +964,45 @@ int ConfigVariable::getFuncprot()
 */
 
 std::list< std::pair<int, std::wstring> > ConfigVariable::m_Where;
-
+std::list<int> ConfigVariable::m_FirstMacroLine;
 void ConfigVariable::where_begin(int _iLineNum, std::wstring _wstName)
 {
-    m_Where.push_back(std::pair<int, std::wstring>(_iLineNum, _wstName));
+    m_Where.push_front(std::pair<int, std::wstring>(_iLineNum, _wstName));
 }
+
 void ConfigVariable::where_end()
 {
-    m_Where.pop_back();
+    if (m_Where.empty() == false)
+    {
+        m_Where.pop_front();
+    }
 }
+
 std::list< std::pair<int, std::wstring> >& ConfigVariable::getWhere()
 {
     return m_Where;
 }
 
+void ConfigVariable::macroFirstLine_begin(int _iLine)
+{
+    m_FirstMacroLine.push_back(_iLine);
+}
+
+void ConfigVariable::macroFirstLine_end()
+{
+    m_FirstMacroLine.pop_back();
+}
+
+int ConfigVariable::getMacroFirstLines()
+{
+    if (m_FirstMacroLine.empty())
+    {
+        return 1;
+    }
+
+    return m_FirstMacroLine.back();
+}
+
 /*
 ** \}
 */
index 8de14ab..9bd762a 100644 (file)
@@ -36,7 +36,10 @@ public :
         Error
     };
 
-    Callable(): InternalType() {}
+    Callable(): InternalType()
+    {
+        m_iFirstLine = 0;
+    }
     virtual             ~Callable() {}
 
     bool                isCallable()
@@ -87,9 +90,20 @@ public :
         return -1;
     }
 
+    virtual int        getFirstLine(void)
+    {
+        return m_iFirstLine;
+    }
+
+    virtual void       setFirstLine(int _iFirstLine)
+    {
+        m_iFirstLine = _iFirstLine;
+    }
+
 protected :
     std::wstring           m_wstName;
     std::wstring           m_wstModule;
+    int                    m_iFirstLine;
 };
 }
 
index c9ddb38..7909095 100644 (file)
@@ -42,11 +42,9 @@ public :
     Callable::ReturnValue   call(typed_list &in, optional_list &opt, int _iRetCount, typed_list &out, ast::ConstVisitor* execFunc);
     bool                    parse(void);
 
-    Macro*                  getMacro(void)
-    {
-        parse();
-        return m_pMacro;
-    }
+    Macro*                  getMacro(void);
+
+    void                    setFirstLine(int _iLine);
 
     /* return type as string ( double, int, cell, list, ... )*/
     virtual wstring         getTypeStr()
index 77871f3..c1ff8a0 100644 (file)
@@ -86,6 +86,8 @@ Callable::ReturnValue Macro::call(typed_list &in, optional_list &opt, int _iRetC
 
     //open a new scope
     pContext->scope_begin();
+    //store the line number where is stored this macro in file.
+    ConfigVariable::macroFirstLine_begin(getFirstLine());
 
     //add optional paramter in current scope
     optional_list::const_iterator it;
@@ -149,6 +151,7 @@ Callable::ReturnValue Macro::call(typed_list &in, optional_list &opt, int _iRetC
         Scierror(58, _("Wrong number of input arguments."));
         sciprint("%s", pst);
         pContext->scope_end();
+        ConfigVariable::macroFirstLine_end();
         return Callable::Error;
     }
     else
@@ -263,6 +266,7 @@ Callable::ReturnValue Macro::call(typed_list &in, optional_list &opt, int _iRetC
         ConfigVariable::setPromptMode(oldVal);
         //close the current scope
         pContext->scope_end();
+        ConfigVariable::macroFirstLine_end();
         for (size_t j = 0; j < out.size(); ++j)
         {
             out[j]->DecreaseRef();
@@ -275,6 +279,7 @@ Callable::ReturnValue Macro::call(typed_list &in, optional_list &opt, int _iRetC
         ConfigVariable::setPromptMode(oldVal);
         //close the current scope
         pContext->scope_end();
+        ConfigVariable::macroFirstLine_end();
         for (size_t j = 0; j < out.size(); ++j)
         {
             out[j]->DecreaseRef();
@@ -284,6 +289,7 @@ Callable::ReturnValue Macro::call(typed_list &in, optional_list &opt, int _iRetC
 
     //close the current scope
     pContext->scope_end();
+    ConfigVariable::macroFirstLine_end();
 
     for (size_t j = 0; j < out.size(); ++j)
     {
index dcfeb51..c0eb89f 100644 (file)
@@ -131,6 +131,7 @@ bool MacroFile::parse(void)
                         //types::Macro *pMacro = new types::Macro(m_stName, *pVarList, *pRetList, (SeqExp&)e.body_get());
 
                         pMacro->m_pMacro = new Macro(m_wstName, *pVarList, *pRetList, (SeqExp&)pFD->body_get(), m_wstModule);
+                        pMacro->setFirstLine(pFD->location_get().first_line);
                     }
                 }
             }
@@ -149,4 +150,14 @@ int MacroFile::getNbOutputArgument(void)
     return getMacro()->getNbOutputArgument();
 }
 
+Macro* MacroFile::getMacro(void)
+{
+    parse();
+    return m_pMacro;
+}
+
+void MacroFile::setFirstLine(int _iLine)
+{
+    getMacro()->setFirstLine(_iLine);
+}
 }