16
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
17
*)
18
18
19
- (* Author: Hongbo Zhang *)
19
+ (* Author: Rahul Kumar *)
20
20
open Ast_mapper
21
21
open Ast_helper
22
22
open Asttypes
@@ -34,7 +34,8 @@ type indication =
34
34
let compare_indication : indication -> indication -> int = compare
35
35
36
36
(* Given an attribute string, determine the indications *)
37
- let classify_indication name = match name with
37
+ let classify_indication name =
38
+ match name with
38
39
| "r" -> [Indication_read ]
39
40
| "w" -> [Indication_write ]
40
41
| "rw" -> [Indication_read ;Indication_write ]
@@ -44,7 +45,7 @@ let classify_indication name = match name with
44
45
(* Get unique indications from an attribute list *)
45
46
let indications_of_attr attrlst =
46
47
List. sort_uniq compare_indication (List. concat
47
- (List. map (fun ({txt =x ;_} ,_ ) -> classify_indication x) attrlst))
48
+ (List. map (fun ({txt =x ;_} ,_ ) -> classify_indication x) attrlst))
48
49
49
50
(* Define the methods generated by this ppx extension *)
50
51
type methods =
@@ -97,7 +98,8 @@ let filter_attributes attrlst = List.filter
97
98
let strip_attr t = {t with ptyp_attributes= filter_attributes t.ptyp_attributes}
98
99
99
100
(* Count the arity of a core_type *)
100
- let rec count_arity z = match z with
101
+ let rec count_arity z =
102
+ match z with
101
103
| {ptyp_desc = Ptyp_arrow (_ ,_ ,y );_} -> 1 + (count_arity y)
102
104
| _ -> 0
103
105
@@ -106,18 +108,23 @@ let is_non_nullary_fn z = (count_arity z) > 0
106
108
107
109
(* Produce a new core_type from the given core_type, removing 'opt/option/def'
108
110
from the return type*)
109
- let rec optless typ loc prefix = match typ with
110
- | {ptyp_desc = Ptyp_constr ({txt= (Lident (" opt" | " def" | " option" )) |
111
- (Ldot (Lident " Js" ,(" opt" | " def" | " option" )));_},[x]);_} -> x
111
+ let rec optless typ loc prefix =
112
+ match typ with
113
+ | {ptyp_desc =
114
+ Ptyp_constr ({txt=
115
+ (Lident (" opt" | " def" | " opt_def" )) |
116
+ (Ldot (Lident " Js" ,
117
+ (" opt" | " def" | " opt_def" )));_},[x]);_} -> x
112
118
| {ptyp_desc = Ptyp_arrow (tag ,t1 ,t2 );_} as t_ ->
113
- {t_ with ptyp_desc = Ptyp_arrow (tag,t1,optless t2 loc prefix)}
119
+ {t_ with ptyp_desc = Ptyp_arrow (tag,t1,optless t2 loc prefix)}
114
120
| _ -> begin
115
121
pwarn loc true (prefix^ " indication provided for non-option type." );
116
122
typ
117
123
end
118
124
119
125
(* Generate method signature with appropriate warnings/checks *)
120
- let gen_method loc original abs vis name attr typ meth = match meth with
126
+ let gen_method loc original abs vis name attr typ meth =
127
+ match meth with
121
128
| Method_read -> begin
122
129
let () = pwarn loc (is_non_nullary_fn typ)
123
130
" Read indication provided for non-property."
@@ -184,7 +191,8 @@ let new_methods m =
184
191
| _ -> [m]
185
192
186
193
(* Map class_type_declaration for FFI *)
187
- let new_ctd mapper ctd = match ctd with
194
+ let new_ctd mapper ctd =
195
+ match ctd with
188
196
| { pci_name= name;
189
197
pci_expr =
190
198
{ pcty_desc = Pcty_signature (
@@ -193,9 +201,9 @@ let new_ctd mapper ctd = match ctd with
193
201
pci_attributes = attrlst
194
202
} as c ->
195
203
{ c with pci_expr =
196
- { expr with pcty_desc = Pcty_signature
197
- { flds with pcsig_fields =
198
- (List. concat (List. map new_methods methodlst)) } };
204
+ { expr with pcty_desc = Pcty_signature
205
+ { flds with pcsig_fields =
206
+ (List. concat (List. map new_methods methodlst)) } };
199
207
}
200
208
| _ -> default_mapper.class_type_declaration mapper ctd
201
209
0 commit comments