calling newstatementexpression from localvar
This commit is contained in:
parent
e7d4a83a1d
commit
c764b710ea
@ -2,11 +2,10 @@ class Example1 {
|
|||||||
int i;
|
int i;
|
||||||
Example e;
|
Example e;
|
||||||
int m(int n){
|
int m(int n){
|
||||||
|
int x;
|
||||||
|
x = -3;
|
||||||
|
int i = 5;
|
||||||
Example e = new Example();
|
Example e = new Example();
|
||||||
e.m(1);
|
|
||||||
this.e = new Example();
|
|
||||||
this.e.m(2);
|
|
||||||
this.m(2);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,20 @@ public class LocalVarDecl extends AbstractType implements IStatement{
|
|||||||
}
|
}
|
||||||
@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 {
|
||||||
TypeCheckHelper.typeExists(this.type, new ArrayList<>(methodContext.keySet()));
|
|
||||||
|
|
||||||
|
// left
|
||||||
|
TypeCheckHelper.typeExists(this.type, new ArrayList<>(methodContext.keySet()));
|
||||||
localVars.put(this.identifier, this.type);
|
localVars.put(this.identifier, this.type);
|
||||||
|
|
||||||
|
// right part if existing
|
||||||
|
if(expression != null){
|
||||||
|
expression.typeCheck(methodContext, typeContext, localVars);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TypeCheckResult result = new TypeCheckResult();
|
TypeCheckResult result = new TypeCheckResult();
|
||||||
result.type = "void";
|
result.type = "void";
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@ public class NewStatementExpression 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 {
|
||||||
//todo testen wenn in ast vorhanden
|
|
||||||
if(!TypeCheckHelper.typeExists(className, new ArrayList<>(typeContext.keySet()))){
|
if(!TypeCheckHelper.typeExists(className, new ArrayList<>(typeContext.keySet()))){
|
||||||
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.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user