* Manage nested functions in macr2tree/tree2code. 22/16722/4
Vincent COUVERT [Tue, 23 Jun 2015 08:24:36 +0000 (10:24 +0200)]
* Update tests since fun2string has been removed.
* Better management of "rc" and "cc" operations.
Test:
test_run functions bug_731
test_run m2sci bug_1124
test_run m2sci bug_683
test_run m2sci bug_943

Change-Id: Ie87f4c4dca4d3cd2f25f5a6a38abf53d58deb253

scilab/modules/ast/ast.vcxproj
scilab/modules/ast/ast.vcxproj.filters
scilab/modules/ast/src/cpp/ast/treevisitor.cpp
scilab/modules/ast/string_Import.def [new file with mode: 0644]
scilab/modules/functions/tests/nonreg_tests/bug_731.dia.ref
scilab/modules/functions/tests/nonreg_tests/bug_731.tst
scilab/modules/m2sci/tests/nonreg_tests/bug_943.dia.ref
scilab/modules/m2sci/tests/nonreg_tests/bug_943.tst
scilab/modules/string/macros/expression2code.sci

index bd23fee..8bf6037 100644 (file)
       <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <ImportLibrary>../../bin/$(ProjectName).lib</ImportLibrary>
-      <AdditionalDependencies>fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <RandomizedBaseAddress>false</RandomizedBaseAddress>
     </Link>
     <PreLinkEvent>
@@ -124,6 +124,7 @@ lib /DEF:"$(ProjectDir)output_stream_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(P
 lib /DEF:"$(ProjectDir)console_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)sciconsole.lib" 1&gt;NUL 2&gt;NUL
 lib /DEF:"$(ProjectDir)dynamic_link_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)dynamic_link.lib" 1&gt;NUL 2&gt;NUL
 lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)fileio.lib" 1&gt;NUL 2&gt;NUL
+lib /DEF:"$(ProjectDir)string_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)string.lib" 1&gt;NUL 2&gt;NUL
 </Command>
     </PreLinkEvent>
   </ItemDefinitionGroup>
@@ -147,7 +148,7 @@ lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
       <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <ImportLibrary>../../bin/$(ProjectName).lib</ImportLibrary>
-      <AdditionalDependencies>fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <RandomizedBaseAddress>false</RandomizedBaseAddress>
     </Link>
     <PreLinkEvent>
@@ -161,6 +162,7 @@ lib /DEF:"$(ProjectDir)output_stream_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(P
 lib /DEF:"$(ProjectDir)console_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)sciconsole.lib" 1&gt;NUL 2&gt;NUL
 lib /DEF:"$(ProjectDir)dynamic_link_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)dynamic_link.lib" 1&gt;NUL 2&gt;NUL
 lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)fileio.lib" 1&gt;NUL 2&gt;NUL
+lib /DEF:"$(ProjectDir)string_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)string.lib" 1&gt;NUL 2&gt;NUL
 </Command>
     </PreLinkEvent>
   </ItemDefinitionGroup>
@@ -181,7 +183,7 @@ lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
     <Link>
       <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
       <ImportLibrary>../../bin/$(ProjectName).lib</ImportLibrary>
-      <AdditionalDependencies>fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <RandomizedBaseAddress>false</RandomizedBaseAddress>
     </Link>
     <PreLinkEvent>
@@ -195,6 +197,7 @@ lib /DEF:"$(ProjectDir)output_stream_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(P
 lib /DEF:"$(ProjectDir)console_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)sciconsole.lib" 1&gt;NUL 2&gt;NUL
 lib /DEF:"$(ProjectDir)dynamic_link_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)dynamic_link.lib" 1&gt;NUL 2&gt;NUL
 lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)fileio.lib" 1&gt;NUL 2&gt;NUL
+lib /DEF:"$(ProjectDir)string_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)string.lib" 1&gt;NUL 2&gt;NUL
 </Command>
     </PreLinkEvent>
   </ItemDefinitionGroup>
