diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedBlock.java b/src/main/java/de/maishai/typedast/typedclass/TypedBlock.java index 0625aeb..e2a6709 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedBlock.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedBlock.java @@ -103,12 +103,12 @@ public class TypedBlock implements TypedNode { Type chekType = null; for (TypedStatement stmt : stmts) { stmt.typeCheck(typedProgram); - if(stmt instanceof TypedReturn returnStmt) { + if (stmt instanceof TypedReturn returnStmt) { chekType = returnStmt.getType(); } } - if(chekType == null) { + if (chekType == null) { chekType = Type.VOID; } type = chekType; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedBoolLiteral.java b/src/main/java/de/maishai/typedast/typedclass/TypedBoolLiteral.java index aa8b9e6..5c62c5b 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedBoolLiteral.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedBoolLiteral.java @@ -32,9 +32,9 @@ public class TypedBoolLiteral implements TypedExpression { @Override public void codeGen(MethodContext ctx) { - if(value){ + if (value) { ctx.getMv().visitInsn(Opcodes.ICONST_1); - }else{ + } else { ctx.getMv().visitInsn(Opcodes.ICONST_0); } } diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedBreak.java b/src/main/java/de/maishai/typedast/typedclass/TypedBreak.java index 54d32c6..4ff64ee 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedBreak.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedBreak.java @@ -10,10 +10,6 @@ import lombok.Data; public class TypedBreak implements TypedStatement { private Type type = Type.VOID; - public TypedBreak convertToTypedBreak(TypedClass clas, Break unTypedBreak) { - return this; - } - @Override public Type typeCheck(TypedProgram typedProgram) { return type; diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java index 26085e1..bc61985 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedClass.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedClass.java @@ -125,6 +125,7 @@ public class TypedClass implements TypedNode { } return false; } + public Type getMethodType(String methodName) { for (TypedMethod m : typedMethods) { if (m.getName().equals(methodName)) { diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java b/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java index f8ec43a..3f18cde 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java @@ -66,6 +66,7 @@ public class TypedConstructor implements TypedNode { throw new RuntimeException("Parameter " + paraName + " already exists"); } } + public void convertToBlock(TypedProgram typedProgram, Constructor unTypedConstructor) { this.typedBlock = new TypedBlock(typedProgram, unTypedConstructor.block()); typeCheck(typedProgram); diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedDeclaration.java b/src/main/java/de/maishai/typedast/typedclass/TypedDeclaration.java index 34f5691..d653b54 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedDeclaration.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedDeclaration.java @@ -29,7 +29,7 @@ public final class TypedDeclaration implements TypedNode { @Override public Type typeCheck(TypedProgram typedProgram) { - if(type.getReference() != null && !typedProgram.getCurrentClass().getClassName().equals(type.getReference())) { + if (type.getReference() != null && !typedProgram.getCurrentClass().getClassName().equals(type.getReference())) { if (!typedProgram.isTypedClassPresent(type.getReference())) { throw new RuntimeException("Type " + type.getReference() + " not found"); } diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java b/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java index 337375b..1a404d1 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java @@ -39,11 +39,12 @@ public class TypedFieldVarAccess implements TypedExpression { return type; } } + private Type checkFieldOrMethodType(TypedProgram typedProgram) { if (typedProgram.getCurrentClass().isThereField(name)) { type = typedProgram.getCurrentClass().getFieldType(name); return type; - } else if(typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) { + } else if (typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) { type = typedProgram.getCurrentClass().getMethodType(name); return type; } else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) { @@ -53,6 +54,7 @@ public class TypedFieldVarAccess implements TypedExpression { throw new RuntimeException("Field " + name + " not declared"); } } + private Type checkVariableType(TypedProgram typedProgram) { if (typedProgram.getCurrentClass().isCurrentConstructorPresent()) { return checkConstructorVariableType(typedProgram); @@ -88,10 +90,9 @@ public class TypedFieldVarAccess implements TypedExpression { private Type checkFieldOrMethodOrRecursiveType(TypedProgram typedProgram) { if (typedProgram.getCurrentClass().isThereField(name)) { type = typedProgram.getCurrentClass().getFieldType(name); - }else if(typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) { + } else if (typedProgram.getCurrentClass().isMethodOfCurrentClass(name)) { type = typedProgram.getCurrentClass().getMethodType(name); - } - else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) { + } else if (recursiveOwnerChain instanceof TypedFieldVarAccess typedFieldVarAccess) { type = typedProgram.getCurrentClass().getFieldType(typedFieldVarAccess.getName()); } else { throw new RuntimeException("Variable " + name + " not declared"); diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java b/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java index 4bb93d9..faedd43 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedMethod.java @@ -40,6 +40,7 @@ public class TypedMethod implements TypedNode { }, () -> { }); } + public void checkIfParameterExists(String parameterName) { if (typedParameters.stream().anyMatch(parameter -> parameter.getParaName().equals(parameterName))) { throw new RuntimeException("Parameter " + parameterName + " already exists"); diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedNew.java b/src/main/java/de/maishai/typedast/typedclass/TypedNew.java index 185e40f..35d446f 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedNew.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedNew.java @@ -29,8 +29,8 @@ public class TypedNew implements TypedExpression, TypedStatement { @Override public Type typeCheck(TypedProgram typedProgram) { - if(typedProgram.isTypedClassPresent(type.getReference())){ - return Type.REFERENCE(type.getReference()); + if (typedProgram.isTypedClassPresent(type.getReference())) { + return Type.REFERENCE(type.getReference()); } for (var constructor : typedProgram.getCurrentClass().getTypedConstructors()) { diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java b/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java index e21c9ba..f57460b 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java @@ -19,7 +19,7 @@ public class TypedProgram { public void startConversion(Program program) { - for(var clas : program.classes()){ + for (var clas : program.classes()) { typedClasses.add(new TypedClass(clas)); } @@ -32,7 +32,7 @@ public class TypedProgram { } int i = 0; - for(var clas : program.classes()){ + for (var clas : program.classes()) { enterCurrentClass(typedClasses.get(i)); typedClasses.get(i).covertBlocksOfConstructorsAndMethods(this, clas); exitCurrentClass(); @@ -43,6 +43,7 @@ public class TypedProgram { public TypedClass getTypedClass(String className) { return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get(); } + public boolean isTypedClassPresent(String className) { return typedClasses.stream().anyMatch(clas -> clas.getClassName().equals(className)); } diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java b/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java index 9995c2e..4562552 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedReturn.java @@ -21,9 +21,9 @@ public class TypedReturn implements TypedStatement { public void convertToTypedReturn(TypedProgram typedProgram, Return unTypedReturn) { ret = convertExpression(typedProgram, unTypedReturn.ret()); - if(ret == null){ + if (ret == null) { type = Type.VOID; - }else{ + } else { type = ret.getType(); } } diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedUnary.java b/src/main/java/de/maishai/typedast/typedclass/TypedUnary.java index a1fdd84..cc2dbfa 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedUnary.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedUnary.java @@ -47,11 +47,11 @@ public class TypedUnary implements TypedExpression { @Override public void codeGen(MethodContext ctx) { right.codeGen(ctx); - if(op == UnaryOperator.NOT){ + if (op == UnaryOperator.NOT) { ctx.getMv().visitInsn(Opcodes.ICONST_1); ctx.getMv().visitInsn(Opcodes.IXOR); } - if(op == UnaryOperator.SUB){ + if (op == UnaryOperator.SUB) { ctx.getMv().visitInsn(Opcodes.INEG); } }