Compare commits

..

No commits in common. "0d827c5f32b8e5fa36a06f2844f16aa2ff236a5b" and "9d9dcfb9b66c8a358d3ea3ad7c7dc89df8a10c62" have entirely different histories.

22 changed files with 16 additions and 104 deletions

View File

@ -1,21 +1,17 @@
class ExampleEmpty {
}
class Example {
int i;
boolean b;
char c;
void callM(){
Example2 example2 = new Example2();
example2.m(1);
}
}
class Example2 {
boolean instVarBool;
int m(int n){
boolean a = this.instVarBool;
return n;
boolean localBool;
localBool = true;
if(localBool){
return n;
}
return -1;
}
}

View File

@ -15,8 +15,8 @@ import java.util.Objects;
public class RefType extends AbstractType implements Node {
public String name; // Class Name
//Class Name
public String name;
public List<FieldDecl> fieldDecls;
public List<MethodDecl> methodDecls;
boolean hasMain;

View File

@ -35,8 +35,5 @@ public class BoolDatatype extends AbstractType implements IDatatype{
}
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -34,9 +34,4 @@ public class CharDatatype extends AbstractType implements IDatatype{
CharDatatype charDatatype = (CharDatatype) o;
return (Objects.equals(value, charDatatype.value));
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -10,8 +10,6 @@ public interface IDatatype {
// visit method for code generation
void codeGen(MethodVisitor mv) throws Exception;
TypeCheckResult getTypeCheckResult();
}
//TODO: Check if we need to differentiate between primitive types and reference types --> for example in "=="

View File

@ -41,9 +41,4 @@ public class IntDatatype extends AbstractType implements IDatatype{
IntDatatype intDatatype = (IntDatatype) o;
return (Objects.equals(value, intDatatype.value));
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -3,6 +3,7 @@ package abstractSyntaxTree.Expression;
import TypeCheck.TypeCheckResult;
import TypeCheck.TypeCheckHelper;
import TypeCheck.AbstractType;
import abstractSyntaxTree.Datatype.IntDatatype;
import abstractSyntaxTree.Parameter.ParameterList;
import org.objectweb.asm.*;
@ -186,9 +187,4 @@ public class BinaryExpression extends AbstractType implements IExpression{
&& Objects.equals(right, binaryExpression.right)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -15,6 +15,4 @@ public interface IExpression extends Node {
// visit method for code generation
void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext) throws Exception;
TypeCheckResult getTypeCheckResult();
}

View File

@ -9,6 +9,7 @@ import org.objectweb.asm.Opcodes;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Objects;
public class InstVarExpression implements IExpression{
@ -73,9 +74,4 @@ public class InstVarExpression implements IExpression{
&& Objects.equals(fieldName, instVarExpression.fieldName)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -35,9 +35,4 @@ public class IntConstantExpression extends AbstractType implements IExpression{
return (Objects.equals(value, intConstantExpression.value)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -81,9 +81,4 @@ public class LocalVarIdentifier implements IExpression{
return (Objects.equals(identifier, localVarIdentifier.identifier)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -80,9 +80,4 @@ public class UnaryExpression extends AbstractType implements IExpression{
&& Objects.equals(operand, unaryExpression.operand)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -99,9 +99,4 @@ public class BlockStatement extends AbstractType implements IStatement {
&& Objects.equals(statements, blockStatement.statements)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -28,9 +28,4 @@ public class EmptyStatement extends AbstractType implements IStatement{
public boolean equals(Object o) {
return true;
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -14,5 +14,4 @@ public interface IStatement extends Node {
TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws Exception;
void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext) throws Exception;
TypeCheckResult getTypeCheckResult();
}

View File

@ -81,9 +81,4 @@ public class IfElseStatement extends AbstractType implements IStatement{
&& Objects.equals(elseStatement, ifElseStatement.elseStatement)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -61,11 +61,6 @@ public class IfStatement extends AbstractType implements IStatement{
&& Objects.equals(ifStatement, ifStatementObj.ifStatement)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -59,9 +59,4 @@ public class LocalVarDecl implements IStatement{
&& Objects.equals(identifier, localVarDecl.identifier)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -63,9 +63,4 @@ public class ReturnStatement extends AbstractType implements IStatement{
return (Objects.equals(expression, returnStatement.expression)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -70,9 +70,4 @@ public class WhileStatement extends AbstractType implements IStatement {
&& Objects.equals(statement, whileStatement.statement)
);
}
@Override
public TypeCheckResult getTypeCheckResult() {
return getTypeCheckResult();
}
}

View File

@ -67,10 +67,10 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
for (MethodDecl methodDecl : methodDecls) {
if (methodDecl.name.equals(methodName)) {
//Get the method descriptor
// descriptor = methodDecl.getMethodDescriptor(methodContext);
descriptor = methodDecl.getMethodDescriptor(methodContext);
}
}
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classThatHasTheMethodIfNotThis.name, methodName, descriptor, false);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classThatHasTheMethodIfNotThis.name, methodName, descriptor, false);
} else {
// Load this onto the stack
@ -86,10 +86,10 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
for (MethodDecl methodDecl : methodDecls) {
if (methodDecl.name.equals(methodName)) {
//Get the method descriptor
// descriptor = methodDecl.getMethodDescriptor(methodContext);
descriptor = methodDecl.getMethodDescriptor(methodContext);
}
}
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, thisClass.name, methodName, descriptor, false);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, thisClass.name, methodName, descriptor, false);
}
}

View File

@ -1,7 +1,6 @@
package abstractSyntaxTree.StatementExpression;
import TypeCheck.AbstractType;
import TypeCheck.TypeCheckHelper;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Parameter.ParameterList;
@ -9,7 +8,6 @@ import abstractSyntaxTree.Statement.IStatement;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@ -24,13 +22,7 @@ public class NewStatementExpression extends AbstractType implements IExpression,
@Override
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws Exception {
if(!TypeCheckHelper.typeExists(className, new ArrayList<>(typeContext.keySet()))){
throw new Exception("TypeCheck Exception: An instance of " + className + " is created, but the type does not exist.");
}
TypeCheckResult result = new TypeCheckResult();
result.type = className;
setTypeCheckResult(result);
return result;
return null;
}
@Override