summaryrefslogtreecommitdiff
path: root/modules/string/macros/tree2code.sci
diff options
context:
space:
mode:
authorShashank2017-05-29 12:40:26 +0530
committerShashank2017-05-29 12:40:26 +0530
commit0345245e860375a32c9a437c4a9d9cae807134e9 (patch)
treead51ecbfa7bcd3cc5f09834f1bb8c08feaa526a4 /modules/string/macros/tree2code.sci
downloadscilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.gz
scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.bz2
scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.zip
CMSCOPE changed
Diffstat (limited to 'modules/string/macros/tree2code.sci')
-rwxr-xr-xmodules/string/macros/tree2code.sci71
1 files changed, 71 insertions, 0 deletions
diff --git a/modules/string/macros/tree2code.sci b/modules/string/macros/tree2code.sci
new file mode 100755
index 000000000..776924c20
--- /dev/null
+++ b/modules/string/macros/tree2code.sci
@@ -0,0 +1,71 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA - Vincent Couvert
+//
+// 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.1-en.txt
+
+
+function C=tree2code(P,bprettyprintformat)
+ // Convert a tree returned by macr2tree() to a macro code
+ // Input:
+ // - P: 'program' tlist
+ // - bprettyprintformat: boolean value, if FALSE (default value), generated code is not formated else it is
+ // Output:
+ // - C: character string matrix (colum vector)
+
+ // Verify good type for input
+ if typeof(P)<>"program" then
+ error(msprintf(gettext("%s: Wrong type for input argument #%d: ''%s'' expected.\n"),"tree2code",2,"program tree"));
+ end
+
+ // Default value
+ rhs = argn(2);
+ if rhs==1 then
+ bprettyprintformat=%F
+ end
+
+ C=""
+
+ // Function prototype
+ lhsstr=[]
+ rhsstr=[]
+ if P.name<>"" then // Not a batch file
+ for k=1:size(P.outputs)
+ lhsstr=[lhsstr,expression2code(P.outputs(k))]
+ end
+ lhsstr="["+strcat(lhsstr,",")+"]"
+
+ for k=1:size(P.inputs)
+ rhsstr=[rhsstr,expression2code(P.inputs(k))]
+ end
+ rhsstr="("+strcat(rhsstr,",")+")"
+
+ C="function "+lhsstr+" = "+P.name+rhsstr;
+ end
+
+ I=P.statements
+
+ // To avoid to have some instructions on the first line (function prototype)
+ if I(1)<>list("EOL") then
+ C=cat_code(C,instruction2code(list("EOL"),%T));
+ end
+
+ // For each statement, generate corresponding code
+ for i=1:size(I)-2 // -2 to ignore last return+EOL
+ if bprettyprintformat then
+ C=cat_code(C," "+instruction2code(I(i),bprettyprintformat));
+ else
+ C=cat_code(C,instruction2code(I(i),bprettyprintformat));
+ end
+ C = format_txt(C,I(i),bprettyprintformat,I(i+1));
+ end
+
+ if P.name<>"" then // Not a batch file
+ C=cat_code(C,"endfunction"); // Replace last return
+ C=cat_code(C,"");
+ end
+endfunction
+