Compare commits

..

No commits in common. "5d75c23f49fd5b137315c8d33ae2765b63c33c07" and "888534955a904882c73e6d06b820d1416a4171bc" have entirely different histories.

4 changed files with 19 additions and 73 deletions

View File

@ -1,3 +1,4 @@
/*
class FourClasses { class FourClasses {
public int notmain(int i) { public int notmain(int i) {
@ -10,56 +11,4 @@ class FourClasses {
} }
} }*/
class Test {
public int x;
public int y;
public Test3 test3;
public Test(int i) {
this.x = i;
this.y = 10;
this.test3 = new Test3(i * 2);
}
public Test3 getTest3() {
return this.test3;
}
public int getX() {
return this.x;
}
}
class Test2 {
public Test test;
public Test2(int i) {
this.test = new Test(i);
}
}
class Test3 {
public int x;
public int y;
public Test3(int i) {
this.x = i;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public void setY(int y) {
this.y = y;
}
}

View File

@ -31,25 +31,11 @@ public class InstVarExpression extends AbstractType implements IExpression{
@Override @Override
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException { public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException {
String typeOfSubreceiver = ""; if(this.receivers.get(0).identifier != null){
if(receivers.get(0).identifier != null) { thisClass = localVars.get(this.receivers.get(0).identifier);
String subreceiver = receivers.get(0).identifier;
typeOfSubreceiver = localVars.get(subreceiver);
if (typeOfSubreceiver == null)
typeContext.get(thisClass).get(subreceiver);
if (receivers.size() > 1) {
for (int i = 1; i < receivers.size(); i++) {
subreceiver = receivers.get(i).identifier;
typeOfSubreceiver = typeContext.get(typeOfSubreceiver).get(subreceiver);
}
}
}else {
typeOfSubreceiver = thisClass;
} }
String varType = typeContext.get(typeOfSubreceiver).get(fieldName); String varType = typeContext.get(thisClass).get(fieldName);
if (varType == null) { if (varType == null) {
throw new TypeCheckException("Field " + fieldName + " was not found in class " + thisClass + "."); throw new TypeCheckException("Field " + fieldName + " was not found in class " + thisClass + ".");
} }

View File

@ -48,11 +48,23 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
// 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; String subreceiver = receiver.instVarExpression.receivers.get(0).identifier;
String typeOfSubreceiver = receiver.instVarExpression.typeCheck(methodContext, typeContext, localVars).type; String typeOfSubreceiver = localVars.get(subreceiver);
if(typeOfSubreceiver == null)
typeContext.get(thisClass).get(subreceiver);
if(receiver.instVarExpression.receivers.size() > 1){
for(int i = 1; i < receiver.instVarExpression.receivers.size(); i++) {
subreceiver = receiver.instVarExpression.receivers.get(i).identifier;
typeOfSubreceiver = typeContext.get(typeOfSubreceiver).get(subreceiver);
}
}
String lastField = receiver.instVarExpression.fieldName; String lastField = receiver.instVarExpression.fieldName;
typeOfSubreceiver = typeContext.get(typeOfSubreceiver).get(lastField);
currentType = typeOfSubreceiver; currentType = typeOfSubreceiver;
//currentType = typeContext.get(receiver.instVarExpression.getTypeCheckResult().type).get(mostLeftField); //currentType = typeContext.get(receiver.instVarExpression.getTypeCheckResult().type).get(mostLeftField);

View File

@ -32,7 +32,6 @@ public class NewStatementExpression extends AbstractType implements IExpression,
throw new TypeCheckException("An instance of " + className + " is created, but the type does not exist."); throw new TypeCheckException("An instance of " + className + " is created, but the type does not exist.");
} }
TypeCheckResult result = new TypeCheckResult(); TypeCheckResult result = new TypeCheckResult();
result.type = className; result.type = className;
setTypeCheckResult(result); setTypeCheckResult(result);
return result; return result;