callstack fixed, wrong file listed 26/21626/2
Cedric Delamarre [Fri, 20 Nov 2020 11:39:59 +0000 (12:39 +0100)]
Change-Id: I833d19cbfcee9db7dc25254120f92a2d905cd0d3

scilab/modules/ast/includes/system_env/configvariable.hxx
scilab/modules/ast/src/cpp/ast/debuggervisitor.cpp
scilab/modules/ast/src/cpp/ast/run_SeqExp.hpp
scilab/modules/ast/src/cpp/system_env/configvariable.cpp
scilab/modules/ast/src/cpp/types/macro.cpp
scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp

index 0380faf..4a20992 100644 (file)
@@ -485,10 +485,10 @@ public:
 
     // executed file with exec
 private:
-    static int m_iFileID;
+    static std::wstring m_strFile;
 public:
-    static void setExecutedFileID(int _iFileID);
-    static int getExecutedFileID();
+    static void setExecutedFile(const std::wstring& _strFile);
+    static const std::wstring& getExecutedFile();
 
     // string read from console by scilabRead
 private:
index 38438b1..fffeef8 100644 (file)
@@ -25,7 +25,6 @@
 
 extern "C"
 {
-#include "filemanager_interface.h"
 #include "FileExist.h"
 }
 
@@ -252,20 +251,22 @@ void DebuggerVisitor::visit(const SeqExp  &e)
             setExpectedSize(iExpectedSize);
             types::InternalType * pIT = getResult();
 
-            // In case of exec file, set the file name in the Macro to store where it is defined.
-            int iFileID = ConfigVariable::getExecutedFileID();
-            if (iFileID && exp->isFunctionDec())
+            if(exp->isFunctionDec())
             {
-                types::InternalType* pITMacro = symbol::Context::getInstance()->get(exp->getAs<ast::FunctionDec>()->getSymbol());
-                if (pITMacro)
+                // In case of exec file, set the file name in the Macro to store where it is defined.
+                std::wstring strFile = ConfigVariable::getExecutedFile();
+                const std::vector<ConfigVariable::WhereEntry>& lWhereAmI = ConfigVariable::getWhere();
+
+                if (strFile != L"" &&  // check if we are executing a script or a macro
+                    lWhereAmI.empty() == false &&
+                    lWhereAmI.back().m_file_name != nullptr && // check the last function execution is a macro
+                    *(lWhereAmI.back().m_file_name) == strFile) // check the last execution is the same macro as the executed one
                 {
-                    types::Macro* pMacro = pITMacro->getAs<types::Macro>();
-                    const wchar_t* filename = getfile_filename(iFileID);
-                    // scilab.quit is not open with mopen
-                    // in this case filename is NULL because FileManager have not been filled.
-                    if (filename)
+                    types::InternalType* pITMacro = symbol::Context::getInstance()->get(exp->getAs<FunctionDec>()->getSymbol());
+                    if (pITMacro)
                     {
-                        pMacro->setFileName(filename);
+                        types::Macro* pMacro = pITMacro->getAs<types::Macro>();
+                        pMacro->setFileName(strFile);
                     }
                 }
             }
index d650ecb..03dade1 100644 (file)
@@ -36,16 +36,12 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
     if (e.getExecFrom() == SeqExp::EXEC)
     {
         //open input file to print exp from it
-        int iFileID = ConfigVariable::getExecutedFileID();
-        if (iFileID)
+        std::wstring strFile = ConfigVariable::getExecutedFile();
+        if (strFile != L"")
         {
-            const wchar_t* filename = getfile_filename(iFileID);
-            if (filename)
-            {
-                char* cfilename = wide_string_to_UTF8(filename);
-                file = new std::ifstream(cfilename);
-                FREE(cfilename);
-            }
+            char* cfilename = wide_string_to_UTF8(strFile.data());
+            file = new std::ifstream(cfilename);
+            FREE(cfilename);
         }
     }
 
@@ -139,20 +135,22 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
             setExpectedSize(iExpectedSize);
             types::InternalType * pIT = getResult();
 
