1
function [tree]=%i_ce2sci(tree)
4
// Conversion function for Matlab insertion in cells
5
// Input: tree = Matlab operation tree
6
// Output: tree = Scilab equivalent for tree
12
if and(to.vtype<>[Cell,Unknown]) then
13
error("%i_ce2sci: destination variable is not a cell: "+to.name+" is of type "+string(to.vtype))
14
elseif to.vtype==Unknown then
15
insert(Equal(list(to),Funcall("cell",1,list(),list(to))))
18
// Just one index value
21
if type(ind)<>15 then // One value index A(xx)={...}
22
if typeof(ind)=="cste" then
23
if ind.vtype<>String then // Not :
24
tree.out(1).dims=list(1,ind.value)
26
tree.out(1).dims=from.dims
27
execstr("tree.out(1).contents=from.contents")
30
tree.out(1).dims=list(1,Unknown)
32
tree.operands(2)=list(Cste(1),ind)
33
if can_infer(tree.operands(2)) then
34
execstr("tree.out(1).contents"+expression2code(tree.operands(2))+".entries=1") // Remove this line when Scilab bug is corrected
35
execstr("tree.out(1).contents"+expression2code(tree.operands(2))+".entries=from.contents.entries")
37
tree.out(1).vtype=Cell
38
else // --- Insertion with more than one index value (index is a list) ---
39
// Cell array of struct A{p,q,...}.name... or recursive index A{p,q,...}(1,2)...
40
for kind=1:lstsize(tree.operands(2))
41
if typeof(tree.operands(2)(kind))=="cste" then
42
if tree.operands(2)(kind).vtype<>String then
43
tree.operands(2)(kind)=list(Cste(1),tree.operands(2)(kind))
48
IND=tree.operands(2)(1)
49
// Update cell dims for inference
50
if can_infer(IND) then
51
if lstsize(IND)>lstsize(tree.out(1).dims) then
52
for kd=lstsize(tree.out(1).dims):lstsize(IND)
53
tree.out(1).dims(kd)=Unknown
56
for kd=1:lstsize(tree.out(1).dims)
57
if tree.out(1).dims(kd)<>Unknown & tree.out(1).dims(kd)<IND(kd).value then
58
tree.out(1).dims(kd)=IND(kd).value
63
// Update cell contents
64
if can_infer(tree.operands(2)) then
65
infertree=tree.operands(2)
67
if typeof(tree.operands(2)(1))=="cste" then
68
if tree.operands(2)(1).vtype<>String then
71
elseif typeof(tree.operands(2)(1))=="list" then
74
tree.out(1).contents=to.contents
75
index=expression2code(infertree)
76
execstr("tree.out(1).contents"+index+"=1") // Remove this line when Scilab bug corrected
77
execstr("tree.out(1).contents"+index+"=from.infer")
79
tree.out(1).contents=cell()
82
// Two indexes: to(ind1,ind2,...)=from or more
84
tree.out(1).dims=list()
85
for k=1:lstsize(tree.operands)-2
86
tree.out(1).dims(k)=Unknown
89
// dim can be infered when index is a constant and when index value is greater than older dim and this dim is not unknown
90
for kdim=1:size(tree.operands)-2
91
if typeof(tree.operands(kdim+1))=="cste" then
92
if to.dims(kdim)<>Unknown then
93
if to.dims(kdim)<=tree.operands(kdim+1).value then
94
tree.out(1).dims(kdim)=tree.operands(kdim+1).value;
96
tree.out(1).dims(kdim)=to.dims(k)
101
tree.out(1).type=from.type
103
// Update contents...
104
infertree=tree.operands
107
if can_infer(infertree) then
108
index=expression2code(infertree)
109
execstr("tree.out(1).contents"+index+".entries=1"); // Remove this line when Scilab bug corrected
110
execstr("tree.out(1).contents"+index+".entries=from.contents.entries");
b'\\ No newline at end of file'