Add Print statements to AST equals Methods

This commit is contained in:
Julian Murek 2024-07-01 08:36:20 +02:00
parent 8e0b215140
commit 21ece58cc9
12 changed files with 71 additions and 14 deletions

View File

@ -3,6 +3,8 @@ package abstractSyntaxTree.Expression;
import abstractSyntaxTree.Node; import abstractSyntaxTree.Node;
import abstractSyntaxTree.StatementExpression.NewStatementExpression; import abstractSyntaxTree.StatementExpression.NewStatementExpression;
import java.util.Objects;
public class SubReceiver implements Node { public class SubReceiver implements Node {
boolean thisExpression; boolean thisExpression;
public NewStatementExpression newStatementExpression; public NewStatementExpression newStatementExpression;
@ -19,4 +21,16 @@ public class SubReceiver implements Node {
public SubReceiver(String identifier) { public SubReceiver(String identifier) {
this.identifier = identifier; this.identifier = identifier;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SubReceiver subReceiver = (SubReceiver) o;
boolean result = (Objects.equals(thisExpression, subReceiver.thisExpression)
);
System.out.println("In SubReceiver: " + result);
return result;
}
} }

View File

@ -77,9 +77,12 @@ public class UnaryExpression extends AbstractType implements IExpression{
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
UnaryExpression unaryExpression = (UnaryExpression) o; UnaryExpression unaryExpression = (UnaryExpression) o;
return (Objects.equals(operator, unaryExpression.operator) boolean result = (Objects.equals(operator, unaryExpression.operator)
&& Objects.equals(operand, unaryExpression.operand) && Objects.equals(operand, unaryExpression.operand)
); );
System.out.println("In UnaryExpression: " + result);
return result;
} }
@Override @Override

View File

@ -19,8 +19,11 @@ public class Parameter implements Node {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
Parameter parameter = (Parameter) o; Parameter parameter = (Parameter) o;
return (Objects.equals(type, parameter.type) boolean result = (Objects.equals(type, parameter.type)
&& Objects.equals(identifier, parameter.identifier) && Objects.equals(identifier, parameter.identifier)
); );
System.out.println("In Parameter: " + result);
return result;
} }
} }

View File

@ -17,7 +17,10 @@ public class ParameterList implements Node {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
ParameterList parameterListObj = (ParameterList) o; ParameterList parameterListObj = (ParameterList) o;
return (Objects.equals(parameterList, parameterListObj.parameterList) boolean result = (Objects.equals(parameterList, parameterListObj.parameterList)
); );
System.out.println("In ParameterList: " + result);
return result;
} }
} }

View File

@ -129,10 +129,13 @@ public class BlockStatement extends AbstractType implements IStatement {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
BlockStatement blockStatement = (BlockStatement) o; BlockStatement blockStatement = (BlockStatement) o;
return (Objects.equals(localVars, blockStatement.localVars) boolean result = (Objects.equals(localVars, blockStatement.localVars)
&& Objects.equals(returnType, blockStatement.returnType) && Objects.equals(returnType, blockStatement.returnType)
&& Objects.equals(statements, blockStatement.statements) && Objects.equals(statements, blockStatement.statements)
); );
System.out.println("In ParameterList: " + result);
return result;
} }
@Override @Override

View File

@ -24,13 +24,16 @@ public class EmptyStatement extends AbstractType implements IStatement{
//An empty statement does not generate any code //An empty statement does not generate any code
} }
@Override
public boolean equals(Object o) {
return true;
}
@Override @Override
public TypeCheckResult getTypeCheckResult() { public TypeCheckResult getTypeCheckResult() {
return super.getTypeCheckResult(); return super.getTypeCheckResult();
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return true;
}
} }

View File

@ -82,10 +82,13 @@ public class IfElseStatement extends AbstractType implements IStatement{
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
IfElseStatement ifElseStatement = (IfElseStatement) o; IfElseStatement ifElseStatement = (IfElseStatement) o;
return (Objects.equals(condition, ifElseStatement.condition) boolean result = (Objects.equals(condition, ifElseStatement.condition)
&& Objects.equals(ifStatement, ifElseStatement.ifStatement) && Objects.equals(ifStatement, ifElseStatement.ifStatement)
&& Objects.equals(elseStatement, ifElseStatement.elseStatement) && Objects.equals(elseStatement, ifElseStatement.elseStatement)
); );
System.out.println("In PrintStatement: " + result);
return result;
} }
@Override @Override

View File

@ -62,9 +62,12 @@ public class IfStatement extends AbstractType implements IStatement{
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
IfStatement ifStatementObj = (IfStatement) o; IfStatement ifStatementObj = (IfStatement) o;
return (Objects.equals(condition, ifStatementObj.condition) boolean result = (Objects.equals(condition, ifStatementObj.condition)
&& Objects.equals(ifStatement, ifStatementObj.ifStatement) && Objects.equals(ifStatement, ifStatementObj.ifStatement)
); );
System.out.println("In IfStatement: " + result);
return result;
} }
@Override @Override

View File

@ -102,9 +102,12 @@ public class LocalVarDecl extends AbstractType implements IStatement{
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
LocalVarDecl localVarDecl = (LocalVarDecl) o; LocalVarDecl localVarDecl = (LocalVarDecl) o;
return (Objects.equals(type, localVarDecl.type) boolean result = (Objects.equals(type, localVarDecl.type)
&& Objects.equals(identifier, localVarDecl.identifier) && Objects.equals(identifier, localVarDecl.identifier)
); );
System.out.println("In LocalVarDecl: " + result);
return result;
} }
@Override @Override

View File

@ -15,6 +15,18 @@ public class PrintStatement extends AbstractType implements IStatement {
String variableName; String variableName;
public String thisClass; public String thisClass;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PrintStatement printStatement = (PrintStatement) o;
boolean result = (Objects.equals(variableName, printStatement.variableName)
);
System.out.println("In PrintStatement: " + result);
return result;
}
public PrintStatement(String variableName) { public PrintStatement(String variableName) {
this.variableName = variableName; this.variableName = variableName;
} }

View File

@ -60,8 +60,11 @@ public class ReturnStatement extends AbstractType implements IStatement{
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
ReturnStatement returnStatement = (ReturnStatement) o; ReturnStatement returnStatement = (ReturnStatement) o;
return (Objects.equals(expression, returnStatement.expression) boolean result = (Objects.equals(expression, returnStatement.expression)
); );
System.out.println("In PrintStatement: " + result);
return result;
} }
@Override @Override

View File

@ -67,9 +67,13 @@ public class WhileStatement extends AbstractType implements IStatement {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
WhileStatement whileStatement = (WhileStatement) o; WhileStatement whileStatement = (WhileStatement) o;
return (Objects.equals(condition, whileStatement.condition) boolean result = (Objects.equals(condition, whileStatement.condition)
&& Objects.equals(statement, whileStatement.statement) && Objects.equals(statement, whileStatement.statement)
); );
System.out.println("In PrintStatement: " + result);
return result;
} }
@Override @Override