diff options
Diffstat (limited to '2.3-1/macros/ASTManagement')
62 files changed, 3993 insertions, 0 deletions
diff --git a/2.3-1/macros/ASTManagement/%comment_string.sci b/2.3-1/macros/ASTManagement/%comment_string.sci new file mode 100644 index 00000000..a963507d --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/%cste_string.sci b/2.3-1/macros/ASTManagement/%cste_string.sci new file mode 100644 index 00000000..ba9971d2 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/%equal_string.sci b/2.3-1/macros/ASTManagement/%equal_string.sci new file mode 100644 index 00000000..9678f0e0 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/%for_string.sci b/2.3-1/macros/ASTManagement/%for_string.sci new file mode 100644 index 00000000..0ed9ca28 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/%funcall_string.sci b/2.3-1/macros/ASTManagement/%funcall_string.sci new file mode 100644 index 00000000..faeb81d9 --- /dev/null +++ b/2.3-1/macros/ASTManagement/%funcall_string.sci @@ -0,0 +1,15 @@ +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 + +txt=['Funcall : '+F.name + ' #lhs : '+string(F.lhsnb) + ' Rhs : ' + ' '+objectlist2string(F.rhs) + 'EndFuncall' + ] +endfunction diff --git a/2.3-1/macros/ASTManagement/%ifthenel_string.sci b/2.3-1/macros/ASTManagement/%ifthenel_string.sci new file mode 100644 index 00000000..6787a87c --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/%ifthenelse_string.sci b/2.3-1/macros/ASTManagement/%ifthenelse_string.sci new file mode 100644 index 00000000..ef588c56 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/%operatio_string.sci b/2.3-1/macros/ASTManagement/%operatio_string.sci new file mode 100644 index 00000000..8421a3f4 --- /dev/null +++ b/2.3-1/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
\ No newline at end of file diff --git a/2.3-1/macros/ASTManagement/%operation_string.sci b/2.3-1/macros/ASTManagement/%operation_string.sci new file mode 100644 index 00000000..84f5ce3c --- /dev/null +++ b/2.3-1/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
\ No newline at end of file diff --git a/2.3-1/macros/ASTManagement/%program_p.sci b/2.3-1/macros/ASTManagement/%program_p.sci new file mode 100644 index 00000000..f45ed69a --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/%program_string.sci b/2.3-1/macros/ASTManagement/%program_string.sci new file mode 100644 index 00000000..93486992 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/%variable_string.sci b/2.3-1/macros/ASTManagement/%variable_string.sci new file mode 100644 index 00000000..86507957 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/%while_string.sci b/2.3-1/macros/ASTManagement/%while_string.sci new file mode 100644 index 00000000..7d5e6223 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/AST2Ccode.sci b/2.3-1/macros/ASTManagement/AST2Ccode.sci new file mode 100644 index 00000000..409eaab1 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST2Ccode.sci @@ -0,0 +1,268 @@ +function AST2Ccode(FileInfoDatFile) +// function AST2Ccode(FileInfoDatFile) +// ----------------------------------------------------------------- +// Read the AST and call the corresponding handlers. +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-May-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),1,1); + + +//NUT: questa funzione e' da sistemare meglio + +// --------------------- +// --- Load section. --- +// --------------------- +// --- Load File Info Structure. --- +load(FileInfoDatFile,'FileInfo'); + +// --- Load Shared Info Structure. --- +load(FileInfo.SharedInfoDatFile,'SharedInfo'); +// ------------------------- +// --- End load section. --- +// ------------------------- + +// --------------------------------------------------- +// --- Extraction of the function name and number. --- +// --------------------------------------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +SharedInfo.Function_list = []; +SharedInfo.Function_list_index = 1; + +// --------------------------------- +// --- Parameter Initialization. --- +// --------------------------------- +global SCI2CSTACK +SCI2CSTACK = ['EMPTYSTACK']; + +global StackPosition; +StackPosition = 1; + +global STACKDEDUG +STACKDEDUG = 0; // 1 -> Every Pop and Push operation on the stack, the stack content will be printed on screen. +// ------------------------------------- +// --- End parameter Initialization. --- +// ------------------------------------- + +ASTFileName = FileInfo.Funct(nxtscifunnumber).ASTFileName; + + +// ----------------------- +// --- Initialization. --- +// ----------------------- +// --- Open AST file. --- +SharedInfo.ASTReader.fidAST = SCI2COpenFileRead(ASTFileName); +fidAST = SharedInfo.ASTReader.fidAST; + +OrigWorkAreaUsedBytes = SharedInfo.WorkAreaUsedBytes; +OrigUsedTempScalarVars = SharedInfo.UsedTempScalarVars; + +PrintStepInfo('Generate C code in '+FileInfo.Funct(nxtscifunnumber).FinalCFileName,... + FileInfo.GeneralReport,'both'); +// --------------------------- +// --- End initialization. --- +// --------------------------- + +// ------------------------ +// --- Parse AST header. --- +// ------------------------ +ASTHeader = AST_ReadASTHeader(fidAST,ReportFileName); +SharedInfo = AST_HandleHeader(ASTHeader,FileInfo,SharedInfo); +//NUT: le metto per ora perche' quando provo a cercare lo specifier di precisione al termine +//NUT: del programma non ho piu' nulla da poppare se lo specifier e' assente. Al limite posso mettere la program e i nomi +//NUT: al posto di dummy. +AST_PushASTStack('Dummy'); +AST_PushASTStack('Dummy'); +AST_PushASTStack('Dummy'); +AST_PushASTStack('Dummy'); +AST_PushASTStack('Dummy'); +AST_PushASTStack('Dummy'); +AST_PushASTStack('Dummy'); +AST_PushASTStack('Dummy'); +//NUT: Se ne tolgo qualcuno ottengo errori +// ---------------------------- +// --- End Parse AST header. --- +// ---------------------------- + //NUT: better to have a function. + + // --- Reset TempVars Structure. --- + TempVars = []; + // Reset info related to temp variables used in the C code. + SharedInfo.WorkAreaUsedBytes = OrigWorkAreaUsedBytes; + 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. --- +// ---------------------------------- +//NUT: file ottenuto con m2sci se hai tempo prova a vedere se ci sono inesattezze. +//NUT: inoltre per maggiore eleganza si puo' pensare di introdurre piu' funzioni + +while ~meof(fidAST) + // Read a line from the AST + tline = mgetl(fidAST,1); + AST_CheckLineLength(tline); + treeline = stripblanks(tline); + + if STACKDEDUG == 1 + disp('Read AST Line: '+treeline); + end + + // Analyze line. + select treeline + + // ------------------ + // --- Functions. --- + // ------------------ + //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'); + case 'EndFuncall' then + [FileInfo,SharedInfo] = AST_HandleEndGenFun(FileInfo,SharedInfo,'Funcall'); + + // -------------- + // --- Equal. --- + // -------------- + case 'EndEqual' then + //NUT: prima di lanciare l'analisi della equal puoi mettere degli argomenti dummy + //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); + 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); + + // lengthNumber = length('Number_'); + // if (part(EqualInArgScope,1:lengthNumber) == 'Number_') + // SharedInfo.SkipNextEqual = 1 + // end + 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/Else. --- + // ---------------- + //NUT: da verificare la gestione dello stack + case 'If Statements' then + [FileInfo,SharedInfo] = AST_HandleIfElse(FileInfo,SharedInfo,'if'); + case 'Else If Expression' then + AST_PushASTStack(treeline); + [FileInfo,SharedInfo] = AST_HandleIfElse(FileInfo,SharedInfo,'else'); + case 'Else If Statements' then + [FileInfo,SharedInfo] = AST_HandleIfElse(FileInfo,SharedInfo,'elseif'); + case 'Else Statements' then + [FileInfo,SharedInfo] = AST_HandleIfElse(FileInfo,SharedInfo,'else'); + case 'EndIf' then + for counter=1:SharedInfo.CountNestedIf+1 + SharedInfo = C_IfElseBlocks(FileInfo,SharedInfo,'out'); + end + SharedInfo.CountNestedIf = 0; + + // -------------- + // --- Dummy. --- + // -------------- + case 'Comment :' then + AST_HandleEOL(FileInfo,SharedInfo); //NUT: si potrebbe differenziare comment da EOL + case '<EOL>' then + AST_HandleEOL(FileInfo,SharedInfo); + + // ----------------- + // --- Epilogue. --- + // ----------------- + case 'EndProgram' + SharedInfo = AST_HandleEndProgram(FileInfo,SharedInfo); + //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. --- + // ------------ + case 'For' then + SharedInfo.For.Level = SharedInfo.For.Level + 1; + FileInfo = AST_HandleFor(FileInfo,SharedInfo); + case 'ForExpression:' + AST_PushASTStack(treeline); + SharedInfo.ForExpr.OnExec = SharedInfo.ForExpr.OnExec + 1; + case 'ForStatements:' + [FileInfo,SharedInfo] = AST_HandleForStatem(FileInfo,SharedInfo); + case 'EndFor' then + SharedInfo = AST_HandleEndFor(FileInfo,SharedInfo); + SharedInfo.For.Level = SharedInfo.For.Level - 1; + + // -------------- + // --- While. --- + // -------------- + case 'While' then + AST_PushASTStack(treeline); + SharedInfo.While.Level = SharedInfo.While.Level + 1; + case 'WhileExpression:' + AST_PushASTStack(treeline); + [FileInfo,SharedInfo] = AST_HandleWhileExpr(FileInfo,SharedInfo); + case 'WhileStatements:' + [FileInfo,SharedInfo] = AST_HandleWhileStatem(FileInfo,SharedInfo); + case 'EndWhile' then + SharedInfo = AST_HandleEndWhile(FileInfo,SharedInfo); + SharedInfo.While.Level = SharedInfo.While.Level - 1; + + // ---------------- + // --- Default. --- + // ---------------- + else + 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. --- +// -------------------------------------- + +mclose(fidAST); +// --------------------- +// --- Save section. --- +// --------------------- +// --- Save Shared Info Structure. --- +save(SharedInfoDatFile, "SharedInfo"); +// ------------------------- +// --- End save section. --- +// ------------------------- +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_CheckCommonInOutArgs.sci b/2.3-1/macros/ASTManagement/AST_CheckCommonInOutArgs.sci new file mode 100644 index 00000000..8e3afdcf --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_CheckCommonInOutArgs.sci @@ -0,0 +1,88 @@ +function AST_CheckCommonInOutArgs(InArg,NInArg,OutArg,NOutArg,ReportFileName) +// function AST_CheckCommonInOutArgs(InArg,NInArg,OutArg,NOutArg,ReportFileName) +// ----------------------------------------------------------------- +// #RNU_RES_B +// Compares input and output arguments names and issues and error +// when at least one output argument is equal to the one of the +// input arguments. The error is issued only when the common argument +// is not a scalar value. This is a safe approach that prevents error +// when the same matrix is used as both input and output argument of +// a function. +// #RNU_RES_E +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 08-Jan-2008 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),5,5); + +ncommonstrings = 0; +commonstrings = ''; + +//RNU non mi ricordo per quale motivo avevo commentato il seguente codice +//RNU e decommentato l'altro a seguire. Sembra che avessi deciso che anche +//RNU le variabili scalari non potessero essere usate nella stessa expr +//RNU contemporaneamente come input e come output +for cnt1 = 1:NInArg + for cnt2 = 1:NOutArg + if ((InArg(cnt1).Name == OutArg(cnt2).Name) & ... + (InArg(cnt1).Dimension > 0)) + ncommonstrings = ncommonstrings + 1; + commonstrings(ncommonstrings) = InArg(cnt1).Name; + end + end +end + +// for cnt1 = 1:NInArg +// for cnt2 = 1:NOutArg +// if ((InArg(cnt1).Name == OutArg(cnt2).Name)) +// ncommonstrings = ncommonstrings + 1; +// commonstrings(ncommonstrings) = InArg(cnt1).Name; +// end +// end +// end + +if (ncommonstrings > 0) + PrintStringInfo(' ',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Found '+string(ncommonstrings)+' input/output 2-D arguments',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: with the same name: ',ReportFileName,'both','y'); + for cntstr = 1:ncommonstrings + PrintStringInfo('SCI2CERROR: Arg('+string(cntstr)+'): '+commonstrings(cntstr),ReportFileName,'both','y'); + end + PrintStringInfo(' ',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: This approach is not allowed because it is not safe',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: due to the fact that arrays are passed by reference to functions.',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: For example if A is a squared matrix then the following code,',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: A = A'';',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: could generate incorrect results.',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: Please consider renaming input or output arguments.',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: See examples below:',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: ',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: // Example 1: Function call.',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: A = zeros(10,9);',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: A = sin(A); // Not Allowed',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: // The previous line must be rewritten as:',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: MYTMP = A; // Allowed',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: A = sin(MYTMP); // Allowed',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: ',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: // Example 2: Function definition.',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: function d = myfun(a,b,c,d) // Not Allowed',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: // The previous line must be rewritten as:',ReportFileName,'both','y'); + PrintStringInfo('SCI2CERROR: function e = myfun(a,b,c,d) // Not Allowed',ReportFileName,'both','y'); + PrintStringInfo(' ',ReportFileName,'both','y'); + error(9999, 'SCI2CERROR: Found '+string(ncommonstrings)+' input/output 2-D arguments with the same name.'); +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_CheckLastFunc.sci b/2.3-1/macros/ASTManagement/AST_CheckLastFunc.sci new file mode 100644 index 00000000..508435b7 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_CheckLastFunc.sci @@ -0,0 +1,77 @@ +function [LhsArgNames,LhsArgScope,NLhsArg] = AST_CheckLastFunc(fidAST,SearchLevel) +// function [LhsArgNames,LhsArgScope,NLhsArg] = AST_CheckLastFunc(fidAST,SearchLevel) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +astfilepos = mtell(fidAST); +NLhsArg = 0; +LhsArgNames = ''; +LhsArgScope = ''; +FlagLastFunc = 0; +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +//NUT: non capisco come mai tu non faccia il flipud degli argometi letti. +//NUT: Level 1 e' quando abbiamo una equal float fun +//NUT: level 0 quando abbiamo equal fun +tline = mgetl(fidAST,1); +AST_CheckLineLength(tline); +LhsField = stripblanks(tline); +if ((SearchLevel == 1) & (LhsField == 'EndFuncall')) + SearchLevel = 0; + tline = mgetl(fidAST,1); + AST_CheckLineLength(tline); + LhsField = stripblanks(tline); +end +if ((SearchLevel == 0) & (LhsField == 'Lhs :')) + tline = mgetl(fidAST,1); + AST_CheckLineLength(tline); + LhsField = stripblanks(tline); + while(LhsField ~= 'EndEqual') + NLhsArg = NLhsArg + 1; + if (LhsField == '<EOL>') + error(9999, 'Found <EOL> before EndEqual'); + elseif (LhsField == 'EndProgram') + error(9999, 'Found EndProgram before EndEqual'); + end + if (LhsField == 'Operation') + // if (LhsField == 'Operator: ins') + // It means that we have to store the results of the function in temp vars. + LhsField = 'EndEqual'; // Force the exit from the while. + NLhsArg = 0; + LhsArgNames = ''; + LhsArgScope = ''; + else + [LhsArgNames(NLhsArg),LhsArgScope(NLhsArg)] = AST_ExtractNameAndScope(LhsField); + tline = mgetl(fidAST,1); + AST_CheckLineLength(tline); + LhsField = stripblanks(tline); + end + end +end +mseek(astfilepos,fidAST,'set'); + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_CheckLineLength.sci b/2.3-1/macros/ASTManagement/AST_CheckLineLength.sci new file mode 100644 index 00000000..3973b188 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_CheckLineLength.sci @@ -0,0 +1,31 @@ +function AST_CheckLineLength(instring) +// function AST_CheckLineLength(instring) +// ----------------------------------------------------------------- +// "Fixes" the AST generator bug. When a line of code is greater +// than 80 chars the generated AST is wrong. +// +// Input data: +// instring: string read from the AST. +// +// Output data: +// --- +// +// Status: +// 15-May-2008 -- Raffaele Nutricato: Author. +// +// Copyright 2008 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),1,1); + +// TODO : Remove me + +//if length(instring) > 77 +// SCI2Cerror('Line too long: please reduce the length of the current line.'); +//end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_CheckPrecSpecifier.sci b/2.3-1/macros/ASTManagement/AST_CheckPrecSpecifier.sci new file mode 100644 index 00000000..e8ffbf1f --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_CheckPrecSpecifier.sci @@ -0,0 +1,82 @@ +function AnnotationFnc = AST_CheckPrecSpecifier(FunctionName,FileInfo,SharedInfo); +// function AnnotationFnc = AST_CheckPrecSpecifier(FunctionName,FileInfo,SharedInfo); +// ----------------------------------------------------------------- +// #RNU_RES_B +// Searches for one of the following data annotation functions: +// Funcall : int +// Funcall : float +// Funcall : double +// Note: remember to execute this function before pushing the output +// argument names into the stack. +// #RNU_RES_E +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 13-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),3,3); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +PrintStringInfo(' ',ReportFileName,'file','y'); +// #RNU_RES_B +PrintStringInfo(' Checking presence of precision specifier',ReportFileName,'file','y'); +//NUT: da sistemare senza le global +// #RNU_RES_E +global SCI2CSTACK +global StackPosition; +global STACKDEDUG + +AnnotationFnc = 'default'; +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +Pop1 = AST_PopASTStack(); // Rhs : +if (mtlb_strcmp(stripblanks(Pop1),'Rhs :')) + Pop2 = AST_PopASTStack(); // #lhs : 1 + if (mtlb_strcmp(stripblanks(Pop2),'#lhs : 1')) + Pop3 = AST_PopASTStack(); // Funcall : double + FunctionName = stripblanks(part(Pop3,12:length(Pop3))); + for counterdataprec = 1:max(size(SharedInfo.Annotations.DataPrec)) + if (mtlb_strcmp(FunctionName,SharedInfo.Annotations.DataPrec(counterdataprec))) + AnnotationFnc = FunctionName; + end + end + // --- Repush strings into the AST stack. --- + AST_PushASTStack(Pop3); + end + // --- Repush strings into the AST stack. --- + AST_PushASTStack(Pop2); +end +// --- Repush strings into the AST stack. --- +AST_PushASTStack(Pop1); + +if mtlb_strcmp(AnnotationFnc,'default') + // #RNU_RES_B + PrintStringInfo('Function is not annotated',ReportFileName,'file','y'); + PrintStringInfo('The ""'+SharedInfo.DefaultPrecision+'"" default precision will be used.',ReportFileName,'file','y'); + // #RNU_RES_E +else + // #RNU_RES_B + PrintStringInfo('Function is annotated with ""'+AnnotationFnc+'"" specifier',ReportFileName,'file','y'); + // #RNU_RES_E +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_DisplayStack.sci b/2.3-1/macros/ASTManagement/AST_DisplayStack.sci new file mode 100644 index 00000000..8543e2e0 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_DisplayStack.sci @@ -0,0 +1,42 @@ +function AST_DisplayStack() +// function AST_DisplayStack() +// ----------------------------------------------------------------- +// Displays the AST stack content. The AST stack is used to read the +// AST. +// +// Input data: +// --- +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),0,0); + +global SCI2CSTACK +global StackPosition; +global STACKDEDUG + +disp('*********************') +disp('*********************') + +if (STACKDEDUG == 1) + for counterposition = 1:StackPosition + disp(SCI2CSTACK(counterposition,1)) + end +end +disp('---------------------') +disp('---------------------') +disp(' ');disp(' ');disp('Press return to continue'); halt; + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_ExtractNameAndScope.sci b/2.3-1/macros/ASTManagement/AST_ExtractNameAndScope.sci new file mode 100644 index 00000000..1dbaaad7 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_ExtractNameAndScope.sci @@ -0,0 +1,107 @@ +function [ArgName,ArgScope] = AST_ExtractNameAndScope(ASTField) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 27-Dec-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),1,1); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +ArgName = ''; +ArgScope = ''; + +cnttag = 0; +cnttag = cnttag + 1; +tagname(cnttag) = 'Number_'; +taglength(cnttag) = length(tagname(cnttag)); + +cnttag = cnttag + 1; +tagname(cnttag) = 'String:'; +taglength(cnttag) = length(tagname(cnttag)); + +cnttag = cnttag + 1; +tagname(cnttag) = 'Variable:'; +taglength(cnttag) = length(tagname(cnttag)); + +cnttag = cnttag + 1; +tagname(cnttag) = 'Global:'; +taglength(cnttag) = length(tagname(cnttag)); + +cnttag = cnttag + 1; +tagname(cnttag) = 'Local:'; +taglength(cnttag) = length(tagname(cnttag)); + +cnttag = cnttag + 1; +tagname(cnttag) = 'Temp:'; +taglength(cnttag) = length(tagname(cnttag)); + +cnttag = cnttag + 1; +tagname(cnttag) = '<empty>'; +taglength(cnttag) = length(tagname(cnttag)); + +fieldlength = length(ASTField); + + +//NUT: il seguente codice e' poco elegante. +if (SCI2Cstrncmps1size(tagname(1),ASTField)) + // Here we can have: + // Number_x: it means default precision. + // Number_s: it means float real type. + // Number_d: it means double real type. + // Number_c: it means float complex type. + // Number_z: it means double complex type. + + // 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'; +else + error(9999, 'Argument specifier not found in the AST field: '+ASTField); +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_GetASTFile.sci b/2.3-1/macros/ASTManagement/AST_GetASTFile.sci new file mode 100644 index 00000000..16fbbbac --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_GetASTFile.sci @@ -0,0 +1,58 @@ +function AST_GetASTFile(FileInfoDatFile) +// function AST_GetASTFile(FileInfoDatFile) +// ----------------------------------------------------------------- +// Generates the AST file starting from the .sci file specified +// in SharedInfo.NextSCIFileName. +// +// Input data: +// FileInfoDatFile: name of the .dat file containing the FileInfo structure. +// +// Output data: +// --- +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),1,1); + +// --------------------------------- +// --- Load File Info Structure. --- +// --------------------------------- +clear FileInfo +load(FileInfoDatFile,'FileInfo'); + +// ----------------------------------- +// --- Load Shared Info Structure. --- +// ----------------------------------- +clear SharedInfo +load(FileInfo.SharedInfoDatFile,'SharedInfo'); + +// --------------------------------------------------- +// --- Extraction of the function name and number. --- +// --------------------------------------------------- +funname = SharedInfo.NextSCIFunName; +funnumber = SharedInfo.NextSCIFunNumber; + +PrintStepInfo('Generate the AST.', FileInfo.GeneralReport,'both'); + +// --- Generation of the AST file. --- +SciFile2ASTFile(FileInfo.Funct(funnumber).SCIFileName,... + FileInfo.Funct(funnumber).ASTFileName); + +// --------------------- +// --- Save section. --- +// --------------------- +// --- Save File Info Structure. --- +// save(FileInfoDatFile, "FileInfo"); +// ------------------------- +// --- End save section. --- +// ------------------------- + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_GetFuncallPrm.sci b/2.3-1/macros/ASTManagement/AST_GetFuncallPrm.sci new file mode 100644 index 00000000..e7c1581c --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_GetFuncallPrm.sci @@ -0,0 +1,54 @@ +function [FunctionName,InArg,NInArg,OutArg,NOutArg] = ... + AST_GetFuncallPrm(FileInfo,SharedInfo,ASTFunType) +// function [FunctionName,InArg,NInArg,NOutArg] = ... +// AST_GetFuncallPrm(FileInfo,SharedInfo,ASTFunType) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),3,3); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +//#RNU_RES_B +PrintStringInfo('***Retrieving '+ASTFunType+' Parameters from AST***',ReportFileName,'file','y'); +//#RNU_RES_E +OutArg = []; +NOutArg = 0; +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// ------------------------------------------------------ +// --- Get Parameters from the AST Funcall structure. --- +// ------------------------------------------------------ +if (ASTFunType=='Funcall') + [FunctionName,InArg,NInArg,NOutArg] = AST_ParseFuncallStruct(FileInfo,SharedInfo); +elseif (ASTFunType=='Operation') + [FunctionName,InArg,NInArg,NOutArg] = AST_ParseOperStruct(FileInfo,SharedInfo); +elseif (ASTFunType=='Equal') + [FunctionName,InArg,NInArg,OutArg,NOutArg] = AST_ParseEqualStruct(FileInfo,SharedInfo); +else + error(9999, 'Unknown Function type: '+ASTFunType+'.'); +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_GetPrecAndLhsArg.sci b/2.3-1/macros/ASTManagement/AST_GetPrecAndLhsArg.sci new file mode 100644 index 00000000..f45c29e5 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_GetPrecAndLhsArg.sci @@ -0,0 +1,99 @@ +function [LhsArg,NLhsArg,PrecisionSpecifier,SharedInfo] = AST_GetPrecAndLhsArg(OutArg,NOutArg,FunctionName,FunTypeAnnot,FunSizeAnnot,ASTFunType,FileInfo,SharedInfo); +// function [LhsArg,NLhsArg,PrecisionSpecifier,SharedInfo] = AST_GetPrecAndLhsArg(OutArg,NOutArg,FunctionName,FunTypeAnnot,FunSizeAnnot,ASTFunType,FileInfo,SharedInfo); +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),8,8); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +// #RNU_RES_B +PrintStringInfo('***Search for Equal Lhs and precision specifier to be applied to the current function.***',ReportFileName,'file','y'); +// #RNU_RES_E +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// #RNU_RES_B +// --------------------------------------- +// --- Search for Precision Specifier. --- +// --------------------------------------- +// #RNU_RES_E +if (NOutArg == 1 & FunTypeAnnot == 'FA_TP_USER') + PrecisionSpecifier = AST_CheckPrecSpecifier(FunctionName,FileInfo,SharedInfo); + if (PrecisionSpecifier == 'default') + SearchLevel = 0; + else + SearchLevel = 1; + SharedInfo.SkipNextPrec = 1; + end +else + PrecisionSpecifier = ''; + SearchLevel = 0; +end + +// #RNU_RES_B +// ------------------------------------------------------------- +// --- Check Last Function Condition and update LhsArg info. --- +// ------------------------------------------------------------- +// #RNU_RES_E +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'); + // #RNU_RES_E + [LhsArgNames,LhsArgScope,NLhsArg] = AST_CheckLastFunc(SharedInfo.ASTReader.fidAST,SearchLevel); +else + LhsArgNames = ''; + LhsArgScope = ''; + NLhsArg = 0; +end +// --- Generate the LhsArg structure. --- +LhsArg = []; +for cntarg = 1:NLhsArg + LhsArg(cntarg).Name = LhsArgNames(cntarg); + LhsArg(cntarg).Scope = LhsArgScope(cntarg); +end + +// #RNU_RES_B +// ------------------------- +// --- Check on NLhsArg. --- +// ------------------------- +// #RNU_RES_E +if (NLhsArg > 0) + // #RNU_RES_B + PrintStringInfo('...Found Equal.',ReportFileName,'file','y'); + PrintStringInfo('OutArg Names will be replaced with Lhs Names of the Equal.',ReportFileName,'file','y'); + // #RNU_RES_E + SharedInfo.SkipNextEqual = 1; // 1 = the next equal in the AST will not produce C code. + if (NLhsArg ~= NOutArg) + error(9999, 'NLhsArg='+string(NLhsArg)+' must be equal to NOutArg='+string(NOutArg)+'.'); + end +else + // #RNU_RES_B + PrintStringInfo('...Equal not found.',ReportFileName,'file','y'); + // #RNU_RES_E +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_HandleEOL.sci b/2.3-1/macros/ASTManagement/AST_HandleEOL.sci new file mode 100644 index 00000000..4b287283 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_HandleEOL.sci @@ -0,0 +1,65 @@ +function AST_HandleEOL(FileInfo,SharedInfo) +// function AST_HandleEOL(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// Handles the EOL tag of the AST. +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + + +//#RNU_RES_B +//NUT: questa parte e' molto interessante perche' ti puo' aiutare per fare confronti +//NUT: incrociati tra le annotazioni della funzione e gli argomenti in uscita. +//NUT: in particolare una volta messi nella tabella dei simboli anche gli argomenti +//NUT: di uscita puoi benissimo verificare che li stai utilizzando bene nel corpo della funzione stessa. +//#RNU_RES_E + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName; +SciFileFid = FileInfo.Funct(nxtscifunnumber).SCICopyFileFid; +IndentLevel = SharedInfo.NIndent; + +PrintStepInfo('Handling EOL',ReportFileName,'file'); +sciline = mgetl(SciFileFid,1); + +// #RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y','n'); +PrintStringInfo('##################'+'################'+'##################'+'##################'+'##################',ReportFileName,'file','y','n'); +PrintStringInfo('##################'+'################'+'##################'+'##################'+'##################',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'; +if (SharedInfo.CopySciCodeIntoCCode == 1) + 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'); +PrintStringInfo(C_IndentBlanks(IndentLevel)+' SCI2C: #############'+'############'+'##############'+'###############'+'############*/',CPass1FileName,modeprintstringinfo,'y','n'); + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_HandleEndFor.sci b/2.3-1/macros/ASTManagement/AST_HandleEndFor.sci new file mode 100644 index 00000000..dc6c4126 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_HandleEndFor.sci @@ -0,0 +1,78 @@ +function SharedInfo = AST_HandleEndFor(FileInfo,SharedInfo) +// function SharedInfo = AST_HandleEndFor(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// #RNU_RES_B +// Handles the EndFor tag of the AST. +// 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) +// txt=['For' +// ' ForExpression:' +// ' '+string(F.expression) +// ' ForStatements:' +// ' '+objectlist2string(F.statements) +// 'EndFor'] +// +// #RNU_RES_E +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 15-Nov-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; + +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName; +CPass1ForProlFileName = FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level); +CPass1ForEpilFileName = FileInfo.Funct(nxtscifunnumber).CPass1ForEpilFileName(SharedInfo.For.Level); + +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Handling EndFor***',ReportFileName,'file','y'); +CCall =''; +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// ---------------------------- +// --- Generate the C code. --- +// ---------------------------- +// --- Copy Epilogue into C code (Pass1) file. --- +[CLinesArray,N_Lines] = File2StringArray(CPass1ForEpilFileName); +CLinesArray = stripblanks(CLinesArray); + +for tmpcnt = 1:N_Lines-1 + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CLinesArray(tmpcnt),CPass1FileName,'file','y'); +end +PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent-1)+CLinesArray(N_Lines),CPass1FileName,'file','y'); + +// -------------------------- +// --- Update SharedInfo. --- +// -------------------------- +SharedInfo.NIndent = SharedInfo.NIndent - 1; + +// ------------------------------- +// --- Delete temporary files. --- +// ------------------------------- +SCI2Cmdelete(FileInfo.Funct(nxtscifunnumber).CPass1ForEpilFileName(SharedInfo.For.Level)); + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_HandleEndGenFun.sci b/2.3-1/macros/ASTManagement/AST_HandleEndGenFun.sci new file mode 100644 index 00000000..fec79532 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_HandleEndGenFun.sci @@ -0,0 +1,564 @@ + +function [FileInfo,SharedInfo] = AST_HandleEndGenFun(FileInfo,SharedInfo,ASTFunType) +// function [FileInfo,SharedInfo] = AST_HandleEndGenFun(FileInfo,SharedInfo,ASTFunType) +// ----------------------------------------------------------------- +// #RNU_RES_B +// Handles the EndFuncall, EndOperation and EndEqual tags of the AST. +// ASTFunType can be 'Funcall', 'Operation', 'Equal' +// Structure of Funcall: +// 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 +// txt=['Funcall : '+F.name +// ' #lhs : '+string(F.lhsnb) +// ' Rhs : ' +// ' '+objectlist2string(F.rhs) +// 'EndFuncall' +// ] +// #RNU_RES_E +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),3,3); + +// ----------------------- +// --- 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; +if(SharedInfo.Target == 'AVR') + PeripheralInitListFile = FileInfo.PeripheralInitListFile; +elseif (SharedInfo.Target == 'Arduino') + SetupListFile = FileInfo.SetupListFile; +end + +Flag_FunAlreadyCalled = 0; +// #RNU_RES_B +PrintStepInfo('Handling Funcall/Operation/Equal',FileInfo.Funct(nxtscifunnumber).ReportFileName,'file'); +// #RNU_RES_E +//NUT: da sistemare senza le global +global SCI2CSTACK +global StackPosition; +global STACKDEDUG +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// #RNU_RES_B +// --------------------------------------------- +// --- Retrieve FunCall Parameters from AST. --- +// --------------------------------------------- +//NUT: verifica se ASTFunType e' veramente importante +// #RNU_RES_E +[ASTFunName,InArg,NInArg,OutArg,NOutArg] = AST_GetFuncallPrm(FileInfo,SharedInfo,ASTFunType); +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(mtlb_strcmp(part(ASTFunName,1:2),'CV') == %T) + SharedInfo.OpenCVUsed = %T; + end + + 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 + end + + // #RNU_RES_B + // -------------------------------------- + // --- Read the function annotations. --- + // -------------------------------------- + // #RNU_RES_E + + 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 + [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 + // -------------------------------- + // --- 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 + 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 + // ------------------------------------------------------------------- + // --- 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 + // --------------------------------- + // --- 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); + else + [OutArg,SharedInfo] = GenOutArgNames(ASTFunName,InArg,NInArg,OutArg,NOutArg,LhsArg,NLhsArg,FileInfo,SharedInfo); + 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. + 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. + 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)) + //disp(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 + 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 + + //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/2.3-1/macros/ASTManagement/AST_HandleEndProgram.sci b/2.3-1/macros/ASTManagement/AST_HandleEndProgram.sci new file mode 100644 index 00000000..2d6d77a9 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_HandleEndProgram.sci @@ -0,0 +1,62 @@ +function SharedInfo = AST_HandleEndProgram(FileInfo,SharedInfo) +// function SharedInfo = AST_HandleEndProgram(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// Handles the EndProgram tag of the AST. +// +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 12-Jun-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName + +IndentLevel = SharedInfo.NIndent; +CCall = ''; +PrintStepInfo('Handling EndProgram',ReportFileName,'file'); +tmpposfirstscalar = SharedInfo.CurrentFunInfo.PosFirstOutScalar; + +if (1==2) + //NUT: disabled because at the moment I am able to decode the return instruction. + if (SharedInfo.CurrentFunInfo.CFunctionName == SharedInfo.CMainFunName) + CCall = CCall+'return(0);'; + else + if (SharedInfo.CurrentFunInfo.PosFirstOutScalar > 0) + CCall = CCall+'return('+SharedInfo.CurrentFunInfo.OutArg(tmpposfirstscalar).Name+');' + end + end + + PrintStringInfo(' '+CCall,ReportFileName,'file','y'); + PrintStringInfo(C_IndentBlanks(IndentLevel)+CCall,CPass1FileName,'file','y'); +end + + +SharedInfo.NIndent = SharedInfo.NIndent - 1; +IndentLevel = SharedInfo.NIndent; +PrintStringInfo(' }',ReportFileName,'file','y'); +PrintStringInfo(C_IndentBlanks(IndentLevel)+'}',CPass1FileName,'file','y'); + +// --- Close the copy of the scilab file. --- +PrintStringInfo(' Closing: '+FileInfo.Funct(nxtscifunnumber).SCICopyFileName,ReportFileName,'file','y'); +mclose(FileInfo.Funct(nxtscifunnumber).SCICopyFileFid); + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_HandleEndWhile.sci b/2.3-1/macros/ASTManagement/AST_HandleEndWhile.sci new file mode 100644 index 00000000..94649b10 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_HandleEndWhile.sci @@ -0,0 +1,76 @@ +function SharedInfo = AST_HandleEndWhile(FileInfo,SharedInfo) +// function SharedInfo = AST_HandleEndWhile(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +//#RNU_RES_B +// Handles the EndWhile 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: +// 15-Nov-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; + +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1FileName; +CPass1WhileEpilFileName = FileInfo.Funct(nxtscifunnumber).CPass1WhileEpilFileName(SharedInfo.While.Level); + +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Handling EndWhile***',ReportFileName,'file','y'); +CCall =''; +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +//#RNU_RES_B +// ---------------------------- +// --- Generate the C code. --- +// ---------------------------- +// --- Copy Epilogue into C code (Pass1) file. --- +//#RNU_RES_E +[CLinesArray,N_Lines] = File2StringArray(CPass1WhileEpilFileName); +CLinesArray = stripblanks(CLinesArray); + +for tmpcnt = 1:N_Lines-1 + PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent)+CLinesArray(tmpcnt),CPass1FileName,'file','y'); +end +PrintStringInfo(C_IndentBlanks(SharedInfo.NIndent-1)+CLinesArray(N_Lines),CPass1FileName,'file','y'); + +//#RNU_RES_B +// -------------------------- +// --- Update SharedInfo. --- +// -------------------------- +//#RNU_RES_E +SharedInfo.NIndent = SharedInfo.NIndent - 1; + +// ------------------------------- +// --- Delete temporary files. --- +// ------------------------------- +SCI2Cmdelete(CPass1WhileEpilFileName); + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_HandleFor.sci b/2.3-1/macros/ASTManagement/AST_HandleFor.sci new file mode 100644 index 00000000..e96edd4c --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_HandleFor.sci @@ -0,0 +1,84 @@ +function FileInfo = AST_HandleFor(FileInfo,SharedInfo) +// function FileInfo = AST_HandleFor(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +//#RNU_RES_B +// Handles the For tag of the AST. +// +// 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) +// txt=['For' +// ' Expression:' +// ' '+string(F.expression) +// ' Statements:' +// ' '+objectlist2string(F.statements) +// 'EndFor'] +// +//#RNU_RES_E +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 10-Nov-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +PfxP1ForProlFileName = FileInfo.Funct(nxtscifunnumber).PfxP1ForProlFileName; +PfxP1ForEpilFileName = FileInfo.Funct(nxtscifunnumber).PfxP1ForEpilFileName; +PrintStepInfo('Handling For',FileInfo.Funct(nxtscifunnumber).ReportFileName,'file'); +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +//#RNU_RES_B +// --- Signal the entrance in a for expression. --- +//#RNU_RES_E +SharedInfo.ForExpr.OnExec = SharedInfo.ForExpr.OnExec + 1; + +//#RNU_RES_B +// --- Generate the file names for the prologue and epilogue files. --- +//#RNU_RES_E +FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level) = ... + PfxP1ForProlFileName+string(SharedInfo.For.Level)+'.c'; +FileInfo.Funct(nxtscifunnumber).CPass1ForEpilFileName(SharedInfo.For.Level) = ... + PfxP1ForEpilFileName+string(SharedInfo.For.Level)+'.c'; + +//#RNU_RES_B +// --------------------------------------------------------- +// --- Create a copy of the For Prologue/Epilogue Files. --- +// --------------------------------------------------------- +//#RNU_RES_E +PrintStringInfo(' ',FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level),'file'); +PrintStringInfo(' ',FileInfo.Funct(nxtscifunnumber).CPass1ForEpilFileName(SharedInfo.For.Level),'file'); + +//#RNU_RES_B +// ------------------------------------------------------ +// --- Replace the CPass1V1 file with a temp ForFile. --- +// ------------------------------------------------------ +// From now up to Expression: all the C code will be written in a for temporary file. +//#RNU_RES_E +tmpfilename = FileInfo.Funct(nxtscifunnumber).CPass1FileName; +FileInfo.Funct(nxtscifunnumber).CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level); +FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level) = tmpfilename; +PrintStringInfo('Redirecting C code to: '+FileInfo.Funct(nxtscifunnumber).CPass1FileName,FileInfo.Funct(nxtscifunnumber).ReportFileName,'file'); + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_HandleForStatem.sci b/2.3-1/macros/ASTManagement/AST_HandleForStatem.sci new file mode 100644 index 00000000..f47538a6 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_HandleForStatem.sci @@ -0,0 +1,87 @@ +function [FileInfo,SharedInfo] = AST_HandleForStatem(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +//#RNU_RES_B +// Handles the ForStatements tag of the AST. +// 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) +// txt=['For' +// ' ForExpression:' +// ' '+string(F.expression) +// ' ForStatements:' +// ' '+objectlist2string(F.statements) +// 'EndFor'] +// +//#RNU_RES_E +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 15-Nov-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(2,2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +PrintStepInfo('Handling ForStatements',FileInfo.Funct(nxtscifunnumber).ReportFileName,'file'); +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +//#RNU_RES_B +// --------------------------------------------- +// --- Resume the correct name for CPass1V1. --- +// --------------------------------------------- +//#RNU_RES_E +tmpfilename = FileInfo.Funct(nxtscifunnumber).CPass1FileName; +FileInfo.Funct(nxtscifunnumber).CPass1FileName = FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level); +FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level) = tmpfilename; +PrintStringInfo(' Redirecting C code to: '+FileInfo.Funct(nxtscifunnumber).CPass1FileName,FileInfo.Funct(nxtscifunnumber).ReportFileName,'file'); + +//#RNU_RES_B +// ------------------------ +// --- Generate C code. --- +// ------------------------ +//#RNU_RES_E +SharedInfo = C_ForExpression(FileInfo,SharedInfo); + +//#RNU_RES_B +// -------------------------- +// --- Update SharedInfo. --- +// -------------------------- +// Signal the exit from a for expression. +//#RNU_RES_E +SharedInfo.ForExpr.OnExec = SharedInfo.ForExpr.OnExec - 1; +SharedInfo.ForExpr.IntCntArg = []; +SharedInfo.ForExpr.MtxValCntArg = []; +SharedInfo.ForExpr.SclValCntArg = []; +SharedInfo.ForExpr.OpColonInfoIn1 = ''; +SharedInfo.ForExpr.OpColonInfoIn2 = ''; +SharedInfo.ForExpr.OpColonInfoIn3 = ''; + + +SharedInfo.ForExpr.AssignmentFun = 0; + +// ------------------------------- +// --- Delete temporary files. --- +// ------------------------------- +SCI2Cmdelete(FileInfo.Funct(nxtscifunnumber).CPass1ForProlFileName(SharedInfo.For.Level)); + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_HandleHeader.sci b/2.3-1/macros/ASTManagement/AST_HandleHeader.sci new file mode 100644 index 00000000..0237bd5f --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_HandleHeader.sci @@ -0,0 +1,249 @@ +function SharedInfo = AST_HandleHeader(ASTHeader,FileInfo,SharedInfo) +// function SharedInfo = AST_HandleHeader(ASTHeader,FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// Handles the Header of the AST. +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),3,3); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; + +FunctionName = ASTHeader.Name; +if (mtlb_strcmp(ASTHeader.Name,SharedInfo.NextSCIFunName) == %F) + error(9999, 'Very strange! AST Name field ""'+ASTHeader.Name+... + '""is different from function name ""'+SharedInfo.NextSCIFunName+'"".'); +end +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// ------------------------------------- +// --- Extract info from AST header. --- +// ------------------------------------- +TmpInNames = tokens(ASTHeader.Inputs,' '); +TmpOutNames = tokens(ASTHeader.Outputs,' '); + +//#RNU_RES_B +// Remove Variable: Number: or String: specifier. +//#RNU_RES_E +NInArg = 0; +for tmpcnt = 1:size(TmpInNames,1) + TmpSingleName = TmpInNames(tmpcnt); + if ((TmpSingleName == 'Variable:') | ... + (TmpSingleName == 'String:') | ... + (TmpSingleName == 'Number:')) + // Skip the specifier. + else + NInArg = NInArg + 1; + InNames(NInArg) = TmpSingleName; + end +end + +//#RNU_RES_B +// Remove Variable: Number: or String: specifier. +//#RNU_RES_E +NOutArg = 0; +for tmpcnt = 1:size(TmpOutNames,1) + TmpSingleName = TmpOutNames(tmpcnt); + if ((TmpSingleName == 'Variable:') | ... + (TmpSingleName == 'String:') | ... + (TmpSingleName == 'Number_x:') | ... + (TmpSingleName == 'Number_s:') | ... + (TmpSingleName == 'Number_d:') | ... + (TmpSingleName == 'Number_c:') | ... + (TmpSingleName == 'Number_z:')) + // Skip the specifier. + else + NOutArg = NOutArg + 1; + OutNames(NOutArg) = TmpSingleName; + end +end + +if (mtlb_strcmp(InNames(1),'<empty>')) + NInArg = 0; +else + NInArg = size(InNames,1); +end + +if ((OutNames(1)=='<empty>') | (FunctionName == 'ins')) + //#RNU_RES_B + //NUT: Force ins to have 0 args. Double check it. + //#RNU_RES_E + + NOutArg = 0; +else + NOutArg = size(OutNames,1); +end + +//#RNU_RES_B +// ------------------------------------- +// --- Load the C function dat file. --- +// ------------------------------------- +//NUT: This load is useful expecially for the second approach. In this case we are not using +//NUT: the size info. +//#RNU_RES_E +load(fullfile(FileInfo.FunctionList.FunInfoDatDir,SharedInfo.NextCFunName+'.dat'),'FunInfo'); + +SharedInfo.CurrentFunInfo = FunInfo; +clear FunInfo + +//#RNU_RES_B +// ----------------------------------------------------------------------------- +// --- Check coherence between In/Out names and In/Out Arg structure loaded. --- +// ----------------------------------------------------------------------------- +//#RNU_RES_E +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)|(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. + //#RNU_RES_E + 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)|(nxtscifunname == SharedInfo.SCIMainFunName)) + for tmpcnt = 1:NOutArg + SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Name = OutNames(tmpcnt); + end +else + //#RNU_RES_B + PrintStringInfo('N. of output arguments found in the AST: '+string(NOutArg),ReportFileName,'both','y'); + PrintStringInfo('N. of output arguments found in the call (FunInfo structure): '+string(SharedInfo.CurrentFunInfo.NOutArg),ReportFileName,'both','y'); + //#RNU_RES_E + error(9999, 'Number of output arguments specified in AST is different from the number specified in .dat file.'); +end +//#RNU_RES_B +//NUT: using approach 1: Setting for input and output arguments symbolic sizes. +//#RNU_RES_E +SharedInfo.CurrentFunInfo.OutArg = ... + FA_GetOutArgInfo(SharedInfo.CurrentFunInfo.InArg,NInArg,... + SharedInfo.CurrentFunInfo.OutArg,NOutArg,... + SharedInfo,... + SharedInfo.CurrentFunInfo.FunPrecSpecifier,... + SharedInfo.CurrentFunInfo.FunTypeAnnot,SharedInfo.CurrentFunInfo.FunSizeAnnot,ReportFileName,''); +//#RNU_RES_B +// ------------------------------------------------------------------------- +// --- Stores InArg structure into the temporary variables symbol table. --- +// ------------------------------------------------------------------------- +//#RNU_RES_E +SymbTableFileName = FileInfo.Funct(nxtscifunnumber).LocalVarFileName; + +// #RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Putting Input and Output arguments in the local symbol table***',ReportFileName,'file','y'); +// #RNU_RES_E +for tmpcnt = 1:NInArg + //#RNU_RES_B + PrintStringInfo(' Symbol ""'+SharedInfo.CurrentFunInfo.InArg(tmpcnt).Name+'""',ReportFileName,'file','y'); + PrintStringInfo(' Setting symbol ""'+SharedInfo.CurrentFunInfo.InArg(tmpcnt).Name+'"" in '+SymbTableFileName+'.',ReportFileName,'file','y'); + //#RNU_RES_E + + ST_Set(SharedInfo.CurrentFunInfo.InArg(tmpcnt).Name,... + SharedInfo.CurrentFunInfo.InArg(tmpcnt).Type,... + SharedInfo.CurrentFunInfo.InArg(tmpcnt).Size,... + SharedInfo.CurrentFunInfo.InArg(tmpcnt).Value,... + SharedInfo.CurrentFunInfo.InArg(tmpcnt).FindLike,... + SharedInfo.CurrentFunInfo.InArg(tmpcnt).Dimension,... + SymbTableFileName); + //#RNU_RES_B + PrintStringInfo(' Type: '+SharedInfo.CurrentFunInfo.InArg(tmpcnt).Type,ReportFileName,'file','y'); + PrintStringInfo(' Size(1): '+string(SharedInfo.CurrentFunInfo.InArg(tmpcnt).Size(1)),ReportFileName,'file','y'); + PrintStringInfo(' Size(2): '+string(SharedInfo.CurrentFunInfo.InArg(tmpcnt).Size(2)),ReportFileName,'file','y'); + PrintStringInfo(' Value: '+string(SharedInfo.CurrentFunInfo.InArg(tmpcnt).Value),ReportFileName,'file','y'); + PrintStringInfo(' FindLike: '+string(SharedInfo.CurrentFunInfo.InArg(tmpcnt).FindLike),ReportFileName,'file','y'); + PrintStringInfo(' Dimension: '+string(SharedInfo.CurrentFunInfo.InArg(tmpcnt).Dimension),ReportFileName,'file','y'); + PrintStringInfo(' ',ReportFileName,'file','y'); + //#RNU_RES_E +end + +// -------------------------------------------------------------------------- +// --- Stores OutArg structure into the temporary variables symbol table. --- +// -------------------------------------------------------------------------- +//NUT: verifica se puoi usare l'outarg2symboltable qui. +for tmpcnt = 1:NOutArg + //#RNU_RES_B + PrintStringInfo(' Symbol ""'+SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Name+'""',ReportFileName,'file','y'); + + 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,... + SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Value,... + SharedInfo.CurrentFunInfo.OutArg(tmpcnt).FindLike,... + SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Dimension,... + SymbTableFileName); + //#RNU_RES_B + PrintStringInfo(' Type: '+SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Type,ReportFileName,'file','y'); + PrintStringInfo(' Size(1): '+string(SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Size(1)),ReportFileName,'file','y'); + PrintStringInfo(' Size(2): '+string(SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Size(2)),ReportFileName,'file','y'); + PrintStringInfo(' Value: '+string(SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Value),ReportFileName,'file','y'); + PrintStringInfo(' FindLike: '+string(SharedInfo.CurrentFunInfo.OutArg(tmpcnt).FindLike),ReportFileName,'file','y'); + PrintStringInfo(' Dimension: '+string(SharedInfo.CurrentFunInfo.OutArg(tmpcnt).Dimension),ReportFileName,'file','y'); + PrintStringInfo(' ',ReportFileName,'file','y'); + //#RNU_RES_E + +end + +//#RNU_RES_B +// ----------------------------------------------- +// --- Check on common input/output arguments. --- +// ----------------------------------------------- +//#RNU_RES_E +AST_CheckCommonInOutArgs(SharedInfo.CurrentFunInfo.InArg,NInArg,SharedInfo.CurrentFunInfo.OutArg,NOutArg,ReportFileName); + +//#RNU_RES_B +// ------------------------ +// --- Generate C code. --- +// ------------------------ +//#RNU_RES_E +FlagCall = 0; +SharedInfo = C_Funcall(SharedInfo.CurrentFunInfo,FileInfo,SharedInfo,FlagCall); +SharedInfo.NIndent = SharedInfo.NIndent+1; // Increase indentation level. + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_HandleIfElse.sci b/2.3-1/macros/ASTManagement/AST_HandleIfElse.sci new file mode 100644 index 00000000..5373adf6 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_HandleIfElse.sci @@ -0,0 +1,92 @@ +function [FileInfo,SharedInfo] = AST_HandleIfElse(FileInfo,SharedInfo,ASTIfExpType) +// function [FileInfo,SharedInfo] = AST_HandleIfElse(FileInfo,SharedInfo,ASTIfExpType) +// ----------------------------------------------------------------- +//#RNU_RES_B +// Handles the Else If tag of the AST. +// +// 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'] +// +// Input data: +// ASTIfExpType: it specifies if we are handling a if condition (ASTIfExpType='if') +// or an elseif condition (ASTIfExpType='elseif') or else statement (ASTIfExpType='else') +//#RNU_RES_E +// //NUT: add description here +// +// +// Output data: +// //NUT: add description here +// +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),3,3); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +PrintStepInfo('Handling If Statements',FileInfo.Funct(nxtscifunnumber).ReportFileName,'file'); + +global SCI2CSTACK +global StackPosition; +global STACKDEDUG +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +//#RNU_RES_B +// --------------------------------------------------- +// --- Retrieve If Expression Parameters from AST. --- +// --------------------------------------------------- +//#RNU_RES_E +if (ASTIfExpType~='else') + [IfCondArg,NIfCondArg] = AST_ParseIfExprStruct(FileInfo,SharedInfo,ASTIfExpType); +else + // "else" type doesn't contain any condition to test. + IfCondArg = ''; + NIfCondArg = 0; +end + +//#RNU_RES_B +// ----------------------------- +// --- C Generation Section. --- +// ----------------------------- +// --- Generate the C code for if/elseif Expression. --- +//#RNU_RES_E +SharedInfo = C_IfExpression(IfCondArg,NIfCondArg,ASTIfExpType,FileInfo,SharedInfo); + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_HandleWhileExpr.sci b/2.3-1/macros/ASTManagement/AST_HandleWhileExpr.sci new file mode 100644 index 00000000..ffcf2f45 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_HandleWhileExpr.sci @@ -0,0 +1,80 @@ +function [FileInfo,SharedInfo] = AST_HandleWhileExpr(FileInfo,SharedInfo) +// function [FileInfo,SharedInfo] = AST_HandleWhileExpr(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +//#RNU_RES_B +// Handles the WhileExpression 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: +// 29-Dec-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +PfxP1WhileProlFileName = FileInfo.Funct(nxtscifunnumber).PfxP1WhileProlFileName; +PfxP1WhileEpilFileName = FileInfo.Funct(nxtscifunnumber).PfxP1WhileEpilFileName; +PrintStepInfo('Handling While',FileInfo.Funct(nxtscifunnumber).ReportFileName,'file'); +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +//#RNU_RES_B +// --- Signal the entrance in a while expression. --- +//#RNU_RES_E +SharedInfo.WhileExpr.OnExec = SharedInfo.WhileExpr.OnExec + 1; + +//#RNU_RES_B +// --- Generate the file names for the prologue and epilogue files. --- +//#RNU_RES_E +FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level) = ... + PfxP1WhileProlFileName+string(SharedInfo.While.Level)+'.c'; +FileInfo.Funct(nxtscifunnumber).CPass1WhileEpilFileName(SharedInfo.While.Level) = ... + PfxP1WhileEpilFileName+string(SharedInfo.While.Level)+'.c'; + +//#RNU_RES_B +// ----------------------------------------------------------- +// --- Create a copy of the While Prologue/Epilogue Files. --- +// ----------------------------------------------------------- +//#RNU_RES_E +PrintStringInfo(' ',FileInfo.Funct(nxtscifunnumber).CPass1WhileProlFileName(SharedInfo.While.Level),'file'); +PrintStringInfo(' ',FileInfo.Funct(nxtscifunnumber).CPass1WhileEpilFileName(SharedInfo.While.Level),'file'); + +//#RNU_RES_B +// -------------------------------------------------------- +// --- Replace the CPass1V1 file with a temp WhileFile. --- +// -------------------------------------------------------- +// From now up to Expression: all the C code will be written in a while temporary file. +//#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; +//#RNU_RES_B +PrintStringInfo('Redirecting C code to: '+FileInfo.Funct(nxtscifunnumber).CPass1FileName,FileInfo.Funct(nxtscifunnumber).ReportFileName,'file'); +//#RNU_RES_E + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_HandleWhileStatem.sci b/2.3-1/macros/ASTManagement/AST_HandleWhileStatem.sci new file mode 100644 index 00000000..79fb516d --- /dev/null +++ b/2.3-1/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 diff --git a/2.3-1/macros/ASTManagement/AST_ParseEqualStruct.sci b/2.3-1/macros/ASTManagement/AST_ParseEqualStruct.sci new file mode 100644 index 00000000..fa76a01d --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_ParseEqualStruct.sci @@ -0,0 +1,168 @@ +function [FunctionName,InArg,NInArg,OutArg,NOutArg] = AST_ParseEqualStruct(FileInfo,SharedInfo) +// function [FunctionName,InArg,NInArg,OutArg,NOutArg] = AST_ParseEqualStruct(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +//#RNU_RES_B +// Parses the Equal structure of the AST. +// Structure of Equal: +// txt=['Equal' +// ' Expression: ' +// ' '+string(e.expression) +// ' Lhs : ' +// ' '+objectlist2string(e.lhs) +// 'EndEqual' +// ] +//#RNU_RES_E +// +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; + +global SCI2CSTACK +global StackPosition; +global STACKDEDUG + +//#RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y','n'); +PrintStringInfo('***Reading AST***',ReportFileName,'file','y','n'); +//#RNU_RES_E + +// ------------------------------- +// --- 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 +OutputArgumentNames = SCI2Cflipud(OutputArgumentNames); +OutputArgumentScope = SCI2Cflipud(OutputArgumentScope); + +// ------------------------------ +// --- Read input parameters. --- +// ------------------------------ +ExprField = AST_PopASTStack(); +NInArg = 0; +InputArgumentNames = []; +while (ExprField ~= 'Expression:') + NInArg = NInArg + 1; + [InputArgumentNames(NInArg),InputArgumentScope(NInArg)] = AST_ExtractNameAndScope(ExprField); + ExprField = AST_PopASTStack(); + if (ExprField == 'Equal') + error(9999, 'Found Equal before Lhs'); + end +end +InputArgumentNames = SCI2Cflipud(InputArgumentNames); +InputArgumentScope = SCI2Cflipud(InputArgumentScope); + +//#RNU_RES_B +// ------------------------------ +// --- Extract function name. --- +// ------------------------------ +//#RNU_RES_E +FunctionName = AST_PopASTStack(); +if (FunctionName ~= 'Equal') then + error(9999, 'Problems with Equal, Expected Equal tag.'); +end +FunctionName = 'OpEqual'; + +//#RNU_RES_B +// ------------------------------------- +// --- Generate the InArg structure. --- +// ------------------------------------- +//#RNU_RES_E +InArg = []; +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. --- +// ------------------------ +//#RNU_RES_B +PrintStringInfo('Function Name: '+FunctionName,ReportFileName,'file','y','n'); +PrintStringInfo('N Intput Arguments: '+string(NInArg),ReportFileName,'file','y','n'); +//#RNU_RES_E +if (SharedInfo.Equal.Nins > 0) + //#RNU_RES_B + PrintStringInfo('N ins functions: '+string(SharedInfo.Equal.Nins),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'); + PrintStringInfo(' Scope: '+InArg(counterinputargs).Scope,... + ReportFileName,'file','y'); + //#RNU_RES_E + end + if (NInArg ~= SharedInfo.Equal.Nins) + error(9999, 'Number of input arguments must be equal to number of ins functions.'); + end +else + //#RNU_RES_B + 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 + if (NInArg ~= NOutArg) + error(9999, 'Number of input arguments must be equal to number of output arguments.'); + end +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_ParseFuncallStruct.sci b/2.3-1/macros/ASTManagement/AST_ParseFuncallStruct.sci new file mode 100644 index 00000000..647a70d7 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_ParseFuncallStruct.sci @@ -0,0 +1,116 @@ +function [FunctionName,InArg,NInArg,NOutArg] = AST_ParseFuncallStruct(FileInfo,SharedInfo) +// function [FunctionName,InArg,NInArg,NOutArg] = AST_ParseFuncallStruct(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +//#RNU_RES_B +// Extracts Input Arguments, Output Arguments and Function Name +// from the AST. +// +// Structure of Funcall: +// 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 +// txt=['Funcall : '+F.name +// ' #lhs : '+string(F.lhsnb) +// ' Rhs : ' +// ' '+objectlist2string(F.rhs) +// 'EndFuncall' +// ] +// +//#RNU_RES_E +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +// #RNU_RES_B +PrintStringInfo(' Parsing Funcall structure',ReportFileName,'file','y'); +// #RNU_RES_E +global SCI2CSTACK +global StackPosition; +global STACKDEDUG + + +// ------------------------------ +// --- Read input parameters. --- +// ------------------------------ +RhsField = AST_PopASTStack(); +NInArg = 0; +while (RhsField ~= 'Rhs :') + NInArg = NInArg + 1; + [InputArgumentNames(NInArg),InputArgumentScope(NInArg)] = AST_ExtractNameAndScope(RhsField); + RhsField = AST_PopASTStack(); + if (RhsField == '#lhs :') + error(9999, 'Found #lhs before Rhs'); + elseif (RhsField == 'Funcall :') + error(9999, 'Found Funcall before Rhs'); + end +end +if (stripblanks(InputArgumentNames(NInArg)) == '<empty>') + NInArg = 0; + InputArgumentNames = []; + InputArgumentScope = []; +end +InputArgumentNames = SCI2Cflipud(InputArgumentNames); +InputArgumentScope = SCI2Cflipud(InputArgumentScope); + +// -------------------------------------------- +// --- Extract number of output parameters. --- +// -------------------------------------------- +buffstring = AST_PopASTStack(); +NOutArg = eval(stripblanks(part(buffstring,10:length(buffstring)))); + +// ------------------------------ +// --- Extract function name. --- +// ------------------------------ +buffstring = AST_PopASTStack(); +FunctionName = stripblanks(part(buffstring,12:length(buffstring))); + +// ------------------------------------- +// --- Generate the InArg structure. --- +// ------------------------------------- +InArg = []; +for counterinputargs = 1:NInArg + if (InputArgumentNames(counterinputargs) == 'r') + InputArgumentNames(counterinputargs) = 'rr'; //NUT: per ora cerco di risolvere cosi' il baco sulla 'r' + end + InArg(counterinputargs).Name=InputArgumentNames(counterinputargs); + InArg(counterinputargs).Scope=InputArgumentScope(counterinputargs); +end + +//#RNU_RES_B +PrintStringInfo('Function Name: '+FunctionName,ReportFileName,'file','y','n'); +PrintStringInfo('N Intput Arguments: '+string(NInArg),ReportFileName,'file','y','n'); +PrintStringInfo('N Output Arguments: '+string(NOutArg),ReportFileName,'file','y','n'); +//#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 + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_ParseIfExprStruct.sci b/2.3-1/macros/ASTManagement/AST_ParseIfExprStruct.sci new file mode 100644 index 00000000..a7da0128 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_ParseIfExprStruct.sci @@ -0,0 +1,119 @@ +function [IfCondArg,NIfCondArg] = AST_ParseIfExprStruct(FileInfo,SharedInfo,ASTIfExpType) +// function [IfCondArg,NIfCondArg] = AST_ParseIfExprStruct(FileInfo,SharedInfo,ASTIfExpType) +// ----------------------------------------------------------------- +//#RNU_RES_B +// Parses the IfExpression structure of the AST. +// +// 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'] +// +//#RNU_RES_E +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),3,3); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +//#RNU_RES_B +PrintStringInfo('***Retrieving '+ASTIfExpType+' expression parameters from AST***',ReportFileName,'file','y'); +//#RNU_RES_E +IfCondArg = []; +NIfCondArg = 0; + +global SCI2CSTACK +global StackPosition; +global STACKDEDUG +// --------------------------- +// --- End Initialization. --- +// --------------------------- + +// ------------------------------------ +// --- Read if condition variables. --- +// ------------------------------------ +flagendpop = 0; +IfExprField = AST_PopASTStack(); +if (ASTIfExpType=='if') + if (IfExprField=='Expression:') + flagendpop = 1; + // Pop Again the If tag from the AST. + IfExprField = AST_PopASTStack(); + end +elseif (ASTIfExpType=='elseif') + if (IfExprField=='Else If Expression') + flagendpop = 1; + end +else + error(9999, 'Unknown ASTIfExpType ""'+ASTIfExpType+'"".'); +end + +while (flagendpop == 0) + if (IfExprField~='<EOL>') + if (ASTIfExpType=='if') + if (IfExprField=='Expression:') + flagendpop = 1; + // Pop Again the If tag from the AST. + IfExprField = AST_PopASTStack(); + else + NIfCondArg = NIfCondArg + 1; + [IfCondArg(NIfCondArg),tmpscope] = AST_ExtractNameAndScope(IfExprField); + end + elseif (ASTIfExpType=='elseif') + if (IfExprField=='Else If Expression') + flagendpop = 1; + else + NIfCondArg = NIfCondArg + 1; + IfCondArg(NIfCondArg) = IfExprField; + [IfCondArg(NIfCondArg),tmpscope] = AST_ExtractNameAndScope(IfExprField); + end + end + end + IfExprField = AST_PopASTStack(); +end + +//#RNU_RES_B +// ------------------------------------------- +// --- Print some info in the report file. --- +// ------------------------------------------- +PrintStringInfo('N '+ASTIfExpType+' Condition Arguments: '+string(NIfCondArg),ReportFileName,'file','y'); +//#RNU_RES_E +for counterifcondargs = 1:NIfCondArg + //#RNU_RES_B + PrintStringInfo(ASTIfExpType+' Condition Argument Number '+string(counterifcondargs)+': '+IfCondArg(counterifcondargs),... + ReportFileName,'file','y'); + //#RNU_RES_E +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_ParseOperStruct.sci b/2.3-1/macros/ASTManagement/AST_ParseOperStruct.sci new file mode 100644 index 00000000..a77317bd --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_ParseOperStruct.sci @@ -0,0 +1,127 @@ +function [FunctionName,InArg,NInArg,NOutArg] = AST_ParseOperStruct(FileInfo,SharedInfo) +// function [FunctionName,InArg,NInArg,NOutArg] = AST_ParseOperStruct(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +//#RNU_RES_B +// Parses the Operation structure of the AST. +// +// Structure of Operation: +//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' +// ] +// +//#RNU_RES_E +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Reading AST***',ReportFileName,'file','y'); + +global SCI2CSTACK +global StackPosition; +global STACKDEDUG +// --------------------------- +// --- End Initialization. --- +// --------------------------- + + +// ------------------------------ +// --- Extract function name. --- +// ------------------------------ +buffstring = AST_PopASTStack(); +LabelFunctName = 'Operator: '; +FunctionName = stripblanks(part(buffstring,length(LabelFunctName)+1:length(buffstring))); +// Generate the proper function name. +FunctionName = Operator2FunName(FunctionName); + +// ------------------------------ +// --- Read input parameters. --- +// ------------------------------ +RhsField = AST_PopASTStack(); +NInArg = 0; +while (RhsField ~= 'Operands:') + NInArg = NInArg + 1; + [InputArgumentNames(NInArg),InputArgumentScope(NInArg)] = AST_ExtractNameAndScope(RhsField); + RhsField = AST_PopASTStack(); + if (RhsField == 'Operation') + error(9999, 'Found Operation before Rhs'); + end +end + +if (stripblanks(InputArgumentNames(NInArg)) == '<empty>') + //NUT: forse non serve per l'operation + NInArg = 0; + InputArgumentNames = []; + InputArgumentScope = []; +end +InputArgumentNames = SCI2Cflipud(InputArgumentNames); +InputArgumentScope = SCI2Cflipud(InputArgumentScope); + +//#RNU_RES_B +// Remove tag "Operation" from the stack. +//#RNU_RES_E +OperationField = AST_PopASTStack(); +if (OperationField ~= 'Operation') then + error(9999, 'Problems with Operation, Expected Operation tag.'); +end + +// -------------------------------------------- +// --- Extract number of output parameters. --- +// -------------------------------------------- +if (FunctionName == 'ins') + NOutArg = 0; // It is always 1. Double check it! +else + NOutArg = 1; // It is always 1. Double check it! +end +// ------------------------------------- +// --- Generate the InArg structure. --- +// ------------------------------------- +InArg = []; +for counterinputargs = 1:NInArg + InArg(counterinputargs).Name=InputArgumentNames(counterinputargs); + InArg(counterinputargs).Scope=InputArgumentScope(counterinputargs); +end + +//#RNU_RES_B +PrintStringInfo('Operation Name: '+FunctionName,ReportFileName,'file','y'); +PrintStringInfo('N Intput Arguments: '+string(NInArg),ReportFileName,'file','y'); +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'); + PrintStringInfo(' Scope: '+InArg(counterinputargs).Scope,... + ReportFileName,'file','y'); + //#RNU_RES_E +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_PopASTStack.sci b/2.3-1/macros/ASTManagement/AST_PopASTStack.sci new file mode 100644 index 00000000..34857499 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_PopASTStack.sci @@ -0,0 +1,40 @@ +function stackelement = AST_PopASTStack() +// function stackelement = AST_PopASTStack() +// ----------------------------------------------------------------- +// Pop the AST stack. +// +// Input data: +// --- +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Aug-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),0,0); + +global SCI2CSTACK; +global StackPosition; +global STACKDEDUG; + +if StackPosition == 1 + error(9999, 'Stack empty. Cannot pop from stack.'); +end + +stackelement = SCI2CSTACK(StackPosition,1); +SCI2CSTACK = SCI2CSTACK(1:StackPosition-1); +StackPosition = StackPosition - 1; + +if (STACKDEDUG == 1) + AST_DisplayStack(); +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_PushASTStack.sci b/2.3-1/macros/ASTManagement/AST_PushASTStack.sci new file mode 100644 index 00000000..34cd883b --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_PushASTStack.sci @@ -0,0 +1,36 @@ +function AST_PushASTStack(stackelement) +// function AST_PushASTStack(stackelement) +// ----------------------------------------------------------------- +// Push the AST stack. +// +// Input data: +// --- +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Aug-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),1,1); + + +global SCI2CSTACK +global StackPosition; +global STACKDEDUG + +StackPosition = StackPosition + 1; +SCI2CSTACK(StackPosition,1) = stackelement; + +if (STACKDEDUG == 1) + AST_DisplayStack(); +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_ReadASTHeader.sci b/2.3-1/macros/ASTManagement/AST_ReadASTHeader.sci new file mode 100644 index 00000000..7a52b1f2 --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_ReadASTHeader.sci @@ -0,0 +1,90 @@ +function ASTHeader = AST_ReadASTHeader(fidAST,ReportFileName) +// function ASTHeader = AST_ReadASTHeader(fidAST,ReportFileName) +// ----------------------------------------------------------------- +// Reads the AST header +// txt=['Program' +// 'Name : '+p.name +// 'Outputs: '+strcat(objectlist2string(p.outputs),' ') +// 'Inputs : '+strcat(objectlist2string(p.inputs),' ') +// 'Statements ' +// +// Input data: +// //NUT: add description here +// +// +// Output data: +// //NUT: add description here +// +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + + +ASTHeader = []; + +tline = mgetl(fidAST,1); +AST_CheckLineLength(tline); +treeline = stripblanks(tline); +if STACKDEDUG == 1 + disp('Read AST Line: '+treeline); +end +if (SCI2Cstrncmps1size('Program',treeline) == %F) + error(9999, 'Expected ""Program"" label in the AST'); +end + +tline = mgetl(fidAST,1); +AST_CheckLineLength(tline); +treeline = stripblanks(tline); +if STACKDEDUG == 1 + disp('Read AST Line: '+treeline); +end +if (SCI2Cstrncmps1size('Name : ',treeline) == %F) + error(9999, 'Expected ""Name : "" label in the AST'); +else + ASTHeader.Name = stripblanks(part(treeline,length('Name : ')+1:length(treeline))); +end + +tline = mgetl(fidAST,1); +AST_CheckLineLength(tline); +treeline = stripblanks(tline); +if STACKDEDUG == 1 + disp('Read AST Line: '+treeline); +end +if (SCI2Cstrncmps1size('Outputs: ',treeline) == %F) + error(9999, 'Expected ""Outputs: "" label in the AST'); +else + ASTHeader.Outputs = stripblanks(part(treeline,length('Outputs: ')+1:length(treeline))); +end + +tline = mgetl(fidAST,1); +AST_CheckLineLength(tline); +treeline = stripblanks(tline); +if STACKDEDUG == 1 + disp('Read AST Line: '+treeline); +end +if (SCI2Cstrncmps1size('Inputs : ',treeline) == %F) + error(9999, 'Expected ""Inputs : "" label in the AST'); +else + ASTHeader.Inputs = stripblanks(part(treeline,length('Inputs : ')+1:length(treeline))); +end + +tline = mgetl(fidAST,1); +AST_CheckLineLength(tline); +treeline = stripblanks(tline); +if STACKDEDUG == 1 + disp('Read AST Line: '+treeline); +end +if (SCI2Cstrncmps1size('Statements ',treeline) == %F) + error(9999, 'Expected ""Statements "" label in the AST'); +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/AST_ReadEqualRhsNames.sci b/2.3-1/macros/ASTManagement/AST_ReadEqualRhsNames.sci new file mode 100644 index 00000000..96ec3ebe --- /dev/null +++ b/2.3-1/macros/ASTManagement/AST_ReadEqualRhsNames.sci @@ -0,0 +1,61 @@ +function [RhsNames,RhsScope,NRhs] = AST_ReadEqualRhsNames(FileInfo,SharedInfo) +// function [RhsNames,RhsScope,NRhs] = AST_ReadEqualRhsNames(FileInfo,SharedInfo) +// ----------------------------------------------------------------- +// //NUT: add description here +// +// Input data: +// //NUT: add description here +// +// Output data: +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),2,2); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; + +global SCI2CSTACK +global StackPosition; +global STACKDEDUG + +//#RNU_RES_B +PrintStringInfo(' ',ReportFileName,'file','y'); +PrintStringInfo('***Reading Equal Rhs Names***',ReportFileName,'file','y'); +//#RNU_RES_E + +// ------------------------------- +// --- Read Output parameters. --- +// ------------------------------- +cntpop = 1; +NRhs = 0; +RhsField(cntpop) = AST_PopASTStack(); +RhsNames = []; +while (RhsField(cntpop) ~= 'Expression:') + NRhs = NRhs + 1; + [RhsNames(NRhs),RhsScope(NRhs)] = AST_ExtractNameAndScope(RhsField(cntpop)); + cntpop = cntpop + 1; + RhsField(cntpop) = AST_PopASTStack(); +end +RhsNames = SCI2Cflipud(RhsNames); +RhsScope = SCI2Cflipud(RhsScope); + +// --- Repush everything into the stack. --- +for cntpush = cntpop:-1:1 + AST_PushASTStack(RhsField(cntpush)); +end + +endfunction diff --git a/2.3-1/macros/ASTManagement/GenOutArgNames.sci b/2.3-1/macros/ASTManagement/GenOutArgNames.sci new file mode 100644 index 00000000..0e683835 --- /dev/null +++ b/2.3-1/macros/ASTManagement/GenOutArgNames.sci @@ -0,0 +1,89 @@ +function [OutArg,SharedInfo] = GenOutArgNames(FunctionName,InArg,NInArg,OldOutArg,NOutArg,LhsArg,NLhsArg,FileInfo,SharedInfo) +// function [OutArg,SharedInfo] = GenOutArgNames(FunctionName,OutArg,NOutArg,LhsArg,NLhsArg,FileInfo,SharedInfo) +// ----------------------------------------------------------------- +//#RNU_RES_B +// Generate the names for the temporary variables that store the +// output arguments. +//#RNU_RES_E +// +// Input data: +// //NUT: add description here +// +// Output data: +// OutArg: is the Output arguments structure containing the field +// name that specifies the output argument names. +// //NUT: add description here +// +// Status: +// 11-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +// ------------------------------ +// --- Check input arguments. --- +// ------------------------------ +SCI2CNInArgCheck(argn(2),9,9); + +// ----------------------- +// --- Initialization. --- +// ----------------------- +nxtscifunname = SharedInfo.NextSCIFunName; +nxtscifunnumber = SharedInfo.NextSCIFunNumber; +ReportFileName = FileInfo.Funct(nxtscifunnumber).ReportFileName; +// #RNU_RES_B +PrintStringInfo(' Generating Out Arg names.',ReportFileName,'file','y'); +// #RNU_RES_E +OutArg = OldOutArg; + +//#RNU_RES_B +// --------------------------------------------------------------------------------------- +// --- Generate the names for the temporary variables that store the output arguments. --- +// --------------------------------------------------------------------------------------- +// 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 +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 + +endfunction diff --git a/2.3-1/macros/ASTManagement/Operator2FunName.sci b/2.3-1/macros/ASTManagement/Operator2FunName.sci new file mode 100644 index 00000000..1aa934cb --- /dev/null +++ b/2.3-1/macros/ASTManagement/Operator2FunName.sci @@ -0,0 +1,119 @@ +function FunName = Operator2FunName(OperatorName); +// -----------------------------------------------------------------
+// Returns the function name corresponding to the input operator.
+// From intmacr2tree.c we have:
+// char *operators[]={"+","-","*",".*","*.",".*.","/","./","/.","./.",
+// "\\",".\\","\\.",".\\.","^","==","<",">","<=",">=","~=",
+// ":","rc","ins","ext","'","cc","|","&","~",".^",".'","cceol"};
+// I also added "<>".
+//
+// Input data:
+// //NUT: add description here
+//
+// Output data:
+// //NUT: add description here
+//
+// Status:
+// 29-May-2007 -- Nutricato Raffaele: Changed code into a function.
+//
+// Copyright 2007 Raffaele Nutricato.
+// Contact: raffaele.nutricato@tiscali.it
+// -----------------------------------------------------------------
+
+//NUT: non e' inserito il "\" verifica come mai.
+//NUT: il ".\" l'ho inserito io
+ +// ------------------------------
+// --- Check input arguments. ---
+// ------------------------------
+SCI2CNInArgCheck(argn(2),1,1);
+
+FuncPrefix = 'Op';
+FuncSuffix = '';
+
+if (OperatorName == '+')
+ FunName = FuncPrefix+'Plus'+FuncSuffix;
+elseif (OperatorName == '-')
+ FunName = FuncPrefix+'Minus'+FuncSuffix;
+elseif (OperatorName == '*')
+ FunName = FuncPrefix+'Star'+FuncSuffix;
+elseif (OperatorName == '.*')
+ FunName = FuncPrefix+'DotStar'+FuncSuffix;
+elseif (OperatorName == '*.')
+ PrintStringInfo('SCI2CERROR: Operator ""'+OperatorName+'"" not supported.','','stout','y');
+ error(9999, 'SCI2CERROR: Operator ""'+OperatorName+'"" not supported.');
+elseif (OperatorName == '.*.')
+ PrintStringInfo('SCI2CERROR: Operator ""'+OperatorName+'"" not supported.','','stout','y');
+ error(9999, 'SCI2CERROR: Operator ""'+OperatorName+'"" not supported.');
+elseif (OperatorName == '/')
+ FunName = FuncPrefix+'Slash'+FuncSuffix;
+elseif (OperatorName == './')
+ FunName = FuncPrefix+'DotSlash'+FuncSuffix;
+elseif (OperatorName == '/.')
+ PrintStringInfo('SCI2CERROR: Operator ""'+OperatorName+'"" not supported.','','stout','y');
+ error(9999, 'SCI2CERROR: Operator ""'+OperatorName+'"" not supported.');
+elseif (OperatorName == './.')
+ PrintStringInfo('SCI2CERROR: Operator ""'+OperatorName+'"" not supported.','','stout','y');
+ error(9999, 'SCI2CERROR: Operator ""'+OperatorName+'"" not supported.');
+elseif (OperatorName == '.\')
+ FunName = FuncPrefix+'DotBackSlash'+FuncSuffix;
+elseif (OperatorName == '\')
+ //PrintStringInfo('SCI2CERROR: Operator ""'+OperatorName+'"" not supported.','','stout','y');
+ //SCI2Cerror(' '); + FunName = FuncPrefix+'BackSlash'+FuncSuffix;
+elseif (OperatorName == '.\')
+ PrintStringInfo('SCI2CERROR: Operator ""'+OperatorName+'"" not supported.','','stout','y');
+ error(9999, 'SCI2CERROR: Operator ""'+OperatorName+'"" not supported.');
+elseif (OperatorName == '\.')
+ PrintStringInfo('SCI2CERROR: Operator ""'+OperatorName+'"" not supported.','','stout','y');
+ error(9999, 'SCI2CERROR: Operator ""'+OperatorName+'"" not supported.');
+elseif (OperatorName == '.\.')
+ PrintStringInfo('SCI2CERROR: Operator ""'+OperatorName+'"" not supported.','','stout','y');
+ error(9999, 'SCI2CERROR: Operator ""'+OperatorName+'"" not supported.');
+elseif (OperatorName == '^')
+ FunName = FuncPrefix+'Hat'+FuncSuffix;
+elseif (OperatorName == '.^')
+ FunName = FuncPrefix+'DotHat'+FuncSuffix;
+elseif (OperatorName == '''')
+ FunName = FuncPrefix+'Apex'+FuncSuffix;
+elseif (OperatorName == '.''')
+ FunName = FuncPrefix+'DotApex'+FuncSuffix;
+elseif (OperatorName == '==')
+ FunName = FuncPrefix+'LogEq'+FuncSuffix;
+elseif (OperatorName == '<')
+ FunName = FuncPrefix+'LogLt'+FuncSuffix;
+elseif (OperatorName == '>')
+ FunName = FuncPrefix+'LogGt'+FuncSuffix;
+elseif (OperatorName == '<=')
+ FunName = FuncPrefix+'LogLe'+FuncSuffix;
+elseif (OperatorName == '>=')
+ FunName = FuncPrefix+'LogGe'+FuncSuffix;
+elseif (OperatorName == '~=')
+ FunName = FuncPrefix+'LogNe'+FuncSuffix;
+elseif (OperatorName == '<>')
+ FunName = FuncPrefix+'LogNe'+FuncSuffix;
+elseif (OperatorName == '|')
+ FunName = FuncPrefix+'LogOr'+FuncSuffix;
+elseif (OperatorName == '&')
+ FunName = FuncPrefix+'LogAnd'+FuncSuffix;
+elseif (OperatorName == '~')
+ FunName = FuncPrefix+'LogNot'+FuncSuffix;
+elseif (OperatorName == ':')
+ FunName = FuncPrefix+'Colon'+FuncSuffix;
+elseif (OperatorName == 'rc')
+ FunName = 'OpRc';
+elseif (OperatorName == 'cc')
+ FunName = 'OpCc';
+elseif (OperatorName == 'ins')
+ FunName = 'OpIns';
+elseif (OperatorName == 'ext')
+ FunName = 'OpExt';
+elseif (OperatorName == 'cceol')
+ PrintStringInfo('SCI2CERROR: Operator ""'+OperatorName+'"" not supported.','','stout','y');
+ error(9999, 'SCI2CERROR: Operator ""'+OperatorName+'"" not supported.');
+else
+ PrintStringInfo('SCI2CERROR: Unknown Operator ""'+OperatorName+'.','','stout','y');
+ error(9999, 'SCI2CERROR: Unknown Operator ""'+OperatorName+'.');
+end
+
+endfunction
diff --git a/2.3-1/macros/ASTManagement/SciFile2ASTFile.sci b/2.3-1/macros/ASTManagement/SciFile2ASTFile.sci new file mode 100644 index 00000000..be978c57 --- /dev/null +++ b/2.3-1/macros/ASTManagement/SciFile2ASTFile.sci @@ -0,0 +1,36 @@ +function SciFile2ASTFile(SciFile,ASTFile); +// function SciFile2ASTFile(SciFile,ASTFile); +// ----------------------------------------------------------------- +// This function makes use of the macr2tree function to generate +// the ASTFile containing the AST (Abstract Syntactic Tree) of the +// input Scilab function (SciFile). +// +// Input data: +// SciFile: full path of the input function. +// ASTFile: full path of the file that will store the AST. +// +// Output data: +// --- +// +// Status: +// 12-Apr-2007 -- Raffaele Nutricato: Author. +// +// Copyright 2007 Raffaele Nutricato. +// Contact: raffaele.nutricato@tiscali.it +// ----------------------------------------------------------------- + +exec(SciFile); +[tmppath,ScilabFunName,tmpext] = fileparts(SciFile); +AST=eval('macr2tree('+ScilabFunName+')'); + + +[ASTx,ASTierr]=fileinfo(ASTFile); +if ASTierr == 0 + mdelete(ASTFile); +end + +fd = mopen(ASTFile, "wt"); +mputl(string(AST), fd); +mclose(fd); + +endfunction diff --git a/2.3-1/macros/ASTManagement/_comment_string.sci b/2.3-1/macros/ASTManagement/_comment_string.sci new file mode 100644 index 00000000..a963507d --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/_cste_string.sci b/2.3-1/macros/ASTManagement/_cste_string.sci new file mode 100644 index 00000000..ba9971d2 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/_equal_string.sci b/2.3-1/macros/ASTManagement/_equal_string.sci new file mode 100644 index 00000000..9678f0e0 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/_for_string.sci b/2.3-1/macros/ASTManagement/_for_string.sci new file mode 100644 index 00000000..0ed9ca28 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/_funcall_string.sci b/2.3-1/macros/ASTManagement/_funcall_string.sci new file mode 100644 index 00000000..faeb81d9 --- /dev/null +++ b/2.3-1/macros/ASTManagement/_funcall_string.sci @@ -0,0 +1,15 @@ +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 + +txt=['Funcall : '+F.name + ' #lhs : '+string(F.lhsnb) + ' Rhs : ' + ' '+objectlist2string(F.rhs) + 'EndFuncall' + ] +endfunction diff --git a/2.3-1/macros/ASTManagement/_ifthenel_string.sci b/2.3-1/macros/ASTManagement/_ifthenel_string.sci new file mode 100644 index 00000000..6787a87c --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/_ifthenelse_string.sci b/2.3-1/macros/ASTManagement/_ifthenelse_string.sci new file mode 100644 index 00000000..ef588c56 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/_operatio_string.sci b/2.3-1/macros/ASTManagement/_operatio_string.sci new file mode 100644 index 00000000..8421a3f4 --- /dev/null +++ b/2.3-1/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
\ No newline at end of file diff --git a/2.3-1/macros/ASTManagement/_operation_string.sci b/2.3-1/macros/ASTManagement/_operation_string.sci new file mode 100644 index 00000000..84f5ce3c --- /dev/null +++ b/2.3-1/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
\ No newline at end of file diff --git a/2.3-1/macros/ASTManagement/_program_p.sci b/2.3-1/macros/ASTManagement/_program_p.sci new file mode 100644 index 00000000..f45ed69a --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/_program_string.sci b/2.3-1/macros/ASTManagement/_program_string.sci new file mode 100644 index 00000000..93486992 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/_variable_string.sci b/2.3-1/macros/ASTManagement/_variable_string.sci new file mode 100644 index 00000000..86507957 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/_while_string.sci b/2.3-1/macros/ASTManagement/_while_string.sci new file mode 100644 index 00000000..7d5e6223 --- /dev/null +++ b/2.3-1/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/2.3-1/macros/ASTManagement/buildmacros.sce b/2.3-1/macros/ASTManagement/buildmacros.sce new file mode 100644 index 00000000..60fd2843 --- /dev/null +++ b/2.3-1/macros/ASTManagement/buildmacros.sce @@ -0,0 +1,15 @@ +// +// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +// Copyright (C) 2009-2009 - DIGITEO - Bruno JOFRET +// +// 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 +// +// + +tbx_build_macros(TOOLBOX_NAME, get_absolute_file_path('buildmacros.sce')); + +clear tbx_build_macros; diff --git a/2.3-1/macros/ASTManagement/lib b/2.3-1/macros/ASTManagement/lib Binary files differnew file mode 100644 index 00000000..5d98a03d --- /dev/null +++ b/2.3-1/macros/ASTManagement/lib diff --git a/2.3-1/macros/ASTManagement/names b/2.3-1/macros/ASTManagement/names new file mode 100644 index 00000000..a1aafbc1 --- /dev/null +++ b/2.3-1/macros/ASTManagement/names @@ -0,0 +1,59 @@ +%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_HandleEOL +AST_HandleEndFor +AST_HandleEndGenFun +AST_HandleEndProgram +AST_HandleEndWhile +AST_HandleFor +AST_HandleForStatem +AST_HandleHeader +AST_HandleIfElse +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 diff --git a/2.3-1/macros/ASTManagement/objectlist2string.sci b/2.3-1/macros/ASTManagement/objectlist2string.sci new file mode 100644 index 00000000..26a38962 --- /dev/null +++ b/2.3-1/macros/ASTManagement/objectlist2string.sci @@ -0,0 +1,13 @@ +function txt=objectlist2string(L) +//auxiliary function for conversion of a list of objects +//into a string vector + txt=[]; + for o=L, + if type(o)==15 then //EOL case + txt=[txt;'<'+o(1)+'>'], + else + txt=[txt; string(o)], + end + end + if txt==[] then txt='<empty>',end +endfunction |