refactoring

This commit is contained in:
Lucas 2024-07-05 13:24:48 +02:00
parent c6e61defce
commit ebef717141
3 changed files with 21 additions and 13 deletions

View File

@ -29,6 +29,10 @@ import java.util.logging.*;
* <code>consoleHandler.setLevel(Level.OFF);</code>
* <code>fileHandler.setLevel(Level.ALL);</code>
*/
public class MiniCompilerLogger {
static Logger logger = Logger.getLogger("miniCompilerLogs");
@ -66,14 +70,16 @@ public class MiniCompilerLogger {
logger.addHandler(consoleHandler);
// Configure file handler
//Handler fileHandler = new FileHandler("src/main/resources/logs/miniCompiler.log");
Handler fileHandler = new FileHandler("src/main/resources/logs/miniCompiler.log");
// Toggle file logging on/off
//fileHandler.setLevel(Level.ALL);
//fileHandler.setFormatter(new CustomFormatter());
//logger.addHandler(fileHandler);
fileHandler.setLevel(Level.ALL);
fileHandler.setFormatter(new CustomFormatter());
logger.addHandler(fileHandler);
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@ -102,7 +108,7 @@ public class MiniCompilerLogger {
public static void logAST(ASTNode abstractSyntaxTree) {
// Printing the AST
logger.info("-------------------- AST builder -> AST --------------------");
// logger.info("AST: " + ast.toString());
logger.info("Abstract Syntax Tree generated, Startnode:");
logAST(abstractSyntaxTree, 0);
logger.info("\n");
}
@ -110,14 +116,15 @@ public class MiniCompilerLogger {
public static void logSemanticAnalyzer(ASTNode typedAst) {
// Printing the typed AST
logger.info("-------------------- Semantic Analyzer -> typed AST --------------------");
logAST(typedAst, 0);
// logAST(typedAst, 0);
logger.info("Typed Abstract Syntax Tree generated without errors");
logger.info("\n");
}
public static void logBytecodeGenerator() {
// Printing the bytecode
logger.info("-------------------- Bytecode Generator -> Bytecode --------------------");
logger.info("Bytecode generated without errors.");
logger.info("Bytecode generated without errors");
logger.info("\n");
}
@ -164,7 +171,6 @@ public class MiniCompilerLogger {
}
}
// TODO: Fix this method
public static void logAST(ASTNode abstractSyntaxTree, int indent) {
if (abstractSyntaxTree == null) {
logger.severe("AST is null !!!");
@ -172,9 +178,9 @@ public class MiniCompilerLogger {
}
String indentString = " ".repeat(indent * 2);
logger.info(indentString + abstractSyntaxTree.getClass());
//for (ASTNode child : abstractSyntaxTree.getChildren()) {
// for (ASTNode child : abstractSyntaxTree.getChildren()) {
// logAST(child, indent + 1);
// }
// }
}
}

View File

@ -10,11 +10,13 @@ compile-javac:
compile-miniCompiler:
cd ../.. ; mvn -DskipTests install
cd ../.. ; mvn exec:java -DgenJar=true -DgenClass=true -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'"
# cp ../main/resources/output/CompilerInput.class .java/resources/output/miniCompiler
# cp ../main/resources/output/*.class .java/resources/output/miniCompiler
test: compile-miniCompiler test-miniCompiler
test-miniCompiler:
# move the compiled class to the test/main folder
mv ../main/resources/output/CompilerInput.class .java/main/
mv ../main/resources/output/Compiler.class .java/
# compile the test class
javac .java/main.EndToEndTester.java
# run the test class

View File

@ -16,7 +16,7 @@ public class EndToEndTester {
public static void main(String[] args) {
try {
// Try to load the class named "CompilerInput"
Class<?> cls = Class.forName("CompilerInput");
Class<?> cls = Class.forName("Compiler");
// Print a success message if the class is loaded successfully
System.out.println("Class loaded successfully: " + cls.getName());