Code cleanup

Deleted imports and comments, fixed warnings and typos
This commit is contained in:
Jochen Seyfried 2024-07-04 19:00:28 +02:00
parent 32353b9a37
commit 302b907d36
21 changed files with 20 additions and 58 deletions

6
.idea/misc.xml generated
View File

@ -24,7 +24,11 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK"> <component name="PWA">
<option name="enabled" value="true" />
<option name="wasEnabledAtLeastOnce" value="true" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/target" /> <output url="file://$PROJECT_DIR$/target" />
</component> </component>
</project> </project>

View File

@ -7,7 +7,6 @@ import TypeCheck.TypeCheckHelper;
import TypeCheck.TypeCheckResult; import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Expression.IExpression; import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Node; import abstractSyntaxTree.Node;
import abstractSyntaxTree.Program;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;

View File

@ -6,9 +6,7 @@ import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Node; import abstractSyntaxTree.Node;
import abstractSyntaxTree.Parameter.Parameter; import abstractSyntaxTree.Parameter.Parameter;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import abstractSyntaxTree.Program;
import abstractSyntaxTree.Statement.BlockStatement; import abstractSyntaxTree.Statement.BlockStatement;
import abstractSyntaxTree.Statement.IStatement;
import org.objectweb.asm.*; import org.objectweb.asm.*;
import java.util.*; import java.util.*;

View File

@ -3,7 +3,6 @@ package abstractSyntaxTree.Class;
import TypeCheck.AbstractType; import TypeCheck.AbstractType;
import TypeCheck.TypeCheckException; import TypeCheck.TypeCheckException;
import TypeCheck.TypeCheckResult; import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Node; import abstractSyntaxTree.Node;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import abstractSyntaxTree.Statement.BlockStatement; import abstractSyntaxTree.Statement.BlockStatement;

View File

@ -2,7 +2,6 @@ package abstractSyntaxTree.Datatype;
import TypeCheck.AbstractType; import TypeCheck.AbstractType;
import TypeCheck.TypeCheckResult; import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Class.RefType;
import org.objectweb.asm.*; import org.objectweb.asm.*;
import java.util.Objects; import java.util.Objects;

View File

@ -7,7 +7,6 @@ import TypeCheck.AbstractType;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import org.objectweb.asm.*; import org.objectweb.asm.*;
import java.beans.Expression;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Objects; import java.util.Objects;

View File

@ -1,9 +1,7 @@
package abstractSyntaxTree.Expression; package abstractSyntaxTree.Expression;
import TypeCheck.AbstractType; import TypeCheck.AbstractType;
import TypeCheck.TypeCheckException;
import TypeCheck.TypeCheckResult; import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Datatype.BoolDatatype;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;

View File

