summaryrefslogtreecommitdiff
path: root/macros/ASTManagement/AST_HandleWhileStatem.sci
diff options
context:
space:
mode:
authorSiddhesh Wani2015-05-25 14:46:31 +0530
committerSiddhesh Wani2015-05-25 14:46:31 +0530
commitdb464f35f5a10b58d9ed1085e0b462689adee583 (patch)
treede5cdbc71a54765d9fec33414630ae2c8904c9b8 /macros/ASTManagement/AST_HandleWhileStatem.sci
downloadScilab2C_fossee_old-db464f35f5a10b58d9ed1085e0b462689adee583.tar.gz
Scilab2C_fossee_old-db464f35f5a10b58d9ed1085e0b462689adee583.tar.bz2
Scilab2C_fossee_old-db464f35f5a10b58d9ed1085e0b462689adee583.zip
Original Version
Diffstat (limited to 'macros/ASTManagement/AST_HandleWhileStatem.sci')
-rw-r--r--macros/ASTManagement/AST_HandleWhileStatem.sci118
1 files changed, 118 insertions, 0 deletions
diff --git a/macros/ASTManagement/AST_HandleWhileStatem.sci b/macros/ASTManagement/AST_HandleWhileStatem.sci
new file mode 100644
index 0000000..79fb516
--- /dev/null
+++ b/macros/ASTManagement/AST_HandleWhileStatem.sci
@@ -0,0 +1,118 @@
+function [FileInfo,SharedInfo] = AST_HandleWhileStatem(FileInfo,SharedInfo)
+// -----------------------------------------------------------------
+//#RNU_RES_B
+// Handles the WhileStatements tag of the AST.
+//
+// txt=['While'
+// ' WhileExpression:'
+// ' '+string(W.expression)
+// ' WhileStatements:'
+// ' '+objectlist2string(W.statements)
+// 'EndWhile']
+//
+//#RNU_RES_E
+// Input data:
+// //NUT: add description here
+//
+// Output data:
+// //NUT: add description here
+//
+// Status:
+// 20-Jan-2008 -- Edoardo Nutricato: Author.
+// 20-Jan-2008 -- Rubby Nutricato: Minor Changes.
+//
+// Copyright 2007 Raffaele Nutricato.
+// Contact: raffaele.nutricato@tiscali.it
+// -----------------------------------------------------------------
+
+//#RNU_RES_B
+
+//NUT: accertati che l'epilogo e il prologo del while siano effettivamente differenti o se
+//NUT: si puo' avere un solo file utilizzato sia per il prologo che per l'epilogo.
+
+//NUT: da sistemare senza le global
+//#RNU_RES_E
+global SCI2CSTACK
+global StackPosition;
+global STACKDEDUG
+
+
+// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+SCI2CNInArgCheck(argn(2),2,2);
+
+// -----------------------
+// --- Initialization. ---
+// -----------------------
+nxtscifunname = SharedInfo.NextSCIFunName;
+nxtscifunnumber = SharedInfo.NextSCIFunNumber;
+ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName;
+CPass1WhileProlFileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level);
+PrintStepInfo('Handling WhileStatements',FileInfo.Funct(nxtscifunnumber).ReportFileName,'file');
+// ---------------------------
+// --- End Initialization. ---
+// ---------------------------
+
+//#RNU_RES_B
+// -----------------------------------------------
+// --- Resume the correct name while CPass1V1. ---
+// -----------------------------------------------
+//#RNU_RES_E
+tmpfilename = FileInfo.Funct(nxtscifunnumber).CPass1FileName;
+FileInfo.Funct(nxtscifunnumber).CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level);
+FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level) = tmpfilename;
+CPass1WhileProlFileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level);
+PrintStringInfo(' Redirecting C code to: '+FileInfo.Funct(nxtscifunnumber).CPass1FileName,FileInfo.Funct(nxtscifunnumber).ReportFileName,'file');
+
+//#RNU_RES_B
+// ------------------------
+// --- Generate C code. ---
+// ------------------------
+//#RNU_RES_E
+if(SharedInfo.WhileExpr.CondVar == '')
+ //#RNU_RES_B
+ // It means that we are handling something like while(a) or while(1)
+ // The while condition variable is generated by the HandleEndGenFun.
+ //#RNU_RES_E
+
+ // --- Pop the name of the condition variable or number. ---
+ Pop1 = AST_PopASTStack();
+
+ [ArgName,ArgScope] = AST_ExtractNameAndScope(Pop1);
+ if (length(ArgName) == 0)
+ PrintStringInfo(' ',ReportFileName,'both','y');
+ PrintStringInfo('SCI2CERROR: Expected while(variable) or while(number).','','stdout','y');
+ PrintStringInfo('SCI2CERROR: Expected a variable or number in the AST while expression.','','stdout','y');
+ PrintStringInfo('SCI2CERROR: Report this error to http://forge.scilab.org/index.php/p/scilab2c/issues/.','','stdout','y');
+ PrintStringInfo(' ',ReportFileName,'both','y');
+ error(9999, 'Expected a conditional variable in the while expression');
+ end
+
+ SharedInfo.WhileExpr.CondVar = ArgName;
+ //#RNU_RES_B
+ // --- Repush strings into the AST stack. ---
+ //#RNU_RES_E
+
+ AST_PushASTStack(Pop1);
+
+elseif (SharedInfo.WhileExpr.DimCondVar > 0)
+ error(9999, 'Cannot manage while with matrix conditions');
+end
+SharedInfo = C_WhileExpression(FileInfo,SharedInfo);
+
+// --------------------------
+// --- Update SharedInfo. ---
+// --------------------------
+// Signal the exit from a while expression.
+SharedInfo.WhileExpr.OnExec = SharedInfo.WhileExpr.OnExec - 1;
+SharedInfo.WhileExpr.CondVar = '';
+SharedInfo.WhileExpr.DimCondVar = -1;
+SharedInfo.WhileExpr.AssignmentFun = 0; //NUT: siamo sicuri che serva?
+
+// -------------------------------
+// --- Delete temporary files. ---
+// -------------------------------
+SCI2Cmdelete(CPass1WhileProlFileName);
+
+endfunction