-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTType.java
More file actions
21 lines (18 loc) · 841 Bytes
/
Copy pathASTType.java
File metadata and controls
21 lines (18 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public interface ASTType {
String toStr();
public boolean eqt(ASTType t);
default boolean subtypeOf(ASTType t, Environment<ASTType> e) throws InterpreterError {
return subtypeOf(t, e, new java.util.HashSet<>());
}
boolean subtypeOf(ASTType t, Environment<ASTType> e, java.util.Set<String> seen) throws InterpreterError;
default ASTType computeLUB(ASTType other, Environment<ASTType> e) throws TypeCheckError, InterpreterError {
ASTType t1 = ASTTypeDef.unfold(this, e);
ASTType t2 = ASTTypeDef.unfold(other, e);
if (t1.subtypeOf(t2, e)) return t2;
if (t2.subtypeOf(t1, e)) return t1;
if (t2 instanceof ASTTEnum) {
return t2.computeLUB(t1, e);
}
throw new TypeCheckError("Incompatible types: " + t1.toStr() + " vs " + t2.toStr());
}
}