@ -4,11 +4,8 @@ import CodeGen.CodeGenHelper;
import TypeCheck.AbstractType; import TypeCheck.AbstractType;
import TypeCheck.TypeCheckException; import TypeCheck.TypeCheckException;
import TypeCheck.TypeCheckResult; import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Class.RefType;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import abstractSyntaxTree.StatementExpression.ReceivingMethod; import abstractSyntaxTree.StatementExpression.ReceivingMethod;
import gen.DecafParser;
import jdk.jshell.spi.ExecutionControl;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
@ -84,7 +81,7 @@ public class InstVarExpression extends AbstractType implements IExpression {
typeOfReciever = typeContext.get(typeOfReciever).get(this.receivers.get(i).identifier); typeOfReciever = typeContext.get(typeOfReciever).get(this.receivers.get(i).identifier);
descriptor = getFieldDescriptor(typeContext, typeOfReciever); descriptor = getFieldDescriptor(typeOfReciever);
// Load the variable onto the stack // Load the variable onto the stack
mv.visitFieldInsn(Opcodes.GETFIELD, classOfField, receivers.get(i).identifier, descriptor); mv.visitFieldInsn(Opcodes.GETFIELD, classOfField, receivers.get(i).identifier, descriptor);
@ -100,12 +97,6 @@ public class InstVarExpression extends AbstractType implements IExpression {
// Get the class of the receiver // Get the class of the receiver
typeOfReciever = localVars.get(this.receivers.get(i).identifier); typeOfReciever = localVars.get(this.receivers.get(i).identifier);
/*
descriptor = getFieldDescriptor(typeContext, typeOfReciever, typeOfReciever);
mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, fieldName, descriptor);
*/
continue;
} }
} }
// Not the first receiver // Not the first receiver
@ -121,7 +112,7 @@ public class InstVarExpression extends AbstractType implements IExpression {
typeOfReciever = typeContext.get(typeOfReciever).get(this.receivers.get(i).identifier); typeOfReciever = typeContext.get(typeOfReciever).get(this.receivers.get(i).identifier);
descriptor = getFieldDescriptor(typeContext, typeOfReciever); descriptor = getFieldDescriptor(typeOfReciever);
// Load the variable onto the stack // Load the variable onto the stack
mv.visitFieldInsn(Opcodes.GETFIELD, classOfField, receivers.get(i).identifier, descriptor); mv.visitFieldInsn(Opcodes.GETFIELD, classOfField, receivers.get(i).identifier, descriptor);
@ -133,7 +124,7 @@ public class InstVarExpression extends AbstractType implements IExpression {
} else { } else {
typeOfReciever = localVars.get(this.receivers.get(i).identifier); typeOfReciever = localVars.get(this.receivers.get(i).identifier);
descriptor = getFieldDescriptor(typeContext, typeOfReciever); descriptor = getFieldDescriptor(typeOfReciever);
mv.visitFieldInsn(Opcodes.GETFIELD, typeOfReciever, fieldName, descriptor); mv.visitFieldInsn(Opcodes.GETFIELD, typeOfReciever, fieldName, descriptor);
} }
@ -151,7 +142,7 @@ public class InstVarExpression extends AbstractType implements IExpression {
typeOfReciever = typeContext.get(typeOfReciever).get(fieldName); typeOfReciever = typeContext.get(typeOfReciever).get(fieldName);
descriptor = getFieldDescriptor(typeContext, typeOfReciever); descriptor = getFieldDescriptor(typeOfReciever);
// Load the variable onto the stack // Load the variable onto the stack
mv.visitFieldInsn(Opcodes.GETFIELD, classOfField, fieldName, descriptor); mv.visitFieldInsn(Opcodes.GETFIELD, classOfField, fieldName, descriptor);
@ -163,7 +154,7 @@ public class InstVarExpression extends AbstractType implements IExpression {
} else { } else {
typeOfReciever = localVars.get(fieldName); typeOfReciever = localVars.get(fieldName);
descriptor = getFieldDescriptor(typeContext, typeOfReciever); descriptor = getFieldDescriptor(typeOfReciever);
mv.visitFieldInsn(Opcodes.GETFIELD, typeOfReciever, fieldName, descriptor); mv.visitFieldInsn(Opcodes.GETFIELD, typeOfReciever, fieldName, descriptor);
} }
@ -179,14 +170,14 @@ public class InstVarExpression extends AbstractType implements IExpression {
} }
String fieldType = typeContext.get(thisClass).get(fieldName); String fieldType = typeContext.get(thisClass).get(fieldName);
descriptor = getFieldDescriptor(typeContext, fieldType); descriptor = getFieldDescriptor(fieldType);
//Load the field onto the stack //Load the field onto the stack
mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, fieldName, descriptor); mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, fieldName, descriptor);
} }
} }
private String getFieldDescriptor(HashMap<String, HashMap<String, String>> typeContext, String fieldType) { private String getFieldDescriptor(String fieldType) {
StringBuilder descriptor = new StringBuilder(); StringBuilder descriptor = new StringBuilder();

View File

@ -3,7 +3,6 @@ package abstractSyntaxTree.Expression;
import CodeGen.CodeGenHelper; import CodeGen.CodeGenHelper;
import TypeCheck.AbstractType; import TypeCheck.AbstractType;
import TypeCheck.TypeCheckException; import TypeCheck.TypeCheckException;
import TypeCheck.TypeCheckHelper;
import TypeCheck.TypeCheckResult; import TypeCheck.TypeCheckResult;
import org.objectweb.asm.*; import org.objectweb.asm.*;
@ -12,7 +11,6 @@ import java.util.LinkedHashMap;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import java.util.HashMap;
import java.util.Objects; import java.util.Objects;
public class LocalVarIdentifier extends AbstractType implements IExpression{ public class LocalVarIdentifier extends AbstractType implements IExpression{

View File

@ -3,8 +3,6 @@ package abstractSyntaxTree.Statement;
import TypeCheck.TypeCheckException; import TypeCheck.TypeCheckException;
import TypeCheck.TypeCheckResult; import TypeCheck.TypeCheckResult;
import TypeCheck.AbstractType; import TypeCheck.AbstractType;
import abstractSyntaxTree.Class.FieldDecl;
import abstractSyntaxTree.Parameter.Parameter;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import abstractSyntaxTree.StatementExpression.AssignStatementExpression; import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
import abstractSyntaxTree.StatementExpression.MethodCallStatementExpression; import abstractSyntaxTree.StatementExpression.MethodCallStatementExpression;
@ -77,7 +75,7 @@ public class BlockStatement extends AbstractType implements IStatement {
} }
if (typeOfCurrentStatement.type.contains(",")) { if (typeOfCurrentStatement.type.contains(",")) {
// else if has 2 returns, all code paths must retrun a value. // else if has 2 returns, all code paths must return a value.
String[] substrings = typeOfCurrentStatement.type.split(","); String[] substrings = typeOfCurrentStatement.type.split(",");
String firstType = substrings[0]; String firstType = substrings[0];

View File

@ -7,8 +7,7 @@ import org.objectweb.asm.MethodVisitor;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
public class EmptyStatement extends AbstractType implements IStatement{ public class EmptyStatement extends AbstractType implements IStatement{

View File

@ -9,7 +9,6 @@ import org.objectweb.asm.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class IfElseStatement extends AbstractType implements IStatement{ public class IfElseStatement extends AbstractType implements IStatement{

View File

@ -9,7 +9,6 @@ import org.objectweb.asm.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class IfStatement extends AbstractType implements IStatement{ public class IfStatement extends AbstractType implements IStatement{

View File

@ -8,7 +8,6 @@ import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Expression.IExpression; import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Expression.LocalVarIdentifier; import abstractSyntaxTree.Expression.LocalVarIdentifier;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
import abstractSyntaxTree.StatementExpression.MethodCallStatementExpression; import abstractSyntaxTree.StatementExpression.MethodCallStatementExpression;
import abstractSyntaxTree.StatementExpression.NewStatementExpression; import abstractSyntaxTree.StatementExpression.NewStatementExpression;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
@ -80,7 +79,7 @@ public class LocalVarDecl extends AbstractType implements IStatement{
} }
} else { } else {
// Set a default value for the variable --> less problems // Set a default value for the variable --> fewer problems
switch (type) { switch (type) {
case "int", "boolean", "char": case "int", "boolean", "char":
mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.ICONST_0);

View File

@ -12,7 +12,6 @@ import org.objectweb.asm.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class ReturnStatement extends AbstractType implements IStatement{ public class ReturnStatement extends AbstractType implements IStatement{

View File

@ -9,7 +9,6 @@ import org.objectweb.asm.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class WhileStatement extends AbstractType implements IStatement { public class WhileStatement extends AbstractType implements IStatement {

View File

@ -11,7 +11,6 @@ import abstractSyntaxTree.Expression.InstVarExpression;
import abstractSyntaxTree.Expression.LocalVarIdentifier; import abstractSyntaxTree.Expression.LocalVarIdentifier;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import abstractSyntaxTree.Statement.IStatement; import abstractSyntaxTree.Statement.IStatement;
import abstractSyntaxTree.Statement.WhileStatement;
import org.objectweb.asm.*; import org.objectweb.asm.*;
import java.util.HashMap; import java.util.HashMap;
@ -43,7 +42,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
String identifier = localVarIdentifier.getIdentifier(); String identifier = localVarIdentifier.getIdentifier();
leftType.type = localVars.get(identifier); leftType.type = localVars.get(identifier);
// local var may be actually instvar of this // local var may be actually instVar of this
if(leftType.type == null){ if(leftType.type == null){
leftType.type = typeContext.get(thisClass).get(identifier); leftType.type = typeContext.get(thisClass).get(identifier);
} }

View File

@ -3,13 +3,10 @@ package abstractSyntaxTree.StatementExpression;
import TypeCheck.AbstractType; import TypeCheck.AbstractType;
import TypeCheck.TypeCheckException; import TypeCheck.TypeCheckException;
import TypeCheck.TypeCheckResult; import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Class.MethodDecl;
import abstractSyntaxTree.Class.RefType;
import abstractSyntaxTree.Expression.IExpression; import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import abstractSyntaxTree.Statement.IStatement; import abstractSyntaxTree.Statement.IStatement;
import jdk.jshell.spi.ExecutionControl; import jdk.jshell.spi.ExecutionControl;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
@ -17,8 +14,8 @@ import java.util.*;
public class MethodCallStatementExpression extends AbstractType implements IExpression, IStatement { public class MethodCallStatementExpression extends AbstractType implements IExpression, IStatement {
String methodName; String methodName;
List<IExpression> arguments; // Need typecheckresults List<IExpression> arguments;
Receiver receiver; // InstVarExpression und NewStatementExpression Braucht typecheckResult Receiver receiver;
List<ReceivingMethod> receivingMethods; List<ReceivingMethod> receivingMethods;
public String thisClass; public String thisClass;
@ -44,7 +41,7 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
String currentType = ""; String currentType = "";
// receiver is instvar // receiver is instVar
if (receiver != null) { if (receiver != null) {
if (receiver.instVarExpression != null) { if (receiver.instVarExpression != null) {
receiver.instVarExpression.thisClass = this.thisClass; receiver.instVarExpression.thisClass = this.thisClass;
@ -150,7 +147,6 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
} }
// ()I
private String getMethodDescriptor(String methodName, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, List<IExpression> arguments, String returnOfPreviousMethod, String owner) { private String getMethodDescriptor(String methodName, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, List<IExpression> arguments, String returnOfPreviousMethod, String owner) {
StringBuilder descriptor = new StringBuilder("("); StringBuilder descriptor = new StringBuilder("(");

View File

@ -6,10 +6,8 @@ import TypeCheck.TypeCheckHelper;
import TypeCheck.TypeCheckResult; import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Expression.IExpression; import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Expression.InstVarExpression; import abstractSyntaxTree.Expression.InstVarExpression;
import abstractSyntaxTree.Parameter.Parameter;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import abstractSyntaxTree.Statement.IStatement; import abstractSyntaxTree.Statement.IStatement;
import abstractSyntaxTree.Statement.WhileStatement;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;

View File

@ -1,16 +1,9 @@
package abstractSyntaxTree.StatementExpression; package abstractSyntaxTree.StatementExpression;
import TypeCheck.TypeCheckException;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Expression.InstVarExpression; import abstractSyntaxTree.Expression.InstVarExpression;
import abstractSyntaxTree.Node; import abstractSyntaxTree.Node;
import abstractSyntaxTree.Parameter.ParameterList;
import abstractSyntaxTree.Statement.IStatement;
import org.objectweb.asm.MethodVisitor;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Objects; import java.util.Objects;
public class Receiver implements Node { public class Receiver implements Node {

View File

@ -5,7 +5,6 @@ import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Expression.LocalVarIdentifier; import abstractSyntaxTree.Expression.LocalVarIdentifier;
import abstractSyntaxTree.Node; import abstractSyntaxTree.Node;
import abstractSyntaxTree.Parameter.ParameterList; import abstractSyntaxTree.Parameter.ParameterList;
import abstractSyntaxTree.Statement.LocalVarDecl;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;