throw exception when exception map is not empty

This commit is contained in:
simon 2024-07-04 18:13:28 +02:00
parent a259aa3a51
commit af757561bb
2 changed files with 11 additions and 10 deletions

View File

@ -70,7 +70,7 @@ public class Compiler {
return generateAST(sources); return generateAST(sources);
} }
public static TypedProgram generateTypedASTFromAst(Program ast) { public static TypedProgram generateTypedASTFromAst(Program ast) throws IllegalArgumentException {
return new TypedProgram(ast); return new TypedProgram(ast);
} }
@ -80,21 +80,22 @@ public class Compiler {
public static List<byte[]> generateByteCodeArrayFromFiles(List<String> sourcePaths) { public static List<byte[]> generateByteCodeArrayFromFiles(List<String> sourcePaths) {
Program program = generateASTFromFiles(sourcePaths); Program program = generateASTFromFiles(sourcePaths);
TypedProgram typedAST = generateTypedASTFromAst(program); TypedProgram typedAST;
typedAST = generateTypedASTFromAst(program);
List<byte[]> byteCode = new ArrayList<>(); List<byte[]> byteCode = new ArrayList<>();
if(TypedProgram.EXCEPTIONS.isEmpty()){ if (TypedProgram.EXCEPTIONS.isEmpty()) {
for (TypedClass c : typedAST.getTypedClasses()) { for (TypedClass c : typedAST.getTypedClasses()) {
byteCode.add(generateByteCodeArrayFromTypedAst(c)); byteCode.add(generateByteCodeArrayFromTypedAst(c));
} }
return byteCode; return byteCode;
}else{ } else {
return Collections.emptyList(); return Collections.emptyList();
} }
} }
public static void generateByteCodeFilesFromFiles(List<String> sourcePaths) { public static void generateByteCodeFilesFromFiles(List<String> sourcePaths) {
List<byte[]> bytes = generateByteCodeArrayFromFiles(sourcePaths); List<byte[]> bytes = generateByteCodeArrayFromFiles(sourcePaths);
if(bytes.isEmpty()){ if (bytes.isEmpty()) {
return; return;
} }
for (int i = 0; i < bytes.size(); i++) { for (int i = 0; i < bytes.size(); i++) {
@ -118,8 +119,8 @@ public class Compiler {
if (cmd.hasOption("debug")) { if (cmd.hasOption("debug")) {
Logger rootLog = Logger.getLogger(""); Logger rootLog = Logger.getLogger("");
rootLog.setLevel( Level.FINEST ); rootLog.setLevel(Level.FINEST);
rootLog.getHandlers()[0].setLevel( Level.FINEST ); rootLog.getHandlers()[0].setLevel(Level.FINEST);
Formatter logFormatter = new LogFormatter(); Formatter logFormatter = new LogFormatter();
for (Handler handler : rootLog.getHandlers()) { for (Handler handler : rootLog.getHandlers()) {
handler.setFormatter(logFormatter); handler.setFormatter(logFormatter);

View File

@ -17,11 +17,11 @@ public class TypedProgram {
public static Map<String, Exception> EXCEPTIONS = new HashMap<>(); public static Map<String, Exception> EXCEPTIONS = new HashMap<>();
private TypedClass currentClass; private TypedClass currentClass;
public TypedProgram(Program program) { public TypedProgram(Program program) throws IllegalArgumentException {
startConversion(program); startConversion(program);
} }
public void startConversion(Program program) { public void startConversion(Program program) throws IllegalArgumentException {
// Initialisiere die Klassen nur mit den Klassennamen und deren Typ // Initialisiere die Klassen nur mit den Klassennamen und deren Typ
for (var clas : program.classes()) { for (var clas : program.classes()) {
@ -61,7 +61,7 @@ public class TypedProgram {
); );
counter++; counter++;
} }
throw new RuntimeException(stringBuilder.toString()); throw new IllegalArgumentException(stringBuilder.toString());
} }
} }