-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy pathScope.ml
136 lines (123 loc) · 3.57 KB
/
Scope.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
type item = SharedTypes.ScopeTypes.item
type t = item list
open SharedTypes.ScopeTypes
let itemToString item =
let str s = if s = "" then "\"\"" else s in
let list l = "[" ^ (l |> List.map str |> String.concat ", ") ^ "]" in
match item with
| Constructor (s, loc) -> "Constructor " ^ s ^ " " ^ Loc.toString loc
| Field (s, loc) -> "Field " ^ s ^ " " ^ Loc.toString loc
| Open sl -> "Open " ^ list sl
| Module (s, loc) -> "Module " ^ s ^ " " ^ Loc.toString loc
| Value (s, loc, _, _) -> "Value " ^ s ^ " " ^ Loc.toString loc
| Type (s, loc) -> "Type " ^ s ^ " " ^ Loc.toString loc
[@@live]
let create () : t = []
let addConstructor ~name ~loc x = Constructor (name, loc) :: x
let addField ~name ~loc x = Field (name, loc) :: x
let addModule ~name ~loc x = Module (name, loc) :: x
let addOpen ~lid x = Open (Utils.flattenLongIdent lid @ ["place holder"]) :: x
let addValue ~name ~loc ?contextPath x =
let showDebug = !Cfg.debugFollowCtxPath in
(if showDebug then
match contextPath with
| None -> Printf.printf "adding value '%s', no ctxPath\n" name
| Some contextPath ->
if showDebug then
Printf.printf "adding value '%s' with ctxPath: %s\n" name
(SharedTypes.Completable.contextPathToString contextPath));
Value (name, loc, contextPath, x) :: x
let addType ~name ~loc x = Type (name, loc) :: x
let iterValuesBeforeFirstOpen f x =
let rec loop items =
match items with
| Value (s, loc, contextPath, scope) :: rest ->
f s loc contextPath scope;
loop rest
| Open _ :: _ -> ()
| _ :: rest -> loop rest
| [] -> ()
in
loop x
let iterValuesAfterFirstOpen f x =
let rec loop foundOpen items =
match items with
| Value (s, loc, contextPath, scope) :: rest ->
if foundOpen then f s loc contextPath scope;
loop foundOpen rest
| Open _ :: rest -> loop true rest
| _ :: rest -> loop foundOpen rest
| [] -> ()
in
loop false x
let iterConstructorsBeforeFirstOpen f x =
let rec loop items =
match items with
| Constructor (s, loc) :: rest ->
f s loc;
loop rest
| Open _ :: _ -> ()
| _ :: rest -> loop rest
| [] -> ()
in
loop x
let iterConstructorsAfterFirstOpen f x =
let rec loop foundOpen items =
match items with
| Constructor (s, loc) :: rest ->
if foundOpen then f s loc;
loop foundOpen rest
| Open _ :: rest -> loop true rest
| _ :: rest -> loop foundOpen rest
| [] -> ()
in
loop false x
let iterTypesBeforeFirstOpen f x =
let rec loop items =
match items with
| Type (s, loc) :: rest ->
f s loc;
loop rest
| Open _ :: _ -> ()
| _ :: rest -> loop rest
| [] -> ()
in
loop x
let iterTypesAfterFirstOpen f x =
let rec loop foundOpen items =
match items with
| Type (s, loc) :: rest ->
if foundOpen then f s loc;
loop foundOpen rest
| Open _ :: rest -> loop true rest
| _ :: rest -> loop foundOpen rest
| [] -> ()
in
loop false x
let iterModulesBeforeFirstOpen f x =
let rec loop items =
match items with
| Module (s, loc) :: rest ->
f s loc;
loop rest
| Open _ :: _ -> ()
| _ :: rest -> loop rest
| [] -> ()
in
loop x
let iterModulesAfterFirstOpen f x =
let rec loop foundOpen items =
match items with
| Module (s, loc) :: rest ->
if foundOpen then f s loc;
loop foundOpen rest
| Open _ :: rest -> loop true rest
| _ :: rest -> loop foundOpen rest
| [] -> ()
in
loop false x
let getRawOpens x =
x
|> Utils.filterMap (function
| Open path -> Some path
| _ -> None)