Compare commits
2 Commits
888534955a
...
5d75c23f49
Author | SHA1 | Date | |
---|---|---|---|
|
5d75c23f49 | ||
|
ba9760fe43 |
@ -1,4 +1,3 @@
|
||||
/*
|
||||
class FourClasses {
|
||||
|
||||
public int notmain(int i) {
|
||||
@ -11,4 +10,56 @@ 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;
|
||||
}
|
||||
|
||||
}
|
@ -31,11 +31,25 @@ public class InstVarExpression 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 TypeCheckException {
|
||||
if(this.receivers.get(0).identifier != null){
|
||||
thisClass = localVars.get(this.receivers.get(0).identifier);
|
||||
String typeOfSubreceiver = "";
|
||||
if(receivers.get(0).identifier != null) {
|
||||
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(thisClass).get(fieldName);
|
||||
String varType = typeContext.get(typeOfSubreceiver).get(fieldName);
|
||||
if (varType == null) {
|
||||
throw new TypeCheckException("Field " + fieldName + " was not found in class " + thisClass + ".");
|
||||
}
|
||||
|
@ -48,23 +48,11 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
// receiver is instvar
|
||||
if (receiver != null) {
|
||||
if (receiver.instVarExpression != null) {
|
||||
String subreceiver = receiver.instVarExpression.receivers.get(0).identifier;
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
receiver.instVarExpression.thisClass = this.thisClass;
|
||||
String typeOfSubreceiver = receiver.instVarExpression.typeCheck(methodContext, typeContext, localVars).type;
|
||||
|
||||
String lastField = receiver.instVarExpression.fieldName;
|
||||
|
||||
typeOfSubreceiver = typeContext.get(typeOfSubreceiver).get(lastField);
|
||||
|
||||
currentType = typeOfSubreceiver;
|
||||
|
||||
//currentType = typeContext.get(receiver.instVarExpression.getTypeCheckResult().type).get(mostLeftField);
|
||||
|
@ -32,6 +32,7 @@ public class NewStatementExpression extends AbstractType implements IExpression,
|
||||
throw new TypeCheckException("An instance of " + className + " is created, but the type does not exist.");
|
||||
}
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
|
||||
result.type = className;
|
||||
setTypeCheckResult(result);
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user