forked from facebookarchive/pfff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscope_code.ml
113 lines (99 loc) · 3.33 KB
/
scope_code.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
(* Yoann Padioleau
*
* Copyright (C) 2009-2010 Facebook
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
* license.txt for more details.
*)
open Common
(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)
(*
* It would be more convenient to move this file elsewhere like in analyse_xxx/
* but we want our AST to contain scope annotations so it's convenient to
* have the type definition of scope there.
*)
(*****************************************************************************)
(* Types *)
(*****************************************************************************)
(* todo? could use open polymorphic variant for that ? the scoping will
* be differerent for each language but they will also have stuff
* in common which may be a good spot for open polymorphic variant.
*)
type scope =
| Global
| Local
| Param
| Static
| Class
| LocalExn
| LocalIterator
(* php specific? *)
| ListBinded
(* closure, could be same as Local, but can be good to visually
* differentiate them in codemap
*)
| Closed
| NoScope
(*****************************************************************************)
(* String-of *)
(*****************************************************************************)
let string_of_scope = function
| Global -> "Global"
| Local -> "Local"
| Param -> "Param"
| Static -> "Static"
| Class -> "Class"
| LocalExn -> "LocalExn"
| LocalIterator -> "LocalIterator"
| ListBinded -> "ListBinded"
| Closed -> "Closed"
| NoScope -> "NoScope"
(*****************************************************************************)
(* Meta *)
(*****************************************************************************)
let vof_scope x =
match x with
| Global -> Ocaml.VSum (("Global", []))
| Local -> Ocaml.VSum (("Local", []))
| Param -> Ocaml.VSum (("Param", []))
| Static -> Ocaml.VSum (("Static", []))
| Class -> Ocaml.VSum (("Class", []))
| LocalExn -> Ocaml.VSum (("LocalExn", []))
| LocalIterator -> Ocaml.VSum (("LocalIterator", []))
| ListBinded -> Ocaml.VSum (("ListBinded", []))
| Closed -> Ocaml.VSum (("Closed", []))
| NoScope -> Ocaml.VSum (("NoScope", []))
let map_scope =
function
| Global -> Global
| Local -> Local
| Param -> Param
| Static -> Static
| NoScope -> NoScope
| ListBinded -> ListBinded
| LocalIterator -> LocalIterator
| LocalExn -> LocalExn
| Closed -> Closed
| Class -> Class
(* still needed ? *)
let sexp_of_scope x =
match x with
| Global -> Sexp.Atom "Global"
| Local -> Sexp.Atom "Local"
| Param -> Sexp.Atom "Param"
| Static -> Sexp.Atom "Static"
| NoScope -> Sexp.Atom "NoScope"
| ListBinded -> Sexp.Atom "ListBinded"
| LocalIterator -> Sexp.Atom "LocalIterator"
| LocalExn -> Sexp.Atom "LocalExn"
| Closed -> Sexp.Atom "Closed"
| Class -> Sexp.Atom "Class"