macr2tree fixed and test updated 27/17727/5
Cedric Delamarre [Wed, 27 Jan 2016 10:44:28 +0000 (11:44 +0100)]
test_run("core", ["comment", "function", "bug_1304", "bug_1619"])

Change-Id: Ic5c25994745ee2a33a83251004200e6bf0ef0abb

scilab/modules/ast/src/cpp/ast/treevisitor.cpp
scilab/modules/core/tests/nonreg_tests/bug_1304.dia.ref
scilab/modules/core/tests/nonreg_tests/bug_1304.tst
scilab/modules/core/tests/unit_tests/function.dia.ref

index 78e2e0a..020ef36 100644 (file)
@@ -51,6 +51,7 @@ void TreeVisitor::visit(const SeqExp  &e)
                 it->isWhileExp() ||
                 it->isTryCatchExp() ||
                 it->isSelectExp() ||
+                it->isFunctionDec() ||
                 it->isIfExp())
         {
             types::InternalType* tmp = getList();
@@ -273,7 +274,7 @@ void TreeVisitor::visit(const OpExp &e)
 
     switch (e.getOper())
     {
-        // Arithmetics.
+            // Arithmetics.
         case OpExp::plus:
             tmp = new types::String(SCI_PLUS);
             break;
@@ -293,7 +294,7 @@ void TreeVisitor::visit(const OpExp &e)
         case OpExp::power:
             tmp = new types::String(SCI_POWER);
             break;
-        // Element wise.
+            // Element wise.
         case OpExp::dottimes:
             tmp = new types::String(SCI_DOTTIMES);
             break;
@@ -306,7 +307,7 @@ void TreeVisitor::visit(const OpExp &e)
         case OpExp::dotpower:
             tmp = new types::String(SCI_DOTPOWER);
             break;
-        // Kroneckers
+            // Kroneckers
         case OpExp::krontimes:
             tmp = new types::String(SCI_KRONTIMES);
             break;
@@ -316,7 +317,7 @@ void TreeVisitor::visit(const OpExp &e)
         case OpExp::kronldivide:
             tmp = new types::String(SCI_KRONLDIVIDE);
             break;
-        // Control
+            // Control
         case OpExp::controltimes:
             tmp = new types::String(SCI_CONTROLTIMES);
             break;
@@ -326,7 +327,7 @@ void TreeVisitor::visit(const OpExp &e)
         case OpExp::controlldivide:
             tmp = new types::String(SCI_CONTROLLDIVIDE);
             break;
-        // Comparisons
+            // Comparisons
         case OpExp::eq:
             tmp = new types::String(SCI_EQ);
             break;
@@ -978,10 +979,9 @@ void TreeVisitor::visit(const FunctionDec  &e)
         wostr << SCI_CLOSE_RETURNS;
     }
 
-    wostr << " ";
     if (returnSize > 0)
     {
-        wostr << SCI_ASSIGN << " ";
+        wostr << L" " << SCI_ASSIGN << L" ";
     }
 
     // Then get the function name
index 9ad93c3..9b786bb 100644 (file)
 // TESTS WITH A 'SIMPLE' FUNCTION
 //
 function bug_1304()
-disp("bug_1304")
+    disp("bug_1304")
 endfunction
 // Reference tree generated using sci2exp
 reftree = tlist(["program","name","outputs","inputs","statements","nblines"],"bug_1304",list(),..
-       list(),..
-       list(list("EOL"),..
-       tlist(["equal","expression","lhs","endsymbol"],..
-       tlist(["funcall","rhs","name","lhsnb"],list(tlist(["cste","value"],"bug_1304")),"disp",1),..
-       list(tlist(["variable","name"],"ans")),""),list("EOL"),list("EOL"),..
-       tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),5);
+list(),..
+list(list("EOL"),..
+tlist(["equal","expression","lhs","endsymbol"],..
+tlist(["funcall","rhs","name","lhsnb"],list(tlist(["cste","value"],"bug_1304")),"disp",1),..
+list(tlist(["variable","name"],"ans")),""),list("EOL"),..
+tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),3);
 if ~and(macr2tree(bug_1304)==reftree) then bugmes();quit;end
