made upperbound method static
This commit is contained in:
parent
c764b710ea
commit
b95bc75a1e
@ -1,5 +1,6 @@
|
||||
class Example1 {
|
||||
int i;
|
||||
int a = 12345;
|
||||
Example e;
|
||||
int m(int n){
|
||||
int x;
|
||||
|
@ -4,7 +4,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class TypeCheckHelper {
|
||||
public String upperBound(String type1, String type2) throws TypeCheckException{
|
||||
public static String upperBound(String type1, String type2) throws TypeCheckException{
|
||||
boolean type1Primitiv = Objects.equals(type1, "boolean") || Objects.equals(type1, "int") || Objects.equals(type1, "char");
|
||||
boolean type2Primitiv = Objects.equals(type2, "boolean") || Objects.equals(type2, "int") || Objects.equals(type2, "char");
|
||||
|
||||
|
@ -26,7 +26,6 @@ public class BinaryExpression 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 {
|
||||
TypeCheckHelper helper = new TypeCheckHelper();
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
|
||||
TypeCheckResult leftType = left.typeCheck(methodContext, typeContext, localVars);
|
||||
@ -36,7 +35,7 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
||||
|
||||
case "&&":
|
||||
case "||" :{
|
||||
if (Objects.equals(helper.upperBound(leftType.type, rightType.type), "bool")){
|
||||
if (Objects.equals(TypeCheckHelper.upperBound(leftType.type, rightType.type), "bool")){
|
||||
result.type = "bool";
|
||||
}
|
||||
break;
|
||||
@ -47,14 +46,14 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
||||
case "<=":
|
||||
case ">=":
|
||||
case "!=":
|
||||
result.type = helper.upperBound(leftType.type, rightType.type);
|
||||
result.type = TypeCheckHelper.upperBound(leftType.type, rightType.type);
|
||||
break;
|
||||
|
||||
case "-":
|
||||
case "+":
|
||||
case "*":
|
||||
case "/":
|
||||
if (Objects.equals(helper.upperBound(leftType.type, rightType.type), "int")){
|
||||
if (Objects.equals(TypeCheckHelper.upperBound(leftType.type, rightType.type), "int")){
|
||||
result.type = "int";
|
||||
}
|
||||
break;
|
||||
|
@ -30,7 +30,6 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
||||
|
||||
@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 helper = new TypeCheckHelper();
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
|
||||
TypeCheckResult leftType;
|
||||
@ -45,7 +44,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
||||
}
|
||||
TypeCheckResult rightType = right.typeCheck(methodContext, typeContext, localVars);
|
||||
|
||||
String upperbound = helper.upperBound(leftType.type, rightType.type);
|
||||
String upperbound = TypeCheckHelper.upperBound(leftType.type, rightType.type);
|
||||
if(Objects.equals(leftType.type, "boolean"))
|
||||
leftType.type = "bool";
|
||||
if (!Objects.equals(upperbound, leftType.type)) {
|
||||
|
Loading…
Reference in New Issue
Block a user