summaryrefslogtreecommitdiff
path: root/macros/ASTManagement
diff options
context:
space:
mode:
Diffstat (limited to 'macros/ASTManagement')
-rw-r--r--macros/ASTManagement/%equal_string.sci2
-rw-r--r--macros/ASTManagement/%funcall_string.sci11
-rw-r--r--macros/ASTManagement/%ifthenelse_string.sci27
-rw-r--r--macros/ASTManagement/%operatio_string.sci14
-rw-r--r--macros/ASTManagement/%operation_string.sci13
-rw-r--r--macros/ASTManagement/AST2Ccode.sci116
-rw-r--r--macros/ASTManagement/AST_ExtractNameAndScope.sci18
-rw-r--r--macros/ASTManagement/AST_GetPrecAndLhsArg.sci4
-rw-r--r--macros/ASTManagement/AST_HandleCC.sci63
-rw-r--r--macros/ASTManagement/AST_HandleEOL.sci8
-rw-r--r--macros/ASTManagement/AST_HandleEndGenFun.sci893
-rw-r--r--macros/ASTManagement/AST_HandleFunCC.sci206
-rw-r--r--macros/ASTManagement/AST_HandleFunRC.sci207
-rw-r--r--macros/ASTManagement/AST_HandleFuncArray.sci62
-rw-r--r--macros/ASTManagement/AST_HandleFuncArray2D.sci69
-rw-r--r--macros/ASTManagement/AST_HandleHeader.sci22
-rw-r--r--macros/ASTManagement/AST_HandleIfElse.sci6
-rw-r--r--macros/ASTManagement/AST_HandleRC.sci58
-rw-r--r--macros/ASTManagement/AST_HandleWhileStatem.sci60
-rw-r--r--macros/ASTManagement/AST_ParseEqualStruct.sci2
-rw-r--r--macros/ASTManagement/AST_ParseFuncallStruct.sci4
-rw-r--r--macros/ASTManagement/AST_ParseIfExprStruct.sci53
-rw-r--r--macros/ASTManagement/AST_ParseOperStruct.sci12
-rw-r--r--macros/ASTManagement/GenOutArgNames.sci110
-rw-r--r--macros/ASTManagement/_comment_string.sci7
-rw-r--r--macros/ASTManagement/_cste_string.sci26
-rw-r--r--macros/ASTManagement/_equal_string.sci16
-rw-r--r--macros/ASTManagement/_for_string.sci15
-rw-r--r--macros/ASTManagement/_funcall_string.sci25
-rw-r--r--macros/ASTManagement/_ifthenel_string.sci27
-rw-r--r--macros/ASTManagement/_ifthenelse_string.sci27
-rw-r--r--macros/ASTManagement/_operatio_string.sci13
-rw-r--r--macros/ASTManagement/_operation_string.sci13
-rw-r--r--macros/ASTManagement/_program_p.sci4
-rw-r--r--macros/ASTManagement/_program_string.sci19
-rw-r--r--macros/ASTManagement/_variable_string.sci26
-rw-r--r--macros/ASTManagement/_while_string.sci14
-rw-r--r--macros/ASTManagement/names65
38 files changed, 1858 insertions, 479 deletions
diff --git a/macros/ASTManagement/%equal_string.sci b/macros/ASTManagement/%equal_string.sci
index 9678f0e0..041fb84a 100644
--- a/macros/ASTManagement/%equal_string.sci
+++ b/macros/ASTManagement/%equal_string.sci
@@ -13,4 +13,4 @@ function txt=%equal_string(e)
' '+objectlist2string(e.lhs)
'EndEqual'
]
-endfunction \ No newline at end of file
+endfunction
diff --git a/macros/ASTManagement/%funcall_string.sci b/macros/ASTManagement/%funcall_string.sci
index faeb81d9..fc4b929b 100644
--- a/macros/ASTManagement/%funcall_string.sci
+++ b/macros/ASTManagement/%funcall_string.sci
@@ -5,11 +5,22 @@ function txt=%funcall_string(F)
// rhs : a list
// name : string, the name of the function
// lhsnb: number, the number of function lhs
+// Modified By: Ukasha Noor
+
+if F.name <> 'disp'
txt=['Funcall : '+F.name
' #lhs : '+string(F.lhsnb)
' Rhs : '
' '+objectlist2string(F.rhs)
'EndFuncall'
]
+else
+txt=['Funcall : '+F.name
+ ' #lhs : '+'0'
+ ' Rhs : '
+ ' '+objectlist2string(F.rhs)
+ 'EndFuncall'
+ ]
+end
endfunction
diff --git a/macros/ASTManagement/%ifthenelse_string.sci b/macros/ASTManagement/%ifthenelse_string.sci
new file mode 100644
index 00000000..ef588c56
--- /dev/null
+++ b/macros/ASTManagement/%ifthenelse_string.sci
@@ -0,0 +1,27 @@
+function txt=%ifthenelse_string(I)
+//overloading function for "ifthenel" type tlist string function
+//this is a node of the AST
+//fields:
+// expression : "expression" type tlist (the if expression)
+// then : list of "equal" type tlist and list('EOL') (the
+// then instructions list)
+// elseifs : a list of tlists
+// else : list of "equal" type tlist and list('EOL') (the
+// else instructions list)
+ txt=['If '
+ ' Expression:'
+ ' '+string(I.expression)
+ ' If Statements'
+ ' '+objectlist2string(I.then)]
+ for e=I.elseifs
+ txt=[txt;
+ ' Else If Expression'
+ ' '+string(e.expression)
+ ' Else If Statements'
+ ' '+objectlist2string(e.then)]
+ end
+ txt=[txt;
+ ' Else Statements'
+ ' '+objectlist2string(I.else)
+ 'EndIf']
+endfunction
diff --git a/macros/ASTManagement/%operatio_string.sci b/macros/ASTManagement/%operatio_string.sci
index 8421a3f4..cc18e919 100644
--- a/macros/ASTManagement/%operatio_string.sci
+++ b/macros/ASTManagement/%operatio_string.sci
@@ -4,10 +4,22 @@ function txt=%operatio_string(O)
//fields:
// operands: a list
// operator: a string
+if O.operator <> 'rc' & O.operator <> 'cc'
txt=['Operation'
' Operands:'
' '+objectlist2string(O.operands)
' Operator: '+O.operator
'EndOperation'
]
-endfunction \ No newline at end of file
+elseif O.operator == 'rc'
+ txt=[' Operands:'
+ ' '+objectlist2string(O.operands)
+ 'Endrc'
+ ]
+elseif O.operator == 'cc'
+ txt=[' Begin:'
+ ' '+objectlist2string(O.operands)
+ 'Endcc'
+ ]
+end
+endfunction
diff --git a/macros/ASTManagement/%operation_string.sci b/macros/ASTManagement/%operation_string.sci
new file mode 100644
index 00000000..c9282f67
--- /dev/null
+++ b/macros/ASTManagement/%operation_string.sci
@@ -0,0 +1,13 @@
+function txt=%operation_string(O)
+//overloading function for "operation" type tlist string function
+//this is a node of the AST
+//fields:
+// operands: a list
+// operator: a string
+ txt=['Operation'
+ ' Operands:'
+ ' '+objectlist2string(O.operands)
+ ' Operator: '+O.operator
+ 'EndOperation'
+ ]
+endfunction
diff --git a/macros/ASTManagement/AST2Ccode.sci b/macros/ASTManagement/AST2Ccode.sci
index 7c95572e..d44a3393 100644
--- a/macros/ASTManagement/AST2Ccode.sci
+++ b/macros/ASTManagement/AST2Ccode.sci
@@ -11,11 +11,11 @@ function AST2Ccode(FileInfoDatFile)
//
// Status:
// 11-May-2007 -- Raffaele Nutricato: Author.
+// 15-June-2017 -- Ukasha Noor: Revised By
//
// Copyright 2007 Raffaele Nutricato.
// Contact: raffaele.nutricato@tiscali.it
// -----------------------------------------------------------------
-
// ------------------------------
// --- Check input arguments. ---
// ------------------------------
@@ -42,10 +42,19 @@ load(FileInfo.SharedInfoDatFile,'SharedInfo');
nxtscifunname = SharedInfo.NextSCIFunName;
nxtscifunnumber = SharedInfo.NextSCIFunNumber;
ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
+SharedInfo.Function_list = [];
+SharedInfo.Function_list_index = 1;
// ---------------------------------
// --- Parameter Initialization. ---
// ---------------------------------
+
+global cc_count
+cc_count = 0;
+
+global rc_count
+rc_count = 0;
+
global SCI2CSTACK
SCI2CSTACK = ['EMPTYSTACK'];
@@ -54,6 +63,11 @@ StackPosition = 1;
global STACKDEDUG
STACKDEDUG = 0; // 1 -> Every Pop and Push operation on the stack, the stack content will be printed on screen.
+
+global disp_isthere
+disp_isthere = 0;
+
+FName = null
// -------------------------------------
// --- End parameter Initialization. ---
// -------------------------------------
@@ -105,7 +119,6 @@ AST_PushASTStack('Dummy');
SharedInfo.UsedTempScalarVars = OrigUsedTempScalarVars;
//NUT: put here a manageeol so that you can have all the save and load you want.
SharedInfo.ASTReader.UsedTempVars = 0;
-
// ----------------------------------
// --- Main loop to read the AST. ---
// ----------------------------------
@@ -121,7 +134,6 @@ while ~meof(fidAST)
if STACKDEDUG == 1
disp('Read AST Line: '+treeline);
end
-
// Analyze line.
select treeline
@@ -131,10 +143,15 @@ while ~meof(fidAST)
//NUT: qui puoi anche aggiunger piu' case per specificare meglio la struttura della funcall
//NUT: i case aggiunti ovviamente faranno solo il push della treeline.
case 'EndOperation' then
- [FileInfo,SharedInfo] = AST_HandleEndGenFun(FileInfo,SharedInfo,'Operation');
+ [disp_isthere,FileInfo,SharedInfo] = AST_HandleEndGenFun(disp_isthere,FileInfo,SharedInfo,'Operation');
case 'EndFuncall' then
- [FileInfo,SharedInfo] = AST_HandleEndGenFun(FileInfo,SharedInfo,'Funcall');
-
+ if rc_count > 0 & cc_count == 0
+ [EqualInArgName,EqualInArgScope,EqualNInArg,FName] = AST_HandleFuncArray(FileInfo,SharedInfo);
+ elseif cc_count > 0
+ [EqualInArgName,EqualInArgScope,EqualNInArg,FName] = AST_HandleFuncArray2D(FileInfo,SharedInfo);
+ else
+ [disp_isthere,FileInfo,SharedInfo] = AST_HandleEndGenFun(disp_isthere,FileInfo,SharedInfo,'Funcall');
+ end
// --------------
// --- Equal. ---
// --------------
@@ -143,21 +160,59 @@ while ~meof(fidAST)
//NUT: per fare in modo di coprire le ins, anche se ci puo' essere qualche rischio quando
//NUT: ho miste ins e variabili, per esempio [c(1,1), a] = twooutfun();
//NUT: in questo caso solo una delle due equal va scartata.
- [FileInfo,SharedInfo] = AST_HandleEndGenFun(FileInfo,SharedInfo,'Equal');
- SharedInfo = INIT_SharedInfoEqual(SharedInfo);
+ if rc_count > 0 & cc_count == 0
+ [FileInfo,SharedInfo] = AST_HandleFunRC(FName,FileInfo,SharedInfo);
+ rc_count = 0;
+ elseif cc_count > 0
+ [FileInfo,SharedInfo] = AST_HandleFunCC(FName,cc_count,FileInfo,SharedInfo);
+ rc_count = 0;
+ cc_count = 0;
+ else
+ if disp_isthere == 0
+ [disp_isthere,FileInfo,SharedInfo] = AST_HandleEndGenFun(disp_isthere,FileInfo,SharedInfo,'Equal');
+ SharedInfo = INIT_SharedInfoEqual(SharedInfo);
+ end
+ end
+ disp_isthere = 0;
+ FName = null
case 'Equal' then
SharedInfo.Equal.Enabled = 1; // 1 means enabled -> we are inside an equal AST block.
AST_PushASTStack(treeline);
case 'Lhs :' then
- SharedInfo.Equal.Lhs = 1; // 1 means that we are inside the Lhs block of the Equal
- [EqualInArgName,EqualInArgScope,EqualNInArg] = AST_ReadEqualRhsNames(FileInfo,SharedInfo);
- SharedInfo.Equal.NInArg = EqualNInArg;
- for tmpcnt = 1:SharedInfo.Equal.NInArg
- SharedInfo.Equal.InArg(tmpcnt).Name = EqualInArgName(tmpcnt);
- SharedInfo.Equal.InArg(tmpcnt).Scope = EqualInArgScope(tmpcnt);
- end
- AST_PushASTStack(treeline);
-
+ if rc_count > 0 & cc_count == 0
+ SharedInfo.Equal.Lhs = 1;
+ [EqualInArgName,EqualInArgScope,EqualNInArg] = AST_HandleRC(FileInfo,SharedInfo);
+ SharedInfo.Equal.NInArg = EqualNInArg - rc_count -1;
+ AST_PushASTStack(treeline);
+ for tmpcnt = 1:SharedInfo.Equal.NInArg
+ SharedInfo.Equal.InArg(tmpcnt).Name = EqualInArgName(tmpcnt);
+ SharedInfo.Equal.InArg(tmpcnt).Scope = EqualInArgScope(tmpcnt);
+ end
+ elseif cc_count > 0
+ SharedInfo.Equal.Lhs = 1;
+ [EqualInArgName,EqualInArgScope,EqualNInArg] = AST_HandleCC(FileInfo,SharedInfo);
+ AST_PushASTStack(treeline);
+ else
+ SharedInfo.Equal.Lhs = 1; // 1 means that we are inside the Lhs block of the Equal
+ //if SharedInfo.Equal.NOutArg > 0
+ if disp_isthere == 0
+ [EqualInArgName,EqualInArgScope,EqualNInArg] = AST_ReadEqualRhsNames(FileInfo,SharedInfo);
+ SharedInfo.Equal.NInArg = EqualNInArg;
+ //end
+
+ // lengthNumber = length('Number_');
+ // if (part(EqualInArgScope,1:lengthNumber) == 'Number_')
+ // SharedInfo.SkipNextEqual = 1
+ // end
+
+ for tmpcnt = 1:SharedInfo.Equal.NInArg
+ SharedInfo.Equal.InArg(tmpcnt).Name = EqualInArgName(tmpcnt);
+ SharedInfo.Equal.InArg(tmpcnt).Scope = EqualInArgScope(tmpcnt);
+ end
+ //end
+ end
+ AST_PushASTStack(treeline);
+ end
// ----------------
// --- If/Else. ---
// ----------------
@@ -176,7 +231,6 @@ while ~meof(fidAST)
SharedInfo = C_IfElseBlocks(FileInfo,SharedInfo,'out');
end
SharedInfo.CountNestedIf = 0;
-
// --------------
// --- Dummy. ---
// --------------
@@ -190,9 +244,9 @@ while ~meof(fidAST)
// -----------------
case 'EndProgram'
SharedInfo = AST_HandleEndProgram(FileInfo,SharedInfo);
+ disp_isthere = 0;
//NUT: per essere precisi si puo' pensare di mettere un check
//NUT: alla fine dell'albero per accertarsi che c'e' end program li' dove ce lo aspettiamo
-
// ------------
// --- For. ---
// ------------
@@ -223,6 +277,15 @@ while ~meof(fidAST)
SharedInfo = AST_HandleEndWhile(FileInfo,SharedInfo);
SharedInfo.While.Level = SharedInfo.While.Level - 1;
+
+ case 'Endrc' then
+ rc_count = rc_count + 1;
+
+ case 'Endcc' then
+ cc_count = cc_count + 1;
+
+ //[FileInfo,SharedInfo] = AST_HandleRC(FileInfo,SharedInfo);
+
// ----------------
// --- Default. ---
// ----------------
@@ -230,6 +293,21 @@ while ~meof(fidAST)
AST_PushASTStack(treeline);
end
end
+// ------------------------------------
+// -----List of functions Used--------
+// -------------------------------------
+
+SharedInfo.Function_list_index = SharedInfo.Function_list_index - 2;
+SharedInfo.Function_list = SharedInfo.Function_list(1:SharedInfo.Function_list_index);
+//To remove function repeatedly used----------
+x = size(unique(SharedInfo.Function_list));
+SharedInfo.Function_list_index = x(1);
+SharedInfo.Function_list = unique(SharedInfo.Function_list);
+
+SharedInfo.Function_list = SharedInfo.Function_list(1:SharedInfo.Function_list_index);
+
+
+
// --------------------------------------
// --- End main loop to read the AST. ---
// --------------------------------------
diff --git a/macros/ASTManagement/AST_ExtractNameAndScope.sci b/macros/ASTManagement/AST_ExtractNameAndScope.sci
index 53830cfc..1dbaaad7 100644
--- a/macros/ASTManagement/AST_ExtractNameAndScope.sci
+++ b/macros/ASTManagement/AST_ExtractNameAndScope.sci
@@ -57,6 +57,7 @@ taglength(cnttag) = length(tagname(cnttag));
fieldlength = length(ASTField);
+
//NUT: il seguente codice e' poco elegante.
if (SCI2Cstrncmps1size(tagname(1),ASTField))
// Here we can have:
@@ -65,24 +66,37 @@ if (SCI2Cstrncmps1size(tagname(1),ASTField))
// Number_d: it means double real type.
// Number_c: it means float complex type.
// Number_z: it means double complex type.
- ArgName = stripblanks(part(ASTField,taglength(1)+3:fieldlength));
- ArgScope = stripblanks(part(ASTField,1:taglength(1)+1));
+
+ // If ArgName is i, make it string
+ if(mtlb_strcmp(ASTField,"Number_x: i") == %T)
+ ArgName = stripblanks(part(ASTField,taglength(1)+3:fieldlength));
+ ArgScope = 'String';
+ else
+ ArgName = stripblanks(part(ASTField,taglength(1)+3:fieldlength));
+ ArgScope = stripblanks(part(ASTField,1:taglength(1)+1));
+ end
+
elseif (SCI2Cstrncmps1size(tagname(2),ASTField))
ArgName = stripblanks(part(ASTField,taglength(2)+1:fieldlength));
ArgName = part(ArgName,2:length(ArgName)-1); // I remove also the first and the last "
ArgScope = 'String';
+
elseif (SCI2Cstrncmps1size(tagname(3),ASTField))
ArgName = stripblanks(part(ASTField,taglength(3)+1:fieldlength));
ArgScope = 'Variable';
+
elseif (SCI2Cstrncmps1size(tagname(4),ASTField))
ArgName = stripblanks(part(ASTField,taglength(4)+1:fieldlength));
ArgScope = 'Global';
+
elseif (SCI2Cstrncmps1size(tagname(5),ASTField))
ArgName = stripblanks(part(ASTField,taglength(5)+1:fieldlength));
ArgScope = 'Local';
+
elseif (SCI2Cstrncmps1size(tagname(6),ASTField))
ArgName = stripblanks(part(ASTField,taglength(6)+1:fieldlength));
ArgScope = 'Temp';
+
elseif (SCI2Cstrncmps1size(tagname(7),ASTField))
ArgName = '<empty>';
ArgScope = 'None';
diff --git a/macros/ASTManagement/AST_GetPrecAndLhsArg.sci b/macros/ASTManagement/AST_GetPrecAndLhsArg.sci
index 07ad3b0a..f45c29e5 100644
--- a/macros/ASTManagement/AST_GetPrecAndLhsArg.sci
+++ b/macros/ASTManagement/AST_GetPrecAndLhsArg.sci
@@ -57,7 +57,8 @@ end
// --- Check Last Function Condition and update LhsArg info. ---
// -------------------------------------------------------------
// #RNU_RES_E
-if (ASTFunType~='Equal')
+if ((ASTFunType~='Equal')& (NOutArg ~= 0))
+ //If NOutArg = 0, bypass.
// #RNU_RES_B
PrintStringInfo(' ',ReportFileName,'file','y');
PrintStringInfo(' Checking presence of Equal after the current function...',ReportFileName,'file','y');
@@ -68,7 +69,6 @@ else
LhsArgScope = '';
NLhsArg = 0;
end
-
// --- Generate the LhsArg structure. ---
LhsArg = [];
for cntarg = 1:NLhsArg
diff --git a/macros/ASTManagement/AST_HandleCC.sci b/macros/ASTManagement/AST_HandleCC.sci
new file mode 100644
index 00000000..897a06f1
--- /dev/null
+++ b/macros/ASTManagement/AST_HandleCC.sci
@@ -0,0 +1,63 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author: Ukasha Noor
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+// This function is used for 2D array declaration
+// This function extracts the input arguments in the array and check there Name and Scope.
+// Then repush everything back to stack
+function [RhsNames,RhsScope,NRhs] = AST_HandleCC(FileInfo,SharedInfo)
+
+SCI2CNInArgCheck(argn(2),2,2)
+
+ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
+
+// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+
+
+global SCI2CSTACK
+global StackPosition;
+global STACKDEDUG
+// ---------------------------
+// --- End Initialization. ---
+// ---------------------------
+
+
+// ------------------------------
+// --- Read input parameters. ---
+// ------------------------------
+cntpop = 1;
+NRhs = 0;
+RhsField(cntpop) = AST_PopASTStack();
+RhsNames = [];
+while (RhsField(cntpop) ~= 'Expression:')
+ if RhsField(cntpop) <> 'Operands:' & RhsField(cntpop) <> 'Begin:'
+ NRhs = NRhs + 1;
+
+ [RhsNames(NRhs),RhsScope(NRhs)] = AST_ExtractNameAndScope(RhsField(cntpop));
+ end
+ cntpop = cntpop + 1;
+ RhsField(cntpop) = AST_PopASTStack();
+end
+RhsNames = SCI2Cflipud(RhsNames);
+RhsScope = SCI2Cflipud(RhsScope);
+
+// --- Repush everything into the stack. ---
+for cntpush = cntpop:-1:1
+ if RhsField(cntpush) <> 'Operands:' & RhsField(cntpush) <> 'Begin:'
+ PrintStringInfo(' ' + RhsField(cntpush),ReportFileName,'file','y');
+ AST_PushASTStack(RhsField(cntpush));
+ end
+end
+
+
+
+
+endfunction
diff --git a/macros/ASTManagement/AST_HandleEOL.sci b/macros/ASTManagement/AST_HandleEOL.sci
index 0f55457e..4b287283 100644
--- a/macros/ASTManagement/AST_HandleEOL.sci
+++ b/macros/ASTManagement/AST_HandleEOL.sci
@@ -46,15 +46,17 @@ sciline = mgetl(SciFileFid,1);
PrintStringInfo(' ',ReportFileName,'file','y','n');
PrintStringInfo('##################'+'################'+'##################'+'##################'+'##################',ReportFileName,'file','y','n');
PrintStringInfo('##################'+'################'+'##################'+'##################'+'##################',ReportFileName,'file','y','n');
-PrintStringInfo('### Scilab code: '+sciline+' ###',ReportFileName,'file','y','n');
+//PrintStringInfo('### Scilab code: '+sciline+' ###',ReportFileName,'file','y','n');
PrintStringInfo('##################'+'################'+'##################'+'##################'+'##################',ReportFileName,'file','y','n');
PrintStringInfo('##################'+'################'+'##################'+'##################'+'##################',ReportFileName,'file','y','n');
// #RNU_RES_E
PrintStringInfo(' ',CPass1FileName,'file','y');
// RNU BRUNO modeprintstringinfo MUST BE AN EXTERNAL PARAMETER!
-modeprintstringinfo = 'both';
+//modeprintstringinfo = 'both';
if (SharedInfo.CopySciCodeIntoCCode == 1)
- modeprintstringinfo = 'both';
+ modeprintstringinfo = 'file';
+else
+ modeprintstringinfo = 'stdout';
end
PrintStringInfo(C_IndentBlanks(IndentLevel)+'/*SCI2C: #############'+'############'+'##############'+'###############'+'############',CPass1FileName,modeprintstringinfo,'y','n');
PrintStringInfo(C_IndentBlanks(IndentLevel)+' SCI2C: '+sciline,CPass1FileName,modeprintstringinfo,'y','n');
diff --git a/macros/ASTManagement/AST_HandleEndGenFun.sci b/macros/ASTManagement/AST_HandleEndGenFun.sci
index 69fbb82e..455cd404 100644
--- a/macros/ASTManagement/AST_HandleEndGenFun.sci
+++ b/macros/ASTManagement/AST_HandleEndGenFun.sci
@@ -1,4 +1,4 @@
-function [FileInfo,SharedInfo] = AST_HandleEndGenFun(FileInfo,SharedInfo,ASTFunType)
+function [disp_isthere,FileInfo,SharedInfo] = AST_HandleEndGenFun(disp_isthere,FileInfo,SharedInfo,ASTFunType)
// function [FileInfo,SharedInfo] = AST_HandleEndGenFun(FileInfo,SharedInfo,ASTFunType)
// -----------------------------------------------------------------
// #RNU_RES_B
@@ -27,25 +27,32 @@ function [FileInfo,SharedInfo] = AST_HandleEndGenFun(FileInfo,SharedInfo,ASTFunT
//
// Status:
// 11-Apr-2007 -- Raffaele Nutricato: Author.
+// 15-June-2017 -- Ukasha Noor : Revised By
//
// Copyright 2007 Raffaele Nutricato.
// Contact: raffaele.nutricato@tiscali.it
// -----------------------------------------------------------------
+
// ------------------------------
// --- Check input arguments. ---
// ------------------------------
-SCI2CNInArgCheck(argn(2),3,3);
+SCI2CNInArgCheck(argn(2),4,4);
// -----------------------
// --- Initialization. ---
// -----------------------
-nxtscifunname = SharedInfo.NextSCIFunName;
-nxtscifunnumber = SharedInfo.NextSCIFunNumber;
-ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
-Pass1HeaderFileName = FileInfo.Funct(nxtscifunnumber).Pass1HeaderFileName;
-FunInfoDatDir = FileInfo.FunctionList.FunInfoDatDir;
-CGblDeclarFileName = FileInfo.Funct(nxtscifunnumber).CGblDeclarFileName;
+nxtscifunname = SharedInfo.NextSCIFunName;
+nxtscifunnumber = SharedInfo.NextSCIFunNumber;
+ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
+Pass1HeaderFileName = FileInfo.Funct(nxtscifunnumber).Pass1HeaderFileName;
+FunInfoDatDir = FileInfo.FunctionList.FunInfoDatDir;
+CGblDeclarFileName = FileInfo.Funct(nxtscifunnumber).CGblDeclarFileName;
+if(SharedInfo.Target == 'AVR')
+ PeripheralInitListFile = FileInfo.PeripheralInitListFile;
+elseif (SharedInfo.Target == 'Arduino')
+ SetupListFile = FileInfo.SetupListFile;
+end
Flag_FunAlreadyCalled = 0;
// #RNU_RES_B
@@ -55,6 +62,8 @@ PrintStepInfo('Handling Funcall/Operation/Equal',FileInfo.Funct(nxtscifunnumber)
global SCI2CSTACK
global StackPosition;
global STACKDEDUG
+
+disp_isthere = 0;
// ---------------------------
// --- End Initialization. ---
// ---------------------------
@@ -66,377 +75,531 @@ global STACKDEDUG
//NUT: verifica se ASTFunType e' veramente importante
// #RNU_RES_E
[ASTFunName,InArg,NInArg,OutArg,NOutArg] = AST_GetFuncallPrm(FileInfo,SharedInfo,ASTFunType);
-if (ASTFunName == 'OpIns')
- SharedInfo.SkipNextEqual = 1;
- SharedInfo.Equal.Nins = SharedInfo.Equal.Nins + 1;
- //NUT: Force ins to have 0 args. Double check it.
- NOutArg = 0;
- // #RNU_RES_B
- //NUT: io aumenterei qui gli argomenti in ingresso della ins cosi qui vengono fatte tutte le modifiche del
- //NUT: caso e la C_FunCall non se ne deve preoccupare, vedi se lo stesso vale per le altre funzioni
- //NUT: speciali presenti nell C_FunCall.
-
- // 1 more input argument containing the values to be inserted in the matrix.
- // #RNU_RES_E
- NInArg = NInArg + 1;
- InArg(NInArg).Name = SharedInfo.Equal.InArg(SharedInfo.Equal.Nins).Name;
- InArg(NInArg).Scope = SharedInfo.Equal.InArg(SharedInfo.Equal.Nins).Scope;
-elseif (ASTFunName == 'global')
- SharedInfo.SkipNextEqual = 1;
- SharedInfo.SkipNextFun = 1;
- if (NInArg ~= 1)
- PrintStringInfo(' ',ReportFileName,'both','y');
- PrintStringInfo('SCI2CERROR: Multiple declaration of global variables is not allowed.',ReportFileName,'both','y');
- PrintStringInfo('SCI2CERROR: See example below:',ReportFileName,'both','y');
- PrintStringInfo('SCI2CERROR: global var1 var2; //NOT ALLOWED',ReportFileName,'both','y');
- PrintStringInfo('SCI2CERROR: global var1; //ALLOWED',ReportFileName,'both','y');
- PrintStringInfo('SCI2CERROR: global var2; //ALLOWED',ReportFileName,'both','y');
- PrintStringInfo(' ',ReportFileName,'both','y');
- error(9999, 'SCI2CERROR: Multiple declaration of global variables is not allowed.');
- end
- if (NOutArg ~= 1)
- PrintStringInfo(' ',ReportFileName,'both','y');
- PrintStringInfo('SCI2CERROR: Unexpected number of output arguments for global function.',ReportFileName,'both','y');
- PrintStringInfo('SCI2CERROR: Please report this error to: http://forge.scilab.org/index.php/p/scilab2c/issues/',ReportFileName,'both','y');
- PrintStringInfo(' ',ReportFileName,'both','y');
- error(9999, 'SCI2CERROR: Unexpected number of output arguments for global function.');
- end
+if (ASTFunType=='Funcall')
+SharedInfo.Function_list(SharedInfo.Function_list_index) = ASTFunName;
+SharedInfo.Function_list_index = SharedInfo.Function_list_index + 1;
end
+NOutArg_mod = NOutArg
+ if ASTFunName == 'OpLogAnd'
+ AST_PushASTStack('&&');
+ return ;
+ end
+ if ASTFunName == 'OpLogOr'
+ AST_PushASTStack('||');
+ return;
+ end
+
+ if ASTFunName == 'disp'
+ disp_isthere = 1;
+ end
-// #RNU_RES_B
-// --------------------------------------
-// --- Read the function annotations. ---
-// --------------------------------------
-// #RNU_RES_E
-if (ASTFunName == 'OpEqual')
- FunTypeAnnot = '';
- FunSizeAnnot = '';
-else
- [FunTypeAnnot,FunSizeAnnot] = FA_GetFunAnn(NInArg,NOutArg,ASTFunName,FileInfo,SharedInfo);
-end
+ if(mtlb_strcmp(part(ASTFunName,1:2),'CV') == %T)
+ SharedInfo.OpenCVUsed = %T;
+ end
-// #RNU_RES_B
-// -------------------------------------------------------------------------------------------
-// --- Search for Equal Lhs and precision specifier to be applied to the current function. ---
-// -------------------------------------------------------------------------------------------
-// #RNU_RES_E
-[LhsArg,NLhsArg,FunPrecSpecifier,SharedInfo] = AST_GetPrecAndLhsArg(OutArg,NOutArg,ASTFunName,FunTypeAnnot,FunSizeAnnot,ASTFunType,FileInfo,SharedInfo);
-//NUT: questa funzione contiene troppi parametri e mi sembra disordinata.
+ if (ASTFunName == 'OpIns')
+ SharedInfo.SkipNextEqual = 1;
+ SharedInfo.Equal.Nins = SharedInfo.Equal.Nins + 1;
+ //NUT: Force ins to have 0 args. Double check it.
+ NOutArg = 0;
+ // #RNU_RES_B
+ //NUT: io aumenterei qui gli argomenti in ingresso della ins cosi qui vengono fatte tutte le modifiche del
+ //NUT: caso e la C_FunCall non se ne deve preoccupare, vedi se lo stesso vale per le altre funzioni
+ //NUT: speciali presenti nell C_FunCall.
-// #RNU_RES_B
-// --------------------------------
-// --- Input Arguments Section. ---
-// --------------------------------
-// --- Get Input Arguments info from their numerical value or from the symbol table. ---
-// #RNU_RES_E
-if (ASTFunName == 'global')
- [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension,TBScope] = ...
- ST_GetSymbolInfo(InArg(1).Name,FileInfo,SharedInfo);
- if (TBFlagfound == 1)
- InArg(1).Type = TBType;
- InArg(1).Size = TBSize;
- InArg(1).Value = TBValue;
- InArg(1).FindLike = TBFindLike;
- InArg(1).Dimension = TBDimension;
- InArg(1).Scope = TBScope;
- IndentLevelGlobal = 0; //NUT: forced always to 1
- FlagExt = 1;
- C_GenDeclarations(InArg(1),CGblDeclarFileName,IndentLevelGlobal,ReportFileName,FlagExt,SharedInfo.ResizeApproach);
- else
- // #RNU_RES_B
- // That means it is the first time we encounter
- // this global variable and in C this means that
- // we don't have to do nothing.
- // #RNU_RES_E
- // SharedInfo.SkipNextFun = SharedInfo.SkipNextFun + 1;
- SharedInfo.SkipNextFun = 1;
-
- InArg(1).Type = 'GBLToBeDefined';
- InArg(1).Size(1) = 'GBLToBeDefined';
- InArg(1).Size(2) = 'GBLToBeDefined';
- InArg(1).Value = %nan;
- InArg(1).FindLike = %nan;
- InArg(1).Dimension = %nan;
- InArg(1).Scope = 'Global';
-
- // #RNU_RES_B
- PrintStringInfo('***Putting global variable in the symbol table***',ReportFileName,'file','y');
- PrintStringInfo(' Symbol ""'+InArg(1).Name+'""',ReportFileName,'file','y');
-
- PrintStringInfo(' Type: '+InArg(1).Type,ReportFileName,'file','y');
- PrintStringInfo(' Size(1): '+string(InArg(1).Size(1)),ReportFileName,'file','y');
- PrintStringInfo(' Size(2): '+string(InArg(1).Size(2)),ReportFileName,'file','y');
- PrintStringInfo(' Value: '+string(InArg(1).Value),ReportFileName,'file','y');
- PrintStringInfo(' FindLike: '+string(InArg(1).FindLike),ReportFileName,'file','y');
- PrintStringInfo(' Dimension: '+string(InArg(1).Dimension),ReportFileName,'file','y');
- PrintStringInfo(' Scope: '+string(InArg(1).Scope),ReportFileName,'file','y');
- PrintStringInfo(' ',ReportFileName,'file','y');
- // #RNU_RES_E
-
- ST_Set(InArg(1).Name,...
- InArg(1).Type,...
- InArg(1).Size,...
- InArg(1).Value,...
- InArg(1).FindLike,...
- InArg(1).Dimension,...
- FileInfo.GlobalVarFileName);
- end
-else
- [InArg,SharedInfo] = ST_GetInArgInfo(InArg,NInArg,FileInfo,SharedInfo);
-end
+ // 1 more input argument containing the values to be inserted in the matrix.
+ // #RNU_RES_E
+ NInArg = NInArg + 1;
+ InArg(NInArg).Name = SharedInfo.Equal.InArg(SharedInfo.Equal.Nins).Name;
+ InArg(NInArg).Scope = SharedInfo.Equal.InArg(SharedInfo.Equal.Nins).Scope;
+ elseif (ASTFunName == 'global')
+ SharedInfo.SkipNextEqual = 1;
+ SharedInfo.SkipNextFun = 1;
+ if (NInArg ~= 1)
+ PrintStringInfo(' ',ReportFileName,'both','y');
+ PrintStringInfo('SCI2CERROR: Multiple declaration of global variables is not allowed.',ReportFileName,'both','y');
+ PrintStringInfo('SCI2CERROR: See example below:',ReportFileName,'both','y');
+ PrintStringInfo('SCI2CERROR: global var1 var2; //NOT ALLOWED',ReportFileName,'both','y');
+ PrintStringInfo('SCI2CERROR: global var1; //ALLOWED',ReportFileName,'both','y');
+ PrintStringInfo('SCI2CERROR: global var2; //ALLOWED',ReportFileName,'both','y');
+ PrintStringInfo(' ',ReportFileName,'both','y');
+ error(9999, 'SCI2CERROR: Multiple declaration of global variables is not allowed.');
+ end
+ if (NOutArg ~= 1)
+ PrintStringInfo(' ',ReportFileName,'both','y');
+ PrintStringInfo('SCI2CERROR: Unexpected number of output arguments for global function.',ReportFileName,'both','y');
+ PrintStringInfo('SCI2CERROR: Please report this error to: http://forge.scilab.org/index.php/p/scilab2c/issues/',ReportFileName,'both','y');
+ PrintStringInfo(' ',ReportFileName,'both','y');
+ error(9999, 'SCI2CERROR: Unexpected number of output arguments for global function.');
+ end
+ //To skip the functions for Raspberry Pi connections
+ elseif(ASTFunName == 'raspi' | ASTFunName == 'raspi_close' | ASTFunName == 'i2cdetect')
+ disp_isthere=1; // Skips the corresponding Lhs argument declaration
+ return // Skips the function call
+ end
-// #RNU_RES_B
-// -------------------------------------------------------------------
-// --- Change info of Input Argument according to resize approach. ---
-// -------------------------------------------------------------------
-//RNU toglimi nella versione da dare ad hartes.
-//RNU per ora gestisco solo la resize all con tutte realloc.
-//RNU global variables are still coded with fixed size.
-// #RNU_RES_E
-if (SharedInfo.ResizeApproach=='REALLOC_ALL_RESIZE_ALL')
- for cntin = 1:NInArg
- if ((InArg(cntin).Dimension > 0))
- // if ((InArg(cntin).Dimension > 0) & (InArg(cntin).Scope ~= 'Global'))
- InArg(cntin).Size(1) = '__'+InArg(cntin).Name+'Size[0]';
- InArg(cntin).Size(2) = '__'+InArg(cntin).Name+'Size[1]';
- end
- //#RNUREM_MERNU vedi se la seguente fa casino l'ho aggiunta in modo che agia=ones(1,3) sia generata come realloc ma non ho verificato.
- tmpscope = InArg(cntin).Scope;
- lengthNumber = length('Number_');
- if (part(tmpscope,1:lengthNumber) == 'Number_')
- //#RNUREM_ME RNU il problema e' che ones(3,1) allora l'output e' 3,1 e come faccio a trasformare 3 e 1 in simboli in modo tale che realloco anziche' allocare
- InArg(cntin).Value = %nan; //RNU non va bene dove per esempio hai problemi di 1:3:4 se al posto dei numeri metti nan ti impalli
- //#RNUREM_ME Credo che dove c'e' uan allocazione secca ones(3,1) non vada lasciata cosi' ma tutto vada ricondotto a realloc
- //#RNUREM_ME quindi devo vedere nella dichiarazione delle variabili come forzare la dichiarazione dei null pointer.
- //#RNUREM_ME successivamente devo vedere come fare a riscrivere la size dell'output.
- else
- end
- end
-end
+ // #RNU_RES_B
+ // --------------------------------------
+ // --- Read the function annotations. ---
+ // --------------------------------------
+ // #RNU_RES_E
+ if ASTFunName == '%k'
+ ASTFunName='modk';
+ end
+
+ if ASTFunName == '%sn'
+ ASTFunName='modsn';
+ end
-// #RNU_RES_B
-// ---------------------------------
-// --- Output Arguments Section. ---
-// ---------------------------------
-// --- Update Out arg structure with info stored in the function annotations. ---
-// #RNU_RES_E
-if (ASTFunName == 'OpEqual')
- for cntin = 1:NInArg
- OutArg(cntin).Type = InArg(cntin).Type;
- OutArg(cntin).Size = InArg(cntin).Size;
- OutArg(cntin).Dimension = InArg(cntin).Dimension;
- OutArg(cntin).Value = InArg(cntin).Value;
- OutArg(cntin).FindLike = InArg(cntin).FindLike;
- //NUT: forse qui occorre aggiungere lo scope che dovrebbe essere local or global.
- //NUT: per ora lo scope viene settato da AST_ParseEqualStruct
- end
-elseif ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0)&(InArg(1).Scope == 'Number'))
- // #RNU_RES_B
- // --- Manage OpMinus when applied to scalars. ---
- // -1 is not translated as tmp = OpMinus(1), but
- // it is considered as a single entity "-1"
- // #RNU_RES_E
- SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI
- OutArg(1).Type = InArg(1).Type;
- OutArg(1).Size = InArg(1).Size;
- OutArg(1).Dimension = InArg(1).Dimension;
- OutArg(1).Value = -InArg(1).Value;
- OutArg(1).FindLike = InArg(1).FindLike;
- OutArg(1).Scope = 'Number_'+InArg(1).Type;
-elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- // #RNU_RES_B
- // --- Manage OpMinus when applied to scalars. ---
- // -1 is not translated as tmp = OpMinus(1), but
- // it is considered as a single entity "-1"
- // #RNU_RES_E
- SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI
- OutArg(1).Type = InArg(1).Type;
- OutArg(1).Size = InArg(1).Size;
- OutArg(1).Dimension = InArg(1).Dimension;
- OutArg(1).Value = InArg(1).Value;
- OutArg(1).FindLike = InArg(1).FindLike;
- OutArg(1).Scope = 'Number_s';
-elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- // #RNU_RES_B
- // --- Manage OpMinus when applied to scalars. ---
- // -1 is not translated as tmp = OpMinus(1), but
- // it is considered as a single entity "-1"
- // #RNU_RES_E
- SharedInfo.SkipNextFun = 1;
- //RN: SISTEMAMI
- SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI
- OutArg(1).Type = InArg(1).Type;
- OutArg(1).Size = InArg(1).Size;
- OutArg(1).Dimension = InArg(1).Dimension;
- OutArg(1).Value = InArg(1).Value;
- OutArg(1).FindLike = InArg(1).FindLike;
- OutArg(1).Scope = 'Number_d';
-else
- OutArg = FA_GetOutArgInfo(InArg,NInArg,OutArg,NOutArg,SharedInfo,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,ReportFileName);
-end
+ if (ASTFunName == 'OpEqual')
+ FunTypeAnnot = '';
+ FunSizeAnnot = '';
+ else
+ [FunTypeAnnot,FunSizeAnnot,NOutArg_mod] = FA_GetFunAnn(NInArg,NOutArg,ASTFunName,FileInfo,SharedInfo);
+ end
+
+ // #RNU_RES_B
+ // -------------------------------------------------------------------------------------------
+ // --- Search for Equal Lhs and precision specifier to be applied to the current function. ---
+ // -------------------------------------------------------------------------------------------
+ // #RNU_RES_E
+ PrintStringInfo(' no of out arguments' + string(NOutArg),ReportFileName,'file','y');
+ [LhsArg,NLhsArg,FunPrecSpecifier,SharedInfo] = AST_GetPrecAndLhsArg(OutArg,NOutArg,ASTFunName,FunTypeAnnot,FunSizeAnnot,ASTFunType,FileInfo,SharedInfo);
+ //NUT: questa funzione contiene troppi parametri e mi sembra disordinata.
-// #RNU_RES_B
-// --- Generate the names for the output arguments. ---
-// Update of OutArg.Name and OutArg.Scope fields.
-// #RNU_RES_E
-if ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- OutArg(1).Name = string(OutArg(1).Value);
-elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- OutArg(1).Name = string(OutArg(1).Value);
-elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- OutArg(1).Name = string(OutArg(1).Value);
-else
- [OutArg,SharedInfo] = GenOutArgNames(ASTFunName,InArg,NInArg,OutArg,NOutArg,LhsArg,NLhsArg,FileInfo,SharedInfo);
-end
+ // #RNU_RES_B
+ // --------------------------------
+ // --- Input Arguments Section. ---
+ // --------------------------------
+ // --- Get Input Arguments info from their numerical value or from the symbol table. ---
+ // #RNU_RES_E
+ if (ASTFunName == 'global')
+ [TBFlagfound,TBType,TBSize,TBValue,TBFindLike,TBDimension,TBScope] = ...
+ ST_GetSymbolInfo(InArg(1).Name,FileInfo,SharedInfo);
+ if (TBFlagfound == 1)
+ InArg(1).Type = TBType;
+ InArg(1).Size = TBSize;
+ InArg(1).Value = TBValue;
+ InArg(1).FindLike = TBFindLike;
+ InArg(1).Dimension = TBDimension;
+ InArg(1).Scope = TBScope;
+ IndentLevelGlobal = 0; //NUT: forced always to 1
+ FlagExt = 1;
+ C_GenDeclarations(InArg(1),CGblDeclarFileName,IndentLevelGlobal,ReportFileName,FlagExt,SharedInfo.ResizeApproach);
+ else
+ // #RNU_RES_B
+ // That means it is the first time we encounter
+ // this global variable and in C this means that
+ // we don't have to do nothing.
+ // #RNU_RES_E
+ // SharedInfo.SkipNextFun = SharedInfo.SkipNextFun + 1;
+ SharedInfo.SkipNextFun = 1;
-// #RNU_RES_B
-// --- Push in the AST stack the Output arguments. ---
-// #RNU_RES_E
-if (ASTFunName == 'OpEqual')
- // Do nothing
-else
- for counteroutargs = 1:NOutArg
- tmppushstack = OutArg(counteroutargs).Scope+': '+OutArg(counteroutargs).Name;
- // #RNU_RES_B
- PrintStringInfo(' Pushing in the AST stack: ""'+tmppushstack+'"".',ReportFileName,'file','y');
- // #RNU_RES_E
- AST_PushASTStack(tmppushstack);
- end
-end
+ InArg(1).Type = 'GBLToBeDefined';
+ InArg(1).Size(1) = 'GBLToBeDefined';
+ InArg(1).Size(2) = 'GBLToBeDefined';
+ InArg(1).Value = %nan;
+ InArg(1).FindLike = %nan;
+ InArg(1).Dimension = %nan;
+ InArg(1).Scope = 'Global';
-// #RNU_RES_B
-//NUT: verificare se si puo' accorpare qualcosa qui sotto
-//RN: non capisco come mai analizzo lo scope dopo che faccio il push nello stack dove lo utilizzo!!!
-// --- Scope analysis of the output arguments. ---
-// #RNU_RES_E
-if (ASTFunName == 'OpMinus' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- // Scope already set above.
-elseif (ASTFunName == 'float' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- // Scope already set above.
-elseif (ASTFunName == 'double' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- // Scope already set above.
-else
- OutArg = ST_AnalyzeScope(OutArg,NOutArg,FileInfo,SharedInfo);
-end
+ // #RNU_RES_B
+ PrintStringInfo('***Putting global variable in the symbol table***',ReportFileName,'file','y');
+ PrintStringInfo(' Symbol ""'+InArg(1).Name+'""',ReportFileName,'file','y');
-//#RNUREM_ME --- Check if the current function is handling for counter variables. ---
-[OutArg,SharedInfo] = ST_InsForCntVars(InArg,NInArg,OutArg,NOutArg,ASTFunName,FileInfo,SharedInfo);
-
-//#RNUREM_ME --- Store the while condition variable (if any). ---
-SharedInfo = GetWhileCondVariable(OutArg,NOutArg,ASTFunName,FileInfo,SharedInfo);
-
-//#RNUREM_ME --- Update Symbol Table with output arguments. ---
-if ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- //#RNUREM_ME A number is not inserted in the symbol table.
-elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- //#RNUREM_ME A number is not inserted in the symbol table.
-elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
- //#RNUREM_ME A number is not inserted in the symbol table.
-else
- ST_InsOutArg(OutArg,NOutArg,FileInfo,SharedInfo,'all');
-end
-//#RNUREM_ME NUT: per risparmiare tempo di esecuzione puoi mettere delle if sulle funzioni che devono
-//#RNUREM_ME NUT: essere skippate.
-
-//#RNU_RES_B
-// --------------------------------------------
-// --- Generate the C name of the function. ---
-// --------------------------------------------
-//#RNU_RES_E
-
-CFunName = C_GenerateFunName(ASTFunName,InArg,NInArg,OutArg,NOutArg);
-//#RNU_RES_B
-PrintStringInfo(' C Function Name: '+CFunName,ReportFileName,'file','y');
-// -------------------------------------------------------------------------
-// --- Determine which library the function belongs to: USER2C or SCI2C. ---
-// -------------------------------------------------------------------------
-//#RNU_RES_E
-if SCI2Cfileexist(FileInfo.SCI2CLibCAnnFun,ASTFunName+'.ann')
- LibTypeInfo = 'SCI2C';
-else
- LibTypeInfo = 'USER2C';
-end
+ PrintStringInfo(' Type: '+InArg(1).Type,ReportFileName,'file','y');
+ PrintStringInfo(' Size(1): '+string(InArg(1).Size(1)),ReportFileName,'file','y');
+ PrintStringInfo(' Size(2): '+string(InArg(1).Size(2)),ReportFileName,'file','y');
+ PrintStringInfo(' Value: '+string(InArg(1).Value),ReportFileName,'file','y');
+ PrintStringInfo(' FindLike: '+string(InArg(1).FindLike),ReportFileName,'file','y');
+ PrintStringInfo(' Dimension: '+string(InArg(1).Dimension),ReportFileName,'file','y');
+ PrintStringInfo(' Scope: '+string(InArg(1).Scope),ReportFileName,'file','y');
+ PrintStringInfo(' ',ReportFileName,'file','y');
+ // #RNU_RES_E
-//#RNU_RES_B
-// ------------------------------------------------------------------------------------
-// --- Check whether the function has been already called in the current .sci file. ---
-// ------------------------------------------------------------------------------------
-//#RNU_RES_E
-if (sum(SharedInfo.CFunctsAlreadyCalled == CFunName) == 1)
- Flag_FunAlreadyCalled = 1;
-else
-
- //#RNUREM_ME Add the C function name to the list of C functions called in the current .sci file.
- SharedInfo.CFunctsAlreadyCalled(size(SharedInfo.CFunctsAlreadyCalled,1)+1) = CFunName;
-end
+ ST_Set(InArg(1).Name,...
+ InArg(1).Type,...
+ InArg(1).Size,...
+ InArg(1).Value,...
+ InArg(1).FindLike,...
+ InArg(1).Dimension,...
+ FileInfo.GlobalVarFileName);
+ end
+ else
+ if(ASTFunName == 'ode')
+ //Differnt handling of ode function is required as one of its input
+ // is a name of a function
+ if NInArg == 4
+ ODEFunName = InArg(4).Name;
+ //To differentiate functions containing differential equations,
+ //'odefn' is added at the beginning of the function name.
+ InArg(4).Name = 'odefn'+ InArg(4).Name
+ SharedInfo.Includelist($+1) = InArg(4).Name;
+ //Add ode function in list. this will be used to add corresponding
+ //header file in main function.
+ elseif NInArg == 5
+ ODEFunName = InArg(5).Name;
+ InArg(5).Name = 'odefn'+ InArg(5).Name
+ SharedInfo.Includelist($+1) = InArg(5).Name;
+ elseif NInArg == 6
+ ODEFunName = InArg(6).Name;
+ InArg(6).Name = 'odefn'+ InArg(6).Name
+ SharedInfo.Includelist($+1) = InArg(6).Name;
+ end
+
+
+ elseif(ASTFunName == 'RPI_ThreadCreate')
+ PI_thread_FunName = InArg(1).Name;
+ InArg(1).Name = 'PI_thread_'+PI_thread_FunName;
+ SharedInfo.Includelist($+1) = InArg(1).Name;
+ elseif(ASTFunName == 'RPI_PinISR')
+ PI_ISR_FunName = InArg(3).Name;
+ InArg(3).Name = 'ISR_'+PI_ISR_FunName;
+ SharedInfo.Includelist($+1) = InArg(3).Name;
+ end
+ [InArg,SharedInfo] = ST_GetInArgInfo(InArg,NInArg,FileInfo,SharedInfo,ASTFunName);
+
+ end
-//#RNU_RES_B
-// ----------------------------------
-// --- Generate FunInfo dat file. ---
-// ----------------------------------
-//NUT: questo .dat deve essere generato sempre perche' cambiano i nomi degli argomenti mentre il resto dovrebbe
-//NUT: essere tutto uguale
-//NUT: magari posso fare una funzione che inserisce solo i campi diversi e fa un check su quelli che
-//NUT: dovrebbero essere identici.
-//#RNU_RES_E
-GenCFunDatFiles(ASTFunName,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,InArg,NInArg,OutArg,NOutArg,CFunName,LibTypeInfo,FunInfoDatDir);
-
-//#RNU_RES_B
-// -----------------------------------
-// --- Update SCI2C Function List. ---
-// -----------------------------------
-// Functions that are not already available in C are stored
-// in the SCI2C Function List and converted in C at the end of
-// the translation of the current .sci file.
-//NUT: il problema della d0d0OpEqual dovrebbe essere legato al fatto che cerco di fare la opequal legata alla ins...
-//NUT: devo evitare di scriveral dentro la lsista delle funzioni da tradurre.
-//#RNU_RES_E
-SharedInfo = FL_UpdateToBeConv(ASTFunName,CFunName,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,InArg,NInArg,OutArg,NOutArg,FileInfo,SharedInfo);
-
-//#RNU_RES_B
-// -----------------------------------------------
-// --- Check on common input/output arguments. ---
-// -----------------------------------------------
-//#RNU_RES_E
-if (((ASTFunName=='OpEqual') & (SharedInfo.SkipNextEqual == 1)) | ...
- SharedInfo.SkipNextFun > 0 | ...
- ((sum(mtlb_strcmp(ASTFunName,SharedInfo.Annotations.DataPrec)) > 0) & (SharedInfo.SkipNextPrec == 1)))
- // Do nothing
-else
- AST_CheckCommonInOutArgs(InArg,NInArg,OutArg,NOutArg,ReportFileName);
-end
+ // #RNU_RES_B
+ // -------------------------------------------------------------------
+ // --- Change info of Input Argument according to resize approach. ---
+ // -------------------------------------------------------------------
+ //RNU toglimi nella versione da dare ad hartes.
+ //RNU per ora gestisco solo la resize all con tutte realloc.
+ //RNU global variables are still coded with fixed size.
+ // #RNU_RES_E
+ if (SharedInfo.ResizeApproach=='REALLOC_ALL_RESIZE_ALL')
+ for cntin = 1:NInArg
+ if ((InArg(cntin).Dimension > 0))
+ // if ((InArg(cntin).Dimension > 0) & (InArg(cntin).Scope ~= 'Global'))
+ InArg(cntin).Size(1) = '__'+InArg(cntin).Name+'Size[0]';
+ InArg(cntin).Size(2) = '__'+InArg(cntin).Name+'Size[1]';s
+ end
+ //#RNUREM_MERNU vedi se la seguente fa casino l'ho aggiunta in modo che agia=ones(1,3) sia generata come realloc ma non ho verificato.
+ tmpscope = InArg(cntin).Scope;
+ lengthNumber = length('Number_');
+ if (part(tmpscope,1:lengthNumber) == 'Number_')
+ //#RNUREM_ME RNU il problema e' che ones(3,1) allora l'output e' 3,1 e come faccio a trasformare 3 e 1 in simboli in modo tale che realloco anziche' allocare
+ InArg(cntin).Value = %nan; //RNU non va bene dove per esempio hai problemi di 1:3:4 se al posto dei numeri metti nan ti impalli
+ //#RNUREM_ME Credo che dove c'e' uan allocazione secca ones(3,1) non vada lasciata cosi' ma tutto vada ricondotto a realloc
+ //#RNUREM_ME quindi devo vedere nella dichiarazione delle variabili come forzare la dichiarazione dei null pointer.
+ //#RNUREM_ME successivamente devo vedere come fare a riscrivere la size dell'output.
+ else
+ end
+ end
+ end
-//#RNU_RES_B
-// -----------------------------
-// --- C Generation Section. ---
-// -----------------------------
-// --- Load FunInfo structure. ---
-//#RNU_RES_E
-FunInfoDatFileName = fullfile(FunInfoDatDir,CFunName+'.dat');
-load(FunInfoDatFileName,'FunInfo');
-
-//#RNU_RES_B
-// --- Generate include. ---
-//#RNU_RES_E
-if ((Flag_FunAlreadyCalled == 0) & (FunInfo.LibTypeInfo == 'USER2C') & (SharedInfo.NextCFunName ~= CFunName))
- // (SharedInfo.NextCFunName ~= CFunName) I don't want an include in the same file. Ex. in main.h I don't want include "main.h"
- // #RNU_RES_B
- PrintStringInfo('Adding include',ReportFileName,'file','y');
- PrintStringInfo('#include ""'+CFunName+'.h""',...
- ReportFileName,'file','y');
- // #RNU_RES_E
- PrintStringInfo('#include ""'+CFunName+'.h""',...
- Pass1HeaderFileName,'file','y');
+ // #RNU_RES_B
+ // ---------------------------------
+ // --- Output Arguments Section. ---
+ // ---------------------------------
+ // --- Update Out arg structure with info stored in the function annotations. ---
+ // #RNU_RES_E
+ if (ASTFunName == 'OpEqual')
+ for cntin = 1:NInArg
+ OutArg(cntin).Type = InArg(cntin).Type;
+ OutArg(cntin).Size = InArg(cntin).Size;
+ OutArg(cntin).Dimension = InArg(cntin).Dimension;
+ OutArg(cntin).Value = InArg(cntin).Value;
+ OutArg(cntin).FindLike = InArg(cntin).FindLike;
+ //NUT: forse qui occorre aggiungere lo scope che dovrebbe essere local or global.
+ //NUT: per ora lo scope viene settato da AST_ParseEqualStruct
+ end
+ elseif ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0)&(InArg(1).Scope == 'Number'))
+ // #RNU_RES_B
+ // --- Manage OpMinus when applied to scalars. ---
+ // -1 is not translated as tmp = OpMinus(1), but
+ // it is considered as a single entity "-1"
+ // #RNU_RES_E
+ SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI
+ OutArg(1).Type = InArg(1).Type;
+ OutArg(1).Size = InArg(1).Size;
+ OutArg(1).Dimension = InArg(1).Dimension;
+ OutArg(1).Value = -InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+ OutArg(1).Scope = 'Number_'+InArg(1).Type;
+ elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ // #RNU_RES_B
+ // --- Manage OpMinus when applied to scalars. ---
+ // -1 is not translated as tmp = OpMinus(1), but
+ // it is considered as a single entity "-1"
+ // #RNU_RES_E
+ SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI
+ OutArg(1).Type = InArg(1).Type;
+ OutArg(1).Size = InArg(1).Size;
+ OutArg(1).Dimension = InArg(1).Dimension;
+ OutArg(1).Value = InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+ OutArg(1).Scope = 'Number_s';
+ elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ // #RNU_RES_B
+ // --- Manage OpMinus when applied to scalars. ---
+ // -1 is not translated as tmp = OpMinus(1), but
+ // it is considered as a single entity "-1"
+ // #RNU_RES_E
+ SharedInfo.SkipNextFun = 1;
+ //RN: SISTEMAMI
+ SharedInfo.SkipNextFun = 1; //RN: SISTEMAMI
+ OutArg(1).Type = InArg(1).Type;
+ OutArg(1).Size = InArg(1).Size;
+ OutArg(1).Dimension = InArg(1).Dimension;
+ OutArg(1).Value = InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+ OutArg(1).Scope = 'Number_d';
+ else
+ OutArg = FA_GetOutArgInfo(InArg,NInArg,OutArg,NOutArg,SharedInfo,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,ReportFileName,ASTFunName);
end
+
+ // #RNU_RES_B
+ // --- Generate the names for the output arguments. ---
+ // Update of OutArg.Name and OutArg.Scope fields.
+ // #RNU_RES_E
+ if ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ OutArg(1).Name = string(OutArg(1).Value);
+ elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ OutArg(1).Name = string(OutArg(1).Value);
+ elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ OutArg(1).Name = string(OutArg(1).Value);
+ //elseif ASTFunName == 'disp'
+ else
+ [OutArg,SharedInfo] = GenOutArgNames(ASTFunName,InArg,NInArg,OutArg,NOutArg,LhsArg,NLhsArg,FileInfo,SharedInfo);
+ if ( ASTFunName == 'OpLogGt' | ASTFunName == 'OpLogLt' | ASTFunName == 'OpLogLe' | ASTFunName == 'OpLogGe' | ASTFunName == 'OpLogNe' | ASTFunName == 'OpLogEq')
+ PrintStringInfo(' returning back due logical function',ReportFileName,'file','y');
+ return;
+ end
+ end
+
+ if ((ASTFunName == 'uint8') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ OutArg(1).Value = InArg(1).Value;
+ SharedInfo.SkipNextFun = 1;
+ elseif ((ASTFunName == 'int8') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ OutArg(1).Value = InArg(1).Value;
+ SharedInfo.SkipNextFun = 1;
+ elseif ((ASTFunName == 'uint16') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ OutArg(1).Value = InArg(1).Value;
+ SharedInfo.SkipNextFun = 1;
+ elseif ((ASTFunName == 'int16') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ OutArg(1).Value = InArg(1).Value;
+ SharedInfo.SkipNextFun = 1;
+ end
+
+ // #RNU_RES_B
+ // --- Push in the AST stack the Output arguments. ---
+ // #RNU_RES_E
+ if (ASTFunName == 'OpEqual')
+ // Do nothing
+ else
+ for counteroutargs = 1:NOutArg
+ tmppushstack = OutArg(counteroutargs).Scope+': '+OutArg(counteroutargs).Name;
+ // #RNU_RES_B
+ PrintStringInfo(' Pushing in the AST stack: ""'+tmppushstack+'"".',ReportFileName,'file','y');
+ // #RNU_RES_E
+ AST_PushASTStack(tmppushstack);
+ end
+ end
+
+
+ // #RNU_RES_B
+ //NUT: verificare se si puo' accorpare qualcosa qui sotto
+ //RN: non capisco come mai analizzo lo scope dopo che faccio il push nello stack dove lo utilizzo!!!
+ // --- Scope analysis of the output arguments. ---
+ // #RNU_RES_E
+ if (ASTFunName == 'OpMinus' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ // Scope already set above.
+ elseif (ASTFunName == 'float' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ // Scope already set above.
+ elseif (ASTFunName == 'double' & NInArg == 1 & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ // Scope already set above.
+ //elseif ASTFunName == 'disp'
+ //do nothing
+ else
+ OutArg = ST_AnalyzeScope(OutArg,NOutArg,FileInfo,SharedInfo);
+ end
+
+ //#RNUREM_ME --- Check if the current function is handling for counter variables. ---
+ [OutArg,SharedInfo] = ST_InsForCntVars(InArg,NInArg,OutArg,NOutArg,ASTFunName,FileInfo,SharedInfo);
+
+ //#RNUREM_ME --- Store the while condition variable (if any). ---
+ SharedInfo = GetWhileCondVariable(OutArg,NOutArg,ASTFunName,FileInfo,SharedInfo);
+
+
+ //#RNUREM_ME --- Update Symbol Table with output arguments. ---
+ if ((ASTFunName == 'OpMinus') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ //#RNUREM_ME A number is not inserted in the symbol table.
+ elseif ((ASTFunName == 'float') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ //#RNUREM_ME A number is not inserted in the symbol table.
+ elseif ((ASTFunName == 'double') & (NInArg == 1) & (InArg(1).Dimension == 0) & (InArg(1).Scope == 'Number'))
+ //#RNUREM_ME A number is not inserted in the symbol table.
+ //elseif ASTFunName == 'disp'
+ //do nothing
+ else
+ ST_InsOutArg(OutArg,NOutArg,FileInfo,SharedInfo,'all');
+ end
+ if ASTFunName == 'ode' then
+ if ((NInArg == 4) | (NInArg == 6))
+ ODE_InArg(1) = InArg(3)
+ ODE_InArg(2) = InArg(1)
+ ODE_OutArg(1) = OutArg(1)
+ elseif NInArg == 5 then
+ ODE_InArg(1) = InArg(4)
+ ODE_InArg(2) = InArg(2)
+ ODE_OutArg(1) = OutArg(1)
+ end
+ ODE_CFunName = C_GenerateFunName('odefn'+ODEFunName,ODE_InArg,2,ODE_OutArg,1);
+ //Functions containing differential equations that are used with 'ode'
+ //function need to be handled differently.
+
+ [FunFound, FunType, FunSize, FunValue, FunFindLike, FunDimension] = ...
+ ST_Get(InArg(4).Name,FileInfo.GlobalVarFileName);
+ //ST_Del(InArg(4).Name,FileInfo.GlobalVarFileName);
+ //ST_Set(ODE_CFunName, FunType, FunSize, FunValue, FunFindLike, FunDimension);
+ end
+
+ //#RNUREM_ME NUT: per risparmiare tempo di esecuzione puoi mettere delle if sulle funzioni che devono
+ //#RNUREM_ME NUT: essere skippate.
+
+ //#RNU_RES_B
+ // --------------------------------------------
+ // --- Generate the C name of the function. ---
+ // --------------------------------------------
+ //#RNU_RES_E
+ //disp(OutArg,InArg,ASTFunName)
+
+
+ CFunName = C_GenerateFunName(ASTFunName,InArg,NInArg,OutArg,NOutArg_mod);
+
+ //#RNU_RES_B
+ PrintStringInfo(' C Function Name: '+CFunName,ReportFileName,'file','y');
+ if(IsArduinoFunction(ASTFunName))
+ if(IsArduinoSetupFunction(ASTFunName))
+ //If current function is an arduino setup function (like 'dc_motor_setup'), it
+ //should not be converted and inserted here. It is inserted in a list now and
+ //added to 'setup_arduino.c' later
+ InsertSetupInList(CFunName,InArg,NInArg,SetupListFile,'Setup');
+ SharedInfo.SkipNextFun = SharedInfo.SkipNextFun + 1;
+ else //Currnet arduino function is not a setup function, so init function must be added
+ InsertSetupInList(ASTFunName,InArg,NInArg,SetupListFile,'Init');
+ end
+ end
+
+ // -------------------------------------------------------------------------
+ // --- Determine which library the function belongs to: USER2C or SCI2C. ---
+ // -------------------------------------------------------------------------
+ //#RNU_RES_E
+ if SCI2Cfileexist(FileInfo.SCI2CLibCAnnFun,ASTFunName+'.ann')
+ LibTypeInfo = 'SCI2C';
+ else
+ LibTypeInfo = 'USER2C';
+ end
+
+
+ //#RNU_RES_B
+ // ------------------------------------------------------------------------------------
+ // --- Check whether the function has been already called in the current .sci file. ---
+ // ------------------------------------------------------------------------------------
+ //#RNU_RES_E
+ if (sum(SharedInfo.CFunctsAlreadyCalled == CFunName) == 1)
+ Flag_FunAlreadyCalled = 1;
+ else
+
+ //#RNUREM_ME Add the C function name to the list of C functions called in the current .sci file.
+ SharedInfo.CFunctsAlreadyCalled(size(SharedInfo.CFunctsAlreadyCalled,1)+1) = CFunName;
+ end
+
+ //#RNU_RES_B
+ // ----------------------------------
+ // --- Generate FunInfo dat file. ---
+ // ----------------------------------
+ //NUT: questo .dat deve essere generato sempre perche' cambiano i nomi degli argomenti mentre il resto dovrebbe
+ //NUT: essere tutto uguale
+ //NUT: magari posso fare una funzione che inserisce solo i campi diversi e fa un check su quelli che
+ //NUT: dovrebbero essere identici.
+ //#RNU_RES_E
+ GenCFunDatFiles(ASTFunName,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,InArg,NInArg,OutArg,NOutArg_mod,CFunName,LibTypeInfo,FunInfoDatDir);
+
+ //#RNU_RES_B
+ // -----------------------------------
+ // --- Update SCI2C Function List. ---
+ // -----------------------------------
+ // Functions that are not already available in C are stored
+ // in the SCI2C Function List and converted in C at the end of
+ // the translation of the current .sci file.
+ //NUT: il problema della d0d0OpEqual dovrebbe essere legato al fatto che cerco di fare la opequal legata alla ins...
+ //NUT: devo evitare di scriveral dentro la lsista delle funzioni da tradurre.
+ //#RNU_RES_E
+
+ SharedInfo = FL_UpdateToBeConv(ASTFunName,CFunName,FunPrecSpecifier,FunTypeAnnot,FunSizeAnnot,InArg,NInArg,OutArg,NOutArg,FileInfo,SharedInfo);
+
+ //#RNU_RES_B
+ // -----------------------------------------------
+ // --- Check on common input/output arguments. ---
+ // -----------------------------------------------
+ //#RNU_RES_E
+ if (((ASTFunName=='OpEqual') & (SharedInfo.SkipNextEqual == 1)) | ...
+ SharedInfo.SkipNextFun > 0 | ...
+ ((sum(mtlb_strcmp(ASTFunName,SharedInfo.Annotations.DataPrec)) > 0) & (SharedInfo.SkipNextPrec == 1)))
+ // Do nothing
+ //elseif ASTFunName == 'disp'
+ // Do nothing
+ else
+ AST_CheckCommonInOutArgs(InArg,NInArg,OutArg,NOutArg,ReportFileName);
+ end
+
+ //#RNU_RES_B
+ // -----------------------------
+ // --- C Generation Section. ---
+ // -----------------------------
+ // --- Load FunInfo structure. ---
+ //#RNU_RES_E
+ FunInfoDatFileName = fullfile(FunInfoDatDir,CFunName+'.dat');
+ load(FunInfoDatFileName,'FunInfo');
+
+ //#RNU_RES_B
+ // --- Generate include. ---
+ //#RNU_RES_E
+ if ((Flag_FunAlreadyCalled == 0) & (FunInfo.LibTypeInfo == 'USER2C') & (SharedInfo.NextCFunName ~= CFunName))
+ // (SharedInfo.NextCFunName ~= CFunName) I don't want an include in the same file. Ex. in main.h I don't want include "main.h"
+ // #RNU_RES_B
+ PrintStringInfo('Adding include',ReportFileName,'file','y');
+ PrintStringInfo('#include ""'+CFunName+'.h""',...
+ ReportFileName,'file','y');
+ // #RNU_RES_E
+ PrintStringInfo('#include ""'+CFunName+'.h""',...
+ Pass1HeaderFileName,'file','y');
+ end
-//#RNU_RES_B
-// --- Generate the C code for the current function. ---
-//#RNU_RES_E
-FlagCall = 1;
-SharedInfo = C_Funcall(FunInfo,FileInfo,SharedInfo,FlagCall);
-//#RNU_RES_B
-//NUT: anziche farla fare alla cfuncall l'aggiornamento delle skip metti qui una funzione dedicata a cio'
-//NUT: e' piu' ordinato.
-//#RNU_RES_E
+ //#RNU_RES_B
+ // --- Generate the C code for the current function. ---
+ //#RNU_RES_E
+ FlagCall = 1;
+ SharedInfo = C_Funcall(FunInfo,FileInfo,SharedInfo,FlagCall);
+ //#RNU_RES_B
+ //NUT: anziche farla fare alla cfuncall l'aggiornamento delle skip metti qui una funzione dedicata a cio'
+ //NUT: e' piu' ordinato.
+ //#RNU_RES_E
+ //If current function being converted is 'ode', insert function containing
+ //in list of functions to be converted
+ if ASTFunName == 'ode' then
+ //ODE_InArg(1) = InArg(3)
+ //ODE_InArg(2) = InArg(1)
+ //ODE_OutArg(1) = OutArg(1)
+ //ODE_CFunName = C_GenerateFunName(ODEFunName,ODE_InArg,2,ODE_OutArg,1);
+ GenCFunDatFiles(ODEFunName,%t,FunTypeAnnot,['IN(2).SZ(1)' 'IN(2).SZ(2)'],ODE_InArg,2,ODE_OutArg,1,ODE_CFunName,LibTypeInfo,FunInfoDatDir);
+ SharedInfo = FL_UpdateToBeConv(ODEFunName,ODE_CFunName,%t,FunTypeAnnot,FunSizeAnnot,ODE_InArg,2,ODE_OutArg,1,FileInfo,SharedInfo);
+ elseif ASTFunName == 'RPI_ThreadCreate' then
+ temp_InArg = InArg;
+ temp_InArg(1).Name = ""
+ PI_thread_CFunName = C_GenerateFunName(InArg(1).Name,temp_InArg,0,%t,0);
+ GenCFunDatFiles(PI_thread_FunName,%t,[],%t,temp_InArg,0,%t,0,PI_thread_CFunName,LibTypeInfo,FunInfoDatDir);
+ SharedInfo = FL_UpdateToBeConv(PI_thread_FunName,PI_thread_CFunName,%t,FunTypeAnnot,[],%t,0,%t,0,FileInfo,SharedInfo);
+ elseif ASTFunName == 'RPI_PinISR' then
+ temp_InArg = InArg;
+ temp_InArg(1).Name = ""
+ PI_ISR_CFunName = C_GenerateFunName(InArg(3).Name,temp_InArg,0,%t,0);
+ GenCFunDatFiles(PI_ISR_FunName,%t,[],%t,temp_InArg,0,%t,0,PI_ISR_CFunName,LibTypeInfo,FunInfoDatDir);
+ SharedInfo = FL_UpdateToBeConv(PI_ISR_FunName,PI_ISR_CFunName,%t,FunTypeAnnot,[],%t,0,%t,0,FileInfo,SharedInfo);
+ end
+
endfunction
diff --git a/macros/ASTManagement/AST_HandleFunCC.sci b/macros/ASTManagement/AST_HandleFunCC.sci
new file mode 100644
index 00000000..395a01df
--- /dev/null
+++ b/macros/ASTManagement/AST_HandleFunCC.sci
@@ -0,0 +1,206 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author: Ukasha Noor
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+// This function put the input elements of array in InArg and
+// output in OutArg from the stack.
+// Then finds the number of columns and rows in matrix and the type of matrix.
+// The call the function to generate the C code for declaration.
+
+function [FileInfo,SharedInfo] = AST_HandleFunCC(FName,NCol,FileInfo,SharedInfo)
+
+SCI2CNInArgCheck(argn(2),4,4)
+
+// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+
+// -----------------------
+// --- Initialization. ---
+// -----------------------
+nxtscifunname = SharedInfo.NextSCIFunName;
+nxtscifunnumber = SharedInfo.NextSCIFunNumber;
+ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
+
+global SCI2CSTACK
+global StackPosition;
+global STACKDEDUG
+// ---------------------------
+// --- End Initialization. ---
+// ---------------------------
+
+// ------------------------------
+// --- Read output parameters. --
+// ------------------------------
+LhsField = AST_PopASTStack();
+NOutArg = 0;
+OutputArgumentNames = [];
+OutputArgumentScope = [];
+while (LhsField ~= 'Lhs :')
+ NOutArg = NOutArg + 1;
+ [OutputArgumentNames(NOutArg),OutputArgumentScope(NOutArg)] = AST_ExtractNameAndScope(LhsField);
+ LhsField = AST_PopASTStack();
+ if (LhsField == 'Expression:')
+ error(9999, 'Found Expression: before Lhs');
+ elseif (LhsField == 'Equal')
+ error(9999, 'Found Equal before Lhs');
+ end
+end
+
+// ------------------------------
+// --- Read input parameters. ---
+// ------------------------------
+
+
+RhsField = AST_PopASTStack();
+InputArgumentNames = [];
+InputArgumentScope = [];
+NInArg = 0;
+InArg = [];
+while (RhsField ~= 'Expression:')
+ NInArg = NInArg + 1;
+ if RhsField <> 'Operands:'
+ [InputArgumentNames(NInArg),InputArgumentScope(NInArg)] = AST_ExtractNameAndScope(RhsField);
+ end
+ //InArg(NInArg) = RhsField;
+ RhsField = AST_PopASTStack();
+end
+InputArgumentNames = SCI2Cflipud(InputArgumentNames);
+InputArgumentScope = SCI2Cflipud(InputArgumentScope);
+
+
+// -------------------------------------
+// --- Generate the InArg structure. ---
+// -------------------------------------
+//#RNU_RES_E
+for counterinputargs = 1:NInArg
+ InArg(counterinputargs).Name=InputArgumentNames(counterinputargs);
+ InArg(counterinputargs).Scope=InputArgumentScope(counterinputargs);
+end
+
+//#RNU_RES_B
+// -------------------------------------
+// --- Generate the InArg structure. ---
+// -------------------------------------
+//#RNU_RES_E
+OutArg = [];
+for counteroutputargs = 1:NOutArg
+ OutArg(counteroutputargs).Name=OutputArgumentNames(counteroutputargs);
+ OutArg(counteroutputargs).Scope=OutputArgumentScope(counteroutputargs);
+end
+
+// ------------------------
+// --- Print Some Info. ---
+// ------------------------
+
+PrintStringInfo('N Input Arguments: '+string(NInArg),ReportFileName,'file','y','n');
+PrintStringInfo('N Output Arguments: '+string(NOutArg),ReportFileName,'file','y');
+
+ //#RNU_RES_E
+ for counterinputargs = 1:NInArg
+ //#RNU_RES_B
+ PrintStringInfo('Input Argument Number '+string(counterinputargs)+': '+InArg(counterinputargs).Name,...
+ ReportFileName,'file','y','n');
+ PrintStringInfo(' Scope: '+InArg(counterinputargs).Scope,...
+ ReportFileName,'file','y','n');
+ //#RNU_RES_E
+ end
+ for counteroutputargs = 1:NOutArg
+ //#RNU_RES_B
+ PrintStringInfo('Output Argument Number '+string(counteroutputargs)+': '+OutArg(counteroutputargs).Name,...
+ ReportFileName,'file','y','n');
+ //PrintStringInfo(' Scope: '+ OutArg(counterinputargs).Scope,ReportFileName,'file','y','n');
+ //#RNU_RES_E
+ end
+
+NOutArg_mod = NOutArg;
+
+FunTypeAnnot = '';
+FunSizeAnnot = '';
+NLhsArg = 0;
+LhsArg = [];
+PrintStringInfo('...Equal not found.',ReportFileName,'file','y');
+
+PrintStringInfo('***Analyzing Input Arguments***',ReportFileName,'file','y');
+UpdatedInArg = InArg;
+[InArg,SharedInfo] = ST_GetInArgInfo(InArg,NInArg,FileInfo,SharedInfo,'OpEqual');
+
+NCol = NCol + 1;
+NRow = NInArg/NCol;
+
+com_type = 0;
+for i = 1:NInArg
+ if InArg(i).Type == 'z'
+ com_type = 1;
+ elseif InArg(i).Type == 'c'
+ com_type = 2;
+ end
+end
+
+
+if FName <> null
+ PrintStringInfo(' Generating Out Arg names.',ReportFileName,'file','y');
+ if FName == 'float'
+ OutArg(1).Type = 's';
+ elseif FName == 'uint8'
+ OutArg(1).Type = 'u8';
+ elseif FName == 'int16'
+ OutArg(1).Type = 'i16';
+ elseif FName == 'uint16'
+ OutArg(1).Type = 'u16';
+ elseif FName == 'int8'
+ OutArg(1).Type = 'i8';
+ elseif FName == 'uint32'
+ OutArg(1).Type = 'u32';
+ elseif FName == 'int32'
+ OutArg(1).Type = 'i32';
+ else
+ OutArg(1).Type = 'd';
+ end
+ OutArg(1).Size(1) = string(NCol);
+ OutArg(1).Size(2) = string(NRow);
+ OutArg(1).Dimension = 2;
+ OutArg(1).Value = InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+else
+ if com_type == 0
+ PrintStringInfo(' Generating Out Arg names.',ReportFileName,'file','y');
+ OutArg(1).Type = InArg(1).Type;
+ OutArg(1).Size(1) = string(NCol);
+ OutArg(1).Size(2) = string(NRow);
+ OutArg(1).Dimension = 2;
+ OutArg(1).Value = InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+ elseif com_type == 1
+ PrintStringInfo(' Generating Out Arg names.',ReportFileName,'file','y');
+ OutArg(1).Type = 'z';
+ OutArg(1).Size(1) = string(NCol);
+ OutArg(1).Size(2) = string(NRow);
+ OutArg(1).Dimension = 2;
+ OutArg(1).Value = InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+ else
+ PrintStringInfo(' Generating Out Arg names.',ReportFileName,'file','y');
+ OutArg(1).Type = 'c';
+ OutArg(1).Size(1) = string(NCol);
+ OutArg(1).Size(2) = string(NRow);
+ OutArg(1).Dimension = 2;
+ OutArg(1).Value = InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+ end
+end
+
+//--- Check for output Argument in symbol table ---//
+OutArg = ST_AnalyzeScope(OutArg,NOutArg,FileInfo,SharedInfo);
+
+//--- Put the output Argument in symbol table ---//
+ST_InsOutArg_Dup(InArg,NInArg,OutArg,NOutArg,com_type,FileInfo,SharedInfo,'all');
+
+
+endfunction
diff --git a/macros/ASTManagement/AST_HandleFunRC.sci b/macros/ASTManagement/AST_HandleFunRC.sci
new file mode 100644
index 00000000..a5885d57
--- /dev/null
+++ b/macros/ASTManagement/AST_HandleFunRC.sci
@@ -0,0 +1,207 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author: Ukasha Noor
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+// This function is used for 1D array declaration.
+// Checks the input and output argumnets and put them in respective variables.
+// Then calls the function to generate the C code for 1D array declaration.
+
+function [FileInfo,SharedInfo] = AST_HandleFunRC(FName,FileInfo,SharedInfo)
+
+SCI2CNInArgCheck(argn(2),3,3)
+
+// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+
+// -----------------------
+// --- Initialization. ---
+// -----------------------
+nxtscifunname = SharedInfo.NextSCIFunName;
+nxtscifunnumber = SharedInfo.NextSCIFunNumber;
+ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
+
+global SCI2CSTACK
+global StackPosition;
+global STACKDEDUG
+// ---------------------------
+// --- End Initialization. ---
+// ---------------------------
+
+// ------------------------------
+// --- Read output parameters. --
+// ------------------------------
+LhsField = AST_PopASTStack();
+NOutArg = 0;
+OutputArgumentNames = [];
+OutputArgumentScope = [];
+while (LhsField ~= 'Lhs :')
+ NOutArg = NOutArg + 1;
+ [OutputArgumentNames(NOutArg),OutputArgumentScope(NOutArg)] = AST_ExtractNameAndScope(LhsField);
+ LhsField = AST_PopASTStack();
+ if (LhsField == 'Expression:')
+ error(9999, 'Found Expression: before Lhs');
+ elseif (LhsField == 'Equal')
+ error(9999, 'Found Equal before Lhs');
+ end
+end
+
+// ------------------------------
+// --- Read input parameters. ---
+// ------------------------------
+
+
+RhsField = AST_PopASTStack();
+InputArgumentNames = [];
+InputArgumentScope = [];
+NInArg = 0;
+InArg = [];
+while (RhsField ~= 'Expression:')
+ NInArg = NInArg + 1;
+ if RhsField <> 'Operands:'
+ [InputArgumentNames(NInArg),InputArgumentScope(NInArg)] = AST_ExtractNameAndScope(RhsField);
+ end
+ //InArg(NInArg) = RhsField;
+ RhsField = AST_PopASTStack();
+end
+InputArgumentNames = SCI2Cflipud(InputArgumentNames);
+InputArgumentScope = SCI2Cflipud(InputArgumentScope);
+
+
+// -------------------------------------
+// --- Generate the InArg structure. ---
+// -------------------------------------
+//#RNU_RES_E
+for counterinputargs = 1:NInArg
+ InArg(counterinputargs).Name=InputArgumentNames(counterinputargs);
+ InArg(counterinputargs).Scope=InputArgumentScope(counterinputargs);
+end
+
+//#RNU_RES_B
+// -------------------------------------
+// --- Generate the InArg structure. ---
+// -------------------------------------
+//#RNU_RES_E
+OutArg = [];
+for counteroutputargs = 1:NOutArg
+ OutArg(counteroutputargs).Name=OutputArgumentNames(counteroutputargs);
+ OutArg(counteroutputargs).Scope=OutputArgumentScope(counteroutputargs);
+end
+
+
+// ------------------------
+// --- Print Some Info. ---
+// ------------------------
+
+PrintStringInfo('N Input Arguments: '+string(NInArg),ReportFileName,'file','y','n');
+PrintStringInfo('N Output Arguments: '+string(NOutArg),ReportFileName,'file','y');
+ //#RNU_RES_E
+ for counterinputargs = 1:NInArg
+ //#RNU_RES_B
+ PrintStringInfo('Input Argument Number '+string(counterinputargs)+': '+InArg(counterinputargs).Name,...
+ ReportFileName,'file','y','n');
+ PrintStringInfo(' Scope: '+InArg(counterinputargs).Scope,...
+ ReportFileName,'file','y','n');
+ //#RNU_RES_E
+ end
+ for counteroutputargs = 1:NOutArg
+ //#RNU_RES_B
+ PrintStringInfo('Output Argument Number '+string(counteroutputargs)+': '+OutArg(counteroutputargs).Name,...
+ ReportFileName,'file','y','n');
+ //PrintStringInfo(' Scope: '+ OutArg(counterinputargs).Scope,ReportFileName,'file','y','n');
+ //#RNU_RES_E
+ end
+
+NOutArg_mod = NOutArg;
+
+FunTypeAnnot = '';
+FunSizeAnnot = '';
+NLhsArg = 0;
+LhsArg = [];
+PrintStringInfo('...Equal not found.',ReportFileName,'file','y');
+
+PrintStringInfo('***Analyzing Input Arguments***',ReportFileName,'file','y');
+UpdatedInArg = InArg;
+[InArg,SharedInfo] = ST_GetInArgInfo(InArg,NInArg,FileInfo,SharedInfo,'OpEqual');
+
+size_count = 0;
+for i = 1:NInArg
+ size_count = size_count + eval(InArg(i).Size(2));
+end
+
+com_type = 0;
+for i = 1:NInArg
+ if InArg(i).Type == 'z'
+ com_type = 1;
+ elseif InArg(i).Type == 'c'
+ com_type = 2;
+ end
+end
+
+
+if FName <> null
+ PrintStringInfo(' Generating Out Arg names.',ReportFileName,'file','y');
+ if FName == 'float'
+ OutArg(1).Type = 's';
+ elseif FName == 'uint8'
+ OutArg(1).Type = 'u8';
+ elseif FName == 'int16'
+ OutArg(1).Type = 'i16';
+ elseif FName == 'uint16'
+ OutArg(1).Type = 'u16';
+ elseif FName == 'int8'
+ OutArg(1).Type = 'i8';
+ elseif FName == 'uint32'
+ OutArg(1).Type = 'u32';
+ elseif FName == 'int32'
+ OutArg(1).Type = 'i32';
+ else
+ OutArg(1).Type = 'd';
+ end
+ OutArg(1).Size(1) = '1'
+ OutArg(1).Size(2) = string(size_count);
+ OutArg(1).Dimension = 2;
+ OutArg(1).Value = InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+else
+ if com_type == 0
+ PrintStringInfo(' Generating Out Arg names.',ReportFileName,'file','y');
+ OutArg(1).Type = InArg(1).Type;
+ OutArg(1).Size(1) = '1'
+ OutArg(1).Size(2) = string(size_count);
+ OutArg(1).Dimension = 2;
+ OutArg(1).Value = InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+ elseif com_type == 1
+ PrintStringInfo(' Generating Out Arg names.',ReportFileName,'file','y');
+ OutArg(1).Type = 'z';
+ OutArg(1).Size(1) = '1'
+ OutArg(1).Size(2) = string(size_count);
+ OutArg(1).Dimension = 2;
+ OutArg(1).Value = InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+ else
+ PrintStringInfo(' Generating Out Arg names.',ReportFileName,'file','y');
+ OutArg(1).Type = 'c';
+ OutArg(1).Size(1) = '1'
+ OutArg(1).Size(2) = string(size_count);
+ OutArg(1).Dimension = 2;
+ OutArg(1).Value = InArg(1).Value;
+ OutArg(1).FindLike = InArg(1).FindLike;
+ end
+end
+
+//--- Check for output Argument in symbol table ---//
+OutArg = ST_AnalyzeScope(OutArg,NOutArg,FileInfo,SharedInfo);
+
+//--- Put the output Argument in symbol table ---//
+ST_InsOutArg_Dup(InArg,NInArg,OutArg,NOutArg,com_type,FileInfo,SharedInfo,'all');
+
+
+endfunction
diff --git a/macros/ASTManagement/AST_HandleFuncArray.sci b/macros/ASTManagement/AST_HandleFuncArray.sci
new file mode 100644
index 00000000..b9ca3c38
--- /dev/null
+++ b/macros/ASTManagement/AST_HandleFuncArray.sci
@@ -0,0 +1,62 @@
+function [RhsNames,RhsScope,NRhs,FName] = AST_HandleFuncArray(FileInfo,SharedInfo)
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author: Ukasha Noor
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+// This function is used for 1D array declaration.
+
+SCI2CNInArgCheck(argn(2),2,2)
+
+ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
+
+// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+
+
+global SCI2CSTACK
+global StackPosition;
+global STACKDEDUG
+// ---------------------------
+// --- End Initialization. ---
+// ---------------------------
+
+
+// ------------------------------
+// --- Read input parameters. ---
+// ------------------------------
+cntpop = 1;
+NRhs = 0;
+RhsField(cntpop) = AST_PopASTStack();
+RhsNames = [];
+while (RhsField(cntpop) ~= 'Rhs :')
+ NRhs = NRhs + 1;
+ if RhsField(cntpop) <> 'Operands:'
+ [RhsNames(NRhs),RhsScope(NRhs)] = AST_ExtractNameAndScope(RhsField(cntpop));
+ end
+ cntpop = cntpop + 1;
+ RhsField(cntpop) = AST_PopASTStack();
+end
+first = AST_PopASTStack();
+second = AST_PopASTStack();
+
+FName = stripblanks(part(second,12:length(second)));
+
+RhsNames = SCI2Cflipud(RhsNames);
+RhsScope = SCI2Cflipud(RhsScope);
+
+// --- Repush everything into the stack. ---
+for cntpush = cntpop:-1:1
+ if RhsField(cntpush) <> 'Operands:' & RhsField(cntpush) <> 'Rhs :'
+ AST_PushASTStack(RhsField(cntpush));
+ end
+end
+
+
+endfunction
diff --git a/macros/ASTManagement/AST_HandleFuncArray2D.sci b/macros/ASTManagement/AST_HandleFuncArray2D.sci
new file mode 100644
index 00000000..859c9942
--- /dev/null
+++ b/macros/ASTManagement/AST_HandleFuncArray2D.sci
@@ -0,0 +1,69 @@
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author: Ukasha Noor
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+// This function is used for 2D array declaration
+// This function extracts the input arguments in the array and check there Name and Scope.
+// Then repush everything back to stack
+function [RhsNames,RhsScope,NRhs,FName] = AST_HandleFuncArray2D(FileInfo,SharedInfo)
+
+SCI2CNInArgCheck(argn(2),2,2)
+
+ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
+
+// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+
+
+global SCI2CSTACK
+global StackPosition;
+global STACKDEDUG
+// ---------------------------
+// --- End Initialization. ---
+// ---------------------------
+
+
+// ------------------------------
+// --- Read input parameters. ---
+// ------------------------------
+cntpop = 1;
+NRhs = 0;
+RhsField(cntpop) = AST_PopASTStack();
+RhsNames = [];
+while (RhsField(cntpop) ~= 'Rhs :')
+ if RhsField(cntpop) <> 'Operands:' & RhsField(cntpop) <> 'Begin:'
+ NRhs = NRhs + 1;
+
+ [RhsNames(NRhs),RhsScope(NRhs)] = AST_ExtractNameAndScope(RhsField(cntpop));
+ end
+ cntpop = cntpop + 1;
+ RhsField(cntpop) = AST_PopASTStack();
+end
+
+first = AST_PopASTStack();
+second = AST_PopASTStack();
+
+FName = stripblanks(part(second,12:length(second)));
+
+RhsNames = SCI2Cflipud(RhsNames);
+RhsScope = SCI2Cflipud(RhsScope);
+
+// --- Repush everything into the stack. ---
+for cntpush = cntpop:-1:1
+ if RhsField(cntpush) <> 'Operands:' & RhsField(cntpush) <> 'Begin:' & RhsField(cntpush) <> 'Rhs :'
+ PrintStringInfo(' ' + RhsField(cntpush),ReportFileName,'file','y');
+ AST_PushASTStack(RhsField(cntpush));
+ end
+end
+
+
+
+
+endfunction
diff --git a/macros/ASTManagement/AST_HandleHeader.sci b/macros/ASTManagement/AST_HandleHeader.sci
index 661c740f..0237bd5f 100644
--- a/macros/ASTManagement/AST_HandleHeader.sci
+++ b/macros/ASTManagement/AST_HandleHeader.sci
@@ -95,7 +95,6 @@ else
NOutArg = size(OutNames,1);
end
-
//#RNU_RES_B
// -------------------------------------
// --- Load the C function dat file. ---
@@ -113,19 +112,26 @@ clear FunInfo
// --- Check coherence between In/Out names and In/Out Arg structure loaded. ---
// -----------------------------------------------------------------------------
//#RNU_RES_E
-if (length(SharedInfo.CurrentFunInfo.InArg(1).Name) > 0)
- NInArgDat = size(SharedInfo.CurrentFunInfo.InArg,1);
+if (~isempty(SharedInfo.CurrentFunInfo.InArg))
+
+ if (length(SharedInfo.CurrentFunInfo.InArg(1).Name) > 0)
+ NInArgDat = size(SharedInfo.CurrentFunInfo.InArg,1);
+ else
+ NInArgDat = 0;
+ end
else
NInArgDat = 0;
end
-if (NInArgDat == NInArg)
+
+if ((NInArgDat == NInArg)|(nxtscifunname == SharedInfo.SCIMainFunName))
for tmpcnt = 1:NInArg
SharedInfo.CurrentFunInfo.InArg(tmpcnt).Name = InNames(tmpcnt);
if (SharedInfo.CurrentFunInfo.InArg(tmpcnt).Dimension == 0)
SharedInfo.CurrentFunInfo.InArg(tmpcnt).Size(1) = '1';
SharedInfo.CurrentFunInfo.InArg(tmpcnt).Size(2) = '1';
SharedInfo.CurrentFunInfo.InArg(tmpcnt).Value = %nan;
+ SharedInfo.CurrentFunInfo.InArg(tmpcnt).FindLike = 0;
else
//#RNU_RES_B
//NUT: using approach 1: Setting for input and output arguments symbolic sizes.
@@ -133,14 +139,14 @@ if (NInArgDat == NInArg)
SharedInfo.CurrentFunInfo.InArg(tmpcnt).Size(1) = '__'+SharedInfo.CurrentFunInfo.InArg(tmpcnt).Name+'Size[0]';
SharedInfo.CurrentFunInfo.InArg(tmpcnt).Size(2) = '__'+SharedInfo.CurrentFunInfo.InArg(tmpcnt).Name+'Size[1]';
SharedInfo.CurrentFunInfo.InArg(tmpcnt).Value = %nan;
+ SharedInfo.CurrentFunInfo.InArg(tmpcnt).FindLike = 0;
end
end
else
error(9999, 'Number of input arguments specified in AST is different from the number specified in .dat file.');
end
-
-if (SharedInfo.CurrentFunInfo.NOutArg == NOutArg)
+if ((SharedInfo.CurrentFunInfo.NOutArg == NOutArg)|(nxtscifunname == SharedInfo.SCIMainFunName))
for tmpcnt = 1:NOutArg
SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Name = OutNames(tmpcnt);
end
@@ -159,8 +165,7 @@ SharedInfo.CurrentFunInfo.OutArg = ...
SharedInfo.CurrentFunInfo.OutArg,NOutArg,...
SharedInfo,...
SharedInfo.CurrentFunInfo.FunPrecSpecifier,...
- SharedInfo.CurrentFunInfo.FunTypeAnnot,SharedInfo.CurrentFunInfo.FunSizeAnnot,ReportFileName);
-
+ SharedInfo.CurrentFunInfo.FunTypeAnnot,SharedInfo.CurrentFunInfo.FunSizeAnnot,ReportFileName,'');
//#RNU_RES_B
// -------------------------------------------------------------------------
// --- Stores InArg structure into the temporary variables symbol table. ---
@@ -206,7 +211,6 @@ for tmpcnt = 1:NOutArg
PrintStringInfo(' Setting symbol ""'+SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Name+'"" in '+SymbTableFileName+'.',ReportFileName,'file','y');
//#RNU_RES_E
-
ST_Set(SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Name,...
SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Type,...
SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Size,...
diff --git a/macros/ASTManagement/AST_HandleIfElse.sci b/macros/ASTManagement/AST_HandleIfElse.sci
index 5373adf6..2b549ed6 100644
--- a/macros/ASTManagement/AST_HandleIfElse.sci
+++ b/macros/ASTManagement/AST_HandleIfElse.sci
@@ -74,11 +74,13 @@ global STACKDEDUG
// ---------------------------------------------------
//#RNU_RES_E
if (ASTIfExpType~='else')
- [IfCondArg,NIfCondArg] = AST_ParseIfExprStruct(FileInfo,SharedInfo,ASTIfExpType);
+ [IfCondArg,NIfCondArg,Op,NOp] = AST_ParseIfExprStruct(FileInfo,SharedInfo,ASTIfExpType);
else
// "else" type doesn't contain any condition to test.
IfCondArg = '';
NIfCondArg = 0;
+ Op = '';
+ NOp = 0;
end
//#RNU_RES_B
@@ -87,6 +89,6 @@ end
// -----------------------------
// --- Generate the C code for if/elseif Expression. ---
//#RNU_RES_E
-SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,ASTIfExpType,FileInfo,SharedInfo);
+SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,Op,NOp,ASTIfExpType,FileInfo,SharedInfo);
endfunction
diff --git a/macros/ASTManagement/AST_HandleRC.sci b/macros/ASTManagement/AST_HandleRC.sci
new file mode 100644
index 00000000..70568612
--- /dev/null
+++ b/macros/ASTManagement/AST_HandleRC.sci
@@ -0,0 +1,58 @@
+function [RhsNames,RhsScope,NRhs] = AST_HandleRC(FileInfo,SharedInfo)
+// Copyright (C) 2017 - IIT Bombay - FOSSEE
+
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// Author: Ukasha Noor
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+// This function is used for 1D array declaration.
+
+SCI2CNInArgCheck(argn(2),2,2)
+
+ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
+
+// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+
+
+global SCI2CSTACK
+global StackPosition;
+global STACKDEDUG
+// ---------------------------
+// --- End Initialization. ---
+// ---------------------------
+
+
+// ------------------------------
+// --- Read input parameters. ---
+// ------------------------------
+cntpop = 1;
+NRhs = 0;
+RhsField(cntpop) = AST_PopASTStack();
+RhsNames = [];
+while (RhsField(cntpop) ~= 'Expression:')
+ NRhs = NRhs + 1;
+ if RhsField(cntpop) <> 'Operands:'
+ [RhsNames(NRhs),RhsScope(NRhs)] = AST_ExtractNameAndScope(RhsField(cntpop));
+ end
+ cntpop = cntpop + 1;
+ RhsField(cntpop) = AST_PopASTStack();
+end
+RhsNames = SCI2Cflipud(RhsNames);
+RhsScope = SCI2Cflipud(RhsScope);
+
+// --- Repush everything into the stack. ---
+for cntpush = cntpop:-1:1
+ if RhsField(cntpush) <> 'Operands:'
+ AST_PushASTStack(RhsField(cntpush));
+ end
+end
+
+
+
+endfunction
diff --git a/macros/ASTManagement/AST_HandleWhileStatem.sci b/macros/ASTManagement/AST_HandleWhileStatem.sci
index 79fb516d..d8c2f73c 100644
--- a/macros/ASTManagement/AST_HandleWhileStatem.sci
+++ b/macros/ASTManagement/AST_HandleWhileStatem.sci
@@ -36,6 +36,8 @@ global SCI2CSTACK
global StackPosition;
global STACKDEDUG
+IfCondArg = [];
+NIfCondArg = 0;
// ------------------------------
// --- Check input arguments. ---
@@ -70,36 +72,40 @@ PrintStringInfo(' Redirecting C code to: '+FileInfo.Funct(nxtscifunnumber).CPa
// --- Generate C code. ---
// ------------------------
//#RNU_RES_E
-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');
+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
- SharedInfo.WhileExpr.CondVar = ArgName;
- //#RNU_RES_B
- // --- Repush strings into the AST stack. ---
- //#RNU_RES_E
-
- AST_PushASTStack(Pop1);
+IfCondArg = SCI2Cflipud(IfCondArg);
-elseif (SharedInfo.WhileExpr.DimCondVar > 0)
- error(9999, 'Cannot manage while with matrix conditions');
-end
-SharedInfo = C_WhileExpression(FileInfo,SharedInfo);
+SharedInfo = C_WhileExpression(IfCondArg,NIfCondArg,Op,NOp,FileInfo,SharedInfo);
// --------------------------
// --- Update SharedInfo. ---
diff --git a/macros/ASTManagement/AST_ParseEqualStruct.sci b/macros/ASTManagement/AST_ParseEqualStruct.sci
index fa76a01d..68bc3da7 100644
--- a/macros/ASTManagement/AST_ParseEqualStruct.sci
+++ b/macros/ASTManagement/AST_ParseEqualStruct.sci
@@ -123,7 +123,7 @@ end
// ------------------------
//#RNU_RES_B
PrintStringInfo('Function Name: '+FunctionName,ReportFileName,'file','y','n');
-PrintStringInfo('N Intput Arguments: '+string(NInArg),ReportFileName,'file','y','n');
+PrintStringInfo('N Input Arguments: '+string(NInArg),ReportFileName,'file','y','n');
//#RNU_RES_E
if (SharedInfo.Equal.Nins > 0)
//#RNU_RES_B
diff --git a/macros/ASTManagement/AST_ParseFuncallStruct.sci b/macros/ASTManagement/AST_ParseFuncallStruct.sci
index 647a70d7..3c322dd5 100644
--- a/macros/ASTManagement/AST_ParseFuncallStruct.sci
+++ b/macros/ASTManagement/AST_ParseFuncallStruct.sci
@@ -87,6 +87,10 @@ NOutArg = eval(stripblanks(part(buffstring,10:length(buffstring))));
buffstring = AST_PopASTStack();
FunctionName = stripblanks(part(buffstring,12:length(buffstring)));
+//if (FunctionName == 'disp')
+ // NOutArg = 0;
+//end
+
// -------------------------------------
// --- Generate the InArg structure. ---
// -------------------------------------
diff --git a/macros/ASTManagement/AST_ParseIfExprStruct.sci b/macros/ASTManagement/AST_ParseIfExprStruct.sci
index a7da0128..88ba2e9c 100644
--- a/macros/ASTManagement/AST_ParseIfExprStruct.sci
+++ b/macros/ASTManagement/AST_ParseIfExprStruct.sci
@@ -1,4 +1,4 @@
-function [IfCondArg,NIfCondArg] = AST_ParseIfExprStruct(FileInfo,SharedInfo,ASTIfExpType)
+function [IfCondArg,NIfCondArg,Op,NOp] = AST_ParseIfExprStruct(FileInfo,SharedInfo,ASTIfExpType)
// function [IfCondArg,NIfCondArg] = AST_ParseIfExprStruct(FileInfo,SharedInfo,ASTIfExpType)
// -----------------------------------------------------------------
//#RNU_RES_B
@@ -31,6 +31,8 @@ function [IfCondArg,NIfCondArg] = AST_ParseIfExprStruct(FileInfo,SharedInfo,ASTI
//
// Status:
// 11-Apr-2007 -- Raffaele Nutricato: Author.
+// 25-June-2017 -- Ukasha Noor: Revised By
+// This function is counting the number of logical operators and there operands.
//
// Copyright 2007 Raffaele Nutricato.
// Contact: raffaele.nutricato@tiscali.it
@@ -63,13 +65,26 @@ global STACKDEDUG
// ------------------------------------
// --- Read if condition variables. ---
// ------------------------------------
+//OutArgOld=[];
+//OutArgNew=[];
+
+//for i = 1:3
+ // OutArgOld(i)=AST_PopASTStack();
+ //PrintStringInfo(' '+OutArgOld(i),ReportFileName,'file','y');
+//end
+//x = AST_PopASTStack();
+
+//OutArgNew = SCI2Cflipud(OutArgOld);
+
flagendpop = 0;
IfExprField = AST_PopASTStack();
+PrintStringInfo(' '+IfExprField+' '+ASTIfExpType,ReportFileName,'file','y');
if (ASTIfExpType=='if')
if (IfExprField=='Expression:')
flagendpop = 1;
// Pop Again the If tag from the AST.
IfExprField = AST_PopASTStack();
+ PrintStringInfo(' '+IfExprField,ReportFileName,'file','y');
end
elseif (ASTIfExpType=='elseif')
if (IfExprField=='Else If Expression')
@@ -78,31 +93,57 @@ elseif (ASTIfExpType=='elseif')
else
error(9999, 'Unknown ASTIfExpType ""'+ASTIfExpType+'"".');
end
-
+NOp=0;
+Op=[];
while (flagendpop == 0)
if (IfExprField~='<EOL>')
if (ASTIfExpType=='if')
if (IfExprField=='Expression:')
flagendpop = 1;
+ //PrintStringInfo('hello dere '+IfExprField,ReportFileName,'file','y');
// 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),tmpscope] = AST_ExtractNameAndScope(IfExprField);
+ IfCondArg(NIfCondArg) = IfExprField;
+ end
+ //[IfCondArg(NIfCondArg),tmpscope] = AST_ExtractNameAndScope(IfExprField);
end
elseif (ASTIfExpType=='elseif')
if (IfExprField=='Else If Expression')
flagendpop = 1;
+ //IfExprField = AST_PopASTStack();
else
- NIfCondArg = NIfCondArg + 1;
- IfCondArg(NIfCondArg) = IfExprField;
- [IfCondArg(NIfCondArg),tmpscope] = AST_ExtractNameAndScope(IfExprField);
+ if (IfExprField=='&&' | IfExprField=='||')
+ NOp = NOp + 1;
+ Op(NOp) = IfExprField;
+ elseif (IfExprField=='Operands:')
+ flagendpop = 0;
+ g = AST_PopASTStack();
+ else
+ NIfCondArg = NIfCondArg + 1;
+ IfCondArg(NIfCondArg) = IfExprField;
+ end
+ //[IfCondArg(NIfCondArg),tmpscope] = AST_ExtractNameAndScope(IfExprField);
end
end
end
+ if flagendpop == 0
IfExprField = AST_PopASTStack();
+ end
+ PrintStringInfo('operators are '+IfExprField,ReportFileName,'file','y');
end
+IfCondArg = SCI2Cflipud(IfCondArg);
+
//#RNU_RES_B
// -------------------------------------------
// --- Print some info in the report file. ---
diff --git a/macros/ASTManagement/AST_ParseOperStruct.sci b/macros/ASTManagement/AST_ParseOperStruct.sci
index a77317bd..ce0bcc72 100644
--- a/macros/ASTManagement/AST_ParseOperStruct.sci
+++ b/macros/ASTManagement/AST_ParseOperStruct.sci
@@ -26,6 +26,7 @@ function [FunctionName,InArg,NInArg,NOutArg] = AST_ParseOperStruct(FileInfo,Shar
//
// Status:
// 11-Apr-2007 -- Raffaele Nutricato: Author.
+// 25-June-2017 -- Ukasha Noor: Revised By
//
// Copyright 2007 Raffaele Nutricato.
// Contact: raffaele.nutricato@tiscali.it
@@ -61,6 +62,17 @@ LabelFunctName = 'Operator: ';
FunctionName = stripblanks(part(buffstring,length(LabelFunctName)+1:length(buffstring)));
// Generate the proper function name.
FunctionName = Operator2FunName(FunctionName);
+PrintStringInfo(' '+FunctionName,ReportFileName,'file','y');
+
+if (FunctionName == 'OpLogAnd' | FunctionName=='OpLogOr')
+ NInArg = 0;
+ NOutArg = 0;
+ InArg=[];
+ //RhsField = AST_PopASTStack();
+ //PrintStringInfo('hello'+RhsField,ReportFileName,'file','y');
+ //RhsField = AST_PopASTStack();
+ return ;
+end
// ------------------------------
// --- Read input parameters. ---
diff --git a/macros/ASTManagement/GenOutArgNames.sci b/macros/ASTManagement/GenOutArgNames.sci
index 0e683835..7b62c794 100644
--- a/macros/ASTManagement/GenOutArgNames.sci
+++ b/macros/ASTManagement/GenOutArgNames.sci
@@ -32,6 +32,12 @@ SCI2CNInArgCheck(argn(2),9,9);
nxtscifunname = SharedInfo.NextSCIFunName;
nxtscifunnumber = SharedInfo.NextSCIFunNumber;
ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
+
+
+global SCI2CSTACK
+global StackPosition;
+global STACKDEDUG
+
// #RNU_RES_B
PrintStringInfo(' Generating Out Arg names.',ReportFileName,'file','y');
// #RNU_RES_E
@@ -43,47 +49,69 @@ OutArg = OldOutArg;
// ---------------------------------------------------------------------------------------
// At this step only the name of the output arguments can be generated. ---
//#RNU_RES_E
-if (NLhsArg > 0)
- //#RNU_RES_B
- // Use the equal Lhs names.
- PrintStringInfo('Using Equal Lhs names.',ReportFileName,'file','y');
- //#RNU_RES_E
- if (NLhsArg ~= NOutArg)
- error(9999, 'NLhsArg='+string(NLhsArg)+' must be equal to NOutArg='+string(NOutArg)+'.');
- end
- for counteroutputargs = 1:NOutArg
- OutArg(counteroutputargs).Name=LhsArg(counteroutputargs).Name;
- OutArg(counteroutputargs).Scope=LhsArg(counteroutputargs).Scope;
- end
+if (FunctionName ~= 'OpLogGt' & FunctionName ~= 'OpLogLt' & FunctionName ~= 'OpLogGe' & FunctionName ~= 'OpLogLe' & FunctionName ~= 'OpLogNe' & FunctionName ~= 'OpLogEq')
+ if (NLhsArg > 0)
+ //#RNU_RES_B
+ // Use the equal Lhs names.
+ PrintStringInfo('Using Equal Lhs names.',ReportFileName,'file','y');
+ //#RNU_RES_E
+ if (NLhsArg ~= NOutArg)
+ error(9999, 'NLhsArg='+string(NLhsArg)+' must be equal to NOutArg='+string(NOutArg)+'.');
+ end
+ for counteroutputargs = 1:NOutArg
+ OutArg(counteroutputargs).Name=LhsArg(counteroutputargs).Name;
+ OutArg(counteroutputargs).Scope=LhsArg(counteroutputargs).Scope;
+ end
+ else
+ //#RNU_RES_B
+ // Generate temporary variables.
+ PrintStringInfo('Generating temporary variables.',ReportFileName,'file','y');
+ //#RNU_RES_E
+ if ((sum(mtlb_strcmp(FunctionName,SharedInfo.Annotations.DataPrec)) > 0) & ...
+ (SharedInfo.SkipNextPrec == 1))
+ //#RNU_RES_B
+ PrintStringInfo(' Skipping code generating because already generated in the previous function.',ReportFileName,'file','y');
+ //#RNU_RES_E
+ for counteroutputargs = 1:NOutArg
+ OutArg(counteroutputargs).Name = InArg(counteroutputargs).Name;
+ end
+ elseif (mtlb_strcmp(FunctionName,'OpEqual'))
+ // do nothing.
+ //NUT: verifica questa parte di codice. e' sicuro che se ho equal gli oldoutarg contengono gia' il nome?
+ else
+ for counteroutputargs = 1:NOutArg
+ if ((SharedInfo.ASTReader.EnableTempVarsReuse == 1) & ...
+ (length(SharedInfo.ASTReader.ReusableTempVars) > 0))
+ TmpOutArgName = strcat([SharedInfo.ASTReader.TempVarsName,string(SharedInfo.ASTReader.ReusableTempVars(1))]);
+ SharedInfo.ASTReader.ReusableTempVars = SharedInfo.ASTReader.ReusableTempVars(2:$);
+ else
+ SharedInfo.ASTReader.UsedTempVars = SharedInfo.ASTReader.UsedTempVars + 1;
+ TmpOutArgName = strcat([SharedInfo.ASTReader.TempVarsName,string(SharedInfo.ASTReader.UsedTempVars)]);
+ end
+ OutArg(counteroutputargs).Name=TmpOutArgName;
+ end
+ end
+ end
else
- //#RNU_RES_B
- // Generate temporary variables.
- PrintStringInfo('Generating temporary variables.',ReportFileName,'file','y');
- //#RNU_RES_E
- if ((sum(mtlb_strcmp(FunctionName,SharedInfo.Annotations.DataPrec)) > 0) & ...
- (SharedInfo.SkipNextPrec == 1))
- //#RNU_RES_B
- PrintStringInfo(' Skipping code generating because already generated in the previous function.',ReportFileName,'file','y');
- //#RNU_RES_E
- for counteroutputargs = 1:NOutArg
- OutArg(counteroutputargs).Name = InArg(counteroutputargs).Name;
- end
- elseif (mtlb_strcmp(FunctionName,'OpEqual'))
- // do nothing.
- //NUT: verifica questa parte di codice. e' sicuro che se ho equal gli oldoutarg contengono gia' il nome?
- else
- for counteroutputargs = 1:NOutArg
- if ((SharedInfo.ASTReader.EnableTempVarsReuse == 1) & ...
- (length(SharedInfo.ASTReader.ReusableTempVars) > 0))
- TmpOutArgName = strcat([SharedInfo.ASTReader.TempVarsName,string(SharedInfo.ASTReader.ReusableTempVars(1))]);
- SharedInfo.ASTReader.ReusableTempVars = SharedInfo.ASTReader.ReusableTempVars(2:$);
- else
- SharedInfo.ASTReader.UsedTempVars = SharedInfo.ASTReader.UsedTempVars + 1;
- TmpOutArgName = strcat([SharedInfo.ASTReader.TempVarsName,string(SharedInfo.ASTReader.UsedTempVars)]);
- end
- OutArg(counteroutputargs).Name=TmpOutArgName;
- end
- end
+ for counterinputargs = 1:NInArg
+ tmppushstack=InArg(counterinputargs).Name;
+ PrintStringInfo(' Pushing in the AST stack: ""'+tmppushstack+'"".',ReportFileName,'file','y');
+ AST_PushASTStack(tmppushstack);
+ if FunctionName=='OpLogGt'
+ AST_PushASTStack('>');
+ elseif FunctionName=='OpLogGe'
+ AST_PushASTStack('>=');
+ elseif FunctionName=='OpLogLt'
+ AST_PushASTStack('<');
+ elseif FunctionName=='OpLogLe'
+ AST_PushASTStack('<=');
+ elseif FunctionName=='OpLogEq'
+ AST_PushASTStack('==');
+ elseif FunctionName=='OpLogNe'
+ AST_PushASTStack('!=');
+ end
+ end
+ s = AST_PopASTStack();
+ PrintStringInfo(' Pushing in the AST stack: ""'+s+'"".',ReportFileName,'file','y');
end
-
endfunction
diff --git a/macros/ASTManagement/_comment_string.sci b/macros/ASTManagement/_comment_string.sci
new file mode 100644
index 00000000..a963507d
--- /dev/null
+++ b/macros/ASTManagement/_comment_string.sci
@@ -0,0 +1,7 @@
+function txt=%comment_string(e)
+//overloading function for "comment" type tlist string function
+//fields:
+// text: a string
+//this is a leaf of the AST
+ txt=['Comment : '+e.text]
+endfunction
diff --git a/macros/ASTManagement/_cste_string.sci b/macros/ASTManagement/_cste_string.sci
new file mode 100644
index 00000000..ba9971d2
--- /dev/null
+++ b/macros/ASTManagement/_cste_string.sci
@@ -0,0 +1,26 @@
+function txt=%cste_string(c)
+//overloading function for "cste" type tlist string function
+//this is a leaf of the AST
+//fields:
+// value : a number or a string
+//NUT: added cste I also need "" for strings in order to be sure that the blanks are
+//NUT: correctly considered and not mistaken with additional blanks present in the ast text file.
+ stringcvalue = string(c.value);
+ if (stringcvalue == "%T" | ...
+ stringcvalue == "%t" | ...
+ stringcvalue == "%F" | ...
+ stringcvalue == "%f" | ...
+ stringcvalue == "%nan" | ...
+ stringcvalue == "%inf" | ...
+ stringcvalue == "%e" | ...
+ stringcvalue == "%pi")
+ txt=['Number_x: '+stringcvalue];
+ elseif (isnum(stringcvalue))
+ //NUT needed to convert format 1D-14 into 1d-14
+ txt=['Number_x: '+strsubst(stringcvalue,'D','e')];
+ elseif (stringcvalue == "%i")
+ txt=['Number_X: '+stringcvalue];
+ else
+ txt=['String: ""'+stringcvalue+'""'];
+ end
+endfunction \ No newline at end of file
diff --git a/macros/ASTManagement/_equal_string.sci b/macros/ASTManagement/_equal_string.sci
new file mode 100644
index 00000000..9678f0e0
--- /dev/null
+++ b/macros/ASTManagement/_equal_string.sci
@@ -0,0 +1,16 @@
+function txt=%equal_string(e)
+//overloading function for "equal" type tlist string function
+//this is a node of the AST
+
+//fields:
+// expression: "expression" type tlist (the right hand side)
+// lhs : list of "variable" type tlist and "operation" type tlist // (the assignment)
+// endsymbol : string (the orginal end-of-instruction symbol (, ; <CR>))
+ txt=['Equal'
+ ' Expression: '
+ ' '+string(e.expression)
+ ' Lhs : '
+ ' '+objectlist2string(e.lhs)
+ 'EndEqual'
+ ]
+endfunction \ No newline at end of file
diff --git a/macros/ASTManagement/_for_string.sci b/macros/ASTManagement/_for_string.sci
new file mode 100644
index 00000000..0ed9ca28
--- /dev/null
+++ b/macros/ASTManagement/_for_string.sci
@@ -0,0 +1,15 @@
+function txt=%for_string(F)
+//overloading function for "for" type tlist string function
+//this is a node of the AST
+//fields:
+// expression : "expression" type tlist (the loop expression)
+// statements : list of "equal" type tlist and list('EOL') (the
+// for instructions list)
+//NUT: raf cambiato ForExpression e ForStatements
+ txt=['For'
+ ' ForExpression:'
+ ' '+string(F.expression)
+ ' ForStatements:'
+ ' '+objectlist2string(F.statements)
+ 'EndFor']
+endfunction \ No newline at end of file
diff --git a/macros/ASTManagement/_funcall_string.sci b/macros/ASTManagement/_funcall_string.sci
new file mode 100644
index 00000000..7c0b0abf
--- /dev/null
+++ b/macros/ASTManagement/_funcall_string.sci
@@ -0,0 +1,25 @@
+function txt=%funcall_string(F)
+//overloading function for "funcall" type tlist string function
+//this is a node of the AST
+//fields:
+// rhs : a list
+// name : string, the name of the function
+// lhsnb: number, the number of function lhs
+// Modified By: Ukasha Noor
+
+if F.name <> 'disp'
+txt=['Funcall : '+F.name
+ ' #lhs : '+string(F.lhsnb)
+ ' Rhs : '
+ ' '+objectlist2string(F.rhs)
+ 'EndFuncall'
+ ]
+else
+txt=['Funcall : '+F.name
+ ' #lhs : '+'0'
+ ' Rhs : '
+ ' '+objectlist2string(F.rhs)
+ 'EndFuncall'
+ ]
+end
+endfunction
diff --git a/macros/ASTManagement/_ifthenel_string.sci b/macros/ASTManagement/_ifthenel_string.sci
new file mode 100644
index 00000000..6787a87c
--- /dev/null
+++ b/macros/ASTManagement/_ifthenel_string.sci
@@ -0,0 +1,27 @@
+function txt=%ifthenel_string(I)
+//overloading function for "ifthenel" type tlist string function
+//this is a node of the AST
+//fields:
+// expression : "expression" type tlist (the if expression)
+// then : list of "equal" type tlist and list('EOL') (the
+// then instructions list)
+// elseifs : a list of tlists
+// else : list of "equal" type tlist and list('EOL') (the
+// else instructions list)
+ txt=['If '
+ ' Expression:'
+ ' '+string(I.expression)
+ ' If Statements'
+ ' '+objectlist2string(I.then)]
+ for e=I.elseifs
+ txt=[txt;
+ ' Else If Expression'
+ ' '+string(e.expression)
+ ' Else If Statements'
+ ' '+objectlist2string(e.then)]
+ end
+ txt=[txt;
+ ' Else Statements'
+ ' '+objectlist2string(I.else)
+ 'EndIf']
+endfunction
diff --git a/macros/ASTManagement/_ifthenelse_string.sci b/macros/ASTManagement/_ifthenelse_string.sci
new file mode 100644
index 00000000..ef588c56
--- /dev/null
+++ b/macros/ASTManagement/_ifthenelse_string.sci
@@ -0,0 +1,27 @@
+function txt=%ifthenelse_string(I)
+//overloading function for "ifthenel" type tlist string function
+//this is a node of the AST
+//fields:
+// expression : "expression" type tlist (the if expression)
+// then : list of "equal" type tlist and list('EOL') (the
+// then instructions list)
+// elseifs : a list of tlists
+// else : list of "equal" type tlist and list('EOL') (the
+// else instructions list)
+ txt=['If '
+ ' Expression:'
+ ' '+string(I.expression)
+ ' If Statements'
+ ' '+objectlist2string(I.then)]
+ for e=I.elseifs
+ txt=[txt;
+ ' Else If Expression'
+ ' '+string(e.expression)
+ ' Else If Statements'
+ ' '+objectlist2string(e.then)]
+ end
+ txt=[txt;
+ ' Else Statements'
+ ' '+objectlist2string(I.else)
+ 'EndIf']
+endfunction
diff --git a/macros/ASTManagement/_operatio_string.sci b/macros/ASTManagement/_operatio_string.sci
new file mode 100644
index 00000000..e9332337
--- /dev/null
+++ b/macros/ASTManagement/_operatio_string.sci
@@ -0,0 +1,13 @@
+function txt=%operatio_string(O)
+//overloading function for "operation" type tlist string function
+//this is a node of the AST
+//fields:
+// operands: a list
+// operator: a string
+ txt=['Operation'
+ ' Operands:'
+ ' '+objectlist2string(O.operands)
+ ' Operator: '+O.operator
+ 'EndOperation'
+ ]
+endfunction
diff --git a/macros/ASTManagement/_operation_string.sci b/macros/ASTManagement/_operation_string.sci
new file mode 100644
index 00000000..c9282f67
--- /dev/null
+++ b/macros/ASTManagement/_operation_string.sci
@@ -0,0 +1,13 @@
+function txt=%operation_string(O)
+//overloading function for "operation" type tlist string function
+//this is a node of the AST
+//fields:
+// operands: a list
+// operator: a string
+ txt=['Operation'
+ ' Operands:'
+ ' '+objectlist2string(O.operands)
+ ' Operator: '+O.operator
+ 'EndOperation'
+ ]
+endfunction
diff --git a/macros/ASTManagement/_program_p.sci b/macros/ASTManagement/_program_p.sci
new file mode 100644
index 00000000..f45ed69a
--- /dev/null
+++ b/macros/ASTManagement/_program_p.sci
@@ -0,0 +1,4 @@
+function %program_p(p)
+ //overloading function for "program" type tlist display
+ mprintf("%s\n",string(p))
+endfunction
diff --git a/macros/ASTManagement/_program_string.sci b/macros/ASTManagement/_program_string.sci
new file mode 100644
index 00000000..93486992
--- /dev/null
+++ b/macros/ASTManagement/_program_string.sci
@@ -0,0 +1,19 @@
+function txt=%program_string(p)
+//overloading function for "program" type tlist string function
+//main (root) node of the Abstract Formal Tree
+//fields:
+// name : string (the function name)
+// outputs : list of "variable" type tlist (the output arg names)
+// inputs : list of "variable" type tlist (the intput arg names)
+// statements: list of "equal" type tlist and list('EOL') (the
+// instructions list)
+// nblines : number (the number of lines in the scilab function)
+ txt=['Program'
+ 'Name : '+p.name
+ 'Outputs: '+strcat(objectlist2string(p.outputs),' ')
+ 'Inputs : '+strcat(objectlist2string(p.inputs),' ')
+ 'Statements '
+ ' '+objectlist2string(p.statements)
+ 'EndProgram'
+ ]
+endfunction
diff --git a/macros/ASTManagement/_variable_string.sci b/macros/ASTManagement/_variable_string.sci
new file mode 100644
index 00000000..86507957
--- /dev/null
+++ b/macros/ASTManagement/_variable_string.sci
@@ -0,0 +1,26 @@
+function txt=%variable_string(v)
+ global anscounter; //NUT: just to fix problem with ans variables.
+//overloading function for "variable" type tlist string function
+//fields: name
+//this is a leaf of the AST
+//NUT: changed here. For me %i is a number not a variable.
+ if (v.name == "%T" | ...
+ v.name == "%t" | ...
+ v.name == "%F"| ...
+ v.name == "%f"| ...
+ v.name == "%nan"| ...
+ v.name == "%inf"| ...
+ v.name == "%e" | ...
+ v.name == "%pi")
+ txt=['Number_x: '+v.name];
+ elseif (v.name == "%i")
+ txt=['Number_X: '+v.name];
+ else
+ if (v.name == 'ans')
+ anscounter = anscounter + 1;
+ txt=['Variable: '+v.name+string(anscounter)];
+ else
+ txt=['Variable: '+v.name];
+ end
+ end
+endfunction \ No newline at end of file
diff --git a/macros/ASTManagement/_while_string.sci b/macros/ASTManagement/_while_string.sci
new file mode 100644
index 00000000..7d5e6223
--- /dev/null
+++ b/macros/ASTManagement/_while_string.sci
@@ -0,0 +1,14 @@
+function txt=%while_string(W)
+//overloading function for "while" type tlist string function
+//this is a node of the AST
+//fields:
+// expression : "expression" type tlist (the loop expression)
+// statements : list of "equal" type tlist and list('EOL') (the
+// while instructions list)
+ txt=['While'
+ ' WhileExpression:'
+ ' '+string(W.expression)
+ ' WhileStatements:'
+ ' '+objectlist2string(W.statements)
+ 'EndWhile']
+endfunction
diff --git a/macros/ASTManagement/names b/macros/ASTManagement/names
new file mode 100644
index 00000000..9ba83f73
--- /dev/null
+++ b/macros/ASTManagement/names
@@ -0,0 +1,65 @@
+%comment_string
+%cste_string
+%equal_string
+%for_string
+%funcall_string
+%ifthenel_string
+%ifthenelse_string
+%operatio_string
+%operation_string
+%program_p
+%program_string
+%variable_string
+%while_string
+AST2Ccode
+AST_CheckCommonInOutArgs
+AST_CheckLastFunc
+AST_CheckLineLength
+AST_CheckPrecSpecifier
+AST_DisplayStack
+AST_ExtractNameAndScope
+AST_GetASTFile
+AST_GetFuncallPrm
+AST_GetPrecAndLhsArg
+AST_HandleCC
+AST_HandleEOL
+AST_HandleEndFor
+AST_HandleEndGenFun
+AST_HandleEndProgram
+AST_HandleEndWhile
+AST_HandleFor
+AST_HandleForStatem
+AST_HandleFunCC
+AST_HandleFunRC
+AST_HandleFuncArray
+AST_HandleFuncArray2D
+AST_HandleHeader
+AST_HandleIfElse
+AST_HandleRC
+AST_HandleWhileExpr
+AST_HandleWhileStatem
+AST_ParseEqualStruct
+AST_ParseFuncallStruct
+AST_ParseIfExprStruct
+AST_ParseOperStruct
+AST_PopASTStack
+AST_PushASTStack
+AST_ReadASTHeader
+AST_ReadEqualRhsNames
+GenOutArgNames
+Operator2FunName
+SciFile2ASTFile
+_comment_string
+_cste_string
+_equal_string
+_for_string
+_funcall_string
+_ifthenel_string
+_ifthenelse_string
+_operatio_string
+_operation_string
+_program_p
+_program_string
+_variable_string
+_while_string
+objectlist2string