-// Test with input which is not a variable reference
-reftree.name = "ans";
 if ~and(macr2tree(evstr("bug_1304"))==reftree) then bugmes();quit;end
 clear bug_1304
 //
 // TESTS WITH A FUNCTION DEFINING AN OTHER FUNCTION
 //
 function f = bug_1304()
-function internal_bug_1304()
-disp("internal_bug_1304()")
-endfunction
-f = internal_bug_1304
+    function internal_bug_1304()
+        disp("internal_bug_1304()")
+    endfunction
+    f = internal_bug_1304
 endfunction
 // Reference tree generated using sci2exp
 reftree = tlist(["program","name","outputs","inputs","statements","nblines"],"bug_1304",..
-       list(tlist(["variable","name"],"f")),list(),..
-       list(list("EOL"),..
-       tlist(["inline","prototype","definition"],"internal_bug_1304()",..
-       ["";"disp(""internal_bug_1304()"")";" "]),list("EOL"),..
-       tlist(["equal","expression","lhs","endsymbol"],..
-       tlist(["variable","name"],"internal_bug_1304"),list(tlist(["variable","name"],"f")),""),..
-       list("EOL"),list("EOL"),tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),..
-       6);
+list(tlist(["variable","name"],"f")),list(),..
+list(list("EOL"),..
+tlist(["inline","prototype","definition"],"internal_bug_1304()",..
+["disp(""internal_bug_1304()"")"]),list("EOL"),..
+tlist(["equal","expression","lhs","endsymbol"],..
+tlist(["variable","name"],"internal_bug_1304"),list(tlist(["variable","name"],"f")),""),..
+list("EOL"),tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),..
+6);
 if ~and(macr2tree(bug_1304)==reftree) then bugmes();quit;end
-// Test with input which is not a variable reference
-reftree.name = "ans";
 if ~and(macr2tree(evstr("bug_1304"))==reftree) then bugmes();quit;end
 // Reference tree generated using sci2exp
-reftree = tlist(["program","name","outputs","inputs","statements","nblines"],"ans",..
-       list(),list(),..
-       list(list("EOL"),..
-       tlist(["equal","expression","lhs","endsymbol"],..
-       tlist(["funcall","rhs","name","lhsnb"],list(tlist(["cste","value"],"internal_bug_1304()")),..
-       "disp",1),list(tlist(["variable","name"],"ans")),""),list("EOL"),list("EOL"),..
-       tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),5);
+reftree = tlist(["program","name","outputs","inputs","statements","nblines"],"internal_bug_1304",..
+list(),list(),..
+list(list("EOL"),..
+tlist(["equal","expression","lhs","endsymbol"],..
+tlist(["funcall","rhs","name","lhsnb"],list(tlist(["cste","value"],"internal_bug_1304()")),..
+"disp",1),list(tlist(["variable","name"],"ans")),""),list("EOL"),..
+tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),3);
 if ~and(macr2tree(bug_1304())==reftree) then bugmes();quit;end
index 78d1deb..e08472c 100644 (file)
 //
 
 function bug_1304()
-disp("bug_1304")
+    disp("bug_1304")
 endfunction
 
 // Reference tree generated using sci2exp
 reftree = tlist(["program","name","outputs","inputs","statements","nblines"],"bug_1304",list(),..
-       list(),..
-       list(list("EOL"),..
-       tlist(["equal","expression","lhs","endsymbol"],..
-       tlist(["funcall","rhs","name","lhsnb"],list(tlist(["cste","value"],"bug_1304")),"disp",1),..
-       list(tlist(["variable","name"],"ans")),""),list("EOL"),list("EOL"),..
-       tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),5);
+list(),..
+list(list("EOL"),..
+tlist(["equal","expression","lhs","endsymbol"],..
+tlist(["funcall","rhs","name","lhsnb"],list(tlist(["cste","value"],"bug_1304")),"disp",1),..
+list(tlist(["variable","name"],"ans")),""),list("EOL"),..
+tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),3);
 
 if ~and(macr2tree(bug_1304)==reftree) then pause;end
