-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASTTId.java
More file actions
46 lines (33 loc) · 1.09 KB
/
Copy pathASTTId.java
File metadata and controls
46 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.HashSet;
import java.util.Set;
public class ASTTId implements ASTType {
String id;
public ASTTId(String id) {
this.id = id;
}
@Override
public String toStr() {
return id;
}
@Override
public boolean eqt(ASTType t)
{
return (id.equals(t.toStr()));
}
@Override
public boolean subtypeOf(ASTType t, Environment<ASTType> e, Set<String> seen)
throws InterpreterError {
if (t instanceof ASTTId other && this.id.equals(other.id))
return true;
Set<String> nextSeen = new HashSet<>(seen);
String pair = this.toStr() + "<:" + t.toStr();
if (nextSeen.contains(pair)) return true;
nextSeen.add(pair);
ASTType resolvedThis = ASTTypeDef.unfold(this, e);
ASTType resolvedTarget = ASTTypeDef.unfold(t, e);
if (resolvedThis instanceof ASTTId || resolvedTarget instanceof ASTTId) {
return resolvedThis.toStr().equals(resolvedTarget.toStr());
}
return resolvedThis.subtypeOf(resolvedTarget, e, nextSeen);
}
}