List display fixed. 46/15346/6
Cedric Delamarre [Tue, 7 Oct 2014 14:37:38 +0000 (16:37 +0200)]
tl = tlist(["test", "f1", "f2"], 12, 15)
l = list(478, tl, "string")
list(l)

function %test_p(a), disp("test"), endfunction
l

lsslist('lss','A','B','C','X0','dt')

Change-Id: I41e6a27a46a1ab585af483e81baa5fc39b50ae94

24 files changed:
scilab/modules/ast/includes/ast/runvisitor.hxx
scilab/modules/ast/includes/types/arrayof.hxx
scilab/modules/ast/includes/types/types_tools.hxx
scilab/modules/ast/src/cpp/ast/run_AssignExp.cpp
scilab/modules/ast/src/cpp/ast/runvisitor.cpp
scilab/modules/ast/src/cpp/types/function.cpp
scilab/modules/ast/src/cpp/types/implicitlist.cpp
scilab/modules/ast/src/cpp/types/library.cpp
scilab/modules/ast/src/cpp/types/list.cpp
scilab/modules/ast/src/cpp/types/listdelete.cpp
scilab/modules/ast/src/cpp/types/listoperation.cpp
scilab/modules/ast/src/cpp/types/listundefined.cpp
scilab/modules/ast/src/cpp/types/macro.cpp
scilab/modules/ast/src/cpp/types/macrofile.cpp
scilab/modules/ast/src/cpp/types/singlepoly.cpp
scilab/modules/ast/src/cpp/types/singlestruct.cpp
scilab/modules/ast/src/cpp/types/sparse.cpp
scilab/modules/ast/src/cpp/types/struct.cpp
scilab/modules/ast/src/cpp/types/threadId.cpp
scilab/modules/ast/src/cpp/types/tlist.cpp
scilab/modules/ast/src/cpp/types/types_tools.cpp
scilab/modules/ast/src/cpp/types/void.cpp
scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp
scilab/modules/output_stream/includes/scilabWrite.hxx

index d2ebbe2..26466fc 100644 (file)
@@ -419,7 +419,9 @@ public :
                 ostr << e.getSymbol().getName() << L"  = " << L"(" << pI->getRef() << L")" << std::endl;
                 ostr << std::endl;
                 scilabWriteW(ostr.str().c_str());
-                VariableToString(pI, e.getSymbol().getName().c_str());
+                std::wostringstream ostrName;
+                ostrName << SPACES_LIST << e.getSymbol().getName();
+                VariableToString(pI, ostrName.str().c_str());
             }
         }
         else
@@ -518,60 +520,6 @@ public :
         }
     }
 
-    void VariableToString(types::InternalType* pIT, const wchar_t* wcsVarName)
-    {
-        std::wostringstream ostr;
-
-        if (pIT->isMList() || pIT->isTList() || pIT->hasToString() == false)
-        {
-            //call overload %type_p
-            types::typed_list in;
-            types::typed_list out;
-
-            pIT->IncreaseRef();
-            in.push_back(pIT);
-
-            try
-            {
-                if (Overload::generateNameAndCall(L"p", in, 1, out, this) != Function::OK)
-                    //if (Overload::call(L"%" + pIT->getAs<TList>()->getShortTypeStr() + L"_p", in, 1, out, this) != Function::OK)
-                {
-                    throw ScilabError();
-                }
-            }
-            catch (ScilabError /*&e*/)
-            {
-                ostr << wcsVarName;
-                pIT->toString(ostr);
-                scilabWriteW(ostr.str().c_str());
-            }
-
-            pIT->DecreaseRef();
-        }
-        else
-        {
-            //to manage lines information
-            int iLines = ConfigVariable::getConsoleLines();
-
-            bool bFinish = false;
-            do
-            {
-                //block by block
-                bFinish = pIT->toString(ostr);
-                scilabWriteW(ostr.str().c_str());
-                if (bFinish == false && iLines != 0)
-                {
-                    //show message on prompt
-                    bFinish = linesmore() == 1;
-                }
-                ostr.str(L"");
-            }
-            while (bFinish == false);
-
-            pIT->clearPrintState();
-        }
-    }
-
     types::InternalType* callOverloadOpExp(OpExp::Oper _oper, types::InternalType* _paramL, types::InternalType* _paramR);
     types::InternalType* callOverloadMatrixExp(std::wstring strType, types::InternalType* _paramL, types::InternalType* _paramR);
 };
