Compare commits
2 Commits
492bab5477
...
194ff3fcf7
Author | SHA1 | Date | |
---|---|---|---|
|
194ff3fcf7 | ||
|
f5dcd4d79f |
@ -60,6 +60,9 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
if(statement instanceof LocalVarDecl localVarDecl){
|
||||
localVarDecl.thisClass = thisClass;
|
||||
}
|
||||
if (statement instanceof PrintStatement printStatement) {
|
||||
printStatement.thisClass = thisClass;
|
||||
}
|
||||
|
||||
TypeCheckResult typeOfCurrentStatement = statement.typeCheck(methodContext, typeContext, localVars);
|
||||
if(statement instanceof LocalVarDecl localVarDecl){
|
||||
|
@ -8,9 +8,11 @@ import org.objectweb.asm.MethodVisitor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PrintStatement extends AbstractType implements IStatement {
|
||||
String variableName;
|
||||
public String thisClass;
|
||||
|
||||
public PrintStatement(String variableName) {
|
||||
this.variableName = variableName;
|
||||
@ -18,7 +20,16 @@ public class PrintStatement 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 {
|
||||
return null;
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
String typeOfVar = localVars.get(variableName);
|
||||
if (typeOfVar == null) {
|
||||
typeOfVar = typeContext.get(thisClass).get(variableName);
|
||||
}
|
||||
if (!Objects.equals(typeOfVar, "int"))
|
||||
throw new TypeCheckException("The variable to be printed is " + typeOfVar + " but should be int.");
|
||||
result.type = typeOfVar;
|
||||
setTypeCheckResult(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,7 +63,7 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
currentType = thisClass;
|
||||
}
|
||||
|
||||
//if classToSearchMethodIn does not conatin method, throw exception. go through list and check each
|
||||
//if classToSearchMethodIn does not contain method, throw exception. go through list and check each
|
||||
|
||||
for (int i = 0; i < receivingMethods.size(); i++) {
|
||||
currentType = (String) methodContext.get(currentType).get(receivingMethods.get(i).methodName).keySet().toArray()[0];
|
||||
|
Loading…
Reference in New Issue
Block a user