Refactoring of ScilabException in AST, exec, execstr. 62/3662/1
Antoine ELIAS [Mon, 28 Mar 2011 13:50:31 +0000 (15:50 +0200)]
Add call to %onprompt function when scilab return to prompt.
Add YaspError(W) function to print error instead of YaspWrite(W).

Change-Id: I3603b0cf67f3f4e240e3235336a8ffef3c4e80a3

24 files changed:
scilab/modules/abstractSyntaxTree/Localization_Import.def [new file with mode: 0644]
scilab/modules/abstractSyntaxTree/abstractSyntaxTree-tools.vcproj
scilab/modules/abstractSyntaxTree/abstractSyntaxTree.vcproj
scilab/modules/abstractSyntaxTree/includes/run_CallExp.hxx
scilab/modules/abstractSyntaxTree/includes/run_OpExp.hxx
scilab/modules/abstractSyntaxTree/includes/runvisitor.hxx
scilab/modules/abstractSyntaxTree/includes/scilabexception.hxx
scilab/modules/abstractSyntaxTree/includes/visitor_common.hxx
scilab/modules/abstractSyntaxTree/src/cpp/scilabexception.cpp
scilab/modules/abstractSyntaxTree/src/cpp/visitor_common.cpp
scilab/modules/api_scilab/src/cpp/overload.cpp
scilab/modules/core/src/cpp/runner.cpp
scilab/modules/core/src/cpp/scilab.cpp
scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp
scilab/modules/functions/sci_gateway/cpp/sci_execstr.cpp
scilab/modules/output_stream/includes/yaspio.hxx
scilab/modules/output_stream/src/c/System_env_Import.def
scilab/modules/output_stream/src/c/output_stream.vcproj
scilab/modules/output_stream/src/cpp/yaspio.cpp
scilab/modules/system_env/includes/configvariable.hxx
scilab/modules/system_env/includes/promptmode.h
scilab/modules/system_env/src/cpp/configvariable.cpp
scilab/modules/system_env/src/cpp/promptmode.cpp
scilab/modules/types/src/cpp/macro.cpp

diff --git a/scilab/modules/abstractSyntaxTree/Localization_Import.def b/scilab/modules/abstractSyntaxTree/Localization_Import.def
new file mode 100644 (file)
index 0000000..2d46c9a
--- /dev/null
@@ -0,0 +1,6 @@
+LIBRARY    scilocalization.dll
+
+
+EXPORTS
+to_wide_string
+
index 473f8bb..5982878 100644 (file)
                        />
                        <Tool
                                Name="VCPreLinkEventTool"
+                               CommandLine="lib /DEF:&quot;$(InputDir)Localization_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X64 /OUT:&quot;$(InputDir)scilocalization.lib&quot; 1&gt;NUL 2&gt;NUL"
                        />
                        <Tool
                                Name="VCLinkerTool"
+                               AdditionalDependencies="scilocalization.lib"
                                OutputFile="&quot;$(SolutionDir)bin\$(ProjectName).dll&quot;"
                                GenerateDebugInformation="true"
                                ImportLibrary="../../bin/$(ProjectName).lib"
                        UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
                        >
                </Filter>
+               <Filter
+                       Name="Libraries Dependencies"
+                       >
+                       <File
+                               RelativePath=".\Localization_Import.def"
+                               >
+                       </File>
+               </Filter>
                <File
                        RelativePath="..\..\bin\blasplus.lib"
                        >
index 9ab0aa8..f3255a2 100644 (file)
@@ -44,7 +44,7 @@
                        <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
-                               AdditionalIncludeDirectories="includes;..\symbol\includes;..\types\includes;..\functions_manager\includes;../core/includes;..\elementary_functions\includes;../operations/includes;../localization/includes;../../libs/intl;../output_stream/includes;../system_env/includes;../string/includes"
+                               AdditionalIncludeDirectories="includes;..\symbol\includes;..\types\includes;..\functions_manager\includes;../core/includes;..\elementary_functions\includes;../operations/includes;../localization/includes;../../libs/intl;../output_stream/includes;../system_env/includes;../string/includes;../api_scilab/includes"
                                PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;AST_EXPORTS"
                                MinimalRebuild="true"
                                BasicRuntimeChecks="3"
                        <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
-                               AdditionalIncludeDirectories="includes;..\symbol\includes;..\types\includes;..\functions_manager\includes;../core/includes;..\elementary_functions\includes;../operations/includes;../localization/includes;../../libs/intl;../output_stream/includes;../system_env/includes;../string/includes"
+                               AdditionalIncludeDirectories="includes;..\symbol\includes;..\types\includes;..\functions_manager\includes;../core/includes;..\elementary_functions\includes;../operations/includes;../localization/includes;../../libs/intl;../output_stream/includes;../system_env/includes;../string/includes;../api_scilab/includes"
                                PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;AST_EXPORTS"
                                MinimalRebuild="true"
                                BasicRuntimeChecks="3"
                                Name="VCCLCompilerTool"
                                Optimization="2"
                                EnableIntrinsicFunctions="true"
