File: transformtree.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (77 lines) | stat: -rw-r--r-- 2,392 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function instr=transformtree(instr)
//Copyright INRIA
//TRANSFORMTREE function
//This function research and transform the equal instructions(if the lhs are a multi_operation and expression is a funcall) 
//of the matlab tree to a sup_equal instructions
//sup_equal is a tlist : tlist([sup_equal,sup_instr,nb_op],sup_instr,nb_op)
//i.e : the equal instruction [a(1),b(2:3)]=f() is replaced by 
//sup_equal, whith sup_intr list is composed to : 
//[%v1,%v2]=f()
//a(1)=%v1
//b(2:3)=%v2
//and nb_op is: the number of insert operation (in this case 2)
//Input
//instr : instruction of matlab tree before tranformation 
//Output
//instr : instruction of matlab tree after transformation
//F.B

Unknown=-1;
// Browse all the instrucions of the matlab tree:
if typeof(instr)=="ifthenelse" then
  for i=1:size(instr.then)
    instr.then(i)=transformtree((instr.then(i)))
  end
  for i=1:size(instr.elseifs)
  for k=1:size(instr.elseifs(i).then)
  instr.elseifs(i).then(k)=transformtree((instr.elseifs(i).then(k))) 
end
end  
for i=1:size(instr.else)
instr.else(i)=transformtree((instr.else(i)))
end
elseif typeof(instr)=="selectcase" then
  for i=1:size(instr.cases)
    for j=1:size(instr.cases(i).then)
      instr.cases(i).then(j)=transformtree((instr.cases(i).then(j)))
    end   
  end
  for i=1:size(instr.else)
  instr.else(i)=transformtree(instr.else(i))
end
elseif typeof(instr)=="while" then
  for i=1:size(instr.statements)
    instr.statements(i)=transformtree(instr.statements(i))
  end
elseif typeof(instr)=="for" then
  for i=1:size(instr.statements)
    instr.statements(i)=transformtree(instr.statements(i))
  end
//instruction is an equal instruction
elseif typeof(instr)=="equal" then
  if typeof(instr.expression)=="funcall" then //expression is a funcall
    nb_opr=0;
    for ind=1:size(instr.lhs)
      if typeof(instr.lhs(ind))=="operation" then
	nb_opr=nb_opr+1
      end
    end
    if nb_opr>1 then //more than one lhs insert operation
      sup_instr=list("");
      lhstemp=list();
      for j=1:size(instr.lhs) 
	if typeof(instr.lhs(j))=="operation" then
	  x=gettempvar();
	  sup_instr($+1)=Equal(list(instr.lhs(j)),x);
	  lhstemp(j)=x;
	else
	  lhstemp(j)=instr.lhs(j)
	end	   
      end
      sup_instr(1)=Equal(lhstemp,instr.expression)
//creation of the sup_equal
      instr=tlist(["sup_equal","sup_instr","nb_opr"],sup_instr,nb_opr)
    end
  end 
end
endfunction