@@ -218,7 +221,7 @@ lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
     <Link>
       <OutputFile>$(SolutionDir)bin\$(ProjectName).dll</OutputFile>
       <ImportLibrary>../../bin/$(ProjectName).lib</ImportLibrary>
-      <AdditionalDependencies>fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>string.lib;fileio.lib;dynamic_link.lib;sciconsole.lib;output_stream.lib;core.lib;io.lib;elementary_functions_f.lib;elementary_functions.lib;polynomials_f.lib;linear_algebra_f.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <RandomizedBaseAddress>false</RandomizedBaseAddress>
     </Link>
     <PreLinkEvent>
@@ -232,6 +235,7 @@ lib /DEF:"$(ProjectDir)output_stream_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(P
 lib /DEF:"$(ProjectDir)console_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)sciconsole.lib" 1&gt;NUL 2&gt;NUL
 lib /DEF:"$(ProjectDir)dynamic_link_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)dynamic_link.lib" 1&gt;NUL 2&gt;NUL
 lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)fileio.lib" 1&gt;NUL 2&gt;NUL
+lib /DEF:"$(ProjectDir)string_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform) /OUT:"$(ProjectDir)string.lib" 1&gt;NUL 2&gt;NUL
 </Command>
     </PreLinkEvent>
   </ItemDefinitionGroup>
@@ -251,6 +255,7 @@ lib /DEF:"$(ProjectDir)fileio_import.def" /SUBSYSTEM:WINDOWS /MACHINE:$(Platform
     <None Include="linear_algebra_f_Import.def" />
     <None Include="output_stream_Import.def" />
     <None Include="polynomials_f_Import.def" />
+    <None Include="string_Import.def" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="includes\analysis\AnalysisVisitor.hxx" />
index f447123..943a4c8 100644 (file)
     <None Include="output_stream_Import.def">
       <Filter>Libraries Dependencies</Filter>
     </None>
+    <None Include="string_Import.def">
+      <Filter>Libraries Dependencies</Filter>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="includes\exps\all.hxx">
index 6aa1ea4..b34f9e2 100644 (file)
 *
 */
 
+#include <wchar.h>
 #include "treevisitor.hxx"
+#include "printvisitor.hxx"
 #include "execvisitor.hxx"
 #include "token.hxx"
 
+extern "C"
+{
+#include "os_string.h"
+#include "os_wcstok.h"
+}
+
 namespace ast
 {
 void TreeVisitor::visit(const SeqExp  &e)
@@ -136,7 +144,6 @@ void TreeVisitor::visit(const MatrixExp &e)
 
     types::List* sub = createOperation();
     types::List* ope = new types::List();
-    sub->append(ope);
 
     int idx = 0;
     for (auto it : lines)
@@ -145,31 +152,36 @@ void TreeVisitor::visit(const MatrixExp &e)
 
         if (idx >= 2)
         {
+            sub->append(ope);
             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);
+            types::List* subcolcatOperation = createOperation();
+            types::List* subcolcatOperands = new types::List();
+            subcolcatOperands->append(sub);
             //add EOL
-            tmp->append(getEOL());
-
-            lst->append(tmp);
-            ope = tmp;
-            sub = lst;
-        }
+            //subcolcatOperands->append(getEOL());
 
-        ope->append(getList());
+            subcolcatOperands->append(getList());
 
-        if (idx == 0)
+            ope = subcolcatOperands;
+            sub = subcolcatOperation;
+        }
+        else
         {
-            //add EOL
-            ope->append(getEOL());
+            ope->append(getList());
+            if (idx == 0)
+            {
+                //add EOL
+                //ope->append(getEOL());
+            }
         }
+
         ++idx;
     }
-
+    sub->append(ope);
     sub->append(new types::String(L"cc"));
     l = sub;
 }
@@ -185,7 +197,6 @@ void TreeVisitor::visit(const MatrixLineExp &e)
 
     types::List* sub = createOperation();
     types::List* ope = new types::List();
