2323import dev .askov .mjcompiler .inheritancetree .InheritanceTree ;
2424import dev .askov .mjcompiler .inheritancetree .visitor .InheritanceTreePrinter ;
2525import dev .askov .mjcompiler .mjsymboltable .MJTab ;
26- import dev .askov .mjcompiler .util .Log4JUtils ;
2726import dev .askov .mjcompiler .vmt .VMTCodeGenerator ;
2827import dev .askov .mjcompiler .vmt .VMTCreator ;
2928import dev .askov .mjcompiler .vmt .VMTStartAddressGenerator ;
3029import java .io .BufferedReader ;
3130import java .io .File ;
3231import java .io .FileOutputStream ;
3332import java .io .FileReader ;
34- import org .apache . log4j .Logger ;
35- import org .apache . log4j . xml . DOMConfigurator ;
33+ import org .slf4j .Logger ;
34+ import org .slf4j . LoggerFactory ;
3635import rs .etf .pp1 .mj .runtime .Code ;
3736
3837/**
3938 * @author Danijel Askov
4039 */
4140public class MJCompiler {
4241
43- static {
44- DOMConfigurator .configure (Log4JUtils .instance ().findLoggerConfigFile ());
45- Log4JUtils .instance ().prepareLogFile (Logger .getRootLogger ());
46- }
47-
48- private static final Logger LOGGER = Logger .getLogger (MJCompiler .class );
42+ private static final Logger LOGGER = LoggerFactory .getLogger (MJCompiler .class );
4943
5044 public static void tsdump () {
5145 MJTab .dump (LOGGER );
@@ -58,22 +52,21 @@ public static void main(String[] args) throws Exception {
5852 }
5953 var sourceFile = new File (args [0 ]);
6054 if (!sourceFile .exists ()) {
61- LOGGER .error ("Source file \" " + sourceFile . getAbsolutePath () + " \" has not been found!" );
55+ LOGGER .error ("Source file \" {} \" has not been found!" , sourceFile . getAbsolutePath () );
6256 return ;
6357 }
64- LOGGER .info ("Compiling source file \" " + sourceFile .getAbsolutePath () + " \" ..." );
58+ LOGGER .info ("Compiling source file \" {} \" ..." , sourceFile .getAbsolutePath ());
6559 try (var br = new BufferedReader (new FileReader (sourceFile ))) {
6660 var lexer = new MJLexer (br );
6761 var parser = new MJParser (lexer );
6862 var symbol = parser .parse ();
6963
7064 if (!parser .lexicalErrorDetected () && !parser .syntaxErrorDetected ()) {
71- LOGGER .info (
72- "No syntax errors have been detected in \" " + sourceFile .getAbsolutePath () + "\" " );
65+ LOGGER .info ("No syntax errors have been detected in \" {}\" " , sourceFile .getAbsolutePath ());
7366
7467 var program = (Program ) symbol .value ;
7568
76- LOGGER .info ("Abstract syntax tree:\n " + program .toString ("" ));
69+ LOGGER .info ("Abstract syntax tree:\n {}" , program .toString ("" ));
7770
7871 MJTab .init ();
7972 var semanticAnalyzer = new SemanticAnalyzer ();
@@ -94,18 +87,17 @@ public static void main(String[] args) throws Exception {
9487 semanticAnalyzer .getStaticVarsCount () + vmtStartAddressGenerator .getTotalVMTSize ();
9588
9689 LOGGER .info (
97- "No semantic errors have been detected in \" " + sourceFile .getAbsolutePath () + " \" " );
90+ "No semantic errors have been detected in \" {} \" " , sourceFile .getAbsolutePath ());
9891
9992 var objFile = new File (args [1 ]);
100- LOGGER .info ("Generating bytecode file \" " + objFile .getAbsolutePath () + " \" ..." );
93+ LOGGER .info ("Generating bytecode file \" {} \" ..." , objFile .getAbsolutePath ());
10194 if (objFile .exists ()) {
102- LOGGER .info ("Deleting old bytecode file \" " + objFile .getAbsolutePath () + " \" ..." );
95+ LOGGER .info ("Deleting old bytecode file \" {} \" ..." , objFile .getAbsolutePath ());
10396 if (objFile .delete ())
104- LOGGER .info (
105- "Old bytecode file \" " + objFile .getAbsolutePath () + "\" has been deleted." );
97+ LOGGER .info ("Old bytecode file \" {}\" has been deleted." , objFile .getAbsolutePath ());
10698 else
10799 LOGGER .error (
108- "Old bytecode file \" " + objFile . getAbsolutePath () + " \" has not been deleted." );
100+ "Old bytecode file \" {} \" has not been deleted." , objFile . getAbsolutePath () );
109101 }
110102
111103 var codeGenerator = new CodeGenerator ();
@@ -138,35 +130,32 @@ public static void main(String[] args) throws Exception {
138130 Code .put (Code .return_ );
139131
140132 Code .write (new FileOutputStream (objFile ));
141- LOGGER .info ("Bytecode file \" " + objFile . getAbsolutePath () + " \" has been generated." );
133+ LOGGER .info ("Bytecode file \" {} \" has been generated." , objFile . getAbsolutePath () );
142134 LOGGER .info (
143- "Compilation of source file \" "
144- + sourceFile .getAbsolutePath ()
145- + "\" has finished successfully.\n " );
135+ "Compilation of source file \" {}\" has finished successfully.\n " ,
136+ sourceFile .getAbsolutePath ());
146137
147- LOGGER .info ("Inheritance tree:\n " + inheritanceTreeNodePrinter .getOutput ());
138+ LOGGER .info ("Inheritance tree:\n {}" , inheritanceTreeNodePrinter .getOutput ());
148139 } else {
149140 LOGGER .error (
150- "Source file \" " + sourceFile . getAbsolutePath () + " \" contains semantic error(s)!" );
141+ "Source file \" {} \" contains semantic error(s)!" , sourceFile . getAbsolutePath () );
151142 LOGGER .error (
152- "Compilation of source file \" "
153- + sourceFile .getAbsolutePath ()
154- + "\" has finished unsuccessfully." );
143+ "Compilation of source file \" {}\" has finished unsuccessfully." ,
144+ sourceFile .getAbsolutePath ());
155145 }
156146
157147 } else {
158148 if (parser .lexicalErrorDetected ()) {
159149 LOGGER .error (
160- "Source file \" " + sourceFile . getAbsolutePath () + " \" contains lexical error(s)!" );
150+ "Source file \" {} \" contains lexical error(s)!" , sourceFile . getAbsolutePath () );
161151 }
162152 if (parser .syntaxErrorDetected ()) {
163153 LOGGER .error (
164- "Source file \" " + sourceFile . getAbsolutePath () + " \" contains syntax error(s)!" );
154+ "Source file \" {} \" contains syntax error(s)!" , sourceFile . getAbsolutePath () );
165155 }
166156 LOGGER .error (
167- "Compilation of source file \" "
168- + sourceFile .getAbsolutePath ()
169- + "\" has finished unsuccessfully." );
157+ "Compilation of source file \" {}\" has finished unsuccessfully." ,
158+ sourceFile .getAbsolutePath ());
170159 }
171160 }
172161 }
0 commit comments