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
|
function [FileInfo,SharedInfo] = AST_HandleWhileStatem(FileInfo,SharedInfo)
// -----------------------------------------------------------------
//#RNU_RES_B
// Handles the WhileStatements tag of the AST.
//
// txt=['While'
// ' WhileExpression:'
// ' '+string(W.expression)
// ' WhileStatements:'
// ' '+objectlist2string(W.statements)
// 'EndWhile']
//
//#RNU_RES_E
// Input data:
// //NUT: add description here
//
// Output data:
// //NUT: add description here
//
// Status:
// 20-Jan-2008 -- Edoardo Nutricato: Author.
// 20-Jan-2008 -- Rubby Nutricato: Minor Changes.
//
// Copyright 2007 Raffaele Nutricato.
// Contact: raffaele.nutricato@tiscali.it
// -----------------------------------------------------------------
//#RNU_RES_B
//NUT: accertati che l'epilogo e il prologo del while siano effettivamente differenti o se
//NUT: si puo' avere un solo file utilizzato sia per il prologo che per l'epilogo.
//NUT: da sistemare senza le global
//#RNU_RES_E
global SCI2CSTACK
global StackPosition;
global STACKDEDUG
<<<<<<< HEAD
IfCondArg = [];
NIfCondArg = 0;
=======
>>>>>>> 9e5793a7b05b23e6044a6d7a9ddd5db39ba375f0
// ------------------------------
// --- Check input arguments. ---
// ------------------------------
SCI2CNInArgCheck(argn(2),2,2);
// -----------------------
// --- Initialization. ---
// -----------------------
nxtscifunname = SharedInfo.NextSCIFunName;
nxtscifunnumber = SharedInfo.NextSCIFunNumber;
ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
CPass1WhileProlFileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level);
PrintStepInfo('Handling WhileStatements',FileInfo.Funct(nxtscifunnumber).ReportFileName,'file');
// ---------------------------
// --- End Initialization. ---
// ---------------------------
//#RNU_RES_B
// -----------------------------------------------
// --- Resume the correct name while CPass1V1. ---
// -----------------------------------------------
//#RNU_RES_E
tmpfilename = FileInfo.Funct(nxtscifunnumber).CPass1FileName;
FileInfo.Funct(nxtscifunnumber).CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level);
FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level) = tmpfilename;
CPass1WhileProlFileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level);
PrintStringInfo(' Redirecting C code to: '+FileInfo.Funct(nxtscifunnumber).CPass1FileName,FileInfo.Funct(nxtscifunnumber).ReportFileName,'file');
//#RNU_RES_B
// ------------------------
// --- Generate C code. ---
// ------------------------
//#RNU_RES_E
<<<<<<< HEAD
flagendpop = 0;
IfExprField = AST_PopASTStack();
NOp=0;
Op=[];
while (flagendpop == 0)
if (IfExprField~='<EOL>')
if (IfExprField=='WhileExpression:')
flagendpop = 1;
// Pop Again the If tag from the AST.
IfExprField = AST_PopASTStack();
elseif (IfExprField=='Operands:')
flagendpop = 0;
g = AST_PopASTStack();
else
if (IfExprField=='&&' | IfExprField=='||')
NOp = NOp + 1;
Op(NOp) = IfExprField;
//PrintStringInfo('operators are '+Op(NOp),ReportFileName,'file','y');
else
NIfCondArg = NIfCondArg + 1;
IfCondArg(NIfCondArg) = IfExprField;
end
//[IfCondArg(NIfCondArg),tmpscope] = AST_ExtractNameAndScope(IfExprField);
//[IfCondArg(NIfCondArg),tmpscope] = AST_ExtractNameAndScope(IfExprField);
end
end
IfExprField = AST_PopASTStack();
PrintStringInfo('operators are '+IfExprField,ReportFileName,'file','y');
end
IfCondArg = SCI2Cflipud(IfCondArg);
SharedInfo = C_WhileExpression(IfCondArg,NIfCondArg,Op,NOp,FileInfo,SharedInfo);
=======
if(SharedInfo.WhileExpr.CondVar == '')
//#RNU_RES_B
// It means that we are handling something like while(a) or while(1)
// The while condition variable is generated by the HandleEndGenFun.
//#RNU_RES_E
// --- Pop the name of the condition variable or number. ---
Pop1 = AST_PopASTStack();
[ArgName,ArgScope] = AST_ExtractNameAndScope(Pop1);
if (length(ArgName) == 0)
PrintStringInfo(' ',ReportFileName,'both','y');
PrintStringInfo('SCI2CERROR: Expected while(variable) or while(number).','','stdout','y');
PrintStringInfo('SCI2CERROR: Expected a variable or number in the AST while expression.','','stdout','y');
PrintStringInfo('SCI2CERROR: Report this error to http://forge.scilab.org/index.php/p/scilab2c/issues/.','','stdout','y');
PrintStringInfo(' ',ReportFileName,'both','y');
error(9999, 'Expected a conditional variable in the while expression');
end
SharedInfo.WhileExpr.CondVar = ArgName;
//#RNU_RES_B
// --- Repush strings into the AST stack. ---
//#RNU_RES_E
AST_PushASTStack(Pop1);
elseif (SharedInfo.WhileExpr.DimCondVar > 0)
error(9999, 'Cannot manage while with matrix conditions');
end
SharedInfo = C_WhileExpression(FileInfo,SharedInfo);
>>>>>>> 9e5793a7b05b23e6044a6d7a9ddd5db39ba375f0
// --------------------------
// --- Update SharedInfo. ---
// --------------------------
// Signal the exit from a while expression.
SharedInfo.WhileExpr.OnExec = SharedInfo.WhileExpr.OnExec - 1;
SharedInfo.WhileExpr.CondVar = '';
SharedInfo.WhileExpr.DimCondVar = -1;
SharedInfo.WhileExpr.AssignmentFun = 0; //NUT: siamo sicuri che serva?
// -------------------------------
// --- Delete temporary files. ---
// -------------------------------
SCI2Cmdelete(CPass1WhileProlFileName);
endfunction
|