summaryrefslogtreecommitdiff
path: root/2.3-1/macros/CCodeGeneration/C_WhileExpression.sci
blob: d7cf70ec2d26833204f50a36bc00fb13edc0d7ea (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
function SharedInfo = C_WhileExpression(IfCondArg,NIfCondArg,Op,NOp,FileInfo,SharedInfo)
// 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.
//
// Copyright 2007 Raffaele Nutricato.
// Contact: raffaele.nutricato@tiscali.it
// -----------------------------------------------------------------

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

// -----------------------
// --- 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.
      // Function not defined for given argument type(s),
      // 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. ---
// ------------------------------
//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');
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