-    sub->append(ope);
 
     int idx = 0;
     int last_line = -1;
@@ -195,6 +206,7 @@ void TreeVisitor::visit(const MatrixLineExp &e)
 
         if (idx >= 2)
         {
+            sub->append(ope);
             sub->append(new types::String(L"rc"));
             //create a new operation
             //put previous stage in lhs and
@@ -202,16 +214,21 @@ void TreeVisitor::visit(const MatrixLineExp &e)
             types::List* lst = createOperation();
             types::List* tmp = new types::List();
             tmp->append(sub);
+            tmp->append(getList());
 
-            lst->append(tmp);
+            //lst->append(tmp);
             ope = tmp;
             sub = lst;
         }
+        else
+        {
+            ope->append(getList());
+        }
 
-        ope->append(getList());
         ++idx;
     }
 
+    sub->append(ope);
     sub->append(new types::String(L"rc"));
     l = sub;
 }
@@ -816,35 +833,75 @@ void TreeVisitor::visit(const TransposeExp  &e)
 
 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();
+    wchar_t* pwstState;
+    wostringstream wostr;
+    PrintVisitor pv(wostr, false, false);
+
+    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);
+    size_t returnSize = e.getReturns().getOriginal()->getAs<ArrayListVar>()->getVars().size();
+    // First ask if there are some return values.
+    if (returnSize > 1)
+    {
+        wostr << SCI_OPEN_RETURNS;
+    }
+
+    e.getReturns().getOriginal()->accept(pv);
+
+    if (returnSize > 1)
+    {
+        wostr << SCI_CLOSE_RETURNS;
+    }
+
+    wostr << " ";
+    if (returnSize > 0)
+    {
+        wostr << SCI_ASSIGN << " ";
+    }
+
+    // Then get the function name
+    wostr << e.getSymbol().getName();
+
+    // Then get function args
+    wostr << SCI_OPEN_ARGS;
+    e.getArgs().getOriginal()->accept(pv);
+    wostr << SCI_CLOSE_ARGS << std::endl;
+    wchar_t* pwstFun = os_wcsdup(wostr.str().data());
+    function->append(new types::String(os_wcstok(pwstFun, L"\n", &pwstState)));
+    FREE(pwstFun);
+
+    // Now print function body
+    wostringstream wostrBody;
+    PrintVisitor pvBody(wostrBody, false, true);
+    std::vector<wchar_t*> allTokens;
+    e.getBody().getOriginal()->accept(pvBody);
+    wchar_t* pwstBody = os_wcsdup(wostrBody.str().data());
+    wchar_t* pwstToken = os_wcstok(pwstBody, L"\n", &pwstState);
+    while (pwstToken != NULL)
+    {
+        allTokens.push_back(pwstToken);
+        pwstToken = os_wcstok(NULL, L"\n", &pwstState);
+    }
+
+    if (allTokens.size() > 0)
+    {
+        types::String* stringMatrix = new types::String(static_cast<int>(allTokens.size()), 1);
+        stringMatrix->set(allTokens.data());
+        function->append(stringMatrix);
+    }
+    else
+    {
+        function->append(types::Double::Empty());
+    }
+    FREE(pwstBody);
+
+    l = function;
 }
 
 types::InternalType* TreeVisitor::getEOL()
diff --git a/scilab/modules/ast/string_Import.def b/scilab/modules/ast/string_Import.def
new file mode 100644 (file)
index 0000000..556cbc5
--- /dev/null
@@ -0,0 +1,5 @@
+LIBRARY    string.dll
+
+
+EXPORTS
+os_wcstok
index adf21cb..f11210e 100644 (file)
@@ -1,3 +1,10 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2005-2008 - INRIA - Pierre MARECHAL <pierre.marechal@inria.fr>
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
 // <-- Non-regression test for bug 731 -->
 //
 // <-- Bugzilla URL -->
 // <-- Short Description -->
 //    fun2string and macr2tree cannot cope with nested function
 //    definitions
