-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ml
69 lines (52 loc) · 1.73 KB
/
app.ml
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
type manifest = string
module MethMap = Lib.Map.Make(String)
type params = string list
type methods = (params * Cfg.t) MethMap.t
module ClassMap = Lib.Map.Make(String)
type classes = methods ClassMap.t
type t = manifest * classes
module InitSet = Lib.Set.Make(Global)
let get_init_states app =
let (manif, c) = app in
let s_m = Site.make manif 0 in
let h0 = Heap.from_list [
(s_m, (Object.bot,
{ Arecord.listeners = Sites.bot ;
Arecord.state = State.from_list [State.Uninit];
Arecord.pending = Pending.bot;
Arecord.finished = Bool.False; }
))] in
let g0 = (h0, As.from_list [s_m]) in
InitSet.singleton g0
let fold_on_init_states f app =
InitSet.fold f (get_init_states app)
let manifest_from_string s =
s
let methods_from_list = MethMap.from_list
let classes_from_list = ClassMap.from_list
let make m c =
if ClassMap.mem m c then
(m, c)
else
failwith "App.make: The class declared in the manifest cannot be found in the app classes."
let rec methods_from_class cl =
match cl with
| [] -> MethMap.empty
| (name, p, m)::tl ->
let cfg = Cfg.from_ast_insts m in
MethMap.add name (p, cfg) (methods_from_class tl)
let rec classes_from_prog prog =
match prog with
| [] -> ClassMap.empty
| (name, c)::tl ->
let methmap = methods_from_class c in
ClassMap.add name methmap (classes_from_prog tl)
let from_ast a =
let (manif, prog) = a in
make manif (classes_from_prog prog)
let get_method app c m =
let (_, classmap) = app in
let methmap = try ClassMap.find c classmap
with Not_found -> failwith (Printf.sprintf "App.get_method: Class %s not found" c) in
try MethMap.find m methmap
with Not_found -> ([], Cfg.make 0 0 [])