calling newstatementexpression from localvar

This commit is contained in:
Krauß, Josefine 2024-06-20 13:59:44 +02:00
parent e7d4a83a1d
commit c764b710ea
3 changed files with 12 additions and 6 deletions

View File

@ -2,11 +2,10 @@ class Example1 {
int i;
Example e;
int m(int n){
int x;
x = -3;
int i = 5;
Example e = new Example();
e.m(1);
this.e = new Example();
this.e.m(2);
this.m(2);
return 0;
}
}

View File

@ -22,12 +22,20 @@ public class LocalVarDecl extends AbstractType implements IStatement{
}
@Override
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException {
TypeCheckHelper.typeExists(this.type, new ArrayList<>(methodContext.keySet()));
// left
TypeCheckHelper.typeExists(this.type, new ArrayList<>(methodContext.keySet()));
localVars.put(this.identifier, this.type);
// right part if existing
if(expression != null){
expression.typeCheck(methodContext, typeContext, localVars);
}
TypeCheckResult result = new TypeCheckResult();
result.type = "void";
return result;
}

View File

@ -28,7 +28,6 @@ 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 TypeCheckException {
//todo testen wenn in ast vorhanden
if(!TypeCheckHelper.typeExists(className, new ArrayList<>(typeContext.keySet()))){
throw new TypeCheckException("An instance of " + className + " is created, but the type does not exist.");
}