* Bugs 16567 16586 fixed: mfile2sci() supports block %{..%}. Appended comments improved"
[scilab.git] / scilab / modules / m2sci / macros / kernel / funcallsearch.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) ???? - INRIA - Scilab
3 //
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
5 //
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.
12
13 function   [funcallname,variablename]=funcallsearch(instr,funcallname,fnamvect,variablename)
14     //
15     //  FUNCALLSEARCH recursive function (used by "translatepaths" function)
16     //  Searches the functions names in each instruction of mtlbtree
17     //  Input-Output
18     //  -funcallname : a vector which contains the names of called functions if it exists a M-file having the same name in the Paths
19     //  -variablename : a vector which contains the names of declared variables
20     //  Input
21     //  -instr : mtlbtree instruction
22     //  -fnamvect : vector which contains all M-files names found in the Paths
23
24     // case : ifthenelse instruction
25     if typeof(instr) == "ifthenelse" then
26         [funcallname,variablename]=funcallsearch(instr.expression,funcallname,fnamvect,variablename)
27         for i=1:size(instr.then)
28             [funcallname,variablename]=funcallsearch((instr.then(i)),funcallname,fnamvect,variablename)
29         end
30         for i=1:size(instr.elseifs)
31             for k=1:size(instr.elseifs(i).then)
32                 [funcallname,variablename]=funcallsearch((instr.elseifs(i).then(k)),funcallname,fnamvect,variablename)
33             end
34         end
35         for i=1:size(instr.else)
36         [funcallname,variablename]=funcallsearch((instr.else(i)),funcallname,fnamvect,variablename)
37         end
38         // case : selectcase instruction
39     elseif typeof(instr) == "selectcase" then
40         [funcallname,variablename]=funcallsearch(instr.expression,funcallname,fnamvect,variablename)
41
42         for i=1:size(instr.cases)
43             [funcallname,variablename]=funcallsearch((instr.cases(i).expression),funcallname,fnamvect,variablename)
44             for j=1:size(instr.cases(i).then)
45                 [funcallname,variablename]=funcallsearch((instr.cases(i).then(j)),funcallname,fnamvect,variablename)
46             end
47         end
48         for i=1:size(instr.else)
49         [funcallname,variablename]=funcallsearch(instr.else(i),funcallname,fnamvect,variablename)
50         end
51         // case : while instruction
52     elseif typeof(instr) == "while" then
53         [funcallname,variablename]=funcallsearch(instr.expression,funcallname,fnamvect,variablename)
54         for i=1:size(instr.statements)
55             [funcallname,variablename]=funcallsearch(instr.statements(i),funcallname,fnamvect,variablename)
56         end
57         // case : for instruction
58     elseif typeof(instr) == "for" then
59         [funcallname,variablename]=funcallsearch(instr.expression,funcallname,fnamvect,variablename)
60         for i=1:size(instr.statements)
61             [funcallname,variablename]=funcallsearch(instr.statements(i),funcallname,fnamvect,variablename)
62         end
63         // case : cste instruction
64     elseif  typeof(instr)== "cste" then
65         return
66         // case : variable instruction
67     elseif typeof(instr)=="variable"
68         if find(instr.name==variablename)==[] & find(instr.name==stripblanks(part(fnamvect,1:24)))<>[] & find(instr.name==funcallname)==[] then
69             funcallname=[funcallname;fnamvect(find(instr.name==stripblanks(part(fnamvect,1:24))))]
70         else
71             return
72         end
73         // case : equal instruction
74     elseif typeof(instr) == "equal" then
75         [funcallname,variablename]=funcallsearch(instr.expression,funcallname,fnamvect,variablename)
76         // case : expression is a funcall
77     elseif typeof(instr) == "funcall" then
78         if find(funcallname==instr.name) == [] & find(instr.name==stripblanks(part(fnamvect,1:24)))<>[]  then
79             if size(find(instr.name==stripblanks(part(fnamvect,1:24))),2)==1 then
80                 funcallname=[funcallname;fnamvect(find(instr.name==stripblanks(part(fnamvect,1:24))))]
81             else
82                 findvect=find(instr.name==stripblanks(part(fnamvect,1:24)))
83                 funcallname=[funcallname;fnamvect(findvect(2))]
84                 st = " " + mtlbtree.name + ": " + fnamvect(findvect(1))
85                 for i=2:size(findvect,2)
86                     st = st+ " <-> " + fnamvect(findvect(i))
87                 end
88                 st = st + gettext(": The 24 first characters of the files names are equal: ");
89                 warning(st)
90             end
91         end
92         // case : expression is cste
93         if typeof(instr.rhs)== "constant" then
94             return
95         else
96             for ind=1:size(instr.rhs)
97                 [funcallname,variablename]=funcallsearch(instr.rhs(ind),funcallname,fnamvect,variablename)
98             end
99         end
100         // case : operation instruction
101     elseif typeof(instr) == "operation" then
102         for ind=1:size(instr.operands)
103             [funcallname,variablename]=funcallsearch(instr.operands(ind),funcallname,fnamvect,variablename)
104         end
105     end
106
107 endfunction