summaryrefslogtreecommitdiff
path: root/2.3-1/macros/SymbolTable/ST_InsForCntVars.sci
blob: b0e6f356dac87619019e0a8e6bad6a5ce47487ae (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
189
190
191
function [OutArg,SharedInfo] = ST_InsForCntVars(InArg,NInArg,OutArg,NOutArg,FunctionName,FileInfo,SharedInfo)
// function [OutArg,SharedInfo] = ST_InsForCntVars(InArg,NInArg,OutArg,NOutArg,FunctionName,FileInfo,SharedInfo)
// -----------------------------------------------------------------
// //NUT: add description here
//
// Input data:
// //NUT: add description here
//
// Output data:
// //NUT: add description here
//
// Status:
// 26-Oct-2007 -- Raffaele Nutricato: Author.
// 26-Oct-2007 -- Alberto Morea: Test Ok.
//
// Copyright 2007 Raffaele Nutricato & Alberto Morea.
// Contact: raffaele.nutricato@tiscali.it
// -----------------------------------------------------------------


// ------------------------------
// --- Check input arguments. ---
// ------------------------------
SCI2CNInArgCheck(argn(2),7,7);

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

// #RNU_RES_B
PrintStringInfo(' ',ReportFileName,'file','y');
PrintStringInfo('***Checking if the current function is handling for counter variables.***',ReportFileName,'file','y');
// #RNU_RES_E

// ---------------------------
// --- End Initialization. ---
// ---------------------------

// -----------------------------------------------
// --- Initial Check on For counter variables. ---
// -----------------------------------------------
if ((SharedInfo.ForExpr.OnExec > 0) & (NOutArg==1) & (OutArg.Scope~='Temp'))
   // #RNU_RES_B
   // If we are here, for sure we are in the last assignment of a for loop expression.
   //
   // All the following cases must be handled:
   // OpColon (1,10,cnt) or Opcolon (1,1,10,cnt) --> cnt must be redefined to dim=0
   // cnt = a; where a is scalar
   // OpEqual(TMP,cnt); where TMP is matrix --> cnt must be redefined to dim=0, a SCI2Cint counter must be generated
   // Fun(TMP,cnt); where TMP is matrix.--> cnt must be redefined to dim=0, a SCI2Cint counter must be generated, CNT must be generated where CNT is a Matrix
   // #RNU_RES_E
   if (FunctionName == 'OpColon')
      // #RNU_RES_B
      PrintStringInfo('   The for expression is using an OpColon-based assignment',ReportFileName,'file','y');
      // #RNU_RES_E
      SharedInfo.SkipNextFun = 1;
      
      OutArg.Size(1)   = '1';
      OutArg.Size(2)   = '1';
      OutArg.Value     = %nan;
      OutArg.FindLike  = 0;
      OutArg.Dimension = 0;
      SharedInfo.ForExpr.OpColonInfoIn1 = InArg(1).Name;

      if (NInArg == 2)
         SharedInfo.ForExpr.OpColonInfoIn2 = '1';
         SharedInfo.ForExpr.OpColonInfoIn3 = InArg(2).Name;
      else 
         SharedInfo.ForExpr.OpColonInfoIn2 = InArg(2).Name;
         if isnan(InArg(2).Value)
            EM_UnknownStep(ReportFileName);
         end
         
         SharedInfo.ForExpr.OpColonInfoIn3 = InArg(3).Name;
      end        
      
      // #RNU_RES_B
      // Generate all info to generate the C for expression
      // #RNU_RES_E
      SharedInfo.ForExpr.AssignmentFun = SharedInfo.CFunId.OpColon;
      SharedInfo.ForExpr.IntCntArg    = [];
      SharedInfo.ForExpr.MtxValCntArg = [];
      SharedInfo.ForExpr.SclValCntArg = OutArg;

   elseif ((FunctionName == 'OpEqual') & (SharedInfo.ForExpr.AssignmentFun == 0))
      // #RNU_RES_B
      //NUT: Test also that SharedInfo.ForExpr.AssignmentFun because sometimes Equal are dummy!
      //NUT: verifica se e' giusta questa mia affermazione.
      // #RNU_RES_E
      if (OutArg.Dimension > 0)
         // #RNU_RES_B
         PrintStringInfo('   The for expression is using a Matrix-Equal-based assignment',ReportFileName,'file','y');
         // #RNU_RES_E
         SharedInfo.SkipNextFun = 1; //NUT: forse qui sarebbe meglio mettere uno skipnextequal per precisione.
         // #RNU_RES_B
         //NUT: a dire il vero occorre capire se c'e' differenza tra i vari skip.
         // #RNU_RES_E
         OutArg.Size(1)   = '1';
         OutArg.Size(2)   = '1';
         OutArg.Value     = %nan;
         OutArg.FindLike  = 0;
         OutArg.Dimension = 0;
         
         // #RNU_RES_B
         // Introduce the int counter variable.
         // #RNU_RES_E
         NNewArg = 1;
         NewArg(NNewArg).Name      = SharedInfo.ASTReader.TempForCntVarsName+string(SharedInfo.CountForTempVars);
         SharedInfo.CountForTempVars = SharedInfo.CountForTempVars + 1;
         NewArg(NNewArg).Size(1)   = '1';
         NewArg(NNewArg).Size(2)   = '1';
         NewArg(NNewArg).Type      = 'i';
         NewArg(NNewArg).Value     = 0;
         NewArg(NNewArg).FindLike  = 0;
         NewArg(NNewArg).Dimension = 0;         
         NewArg(NNewArg).Scope     = 'Temp';         
         
         // #RNU_RES_B
         // Insert New Arguments in the symbol table.
         // #RNU_RES_E
         NNewArg = 1;
         ST_InsOutArg(NewArg,NNewArg,FileInfo,SharedInfo,'all');
         
         // #RNU_RES_B
         // Generate all info to generate the C for expression
         // #RNU_RES_E
         SharedInfo.ForExpr.AssignmentFun = SharedInfo.CFunId.EqMatrix;
         SharedInfo.ForExpr.IntCntArg    = NewArg(1);
         SharedInfo.ForExpr.MtxValCntArg = InArg(1);
         SharedInfo.ForExpr.SclValCntArg = OutArg;
      else
         // #RNU_RES_B
         PrintStringInfo('   The for expression is using a Scalar-Equal-based assignment',ReportFileName,'file','y');
         // #RNU_RES_E
         SharedInfo.ForExpr.AssignmentFun = SharedInfo.CFunId.EqScalar;
      end
   else
      if (OutArg.Dimension > 0)
         // #RNU_RES_B
         PrintStringInfo('   The for expression is using a Matrix-Function-based assignment',ReportFileName,'file','y');

         // Introduce the val counter variable.
         // #RNU_RES_E
         NewArg = OutArg;
         OutArg.Name = SharedInfo.ASTReader.TempForValVarsName+OutArg.Name;

         // #RNU_RES_B
         // Set the counter variable to scalar.
         // #RNU_RES_E
         NNewArg = 1;
         NewArg(NNewArg).Size(1)   = '1';
         NewArg(NNewArg).Size(2)   = '1';
         NewArg(NNewArg).Value     = %nan;
         NewArg(NNewArg).FindLike  = 0;
         NewArg(NNewArg).Dimension = 0;      
         
         // #RNU_RES_B
         // Introduce the int counter variable.
         // #RNU_RES_E
         NNewArg = 2;
         NewArg(NNewArg).Name      = SharedInfo.ASTReader.TempForCntVarsName+string(SharedInfo.CountForTempVars);
         SharedInfo.CountForTempVars = SharedInfo.CountForTempVars + 1;
         NewArg(NNewArg).Size(1)   = '1';
         NewArg(NNewArg).Size(2)   = '1';
         NewArg(NNewArg).Type      = 'i';
         NewArg(NNewArg).Value     = 0;
         NewArg(NNewArg).FindLike  = 0;
         NewArg(NNewArg).Dimension = 0;         
         NewArg(NNewArg).Scope     = 'Temp';         
         
         // #RNU_RES_B
         // Insert New Arguments in the symbol table.         
         // #RNU_RES_E
         NNewArg  = 2;
         ST_InsOutArg(NewArg,NNewArg,FileInfo,SharedInfo,'all');
         
         // #RNU_RES_B
         // Generate all info to generate the C for expression
         // #RNU_RES_E
         SharedInfo.ForExpr.AssignmentFun = SharedInfo.CFunId.GenFunMtx;
         SharedInfo.ForExpr.IntCntArg    = NewArg(2);
         SharedInfo.ForExpr.MtxValCntArg = OutArg(1);
         SharedInfo.ForExpr.SclValCntArg = NewArg(1);
      end
   end   
end

endfunction