2024-05-02 11:12:39 +00:00
|
|
|
package TypeCheck;
|
|
|
|
|
2024-05-08 09:22:12 +00:00
|
|
|
import java.util.List;
|
2024-05-02 11:12:39 +00:00
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
public class TypeCheckHelper {
|
|
|
|
public String upperBound(String type1, String type2) throws Exception{
|
|
|
|
boolean type1Primitiv = Objects.equals(type1, "bool") || Objects.equals(type1, "int") || Objects.equals(type1, "char");
|
|
|
|
boolean type2Primitiv = Objects.equals(type2, "bool") || Objects.equals(type2, "int") || Objects.equals(type2, "char");
|
|
|
|
|
|
|
|
String result;
|
|
|
|
if(type1Primitiv && type2Primitiv){
|
|
|
|
if(Objects.equals(type1, type2)){
|
|
|
|
result = type1;
|
|
|
|
}
|
|
|
|
throw new Exception("no upper bound");
|
|
|
|
}else if(type1Primitiv || type2Primitiv){
|
|
|
|
throw new Exception("no upper bound");
|
|
|
|
}else{
|
|
|
|
result = "class";
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2024-05-08 09:22:12 +00:00
|
|
|
public static boolean typeExists(String type, List<String> typeslist) {
|
|
|
|
|
|
|
|
if(type.equals("int") || type.equals("bool") || type.equals("char")){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return typeslist.contains(type);
|
|
|
|
}
|
|
|
|
|
2024-05-02 11:12:39 +00:00
|
|
|
}
|