Refactored TypedAST and removed imports with star *

This commit is contained in:
ahmad 2024-07-05 02:15:48 +02:00
parent ecd0b801c7
commit 976f9c2ba6
23 changed files with 95 additions and 68 deletions

View File

@ -2,10 +2,6 @@ package de.maishai.typedast.ExceptionHandler;
public class NotMatchConstructorException extends RuntimeException { public class NotMatchConstructorException extends RuntimeException {
public NotMatchConstructorException(String constructorName) {
super(constructorName);
}
public NotMatchConstructorException() { public NotMatchConstructorException() {
super("Not matching constructor found"); super("Not matching constructor found");
} }

View File

@ -4,11 +4,5 @@ public class ParameterAlreadyExistsException extends RuntimeException{
public ParameterAlreadyExistsException(String paraName) { public ParameterAlreadyExistsException(String paraName) {
super("Parameter '" + paraName + "' already exists"); super("Parameter '" + paraName + "' already exists");
} }
public ParameterAlreadyExistsException(String paraName, String methodOrConstructorName) {
super("Parameter '" + paraName + "' already exists in " + methodOrConstructorName);
}
public ParameterAlreadyExistsException() {
super("Parameter already exists");
}
} }

View File

@ -1,6 +1,5 @@
package de.maishai.typedast.ExceptionHandler; package de.maishai.typedast.ExceptionHandler;
import de.maishai.typedast.Type;
public class TypeOfReturnNotMatchException extends RuntimeException { public class TypeOfReturnNotMatchException extends RuntimeException {
@ -11,7 +10,4 @@ public class TypeOfReturnNotMatchException extends RuntimeException{
" Method name: " + name " Method name: " + name
); );
} }
public TypeOfReturnNotMatchException(String name){
super("Constructor " + name + " must not have a return");
}
} }

View File

