summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Delamarre <cdl@esi-group.com>2020-10-23 11:25:11 +0200
committerAntoine ELIAS <antoine.elias@esi-group.com>2020-10-27 16:48:29 +0100
commit464eed23f89ae309886ffdabeea5a5d8ac7ad25e (patch)
treec6d09877b78b7013432936d653c039de7382d72c
parentbc87e5e8ec8bdd171f6ecfbf846418663687b5f9 (diff)
downloadscilab-6.1.zip
scilab-6.1.tar.gz
macr2tree, tree2code: matrix cell exp.6.1
https://bugzilla.scilab.org/show_bug.cgi?id=16297 https://bugzilla.scilab.org/show_bug.cgi?id=16557 test_run functions bug_16397 // for both this commit manage only cell creation using {}. Change-Id: If7577584e60855267834fe1e75a701a7bbaf61ad
-rw-r--r--scilab/CHANGES.md2
-rw-r--r--scilab/modules/ast/includes/ast/treevisitor.hxx2
-rw-r--r--scilab/modules/ast/src/cpp/ast/treevisitor.cpp105
-rw-r--r--scilab/modules/functions/macros/expression2code.sci17
-rw-r--r--scilab/modules/functions/tests/nonreg_tests/bug_16297.tst32
5 files changed, 114 insertions, 44 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index cf3ce0a..34e4bd7 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -304,6 +304,7 @@ Bug Fixes
304* [#16193](https://bugzilla.scilab.org/16193): `covStart()` clear previous coverage information. `profileEnable()` could be use to append a macro later on. 304* [#16193](https://bugzilla.scilab.org/16193): `covStart()` clear previous coverage information. `profileEnable()` could be use to append a macro later on.
305* [#16196](https://bugzilla.scilab.org/16196): `covStart()` help page was incomplete about the API usage. 305* [#16196](https://bugzilla.scilab.org/16196): `covStart()` help page was incomplete about the API usage.
306* [#16274](https://bugzilla.scilab.org/16274): assert_checkequal() did not considered equal matching Nan or void elements in (nested) containers. 306* [#16274](https://bugzilla.scilab.org/16274): assert_checkequal() did not considered equal matching Nan or void elements in (nested) containers.
307* [#16297](https://bugzilla.scilab.org/16297): After function test(), e={}, endfunction; macr2tree(test) crashes Scilab.
307* [#16337](https://bugzilla.scilab.org/16337): The 3rd output of `[U,km,ku] = unique(..)` was not implemented. 308* [#16337](https://bugzilla.scilab.org/16337): The 3rd output of `[U,km,ku] = unique(..)` was not implemented.
308* [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2. 309* [#16342](https://bugzilla.scilab.org/16342): `strcat()` was much slower in Scilab 6.0.2.
309* [#16350](https://bugzilla.scilab.org/16350): in if/while conditions, the empty sparse boolean was considered as TRUE. 310* [#16350](https://bugzilla.scilab.org/16350): in if/while conditions, the empty sparse boolean was considered as TRUE.
@@ -340,6 +341,7 @@ Bug Fixes
340* [#16549](https://bugzilla.scilab.org/16549): simple script crashed Scilab in GUI mode. 341* [#16549](https://bugzilla.scilab.org/16549): simple script crashed Scilab in GUI mode.
341* [#16551](https://bugzilla.scilab.org/16551): `num2cell` returned {} for any input array of empty strings. 342* [#16551](https://bugzilla.scilab.org/16551): `num2cell` returned {} for any input array of empty strings.
342* [#16553](https://bugzilla.scilab.org/16553): `unique(["" ""])` returned `["" ""]`. 343* [#16553](https://bugzilla.scilab.org/16553): `unique(["" ""])` returned `["" ""]`.
344* [#16557](https://bugzilla.scilab.org/16557): `macr2tree` + `tree2code` translated `e={2}` into `"e=1"` and `e={2,"ab"}` into `"e=[2,"ab"]"`.
343 345
344 346
345### Bugs fixed in 6.1.0: 347### Bugs fixed in 6.1.0:
diff --git a/scilab/modules/ast/includes/ast/treevisitor.hxx b/scilab/modules/ast/includes/ast/treevisitor.hxx
index e206f6b..b6e432b 100644
--- a/scilab/modules/ast/includes/ast/treevisitor.hxx
+++ b/scilab/modules/ast/includes/ast/treevisitor.hxx
@@ -62,6 +62,7 @@ public:
62 virtual void visit(const NotExp &e); 62 virtual void visit(const NotExp &e);
63 virtual void visit(const TransposeExp &e); 63 virtual void visit(const TransposeExp &e);
64 virtual void visit(const FunctionDec &e); 64 virtual void visit(const FunctionDec &e);
65 virtual void visit(const CellExp &e);
65 66
66 inline types::List* getList() 67 inline types::List* getList()
67 { 68 {
@@ -73,6 +74,7 @@ public:
73 static types::List* createOperation(); 74 static types::List* createOperation();
74 static types::List* createAssign(); 75 static types::List* createAssign();
75 static types::InternalType* getVerbose(const Exp& e); 76 static types::InternalType* getVerbose(const Exp& e);
77 static types::List* matrixOrCellExp(const exps_t& lines, TreeVisitor& me, const std::wstring& what);
76 78
77 types::InternalType* getEOL(); 79 types::InternalType* getEOL();
78private: 80private:
diff --git a/scilab/modules/ast/src/cpp/ast/treevisitor.cpp b/scilab/modules/ast/src/cpp/ast/treevisitor.cpp
index c8bb815..9e5bffa 100644
--- a/scilab/modules/ast/src/cpp/ast/treevisitor.cpp
+++ b/scilab/modules/ast/src/cpp/ast/treevisitor.cpp
@@ -17,6 +17,7 @@
17#include "printvisitor.hxx" 17#include "printvisitor.hxx"
18#include "execvisitor.hxx" 18#include "execvisitor.hxx"
19#include "token.hxx" 19#include "token.hxx"
20#include "cell.hxx"
20 21
21extern "C" 22extern "C"
22{ 23{
@@ -154,49 +155,28 @@ void TreeVisitor::visit(const MatrixExp &e)
154 return; 155 return;
155 } 156 }
156 157
157 types::List* sub = createOperation(); 158 l = matrixOrCellExp(lines, *this, L"cc");
158 types::List* ope = new types::List(); 159}
159
160 int idx = 0;
161 for (auto it : lines)
162 {
163 it->accept(*this);
164
165 if (idx >= 2)
166 {
167 sub->append(ope);
168 ope->killMe();
169 sub->append(new types::String(L"cc"));
170 160
171 //create a new operation 161void TreeVisitor::visit(const CellExp &e)
172 //put previous stage in lhs and 162{
173 //result in rhs 163 exps_t lines = e.getLines();
174 types::List* subcolcatOperation = createOperation();
175 types::List* subcolcatOperands = new types::List();
176 subcolcatOperands->append(sub);
177 sub->killMe();
178 //add EOL
179 //subcolcatOperands->append(getEOL());
180 types::InternalType* tmp = getList();
181 subcolcatOperands->append(tmp);
182 tmp->killMe();
183 164
184 ope = subcolcatOperands; 165 if (lines.size() == 0)
185 sub = subcolcatOperation; 166 {
186 } 167 l = createConst(new types::Cell());
187 else 168 return;
188 { 169 }
189 types::InternalType* tmp = getList();
190 ope->append(tmp);
191 tmp->killMe();
192 }
193 170
194 ++idx; 171 if (lines.size() == 1)
172 {
173 lines.front()->accept(*this);
174 types::List* pL = getList();
175 pL->get(pL->getSize() - 1)->getAs<types::String>()->set(0, L"crc");
176 return;
195 } 177 }
196 sub->append(ope); 178
197 ope->killMe(); 179 l = matrixOrCellExp(lines, *this, L"ccc");
198 sub->append(new types::String(L"cc"));
199 l = sub;
200} 180}
201 181
202void TreeVisitor::visit(const MatrixLineExp &e) 182void TreeVisitor::visit(const MatrixLineExp &e)
@@ -1102,4 +1082,51 @@ types::InternalType* TreeVisitor::getVerbose(const Exp& e)
1102 return new types::String(L";"); 1082 return new types::String(L";");
1103 } 1083 }
1104} 1084}
1085
1086types::List* TreeVisitor::matrixOrCellExp(const exps_t& lines, TreeVisitor& me, const std::wstring& what)
1087{
1088 types::List* sub = createOperation();
1089 types::List* ope = new types::List();
1090
1091 int idx = 0;
1092 for (auto it : lines)
1093 {
1094 it->accept(me);
1095
1096 if (idx >= 2)
1097 {
1098 sub->append(ope);
1099 ope->killMe();
1100 sub->append(new types::String(what.data()));
1101
1102 //create a new operation
1103 //put previous stage in lhs and
1104 //result in rhs
1105 types::List* subcolcatOperation = createOperation();
1106 types::List* subcolcatOperands = new types::List();
1107 subcolcatOperands->append(sub);
1108 sub->killMe();
1109 //add EOL
1110 //subcolcatOperands->append(getEOL());
1111 types::InternalType* tmp = me.getList();
1112 subcolcatOperands->append(tmp);
1113 tmp->killMe();
1114
1115 ope = subcolcatOperands;
1116 sub = subcolcatOperation;
1117 }
1118 else
1119 {
1120 types::InternalType* tmp = me.getList();
1121 ope->append(tmp);
1122 tmp->killMe();
1123 }
1124
1125 ++idx;
1126 }
1127 sub->append(ope);
1128 ope->killMe();
1129 sub->append(new types::String(what.data()));
1130 return sub;
1131}
1105} 1132}
diff --git a/scilab/modules/functions/macros/expression2code.sci b/scilab/modules/functions/macros/expression2code.sci
index 4b7713e..e634565 100644
--- a/scilab/modules/functions/macros/expression2code.sci
+++ b/scilab/modules/functions/macros/expression2code.sci
@@ -35,6 +35,13 @@ function C=expression2code(e)
35 // --------- 35 // ---------
36 case "operation" then 36 case "operation" then
37 operator=e.operator 37 operator=e.operator
38 bracket = ["[", "]"];
39 // if Cell Exp {}
40 if or(operator == ["ccc", "crc"]) then
41 operator = part(operator, 2:$);
42 bracket = ["{", "}"];
43 end
44
38 operands=[] 45 operands=[]
39 nb_op=size(e.operands) 46 nb_op=size(e.operands)
40 if and(operator<>["cc","cceol"]) then 47 if and(operator<>["cc","cceol"]) then
@@ -62,7 +69,7 @@ function C=expression2code(e)
62 end 69 end
63 end 70 end
64 end 71 end
65 C="["+strcat(operands,",")+"]" 72 C=bracket(1)+strcat(operands,",")+bracket(2);
66 // Multi-line column concatenation 73 // Multi-line column concatenation
67 elseif operator=="cceol" then 74 elseif operator=="cceol" then
68 for i=1:nb_op 75 for i=1:nb_op
@@ -77,7 +84,7 @@ function C=expression2code(e)
77 end 84 end
78 85
79 if i==1 then 86 if i==1 then
80 C="[" 87 C=bracket(1)
81 if size(opi,"*")>1 then 88 if size(opi,"*")>1 then
82 C = [C+opi(1);opi(2:$)] 89 C = [C+opi(1);opi(2:$)]
83 else 90 else
@@ -91,12 +98,12 @@ function C=expression2code(e)
91 else 98 else
92 C = [C(1:$-1);C($)+opi] 99 C = [C(1:$-1);C($)+opi]
93 end 100 end
94 C($)=C($)+"]" 101 C($)=C($)+bracket(2)
95 end 102 end
96 end 103 end
97 // Column concatenation 104 // Column concatenation
98 elseif operator=="cc" then 105 elseif operator=="cc" then
99 C="[" 106 C=bracket(1)
100 for i=1:nb_op 107 for i=1:nb_op
101 opi=expression2code(e.operands(i)) 108 opi=expression2code(e.operands(i))
102 // Delete [ and ] if there are... 109 // Delete [ and ] if there are...
@@ -127,7 +134,7 @@ function C=expression2code(e)
127 end 134 end
128 end 135 end
129 end 136 end
130 C($)=C($)+"]" 137 C($)=C($)+bracket(2)
131 // Extraction 138 // Extraction
132 elseif operator=="ext" then 139 elseif operator=="ext" then
133 if size(e.operands)==1 then 140 if size(e.operands)==1 then
diff --git a/scilab/modules/functions/tests/nonreg_tests/bug_16297.tst b/scilab/modules/functions/tests/nonreg_tests/bug_16297.tst
new file mode 100644
index 0000000..4bb759b
--- /dev/null
+++ b/scilab/modules/functions/tests/nonreg_tests/bug_16297.tst
@@ -0,0 +1,32 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2020 - ESI Group - Cedric Delamarre
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7//
8// <-- CLI SHELL MODE -->
9// <-- NO CHECK REF -->
10// <-- Non-regression test for bug 16297 -->
11//
12// <-- Bugzilla URL -->
13// https://bugzilla.scilab.org/show_bug.cgi?id=16297
14//
15// <-- Short Description -->
16// After function test(), e={}, endfunction; macr2tree(test) crashes Scilab
17
18function test()
19 e = {};
20 e = {1,2};
21 e = {1,2;3,4};
22endfunction
23t=macr2tree(test);
24
25result = ["function test()"; ...
26 "e = {};"; ...
27 "e = {1,2};"; ...
28 "e = {1,2;3,4};"; ...
29 "endfunction"; ...
30 "" ];
31
32assert_checkequal(tree2code(t), result); \ No newline at end of file