forked from ballerina-platform/nballerina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowTypes.bal
41 lines (35 loc) · 1.18 KB
/
showTypes.bal
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
import ballerina/io;
import wso2/nballerina.front;
import wso2/nballerina.types as t;
// import wso2/nballerina.types.bdd;
public function showTypes(string filename) returns error? {
string[] results = check subtypeRels(filename);
foreach var line in results {
io:println(line);
}
// io:println("Total BDDs ", bdd:getCount());
}
function subtypeRels(string filename) returns string[]|error {
var [env, m] = check front:loadTypes(filename);
var tc = t:typeCheckContext(env);
var entries = from var [name, t] in m.entries() order by name select [name, t];
[string, string][] results = [];
foreach int i in 0 ..< entries.length() {
foreach int j in i + 1 ..< entries.length() {
var [name1, t1] = entries[i];
var [name2, t2] = entries[j];
if t:isSubtype(tc, t1, t2) {
results.push([name1, name2]);
}
if t:isSubtype(tc, t2, t1) {
results.push([name2, name1]);
}
}
}
string[] lines =
from var [name1, name2] in results
let string s = name1 + "<:" + name2
order by s
select s;
return lines;
}