missing thisclass and subreceiver
This commit is contained in:
parent
1100cef668
commit
0711028dc3
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@ -24,7 +24,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/target" />
|
<output url="file://$PROJECT_DIR$/target" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -1,32 +1,13 @@
|
|||||||
class TestClass {
|
class FourClasses {
|
||||||
int i;
|
|
||||||
int a = 12345;
|
|
||||||
Example e;
|
|
||||||
public TestClass(){i = 3456;}
|
|
||||||
int meth(int n){
|
|
||||||
Example e = new Example();
|
|
||||||
e.example1 = new TestClass();
|
|
||||||
int abc = e.example1.m1(2).m2().m3();
|
|
||||||
|
|
||||||
return 0;
|
public int notmain(int i) {
|
||||||
}
|
Test t = new Test(i);
|
||||||
Example m1(int n){
|
Test2 t2 = new Test2(t.y);
|
||||||
return new Example();
|
return t2.test.test3.getX();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
TestClass t2 = new TestClass();
|
|
||||||
t2.meth(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Example {
|
|
||||||
int i;
|
|
||||||
boolean b;
|
|
||||||
char c;
|
|
||||||
TestClass example1;
|
|
||||||
TestClass m(int a){
|
|
||||||
return new TestClass();
|
|
||||||
}
|
}
|
||||||
Example m2(){return new Example();}
|
|
||||||
int m3(){return 1;}
|
|
||||||
}
|
}
|
@ -63,6 +63,9 @@ public class BlockStatement extends AbstractType implements IStatement {
|
|||||||
if (statement instanceof PrintStatement printStatement) {
|
if (statement instanceof PrintStatement printStatement) {
|
||||||
printStatement.thisClass = thisClass;
|
printStatement.thisClass = thisClass;
|
||||||
}
|
}
|
||||||
|
if (statement instanceof ReturnStatement returnStatement) {
|
||||||
|
returnStatement.thisClass = thisClass;
|
||||||
|
}
|
||||||
|
|
||||||
TypeCheckResult typeOfCurrentStatement = statement.typeCheck(methodContext, typeContext, localVars);
|
TypeCheckResult typeOfCurrentStatement = statement.typeCheck(methodContext, typeContext, localVars);
|
||||||
if(statement instanceof MethodCallStatementExpression methodCall){
|
if(statement instanceof MethodCallStatementExpression methodCall){
|
||||||
|
@ -4,7 +4,9 @@ import TypeCheck.TypeCheckException;
|
|||||||
import TypeCheck.TypeCheckResult;
|
import TypeCheck.TypeCheckResult;
|
||||||
import TypeCheck.AbstractType;
|
import TypeCheck.AbstractType;
|
||||||
import abstractSyntaxTree.Expression.IExpression;
|
import abstractSyntaxTree.Expression.IExpression;
|
||||||
|
import abstractSyntaxTree.Expression.InstVarExpression;
|
||||||
import abstractSyntaxTree.Parameter.ParameterList;
|
import abstractSyntaxTree.Parameter.ParameterList;
|
||||||
|
import abstractSyntaxTree.StatementExpression.MethodCallStatementExpression;
|
||||||
import org.objectweb.asm.*;
|
import org.objectweb.asm.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -14,6 +16,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class ReturnStatement extends AbstractType implements IStatement{
|
public class ReturnStatement extends AbstractType implements IStatement{
|
||||||
IExpression expression;
|
IExpression expression;
|
||||||
|
public String thisClass;
|
||||||
|
|
||||||
public ReturnStatement(IExpression expression) {
|
public ReturnStatement(IExpression expression) {
|
||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
@ -26,6 +29,10 @@ public class ReturnStatement extends AbstractType implements IStatement{
|
|||||||
if (expression == null) {
|
if (expression == null) {
|
||||||
result.type = "void";
|
result.type = "void";
|
||||||
} else {
|
} else {
|
||||||
|
if(expression instanceof MethodCallStatementExpression methodCallStatementExpression)
|
||||||
|
methodCallStatementExpression.thisClass = this.thisClass;
|
||||||
|
else if(expression instanceof InstVarExpression instVarExpression)
|
||||||
|
instVarExpression.thisClass = this.thisClass;
|
||||||
TypeCheckResult typedExpression = expression.typeCheck(methodContext, typeContext, localVars);
|
TypeCheckResult typedExpression = expression.typeCheck(methodContext, typeContext, localVars);
|
||||||
result.type = typedExpression.type;
|
result.type = typedExpression.type;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
|||||||
if(leftType.type == null){
|
if(leftType.type == null){
|
||||||
leftType.type = typeContext.get(thisClass).get(identifier);
|
leftType.type = typeContext.get(thisClass).get(identifier);
|
||||||
}
|
}
|
||||||
}else{
|
}else {
|
||||||
if(left instanceof InstVarExpression instVarExpression)
|
if(left instanceof InstVarExpression instVarExpression)
|
||||||
instVarExpression.thisClass = this.thisClass;
|
instVarExpression.thisClass = this.thisClass;
|
||||||
leftType = left.typeCheck(methodContext, typeContext, localVars);
|
leftType = left.typeCheck(methodContext, typeContext, localVars);
|
||||||
|
@ -48,14 +48,25 @@ 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) {
|
||||||
String Subreceiver = receiver.instVarExpression.receivers.get(0).identifier; // e
|
String subreceiver = receiver.instVarExpression.receivers.get(0).identifier;
|
||||||
String mostLeftField = receiver.instVarExpression.fieldName; // example1
|
String typeOfSubreceiver = localVars.get(subreceiver);
|
||||||
|
if(typeOfSubreceiver == null)
|
||||||
|
typeContext.get(thisClass).get(subreceiver);
|
||||||
|
|
||||||
String typeOfSubreceiver = 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;
|
||||||
|
|
||||||
|
typeOfSubreceiver = typeContext.get(typeOfSubreceiver).get(lastField);
|
||||||
|
|
||||||
|
currentType = typeOfSubreceiver;
|
||||||
|
|
||||||
receiver.instVarExpression.thisClass = typeOfSubreceiver;
|
|
||||||
receiver.instVarExpression.typeCheck(methodContext, typeContext, localVars);
|
|
||||||
currentType = typeContext.get(typeOfSubreceiver).get(mostLeftField);
|
|
||||||
//currentType = typeContext.get(receiver.instVarExpression.getTypeCheckResult().type).get(mostLeftField);
|
//currentType = typeContext.get(receiver.instVarExpression.getTypeCheckResult().type).get(mostLeftField);
|
||||||
} else {
|
} else {
|
||||||
currentType = classToSearchMethodIn;
|
currentType = classToSearchMethodIn;
|
||||||
|
Loading…
Reference in New Issue
Block a user