-                               AdditionalIncludeDirectories="includes;..\symbol\includes;..\types\includes;..\functions_manager\includes;../core/includes;..\elementary_functions\includes;../operations/includes;../localization/includes;../../libs/intl;../output_stream/includes;../system_env/includes;../string/includes"
+                               AdditionalIncludeDirectories="includes;..\symbol\includes;..\types\includes;..\functions_manager\includes;../core/includes;..\elementary_functions\includes;../operations/includes;../localization/includes;../../libs/intl;../output_stream/includes;../system_env/includes;../string/includes;../api_scilab/includes"
                                PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;AST_EXPORTS"
                                RuntimeLibrary="2"
                                EnableFunctionLevelLinking="true"
                                Name="VCCLCompilerTool"
                                Optimization="2"
                                EnableIntrinsicFunctions="true"
-                               AdditionalIncludeDirectories="includes;..\symbol\includes;..\types\includes;..\functions_manager\includes;../core/includes;..\elementary_functions\includes;../operations/includes;../localization/includes;../../libs/intl;../output_stream/includes;../system_env/includes;../string/includes"
+                               AdditionalIncludeDirectories="includes;..\symbol\includes;..\types\includes;..\functions_manager\includes;../core/includes;..\elementary_functions\includes;../operations/includes;../localization/includes;../../libs/intl;../output_stream/includes;../system_env/includes;../string/includes;../api_scilab/includes"
                                PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;AST_EXPORTS"
                                RuntimeLibrary="2"
                                EnableFunctionLevelLinking="true"
index d060bc5..5011b05 100644 (file)
@@ -136,17 +136,17 @@ void visitprivate(const CallExp &e)
                 }
             }
         }
-        catch(ScilabException se)
+        catch(ScilabMessage sm)
         {
             if(pCall->isMacro() || pCall->isMacroFile())
             {
                 wchar_t szError[bsiz];
-                os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), se.GetErrorLocation().first_line, pCall->getName().c_str());
+                os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), sm.GetErrorLocation().first_line, pCall->getName().c_str());
                 throw ScilabMessage(szError);
             }
             else
             {
-                throw se;
+                throw sm;
             }
         }
     }
index 61ebad7..21e6ff2 100644 (file)
@@ -40,9 +40,8 @@ void visitprivate(const OpExp &e)
             ImplicitList* pIL = pITL->getAsImplicitList();
             if(pIL->isComputable())
             {
-                InternalType *pIT = pIL->extractFullMatrix();
-                execMeL.result_set(pIT);
-                TypeL = pIT->getType();
+                pITL = pIL->extractFullMatrix();
+                TypeL = pITL->getType();
             }
         }
 
@@ -51,9 +50,8 @@ void visitprivate(const OpExp &e)
             ImplicitList* pIL = pITR->getAsImplicitList();
             if(pIL->isComputable())
             {
-                InternalType *pIT = pIL->extractFullMatrix();
-                execMeR.result_set(pIT);
-                TypeR = pIT->getType();
+                pITR = pIL->extractFullMatrix();
+                TypeR = pITR->getType();
             }
         }
 
index b11bafd..2b125b1 100644 (file)
@@ -628,25 +628,25 @@ namespace ast
         void visitprivate(const TryCatchExp  &e)
         {
             //save current prompt mode
-            int oldVal = ConfigVariable::getPromptMode();
+            int oldVal = ConfigVariable::getSilentError();
             //set mode silent for errors
-            ConfigVariable::setPromptMode(-1);
+            ConfigVariable::setSilentError(1);
             try
             {
                 T execMe;
                 e.try_get().accept(execMe);
+                //restore previous prompt mode
+                ConfigVariable::setSilentError(oldVal);
             }
             catch(ScilabMessage sm)
             {
                 T execMe;
-
+                //restore previous prompt mode
+                ConfigVariable::setSilentError(oldVal);
                 //to lock lasterror
                 ConfigVariable::setLastErrorCall();
                 e.catch_get().accept(execMe);
             }
-
-            //restore previous prompt mode
-            ConfigVariable::setPromptMode(oldVal);
         }
 
 
@@ -1003,33 +1003,59 @@ namespace ast
                             types::typed_list out;
                             types::typed_list in;
 