@ -5,6 +5,7 @@ public class VariableNotDeclaredException extends RuntimeException{
public VariableNotDeclaredException(String variableName) { public VariableNotDeclaredException(String variableName) {
super("Variable '" + variableName + "' not declared"); super("Variable '" + variableName + "' not declared");
} }
public VariableNotDeclaredException(String variableName, String constrOrMethod) { public VariableNotDeclaredException(String variableName, String constrOrMethod) {
super("Variable '" + variableName + "' not declared in'" + constrOrMethod + "'"); super("Variable '" + variableName + "' not declared in'" + constrOrMethod + "'");
} }

View File

@ -1,8 +1,24 @@
package de.maishai.typedast.Util; package de.maishai.typedast.Util;
import de.maishai.ast.records.*; import de.maishai.ast.records.CharLiteral;
import de.maishai.ast.records.Expression;
import de.maishai.ast.records.IntLiteral;
import de.maishai.ast.records.BoolLiteral;
import de.maishai.ast.records.Binary;
import de.maishai.ast.records.FieldVarAccess;
import de.maishai.ast.records.MethodCall;
import de.maishai.ast.records.New;
import de.maishai.ast.records.Unary;
import de.maishai.typedast.TypedExpression; import de.maishai.typedast.TypedExpression;
import de.maishai.typedast.typedclass.*; import de.maishai.typedast.typedclass.TypedBoolLiteral;
import de.maishai.typedast.typedclass.TypedCharLiteral;
import de.maishai.typedast.typedclass.TypedIntLiteral;
import de.maishai.typedast.typedclass.TypedBinary;
import de.maishai.typedast.typedclass.TypedFieldVarAccess;
import de.maishai.typedast.typedclass.TypedMethodCall;
import de.maishai.typedast.typedclass.TypedNew;
import de.maishai.typedast.typedclass.TypedUnary;
import de.maishai.typedast.typedclass.TypedProgram;
public class TypedExpressionUtil { public class TypedExpressionUtil {

View File

@ -6,7 +6,6 @@ import de.maishai.ast.records.Declaration;
import de.maishai.ast.records.Method; import de.maishai.ast.records.Method;
import de.maishai.typedast.ClassContext; import de.maishai.typedast.ClassContext;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.TypedExpression;
import de.maishai.typedast.TypedNode; import de.maishai.typedast.TypedNode;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;

View File

@ -33,6 +33,7 @@ public class TypedConstructor implements TypedNode {
this.typedParameters = typedParameters; this.typedParameters = typedParameters;
this.typedBlock = typedBlock; this.typedBlock = typedBlock;
} }
public TypedConstructor(Constructor unTypedConstructor, String className) { public TypedConstructor(Constructor unTypedConstructor, String className) {
convertToTypedConstructor(unTypedConstructor, className); convertToTypedConstructor(unTypedConstructor, className);
} }

View File

@ -1,7 +1,10 @@
package de.maishai.typedast.typedclass; package de.maishai.typedast.typedclass;
import de.maishai.ast.records.*; import de.maishai.ast.records.DoWhile;
import de.maishai.typedast.*; import de.maishai.typedast.MethodContext;
import de.maishai.typedast.Type;
import de.maishai.typedast.TypedExpression;
import de.maishai.typedast.TypedStatement;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.objectweb.asm.Label; import org.objectweb.asm.Label;

View File

@ -1,7 +1,10 @@
package de.maishai.typedast.typedclass; package de.maishai.typedast.typedclass;
import de.maishai.ast.records.*; import de.maishai.ast.records.For;
import de.maishai.typedast.*; import de.maishai.typedast.MethodContext;
import de.maishai.typedast.Type;
import de.maishai.typedast.TypedExpression;
import de.maishai.typedast.TypedStatement;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;

View File

@ -1,7 +1,10 @@
package de.maishai.typedast.typedclass; package de.maishai.typedast.typedclass;
import de.maishai.ast.records.*; import de.maishai.ast.records.IfElse;
import de.maishai.typedast.*; import de.maishai.typedast.MethodContext;
import de.maishai.typedast.Type;
import de.maishai.typedast.TypedExpression;
import de.maishai.typedast.TypedStatement;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;

View File

@ -2,8 +2,13 @@ package de.maishai.typedast.typedclass;
import de.maishai.ast.records.Method; import de.maishai.ast.records.Method;
import de.maishai.ast.records.Parameter; import de.maishai.ast.records.Parameter;
import de.maishai.typedast.*; import de.maishai.typedast.CodeGenUtils;
import de.maishai.typedast.ExceptionHandler.ParameterAlreadyExistsException; import de.maishai.typedast.ExceptionHandler.ParameterAlreadyExistsException;
import de.maishai.typedast.Type;
import de.maishai.typedast.TypedNode;
import de.maishai.typedast.TypedStatement;
import de.maishai.typedast.MethodContext;
import de.maishai.typedast.ClassContext;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;

View File

@ -2,8 +2,12 @@ package de.maishai.typedast.typedclass;
import de.maishai.ast.records.Expression; import de.maishai.ast.records.Expression;
import de.maishai.ast.records.New; import de.maishai.ast.records.New;
import de.maishai.typedast.*; import de.maishai.typedast.MethodContext;
import de.maishai.typedast.ExceptionHandler.NotMatchConstructorException; import de.maishai.typedast.ExceptionHandler.NotMatchConstructorException;
import de.maishai.typedast.Type;
import de.maishai.typedast.TypedExpression;
import de.maishai.typedast.TypedStatement;
import de.maishai.typedast.CodeGenUtils;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;

View File

@ -16,6 +16,7 @@ public class TypedParameter implements TypedNode {
public TypedParameter(Parameter unTypedParameter) { public TypedParameter(Parameter unTypedParameter) {
convertToTypedParameter(unTypedParameter); convertToTypedParameter(unTypedParameter);
} }
private void convertToTypedParameter(Parameter unTypedParameter) { private void convertToTypedParameter(Parameter unTypedParameter) {
paraName = unTypedParameter.name(); paraName = unTypedParameter.name();
type = unTypedParameter.type(); type = unTypedParameter.type();

View File

@ -1,7 +1,11 @@
package de.maishai.typedast.typedclass; package de.maishai.typedast.typedclass;
import de.maishai.ast.records.Print; import de.maishai.ast.records.Print;
import de.maishai.typedast.*; import de.maishai.typedast.MethodContext;
import de.maishai.typedast.Type;
import de.maishai.typedast.TypedExpression;
import de.maishai.typedast.TypedStatement;
import de.maishai.typedast.CodeGenUtils;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;

View File

@ -58,6 +58,7 @@ public class TypedProgram {
} }
return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get().getFieldType(fieldName); return typedClasses.stream().filter(clas -> clas.getClassName().equals(className)).findFirst().get().getFieldType(fieldName);
} }
public Type getTypeOfFieldOrMethodNameInClass(String className, String fieldName) { public Type getTypeOfFieldOrMethodNameInClass(String className, String fieldName) {
if (className == null || fieldName == null) { if (className == null || fieldName == null) {
return null; return null;