-// Copyright INRIA
-// Scilab Project - Pierre MARECHAL
-// Date : 3 mai 2005
-// last modified : 10 Jan 2006
 // =============== Test 1 ===============
 function y=foo(x)
-       a=sin(x)
-       function y=sq(x), y=x^2,endfunction
-       y=sq(a)+1
+  a=sin(x)
+  function y=sq(x), y=x^2,endfunction
+  y=sq(a)+1
 endfunction
-CONTENTS = fun2string(foo);
-REFCONTENTS=["function y=ans(x)";
-               "  a = sin(x)";
-               "  function y=sq(x), y=x^2,endfunction";
-               "  y = sq(a) + 1";
-               "endfunction"];
+CONTENTS = tree2code(macr2tree(foo));
+REFCONTENTS=["function [y] = foo(x)";
+"a = sin(x)";
+"function y = sq(x)";
+"  y = x ^ 2";
+"endfunction";
+"y = sq(a)+1";
+"endfunction"
+""];
 if or(REFCONTENTS<>CONTENTS) then bugmes();quit;end
 // =============== Test 2 ===============
 function one()
@@ -33,25 +39,29 @@ function one()
   endfunction
     //a comment here
 endfunction
-CONTENTS_II = fun2string(one);
-REFCONTENTS_II=["function []=ans()";
-               "  function two()";
-               "      // A comment";
-               "  endfunction";
-               "  function three()";
-               "      // A comment";
-               "  endfunction";
-               "  //a comment here";
-               "endfunction"];
+CONTENTS_II = tree2code(macr2tree(one));
+REFCONTENTS_II=["function [] = one()";
+"function  two()";
+"  // A comment";
+"endfunction";
+"function  three()";
+"  // A comment";
+"endfunction";
+"//a comment here";
+"endfunction";
+""];
 if or(REFCONTENTS_II<>CONTENTS_II) then bugmes();quit;end
 // =============== Test 3 ===============
 function a=foo1()
-       a = 1 ; function foo2() ; disp("hello") ; endfunction ; disp("zut");
-       a = 2
+  a = 1 ; function foo2() ; disp("hello") ; endfunction ; disp("zut");
+  a = 2
 endfunction
-CONTENTS_III=fun2string(foo1);
-REFCONTENTS_III=["function a=ans()";
-                "  a = 1;function foo2() , disp(""hello"") ;endfunction;disp(''zut'');";
-                "  a = 2";
-                "endfunction"];
+CONTENTS_III=tree2code(macr2tree(foo1));
+REFCONTENTS_III=["function [a] = foo1()";
+"a = 1;function  foo2()";
+"  disp(""hello"");";
+"endfunction;disp(""zut"");";
+"a = 2";
+"endfunction";
+""];
 if or(REFCONTENTS_III<>CONTENTS_III) then bugmes();quit;end
index 2834286..68af5ed 100644 (file)
 // =============== Test 1 ===============
 
 function y=foo(x)
-       a=sin(x)
-       function y=sq(x), y=x^2,endfunction
-       y=sq(a)+1
+    a=sin(x)
+    function y=sq(x), y=x^2,endfunction
+    y=sq(a)+1
 endfunction
 
-CONTENTS = fun2string(foo);
+CONTENTS = tree2code(macr2tree(foo));
 
-REFCONTENTS=["function y=ans(x)";
-               "  a = sin(x)";
-               "  function y=sq(x), y=x^2,endfunction";
-               "  y = sq(a) + 1";
-               "endfunction"];
+REFCONTENTS=["function [y] = foo(x)";
+"a = sin(x)";
+"function y = sq(x)";
+"  y = x ^ 2";
+"endfunction";
+"y = sq(a)+1";
+"endfunction"
+""];
 
 if or(REFCONTENTS<>CONTENTS) then pause,end
 
 // =============== Test 2 ===============
 
 function one()