-                            T execCall;
-                            Function::ReturnValue Ret = pCall->call(in, expected_getSize(), out, &execCall);
-
-                            if(Ret == Callable::OK)
+                            try
                             {
-                                if(out.size() == 0)
-                                {
-                                    execMe.result_set(NULL);
-                                }
-                                else if(out.size() == 1)
+                                T execCall;
+                                Function::ReturnValue Ret = pCall->call(in, expected_getSize(), out, &execCall);
+
+                                if(Ret == Callable::OK)
                                 {
-                                    out[0]->DecreaseRef();
-                                    execMe.result_set(out[0]);
+                                    if(out.size() == 0)
+                                    {
+                                        execMe.result_set(NULL);
+                                    }
+                                    else if(out.size() == 1)
+                                    {
+                                        out[0]->DecreaseRef();
+                                        execMe.result_set(out[0]);
+                                    }
+                                    else
+                                    {
+                                        for(int i = 0 ; i < static_cast<int>(out.size()) ; i++)
+                                        {
+                                            out[i]->DecreaseRef();
+                                            execMe.result_set(i, out[i]);
+                                        }
+                                    }
+
+                                    bImplicitCall = true;
                                 }
-                                else
+                                else if(Ret == Callable::Error)
                                 {
-                                    for(int i = 0 ; i < static_cast<int>(out.size()) ; i++)
+                                    if(ConfigVariable::getLastErrorFunction() == L"")
                                     {
-                                        out[i]->DecreaseRef();
-                                        execMe.result_set(i, out[i]);
+                                        ConfigVariable::setLastErrorFunction(pCall->getName());
+                                        ConfigVariable::setLastErrorLine(e.location_get().first_line);
                                     }
-                                }
 
-                                bImplicitCall = true;
+                                    if(pCall->isMacro() || pCall->isMacroFile())
+                                    {
+                                        wchar_t szError[bsiz];
+                                        os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), (*itExp)->location_get().first_line, pCall->getName().c_str());
+                                        throw ScilabMessage(szError);
+                                    }
+                                    else
+                                    {
+                                        throw ScilabMessage();
+                                    }
+                                }
                             }
-                            else if(Ret == Callable::Error)
+                            catch(ScilabMessage sm)
                             {
+                                wostringstream os;
+                                PrintVisitor printMe(os);
+                                (*itExp)->accept(printMe);
+                                os << std::endl << std::endl;
                                 if(ConfigVariable::getLastErrorFunction() == L"")
                                 {
                                     ConfigVariable::setLastErrorFunction(pCall->getName());
@@ -1038,17 +1064,17 @@ namespace ast
                                 if(pCall->isMacro() || pCall->isMacroFile())
                                 {
                                     wchar_t szError[bsiz];
-                                    os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), (*itExp)->location_get().first_line, pCall->getName().c_str());
-                                    throw ScilabMessage(szError);
+                                    os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), sm.GetErrorLocation().first_line, pCall->getName().c_str());
+                                    throw ScilabMessage(szError + os.str());
                                 }
                                 else
                                 {
-                                    throw ScilabMessage();
+                                    sm.SetErrorMessage(sm.GetErrorMessage() + os.str());
+                                    throw sm;
                                 }
                             }
                         }
 
-
                         SimpleVar* pVar = dynamic_cast<SimpleVar*>(*itExp);
                         //don't output Simplevar and empty result
                         if(execMe.result_get() != NULL && (pVar == NULL || bImplicitCall))
@@ -1087,7 +1113,7 @@ namespace ast
                 }
                 catch(ScilabMessage sm)
                 {
-                    YaspWriteW(sm.GetErrorMessage().c_str());
+                    YaspErrorW(sm.GetErrorMessage().c_str());
 
                     CallExp* pCall = dynamic_cast<CallExp*>(*itExp);
                     if(pCall != NULL)
@@ -1137,7 +1163,7 @@ namespace ast
                                 pCall->accept(printMe);
                                 os << std::endl << std::endl;
                                 ConfigVariable::setLastErrorFunction(execFunc.result_get()->getAsCallable()->getName());
-                                YaspWriteW(se.GetErrorMessage().c_str());
+                                YaspErrorW(se.GetErrorMessage().c_str());
                                 throw ScilabMessage(os.str(), 0, (*itExp)->location_get());
                             }
                         }
@@ -1146,7 +1172,7 @@ namespace ast
                         }
                     }
 
-                    YaspWriteW(se.GetErrorMessage().c_str());
+                    YaspErrorW(se.GetErrorMessage().c_str());
                     throw ScilabMessage((*itExp)->location_get());
                 }
             }
index 5837d57..43cb5bc 100644 (file)
@@ -25,6 +25,7 @@ namespace ast
     public :
         ScilabException();
         ScilabException(std::wstring _wstErrorMesssage);
+        ScilabException(std::string _stErrorMesssage);
         ScilabException(const Location& _ErrorLocation);
         ScilabException(std::wstring _wstErrorMesssage, int _iErrorNumber, const Location& _ErrorLocation);
         virtual ~ScilabException() throw() {};
@@ -49,6 +50,7 @@ namespace ast
     public :
         ScilabError() : ScilabException(){}
         ScilabError(std::wstring _wstErrorMesssage) : ScilabException(_wstErrorMesssage){}
+        ScilabError(std::string _stErrorMesssage) : ScilabException(_stErrorMesssage){}
         ScilabError(const Location& _ErrorLocation) : ScilabException(_ErrorLocation){}
         ScilabError(std::wstring _wstErrorMesssage, int _iErrorNumber, const Location& _ErrorLocation) : ScilabException(_wstErrorMesssage, _iErrorNumber, _ErrorLocation){}
     };