index e847574..ab6af10 100644 (file)
@@ -24,6 +24,7 @@
 #include "scilabexception.hxx"
 #include "inspector.hxx"
 #include "type_traits.hxx"
+#include "scilabWrite.hxx"
 
 extern "C"
 {
@@ -1512,6 +1513,7 @@ public :
         int* piDims = new int[m_iDims];
         bool bFinish = parseSubMatrix(ostr, piDims, m_iDims, m_iDims - 1);
         delete[] piDims;
+        scilabWriteW(ostr.str().c_str());
         return bFinish;
     }
 
index daefe37..1621493 100644 (file)
@@ -20,6 +20,7 @@ namespace types
 EXTERN_AST int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list* _pArgsOut, int* _piMaxDim, int* _piCountDim);
 EXTERN_AST void getIndexesWithDims(int _iIndex, int* _piIndexes, int* _piDims, int _iDims);
 EXTERN_AST int getIndexWithDims(int* _piIndexes, int* _piDims, int _iDims);
+EXTERN_AST void VariableToString(types::InternalType* pIT, const wchar_t* wcsVarName);
 }
 
 #endif /* !__TYPES_TOOLS_HXX__ */
index 6ed628c..6b6e752 100644 (file)
@@ -83,10 +83,13 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
 
             if (e.isVerbose() && ConfigVariable::isPromptShow())
             {
+                std::wstring wstrName = pVar->getSymbol().getName();
                 std::wostringstream ostr;
-                ostr << pVar->getSymbol().getName() << L"  = " << std::endl << std::endl;
+                ostr << wstrName << L"  = " << std::endl << std::endl;
                 scilabWriteW(ostr.str().c_str());
-                VariableToString(pIT, pVar->getSymbol().getName().c_str());
+                std::wostringstream ostrName;
+                ostrName << SPACES_LIST << wstrName;
+                VariableToString(pIT, ostrName.str().c_str());
             }
             return;
         }
@@ -144,20 +147,16 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
                 if (e.isVerbose() && ConfigVariable::isPromptShow())
                 {
                     std::wostringstream ostr;
-                    const wchar_t* wcsVarName;
                     if (pVar)
                     {
-                        ostr << pVar->getSymbol().getName() << L"  = " << std::endl;
-                        wcsVarName = pVar->getSymbol().getName().c_str();
+                        ostr << SPACES_LIST << pVar->getSymbol().getName();
                     }
                     else
                     {
-                        ostr << L"???" << L"  = " << std::endl;
-                        wcsVarName = L"???";
+                        ostr << SPACES_LIST << L"???";
                     }
 
-                    ostr << std::endl;
-                    VariableToString(pOut, wcsVarName);
+                    VariableToString(pOut, ostr.str().c_str());
                 }
             }
             else
@@ -223,14 +222,13 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
             if (e.isVerbose() && ConfigVariable::isPromptShow())
             {
                 std::wostringstream ostr;
-                const wchar_t* wcsVarName;
-
                 ostr << *getStructNameFromExp(&pCall->getName()) << L"  = " << std::endl;
-                wcsVarName = getStructNameFromExp(&pCall->getName())->c_str();
-
                 ostr << std::endl;
                 scilabWriteW(ostr.str().c_str());
-                VariableToString(pOut, wcsVarName);
+
+                std::wostringstream ostrName;
+                ostrName << SPACES_LIST << *getStructNameFromExp(&pCall->getName());
+                VariableToString(pOut, ostrName.str().c_str());
             }
 
             pITR->killMe();
