fixed another localvaridentifier that just isnt local actually
This commit is contained in:
parent
ed2f64eff9
commit
6365e994d2
@ -1,9 +1,11 @@
|
||||
class Example1 {
|
||||
int instVar;
|
||||
Example e;
|
||||
public Example1(){}
|
||||
int meth(int n){
|
||||
Example e = new Example();
|
||||
int i = m1(2).m2().m3();
|
||||
instVar = 2;
|
||||
int i = m1(instVar).m2().m3();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import java.util.Objects;
|
||||
public class LocalVarIdentifier extends AbstractType implements IExpression{
|
||||
|
||||
String identifier;
|
||||
public String thisClass;
|
||||
public LocalVarIdentifier(String identifier){
|
||||
this.identifier = identifier;
|
||||
}
|
||||
@ -31,6 +32,12 @@ public class LocalVarIdentifier extends AbstractType implements IExpression{
|
||||
if (localVars.containsKey(identifier)) {
|
||||
result.type = localVars.get(identifier);
|
||||
} else {
|
||||
// check if instvar
|
||||
result.type = typeContext.get(thisClass).get(identifier);
|
||||
if(result.type != null){
|
||||
setTypeCheckResult(result);
|
||||
return result;
|
||||
}
|
||||
throw new TypeCheckException("Local var " + identifier + " does not exist.");
|
||||
}
|
||||
setTypeCheckResult(result);
|
||||
|
@ -67,9 +67,8 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
currentType = (String) methodContext.get(currentType).get(receivingMethods.get(i).methodName).keySet().toArray()[0];
|
||||
if(currentType == null)
|
||||
throw new TypeCheckException("The method " + methodName + " was not found in "+ classToSearchMethodIn + ".");
|
||||
receivingMethods.get(i).thisClass = this.thisClass;
|
||||
receivingMethods.get(i).checkParameters(methodContext, typeContext, localVars);
|
||||
System.out.println(currentType);
|
||||
|
||||
}
|
||||
currentType = (String) methodContext.get(currentType).get(methodName).keySet().toArray()[0];
|
||||
|
||||
|
@ -2,8 +2,10 @@ package abstractSyntaxTree.StatementExpression;
|
||||
|
||||
import TypeCheck.TypeCheckException;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Node;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Statement.LocalVarDecl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -11,6 +13,7 @@ import java.util.List;
|
||||
public class ReceivingMethod implements Node {
|
||||
public String methodName;
|
||||
public List<IExpression> arguments;
|
||||
public String thisClass;
|
||||
|
||||
public ReceivingMethod(String methodName, List<IExpression> arguments) {
|
||||
this.methodName = methodName;
|
||||
@ -18,6 +21,9 @@ public class ReceivingMethod implements Node {
|
||||
}
|
||||
void checkParameters(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException {
|
||||
for (IExpression parameter : arguments){
|
||||
if(parameter instanceof LocalVarIdentifier localVarIdentifier){
|
||||
localVarIdentifier.thisClass = thisClass;
|
||||
}
|
||||
parameter.typeCheck(methodContext, typeContext, localVars);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user