-  function two()
-    // A comment
-  endfunction
-  function three()
-    // A comment
-  endfunction
+    function two()
+        // A comment
+    endfunction
+    function three()
+        // A comment
+    endfunction
     //a comment here
 endfunction
 
-CONTENTS_II = fun2string(one);
+CONTENTS_II = tree2code(macr2tree(one));
 
-REFCONTENTS_II=["function []=ans()";
-               "  function two()";
-               "      // A comment";
-               "  endfunction";
-               "  function three()";
-               "      // A comment";
-               "  endfunction";
-               "  //a comment here";
-               "endfunction"];
+REFCONTENTS_II=["function [] = one()";
+"function  two()";
+"  // A comment";
+"endfunction";
+"function  three()";
+"  // A comment";
+"endfunction";
+"//a comment here";
+"endfunction";
+""];
 
 if or(REFCONTENTS_II<>CONTENTS_II) then pause,end
 
 // =============== Test 3 ===============
 
 function a=foo1()
-       a = 1 ; function foo2() ; disp("hello") ; endfunction ; disp("zut");
-       a = 2
+    a = 1 ; function foo2() ; disp("hello") ; endfunction ; disp("zut");
+    a = 2
 endfunction
 
-CONTENTS_III=fun2string(foo1);
+CONTENTS_III=tree2code(macr2tree(foo1));
 
-REFCONTENTS_III=["function a=ans()";
-                "  a = 1;function foo2() , disp(""hello"") ;endfunction;disp(''zut'');";
-                "  a = 2";
-                "endfunction"];
+REFCONTENTS_III=["function [a] = foo1()";
+"a = 1;function  foo2()";
+"  disp(""hello"");";
+"endfunction;disp(""zut"");";
+"a = 2";
+"endfunction";
+""];
 
 if or(REFCONTENTS_III<>CONTENTS_III) then pause,end
index 08cea72..26c2f2b 100644 (file)
 //
 // ...
 MFILECONTENTS=["a=10;";
-               "if     (a==1), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
-               "elseif (a==2), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
-               "elseif (a==3), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
-               "else, J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ; end,"];
+"if     (a==1), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
+"elseif (a==2), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
+"elseif (a==3), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
+"else, J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ; end,"];
 MFILE=TMPDIR+"/bug943.m";
 SCIFILE=TMPDIR+"/bug943.sci";
 mputl(MFILECONTENTS,MFILE);
@@ -61,15 +61,24 @@ mfile2sci(MFILE,TMPDIR);
   ****** End of mfile2sci() session ******
 SCIFILECONTENTS=mgetl(SCIFILE);
 SCIFILECONTENTSREF=["";
-               "// Display mode";
-               "mode(0);";
-               "";
-               "// Display warning for floating point exception";
-               "ieee(1);";
-               "";
-               "a = 10;";
-               "if a==1 then J = [1;2;3]; G = [4;5;6];";
-               "elseif a==2 then J = [1;2;3]; G = [4;5;6];";
-               "elseif a==3 then J = [1;2;3]; G = [4;5;6];";
-               "else J = [1;2;3]; G = [4;5;6];end;"];
+"// Display mode";
+"mode(0);";
+"";
+"// Display warning for floating point exception";
+"ieee(1);";
+"";
+"a = 10;";
+"if a==1 then";
+"  J = [1;2;3];  G = [4;5;6];";
+"else";
+"  if a==2 then";
+"    J = [1;2;3];  G = [4;5;6];";
+"  else";
+"    if a==3 then";
+"      J = [1;2;3];  G = [4;5;6];";
+"    else";
+"      J = [1;2;3];  G = [4;5;6];";
+"    end;";
+"  end;";
+"end;"];
 if or(SCIFILECONTENTSREF<>SCIFILECONTENTS) then bugmes();quit;end
index 9002d94..f40a449 100644 (file)
@@ -15,7 +15,7 @@
 // http://bugzilla.scilab.org/show_bug.cgi?id=943
 //
 // <-- Short Description -->