-
-// Test with input which is not a variable reference
-reftree.name = "ans";
 if ~and(macr2tree(evstr("bug_1304"))==reftree) then pause;end
 
 clear bug_1304
@@ -43,35 +40,33 @@ clear bug_1304
 //
 
 function f = bug_1304()
-function internal_bug_1304()
-disp("internal_bug_1304()")
-endfunction
-f = internal_bug_1304
+    function internal_bug_1304()
+        disp("internal_bug_1304()")
+    endfunction
+    f = internal_bug_1304
 endfunction
 
 // Reference tree generated using sci2exp
 reftree = tlist(["program","name","outputs","inputs","statements","nblines"],"bug_1304",..
-       list(tlist(["variable","name"],"f")),list(),..
-       list(list("EOL"),..
-       tlist(["inline","prototype","definition"],"internal_bug_1304()",..
-       ["";"disp(""internal_bug_1304()"")";" "]),list("EOL"),..
-       tlist(["equal","expression","lhs","endsymbol"],..
-       tlist(["variable","name"],"internal_bug_1304"),list(tlist(["variable","name"],"f")),""),..
-       list("EOL"),list("EOL"),tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),..
-       6);
-if ~and(macr2tree(bug_1304)==reftree) then pause;end
+list(tlist(["variable","name"],"f")),list(),..
+list(list("EOL"),..
+tlist(["inline","prototype","definition"],"internal_bug_1304()",..
+["disp(""internal_bug_1304()"")"]),list("EOL"),..
+tlist(["equal","expression","lhs","endsymbol"],..
+tlist(["variable","name"],"internal_bug_1304"),list(tlist(["variable","name"],"f")),""),..
+list("EOL"),tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),..
+6);
 
-// Test with input which is not a variable reference
-reftree.name = "ans";
+if ~and(macr2tree(bug_1304)==reftree) then pause;end
 if ~and(macr2tree(evstr("bug_1304"))==reftree) then pause;end
 
 // Reference tree generated using sci2exp
-reftree = tlist(["program","name","outputs","inputs","statements","nblines"],"ans",..
-       list(),list(),..
-       list(list("EOL"),..
-       tlist(["equal","expression","lhs","endsymbol"],..
-       tlist(["funcall","rhs","name","lhsnb"],list(tlist(["cste","value"],"internal_bug_1304()")),..
-       "disp",1),list(tlist(["variable","name"],"ans")),""),list("EOL"),list("EOL"),..
-       tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),5);
+reftree = tlist(["program","name","outputs","inputs","statements","nblines"],"internal_bug_1304",..
+list(),list(),..
+list(list("EOL"),..
+tlist(["equal","expression","lhs","endsymbol"],..
+tlist(["funcall","rhs","name","lhsnb"],list(tlist(["cste","value"],"internal_bug_1304()")),..
+"disp",1),list(tlist(["variable","name"],"ans")),""),list("EOL"),..
+tlist(["funcall","rhs","name","lhsnb"],[],"return",0),list("EOL")),3);
 
 if ~and(macr2tree(bug_1304())==reftree) then pause;end
index 56d5b4a..916b53c 100644 (file)
@@ -137,13 +137,13 @@ for k=1:2
 end
 if z<>3 then bugmes();quit;end
 //
-z=0;
+z=0;for k=1:2
     function y=foo(),y=k,endfunction
     z=z+foo();
 end
 if z<>3 then bugmes();quit;end
 //
-z=0;
+z=0;for k=1:2, function y=foo(),y=k,endfunction
     z=z+foo();
 end
 if z<>3 then bugmes();quit;end