@@ -335,7 +333,10 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
                 std::wostringstream ostr;
                 ostr << *pstName << L"  = " << std::endl << std::endl;
                 scilabWriteW(ostr.str().c_str());
-                VariableToString(pPrint, pstName->c_str());
+
+                std::wostringstream ostrName;
+                ostrName << SPACES_LIST << *pstName;
+                VariableToString(pPrint, ostrName.str().c_str());
             }
 
             clearResult();
index 8e5ab5d..a61d8c7 100644 (file)
@@ -748,7 +748,9 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
                     {
                         //TODO manage multiple returns
                         scilabWriteW(L" ans  =\n\n");
-                        VariableToString(pITAns, L"ans");
+                        std::wostringstream ostrName;
+                        ostrName << SPACES_LIST << L"ans";
+                        VariableToString(pITAns, ostrName.str().c_str());
                     }
                 }
 
index c4b88c5..689d7e8 100644 (file)
@@ -17,6 +17,7 @@
 #include "double.hxx"
 #include "gatewaystruct.hxx"
 #include "configvariable.hxx"
+#include "scilabWrite.hxx"
 
 extern "C"
 {
@@ -115,7 +116,7 @@ bool Function::toString(std::wostringstream& ostr)
 {
     // FIXME : Implement me.
     ostr << L"FIXME : Implement Function::toString" << std::endl;
-
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 
index 2f2a992..2c67ef4 100644 (file)
@@ -16,6 +16,7 @@
 #include "implicitlist.hxx"
 #include "int.hxx"
 #include "configvariable.hxx"
+#include "scilabWrite.hxx"
 
 #ifndef NDEBUG
 #include "inspector.hxx"
@@ -368,7 +369,9 @@ bool ImplicitList::toString(std::wostringstream& ostr)
 {
     if (isComputable())
     {
-        return extractFullMatrix()->toString(ostr);
+        bool ret = extractFullMatrix()->toString(ostr);
+        scilabWriteW(ostr.str().c_str());
+        return ret;
     }
     else
     {
@@ -410,6 +413,7 @@ bool ImplicitList::toString(std::wostringstream& ostr)
             ostr << printInLinePoly(pMP->get(0), pMP->getVariableName());
         }
         ostr << std::endl;
+        scilabWriteW(ostr.str().c_str());
         return true;
     }
 }
index 176127c..fdcd90c 100644 (file)
@@ -15,6 +15,7 @@
 #include "library.hxx"
 #include "localization.hxx"
 #include "configvariable.hxx"
+#include "scilabWrite.hxx"
 
 extern "C"
 {
@@ -68,6 +69,7 @@ bool Library::toString(std::wostringstream& ostr)
     }
 
     ostr << std::endl;
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 
index ab0655e..55a508c 100644 (file)
@@ -18,6 +18,8 @@
 #include "types_tools.hxx"
 #include "scilabexception.hxx"
 #include "localization.hxx"
+#include "scilabWrite.hxx"
+#include "types_tools.hxx"
 
 #ifndef NDEBUG
 #include "inspector.hxx"
@@ -113,31 +115,33 @@ InternalType *List::clone()
 
 /**
 ** toString to display Lists
-** FIXME : Find a better indentation process
 */
 bool List::toString(std::wostringstream& ostr)
 {
-    wchar_t* wcsVarName = os_wcsdup(ostr.str().c_str());
-    ostr.str(L"");
-
     if (getSize() == 0)
     {
-        ostr << wcsVarName << L"()" << std::endl;
+        ostr.str(L"");
+        ostr << L"     ()" << std::endl;
+        scilabWriteW(ostr.str().c_str());
     }
     else
     {
+        wchar_t* wcsVarName = os_wcsdup(ostr.str().c_str());
         int iPosition = 1;
         std::vector<InternalType *>::iterator itValues;
         for (itValues = m_plData->begin() ; itValues != m_plData->end() ; ++itValues, ++iPosition)
         {
-            ostr << "     " << wcsVarName << L"(" << iPosition << L")" << std::endl;
-            //maange lines
-            (*itValues)->toString(ostr);
-            ostr << std::endl;
+            std::wostringstream nextVarName;
+            ostr.str(L"");
+            nextVarName << " " << wcsVarName << L"(" << iPosition << L")";
+            ostr << std::endl << nextVarName.str() << std::endl << std::endl;
+            scilabWriteW(ostr.str().c_str());
+            VariableToString(*itValues, nextVarName.str().c_str());
         }
+
+        free(wcsVarName);
     }
 
-    free(wcsVarName);
     return true;
 }
 
index 3960740..4dc1ae1 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "listdelete.hxx"
 #include "localization.h"
+#include "scilabWrite.hxx"
 
 namespace types
 {
@@ -35,6 +36,7 @@ InternalType* ListDelete::clone(void)
 bool ListDelete::toString(std::wostringstream& ostr)
 {
     ostr << L"FIXME : Implement ListDelete::toString" << std::endl;
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 }
index a84265c..fae4c60 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "listoperation.hxx"
 #include "localization.h"
+#include "scilabWrite.hxx"
 
 namespace types
 {
@@ -35,6 +36,7 @@ InternalType* ListOperation::clone(void)
 bool ListOperation::toString(std::wostringstream& ostr)
 {
     ostr << L"FIXME : Implement ListOperation::toString" << std::endl;
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 }
index 7cfdcae..5931f0f 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "listundefined.hxx"
 #include "localization.h"
+#include "scilabWrite.hxx"
 
 namespace types
 {
@@ -40,6 +41,7 @@ InternalType::ScilabType ListUndefined::getType(void)
 bool ListUndefined::toString(std::wostringstream& ostr)
 {
     ostr << L"    Undefined" << std::endl;
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 }
index 4f9a5ea..3517e29 100644 (file)
@@ -99,6 +99,7 @@ ast::SeqExp* Macro::getBody(void)
 bool Macro::toString(std::wostringstream& ostr)
 {
     ostr << L"FIXME : Implement Macro::toString" << std::endl;
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 
index 0e7f403..b5d9680 100644 (file)
@@ -21,6 +21,7 @@
 #include "parser.hxx"
 #include "configvariable.hxx"
 #include "deserializervisitor.hxx"
+#include "scilabWrite.hxx"
 
 namespace types
 {
@@ -53,6 +54,7 @@ void MacroFile::whoAmI()
 bool MacroFile::toString(std::wostringstream& ostr)
 {
     ostr << L"FIXME : Implement MacroFile::toString" << std::endl;
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 
index 60d67f7..fc18572 100644 (file)
@@ -15,6 +15,7 @@
 #include "double.hxx"
 #include "tostring_common.hxx"
 #include "configvariable.hxx"
+#include "scilabWrite.hxx"
 
 extern "C"
 {
@@ -315,6 +316,7 @@ void SinglePoly::updateRank(void)
 bool SinglePoly::toString(std::wostringstream& ostr)
 {
     ostr << L"FIXME : implement SinglePoly::toString" << std::endl;
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 
index c2d8b83..542b2e2 100644 (file)
@@ -17,6 +17,7 @@
 #include "double.hxx"
 #include "scilabexception.hxx"
 #include "localization.hxx"
+#include "scilabWrite.hxx"
 
 namespace types
 {
@@ -279,6 +280,8 @@ bool SingleStruct::toString(std::wostringstream& ostr)
             ostr << *iterFieldNames << L" : " << (*iterFieldData)->getTypeStr() << std::endl;
         }
     }
+
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 
index f3732df..2b88472 100644 (file)
@@ -26,6 +26,7 @@
 #include "types_addition.hxx"
 #include "types_multiplication.hxx"
 #include "configvariable.hxx"
+#include "scilabWrite.hxx"
 
 #include "sparseOp.hxx"
 
@@ -535,6 +536,7 @@ bool Sparse::toString(std::wostringstream& ostr) const
     }
 
     ostr << res;
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 
index bb69989..e235e56 100644 (file)
@@ -15,6 +15,7 @@
 #include "list.hxx"
 #include "int.hxx"
 #include "localization.hxx"
+#include "scilabWrite.hxx"
 
 namespace types
 {
@@ -498,6 +499,7 @@ bool Struct::toString(std::wostringstream& ostr)
         delete pwstFields;
     }
 
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 
index 7027c3e..685c74b 100644 (file)
@@ -15,6 +15,7 @@
 #include "core_math.h"
 #include "threadId.hxx"
 #include "tostring_common.hxx"
+#include "scilabWrite.hxx"
 
 extern "C"
 {
@@ -140,6 +141,7 @@ bool ThreadId::toString(std::wostringstream& ostr)
 {
     ostr << L"ThreadId : " << this << std::endl;
     ostr << L"Status : " << StatusToString(this->getStatus());
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 }
index f979a02..7843fe1 100644 (file)
@@ -18,6 +18,7 @@
 #include "listundefined.hxx"
 #include "callable.hxx"
 #include "overload.hxx"
+#include "execvisitor.hxx"
 
 #ifndef NDEBUG
 #include "inspector.hxx"
@@ -240,46 +241,60 @@ String* TList::getFieldNames()
 
 /**
 ** toString to display TLists
-** FIXME : Find a better indentation process
 */
 bool TList::toString(std::wostringstream& ostr)
 {
-    wchar_t* wcsVarName = os_wcsdup(ostr.str().c_str());
-    ostr.str(L"");
+    //call overload %type_p if exists
+    types::typed_list in;
+    types::typed_list out;
+    ast::ExecVisitor* exec = new ast::ExecVisitor();
 
-    if (getSize() == 0)
-    {
-        ostr << wcsVarName << L"()" << std::endl;
-    }
-    else if ((*m_plData)[0]->isString() &&
-             (*m_plData)[0]->getAs<types::String>()->getSize() > 0 &&
-             wcscmp((*m_plData)[0]->getAs<types::String>()->get(0), L"lss") == 0)
+    IncreaseRef();
+    in.push_back(this);
+
+    try
     {
-        int iPosition = 1;
-        const wchar_t * wcsDesc[7] = {L"  (state-space system:)", L"= A matrix =", L"= B matrix =", L"= C matrix =", L"= D matrix =", L"= X0 (initial state) =", L"= Time domain ="};
-        std::vector<InternalType *>::iterator itValues;
-        for (itValues = m_plData->begin() ; itValues != m_plData->end() ; ++itValues, ++iPosition)
+        if (Overload::generateNameAndCall(L"p", in, 1, out, exec) == Function::OK)
         {
-            ostr << "     " << wcsVarName << L"(" << iPosition << L") " << wcsDesc[iPosition - 1] << std::endl;
-            //maange lines
-            (*itValues)->toString(ostr);
-            ostr << std::endl;
+            ostr.str(L"");
+            DecreaseRef();
+            delete exec;
+            return true;
         }
     }
-    else
+    catch (ast::ScilabError /* &e */)
+    {
+        // avoid error message about undefined overload %type_p
+    }
+
+    DecreaseRef();
+    delete exec;
+
+    // special case for lss
+    if (getSize() != 0 &&
+            (*m_plData)[0]->isString() &&
+            (*m_plData)[0]->getAs<types::String>()->getSize() > 0 &&
+            wcscmp((*m_plData)[0]->getAs<types::String>()->get(0), L"lss") == 0)
     {
+        wchar_t* wcsVarName = os_wcsdup(ostr.str().c_str());
         int iPosition = 1;
+        const wchar_t * wcsDesc[7] = {L"  (state-space system:)", L"= A matrix =", L"= B matrix =", L"= C matrix =", L"= D matrix =", L"= X0 (initial state) =", L"= Time domain ="};
         std::vector<InternalType *>::iterator itValues;
         for (itValues = m_plData->begin() ; itValues != m_plData->end() ; ++itValues, ++iPosition)
         {
-            ostr << "     " << wcsVarName << L"(" << iPosition << L")" << std::endl;
-            //maange lines
-            (*itValues)->toString(ostr);
-            ostr << std::endl;
+            std::wostringstream nextVarName;
+            ostr.str(L"");
+            nextVarName << " " << wcsVarName << L"(" << iPosition << L")";
+            ostr << std::endl << nextVarName.str() << wcsDesc[iPosition - 1] << std::endl << std::endl;
+            scilabWriteW(ostr.str().c_str());
+            VariableToString(*itValues, nextVarName.str().c_str());
         }
+
+        free(wcsVarName);
+        return true;
     }
 
-    free(wcsVarName);
-    return true;
+    // call normal toString
+    return List::toString(ostr);
 }
 } // end namespace types
index 8e0d7df..df342a2 100644 (file)
@@ -12,6 +12,8 @@
 
 #include "alltypes.hxx"
 #include "types_tools.hxx"
+#include "overload.hxx"
+#include "execvisitor.hxx"
 
 namespace types
 {
@@ -262,4 +264,58 @@ int getIndexWithDims(int* _piIndexes, int* _piDims, int _iDims)
     }
     return idx;
 }
+
+void VariableToString(types::InternalType* pIT, const wchar_t* wcsVarName)
+{
+    std::wostringstream ostr;
+    if (pIT->hasToString() == false)
+    {
+        //call overload %type_p
+        types::typed_list in;
+        types::typed_list out;
+        ast::ExecVisitor* exec = new ast::ExecVisitor();
+
+        pIT->IncreaseRef();
+        in.push_back(pIT);
+
+        try
+        {
+            Overload::generateNameAndCall(L"p", in, 1, out, exec);
+            delete exec;
+            pIT->DecreaseRef();
+        }
+        catch (ast::ScilabError &e)
+        {
+            delete exec;
+            pIT->DecreaseRef();
+            throw e;
+        }
+    }
+    else
+    {
+        if (pIT->isList())
+        {
+            ostr << wcsVarName;
+        }
+
+        //to manage lines information
+        int iLines = ConfigVariable::getConsoleLines();
+
+        bool bFinish = false;
+        do
+        {
+            //block by block
+            bFinish = pIT->toString(ostr);
+            if (bFinish == false && iLines != 0)
+            {
+                //show message on prompt
+                bFinish = linesmore() == 1;
+            }
+            ostr.str(L"");
+        }
+        while (bFinish == false);
+
+        pIT->clearPrintState();
+    }
+}
 }
index d2f427c..32ea43d 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "void.hxx"
 #include "localization.h"
+#include "scilabWrite.hxx"
 
 namespace types
 {
@@ -35,6 +36,7 @@ InternalType* Void::clone(void)
 bool Void::toString(std::wostringstream& ostr)
 {
     ostr << L"" << std::endl;
+    scilabWriteW(ostr.str().c_str());
     return true;
 }
 }
index a1037dc..dc2dcd8 100644 (file)
@@ -23,6 +23,7 @@
 #include "scilabWrite.hxx"
 #include "scilabexception.hxx"
 #include "configvariable.hxx"
+#include "types_tools.hxx"
 
 #include <iostream>
 #include <fstream>
@@ -360,7 +361,9 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
                     {
                         //TODO manage multiple returns
                         scilabWriteW(L" ans  =\n\n");
-                        execMe.VariableToString(pITAns, L"ans");
+                        std::wostringstream ostrName;
+                        ostrName << SPACES_LIST << L"ans";
+                        VariableToString(pITAns, ostrName.str().c_str());
                     }
                 }
             }
index 7a111fc..a4f9670 100644 (file)
@@ -13,6 +13,8 @@
 #ifndef __YASPIO_HXX__
 #define __YASPIO_HXX__
 
+#define SPACES_LIST L"      "
+
 #include "dynlib_output_stream.h"
 
 #ifdef __cplusplus