@@ -64,6 +66,7 @@ namespace ast
     public :
         ScilabMessage() : ScilabException(){}
         ScilabMessage(std::wstring _wstErrorMesssage) : ScilabException(_wstErrorMesssage){}
+        ScilabMessage(std::string _stErrorMesssage) : ScilabException(_stErrorMesssage){}
         ScilabMessage(const Location& _ErrorLocation) : ScilabException(_ErrorLocation){}
         ScilabMessage(std::wstring _wstErrorMesssage, int _iErrorNumber, const Location& _ErrorLocation) : ScilabException(_wstErrorMesssage, _iErrorNumber, _ErrorLocation){}
     };
index f2755b7..ff31064 100644 (file)
@@ -41,4 +41,6 @@ EXTERN_AST const std::wstring* getStructNameFromExp(const ast::Exp* _pExp);
 
 EXTERN_AST types::Struct* getStructFromExp(const ast::Exp* _pExp);
 
+EXTERN_AST void callOnPrompt(void);
+
 #endif //!AST_VISITOR_COMMON_HXX
index 34300ca..23d111f 100644 (file)
  */
 
 #include "scilabexception.hxx"
+
+extern "C"
+{
 #include "lasterror.h"
+#include "charEncoding.h"
+}
 
 namespace ast
 {
@@ -20,6 +25,11 @@ namespace ast
         m_wstErrorMessage = _wstErrorMesssage;
     }
 
+    ScilabException::ScilabException(std::string _stErrorMesssage)
+    {
+        m_wstErrorMessage = to_wide_string(_stErrorMesssage.c_str());
+    }
+
     void ScilabException::SetErrorMessage(std::wstring _wstErrorMesssage)
     {
         m_wstErrorMessage = _wstErrorMesssage;
index 156e831..ae428ed 100644 (file)
@@ -19,6 +19,7 @@
 #include "callexp.hxx"
 #include "struct.hxx"
 #include "context.hxx"
+#include "execvisitor.hxx"
 
 #include "alltypes.hxx"
 
@@ -28,8 +29,12 @@ bool bConditionState(types::InternalType *_pITResult)
         _pITResult->getAs<types::Double>()->isComplex() == false)
        {
                types::Double *pR = _pITResult->getAs<types::Double>();
-               double *pReal = pR->getReal();
+        if(pR->isEmpty())
+        {//[]
+            return false;
+        }
 
+               double *pReal = pR->getReal();
                for(int i = 0 ; i < pR->getSize() ; i++)
                {
                        if(pReal[i] == 0)
@@ -531,3 +536,16 @@ types::Struct* getStructFromExp(const Exp* _pExp)
     // FIXME
     return NULL;
 }
+
+void callOnPrompt(void)
+{
+    types::InternalType* pOnPrompt = NULL;
+    pOnPrompt = symbol::Context::getInstance()->get(symbol::Symbol(L"%onprompt"));
+    if(pOnPrompt != NULL && pOnPrompt->isCallable())
+    {
+        types::typed_list in;
+        types::typed_list out;
+        ExecVisitor execCall;
+        pOnPrompt->getAs<types::Callable>()->call(in, 1, out, &execCall);
+    }
+}
\ No newline at end of file
index eb6a0dd..327e500 100644 (file)
@@ -55,17 +55,17 @@ types::Function::ReturnValue Overload::call(std::wstring _stOverloadingFunctionN
     {
         return pCall->call(in, _iRetCount, out, _execMe);
     }
-    catch (ScilabException se)
+    catch (ScilabMessage sm)
     {
         if(pCall->isMacro() || pCall->isMacroFile())
         {
             wchar_t szError[bsiz];
-            os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), se.GetErrorLocation().first_line, pCall->getName().c_str());
+            os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), sm.GetErrorLocation().first_line, pCall->getName().c_str());
             throw ScilabMessage(szError);
         }
         else
         {
-            throw se;
+            throw sm;
         }
     }
 }
index f38a0dc..2315051 100644 (file)
@@ -38,7 +38,7 @@ void *Runner::launch(void *args)
     }
     catch(ScilabException se)
     {
-        YaspWriteW(se.GetErrorMessage().c_str());
+        YaspErrorW(se.GetErrorMessage().c_str());
     }
 
 
index e3d65a6..16795f6 100644 (file)
@@ -310,6 +310,9 @@ static int interactiveMain (void)
         commentbeginsession=NULL;
     }
 
+    //before calling reader, try to call %onprompt function
+    callOnPrompt();
+
     while (!ConfigVariable::getForceQuit())
     {
         // Show Parser Sate before prompt
@@ -327,6 +330,9 @@ static int interactiveMain (void)
                 FREE(command);
                 command = NULL;
             }
+            //before calling YaspReader, try to call %onprompt function
+            callOnPrompt();
+
             command = YaspRead();
         }
         else
@@ -537,7 +543,7 @@ int StartScilabEngine(int argc, char*argv[], int iFileIndex)
     }
     catch(ScilabException se)
     {
-        YaspWriteW(se.GetErrorMessage().c_str());
+        YaspErrorW(se.GetErrorMessage().c_str());
     }
 
     ConfigVariable::setPromptMode(2);
