summaryrefslogtreecommitdiff
path: root/2.3-1/macros/ASTManagement/AST_HandleFunCC.sci
blob: 12cb577ac0fddb68351534c99dfcca7decec8735 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
function [FileInfo,SharedInfo] = AST_HandleFunCC(NCol,FileInfo,SharedInfo)
// function [FileInfo,SharedInfo] = AST_HandleEndGenFun(FileInfo,SharedInfo,ASTFunType)
// -----------------------------------------------------------------
// #RNU_RES_B
// Handles the EndFuncall, EndOperation and EndEqual tags of the AST.
// ASTFunType can be 'Funcall', 'Operation', 'Equal'
// Structure of Funcall:
// overloading function for "funcall" type tlist string function
// this is a node of the AST
// fields:
//     rhs  : a list
//     name : string, the name of the function
//     lhsnb: number, the number of function lhs
//  txt=['Funcall  : '+F.name
//       '  #lhs   : '+string(F.lhsnb)
//       '  Rhs    : '
//       '      '+objectlist2string(F.rhs)
//       'EndFuncall'
//      ]
// #RNU_RES_E
//
// Input data:
// //NUT: add description here
//
// Output data:
// //NUT: add description here
//
// Status:
// 11-Apr-2007 -- Ukasha Noor: Author.
//
// Copyright 2017 Ukasha Noor.
// Contact: ukashanoor.iiitk@gmail.com
// -----------------------------------------------------------------

// ------------------------------
// --- Check input arguments. ---
// ------------------------------

// -----------------------
// --- Initialization. ---
// -----------------------
nxtscifunname   = SharedInfo.NextSCIFunName;
nxtscifunnumber = SharedInfo.NextSCIFunNumber;
ReportFileName         = FileInfo.Funct(nxtscifunnumber).ReportFileName;

global SCI2CSTACK
global StackPosition;
global STACKDEDUG
// ---------------------------
// --- End Initialization. ---
// ---------------------------

// ------------------------------
// --- Read output parameters. --
// ------------------------------
LhsField = AST_PopASTStack();
NOutArg = 0;
OutputArgumentNames = [];
OutputArgumentScope = [];
while (LhsField ~= 'Lhs       :')
   NOutArg = NOutArg + 1;
   [OutputArgumentNames(NOutArg),OutputArgumentScope(NOutArg)] = AST_ExtractNameAndScope(LhsField);
   LhsField = AST_PopASTStack();
   if (LhsField == 'Expression:')
     error(9999, 'Found Expression: before Lhs');
   elseif (LhsField == 'Equal')
     error(9999, 'Found Equal before Lhs');
   end
end

// ------------------------------
// --- Read input parameters. ---
// ------------------------------


RhsField = AST_PopASTStack();
InputArgumentNames = [];
InputArgumentScope = [];
NInArg = 0;
InArg = [];
while (RhsField ~= 'Expression:')
   NInArg = NInArg + 1;
   if RhsField <> 'Operands:'
   [InputArgumentNames(NInArg),InputArgumentScope(NInArg)] = AST_ExtractNameAndScope(RhsField);
   end
   //disp(InputArgumentNames(NInArg));
   //InArg(NInArg) = RhsField;
   RhsField = AST_PopASTStack();
end
InputArgumentNames = SCI2Cflipud(InputArgumentNames);
InputArgumentScope = SCI2Cflipud(InputArgumentScope);

disp(NInArg);


// -------------------------------------
// --- Generate the InArg structure. ---
// -------------------------------------
//#RNU_RES_E
for counterinputargs = 1:NInArg
   InArg(counterinputargs).Name=InputArgumentNames(counterinputargs);
   InArg(counterinputargs).Scope=InputArgumentScope(counterinputargs);
end

//#RNU_RES_B
// -------------------------------------
// --- Generate the InArg structure. ---
// -------------------------------------
//#RNU_RES_E
OutArg = [];
for counteroutputargs = 1:NOutArg
   OutArg(counteroutputargs).Name=OutputArgumentNames(counteroutputargs);
   OutArg(counteroutputargs).Scope=OutputArgumentScope(counteroutputargs);
end
disp(NOutArg);

// ------------------------
// --- Print Some Info. ---
// ------------------------

PrintStringInfo('N Input Arguments: '+string(NInArg),ReportFileName,'file','y','n');
PrintStringInfo('N Output Arguments: '+string(NOutArg),ReportFileName,'file','y');
   //#RNU_RES_E
   for counterinputargs = 1:NInArg
      //#RNU_RES_B
      PrintStringInfo('Input Argument Number '+string(counterinputargs)+': '+InArg(counterinputargs).Name,...
         ReportFileName,'file','y','n');
      PrintStringInfo('   Scope: '+InArg(counterinputargs).Scope,...
         ReportFileName,'file','y','n');
      //#RNU_RES_E
   end
   for counteroutputargs = 1:NOutArg
      //#RNU_RES_B
      PrintStringInfo('Output Argument Number '+string(counteroutputargs)+': '+OutArg(counteroutputargs).Name,...
         ReportFileName,'file','y','n');
      //PrintStringInfo('   Scope: '+ OutArg(counterinputargs).Scope,ReportFileName,'file','y','n');
      //#RNU_RES_E
   end

NOutArg_mod = NOutArg;

FunTypeAnnot = '';
FunSizeAnnot = '';
NLhsArg = 0;
LhsArg = [];
PrintStringInfo('...Equal not found.',ReportFileName,'file','y');

PrintStringInfo('***Analyzing Input Arguments***',ReportFileName,'file','y');
UpdatedInArg = InArg;
[InArg,SharedInfo] = ST_GetInArgInfo(InArg,NInArg,FileInfo,SharedInfo,'OpEqual');

NCol = NCol + 1;
NRow = NInArg/NCol;

com_type = 0;
for i = 1:NInArg
	if InArg(i).Type == 'z'
		com_type = 1;
	end
end
	

if com_type == 0
	PrintStringInfo('   Generating Out Arg names.',ReportFileName,'file','y');
	OutArg(1).Type      = InArg(1).Type;
	OutArg(1).Size(1)   = string(NCol);
	OutArg(1).Size(2)   = string(NRow);
	OutArg(1).Dimension = 2;
	OutArg(1).Value     = InArg(1).Value;
	OutArg(1).FindLike  = InArg(1).FindLike;
else
	PrintStringInfo('   Generating Out Arg names.',ReportFileName,'file','y');
	OutArg(1).Type      = 'z';
	OutArg(1).Size(1)   = string(NCol);
	OutArg(1).Size(2)   = string(NRow);
	OutArg(1).Dimension = 2;
	OutArg(1).Value     = InArg(1).Value;
	OutArg(1).FindLike  = InArg(1).FindLike;
end

//--- Check for output Argument in symbol table ---//
OutArg = ST_AnalyzeScope(OutArg,NOutArg,FileInfo,SharedInfo);

//--- Put the output Argument in symbol table ---//
ST_InsOutArg_Dup(InArg,NInArg,OutArg,NOutArg,com_type,FileInfo,SharedInfo,'all');


endfunction