Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
d665c0393c
@ -1,17 +1,21 @@
|
||||
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 localBool;
|
||||
localBool = true;
|
||||
if(localBool){
|
||||
boolean a = this.instVarBool;
|
||||
return n;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ import java.util.Objects;
|
||||
|
||||
public class RefType extends AbstractType implements Node {
|
||||
|
||||
//Class Name
|
||||
public String name;
|
||||
|
||||
public String name; // Class Name
|
||||
public List<FieldDecl> fieldDecls;
|
||||
public List<MethodDecl> methodDecls;
|
||||
boolean hasMain;
|
||||
|
@ -35,5 +35,8 @@ public class BoolDatatype extends AbstractType implements IDatatype{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,9 @@ public class CharDatatype extends AbstractType implements IDatatype{
|
||||
CharDatatype charDatatype = (CharDatatype) o;
|
||||
return (Objects.equals(value, charDatatype.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ 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 "=="
|
@ -41,4 +41,9 @@ public class IntDatatype extends AbstractType implements IDatatype{
|
||||
IntDatatype intDatatype = (IntDatatype) o;
|
||||
return (Objects.equals(value, intDatatype.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package abstractSyntaxTree.Expression;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
import TypeCheck.AbstractType;
|
||||
import abstractSyntaxTree.Datatype.IntDatatype;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
@ -187,4 +186,9 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
||||
&& Objects.equals(right, binaryExpression.right)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
@ -15,4 +15,6 @@ 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();
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class InstVarExpression implements IExpression{
|
||||
|
||||
@ -74,4 +73,9 @@ public class InstVarExpression implements IExpression{
|
||||
&& Objects.equals(fieldName, instVarExpression.fieldName)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -35,4 +35,9 @@ public class IntConstantExpression extends AbstractType implements IExpression{
|
||||
return (Objects.equals(value, intConstantExpression.value)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -81,4 +81,9 @@ public class LocalVarIdentifier implements IExpression{
|
||||
return (Objects.equals(identifier, localVarIdentifier.identifier)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -80,4 +80,9 @@ public class UnaryExpression extends AbstractType implements IExpression{
|
||||
&& Objects.equals(operand, unaryExpression.operand)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -99,4 +99,9 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
&& Objects.equals(statements, blockStatement.statements)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
@ -28,4 +28,9 @@ public class EmptyStatement extends AbstractType implements IStatement{
|
||||
public boolean equals(Object o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -14,4 +14,5 @@ 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();
|
||||
}
|
||||
|
@ -81,4 +81,9 @@ public class IfElseStatement extends AbstractType implements IStatement{
|
||||
&& Objects.equals(elseStatement, ifElseStatement.elseStatement)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,11 @@ public class IfStatement extends AbstractType implements IStatement{
|
||||
&& Objects.equals(ifStatement, ifStatementObj.ifStatement)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,4 +59,9 @@ public class LocalVarDecl implements IStatement{
|
||||
&& Objects.equals(identifier, localVarDecl.identifier)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -63,4 +63,9 @@ public class ReturnStatement extends AbstractType implements IStatement{
|
||||
return (Objects.equals(expression, returnStatement.expression)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
|
@ -70,4 +70,9 @@ public class WhileStatement extends AbstractType implements IStatement {
|
||||
&& Objects.equals(statement, whileStatement.statement)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return getTypeCheckResult();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package abstractSyntaxTree.StatementExpression;
|
||||
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
@ -8,6 +9,7 @@ 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;
|
||||
@ -22,7 +24,13 @@ 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 {
|
||||
return null;
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user