index 512c780..6633bf0 100644 (file)
@@ -49,7 +49,7 @@ void printExp(std::ifstream* _pFile, Exp* _pExp, char* _pstPrompt, int* _piLine
 /*--------------------------------------------------------------------------*/
 Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
-    int promptMode  = 2;
+    int promptMode  = 1;
     int iErr        = 0;
        bool bErrCatch  = false;
        Exp* pExp               = NULL;
@@ -190,8 +190,6 @@ Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, types::typ
             ExecVisitor execMe;
             (*j)->accept(execMe);
 
-            bool bImplicitCall = false;
-
             //to manage call without ()
             if(execMe.result_get() != NULL && execMe.result_get()->getAsCallable())
             {
@@ -199,33 +197,56 @@ Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, types::typ
                 types::typed_list out;
                 types::typed_list in;
 
-                ExecVisitor execCall;
-                Function::ReturnValue Ret = pCall->call(in, 1, out, &execCall);
-
-                if(Ret == Callable::OK)
+                try
                 {
-                    if(out.size() == 0)
-                    {
-                        execMe.result_set(NULL);
-                    }
-                    else if(out.size() == 1)
+                    ExecVisitor execCall;
+                    Function::ReturnValue Ret = pCall->call(in, 1, out, &execCall);
+
+                    if(Ret == Callable::OK)
                     {
-                        out[0]->DecreaseRef();
-                        execMe.result_set(out[0]);
+                        if(out.size() == 0)
+                        {
+                            execMe.result_set(NULL);
+                        }
+                        else if(out.size() == 1)
+                        {
+                            out[0]->DecreaseRef();
+                            execMe.result_set(out[0]);
+                        }
+                        else
+                        {
+                            for(int i = 0 ; i < static_cast<int>(out.size()) ; i++)
+                            {
+                                out[i]->DecreaseRef();
+                                execMe.result_set(i, out[i]);
+                            }
+                        }
                     }
-                    else
+                    else if(Ret == Callable::Error)
                     {
-                        for(int i = 0 ; i < static_cast<int>(out.size()) ; i++)
+                        if(ConfigVariable::getLastErrorFunction() == L"")
                         {
-                            out[i]->DecreaseRef();
-                            execMe.result_set(i, out[i]);
+                            ConfigVariable::setLastErrorFunction(pCall->getName());
                         }
-                    }
 
-                    bImplicitCall = true;
+                        if(pCall->isMacro() || pCall->isMacroFile())
+                        {
+                            wchar_t szError[bsiz];
+                            os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), (*j)->location_get().first_line, pCall->getName().c_str());
+                            throw ScilabMessage(szError);
+                        }
+                        else
+                        {
+                            throw ScilabMessage();
+                        }
+                    }
                 }
-                else if(Ret == Callable::Error)
+                catch(ScilabMessage sm)
                 {
+                    wostringstream os;
+                    PrintVisitor printMe(os);
+                    (*j)->accept(printMe);
+                    os << std::endl << std::endl;
                     if(ConfigVariable::getLastErrorFunction() == L"")
                     {
                         ConfigVariable::setLastErrorFunction(pCall->getName());
@@ -233,13 +254,18 @@ Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, types::typ
 
                     if(pCall->isMacro() || pCall->isMacroFile())
                     {
+                        wstring szAllError;
                         wchar_t szError[bsiz];
-                        os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), (*j)->location_get().first_line, pCall->getName().c_str());
-                        throw ScilabMessage(szError);
+                        os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), sm.GetErrorLocation().first_line, pCall->getName().c_str());
+                        szAllError = szError + os.str();
+                        os_swprintf(szError, bsiz, _W("at line % 5d of exec file called by :\n"), (*j)->location_get().first_line);
+                        szAllError += szError;
+                        throw ScilabMessage(szAllError);
                     }
                     else
                     {
-                        throw ScilabMessage();
+                        sm.SetErrorMessage(sm.GetErrorMessage() + os.str());
+                        throw sm;
                     }
                 }
             }