-            // In case of exec file, set the file name in the Macro to store where it is defined.
-            int iFileID = ConfigVariable::getExecutedFileID();
-            if (iFileID && (*it)->isFunctionDec())
+            if((*it)->isFunctionDec())
             {
-                types::InternalType* pITMacro = symbol::Context::getInstance()->get((*it)->getAs<FunctionDec>()->getSymbol());
-                if (pITMacro)
+                // In case of exec file, set the file name in the Macro to store where it is defined.
+                std::wstring strFile = ConfigVariable::getExecutedFile();
+                const std::vector<ConfigVariable::WhereEntry>& lWhereAmI = ConfigVariable::getWhere();
+
+                if (strFile != L"" &&  // check if we are executing a script or a macro
+                    lWhereAmI.empty() == false &&
+                    lWhereAmI.back().m_file_name != nullptr && // check the last function execution is a macro
+                    *(lWhereAmI.back().m_file_name) == strFile) // check the last execution is the same macro as the executed one
                 {
-                    types::Macro* pMacro = pITMacro->getAs<types::Macro>();
-                    const wchar_t* filename = getfile_filename(iFileID);
-                    // scilab.quit is not open with mopen
-                    // in this case filename is NULL because FileManager have not been filled.
-                    if (filename)
+                    types::InternalType* pITMacro = symbol::Context::getInstance()->get((*it)->getAs<FunctionDec>()->getSymbol());
+                    if (pITMacro)
                     {
-                        pMacro->setFileName(filename);
+                        types::Macro* pMacro = pITMacro->getAs<types::Macro>();
+                        pMacro->setFileName(strFile);
                     }
                 }
             }
index 7845243..bf83d4f 100644 (file)
@@ -1475,15 +1475,15 @@ std::string& ConfigVariable::getMexFunctionName()
 ** \}
 */
 // executed file with exec
-int ConfigVariable::m_iFileID = 0;
-void ConfigVariable::setExecutedFileID(int _iFileID)
+std::wstring ConfigVariable::m_strFile = L"";
+void ConfigVariable::setExecutedFile(const std::wstring& _strFile)
 {
-    m_iFileID = _iFileID;
+    m_strFile = _strFile;
 }
 
-int ConfigVariable::getExecutedFileID()
+const std::wstring& ConfigVariable::getExecutedFile()
 {
-    return m_iFileID;
+    return m_strFile;
 }
 
 /*
index 9b6599e..f845a3d 100644 (file)
@@ -27,6 +27,7 @@
 #include "scilabWrite.hxx"
 #include "configvariable.hxx"
 #include "serializervisitor.hxx"
+#include "filemanager.hxx"
 
 extern "C"
 {
@@ -331,21 +332,26 @@ Callable::ReturnValue Macro::call(typed_list &in, optional_list &opt, int _iRetC
 
     //save current prompt mode
     int oldVal = ConfigVariable::getPromptMode();
+    std::wstring iExecFile = ConfigVariable::getExecutedFile();
     std::unique_ptr<ast::ConstVisitor> exec (ConfigVariable::getDefaultVisitor());
     try
     {
+        ConfigVariable::setExecutedFile(m_stPath);
         ConfigVariable::setPromptMode(-1);
         m_body->accept(*exec);
         //restore previous prompt mode
         ConfigVariable::setPromptMode(oldVal);
+        ConfigVariable::setExecutedFile(iExecFile);
     }
     catch (const ast::InternalError& ie)
     {
+        ConfigVariable::setExecutedFile(iExecFile);
         cleanCall(pContext, oldVal);
         throw ie;
     }
     catch (const ast::InternalAbort& ia)
     {
+        ConfigVariable::setExecutedFile(iExecFile);
         cleanCall(pContext, oldVal);
         throw ia;
     }
index 15f9c6e..7d16abf 100644 (file)
@@ -233,7 +233,7 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
 
         ThreadManagement::UnlockParser();
 
-        ConfigVariable::setExecutedFileID(iID);
+        ConfigVariable::setExecutedFile(wstFile);
     }
     else if (in[0]->isMacro() || in[0]->isMacroFile())
     {
@@ -341,7 +341,7 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
         {
             closeFile(file, iID, wstFile, pExp);
             ConfigVariable::setPromptMode(oldVal);
-            ConfigVariable::setExecutedFileID(0);
+            ConfigVariable::setExecutedFile(L"");
             throw ie;
         }