1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2004-2006 - INRIA - Farid BELAHCENE
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
13 function instr=transformtree(instr)
14 //TRANSFORMTREE function
15 //This function research and transform the equal instructions(if the lhs are a multi_operation and expression is a funcall)
16 //of the matlab tree to a sup_equal instructions
17 //sup_equal is a tlist : tlist([sup_equal,sup_instr,nb_op],sup_instr,nb_op)
18 //i.e : the equal instruction [a(1),b(2:3)]=f() is replaced by
19 //sup_equal, whith sup_intr list is composed to :
23 //and nb_op is: the number of insert operation (in this case 2)
25 //instr : instruction of matlab tree before tranformation
27 //instr : instruction of matlab tree after transformation
30 // Browse all the instrucions of the matlab tree:
31 if typeof(instr)=="ifthenelse" then
32 for i=1:size(instr.then)
33 instr.then(i)=transformtree((instr.then(i)))
35 for i=1:size(instr.elseifs)
36 for k=1:size(instr.elseifs(i).then)
37 instr.elseifs(i).then(k)=transformtree((instr.elseifs(i).then(k)))
40 for i=1:size(instr.else)
41 instr.else(i)=transformtree((instr.else(i)))
43 elseif typeof(instr)=="selectcase" then
44 for i=1:size(instr.cases)
45 for j=1:size(instr.cases(i).then)
46 instr.cases(i).then(j)=transformtree((instr.cases(i).then(j)))
49 for i=1:size(instr.else)
50 instr.else(i)=transformtree(instr.else(i))
52 elseif typeof(instr)=="while" then
53 for i=1:size(instr.statements)
54 instr.statements(i)=transformtree(instr.statements(i))
56 elseif typeof(instr)=="for" then
57 for i=1:size(instr.statements)
58 instr.statements(i)=transformtree(instr.statements(i))
60 //instruction is an equal instruction
61 elseif typeof(instr)=="equal" then
62 if typeof(instr.expression)=="funcall" then //expression is a funcall
64 for ind=1:size(instr.lhs)
65 if typeof(instr.lhs(ind))=="operation" then
69 if nb_opr>1 then //more than one lhs insert operation
72 for j=1:size(instr.lhs)
73 if typeof(instr.lhs(j))=="operation" then
75 sup_instr($+1)=Equal(list(instr.lhs(j)),x);
78 lhstemp(j)=instr.lhs(j)
81 sup_instr(1)=Equal(lhstemp,instr.expression)
82 //creation of the sup_equal
83 instr=tlist(["sup_equal","sup_instr","nb_opr"],sup_instr,nb_opr)