First macr2tree implementation based on AST. 14/15914/8
Antoine ELIAS [Thu, 5 Feb 2015 13:43:48 +0000 (14:43 +0100)]
Change-Id: I0ffa8c95ede341cb0767f05a08c4d6ada8f80e5d

87 files changed:
scilab/modules/ast/Makefile.am
scilab/modules/ast/Makefile.in
scilab/modules/ast/ast.vcxproj
scilab/modules/ast/ast.vcxproj.filters
scilab/modules/ast/includes/ast/dummyvisitor.hxx
scilab/modules/ast/includes/ast/treevisitor.hxx [new file with mode: 0644]
scilab/modules/ast/includes/exps/listexp.hxx
scilab/modules/ast/includes/exps/token.hxx
scilab/modules/ast/src/cpp/ast/run_AssignExp.hpp
scilab/modules/ast/src/cpp/ast/runvisitor.cpp
scilab/modules/ast/src/cpp/ast/treevisitor.cpp [new file with mode: 0644]
scilab/modules/ast/src/cpp/types/tlist.cpp
scilab/modules/core/Makefile.am
scilab/modules/core/Makefile.in
scilab/modules/core/includes/core_gw.hxx
scilab/modules/core/includes/gw_core.h
scilab/modules/core/sci_gateway/cpp/core_gw.cpp
scilab/modules/core/sci_gateway/cpp/core_gw.vcxproj
scilab/modules/core/sci_gateway/cpp/core_gw.vcxproj.filters
scilab/modules/core/sci_gateway/cpp/sci_macr2tree.cpp [new file with mode: 0644]
scilab/modules/m2sci/help/en_US/sci_files.xml
scilab/modules/m2sci/help/fr_FR/sci_files.xml
scilab/modules/m2sci/macros/kernel/Equal.sci
scilab/modules/m2sci/macros/kernel/is_a_scalar.sci
scilab/modules/m2sci/macros/kernel/m2sci_insert.sci [moved from scilab/modules/m2sci/macros/kernel/insert.sci with 95% similarity]
scilab/modules/m2sci/macros/kernel/m2sci_syntax.sci
scilab/modules/m2sci/macros/kernel/mtlbtree2sci.sci
scilab/modules/m2sci/macros/mfile2sci.sci
scilab/modules/m2sci/macros/percent/%g2sci.sci
scilab/modules/m2sci/macros/percent/%h2sci.sci
scilab/modules/m2sci/macros/percent/%i2sci.sci
scilab/modules/m2sci/macros/percent/%i2sci_c.sci
scilab/modules/m2sci/macros/percent/%i2sci_g.sci
scilab/modules/m2sci/macros/percent/%i2sci_r.sci
scilab/modules/m2sci/macros/percent/%i_ce2sci.sci
scilab/modules/m2sci/macros/sci_files/sci_PROTO1.g
scilab/modules/m2sci/macros/sci_files/sci_PROTO11.g
scilab/modules/m2sci/macros/sci_files/sci_PROTO15.g
scilab/modules/m2sci/macros/sci_files/sci_PROTO3.g
scilab/modules/m2sci/macros/sci_files/sci_PROTO5.g
scilab/modules/m2sci/macros/sci_files/sci_acoth.sci
scilab/modules/m2sci/macros/sci_files/sci_angle.sci
scilab/modules/m2sci/macros/sci_files/sci_asin.sci
scilab/modules/m2sci/macros/sci_files/sci_atan.sci
scilab/modules/m2sci/macros/sci_files/sci_atanh.sci
scilab/modules/m2sci/macros/sci_files/sci_balance.sci
scilab/modules/m2sci/macros/sci_files/sci_beta.sci
scilab/modules/m2sci/macros/sci_files/sci_blanks.sci
scilab/modules/m2sci/macros/sci_files/sci_box.sci
scilab/modules/m2sci/macros/sci_files/sci_cla.sci
scilab/modules/m2sci/macros/sci_files/sci_clf.sci
scilab/modules/m2sci/macros/sci_files/sci_clock.sci
scilab/modules/m2sci/macros/sci_files/sci_colordef.sci
scilab/modules/m2sci/macros/sci_files/sci_docopt.sci
scilab/modules/m2sci/macros/sci_files/sci_dos.sci
scilab/modules/m2sci/macros/sci_files/sci_eig.sci
scilab/modules/m2sci/macros/sci_files/sci_eye.sci
scilab/modules/m2sci/macros/sci_files/sci_false.sci
scilab/modules/m2sci/macros/sci_files/sci_ferror.sci
scilab/modules/m2sci/macros/sci_files/sci_fgetl.sci
scilab/modules/m2sci/macros/sci_files/sci_fgets.sci
scilab/modules/m2sci/macros/sci_files/sci_fileparts.sci
scilab/modules/m2sci/macros/sci_files/sci_fliplr.sci
scilab/modules/m2sci/macros/sci_files/sci_flipud.sci
scilab/modules/m2sci/macros/sci_files/sci_fopen.sci
scilab/modules/m2sci/macros/sci_files/sci_fseek.sci
scilab/modules/m2sci/macros/sci_files/sci_grid.sci
scilab/modules/m2sci/macros/sci_files/sci_hankel.sci
scilab/modules/m2sci/macros/sci_files/sci_isfield.sci
scilab/modules/m2sci/macros/sci_files/sci_logical.sci
scilab/modules/m2sci/macros/sci_files/sci_max.sci
scilab/modules/m2sci/macros/sci_files/sci_min.sci
scilab/modules/m2sci/macros/sci_files/sci_mkdir.sci
scilab/modules/m2sci/macros/sci_files/sci_nargin.sci
scilab/modules/m2sci/macros/sci_files/sci_nargout.sci
scilab/modules/m2sci/macros/sci_files/sci_ones.sci
scilab/modules/m2sci/macros/sci_files/sci_rand.sci
scilab/modules/m2sci/macros/sci_files/sci_randn.sci
scilab/modules/m2sci/macros/sci_files/sci_repmat.sci
scilab/modules/m2sci/macros/sci_files/sci_setstr.sci
scilab/modules/m2sci/macros/sci_files/sci_size.sci
scilab/modules/m2sci/macros/sci_files/sci_sparse.sci
scilab/modules/m2sci/macros/sci_files/sci_true.sci
scilab/modules/m2sci/macros/sci_files/sci_unix.sci
scilab/modules/m2sci/macros/sci_files/sci_waitforbuttonpress.sci
scilab/modules/m2sci/macros/sci_files/sci_warning.sci
scilab/modules/m2sci/macros/sci_files/sci_zeros.sci

index c6e3d45..3654667 100644 (file)
@@ -31,6 +31,7 @@ src/cpp/ast/mutevisitor.cpp \
 src/cpp/ast/printvisitor.cpp \
 src/cpp/ast/runvisitor.cpp \
 src/cpp/ast/shortcutvisitor.cpp \
+src/cpp/ast/treevisitor.cpp \
 src/cpp/ast/visitor_common.cpp \
 src/cpp/operations/interface_addition.cpp \
 src/cpp/operations/operations.cpp \
index ccf4e35..337edd3 100644 (file)
@@ -174,7 +174,8 @@ am__libsciast_la_SOURCES_DIST = src/c/operations/doublecomplex.c \
        src/cpp/ast/debugvisitor.cpp src/cpp/ast/expHistory.cpp \
        src/cpp/ast/macrovarvisitor.cpp src/cpp/ast/mutevisitor.cpp \
        src/cpp/ast/printvisitor.cpp src/cpp/ast/runvisitor.cpp \
-       src/cpp/ast/shortcutvisitor.cpp src/cpp/ast/visitor_common.cpp \
+       src/cpp/ast/shortcutvisitor.cpp src/cpp/ast/treevisitor.cpp \
+       src/cpp/ast/visitor_common.cpp \
        src/cpp/operations/interface_addition.cpp \
        src/cpp/operations/operations.cpp \
        src/cpp/operations/types_addition.cpp \
@@ -244,6 +245,7 @@ am_libsciast_la_OBJECTS =  \
        src/cpp/ast/libsciast_la-printvisitor.lo \
        src/cpp/ast/libsciast_la-runvisitor.lo \
        src/cpp/ast/libsciast_la-shortcutvisitor.lo \
+       src/cpp/ast/libsciast_la-treevisitor.lo \
        src/cpp/ast/libsciast_la-visitor_common.lo \
        src/cpp/operations/libsciast_la-interface_addition.lo \
        src/cpp/operations/libsciast_la-operations.lo \
@@ -698,7 +700,8 @@ libsciast_la_SOURCES = src/c/operations/doublecomplex.c \
        src/cpp/ast/debugvisitor.cpp src/cpp/ast/expHistory.cpp \
        src/cpp/ast/macrovarvisitor.cpp src/cpp/ast/mutevisitor.cpp \
        src/cpp/ast/printvisitor.cpp src/cpp/ast/runvisitor.cpp \
-       src/cpp/ast/shortcutvisitor.cpp src/cpp/ast/visitor_common.cpp \
+       src/cpp/ast/shortcutvisitor.cpp src/cpp/ast/treevisitor.cpp \
+       src/cpp/ast/visitor_common.cpp \
        src/cpp/operations/interface_addition.cpp \
        src/cpp/operations/operations.cpp \
        src/cpp/operations/types_addition.cpp \
@@ -1181,6 +1184,8 @@ src/cpp/ast/libsciast_la-runvisitor.lo: src/cpp/ast/$(am__dirstamp) \
 src/cpp/ast/libsciast_la-shortcutvisitor.lo:  \
        src/cpp/ast/$(am__dirstamp) \
        src/cpp/ast/$(DEPDIR)/$(am__dirstamp)
+src/cpp/ast/libsciast_la-treevisitor.lo: src/cpp/ast/$(am__dirstamp) \
+       src/cpp/ast/$(DEPDIR)/$(am__dirstamp)
 src/cpp/ast/libsciast_la-visitor_common.lo:  \
        src/cpp/ast/$(am__dirstamp) \
        src/cpp/ast/$(DEPDIR)/$(am__dirstamp)
@@ -1439,6 +1444,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/ast/$(DEPDIR)/libsciast_la-printvisitor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/ast/$(DEPDIR)/libsciast_la-runvisitor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/ast/$(DEPDIR)/libsciast_la-shortcutvisitor.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/ast/$(DEPDIR)/libsciast_la-treevisitor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/ast/$(DEPDIR)/libsciast_la-visitor_common.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/operations/$(DEPDIR)/libsciast_la-interface_addition.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/operations/$(DEPDIR)/libsciast_la-operations.Plo@am__quote@
@@ -1677,6 +1683,13 @@ src/cpp/ast/libsciast_la-shortcutvisitor.lo: src/cpp/ast/shortcutvisitor.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/ast/libsciast_la-shortcutvisitor.lo `test -f 'src/cpp/ast/shortcutvisitor.cpp' || echo '$(srcdir)/'`src/cpp/ast/shortcutvisitor.cpp
 
+src/cpp/ast/libsciast_la-treevisitor.lo: src/cpp/ast/treevisitor.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/ast/libsciast_la-treevisitor.lo -MD -MP -MF src/cpp/ast/$(DEPDIR)/libsciast_la-treevisitor.Tpo -c -o src/cpp/ast/libsciast_la-treevisitor.lo `test -f 'src/cpp/ast/treevisitor.cpp' || echo '$(srcdir)/'`src/cpp/ast/treevisitor.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/ast/$(DEPDIR)/libsciast_la-treevisitor.Tpo src/cpp/ast/$(DEPDIR)/libsciast_la-treevisitor.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/ast/treevisitor.cpp' object='src/cpp/ast/libsciast_la-treevisitor.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/ast/libsciast_la-treevisitor.lo `test -f 'src/cpp/ast/treevisitor.cpp' || echo '$(srcdir)/'`src/cpp/ast/treevisitor.cpp
+
 src/cpp/ast/libsciast_la-visitor_common.lo: src/cpp/ast/visitor_common.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/ast/libsciast_la-visitor_common.lo -MD -MP -MF src/cpp/ast/$(DEPDIR)/libsciast_la-visitor_common.Tpo -c -o src/cpp/ast/libsciast_la-visitor_common.lo `test -f 'src/cpp/ast/visitor_common.cpp' || echo '$(srcdir)/'`src/cpp/ast/visitor_common.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/ast/$(DEPDIR)/libsciast_la-visitor_common.Tpo src/cpp/ast/$(DEPDIR)/libsciast_la-visitor_common.Plo
index 9054ce3..14e221e 100644 (file)
@@ -255,6 +255,7 @@ lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
     <ClInclude Include="includes\ast\dynlib_ast.h" />
     <ClInclude Include="includes\ast\execvisitor.hxx" />
     <ClInclude Include="includes\ast\expHistory.hxx" />
+    <ClInclude Include="includes\ast\treevisitor.hxx" />
     <ClInclude Include="includes\ast\macrovarvisitor.hxx" />
     <ClInclude Include="includes\ast\mutevisitor.hxx" />
     <ClInclude Include="includes\ast\printvisitor.hxx" />
@@ -424,6 +425,7 @@ lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
   <ItemGroup>
     <ClCompile Include="src\cpp\ast\debugvisitor.cpp" />
     <ClCompile Include="src\cpp\ast\expHistory.cpp" />
+    <ClCompile Include="src\cpp\ast\treevisitor.cpp" />
     <ClCompile Include="src\cpp\ast\macrovarvisitor.cpp" />
     <ClCompile Include="src\cpp\ast\mutevisitor.cpp" />
     <ClCompile Include="src\cpp\ast\printvisitor.cpp" />
index 6c1bcfe..1470833 100644 (file)
     <ClInclude Include="src\cpp\ast\run_OpExp.hpp">
       <Filter>Header Files\ast</Filter>
     </ClInclude>
