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