@@ -267,7 +293,7 @@ Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, types::typ
                }
         catch(ScilabMessage sm)
         {
-            YaspWriteW(sm.GetErrorMessage().c_str());
+            YaspErrorW(sm.GetErrorMessage().c_str());
 
             CallExp* pCall = dynamic_cast<CallExp*>(*j);
             if(pCall != NULL)
@@ -320,11 +346,9 @@ Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, types::typ
             iErr = ConfigVariable::getLastErrorNumber();
             if(bErrCatch == false)
             {
-                //in case of error, change mode to 2 ( prompt )
-                ConfigVariable::setPromptMode(2);
                 //write error
-                YaspWriteW(se.GetErrorMessage().c_str());
-                YaspWriteW(L"\n");
+                YaspErrorW(se.GetErrorMessage().c_str());
+                YaspErrorW(L"\n");
 
                 //write positino
                 wchar_t szError[bsiz];
index 9baabcf..05c8df7 100644 (file)
@@ -158,25 +158,182 @@ Function::ReturnValue sci_execstr(types::typed_list &in, int _iRetCount, types::
        {
                try
                {
-                       //excecute script
-                       ExecVisitor execMe;
-                       (*j)->accept(execMe);
+            //excecute script
+            ExecVisitor execMe;
+            (*j)->accept(execMe);
+
+            //to manage call without ()
+            if(execMe.result_get() != NULL && execMe.result_get()->getAsCallable())
+            {
+                Callable *pCall = execMe.result_get()->getAsCallable();
+                types::typed_list out;
+                types::typed_list in;
+
+                try
+                {
+                    ExecVisitor execCall;
+                    Function::ReturnValue Ret = pCall->call(in, 1, out, &execCall);
+
+                    if(Ret == Callable::OK)
+                    {
+                        if(out.size() == 0)
+                        {
+                            execMe.result_set(NULL);
+                        }
+                        else if(out.size() == 1)
+                        {
+                            out[0]->DecreaseRef();
+                            execMe.result_set(out[0]);
+                        }
+                        else
+                        {
+                            for(int i = 0 ; i < static_cast<int>(out.size()) ; i++)
+                            {
+                                out[i]->DecreaseRef();
+                                execMe.result_set(i, out[i]);
+                            }
+                        }
+                    }
+                    else if(Ret == Callable::Error)
+                    {
+                        if(ConfigVariable::getLastErrorFunction() == L"")
+                        {
+                            ConfigVariable::setLastErrorFunction(pCall->getName());
+                        }
+
+                        if(pCall->isMacro() || pCall->isMacroFile())
+                        {
+                            wchar_t szError[bsiz];
+                            os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), (*j)->location_get().first_line, pCall->getName().c_str());
+                            throw ScilabMessage(szError);
+                        }
+                        else
+                        {
+                            throw ScilabMessage();
+                        }
+                    }
+                }
+                catch(ScilabMessage sm)
+                {
+                    wostringstream os;
+                    PrintVisitor printMe(os);
+                    (*j)->accept(printMe);
+                    os << std::endl << std::endl;
+                    if(ConfigVariable::getLastErrorFunction() == L"")
+                    {
+                        ConfigVariable::setLastErrorFunction(pCall->getName());
+                    }
+
+                    if(pCall->isMacro() || pCall->isMacroFile())
+                    {
+                        wstring szAllError;
+                        wchar_t szError[bsiz];
+                        os_swprintf(szError, bsiz, _W("at line % 5d of function %ls called by :\n"), sm.GetErrorLocation().first_line, pCall->getName().c_str());
+                        szAllError = szError + os.str();
+                        os_swprintf(szError, bsiz, _W("in  execstr instruction    called by :\n"));
+                        szAllError += szError;
+                        throw ScilabMessage(szAllError);
+                    }
+                    else
+                    {
+                        sm.SetErrorMessage(sm.GetErrorMessage() + os.str());
+                        throw sm;
+                    }
+                }
+            }
+
+            //update ans variable.
+                       if(execMe.result_get() != NULL && execMe.result_get()->isDeletable())
+                       {
+                               symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *execMe.result_get());
+                               if( (*j)->is_verbose() && 
+                    bErrCatch == false)
+                               {
+                                       std::wostringstream ostr;
+                                       ostr << L"ans = " << std::endl;
+                                       ostr << std::endl;
+                                       ostr << execMe.result_get()->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth()) << std::endl;
+                                       YaspWriteW(ostr.str().c_str());
+                               }
+                       }
+
+                       //if( !checkPrompt(iMode, EXEC_MODE_MUTE) &&
+   //             bErrCatch == false)
+                       //{
+                       //      YaspWriteW(L"\n");
+                       //}
                }
