gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
transf-min goto typo
[mjc2wsl.git] / src-wsl / transf-stack.wsl
1 C:"
2 Copyright (C) 2015 Doni Pracner http://perun.dmi.rs/pracner
4 This program is free software; you can redistribute it
5 and/or modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later
8 version.
10 This program is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied
12 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU General Public License for more
14 details.
16 You should have received a copy of the GNU General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19 ==========================================================";
21 C:"This version was used for some experiments with stacks.
23 It is left in here as an example of how some transformations
24 can be applied.";
25 MW_PROC @Process_Prog() ==
27 had_trans := 1;
28 WHILE had_trans > 0 DO
30 had_trans := 0;
32 C:"start of the program";
33 @Goto(< >);
34 C:"'manual' navigating to find the procedures";
35 DO IF @Spec_Type(@Item) = T_Proc THEN
36 IF @Trans?(TR_Stack_To_Par) THEN
37 had_trans := 1; PRINT("----- STACK TO PAR -------"); @Trans(TR_Stack_To_Par, "") FI; FI;
38 IF @Down? THEN @Down
39 ELSIF @Right? THEN @Right
40 ELSIF @Up?
41 THEN @Up; WHILE @Up? AND NOT @Right? DO @Up OD;
42 IF @Right? THEN @Right ELSE EXIT(1) FI
43 ELSE EXIT(1) FI OD
44 ;
46 ATEACH Statement DO
47 IF @Trans?(TR_Stack_To_Var) THEN
48 had_trans := 1; PRINT("----- STACK TO VAR -------"); @Trans(TR_Stack_To_Var,"")
49 FI
50 OD
51 OD;
52 SKIP
53 END;
55 C:"Here are some pieces that are not used, but could be
56 useful in some experiments later";
57 MW_PROC @Not_Used() ==
58 @Goto(< >);
59 IF @Trans?(TR_Remove_Redundant_Vars) THEN
60 @Trans(TR_Remove_Redundant_Vars,"") FI;
61 SKIP
62 END;
64 C:"----------------------------------------";
66 C:"The rest of the code is loaders and similar procedures,
67 very similar to other transf programs.";
69 MW_PROC @Process_File(filename) ==
70 IF @File_Exists?(filename) THEN
71 @New_Program(@Parse_File(filename, T_Statements));
72 PRINT("Processing: ", filename);
73 prog := @Program;
74 @Process_Prog();
75 @Get_New_Name(VAR filename);
76 @PP_Item(@Program, 80, filename);
77 PRINT("<Metrics>");
78 PRINT(filename);
79 @Prog_Stat_Comp(prog, @Program);
80 PRINT("</Metrics>")
81 ELSE
82 PRINT("ERROR: File ",filename," not found");
83 FI
84 END;
86 MW_PROC @Get_New_Name(VAR str) ==
87 IF @Ends_With?(str, ".wsl") THEN
88 str := SUBSTR(str, 0, SLENGTH(str)-4)
89 FI;
90 str := str ++ "_t.wsl"
91 END;
93 MW_PROC @Prog_Stat_Comp(Pro, After VAR)==
94 VAR < ma := 0, mb :=1 > :
95 ma := @McCabe(Pro);
96 mb := @McCabe(After);
97 PRINT ("McCabe ", ma, " ", mb, " ",(mb-ma));
98 ma := @Stat_Count(Pro);
99 mb := @Stat_Count(After);
100 PRINT ("Statem ", ma, " ",mb, " ",(mb-ma));
101 ma := @CFDF_Metric(Pro);
102 mb := @CFDF_Metric(After);
103 PRINT ("CF/DF ", ma," ", mb," ", (mb-ma));
104 ma := @Total_Size(Pro);
105 mb := @Total_Size(After);
106 PRINT ("Size ", ma," ", mb, " ",(mb-ma));
107 ma := @Struct_Metric(Pro);
108 mb := @Struct_Metric(After);
109 PRINT ("Struct ", ma, " ",mb, " ",(mb-ma));
110 SKIP
111 ENDVAR
112 END;
114 VAR< prog := < >, inifilename := "transf.ini",
115 filename:="", file := "", inifile:= "",
116 Argv := @Argv
117 >:
118 C:"First one is the script name that is being executed";
119 Argv := TAIL(Argv);
121 IF Argv = < > THEN
122 PRINT("no arguments passed; using ",inifilename);
123 IF @File_Exists?(inifilename) THEN
124 inifile := @Open_Input_File(inifilename);
125 filename := @Read_Line(inifile);
126 WHILE NOT @EOF?(filename) DO
127 PRINT("");
128 @Process_File(filename);
129 filename := @Read_Line(inifile)
130 OD;
131 @Close_Input_Port(inifile);
132 ELSE
133 PRINT("ini file (",inifilename,") not found.",
134 " it should contain a list of filenames to be converted");
135 PRINT("OR you can give command line arguments to be processed");
136 FI
137 ELSE
138 FOR arg IN Argv DO
139 @Process_File(arg);
140 OD
141 FI
142 ENDVAR
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner