summaryrefslogtreecommitdiff
path: root/2.3-1/macros/CCodeGeneration/C_IfExpression.sci
blob: 23be4522d58319b3b81b0c1f5e5f5631f955bd41 (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
<<<<<<< HEAD
function SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,Op,NOp,ASTIfExpType,FileInfo,SharedInfo)
=======
function SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,ASTIfExpType,FileInfo,SharedInfo)
>>>>>>> 9e5793a7b05b23e6044a6d7a9ddd5db39ba375f0
// function SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,ASTIfExpType,FileInfo,SharedInfo)
// -----------------------------------------------------------------
// //NUT: add description here
//
// Input data:
// //NUT: add description here
//
// Output data:
// //NUT: add description here
//
// Status:
// 27-Oct-2007 -- Raffaele Nutricato: Author.
//
// Copyright 2007 Raffaele Nutricato.
// Contact: raffaele.nutricato@tiscali.it
// -----------------------------------------------------------------

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

//global SCI2CSTACK 
//global StackPosition;
//global STACKDEDUG

// --- Check NIfCondArg value. ---
//if ((NIfCondArg ~= 1) & (ASTIfExpType~='else'))
  // error(9999, 'Cannot manage ""if/elseif"" with a number of condition variables not equal to 1.');
//end
=======
SCI2CNInArgCheck(argn(2),5,5);

// --- Check NIfCondArg value. ---
if ((NIfCondArg ~= 1) & (ASTIfExpType~='else'))
   error(9999, 'Cannot manage ""if/elseif"" with a number of condition variables not equal to 1.');
end
>>>>>>> 9e5793a7b05b23e6044a6d7a9ddd5db39ba375f0

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

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

// #RNU_RES_B
PrintStringInfo(' ',ReportFileName,'file','y');
<<<<<<< HEAD
PrintStringInfo('***Generating C code***'+ string(NIfCondArg),ReportFileName,'file','y');
=======
PrintStringInfo('***Generating C code***',ReportFileName,'file','y');
>>>>>>> 9e5793a7b05b23e6044a6d7a9ddd5db39ba375f0
// #RNU_RES_E
// ---------------------------
// --- End Initialization. ---
// ---------------------------

// --------------------------------------------
// --- Generate the C name of the function. ---
// --------------------------------------------
if (ASTIfExpType=='if')
   CFunName = 'if';
elseif (ASTIfExpType=='elseif')
   CFunName = 'if';
elseif (ASTIfExpType=='else')
   CFunName = 'else';
else
   error(9999, 'Unknown ASTIfExpType ""'+ASTIfExpType+'"".');
end

// ----------------------------
// --- Generate the C call. ---
// ----------------------------
if SCI2Cstrncmps1size(ASTIfExpType,'else')
   // #RNU_RES_B
   // before opening a new C block, closes the previous one.
   // #RNU_RES_E
   SharedInfo = C_IfElseBlocks(FileInfo,SharedInfo,'out');
end

<<<<<<< HEAD
i=1;
k=1;
CCall ='';
CCall = CCall+CFunName;
if (ASTIfExpType~='else')
   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+')';
=======
CCall ='';
CCall = CCall+CFunName;
if (ASTIfExpType~='else')
   CCall = CCall+'('+IfCondArg(1)+')';
>>>>>>> 9e5793a7b05b23e6044a6d7a9ddd5db39ba375f0
end
PrintStringInfo('   '+CCall,ReportFileName,'file','y');
PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CCall,CPass1FileName,'file','y');

SharedInfo = C_IfElseBlocks(FileInfo,SharedInfo,'in');

// #RNU_RES_B
// ---------------------------------
// --- Update counter nested if. ---
// ---------------------------------
// #RNU_RES_E
if (ASTIfExpType=='elseif')
   // #RNU_RES_B
   // every  elseif statement a new } is required.
   // #RNU_RES_E
   SharedInfo.CountNestedIf = SharedInfo.CountNestedIf + 1;
end

endfunction