+        catch(ScilabMessage sm)
+        {
+            if(bErrCatch  == false && bMute == false)
+            {
+                YaspErrorW(sm.GetErrorMessage().c_str());
+
+                CallExp* pCall = dynamic_cast<CallExp*>(*j);
+                if(pCall != NULL)
+                {//to print call expression only of it is a macro
+                    ExecVisitor execFunc;
+                    pCall->name_get().accept(execFunc);
+
+                    if(execFunc.result_get() != NULL &&
+                        (execFunc.result_get()->isMacro() || execFunc.result_get()->isMacroFile()))
+                    {
+                        wostringstream os;
+
+                        //add function failed
+                        PrintVisitor printMe(os);
+                        pCall->accept(printMe);
+                        os << std::endl;
+
+                        //add info on file failed
+                        wchar_t szError[bsiz];
+                        os_swprintf(szError, bsiz, _W("at line % 5d of exec file called by :\n"), (*j)->location_get().first_line);
+                        os << szError;
+
+                        if(ConfigVariable::getLastErrorFunction() == L"")
+                        {
+                            ConfigVariable::setLastErrorFunction(execFunc.result_get()->getAsCallable()->getName());
+                        }
+
+                        //restore previous prompt mode
+                        ConfigVariable::setPromptMode(oldVal);
+                        throw ScilabMessage(os.str(), 0, (*j)->location_get());
+                    }
+                }
+                throw ScilabMessage((*j)->location_get());
+            }
+            else
+            {
+                iErr = ConfigVariable::getLastErrorNumber();
+                break;
+            }
+        }
                catch(ScilabError se)
                {
-            if(bErrCatch && bMute == true)
+            if(ConfigVariable::getLastErrorMessage() == L"")
             {
-                //set mode silent for errors
-                ConfigVariable::setPromptMode(-1);
+                ConfigVariable::setLastErrorMessage(se.GetErrorMessage());
+                ConfigVariable::setLastErrorNumber(se.GetErrorNumber());
+                ConfigVariable::setLastErrorLine(se.GetErrorLocation().first_line);
+                ConfigVariable::setLastErrorFunction(wstring(L""));
             }
 
             //store message
-            ScierrorW(ConfigVariable::getLastErrorNumber(), L"%ls", ConfigVariable::getLastErrorMessage().c_str());
             iErr = ConfigVariable::getLastErrorNumber();
             if(bErrCatch == false)
             {
-               delete parser.getTree();
-                           return Function::Error;
+                //in case of error, change mode to 2 ( prompt )
+                ConfigVariable::setPromptMode(2);
+                //write error
+                YaspErrorW(se.GetErrorMessage().c_str());
+                YaspErrorW(L"\n");
+
+                //write positino
+                wchar_t szError[bsiz];
+                os_swprintf(szError, bsiz, _W("at line % 5d of exec file called by :\n"), (*j)->location_get().first_line);
+                //restore previous prompt mode
+                ConfigVariable::setPromptMode(oldVal);
+                throw ScilabMessage(szError, 1, (*j)->location_get());
             }
             break;
                }
@@ -196,3 +353,27 @@ Function::ReturnValue sci_execstr(types::typed_list &in, int _iRetCount, types::
        return Function::OK;
 }
 /*--------------------------------------------------------------------------*/
+
+/*
+               catch(ScilabError se)
+               {
+            if(bErrCatch && bMute == true)
+            {
+                //set mode silent for errors
+                ConfigVariable::setPromptMode(-1);
+            }
+
+            //store message
+            ScierrorW(ConfigVariable::getLastErrorNumber(), L"%ls", ConfigVariable::getLastErrorMessage().c_str());
+            iErr = ConfigVariable::getLastErrorNumber();
+            if(bErrCatch == false)
+            {
+               delete parser.getTree();
+                           return Function::Error;
+            }
+            break;
+               }
+*/
+
+/*
+*/
\ No newline at end of file
index 5b7922c..a60dc42 100644 (file)
@@ -30,9 +30,12 @@ OUTPUT_STREAM_IMPEXP void setYaspInputMethod(YASP_INPUT reader);
 
 OUTPUT_STREAM_IMPEXP char *YaspRead();
 
-OUTPUT_STREAM_IMPEXP void YaspWrite(const char* text);
+OUTPUT_STREAM_IMPEXP void YaspWrite(const char* _pstText);
 
-OUTPUT_STREAM_IMPEXP void YaspWriteW(const wchar_t* text);
+OUTPUT_STREAM_IMPEXP void YaspWriteW(const wchar_t* _pwstText);
+
+OUTPUT_STREAM_IMPEXP void YaspError(const char* _pstText);
+OUTPUT_STREAM_IMPEXP void YaspErrorW(const wchar_t* _pwstText);
 
 #ifdef __cplusplus
 }
index 5553930..dd84b2a 100644 (file)
@@ -5,4 +5,5 @@ EXPORTS
 getScilabMode
 getWarningMode
 setLastError
-getPromptMode
\ No newline at end of file
+getPromptMode
+getSilentError
index 97c701a..8b22f98 100644 (file)
                                        RelativePath=".\String_Import.def"
                                        >
                                </File>
+                               <File
+                                       RelativePath=".\System_env_Import.def"
+                                       >
+                               </File>
                        </Filter>
                        <Filter
                                Name="Export"
index b366c5b..c423c81 100644 (file)
 
 
 #include "yaspio.hxx"
-#include "promptmode.h"
 
 extern "C"
 {
+#include "promptmode.h"
 #include <stdio.h>
 #include "charEncoding.h"
 #include "MALLOC.h"
@@ -36,8 +36,17 @@ void setYaspInputMethod(YASP_INPUT reader)
     _reader = reader;
 }
 
+static void YaspPrint(const char* _pstText)
+{
+    wchar_t* pwstTemp = to_wide_string(_pstText);
+    diaryWrite(pwstTemp, FALSE);
+    FREE(pwstTemp);
+    (*_writer)(const_cast<char*>(_pstText));
+}
+
 char *YaspRead()
 {
+    //call reader
     char* pstTemp = (*_reader)();
 
     //add prompt to diary
@@ -55,26 +64,38 @@ char *YaspRead()
     return pstTemp;
 }
 