-//    Conversion of (if, elseif, else) structure leads to 
+//    Conversion of (if, elseif, else) structure leads to
 //    mfile2sci failure in some particular indentation scheme.
 //
 //    Cyl_.m
 //    v = (r^2)*abs(p2-p1)*pi;
 //    l = p1-p2 ; d = 0.5*(p1+p2) ;
 //    j1 = (r^2)/2. ; j2 = (r^2)/4. + (l^2)/12. + d^2 ;
-//    if     (a==1), J = [j1,0.,0. ; 0.,j2,0. ; 0.,0.,j2] ; G = 
+//    if     (a==1), J = [j1,0.,0. ; 0.,j2,0. ; 0.,0.,j2] ; G =
 //    [0.5*(p1+p2);0.;0.] ;
-//    elseif (a==2), J = [j2,0.,0. ; 0.,j1,0. ; 0.,0.,j2] ; G = 
+//    elseif (a==2), J = [j2,0.,0. ; 0.,j1,0. ; 0.,0.,j2] ; G =
 //    [0.;0.5*(p1+p2);0.] ;
-//    elseif (a==3), J = [j2,0.,0. ; 0.,j2,0. ; 0.,0.,j1] ; G = 
+//    elseif (a==3), J = [j2,0.,0. ; 0.,j2,0. ; 0.,0.,j1] ; G =
 //    [0.;0.;0.5*(p1+p2)] ;
-//    else, J = [0.,0.,0. ; 0.,0.,0. ; 0.,0.,0.] ; G = 
+//    else, J = [0.,0.,0. ; 0.,0.,0. ; 0.,0.,0.] ; G =
 //    [0.;0.;0.] ; end,
 //
 //    Cyl2_.m
 // ...
 
 MFILECONTENTS=["a=10;";
-               "if     (a==1), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
-               "elseif (a==2), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
-               "elseif (a==3), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
-               "else, J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ; end,"];
+"if     (a==1), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
+"elseif (a==2), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
+"elseif (a==3), J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ;";
+"else, J = [1 ; 2 ; 3] ; G = [4 ; 5 ; 6] ; end,"];
 
 MFILE=TMPDIR+"/bug943.m";
 SCIFILE=TMPDIR+"/bug943.sci";
@@ -51,16 +51,25 @@ mfile2sci(MFILE,TMPDIR);
 SCIFILECONTENTS=mgetl(SCIFILE);
 
 SCIFILECONTENTSREF=["";
-               "// Display mode";
-               "mode(0);";
-               "";
-               "// Display warning for floating point exception";
-               "ieee(1);";
-               "";
-               "a = 10;";
-               "if a==1 then J = [1;2;3]; G = [4;5;6];";
-               "elseif a==2 then J = [1;2;3]; G = [4;5;6];";
-               "elseif a==3 then J = [1;2;3]; G = [4;5;6];";
-               "else J = [1;2;3]; G = [4;5;6];end;"];
+"// Display mode";
+"mode(0);";
+"";
+"// Display warning for floating point exception";
+"ieee(1);";
+"";
+"a = 10;";
+"if a==1 then";
+"  J = [1;2;3];  G = [4;5;6];";
+"else";
+"  if a==2 then";
+"    J = [1;2;3];  G = [4;5;6];";
+"  else";
+"    if a==3 then";
+"      J = [1;2;3];  G = [4;5;6];";
+"    else";
+"      J = [1;2;3];  G = [4;5;6];";
+"    end;";
+"  end;";
+"end;"];
 
 if or(SCIFILECONTENTSREF<>SCIFILECONTENTS) then pause,end
index 977a02f..33f76e0 100644 (file)
@@ -340,6 +340,11 @@ function C=expression2code(e)
         // -----
     case "equal"
         C=instruction2code(e)
+        // ------
+        // INLINE
+        // ------
+    case "inline"
+        C=["function " + e.prototype;"  " + e.definition;"endfunction"];
         // -------
         // COMMENT (inside a matrix declaration for example)
         // -------