~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/m2sci/percent/%i_ce2sci.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [tree]=%i_ce2sci(tree)
 
2
// Copyright INRIA
 
3
// M2SCI function
 
4
// Conversion function for Matlab insertion in cells
 
5
// Input: tree = Matlab operation tree
 
6
// Output: tree = Scilab equivalent for tree
 
7
// V.C.
 
8
 
 
9
from=tree.operands($)
 
10
to=tree.operands(1)
 
11
 
 
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))))
 
16
end
 
17
 
 
18
// Just one index value
 
19
if rhs==1 then
 
20
  ind=tree.operands(2)
 
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)
 
25
      else
 
26
        tree.out(1).dims=from.dims
 
27
        execstr("tree.out(1).contents=from.contents")
 
28
      end
 
29
    else
 
30
      tree.out(1).dims=list(1,Unknown)
 
31
    end
 
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")
 
36
    end
 
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))
 
44
        end
 
45
      end
 
46
    end
 
47
    
 
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
 
54
        end
 
55
      end
 
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
 
59
        end
 
60
      end
 
61
    end
 
62
    
 
63
    // Update cell contents
 
64
    if can_infer(tree.operands(2)) then
 
65
      infertree=tree.operands(2)
 
66
      endind=1
 
67
      if typeof(tree.operands(2)(1))=="cste" then
 
68
        if tree.operands(2)(1).vtype<>String then
 
69
          endind=2
 
70
        end
 
71
      elseif typeof(tree.operands(2)(1))=="list" then
 
72
        endind=2
 
73
      end
 
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")
 
78
    else
 
79
      tree.out(1).contents=cell()
 
80
    end
 
81
  end
 
82
// Two indexes: to(ind1,ind2,...)=from or more
 
83
else
 
84
  tree.out(1).dims=list()
 
85
  for k=1:lstsize(tree.operands)-2
 
86
    tree.out(1).dims(k)=Unknown
 
87
  end
 
88
 
 
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;
 
95
        else
 
96
          tree.out(1).dims(kdim)=to.dims(k)
 
97
        end
 
98
      end
 
99
    end
 
100
  end
 
101
  tree.out(1).type=from.type
 
102
 
 
103
  // Update contents...
 
104
  infertree=tree.operands
 
105
  infertree(1)=null()
 
106
  infertree($)=null()
 
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");
 
111
  end
 
112
end
 
113
errclear();
 
114
endfunction
 
115
 
 
116
  
 
 
b'\\ No newline at end of file'