callstack fixed, wrong file listed
[scilab.git] / scilab / modules / ast / src / cpp / ast / run_SeqExp.hpp
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);
                     }
                 }
             }