-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbmain.bal
42 lines (38 loc) · 1.27 KB
/
bmain.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
42
import ballerina/io;
import semtype.b;
import semtype.core;
// import semtype.bdd;
public function bmain(string? f) returns error? {
string filename = f ?: "tests/data/test.bal";
string balString = check io:fileReadString(filename);
string[] results = check subtypeRels(balString);
foreach var line in results {
io:println(line);
}
// io:println("Total BDDs ", bdd:getCount());
}
function subtypeRels(string balString) returns string[]|error {
core:Env env = new;
map<core:SemType> m = check b:parse(env, balString);
var tc = core: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 core:isSubtype(tc, t1, t2) {
results.push([name1, name2]);
}
if core: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;
}