summaryrefslogtreecommitdiff
path: root/macros/CCodeGeneration/C_WhileExpression.sci
blob: 00c60059c72d5c11e6964797728c9d734490eaec (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
<<<<<<< HEAD
function SharedInfo = C_WhileExpression(IfCondArg,NIfCondArg,Op,NOp,FileInfo,SharedInfo)
=======
function SharedInfo = C_WhileExpression(FileInfo,SharedInfo)
>>>>>>> 9e5793a7b05b23e6044a6d7a9ddd5db39ba375f0
// function SharedInfo = C_WhileExpression(FileInfo,SharedInfo)
// -----------------------------------------------------------------
// //NUT: add description here
//
// Input data:
// //NUT: add description here
//
// Output data:
// //NUT: add description here
//
// Status:
// 15-Nov-2007 -- Raffaele Nutricato: Author.
// 27-June-2017 -- Ukasha Noor: Modified by
//
// Copyright 2007 Raffaele Nutricato.
// Contact: raffaele.nutricato@tiscali.it
// -----------------------------------------------------------------

// ------------------------------
// --- Check input arguments. ---
// ------------------------------
<<<<<<< HEAD
SCI2CNInArgCheck(argn(2),6,6);
=======
SCI2CNInArgCheck(argn(2),2,2);
>>>>>>> 9e5793a7b05b23e6044a6d7a9ddd5db39ba375f0

// -----------------------
// --- Initialization. ---
// -----------------------
nxtscifunname   = SharedInfo.NextSCIFunName;
nxtscifunnumber = SharedInfo.NextSCIFunNumber;

ReportFileName  = FileInfo.Funct(nxtscifunnumber).ReportFileName;
CPass1FileName  = FileInfo.Funct(nxtscifunnumber).CPass1FileName;

CPass1WhileProlFileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level);
CPass1WhileEpilFileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileEpilFileName(SharedInfo.While.Level);
CDeclarationFileName    = FileInfo.Funct(nxtscifunnumber).CDeclarationFileName;

// #RNU_RES_B
PrintStringInfo(' ',ReportFileName,'file','y');
PrintStringInfo('***Generating C code***',ReportFileName,'file','y');
// #RNU_RES_E
CCall ='';
// ---------------------------
// --- End Initialization. ---
// ---------------------------

// ----------------------------
// --- Generate the C call. ---
// ----------------------------

// -------------------------
// --- Manage all cases. ---
// -------------------------
PrintStringInfo('   Handling While Expression with OpColon.',ReportFileName,'file','y'); //NUT: sistema il commento.
   
// -------------------------------------------------------------------------------------
// --- Generate Prologue and Epilogue -> Copy the first N-1 lines of the for.c code. ---
// -------------------------------------------------------------------------------------
[C_Strings,NumCStrings] = File2StringArray(CPass1WhileProlFileName);
C_Strings = stripblanks(C_Strings);
for cntstr = 1:NumCStrings
   // Prologue
   PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+C_Strings(cntstr),CPass1FileName,'file','y','n');
   // Epilogue
   if (length(C_Strings(cntstr)) == 0)
      C_Strings(cntstr) = ' '; // RNU for Bruno: If I don't do that I get a PrintStringInfo error related to mputstr.
<<<<<<< HEAD
      // Function not defined for given argument type(s),
=======
      // Function not defined for given argument type(s),
>>>>>>> 9e5793a7b05b23e6044a6d7a9ddd5db39ba375f0
      // check arguments or define function %0_mputstr for overloading.
   end
   PrintStringInfo(C_Strings(cntstr),CPass1WhileEpilFileName ,'file','y','n');
end
// ----------------------------------------
// --- Insert "}" in the epilogue file. ---
// ----------------------------------------
PrintStringInfo('}',CPass1WhileEpilFileName ,'file','y');
   
// ------------------------------
// --- Insert for expression. ---
// ------------------------------
<<<<<<< HEAD
//CCall = 'while('+SharedInfo.WhileExpr.CondVar+')';
//PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y');

i=1;
k=1;
CCall ='';
CCall = CCall+'while';
   CCall = CCall+'(';
   while i <= NIfCondArg
	CCall = CCall + IfCondArg(i) + ' ';
	//d = modulo(i,3);
	//PrintStringInfo(' '+string(i)+string(d),'file','y');
	if (modulo(i,3)==0 & i<>NIfCondArg)
	    CCall = CCall + Op(k) + ' ';
	    k = k + 1;
	end
        i = i + 1;
   end 
   CCall = CCall+')';

PrintStringInfo('   '+CCall,ReportFileName,'file','y');
=======
CCall = 'while('+SharedInfo.WhileExpr.CondVar+')';
>>>>>>> 9e5793a7b05b23e6044a6d7a9ddd5db39ba375f0
PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y');
   
// -------------------
// --- Insert "{". ---
// -------------------
CCall = '{';
PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y');
   
// ---------------------------------
// --- Update Indentation Level. ---
// ---------------------------------
SharedInfo.NIndent = SharedInfo.NIndent + 1;   

endfunction