File: macrovar.sci

package info (click to toggle)
scilab 2.6-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 54,632 kB
  • ctags: 40,267
  • sloc: ansic: 267,851; fortran: 166,549; sh: 10,005; makefile: 4,119; tcl: 1,070; cpp: 233; csh: 143; asm: 135; perl: 130; java: 39
file content (72 lines) | stat: -rw-r--r-- 1,693 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
function vars=macrovar(macro)
// Returns in a list the set of varibles used by a macro
//    mac  : macro
//    vars : list(in,out,globals,called,locals)
//           in : input variables
//           out: output variables
//           globals: global variables
//           called : macros called
//           locals : local variables
//!
//origin S Steer inria 1992
// Copyright INRIA
if type(macro)==11 then comp(macro),end
if type(macro)<>13 then error('Argument to macrovars must be a macro!'),end
lst=macr2lst(macro);
out=lst(2)',if prod(size(out))==0 then out =[],end
in=lst(3)'
vars=[]
getted=[]
[vars,getted]=listvars(lst)
ng=prod(size(getted))
globals=[],called=[]
for k=1:ng
  if (find(getted(k)==vars)==[])&(find(getted(k)==in)==[]) then 
    if whereis(getted(k))<>[] then
      called=[called;getted(k)]
    elseif exists(getted(k))==0 then
      globals=[globals;getted(k)]
    else
      w=null()
      w=evstr(getted(k))
      if type(w)==11|type(w)==13 then
        called=[called;getted(k)]
      else
        globals=[globals;getted(k)]
      end
    end
  end
end
locals=[]
nl=prod(size(vars))
for k=1:nl
  if (find(vars(k)==in)==[])&(find(vars(k)==out)==[]) then 
    locals=[locals;vars(k)]
  end
end
vars=list(in,out,globals,called,locals)

function [vars,getted]=listvars(lst)
for lstk=lst
  if type(lstk)==15 then
    [vars,getted]=listvars(lstk)
  else
    if lstk(1)=='1'|lstk(1)=='for' then 
       vars=[vars;addvar(lstk(2))],
    elseif lstk(1)=='2' then 
       getted=[getted;addget(lstk(2))],
    end
  end
end

function vnam=addvar(vnam)
if find(vnam==vars)<>[] then 
  vnam=[]
end

function vnam=addget(vnam)
if find(vnam==getted)<>[] then 
  vnam=[]
end