-void YaspWrite(const char* text)
+void YaspWrite(const char* _pstText)
 {
-    int iMode =  getPromptMode();
-    char sz[256];
-
-    //sprintf(sz, "getPromptMode() -> %d", iMode);
-    //MessageBoxA(NULL, sz, NULL, 0);
+    if(getPromptMode() != PROMPTMODE_SILENT)
+    {
+        YaspPrint(const_cast<char*>(_pstText));
+    }
+}
 
-    if(iMode != PROMPTMODE_SILENT)
+void YaspWriteW(const wchar_t* _pwsText)
+{
+    if(getPromptMode() != PROMPTMODE_SILENT)
     {
-        wchar_t* pwstTemp = to_wide_string(text);
-        diaryWrite(pwstTemp, FALSE);
-        FREE(pwstTemp);
-        (*_writer)(const_cast<char*>(text));
+        char* pstTemp = wide_string_to_UTF8(_pwsText);
+        YaspWrite(pstTemp);
+        FREE(pstTemp);
     }
 }
 
-void YaspWriteW(const wchar_t* text)
+void YaspError(const char* _pstText)
 {
-    char* pstTemp = wide_string_to_UTF8(text);
-    YaspWrite(pstTemp);
-    FREE(pstTemp);
+    if(getSilentError() == VERBOSE_ERROR)
+    {
+        YaspPrint(const_cast<char*>(_pstText));
+    }
 }
+
+void YaspErrorW(const wchar_t* _pwsText)
+{
+    if(getSilentError() == VERBOSE_ERROR)
+    {
+        char* pstTemp = wide_string_to_UTF8(_pwsText);
+        YaspPrint(pstTemp);
+        FREE(pstTemp);
+    }
+}
\ No newline at end of file
index e29b0c7..623ac16 100644 (file)
@@ -160,9 +160,10 @@ public :
     static void setLastErrorFunction(std::wstring _wstFunction);
     static std::wstring getLastErrorFunction();
 
-    //Prompt Mode
+    //Prompt Mode and Silent error
 public :
     /*
+    Prompt mode
     normal = 0,
     silent = -1,
     prompt = 2,
@@ -171,12 +172,20 @@ public :
     step = 4,
     step7 = 7
     */
+
+    /*
+       show = 0
+       silent = 1
+    */
 private :
     static int m_iPromptMode;
+    static int m_iSilentError;
 
 public :
     static void setPromptMode(int _iPromptMode);
     static int getPromptMode(void);
+    static void setSilentError(int _iSilentError);
+    static int getSilentError(void);
 
     //Thread List
 
index 12dba70..f18a3b1 100644 (file)
@@ -28,9 +28,15 @@ extern "C"
 #define PROMPTMODE_STEP     4
 #define PROMPTMODE_STEP7    7
 
+#define SILENT_ERROR        1
+#define VERBOSE_ERROR       0
+
 EXTERN_SYSTEM_ENV int getPromptMode(void);
 EXTERN_SYSTEM_ENV void setPromptMode(int _iMode);
 
+EXTERN_SYSTEM_ENV int getSilentError(void);
+EXTERN_SYSTEM_ENV void setSilentError(int _iSilent);
+
 #ifdef __cplusplus
 }
 #endif
index ecca19e..fe184c7 100644 (file)
@@ -352,6 +352,7 @@ std::wstring ConfigVariable::getLastErrorFunction()
 */
 
 int ConfigVariable::m_iPromptMode = 0;
+int ConfigVariable::m_iSilentError = 0;
 
 void ConfigVariable::setPromptMode(int _iPromptMode)
 {
@@ -363,6 +364,16 @@ int ConfigVariable::getPromptMode(void)
     return m_iPromptMode;
 }
 
+void ConfigVariable::setSilentError(int _iSilentError)
+{
+    m_iSilentError = _iSilentError;
+}
+
+int ConfigVariable::getSilentError(void)
+{
+    return m_iSilentError;
+}
+
 /*
 ** ThreadList
 ** \{
index 92d6b6e..55c68fc 100644 (file)
 
 #include <stdlib.h>
 
-#include "promptmode.h"
 #include "configvariable.hxx"
 #include "setenvvar.hxx"
 #include "arrayof.hxx"
 #include "context.hxx"
+#include "promptmode.h"
+
 
 int getPromptMode(void)
 {
@@ -27,3 +28,13 @@ void setPromptMode(int _iMode)
 {
     ConfigVariable::setPromptMode(_iMode);
 }
+
+int getSilentError(void)
+{
+    return static_cast<int>(ConfigVariable::getSilentError());
+}
+
+void setSilentError(int _iSilent)
+{
+    ConfigVariable::setSilentError(_iSilent);
+}
index f051783..6e521e7 100644 (file)
@@ -195,7 +195,7 @@ namespace types
                 }
             }
         }
-        catch(ast::ScilabException se)
+        catch(ast::ScilabMessage se)
         {
             //close the current scope
             pContext->scope_end();