+    <ClInclude Include="includes\ast\treevisitor.hxx">
+      <Filter>Header Files\ast</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="src\cpp\ast\debugvisitor.cpp">
     <ClCompile Include="src\cpp\types\addfunction.cpp">
       <Filter>Source Files\types</Filter>
     </ClCompile>
+    <ClCompile Include="src\cpp\ast\treevisitor.cpp">
+      <Filter>Source Files\ast</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
index a8d2cd2..ffb1674 100644 (file)
@@ -30,7 +30,7 @@ class EXTERN_AST DummyVisitor : public ConstVisitor
 protected:
     DummyVisitor() {}
 
-    virtual void visit (const MatrixExp &e)
+    virtual void visit(const MatrixExp &e)
     {
         exps_t lines = e.getLines();
         for (exps_t::const_iterator it = lines.begin(), itEnd = lines.end(); it != itEnd ; ++it)
diff --git a/scilab/modules/ast/includes/ast/treevisitor.hxx b/scilab/modules/ast/includes/ast/treevisitor.hxx
new file mode 100644 (file)
index 0000000..b27a1a3
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
+*
+*  This file must be used under the terms of the CeCILL.
+*  This source file is licensed as described in the file COPYING, which
+*  you should have received as part of this distribution.  The terms
+*  are also available at
+*  http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+*
+*/
+
+#ifndef __LISTVISITOR_HXX__
+#define __LISTVISITOR_HXX__
+
+#include "dummyvisitor.hxx"
+#include "tlist.hxx"
+
+//used by macr2tree to generate a tlist from an AST
+
+namespace ast
+{
+class EXTERN_AST TreeVisitor : public DummyVisitor
+{
+public:
+    TreeVisitor() : l(nullptr), eol(nullptr) {}
+    ~TreeVisitor() {}
+
+    virtual void visit(const SeqExp  &e);
+    virtual void visit(const CommentExp &e);
+    virtual void visit(const SimpleVar &e);
+    virtual void visit(const DoubleExp &e);
+    virtual void visit(const StringExp &e);
+    virtual void visit(const BoolExp &e);
+    virtual void visit(const DollarVar &e);
+    virtual void visit(const ColonVar &e);
+    virtual void visit(const MatrixExp &e);
+    virtual void visit(const MatrixLineExp &e);
+    virtual void visit(const OpExp &e);
+    virtual void visit(const LogicalOpExp &e);
+    virtual void visit(const IfExp &e);
+    virtual void visit(const ListExp &e);
+    virtual void visit(const AssignExp &e);
+    virtual void visit(const CallExp &e);
+    virtual void visit(const ForExp &e);
+    virtual void visit(const FieldExp &e);
+    virtual void visit(const TryCatchExp  &e);
+    virtual void visit(const WhileExp  &e);
+    virtual void visit(const ContinueExp &/*e*/);
+    virtual void visit(const BreakExp &/*e*/);
+    virtual void visit(const ReturnExp &e);
+    virtual void visit(const SelectExp &e);
+    virtual void visit(const CaseExp &e);
+    virtual void visit(const ArrayListExp &e);
+    virtual void visit(const NotExp &e);
+    virtual void visit(const TransposeExp &e);
+    virtual void visit(const FunctionDec &e);
+
+    inline types::List* getList()
+    {
+        return l;
+    }
+
+    static types::List* createVar(const std::wstring& str);
+    static types::List* createConst(types::InternalType* pIT);
+    static types::List* createOperation();
+    static types::List* createAssign();
+    static types::InternalType* getVerbose(const Exp& e);
+
+    types::InternalType* getEOL();
+private:
+
+    types::List* l;
+    types::List* eol;
+};
+}
+#endif /* !__LISTVISITOR_HXX__ */
\ No newline at end of file
index cb13be5..3370621 100644 (file)
@@ -70,7 +70,7 @@ public:
 
     virtual ListExp* clone()
     {
-        ListExp* cloned = new ListExp(getLocation(), *getStart().clone(), *getStep().clone(), *getEnd().clone());
+        ListExp* cloned = new ListExp(getLocation(), *getStart().clone(), *getStep().clone(), *getEnd().clone(), hasExplicitStep());
         cloned->setVerbose(isVerbose());
         return cloned;
     }
index fc9e8d4..15059e6 100644 (file)
 /** Scilab tokens and key words
  ** \{ */
 
-#define SCI_DOT                        L"."
-
-#define SCI_TRUE               L"%T"
-#define SCI_FALSE              L"%F"
-
-#define SCI_INT8               L"int8"
-#define SCI_INT16              L"int16"
-#define SCI_INT32              L"int32"
-#define SCI_INT64              L"int64"
-#define SCI_LPAREN             L"("
-#define SCI_RPAREN             L")"
-#define SCI_LBRACE             L"{"
-#define SCI_RBRACE             L"}"
-#define SCI_LBRACK             L"["
-#define SCI_RBRACK             L"]"
-
-#define SCI_PLUS               L"+"
-#define SCI_MINUS              L"-"
-#define SCI_TIMES              L"*"
-#define SCI_RDIVIDE            L"/"
-#define SCI_LDIVIDE            L"\\"
-#define SCI_POWER              L"^"
-
-#define SCI_DOTTIMES           L".*"
-#define SCI_DOTRDIVIDE         L"./"
-#define SCI_DOTLDIVIDE         L".\\"
-#define SCI_DOTPOWER           L".^"
-
-#define SCI_KRONTIMES          L".*."
-#define SCI_KRONRDIVIDE                L"./."
-#define SCI_KRONLDIVIDE                L".\\."
-
-#define SCI_CONTROLTIMES       L"*."
-#define SCI_CONTROLRDIVIDE     L"/."
-#define SCI_CONTROLLDIVIDE     L"\\."
-
-#define SCI_EQ                 L"=="
-#define SCI_NE                 L"<>"
-#define SCI_GE                 L">="
-#define SCI_GT                 L">"
-#define SCI_LE                 L"<="
-#define SCI_LT                 L"<"
-
-#define SCI_AND                        L"&"
-#define SCI_OR                 L"|"
-#define SCI_ANDAND     L"&&"
-#define SCI_OROR               L"||"
-#define SCI_NOT                        L"~"
-
-#define SCI_CONJUGATE_TRANSPOSE        L"'"
-#define SCI_TRANSPOSE          L".'"
-
-#define SCI_QUOTE              L"\'"
-#define SCI_DQUOTE             L"\""
-#define SCI_COMMA              L","
-#define SCI_SEMICOLON          L";"
-#define SCI_COLON              L":"
-
-#define SCI_DOLLAR             L"$"
-
-#define SCI_ASSIGN             L"="
-#define SCI_OPEN_COMMENT       L"//"
+#define SCI_DOT                                    L"."
+
+#define SCI_TRUE                           L"%T"
+#define SCI_FALSE                          L"%F"
+
+#define SCI_INT8                           L"int8"
+#define SCI_INT16                          L"int16"
+#define SCI_INT32                          L"int32"
+#define SCI_INT64                          L"int64"
+#define SCI_LPAREN                         L"("
+#define SCI_RPAREN                         L")"
+#define SCI_LBRACE                         L"{"
+#define SCI_RBRACE                         L"}"
+#define SCI_LBRACK                         L"["
+#define SCI_RBRACK                         L"]"
+
+#define SCI_PLUS                           L"+"
+#define SCI_MINUS                          L"-"
+#define SCI_TIMES                          L"*"
+#define SCI_RDIVIDE                        L"/"
+#define SCI_LDIVIDE                        L"\\"
+#define SCI_POWER                          L"^"
+
+#define SCI_DOTTIMES                   L".*"
+#define SCI_DOTRDIVIDE                 L"./"
+#define SCI_DOTLDIVIDE                 L".\\"
+#define SCI_DOTPOWER                   L".^"
+
+#define SCI_KRONTIMES                  L".*."
+#define SCI_KRONRDIVIDE                        L"./."
+#define SCI_KRONLDIVIDE                        L".\\."
+
+#define SCI_CONTROLTIMES               L"*."
+#define SCI_CONTROLRDIVIDE             L"/."
+#define SCI_CONTROLLDIVIDE             L"\\."
+
+#define SCI_EQ                             L"=="
+#define SCI_NE                             L"<>"
+#define SCI_GE                             L">="
+#define SCI_GT                             L">"
+#define SCI_LE                             L"<="
+#define SCI_LT                             L"<"
+
+#define SCI_AND                                    L"&"
+#define SCI_OR                             L"|"
+#define SCI_ANDAND                     L"&&"
+#define SCI_OROR                           L"||"
+#define SCI_NOT                                    L"~"
+
+#define SCI_CONJUGATE_TRANSPOSE            L"'"
+#define SCI_TRANSPOSE                  L".'"
+
+#define SCI_QUOTE                          L"\'"
+#define SCI_DQUOTE                         L"\""
+#define SCI_COMMA                          L","
+#define SCI_SEMICOLON              L";"
+#define SCI_COLON                          L":"
+
+#define SCI_DOLLAR                         L"$"
+
+#define SCI_ASSIGN                         L"="
+#define SCI_OPEN_COMMENT               L"//"
 
 // Syntax to acces field 'bar' in variable 'foo'
 // foo.var
-#define SCI_FVAR_SEPARATOR             SCI_DOT
+#define SCI_FVAR_SEPARATOR          SCI_DOT
 
 // Syntax to access indexed variable in 'foo'
 // foo(5)
index 94623f3..2441c13 100644 (file)
@@ -305,7 +305,7 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
 
             for (i = iLhsCount - 1, it = exps.rbegin(); it != exps.rend(); it++, i--)
             {
-                AssignExp pAssign((*it)->getLocation(), *(*it), *const_cast<Exp*>(&e.getRightExp()), pIT[i]);
+                AssignExp pAssign((*it)->getLocation(), *(*it), *e.getRightExp().clone(), pIT[i]);
                 pAssign.setLrOwner(false);
                 pAssign.setVerbose(e.isVerbose());
                 pAssign.accept(*this);
index 64c5996..8a945d5 100644 (file)
@@ -203,21 +203,34 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
         in.push_back(pS);
         in.push_back(pValue);
         Callable::ReturnValue Ret = Callable::Error;
+        std::wstring stType = pValue->getShortTypeStr();
 
         try
         {
-            Ret = Overload::call(L"%" + pValue->getShortTypeStr() + L"_e", in, 1, out, this);
+            Ret = Overload::call(L"%" + stType + L"_e", in, 1, out, this);
         }
-        catch (ast::ScilabError & se)
+        catch (ast::ScilabError &/*se*/)
         {
-            // TList or Mlist
-            if (pValue->isList())
+            try
             {
-                Ret = Overload::call(L"%l_e", in, 1, out, this);
+                //to compatibility with scilab 5 code.
+                //tlist/mlist name are truncated to 8 first character
+                if (stType.size() > 8)
+                {
+                    Ret = Overload::call(L"%" + stType.substr(0, 8) + L"_e", in, 1, out, this);
+                }
             }
-            else
+            catch (ast::ScilabError & se)
             {
-                throw se;
+                // TList or Mlist
+                if (pValue->isList())
+                {
+                    Ret = Overload::call(L"%l_e", in, 1, out, this);
+                }
+                else
+                {
+                    throw se;
+                }
             }
         }
 
diff --git a/scilab/modules/ast/src/cpp/ast/treevisitor.cpp b/scilab/modules/ast/src/cpp/ast/treevisitor.cpp
new file mode 100644 (file)
index 0000000..8b50dd0
--- /dev/null
@@ -0,0 +1,914 @@
+/*
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
+*
+*  This file must be used under the terms of the CeCILL.
+*  This source file is licensed as described in the file COPYING, which
+*  you should have received as part of this distribution.  The terms
+*  are also available at
+*  http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+*
+*/
+
+#include "treevisitor.hxx"
+#include "execvisitor.hxx"
+#include "token.hxx"
+
+namespace ast
+{
+void TreeVisitor::visit(const SeqExp  &e)
+{
+    types::List* lst = new types::List();
+    lst->append(getEOL());
+
+    int last_line = -1;
+    for (auto it : e.getExps())
+    {
+        int fisrt = it->getLocation().first_line;
+        while (last_line != -1 && last_line < it->getLocation().first_line)
+        {
+            lst->append(getEOL());
+            ++last_line;
+        }
+
+        last_line = it->getLocation().last_line;
+
+        it->accept(*this);
+        if (it->isAssignExp() ||
+                it->isCommentExp() ||
+                it->isForExp() ||
+                it->isWhileExp() ||
+                it->isTryCatchExp() ||
+                it->isSelectExp() ||
+                it->isIfExp())
+        {
+            lst->append(getList());
+        }
+        else
+        {
+            //add ans = before expression
+            types::TList* tl = new types::TList();
+            types::String* s = new types::String(1, 4);
+            s->set(0, L"equal");
+            s->set(1, L"expression");
+            s->set(2, L"lhs");
+            s->set(3, L"endsymbol");
+            //header
+            tl->append(s);
+            //expression
+            tl->append(getList());
+            //lhs
+            types::List* lhs = new types::List();
+            lhs->append(createVar(L"ans"));
+            tl->append(lhs);
+            //endsymbol
+            tl->append(getVerbose(*it));
+            lst->append(tl);
+        }
+    }
+
+    lst->append(getEOL());
+    l = lst;
+}
+
+void TreeVisitor::visit(const CommentExp  &e)
+{
+    types::TList* tl = new types::TList();
+    types::String* s = new types::String(1, 2);
+    s->set(0, L"comment");
+    s->set(1, L"text");
+    tl->append(s);
+    tl->append(new types::String(e.getComment().c_str()));
+    l = tl;
+}
+
+void TreeVisitor::visit(const SimpleVar &e)
+{
+    l = createVar(e.getSymbol().getName());
+}
+
+void TreeVisitor::visit(const DoubleExp &e)
+{
+    ExecVisitor exec;
+    e.accept(exec);
+    l = createConst(exec.getResult());
+}
+
+void TreeVisitor::visit(const StringExp &e)
+{
+    ExecVisitor exec;
+    e.accept(exec);
+    l = createConst(exec.getResult());
+}
+
+void TreeVisitor::visit(const BoolExp &e)
+{
+    ExecVisitor exec;
+    e.accept(exec);
+    l = createConst(exec.getResult());
+}
+
+void TreeVisitor::visit(const DollarVar &e)
+{
+    l = createVar(L"$");
+}
+
+void TreeVisitor::visit(const ColonVar &e)
+{
+    l = createVar(L":");
+}
+
+void TreeVisitor::visit(const MatrixExp &e)
+{
+    exps_t lines = e.getLines();
+
+    if (lines.size() == 0)
+    {
+        l = createConst(Double::Empty());
+        return;
+    }
+
+    if (lines.size() == 1)
+    {
+        lines.front()->accept(*this);
+        return;
+    }
+
+    types::List* sub = createOperation();
+    types::List* ope = new types::List();
+    sub->append(ope);
+
+    int idx = 0;
+    for (auto it : lines)
+    {
+        it->accept(*this);
+
+        if (idx >= 2)
+        {
+            sub->append(new types::String(L"cc"));
+            //create a new operation
+            //put previous stage in lhs and
+            //result in rhs
+            types::List* lst = createOperation();
+            types::List* tmp = new types::List();
+            tmp->append(sub);
+            //add EOL
+            tmp->append(getEOL());
+
+            lst->append(tmp);
+            ope = tmp;
+            sub = lst;
+        }
+
+        ope->append(getList());
+
+        if (idx == 0)
+        {
+            //add EOL
+            ope->append(getEOL());
+        }
+        ++idx;
+    }
+
+    sub->append(new types::String(L"cc"));
+    l = sub;
+}
+
+void TreeVisitor::visit(const MatrixLineExp &e)
+{
+    exps_t columns = e.getColumns();
+    if (columns.size() == 1)
+    {
+        columns.front()->accept(*this);
+        return;
+    }
+
+    types::List* sub = createOperation();
+    types::List* ope = new types::List();
+    sub->append(ope);
+
+    int idx = 0;
+    int last_line = -1;
+    for (auto it : columns)
+    {
+        it->accept(*this);
+
+        if (idx >= 2)
+        {
+            sub->append(new types::String(L"rc"));
+            //create a new operation
+            //put previous stage in lhs and
+            //result in rhs
+            types::List* lst = createOperation();
+            types::List* tmp = new types::List();
+            tmp->append(sub);
+
+            lst->append(tmp);
+            ope = tmp;
+            sub = lst;
+        }
+
+        ope->append(getList());
+        ++idx;
+    }
+
+    sub->append(new types::String(L"rc"));
+    l = sub;
+}
+
+void TreeVisitor::visit(const OpExp &e)
+{
+    types::List* ope = createOperation();
+    types::List* sub = new types::List();
+
+    if (e.getOper() != OpExp::unaryMinus)
+    {
+        e.getLeft().accept(*this);
+        sub->append(getList());
+    }
+    e.getRight().accept(*this);
+    sub->append(getList());
+    ope->append(sub);
+
+    types::String* s = new types::String(1, 1);
+    switch (e.getOper())
+    {
+        // Arithmetics.
+        case OpExp::plus:
+            ope->append(new types::String(SCI_PLUS));
+            break;
+        case OpExp::unaryMinus:
+        case OpExp::minus:
+            ope->append(new types::String(SCI_MINUS));
+            break;
+        case OpExp::times:
+            ope->append(new types::String(SCI_TIMES));
+            break;
+        case OpExp::rdivide:
+            ope->append(new types::String(SCI_RDIVIDE));
+            break;
+        case OpExp::ldivide:
+            ope->append(new types::String(SCI_LDIVIDE));
+            break;
+        case OpExp::power:
+            ope->append(new types::String(SCI_POWER));
+            break;
+        // Element wise.
+        case OpExp::dottimes:
+            ope->append(new types::String(SCI_DOTTIMES));
+            break;
+        case OpExp::dotrdivide:
+            ope->append(new types::String(SCI_DOTRDIVIDE));
+            break;
+        case OpExp::dotldivide:
+            ope->append(new types::String(SCI_DOTLDIVIDE));
+            break;
+        case OpExp::dotpower:
+            ope->append(new types::String(SCI_DOTPOWER));
+            break;
+        // Kroneckers
+        case OpExp::krontimes:
+            ope->append(new types::String(SCI_KRONTIMES));
+            break;
+        case OpExp::kronrdivide:
+            ope->append(new types::String(SCI_KRONRDIVIDE));
+            break;
+        case OpExp::kronldivide:
+            ope->append(new types::String(SCI_KRONLDIVIDE));
+            break;
+        // Control
+        case OpExp::controltimes:
+            ope->append(new types::String(SCI_CONTROLTIMES));
+            break;
+        case OpExp::controlrdivide:
+            ope->append(new types::String(SCI_CONTROLRDIVIDE));
+            break;
+        case OpExp::controlldivide:
+            ope->append(new types::String(SCI_CONTROLLDIVIDE));
+            break;
+        // Comparisons
+        case OpExp::eq:
+            ope->append(new types::String(SCI_EQ));
+            break;
+        case OpExp::ne:
+            ope->append(new types::String(SCI_NE));
+            break;
+        case OpExp::lt:
+            ope->append(new types::String(SCI_LT));
+            break;
+        case OpExp::le:
+            ope->append(new types::String(SCI_LE));
+            break;
+        case OpExp::gt:
+            ope->append(new types::String(SCI_GT));
+            break;
+        case OpExp::ge:
+            ope->append(new types::String(SCI_GE));
+            break;
+        default:
+            ope->append(new types::String(L"BAD OPERATOR"));
+            break;
+    }
+
+    l = ope;
+}
+
+void TreeVisitor::visit(const LogicalOpExp &e)
+{
+    types::List* ope = createOperation();
+    types::List* sub = new types::List();
+
+    if (e.getOper() != OpExp::unaryMinus)
+    {
+        e.getLeft().accept(*this);
+        sub->append(getList());
+    }
+    e.getRight().accept(*this);
+    sub->append(getList());
+    ope->append(sub);
+
+    types::String* s = new types::String(1, 1);
+    switch (e.getOper())
+    {
+        case LogicalOpExp::logicalAnd:
+            ope->append(new types::String(SCI_AND));
+            break;
+        case LogicalOpExp::logicalOr:
+            ope->append(new types::String(SCI_OR));
+            break;
+        case LogicalOpExp::logicalShortCutAnd:
+            ope->append(new types::String(SCI_ANDAND));
+            break;
+        case LogicalOpExp::logicalShortCutOr:
+            ope->append(new types::String(SCI_OROR));
+            break;
+        default:
+            ope->append(new types::String(L"BAD LOGICAL OPERATOR"));
+            break;
+    }
+
+    l = ope;
+}
+
+void TreeVisitor::visit(const IfExp  &e)
+{
+    types::TList* tl = new types::TList();
+    bool hasElse = e.hasElse() && e.getElse().isCommentExp() == false;
+    //header
+    types::String* s = new types::String(1, 5);
+    s->set(0, L"ifthenelse");
+    s->set(1, L"expression");
+    s->set(2, L"then");
+    s->set(3, L"elseifs"); //always empty
+    s->set(4, L"else");
+    tl->append(s);
+
+    //expression -> condition
+    e.getTest().accept(*this);
+    tl->append(getList());
+
+    //then
+    e.getThen().accept(*this);
+    tl->append(getList());
+
+    //elseif
+    tl->append(new types::List());
+
+    //else
+    if (hasElse)
+    {
+        e.getElse().accept(*this);
+        tl->append(getList());
+    }
+    else
+    {
+        tl->append(new types::List());
+    }
+    l = tl;
+}
+
+void TreeVisitor::visit(const ListExp  &e)
+{
+    types::List* ope = createOperation();
+    types::List* sub = new types::List();
+
+    e.getStart().accept(*this);
+    sub->append(getList());
+
+    if (e.hasExplicitStep())
+    {
+        e.getStep().accept(*this);
+        sub->append(getList());
+    }
+
+    e.getEnd().accept(*this);
+    sub->append(getList());
+
+    ope->append(sub);
+    ope->append(new types::String(L":"));
+    l = ope;
+}
+
+void TreeVisitor::visit(const AssignExp &e)
+{
+    types::List* assign = createAssign();
+
+    //expression : what to assign
+    e.getRightExp().accept(*this);
+    assign->append(getList());
+
+    double* dlhs = NULL;
+    if (e.getRightExp().isCallExp())
+    {
+        types::TList* tl = getList()->getAs<types::TList>();
+        types::Double* lhsnb = tl->get(tl->getSize() - 1)->getAs<types::Double>();
+        dlhs = lhsnb->get();
+    }
+
+    //lhs : who to assign
+    Exp& left = e.getLeftExp();
+    if (left.isSimpleVar())
+    {
+        left.accept(*this);
+        types::List* lhs = new types::List();
+        lhs->append(getList());
+        assign->append(lhs);
+        if (dlhs)
+        {
+            dlhs[0] = 1;//lhs = 1
+        }
+    }
+
+    if (left.isCellCallExp())
+    {
+        //not yet manage
+    }
+
+    if (left.isCallExp())
+    {
+        CallExp* call = left.getAs<CallExp>();
+        types::List* ins = createOperation();
+        types::List* lhs = new types::List();
+        //varname
+        call->getName().accept(*this);
+        lhs->append(getList());
+
+        //indexes
+        for (auto arg : call->getArgs())
+        {
+            arg->accept(*this);
+            lhs->append(getList());
+        }
+        if (dlhs)
+        {
+            dlhs[0] = 1;//lhs = 1
+        }
+        ins->append(lhs);
+
+        //operator
+        ins->append(new types::String(L"ins"));
+        types::List* tmp = new types::List();
+        tmp->append(ins);
+        assign->append(tmp);
+    }
+
+    if (left.isAssignListExp())
+    {
+        AssignListExp* lst = left.getAs<AssignListExp>();
+        types::List* lhs = new types::List();
+        for (auto exp : lst->getExps())
+        {
+            exp->accept(*this);
+            lhs->append(getList());
+        }
+        if (dlhs)
+        {
+            dlhs[0] = static_cast<double>(lst->getExps().size());
+        }
+
+
+        assign->append(lhs);
+    }
+
+    if (left.isFieldExp())
+    {
+        FieldExp* field = left.getAs<FieldExp>();
+        types::List* ins = createOperation();
+        types::List* lhs = new types::List();
+
+        field->getHead()->accept(*this);
+        lhs->append(getList());
+
+        if (field->getTail()->isSimpleVar())
+        {
+            SimpleVar* pVar = field->getTail()->getAs<SimpleVar>();
+            lhs->append(createConst(new types::String(pVar->getSymbol().getName().c_str())));
+        }
+        else
+        {
+            //never occur ?
+            field->accept(*this);
+            lhs->append(getList());
+        }
+
+        ins->append(lhs);
+
+        //operator
+        ins->append(new types::String(L"ins"));
+        types::List* tmp = new types::List();
+        tmp->append(ins);
+        assign->append(tmp);
+    }
+
+    //verbose ?
+    assign->append(getVerbose(e));
+    l = assign;
+}
+
+void TreeVisitor::visit(const CallExp &e)
+{
+    types::TList* call = new types::TList();
+
+    //header
+    types::String* varstr = new types::String(1, 4);
+    varstr->set(0, L"funcall");
+    varstr->set(1, L"rhs");
+    varstr->set(2, L"name");
+    varstr->set(3, L"lhsnb");
+    call->append(varstr);
+
+    //rhs
+    types::List* rhs = new types::List();
+    for (auto arg : e.getArgs())
+    {
+        arg->accept(*this);
+        rhs->append(getList());
+    }
+    call->append(rhs);
+
+    //name
+    call->append(new types::String(e.getName().getAs<SimpleVar>()->getSymbol().getName().c_str()));
+
+    //lhsnb
+    //use default value 1
+    //parent exp like assign can adapt it.
+    call->append(new types::Double(1));
+
+    l = call;
+}
+
+void TreeVisitor::visit(const ForExp &e)
+{
+    types::TList* f = new types::TList();
+
+    //header
+    types::String* varstr = new types::String(1, 3);
+    varstr->set(0, L"for");
+    varstr->set(1, L"expression");
+    varstr->set(2, L"statements");
+    f->append(varstr);
+
+    //expression
+    //create a AssignExp to call visitor it
+    VarDec* vardec = e.getVardec().getAs<VarDec>();
+    SimpleVar* var = new SimpleVar(*vardec->getLocation().clone(), *new symbol::Symbol(vardec->getSymbol()));
+    Exp* init = vardec->getInit().clone();
+    AssignExp* assign = new AssignExp(*vardec->getLocation().clone(), *var, *init);
+    assign->setVerbose(true);
+
+    assign->accept(*this);
+    f->append(getList());
+    delete assign;
+
+    //statements
+    e.getBody().accept(*this);
+    f->append(getList());
+    l = f;
+}
+
+void TreeVisitor::visit(const FieldExp &e)
+{
+    types::List* ext = createOperation();
+    types::List* ope = new types::List();
+
+    //function or varname
+    e.getHead()->accept(*this);
+    ope->append(getList());
+
+    //arguments
+    if (e.getTail()->isSimpleVar())
+    {
+        const SimpleVar* pVar = e.getTail()->getAs<SimpleVar>();
+        ope->append(createConst(new types::String(pVar->getSymbol().getName().c_str())));
+    }
+    else
+    {
+        ope->append(getList());
+    }
+
+    //operator
+    ext->append(ope);
+    ext->append(new types::String(L"ext"));
+    l = ext;
+}
+
+void TreeVisitor::visit(const TryCatchExp &e)
+{
+    types::TList* tc = new types::TList();
+
+    //header
+    types::String* varstr = new types::String(1, 3);
+    varstr->set(0, L"trycatch");
+    varstr->set(1, L"trystat");
+    varstr->set(2, L"catchstat");
+    tc->append(varstr);
+
+    //trystat
+    e.getTry().accept(*this);
+    tc->append(getList());
+
+    //catchstat
+    e.getCatch().accept(*this);
+    tc->append(getList());
+
+    l = tc;
+}
+
+void TreeVisitor::visit(const WhileExp &e)
+{
+    types::TList* w = new types::TList();
+
+    //header
+    types::String* varstr = new types::String(1, 3);
+    varstr->set(0, L"while");
+    varstr->set(1, L"expression");
+    varstr->set(2, L"statements");
+    w->append(varstr);
+
+    //expression
+    e.getTest().accept(*this);
+    w->append(getList());
+
+    //statements
+    e.getBody().accept(*this);
+    w->append(getList());
+    l = w;
+}
+
+void TreeVisitor::visit(const ContinueExp &e)
+{
+    l = createVar(L"continue");
+}
+
+void TreeVisitor::visit(const BreakExp &e)
+{
+    l = createVar(L"break");
+}
+
+void TreeVisitor::visit(const ReturnExp &e)
+{
+    if (e.isGlobal())
+    {
+        l = createVar(L"resume");
+    }
+    else
+    {
+        types::List* ext = createOperation();
+        types::List* ope = new types::List();
+
+        //function or varname
+        ope->append(new types::String(L"return"));
+
+        //arguments
+        for (auto arg : e.getExp().getAs<ArrayListExp>()->getExps())
+        {
+            arg->accept(*this);
+            ope->append(getList());
+        }
+
+        //operator
+        ext->append(ope);
+        ext->append(new types::String(L"ext"));
+        l = ext;
+    }
+}
+
+void TreeVisitor::visit(const SelectExp &e)
+{
+    types::TList* select = new types::TList();
+
+    //header
+    types::String* varstr = new types::String(1, 4);
+    varstr->set(0, L"selectcase");
+    varstr->set(1, L"expression");
+    varstr->set(2, L"cases");
+    varstr->set(3, L"else");
+    select->append(varstr);
+
+    //expression
+    types::List* cond = new types::List();
+    e.getSelect()->accept(*this);
+    cond->append(getList());
+    cond->append(getEOL());
+    select->append(cond);
+
+
+    //cases
+    types::List* cases = new types::List();
+    for (auto c : *e.getCases())
+    {
+        c->accept(*this);
+        cases->append(getList());
+    }
+
+    select->append(cases);
+
+    //default
+    if (e.hasDefault())
+    {
+        e.getDefaultCase()->accept(*this);
+        select->append(getList());
+    }
+    else
+    {
+        select->append(new types::List());
+
+    }
+    l = select;
+}
+
+void TreeVisitor::visit(const CaseExp &e)
+{
+    types::TList* c = new types::TList();
+
+    //header
+    types::String* varstr = new types::String(1, 3);
+    varstr->set(0, L"case");
+    varstr->set(1, L"expression");
+    varstr->set(2, L"then");
+    c->append(varstr);
+
+    //expression
+    e.getTest()->accept(*this);
+    c->append(getList());
+
+    //then
+    e.getBody()->accept(*this);
+    c->append(getList());
+
+    l = c;
+}
+
+void TreeVisitor::visit(const ArrayListExp  &e)
+{
+    types::List* ext = createOperation();
+    types::List* ope = new types::List();
+
+    //function or varname
+    ope->append(new types::String(L""));
+
+    //arguments
+    for (auto arg : e.getExps())
+    {
+        arg->accept(*this);
+        ope->append(getList());
+    }
+
+    //operator
+    ext->append(ope);
+    ext->append(new types::String(L"ext"));
+    l = ext;
+}
+
+void TreeVisitor::visit(const NotExp  &e)
+{
+    types::List* ext = createOperation();
+    types::List* ope = new types::List();
+
+    //function or varname
+    e.getExp().accept(*this);
+    ope->append(getList());
+
+    //operator
+    ext->append(ope);
+    ext->append(new types::String(L"~"));
+    l = ext;
+}
+
+void TreeVisitor::visit(const TransposeExp  &e)
+{
+    types::List* ext = createOperation();
+    types::List* ope = new types::List();
+
+    //function or varname
+    e.getExp().accept(*this);
+    ope->append(getList());
+
+    //operator
+    ext->append(ope);
+    ext->append(new types::String(L"'"));
+    l = ext;
+}
+
+void TreeVisitor::visit(const FunctionDec  &e)
+{
+    //types::TList* function = new types::TList();
+
+    ////header
+    //types::String* varstr = new types::String(1, 3);
+    //varstr->set(0, L"inline");
+    //varstr->set(1, L"prototype");
+    //varstr->set(2, L"definition");
+    //function->append(varstr);
+
+    ////add returns
+    //std::wstring returns;
+    //returns += L"[";
+
+    //const ArrayListVar *pListRet = e.getReturns().getAs<ArrayListVar>();
+    //exps_t rets = pListRet->getVars();
+    //int idx = 0;
+    //for (auto ret : rets)
+    //{
+    //    if (idx > 0)
+    //    {
+    //        returns += L", ";
+    //    }
+
+    //    SimpleVar* s = ret->getAs<SimpleVar>();
+    //    returns += s->getSymbol().getName();
+    //    ++idx;
+    //}
+    //
+    l = new types::List();
+}
+
+types::InternalType* TreeVisitor::getEOL()
+{
+    if (eol)
+    {
+        return eol;
+    }
+
+    eol = new types::List();
+    eol->append(new types::String(L"EOL"));
+    return eol;
+}
+
+types::List* TreeVisitor::createVar(const std::wstring& str)
+{
+    types::TList* var = new types::TList();
+    types::String* varstr = new types::String(1, 2);
+    varstr->set(0, L"variable");
+    varstr->set(1, L"name");
+    var->append(varstr);
+    var->append(new types::String(str.c_str()));
+    return var;
+}
+
+types::List* TreeVisitor::createConst(types::InternalType* pIT)
+{
+    types::TList* var = new types::TList();
+    types::String* varstr = new types::String(1, 2);
+    varstr->set(0, L"cste");
+    varstr->set(1, L"value");
+    var->append(varstr);
+    var->append(pIT);
+    return var;
+}
+
+types::List* TreeVisitor::createOperation()
+{
+    types::TList* var = new types::TList();
+    types::String* varstr = new types::String(1, 3);
+    varstr->set(0, L"operation");
+    varstr->set(1, L"operands");
+    varstr->set(2, L"operator");
+    var->append(varstr);
+    return var;
+}
+
+types::List* TreeVisitor::createAssign()
+{
+    types::TList* var = new types::TList();
+    types::String* varstr = new types::String(1, 4);
+    varstr->set(0, L"equal");
+    varstr->set(1, L"expression");
+    varstr->set(2, L"lhs");
+    varstr->set(3, L"endsymbol");
+    var->append(varstr);
+    return var;
+}
+
+types::InternalType* TreeVisitor::getVerbose(const Exp& e)
+{
+    if (e.isVerbose())
+    {
+        return new types::String(L"");
+    }
+    else
+    {
+        return new types::String(L";");
+    }
+}
+}
\ No newline at end of file
index 74e24dd..d5f3770 100644 (file)
@@ -142,13 +142,31 @@ bool TList::invoke(typed_list & in, optional_list & /*opt*/, int _iRetCount, typ
     this->IncreaseRef();
     in.push_back(this);
 
+    std::wstring stType = getShortTypeStr();
     try
     {
-        ret = Overload::call(L"%" + getShortTypeStr() + L"_e", in, _iRetCount, out, &execFunc);
+        ret = Overload::call(L"%" + stType + L"_e", in, _iRetCount, out, &execFunc);
     }
-    catch (ast::ScilabError & /*se*/)
+    catch (ast::ScilabError &se)
     {
-        ret = Overload::call(L"%l_e", in, 1, out, &execFunc);
+        try
+        {
+            //to compatibility with scilab 5 code.
+            //tlist/mlist name are truncated to 8 first character
+            if (stType.size() > 8)
+            {
+                std::wcout << (L"%" + stType.substr(0, 8) + L"_e") << std::endl;
+                ret = Overload::call(L"%" + stType.substr(0, 8) + L"_e", in, 1, out, &execFunc);
+            }
+            else
+            {
+                throw se;
+            }
+        }
+        catch (ast::ScilabError & /*se*/)
+        {
+            ret = Overload::call(L"%l_e", in, 1, out, &execFunc);
+        }
     }
 
     // Remove this from "in" for keep "in" unchanged.
index c9a1a9a..72465f9 100644 (file)
@@ -172,7 +172,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_getmemory.cpp \
        sci_gateway/cpp/sci_errclear.cpp \
        sci_gateway/cpp/sci_intppty.cpp \
-       sci_gateway/cpp/sci_analyzeroptions.cpp
+       sci_gateway/cpp/sci_analyzeroptions.cpp \
+       sci_gateway/cpp/sci_macr2tree.cpp
 
 libscicore_la_CPPFLAGS = \
     -I$(srcdir)/includes/ \
index eedd031..e9c22d3 100644 (file)
@@ -317,7 +317,8 @@ am__objects_5 = sci_gateway/cpp/libscicore_la-core_gw.lo \
        sci_gateway/cpp/libscicore_la-sci_getmemory.lo \
        sci_gateway/cpp/libscicore_la-sci_errclear.lo \
        sci_gateway/cpp/libscicore_la-sci_intppty.lo \
-       sci_gateway/cpp/libscicore_la-sci_analyzeroptions.lo
+       sci_gateway/cpp/libscicore_la-sci_analyzeroptions.lo \
+       sci_gateway/cpp/libscicore_la-sci_macr2tree.lo
 am_libscicore_la_OBJECTS = $(am__objects_4) $(am__objects_5)
 libscicore_la_OBJECTS = $(am_libscicore_la_OBJECTS)
 libscicore_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
@@ -871,7 +872,8 @@ GATEWAY_CPP_SOURCES = \
        sci_gateway/cpp/sci_getmemory.cpp \
        sci_gateway/cpp/sci_errclear.cpp \
        sci_gateway/cpp/sci_intppty.cpp \
-       sci_gateway/cpp/sci_analyzeroptions.cpp
+       sci_gateway/cpp/sci_analyzeroptions.cpp \
+       sci_gateway/cpp/sci_macr2tree.cpp
 
 libscicore_la_CPPFLAGS = -I$(srcdir)/includes/ -I$(srcdir)/src/c/ \
        -I$(srcdir)/src/cpp/ -I$(top_srcdir)/modules/ast/includes/ast/ \
@@ -1526,6 +1528,9 @@ sci_gateway/cpp/libscicore_la-sci_intppty.lo:  \
 sci_gateway/cpp/libscicore_la-sci_analyzeroptions.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscicore_la-sci_macr2tree.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 
 libscicore.la: $(libscicore_la_OBJECTS) $(libscicore_la_DEPENDENCIES) $(EXTRA_libscicore_la_DEPENDENCIES) 
        $(AM_V_CXXLD)$(libscicore_la_LINK) $(am_libscicore_la_rpath) $(libscicore_la_OBJECTS) $(libscicore_la_LIBADD) $(LIBS)
@@ -1579,6 +1584,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_intppty.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_isglobal.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_lasterror.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_macr2tree.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_mode.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_newfun.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_pause.Plo@am__quote@
@@ -2445,6 +2451,13 @@ sci_gateway/cpp/libscicore_la-sci_analyzeroptions.lo: sci_gateway/cpp/sci_analyz
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscicore_la-sci_analyzeroptions.lo `test -f 'sci_gateway/cpp/sci_analyzeroptions.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_analyzeroptions.cpp
 
+sci_gateway/cpp/libscicore_la-sci_macr2tree.lo: sci_gateway/cpp/sci_macr2tree.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscicore_la-sci_macr2tree.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_macr2tree.Tpo -c -o sci_gateway/cpp/libscicore_la-sci_macr2tree.lo `test -f 'sci_gateway/cpp/sci_macr2tree.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_macr2tree.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_macr2tree.Tpo sci_gateway/cpp/$(DEPDIR)/libscicore_la-sci_macr2tree.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_macr2tree.cpp' object='sci_gateway/cpp/libscicore_la-sci_macr2tree.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscicore_la-sci_macr2tree.lo `test -f 'sci_gateway/cpp/sci_macr2tree.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_macr2tree.cpp
+
 .f.o:
        $(AM_V_F77)$(F77COMPILE) -c -o $@ $<
 
index 6891b92..b3972f0 100644 (file)
@@ -67,5 +67,6 @@ CPP_GATEWAY_PROTOTYPE(sci_newfun);
 CPP_GATEWAY_PROTOTYPE(sci_clearfun);
 CPP_GATEWAY_PROTOTYPE(sci_funptr);
 CPP_GATEWAY_PROTOTYPE(sci_analyzeroptions);
+CPP_GATEWAY_PROTOTYPE(sci_macr2tree);
 
 #endif /* __CORE_GW_HXX__ */
index 1a6e292..c6304b4 100644 (file)
@@ -41,7 +41,6 @@ int C2F(sci_mtlb_mode)(char *fname, unsigned long fname_len);
 int C2F(sci_what)(char *fname, unsigned long fname_len);
 int C2F(sci_ieee)(char *fname, unsigned long fname_len);
 int C2F(sci_gstacksize)(char *fname, unsigned long fname_len);
-int C2F(sci_macr2tree)(char *fname, unsigned long fname_len);
 int C2F(sci_getos)(char *fname, unsigned long fname_len);
 int C2F(sci_fromjava)(char *fname, unsigned long fname_len);
 int C2F(sci_getmemory)(char *fname, unsigned long fname_len);
index d5e22bb..652919b 100644 (file)
@@ -62,5 +62,6 @@ int CoreModule::Load()
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"clearfun", &sci_clearfun, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"funptr", &sci_funptr, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(Function::createFunction(L"analyzerOptions", &sci_analyzeroptions, MODULE_NAME));
+    symbol::Context::getInstance()->addFunction(Function::createFunction(L"macr2tree", &sci_macr2tree, MODULE_NAME));
     return 1;
 }
index a2603fa..a8556e1 100644 (file)
     <ClCompile Include="sci_funptr.cpp" />
     <ClCompile Include="sci_getmemory.cpp" />
     <ClCompile Include="sci_ieee.cpp" />
+    <ClCompile Include="sci_macr2tree.cpp" />
     <ClCompile Include="sci_mode.cpp" />
     <ClCompile Include="sci_newfun.cpp" />
     <ClCompile Include="sci_sciargs.cpp" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
index b5c2620..1234be1 100644 (file)
     <ClCompile Include="sci_analyzeroptions.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="sci_macr2tree.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\banner.hxx">
diff --git a/scilab/modules/core/sci_gateway/cpp/sci_macr2tree.cpp b/scilab/modules/core/sci_gateway/cpp/sci_macr2tree.cpp
new file mode 100644 (file)
index 0000000..d83ae68
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2010 - DIGITEO- Antoine ELIAS
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+#include "core_gw.hxx"
+#include "function.hxx"
+#include "macro.hxx"
+#include "macrofile.hxx"
+#include "tlist.hxx"
+#include "string.hxx"
+#include "configvariable.hxx"
+#include "treevisitor.hxx"
+
+extern "C"
+{
+#include "localization.h"
+#include "Scierror.h"
+}
+/*--------------------------------------------------------------------------*/
+
+types::Function::ReturnValue sci_macr2tree(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    if (in.size() != 1)
+    {
+        Scierror(999, _("%s: Wrong number of input argument(s): %d expected."), "macr2tree", 1);
+        return types::Function::Error;
+    }
+
+    if (_iRetCount != 1)
+    {
+        Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "macr2tree", 1);
+        return types::Function::Error;
+    }
+
+    types::InternalType* pIT = in[0];
+    if (pIT->isMacro() == false && pIT->isMacroFile() == false)
+    {
+        Scierror(999, _("%s: Wrong type for input argument #%d: macro expected.\n"), "macr2tree", 1);
+        return types::Function::Error;
+    }
+
+    types::Macro* macro = NULL;
+    if (pIT->isMacroFile())
+    {
+        types::MacroFile* pMF = pIT->getAs<types::MacroFile>();
+        macro = pMF->getMacro();
+    }
+    else
+    {
+        macro = pIT->getAs<types::Macro>();
+    }
+
+    std::list<symbol::Variable*>* outputs = macro->outputs_get();
+    std::list<symbol::Variable*>* inputs = macro->inputs_get();
+    ast::SeqExp* body = macro->getBody();
+
+    //create a tlist "program"
+    types::TList* l = new types::TList();
+    types::String* s = new types::String(1, 6);
+    s->set(0, L"program");
+    s->set(1, L"name");
+    s->set(2, L"outputs");
+    s->set(3, L"inputs");
+    s->set(4, L"statements");
+    s->set(5, L"nblines");
+
+    //header
+    l->append(s);
+    //name
+    l->append(new types::String(macro->getName().c_str()));
+
+    //outputs
+    types::List* o = new types::List();
+    for (auto p : *outputs)
+    {
+        o->append(ast::TreeVisitor::createVar(p->getSymbol().getName()));
+    }
+
+    l->append(o);
+
+    //inputs
+    types::List* i = new types::List();
+    for (auto p : *inputs)
+    {
+        i->append(ast::TreeVisitor::createVar(p->getSymbol().getName()));
+    }
+
+    l->append(i);
+    //statement
+    ast::TreeVisitor v;
+    body->accept(v);
+    //add fake return
+    types::List* statement = v.getList();
+
+    types::TList* funcall = new types::TList();
+    types::String* sf = new String(1, 4);
+    sf->set(0, L"funcall");
+    sf->set(1, L"rhs");
+    sf->set(2, L"name");
+    sf->set(3, L"lhsnb");
+
+    funcall->append(sf);
+    funcall->append(types::Double::Empty());
+    funcall->append(new types::String(L"return"));
+    funcall->append(new types::Double(0));
+
+    statement->append(funcall);
+
+    statement->append(v.getEOL());
+
+    l->append(v.getList());
+    //nb lines
+    l->append(new types::Double(body->getLocation().last_line - body->getLocation().first_line + 1));
+    out.push_back(l);
+    return types::Function::OK;
+}
\ No newline at end of file
index 28b6c9e..d8df8f3 100644 (file)
                         <term>insert</term>
                         <listitem>
                             <para>
-                                allows to insert instructions. Calling sequence:<literal> insert(Equal(...),opt)</literal> with <literal>opt~=1</literal>  to insert before current instruction and <literal> opt=1</literal>  to insert after it.
+                                allows to insert instructions. Calling sequence:<literal> m2sci_insert(Equal(...),opt)</literal> with <literal>opt~=1</literal>  to insert before current instruction and <literal> opt=1</literal>  to insert after it.
                             </para>
                         </listitem>
                     </varlistentry>
index f6cf285..bd4d7ee 100644 (file)
                     <varlistentry>
                         <term>insert</term>
                         <listitem>
-                            <para>permet d'insérer des instruction. Séquence d'appel : insert(Equal(...),opt) avec opt~=1 pour insérer avan tl'instruction courante et opt=1 pour insérer après celle-ci.</para>
+                            <para>permet d'insérer des instruction. Séquence d'appel : m2sci_insert(Equal(...),opt) avec opt~=1 pour insérer avan tl'instruction courante et opt=1 pour insérer après celle-ci.</para>
                         </listitem>
                     </varlistentry>
                     <varlistentry>
index d742b69..785e7ff 100644 (file)
@@ -22,7 +22,6 @@ function eq=Equal(lhslist,expression,endsymbol)
         error(msprintf(gettext("lhslist should be a list and not a: %s."),typeof(lhslist)));
     end
     if and(typeof(expression)<>["funcall","cste","operation","variable"]) then
-        disp(expression)
         error(msprintf(gettext("expression can not be a: %s."),typeof(expression)))
     end
     if type(endsymbol)<>10 then
index 5ad16a0..23e6077 100644 (file)
@@ -18,7 +18,17 @@ function r=is_a_scalar(A)
     for k=1:n
         if A.dims(k)<>1 then
             r=%F
-            return
+            //return
         end
     end
 endfunction
+
+
+function a = toto()
+a = %T;
+if 1 then
+a = %F;
+return
+end
+a = %T;
+endfunction
@@ -7,8 +7,7 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-function []=insert(instr,opt)
-
+function []=m2sci_insert(instr,opt)
     // Global variables for M2SCI
     global("m2sci_to_insert_b")
     global("m2sci_to_insert_a")
@@ -23,4 +22,5 @@ function []=insert(instr,opt)
     else
         m2sci_to_insert_a($+1)=instr
     end
+
 endfunction
index d9f5aca..fbce369 100644 (file)
@@ -226,7 +226,7 @@ function [helppart,txt,batch]=m2sci_syntax(txt)
                 end
                 com=";m2scideclare("+quote+part(com,13:length(com))+quote+")"
             else
-                com=";//"+com
+                com=" //"+com
             end
             tkbeg=part(tk,1:kc-1)
 
index 4748eec..7c76c3b 100644 (file)
@@ -65,27 +65,28 @@ function [scitree,crp]=mtlbtree2sci(mtlbtree,prettyprintoutput)
         crp=lhsstr+" = "+scitree.name+rhsstr;
     end
 
+
     // Convert Matlab instruction tree to Scilab
     while ninstr<=size(mtlbtree.statements)-3
         //Case : sup_equal instruction
         // Add converted tree to scitree and also inserted instructions
         if typeof(mtlbtree.statements(ninstr))=="sup_equal"
 
-            sci_stat=list()
+            sci_stat=list();
             for i=1:size(mtlbtree.statements(ninstr).sup_instr)
-                [converted_tree,nblines]=instruction2sci(mtlbtree.statements(ninstr).sup_instr(i),nblines)
+                [converted_tree,nblines]=instruction2sci(mtlbtree.statements(ninstr).sup_instr(i),nblines);
 
-                sci_stat=update_instr_list(sci_stat,converted_tree)
+                sci_stat=update_instr_list(sci_stat,converted_tree);
             end
 
-            scitree.statements($+1)=tlist(["sup_equal","sup_instr","nb_opr"],sci_stat,mtlbtree.statements(ninstr).nb_opr)
+            scitree.statements($+1)=tlist(["sup_equal","sup_instr","nb_opr"],sci_stat,mtlbtree.statements(ninstr).nb_opr);
         else
 
-            [converted_tree,nblines]=instruction2sci(mtlbtree.statements(ninstr),nblines)
+            [converted_tree,nblines]=instruction2sci(mtlbtree.statements(ninstr),nblines);
 
             // Add converted tree to scitree and also inserted instructions
 
-            scitree.statements=update_instr_list(scitree.statements,converted_tree)
+            scitree.statements=update_instr_list(scitree.statements,converted_tree);
 
             // Generate code corresponding to scitree.statements
         end
@@ -96,12 +97,12 @@ function [scitree,crp]=mtlbtree2sci(mtlbtree,prettyprintoutput)
             end
         end
 
-        scitree.statements=list(scitree.statements($))
+        scitree.statements=list(scitree.statements($));
 
         // Disp percentage of conversion done
-        msprintf(gettext("%s line %s out of %s..."),margin, string(nblines), string(mtlbtree.nblines))
-        ninstr=ninstr+1
-        tmpvarnb=0
+        msprintf(gettext("%s line %s out of %s..."),margin, string(nblines), string(mtlbtree.nblines));
+        ninstr=ninstr+1;
+        tmpvarnb=0;
     end
 
     if scitree.statements(1)<>list("EOL") then
index cade504..543f402 100644 (file)
@@ -193,12 +193,17 @@ function res=mfile2sci(fil,res_path,Recmode,only_double,verbose_mode,prettyprint
         if isempty(kpar) then
             kpar=length(func_proto)+1
         end
-        func_proto=part(func_proto,1:keq)+..
-        strsubst(stripblanks(part(func_proto,keq+1:kpar-1))," ","_")+..
-        part(func_proto,kpar:length(func_proto))
 
+        func_proto=part(func_proto,1:keq)+strsubst(stripblanks(part(func_proto,keq+1:kpar-1))," ","_")+part(func_proto,kpar:length(func_proto))
+
+        wold = who("get");
         deff(func_proto,[firstline;txt(2:$)],"n")
-        w=who("get");
+        w = who("get");
+        w(find(w == "deff")) = [];
+        w(find(w == "wold")) = [];
+        for i=1:size(wold, "*")
+            w(find(w == wold(i))) = [];
+        end
         mname=w(1);
         nametbl=[nametbl;mname]
         if fnam<>mname & ~batch then // warning is not displayed for a batch file
index 89cf5ad..8e77479 100644 (file)
@@ -34,8 +34,8 @@ function [tree]=%g2sci(tree)
             varslist($+1)=M2scivar(tree.out(1).name,tree.out(1).name,Infer(list(1,1),Type(Boolean,Real)))
             tree=list()
         end
-        insert(Equal(list(tmp),Cste(%T)))
-        insert(tlist(["ifthenelse","expression","then","elseifs","else"],Operation("~",list(A.operands(1)),list()),list(Equal(list(tmp),A.operands(2))),list(),list()))
+        m2sci_insert(Equal(list(tmp),Cste(%T)))
+        m2sci_insert(tlist(["ifthenelse","expression","then","elseifs","else"],Operation("~",list(A.operands(1)),list()),list(Equal(list(tmp),A.operands(2))),list(),list()))
         return
     end
 
index 4a43049..7cf8161 100644 (file)
@@ -34,8 +34,8 @@ function [tree]=%h2sci(tree)
             varslist($+1)=M2scivar(tree.out(1).name,tree.out(1).name,Infer(list(1,1),Type(Boolean,Real)))
             tree=list()
         end
-        insert(Equal(list(tmp),Cste(%F)))
-        insert(tlist(["ifthenelse","expression","then","elseifs","else"],A.operands(1),list(Equal(list(tmp),A.operands(2))),list(),list()))
+        m2sci_insert(Equal(list(tmp),Cste(%F)))
+        m2sci_insert(tlist(["ifthenelse","expression","then","elseifs","else"],A.operands(1),list(Equal(list(tmp),A.operands(2))),list(),list()))
         return
     end
 
index 27a6960..24f7285 100644 (file)
@@ -64,7 +64,7 @@ function [tree]=%i2sci(tree)
             if bval then
                 varslist(index).infer.dims=allunknown(to.dims)
             end
-            insert(Equal(list(to),Funcall("mtlb_is",1,Rhs_tlist(to,from,ind),list(to))),1)
+            m2sci_insert(Equal(list(to),Funcall("mtlb_is",1,Rhs_tlist(to,from,ind),list(to))),1)
             // --- Insertion with just one index ---
         elseif type(ind)<>15 then
             if ind.vtype==String then
@@ -113,7 +113,7 @@ function [tree]=%i2sci(tree)
                                 break
                             end
                         end
-                        insert(Equal(list(to),list(from)))
+                        m2sci_insert(Equal(list(to),list(from)))
                     end
                 end
                 tree.out(1).dims=list(Unknown,1)
@@ -153,7 +153,7 @@ function [tree]=%i2sci(tree)
             if bval then
                 varslist(index).infer.dims=allunknown(to.dims)
             end
-            insert(Equal(list(to),Funcall("mtlb_is",1,Rhs_tlist(to,from,tree.operands(2),tree.operands(3)),list(to))),1)
+            m2sci_insert(Equal(list(to),Funcall("mtlb_is",1,Rhs_tlist(to,from,tree.operands(2),tree.operands(3)),list(to))),1)
         else
             tree.out(1).dims=list()
             for k=1:lstsize(tree.operands)-2
index 344bf6d..9be4202 100644 (file)
@@ -24,7 +24,7 @@ function [tree]=%i2sci_c(tree)
     else
         if ~isdefinedvar(from) then
             w=gettempvar()
-            insert(Equal(list(w),from))
+            m2sci_insert(Equal(list(w),from))
         else
             w=from
         end
index 380e620..05dfd61 100644 (file)
@@ -18,7 +18,7 @@ function [tree]=%i2sci_g(tree)
     ind=tree.operands(2)
 
     newtree=Funcall("mtlb_i",1,Rhs_tlist(to,ind,from),list(to))
-    insert(Equal(list(to),newtree))
+    m2sci_insert(Equal(list(to),newtree))
     tree=list()
 endfunction
 
index 37f1322..8325bfd 100644 (file)
@@ -24,7 +24,7 @@ function [tree]=%i2sci_r(tree)
     else
         if ~isdefinedvar(from) then
             w=gettempvar()
-            insert(Equal(list(w),from))
+            m2sci_insert(Equal(list(w),from))
         else
             w=from
         end
index 2c3fbcd..7202f53 100644 (file)
@@ -30,7 +30,7 @@ function [tree]=%i_ce2sci(tree)
     if to.vtype<>Struct then
         if and(to.vtype<>[Cell,Unknown]) then
             if to.vtype==Double & and(to.dims==list(0,0)) then
-                insert(Equal(list(to),Funcall("cell",1,list(),list(to))))
+                m2sci_insert(Equal(list(to),Funcall("cell",1,list(),list(to))))
                 // To be sure that variable will now be of type Cell
                 [bval,index]=isdefinedvar(to)
                 varslist(index).infer.type.vtype=Cell
@@ -38,7 +38,7 @@ function [tree]=%i_ce2sci(tree)
                 error(msprintf(gettext("destination variable is not a cell: %s is of type %s."),to.name,string(to.vtype)))
             end
         elseif to.vtype==Unknown then
-            insert(Equal(list(to),Funcall("cell",1,list(),list(to))))
+            m2sci_insert(Equal(list(to),Funcall("cell",1,list(),list(to))))
             // To be sure that variable will now be of type Cell
             [bval,index]=isdefinedvar(to)
             varslist(index).infer.type.vtype=Cell
index f25e8a7..48dfeec 100644 (file)
@@ -30,7 +30,7 @@ if rhs==1 then
     // All output dims are unknown
     tree.lhs(1).dims=allunknown(A.dims)
     tmp=gettempvar()
-    insert(Equal(list(tmp),A))
+    m2sci_insert(Equal(list(tmp),A))
     // First non singleton dimension will be computed at execution
     tree.rhs=Rhs_tlist(tmp,Funcall("firstnonsingleton",1,list(tmp),list()))
   else
index 8142821..03a201c 100644 (file)
@@ -26,17 +26,17 @@ if lhs==1 then
   else
     tree.lhs=list(V,S)
   end
-  insert(Equal(tree.lhs,tree))
+  m2sci_insert(Equal(tree.lhs,tree))
   tree=list()
   
   if rhs==2 then
-    insert(Equal(list(),Funcall("disp",1,list(S),list())),1)
+    m2sci_insert(Equal(list(),Funcall("disp",1,list(S),list())),1)
   end
 else
   tree.lhs=list(tree.lhs($:-1:1))
 
   if rhs==2 then
-    insert(Equal(list(),Funcall("disp",1,list(tree.lhs(1),tree.lhs(2)),list())),1)
+    m2sci_insert(Equal(list(),Funcall("disp",1,list(tree.lhs(1),tree.lhs(2)),list())),1)
   end
 
   tree.lhs(1).dims=list(Unknown,Unknown)
index 7417d7c..f63d0e1 100644 (file)
@@ -25,7 +25,7 @@ else // Number of arguments of M-file
   else
     fieldnb=2
   end
-  set_infos(msprintf(gettext("%s considered to be a Scilab macro."),rhs2code(tree.rhs)),2);
+  set_infos(msprintf(gettext("%s considered to be a Scilab macro."), strcat(rhs2code(tree.rhs), "")),2);
   evstrtree=Funcall("evstr",1,tree.rhs,list())
   macrovartree=Funcall("macrovar",1,Rhs_tlist(evstrtree),list())
   getfieldtree=Funcall("getfield",1,Rhs_tlist(fieldnb,macrovartree),list())
index 8281759..9486b42 100644 (file)
@@ -104,7 +104,7 @@ if rhs==1 then
     tmp=n
     if typeof(n)<>"variable" then
       tmp=gettempvar()
-      insert(Equal(list(tmp),n))
+      m2sci_insert(Equal(list(tmp),n))
     end
     newrhs=list()
     for k=1:size(n.dims)
index 6e67b2c..22717eb 100644 (file)
@@ -19,9 +19,9 @@ A=convert2double(A)
 tree.rhs=Rhs_tlist(A)
 
 if tree.name=="atan" then
-  set_infos(msprintf(gettext("If %s is outside [-1,1]\n   real part of output of %s will be the opposite of Matlab one."),expression2code(A),expression2code(tree)),2)
+  set_infos(msprintf(gettext("If %s is outside [-1,1]\n   real part of output of %s will be the opposite of Matlab one."), strcat(expression2code(A), ""), strcat(expression2code(tree), "")),2)
 else
-  set_infos(msprintf(gettext("If %s is outside [-1,1]\n   complex part of output of %s will be the opposite of Matlab one."),expression2code(A),expression2code(tree)),2)
+  set_infos(msprintf(gettext("If %s is outside [-1,1]\n   complex part of output of %s will be the opposite of Matlab one."), strcat(expression2code(A), ""), strcat(expression2code(tree), "")),2)
 end
 
 tree.lhs(1).dims=A.dims
index 9b27c22..90dae20 100644 (file)
@@ -16,7 +16,7 @@ function tree=sci_acoth(tree)
     X=getrhs(tree)
     X=convert2double(X)
 
-    set_infos(msprintf(gettext("If %s is outside [-1,1]\n   complex part of output of %s will be the opposite of Matlab one."),expression2code(X),expression2code(tree)),2)
+    set_infos(msprintf(gettext("If %s is outside [-1,1]\n   complex part of output of %s will be the opposite of Matlab one."), strcat(expression2code(X), ""), strcat(expression2code(tree), "")),2)
 
     tree.name="atanh"
     Op=Operation("./",list(Cste(1),X),list())
index 1528b64..7d29c73 100644 (file)
@@ -20,7 +20,7 @@ function tree=sci_angle(tree)
         n=A
     else
         n=gettempvar()
-        insert(Equal(list(n),A))
+        m2sci_insert(Equal(list(n),A))
     end
 
     realpart=Funcall("real",1,list(n),list())
index 052da34..7519b3b 100644 (file)
@@ -19,9 +19,9 @@ function [tree]=sci_asin(tree)
     tree.rhs=Rhs_tlist(A)
 
     if tree.name=="atan" then
-        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   real part of output of %s will be the opposite of Matlab one."),expression2code(A),expression2code(tree)),2)
+        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   real part of output of %s will be the opposite of Matlab one."),strcat(expression2code(A), ""), strcat(expression2code(tree), "")),2)
     else
-        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   complex part of output of %s will be the opposite of Matlab one."),expression2code(A),expression2code(tree)),2)
+        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   complex part of output of %s will be the opposite of Matlab one."),strcat(expression2code(A), ""),strcat(expression2code(tree), "")),2)
     end
 
     tree.lhs(1).dims=A.dims
index 687f200..c95a871 100644 (file)
@@ -19,9 +19,9 @@ function [tree]=sci_atan(tree)
     tree.rhs=Rhs_tlist(A)
 
     if tree.name=="atan" then
-        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   real part of output of %s will be the opposite of Matlab one."),expression2code(A),expression2code(tree)),2)
+        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   real part of output of %s will be the opposite of Matlab one."), strcat(expression2code(A), ""), strcat(expression2code(tree), "")),2)
     else
-        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   complex part of output of %s will be the opposite of Matlab one."),expression2code(A),expression2code(tree)),2)
+        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   complex part of output of %s will be the opposite of Matlab one."), strcat(expression2code(A), ""), strcat(expression2code(tree), "")),2)
     end
 
     tree.lhs(1).dims=A.dims
index 5470460..632dc2f 100644 (file)
@@ -19,9 +19,9 @@ function [tree]=sci_atanh(tree)
     tree.rhs=Rhs_tlist(A)
 
     if tree.name=="atan" then
-        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   real part of output of %s will be the opposite of Matlab one."),expression2code(A),expression2code(tree)),2)
+        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   real part of output of %s will be the opposite of Matlab one."), strcat(expression2code(A), ""), strcat(expression2code(tree), "")),2)
     else
-        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   complex part of output of %s will be the opposite of Matlab one."),expression2code(A),expression2code(tree)),2)
+        set_infos(msprintf(gettext("If %s is outside [-1,1]\n   complex part of output of %s will be the opposite of Matlab one."), strcat(expression2code(A), ""), strcat(expression2code(tree), "")),2)
     end
 
     tree.lhs(1).dims=A.dims
index 8fa05e4..628786b 100644 (file)
@@ -26,7 +26,7 @@ function [tree]=sci_balance(tree)
         if tree.lhs(1).name=="ans" then
             B=gettempvar(1)
             T=gettempvar(2)
-            insert(Equal(list(B,T),tree))
+            m2sci_insert(Equal(list(B,T),tree))
             tree=B
         else
             T=gettempvar(2)
index f1a900e..3baa213 100644 (file)
@@ -20,14 +20,14 @@ function [tree]=sci_beta(tree)
 
     if is_a_scalar(A) & not_a_scalar(B) then // A is a scalar but not B
         n=gettempvar()
-        insert(Equal(list(n),B))
-        insert(Equal(list(Operation("ins",list(n,Cste(":")),list())),A))
+        m2sci_insert(Equal(list(n),B))
+        m2sci_insert(Equal(list(Operation("ins",list(n,Cste(":")),list())),A))
         tree.rhs(1)=n
         tree.lhs(1).dims=B.dims
     elseif is_a_scalar(B) & not_a_scalar(A) then // B is be a scalar but not A
         n=gettempvar()
-        insert(Equal(list(n),A))
-        insert(Equal(list(Operation("ins",list(n,Cste(":")),list())),B))
+        m2sci_insert(Equal(list(n),A))
+        m2sci_insert(Equal(list(Operation("ins",list(n,Cste(":")),list())),B))
         tree.rhs(2)=n
         tree.lhs(1).dims=A.dims
     elseif is_a_scalar(A) & is_a_scalar(B) then // Both A and B are scalars
index b8b7387..e243bf8 100644 (file)
@@ -18,7 +18,7 @@ function [tree]=sci_blanks(tree)
 
     if ~is_a_scalar(A) & typeof(A)<>"variable" then
         n=gettempvar()
-        insert(Equal(list(n),A))
+        m2sci_insert(Equal(list(n),A))
         B=Operation("ext",list(n,Cste(1)),list())
         repl_poss(B,..
         A,A,gettext("is a scalar."))
index bdf9533..269419d 100644 (file)
@@ -20,10 +20,10 @@ function [tree]=sci_box(tree)
     elseif rhs==1 then
         if typeof(tree.rhs(1))=="cste" then
             a=gettempvar()
-            insert(Equal(list(a),Funcall("gca",1,list(),list())))
+            m2sci_insert(Equal(list(a),Funcall("gca",1,list(),list())))
 
             LHS=Operation("ins",list(a,Cste("box")),list())
-            insert(Equal(list(LHS),Cste(convstr(tree.rhs(1).value,"l"))))
+            m2sci_insert(Equal(list(LHS),Cste(convstr(tree.rhs(1).value,"l"))))
 
             tree=list()
         else
@@ -34,7 +34,7 @@ function [tree]=sci_box(tree)
     else
         if typeof(tree.rhs(2))=="cste" then
             LHS=Operation("ins",list(tree.rhs(1),Cste("box")),list())
-            insert(Equal(list(LHS),Cste(convstr(tree.rhs(2).value,"l"))))
+            m2sci_insert(Equal(list(LHS),Cste(convstr(tree.rhs(2).value,"l"))))
 
             tree=list()
         else
index 40ddc4a..f7ddd17 100644 (file)
@@ -19,7 +19,7 @@ function [tree]=sci_cla(tree)
 
     // a=gca()
     a=gettempvar()
-    insert(Equal(list(a),Funcall("gca",1,list(),list())))
+    m2sci_insert(Equal(list(a),Funcall("gca",1,list(),list())))
 
     tree.name="delete"
     tree.rhs=list(Operation("ext",list(a,Cste("children")),list()))
index 223749a..a30f0de 100644 (file)
@@ -23,7 +23,7 @@ function [tree]=sci_clf(tree)
     // f=gcf() inserted if output value stored in a variable
     if tree.lhs(1).name<>"ans" then
         f=tree.lhs(1)
-        insert(Equal(list(f),Funcall("gcf",1,list(),list())),1)
+        m2sci_insert(Equal(list(f),Funcall("gcf",1,list(),list())),1)
     end
     tree.lhs(1).name="ans"
 endfunction
index a20d8f3..0dd7f9d 100644 (file)
@@ -19,12 +19,12 @@ function [tree]=sci_clock(tree)
     row=Operation("rc",list(elt1,elt2),list())
 
     // w = getdate();
-    insert(Equal(list(w),Funcall("getdate",1,list(),list())))
+    m2sci_insert(Equal(list(w),Funcall("getdate",1,list(),list())))
 
     // w(3:5)=[] (then w with 7 values)
     imp=Operation(":",list(Cste(3),Cste(5)),list())
     w35=Operation("ins",list(w,imp),list())
-    insert(Equal(list(w35),Cste([])))
+    m2sci_insert(Equal(list(w35),Cste([])))
 
     // w(6)=w(6)+w(7)/1000
     w7=Operation("ext",list(w,Cste(7)),list())
@@ -32,7 +32,7 @@ function [tree]=sci_clock(tree)
     w6ins=Operation("ext",list(w,Cste(6)),list())
     div=Operation("/",list(w7,Cste(1000)),list())
     add=Operation("+",list(w6ext,div),list())
-    insert(Equal(list(w6ins),add))
+    m2sci_insert(Equal(list(w6ins),add))
 
     // c= w(1:6)
     imp=Operation(":",list(Cste(1),Cste(6)),list())
index 441eb70..374677f 100644 (file)
@@ -23,14 +23,14 @@ function [tree]=sci_colordef(tree)
     if rhs==1 then
         if typeof(tree.rhs(1))=="cste" then
             if or(tree.rhs(1).value==["black","none"]) then
-                insert(Equal(list(f),Funcall("gcf",1,list(),list())))
+                m2sci_insert(Equal(list(f),Funcall("gcf",1,list(),list())))
                 LHS=Operation("ins",list(f,Cste("background")),list())
-                insert(Equal(list(LHS),Cste(-1)))
+                m2sci_insert(Equal(list(LHS),Cste(-1)))
                 tree=list()
             elseif tree.rhs(1).value=="white" then
-                insert(Equal(list(f),Funcall("gcf",1,list(),list())))
+                m2sci_insert(Equal(list(f),Funcall("gcf",1,list(),list())))
                 LHS=Operation("ins",list(f,Cste("background")),list())
-                insert(Equal(list(LHS),Cste(-2)))
+                m2sci_insert(Equal(list(LHS),Cste(-2)))
                 tree=list()
             else
                 no_equiv(expression2code(tree))
@@ -45,14 +45,14 @@ function [tree]=sci_colordef(tree)
             max_funcall=Funcall("max",1,list(winsid_funcall),list())
             addition=Operation("+",list(max_funcall,Cste(1)),list())
             scf_funcall=Funcall("scf",1,list(addition),list())
-            insert(Equal(list(f),scf_funcall))
+            m2sci_insert(Equal(list(f),scf_funcall))
             if or(tree.rhs(2).value==["black","none"]) then
                 LHS=Operation("ins",list(f,Cste("background")),list())
-                insert(Equal(list(LHS),Cste(-1)))
+                m2sci_insert(Equal(list(LHS),Cste(-1)))
                 tree=list()
             elseif tree.rhs(2).value=="white" then
                 LHS=Operation("ins",list(f,Cste("background")),list())
-                insert(Equal(list(LHS),Cste(-2)))
+                m2sci_insert(Equal(list(LHS),Cste(-2)))
                 tree=list()
             else
                 no_equiv(expression2code(tree))
@@ -63,16 +63,16 @@ function [tree]=sci_colordef(tree)
             f=tree.rhs(1)
             if or(tree.rhs(2).value==["black","none"]) then
                 LHS=Operation("ins",list(f,Cste("background")),list())
-                insert(Equal(list(LHS),Cste(-1)))
+                m2sci_insert(Equal(list(LHS),Cste(-1)))
                 if tree.lhs(1).name<>"ans" then
-                    insert(Equal(list(tree.lhs(1)),f))
+                    m2sci_insert(Equal(list(tree.lhs(1)),f))
                 end
                 tree=list()
             elseif tree.rhs(2).value=="white" then
                 LHS=Operation("ins",list(f,Cste("background")),list())
-                insert(Equal(list(LHS),Cste(-2)))
+                m2sci_insert(Equal(list(LHS),Cste(-2)))
                 if tree.lhs(1).name<>"ans" then
-                    insert(Equal(list(tree.lhs(1)),f))
+                    m2sci_insert(Equal(list(tree.lhs(1)),f))
                 end
                 tree=list()
             else
index 95c9ecc..2b01087 100644 (file)
@@ -14,5 +14,5 @@ function [tree]=sci_docopt(tree)
     // Ouput: tree = Scilab equivalent for tree
 
     tree=Variable("%browsehelp",Infer(list(1,Unknown),Type(String,Real)))
-    insert(Equal(list(),Funcall("global",1,list(Cste(tree.name)),list())))
+    m2sci_insert(Equal(list(),Funcall("global",1,list(Cste(tree.name)),list())))
 endfunction
index 28cf889..72393ea 100644 (file)
@@ -26,17 +26,17 @@ function [tree]=sci_dos(tree)
         else
             tree.lhs=list(V,S)
         end
-        insert(Equal(tree.lhs,tree))
+        m2sci_insert(Equal(tree.lhs,tree))
         tree=list()
 
         if rhs==2 then
-            insert(Equal(list(),Funcall("disp",1,list(S),list())),1)
+            m2sci_insert(Equal(list(),Funcall("disp",1,list(S),list())),1)
         end
     else
         tree.lhs=list(tree.lhs($:-1:1))
 
         if rhs==2 then
-            insert(Equal(list(),Funcall("disp",1,list(tree.lhs(1),tree.lhs(2)),list())),1)
+            m2sci_insert(Equal(list(),Funcall("disp",1,list(tree.lhs(1),tree.lhs(2)),list())),1)
         end
 
         tree.lhs(1).dims=list(Unknown,Unknown)
index 9313e70..24b24d7 100644 (file)
@@ -66,7 +66,7 @@ function [tree]=sci_eig(tree)
         if lhs==1 then
             al=gettempvar(1)
             be=gettempvar(2)
-            insert(Equal(list(al,be),Funcall("spec",1,tree.rhs,list(al,be))))
+            m2sci_insert(Equal(list(al,be),Funcall("spec",1,tree.rhs,list(al,be))))
             tree=Operation("./",list(al,be),tree.lhs)
 
             tree.out(1).dims=list(m,1)
@@ -75,7 +75,7 @@ function [tree]=sci_eig(tree)
             al=gettempvar(1)
             be=gettempvar(2)
 
-            insert(Equal(list(al,be,tree.lhs(1)),Funcall("eig",1,tree.rhs,list(al,be,tree.lhs(1)))))
+            m2sci_insert(Equal(list(al,be,tree.lhs(1)),Funcall("eig",1,tree.rhs,list(al,be,tree.lhs(1)))))
 
             tree=Operation("./",list(al,be),list(tree.lhs(1)))
             tree=Funcall("diag",1,list(tree),tree.out)
@@ -87,7 +87,7 @@ function [tree]=sci_eig(tree)
         end
         // eig(A,B,flag)
     else
-        no_equiv(msprintf(gettext("%s, flag IGNORED."),expression2code(tree)))
+        no_equiv(msprintf(gettext("%s, flag IGNORED."), strcat(expression2code(tree), "")))
 
         tree.rhs(3)=null()
 
index 8820a67..707c923 100644 (file)
@@ -104,7 +104,7 @@ function [tree]=sci_eye(tree)
             tmp=n
             if typeof(n)<>"variable" then
                 tmp=gettempvar()
-                insert(Equal(list(tmp),n))
+                m2sci_insert(Equal(list(tmp),n))
             end
             newrhs=list()
             for k=1:size(n.dims)
index 4e4f8ca..6fe589e 100644 (file)
@@ -104,7 +104,7 @@ function [tree]=sci_false(tree)
             tmp=n
             if typeof(n)<>"variable" then
                 tmp=gettempvar()
-                insert(Equal(list(tmp),n))
+                m2sci_insert(Equal(list(tmp),n))
             end
             newrhs=list()
             for k=1:size(n.dims)
index 9f1b4d6..1ac31f4 100644 (file)
@@ -19,7 +19,7 @@ function [tree]=sci_ferror(tree)
     if rhs==2 then
         tree.rhs(2)=null()
         if lhs==2 then
-            no_equiv(msprintf(gettext("%s with two outputs."),expression2code(tree)));
+            no_equiv(msprintf(gettext("%s with two outputs."), strcat(expression2code(tree), "")));
         else
             tree.name="mclearerr"
             tree.lhs(1).dims=list(1,Unknown)
@@ -28,7 +28,7 @@ function [tree]=sci_ferror(tree)
         // ferror(fid)
     else
         if lhs==2 then
-            no_equiv(msprintf(gettext("%s with two outputs."),expression2code(tree)));
+            no_equiv(msprintf(gettext("%s with two outputs."), strcat(expression2code(tree), "")));
         else
             tree.name="merror"
             tree.lhs(1).dims=list(1,1)
index 96e8e40..7fed275 100644 (file)
@@ -18,7 +18,7 @@ function [tree]=sci_fgetl(tree)
 
     if typeof(tree.lhs(1))=="variable" & tree.lhs(1).name=="ans" then
         out=gettempvar()
-        insert(Equal(list(out),tree))
+        m2sci_insert(Equal(list(out),tree))
         tree=out
     else
         out=tree.lhs(1)
@@ -33,9 +33,9 @@ function [tree]=sci_fgetl(tree)
     EQ=Equal(list(out),Cste(-1))
 
     if typeof(tree)=="variable" then
-        insert(tlist(["ifthenelse","expression","then","elseifs","else"],neq,list(EQ),list(),list()));
+        m2sci_insert(tlist(["ifthenelse","expression","then","elseifs","else"],neq,list(EQ),list(),list()));
     else
-        insert(tlist(["ifthenelse","expression","then","elseifs","else"],neq,list(EQ),list(),list()),1);
+        m2sci_insert(tlist(["ifthenelse","expression","then","elseifs","else"],neq,list(EQ),list(),list()),1);
     end
 
     if typeof(tree)<>"variable" then
index 1fe42dd..e3e8359 100644 (file)
@@ -43,13 +43,13 @@ function [tree]=sci_fgets(tree)
         // If the result is not assigned to a variable then a temporary variable is returned
         if tempvar then
             // Assign result to tmp
-            insert(Equal(list(outputvar), tree));
+            m2sci_insert(Equal(list(outputvar), tree));
             // Just add the test for EOF
-            insert(tlist(["ifthenelse","expression","then","elseifs","else"],isemptyfuncall, list(newvalue),list(),list()));
+            m2sci_insert(tlist(["ifthenelse","expression","then","elseifs","else"],isemptyfuncall, list(newvalue),list(),list()));
             tree = outputvar;
             tree.type = Type(Unknown,Real);
         else // Just add the test for EOF
-            insert(tlist(["ifthenelse","expression","then","elseifs","else"],isemptyfuncall, list(newvalue),list(),list()), 1);
+            m2sci_insert(tlist(["ifthenelse","expression","then","elseifs","else"],isemptyfuncall, list(newvalue),list(),list()), 1);
             tree.lhs(1).type=Type(Unknown,Real)
         end
     end
index d7742b0..67ab5f7 100644 (file)
@@ -24,11 +24,11 @@ function [tree]=sci_fileparts(tree)
         tree=Operation("+",list(tree,pathconvert_funcall),tree.lhs)
     else
         add=Operation("+",list(tree.lhs(1),pathconvert_funcall),list())
-        insert(Equal(list(tree.lhs(1)),add),1)
+        m2sci_insert(Equal(list(tree.lhs(1)),add),1)
     end
 
     if lhs==4 then
-        insert(Equal(list(tree.lhs(4)),Cste("")),1)
+        m2sci_insert(Equal(list(tree.lhs(4)),Cste("")),1)
         tree.lhs(4)=null()
     end
 endfunction
index 2241532..ca7aff2 100644 (file)
@@ -25,7 +25,7 @@ function [tree]=sci_fliplr(tree)
     else
         if typeof(tree.rhs(1))<>"variable" then
             tmp=gettempvar()
-            insert(Equal(list(tmp),tree.rhs(1)))
+            m2sci_insert(Equal(list(tmp),tree.rhs(1)))
         else
             tmp=tree.rhs(1)
         end
index ecb0e00..0649fab 100644 (file)
@@ -19,7 +19,7 @@ function [tree]=sci_flipud(tree)
 
     if typeof(tree.rhs(1))<>"variable" then
         tmp=gettempvar()
-        insert(Equal(list(tmp),tree.rhs(1)))
+        m2sci_insert(Equal(list(tmp),tree.rhs(1)))
     else
         tmp=tree.rhs(1)
     end
index acdfc6a..99d75c7 100644 (file)
@@ -30,7 +30,7 @@ function [tree]=sci_fopen(tree)
             return
         end
     elseif filename.vtype==Double then
-        no_equiv(msprintf(gettext("%s (See fileinfo() function)."),expression2code(tree)))
+        no_equiv(msprintf(gettext("%s (See fileinfo() function)."), strcat(expression2code(tree), "")))
         return
     end
 
index 4777131..c79d87e 100644 (file)
@@ -30,7 +30,7 @@ function [tree]=sci_fseek(tree)
         case 1 then
             flag="end"
         else
-            set_infos(msprintf(gettext("Not enough information on %s to set the proper flag."),expression2code(origin)),1)
+            set_infos(msprintf(gettext("Not enough information on %s to set the proper flag."), strcat(expression2code(origin), "")),1)
             flag=Funcall("fseek_origin",1,list(origin),list())
         end
     else
@@ -41,7 +41,7 @@ function [tree]=sci_fseek(tree)
                 end
             end
         else
-            set_infos(msprintf(gettext("Not enough information on %s to set the proper flag."),expression2code(origin)),1)
+            set_infos(msprintf(gettext("Not enough information on %s to set the proper flag."), strcat(expression2code(origin), "")),1)
             flag=Funcall("fseek_origin",1,list(origin),list())
         end
     end
index 3bae2bf..28fdce5 100644 (file)
@@ -42,10 +42,10 @@ function [tree]=sci_grid(tree)
         opt=tree.rhs(2)
         if typeof(opt)=="cste" then
             if opt.value=="on" then
-                insert(Equal(list(Operation("ins",list(ax,Cste("grid")),list())),on))
+                m2sci_insert(Equal(list(Operation("ins",list(ax,Cste("grid")),list())),on))
                 tree=list()
             elseif opt.value=="off" then
-                insert(Equal(list(Operation("ins",list(ax,Cste("grid")),list())),off))
+                m2sci_insert(Equal(list(Operation("ins",list(ax,Cste("grid")),list())),off))
                 tree=list()
             else
                 set_infos(gettext("No minor grid in Scilab."),2);
index 11b6c20..3290420 100644 (file)
@@ -19,13 +19,13 @@ function [tree]=sci_hankel(tree)
     if rhs==1 then
         if typeof(tree.rhs(1))<>"variable" then
             c=gettempvar();
-            insert(Equal(list(c),tree.rhs(1)))
+            m2sci_insert(Equal(list(c),tree.rhs(1)))
         else
             c=tree.rhs(1);
         end
 
         n=gettempvar()
-        insert(Equal(list(n),Funcall("size",1,Rhs_tlist(c,"*"),list())));
+        m2sci_insert(Equal(list(n),Funcall("size",1,Rhs_tlist(c,"*"),list())));
 
         if is_a_scalar(tree.rhs(1)) then
             v=c
@@ -54,22 +54,22 @@ function [tree]=sci_hankel(tree)
     else
         if typeof(tree.rhs(1))<>"variable" then
             c=gettempvar();
-            insert(Equal(list(c),tree.rhs(1)))
+            m2sci_insert(Equal(list(c),tree.rhs(1)))
         else
             c=tree.rhs(1);
         end
 
         if typeof(tree.rhs(2))<>"variable" then
             r=gettempvar();
-            insert(Equal(list(r),tree.rhs(2)))
+            m2sci_insert(Equal(list(r),tree.rhs(2)))
         else
             r=tree.rhs(2);
         end
 
         m=gettempvar();
         n=gettempvar();
-        insert(Equal(list(m),Funcall("size",1,Rhs_tlist(c,"*"),list())));
-        insert(Equal(list(n),Funcall("size",1,Rhs_tlist(r,"*"),list())));
+        m2sci_insert(Equal(list(m),Funcall("size",1,Rhs_tlist(c,"*"),list())));
+        m2sci_insert(Equal(list(n),Funcall("size",1,Rhs_tlist(r,"*"),list())));
 
 
         // v=[matrix(c,1,-1),matrix(r(2:$),1,-1)]
index 30bb017..6d80f64 100644 (file)
@@ -24,7 +24,7 @@ function [tree]=sci_isfield(tree)
     else
         // allf=getfield(1,st);tf=or(allf(3:$)==f);
         allf=gettempvar()
-        insert(Equal(list(allf),Funcall("getfield",1,Rhs_tlist(1,st),list())))
+        m2sci_insert(Equal(list(allf),Funcall("getfield",1,Rhs_tlist(1,st),list())))
 
         imp=Operation(":",list(Cste(3),Cste("$")),list())
         ext=Operation("ext",list(allf,imp),list())
index 1688661..cc78750 100644 (file)
@@ -22,7 +22,7 @@ function [tree]=sci_logical(tree)
     end
 
     if is_empty(X) then
-        set_infos(msprintf(gettext("%s is an empty matrix, so result is set to []."),expression2code(X)),0);
+        set_infos(msprintf(gettext("%s is an empty matrix, so result is set to []."), strcat(expression2code(X), "")),0);
         tree=Cste([])
     elseif not_empty(X) then
         if X.vtype==Boolean then
index 66bfdbe..f02ec7a 100644 (file)
@@ -30,7 +30,7 @@ function [tree]=sci_max(tree)
             // All output dims are unknown
             tree.lhs(1).dims=allunknown(A.dims)
             tmp=gettempvar()
-            insert(Equal(list(tmp),A))
+            m2sci_insert(Equal(list(tmp),A))
             // First non singleton dimension will be computed at execution
             tree.rhs=Rhs_tlist(tmp,Funcall("firstnonsingleton",1,list(tmp),list()))
         else
index 550bb60..7315e74 100644 (file)
@@ -30,7 +30,7 @@ function [tree]=sci_min(tree)
             // All output dims are unknown
             tree.lhs(1).dims=allunknown(A.dims)
             tmp=gettempvar()
-            insert(Equal(list(tmp),A))
+            m2sci_insert(Equal(list(tmp),A))
             // First non singleton dimension will be computed at execution
             tree.rhs=Rhs_tlist(tmp,Funcall("firstnonsingleton",1,list(tmp),list()))
         else
index 358b6cc..54daee0 100644 (file)
@@ -22,7 +22,7 @@ function [tree]=sci_mkdir(tree)
     end
 
     if lhs==3 then
-        no_equiv(msprintf(gettext("%s when called with three outputs."),expression2code(tree)));
+        no_equiv(msprintf(gettext("%s when called with three outputs."), strcat(expression2code(tree), "")));
     end
 
 endfunction
index fef9e3d..2860060 100644 (file)
@@ -25,7 +25,7 @@ function [tree]=sci_nargin(tree)
         else
             fieldnb=2
         end
-        set_infos(msprintf(gettext("%s considered to be a Scilab macro."),rhs2code(tree.rhs)),2);
+        set_infos(msprintf(gettext("%s considered to be a Scilab macro."),strcat(rhs2code(tree.rhs), "")),2);
         evstrtree=Funcall("evstr",1,tree.rhs,list())
         macrovartree=Funcall("macrovar",1,Rhs_tlist(evstrtree),list())
         getfieldtree=Funcall("getfield",1,Rhs_tlist(fieldnb,macrovartree),list())
index 813fb9d..0bf3a83 100644 (file)
@@ -25,7 +25,7 @@ function [tree]=sci_nargout(tree)
         else
             fieldnb=2
         end
-        set_infos(msprintf(gettext("%s considered to be a Scilab macro."),rhs2code(tree.rhs)),2);
+        set_infos(msprintf(gettext("%s considered to be a Scilab macro."),strcat(rhs2code(tree.rhs), "")),2);
         evstrtree=Funcall("evstr",1,tree.rhs,list())
         macrovartree=Funcall("macrovar",1,Rhs_tlist(evstrtree),list())
         getfieldtree=Funcall("getfield",1,Rhs_tlist(fieldnb,macrovartree),list())
index df0921e..7cabf41 100644 (file)
@@ -104,7 +104,7 @@ function [tree]=sci_ones(tree)
             tmp=n
             if typeof(n)<>"variable" then
                 tmp=gettempvar()
-                insert(Equal(list(tmp),n))
+                m2sci_insert(Equal(list(tmp),n))
             end
             newrhs=list()
             for k=1:size(n.dims)
index f2962e6..0a30971 100644 (file)
@@ -104,7 +104,7 @@ function [tree]=sci_rand(tree)
             tmp=n
             if typeof(n)<>"variable" then
                 tmp=gettempvar()
-                insert(Equal(list(tmp),n))
+                m2sci_insert(Equal(list(tmp),n))
             end
             newrhs=list()
             for k=1:size(n.dims)
index 4bc1f7c..d9694c4 100644 (file)
@@ -104,7 +104,7 @@ function [tree]=sci_randn(tree)
             tmp=n
             if typeof(n)<>"variable" then
                 tmp=gettempvar()
-                insert(Equal(list(tmp),n))
+                m2sci_insert(Equal(list(tmp),n))
             end
             newrhs=list()
             for k=1:size(n.dims)
index fac5b27..1e42e52 100644 (file)
@@ -57,7 +57,7 @@ function [tree]=sci_repmat(tree)
             tmp=m
             if typeof(m)<>"variable" then
                 tmp=gettempvar()
-                insert(Equal(list(tmp),m))
+                m2sci_insert(Equal(list(tmp),m))
             end
             newrhs=list()
             for k=1:size(m.dims)
index 766571b..bbbc204 100644 (file)
@@ -17,7 +17,7 @@ function [tree]=sci_setstr(tree)
     X = getrhs(tree)
 
     if X.vtype==String then
-        set_infos(msprintf(gettext("In %s %s is a String,\nSo result is set to %s."),expression2code(tree),expression2code(X),expression2code(X)),0)
+        set_infos(msprintf(gettext("In %s %s is a String,\nSo result is set to %s."), strcat(expression2code(tree), ""), strcat(expression2code(X), ""), strcat(expression2code(X), "")),0)
         // Because of String concatenation
         if typeof(X)=="operation" then
             X.out(1)=tree.lhs(1)
index 620be40..a426380 100644 (file)
@@ -29,7 +29,7 @@ function [tree]=sci_size(tree)
         // Matlab can work with dim > size(size(X),2) but not Scilab
         if typeof(dim)=="cste" then
             if dim.value>size(X.dims) then
-                set_infos(msprintf(gettext("M2SCI found: %s > size(size(%s),2),\nSo result is set to 1."),expression2code(dim),expression2code(X)),0)
+                set_infos(msprintf(gettext("M2SCI found: %s > size(size(%s),2),\nSo result is set to 1."),strcat(expression2code(dim), ""), strcat(expression2code(X), "")),0)
                 tree=Cste(1)
             else
                 tree.lhs(1).dims=list(1,1)
index 8ed4d22..537290b 100644 (file)
@@ -68,13 +68,13 @@ function [tree]=sci_sparse(tree)
         else
             if typeof(i)<>"variable" then
                 V1=gettempvar(1)
-                insert(Equal(list(V1),i))
+                m2sci_insert(Equal(list(V1),i))
             else
                 V1=i
             end
             if typeof(j)<>"variable" then
                 V2=gettempvar(2)
-                insert(Equal(list(V2),j))
+                m2sci_insert(Equal(list(V2),j))
             else
                 V2=j
             end
@@ -105,13 +105,13 @@ function [tree]=sci_sparse(tree)
         else
             if typeof(i)<>"variable" then
                 V1=gettempvar(1)
-                insert(Equal(list(V1),i))
+                m2sci_insert(Equal(list(V1),i))
             else
                 V1=i
             end
             if typeof(j)<>"variable" then
                 V2=gettempvar(2)
-                insert(Equal(list(V2),j))
+                m2sci_insert(Equal(list(V2),j))
             else
                 V2=j
             end
index 138a1aa..909fd87 100644 (file)
@@ -104,7 +104,7 @@ function [tree]=sci_true(tree)
             tmp=n
             if typeof(n)<>"variable" then
                 tmp=gettempvar()
-                insert(Equal(list(tmp),n))
+                m2sci_insert(Equal(list(tmp),n))
             end
             newrhs=list()
             for k=1:size(n.dims)
index dc9ae43..74bc0d0 100644 (file)
@@ -26,17 +26,17 @@ function [tree]=sci_unix(tree)
         else
             tree.lhs=list(V,S)
         end
-        insert(Equal(tree.lhs,tree))
+        m2sci_insert(Equal(tree.lhs,tree))
         tree=list()
 
         if rhs==2 then
-            insert(Equal(list(),Funcall("disp",1,list(S),list())),1)
+            m2sci_insert(Equal(list(),Funcall("disp",1,list(S),list())),1)
         end
     else
         tree.lhs=list(tree.lhs($:-1:1))
 
         if rhs==2 then
-            insert(Equal(list(),Funcall("disp",1,list(tree.lhs(1),tree.lhs(2)),list())),1)
+            m2sci_insert(Equal(list(),Funcall("disp",1,list(tree.lhs(1),tree.lhs(2)),list())),1)
         end
 
         tree.lhs(1).dims=list(Unknown,Unknown)
index 28c108a..d14d107 100644 (file)
@@ -19,7 +19,7 @@ function [tree]=sci_waitforbuttonpress(tree)
     win=gettempvar()
     str=gettempvar()
 
-    insert(Equal(list(btn,xc,yc,win,str),Funcall("xclick",1,list(),list())))
+    m2sci_insert(Equal(list(btn,xc,yc,win,str),Funcall("xclick",1,list(),list())))
 
     comp=Operation(">",list(btn,Cste(64)),list())
 
index aa2a643..b2f776d 100644 (file)
@@ -20,7 +20,7 @@ function [tree]=sci_warning(tree)
             tree.rhs(1)=Cste("query")
             // [s,f] = warning
         else
-            insert(Equal(list(tree.lhs(2)),Cste("once")))
+            m2sci_insert(Equal(list(tree.lhs(2)),Cste("once")))
             tree.rhs(1)=Cste("query");
             tree.lhs(2)=null();
         end
@@ -34,7 +34,7 @@ function [tree]=sci_warning(tree)
 
         if typeof(tree.rhs(1))=="cste" & or(convstr(tree.rhs(1).value)==["""on""","""off""","""backtrace""","""debug""","""once""","""always"""]) then
             if tree.lhs(1).name<>"ans" then
-                no_equiv(msprintf(gettext("%s: Output value set to ''on''."),expression2code(tree)))
+                no_equiv(msprintf(gettext("%s: Output value set to ''on''."), strcat(expression2code(tree), "")))
                 tree=Cste("on")
             else
                 no_equiv(expression2code(tree))
index 0ea7eac..a527390 100644 (file)
@@ -104,7 +104,7 @@ function [tree]=sci_zeros(tree)
             tmp=n
             if typeof(n)<>"variable" then
                 tmp=gettempvar()
-                insert(Equal(list(tmp),n))
+                m2sci_insert(Equal(list(tmp),n))
             end
             newrhs=list()
             for k=1:size(n.dims)