Skip to content

Commit ae7b2a0

Browse files
committed
[clean] spin off primtive in ppx
1 parent ec9568a commit ae7b2a0

File tree

11 files changed

+594
-243
lines changed

11 files changed

+594
-243
lines changed

jscomp/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ SYNTAX_SRCS= \
256256
external_process\
257257
ast_util\
258258
ast_tdcls\
259+
ast_primitive\
259260
ast_exp_apply\
260261
ast_exp_extension\
261262
ast_core_type_class_type\

jscomp/all.depend

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ syntax/ast_tdcls.cmx : ext/ext_list.cmx syntax/bs_ast_mapper.cmx \
243243
syntax/ast_structure.cmx syntax/ast_signature.cmx syntax/ast_payload.cmx \
244244
syntax/ast_derive_abstract.cmx syntax/ast_derive.cmx \
245245
syntax/ast_attributes.cmx syntax/ast_tdcls.cmi
246+
syntax/ast_primitive.cmx : syntax/external_process.cmx \
247+
syntax/bs_ast_mapper.cmx syntax/ast_primitive.cmi
246248
syntax/ast_exp_apply.cmx : ext/literals.cmx ext/ext_list.cmx \
247249
syntax/bs_ast_mapper.cmx syntax/bs_ast_invariant.cmx syntax/ast_util.cmx \
248250
syntax/ast_literal.cmx syntax/ast_attributes.cmx syntax/ast_exp_apply.cmi
@@ -257,14 +259,14 @@ syntax/ast_core_type_class_type.cmx : ext/literals.cmx ext/ext_ref.cmx \
257259
syntax/ast_tuple_pattern_flatten.cmx : ext/ext_list.cmx \
258260
syntax/bs_ast_mapper.cmx syntax/ast_tuple_pattern_flatten.cmi
259261
syntax/ppx_entry.cmx : ext/string_map.cmx ext/literals.cmx \
260-
syntax/external_process.cmx ext/ext_string.cmx syntax/bs_ast_mapper.cmx \
261-
syntax/bs_ast_invariant.cmx syntax/ast_util.cmx \
262-
syntax/ast_utf8_string_interp.cmx syntax/ast_utf8_string.cmx \
263-
syntax/ast_tuple_pattern_flatten.cmx syntax/ast_tdcls.cmx \
264-
syntax/ast_payload.cmx syntax/ast_exp_extension.cmx \
265-
syntax/ast_exp_apply.cmx syntax/ast_derive_projector.cmx \
266-
syntax/ast_derive_js_mapper.cmx syntax/ast_core_type_class_type.cmx \
267-
syntax/ast_attributes.cmx syntax/ppx_entry.cmi
262+
ext/ext_string.cmx syntax/bs_ast_mapper.cmx syntax/bs_ast_invariant.cmx \
263+
syntax/ast_util.cmx syntax/ast_utf8_string_interp.cmx \
264+
syntax/ast_utf8_string.cmx syntax/ast_tuple_pattern_flatten.cmx \
265+
syntax/ast_tdcls.cmx syntax/ast_primitive.cmx syntax/ast_payload.cmx \
266+
syntax/ast_exp_extension.cmx syntax/ast_exp_apply.cmx \
267+
syntax/ast_derive_projector.cmx syntax/ast_derive_js_mapper.cmx \
268+
syntax/ast_core_type_class_type.cmx syntax/ast_attributes.cmx \
269+
syntax/ppx_entry.cmi
268270
syntax/bs_syntaxerr.cmi :
269271
syntax/ast_utf8_string.cmi :
270272
syntax/ast_utf8_string_interp.cmi :
@@ -297,6 +299,7 @@ syntax/external_process.cmi : common/bs_loc.cmi syntax/ast_core_type.cmi \
297299
syntax/ast_util.cmi : syntax/bs_ast_mapper.cmi syntax/ast_payload.cmi
298300
syntax/ast_tdcls.cmi : syntax/bs_ast_mapper.cmi syntax/ast_structure.cmi \
299301
syntax/ast_signature.cmi
302+
syntax/ast_primitive.cmi : syntax/bs_ast_mapper.cmi
300303
syntax/ast_exp_apply.cmi : syntax/bs_ast_mapper.cmi
301304
syntax/ast_exp_extension.cmi : syntax/bs_ast_mapper.cmi
302305
syntax/ast_core_type_class_type.cmi : syntax/bs_ast_mapper.cmi
@@ -765,13 +768,15 @@ super_errors/super_main.cmx : super_errors/super_typetexp.cmx \
765768
super_errors/super_env.cmx
766769
super_errors/super_reason_react.cmi :
767770
super_errors/super_misc.cmi :
768-
outcome_printer/reason_syntax_util.cmx :
771+
outcome_printer/reason_syntax_util.cmx : \
772+
outcome_printer/reason_syntax_util.cmi
769773
outcome_printer/outcome_printer_ns.cmx : ext/ext_namespace.cmx \
770774
outcome_printer/outcome_printer_ns.cmi
771775
outcome_printer/tweaked_reason_oprint.cmx : \
772776
outcome_printer/reason_syntax_util.cmx
773777
outcome_printer/reason_outcome_printer_main.cmx : \
774778
outcome_printer/tweaked_reason_oprint.cmx
779+
outcome_printer/reason_syntax_util.cmi :
775780
outcome_printer/outcome_printer_ns.cmi :
776781
ounit_tests/ounit_cmd_util.cmi :
777782
ounit_tests/ounit_tests_main.cmi :

jscomp/syntax/ast_primitive.ml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
(* Copyright (C) 2018 Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
26+
let handlePrimitiveInSig
27+
(self : Bs_ast_mapper.mapper)
28+
({pval_attributes;
29+
pval_type;
30+
pval_loc;
31+
pval_prim;
32+
pval_name ;
33+
} as prim : Parsetree.value_description)
34+
(sigi : Parsetree.signature_item)
35+
: Parsetree.signature_item
36+
=
37+
let pval_type = self.typ self pval_type in
38+
let pval_attributes = self.attributes self pval_attributes in
39+
let pval_type, pval_prim, pval_attributes =
40+
match pval_prim with
41+
| [ v ] ->
42+
External_process.handle_attributes_as_string
43+
pval_loc
44+
pval_name.txt
45+
pval_type
46+
pval_attributes v
47+
| _ ->
48+
Location.raise_errorf
49+
~loc:pval_loc
50+
"only a single string is allowed in bs external" in
51+
{sigi with
52+
psig_desc =
53+
Psig_value
54+
{prim with
55+
pval_type ;
56+
pval_prim ;
57+
pval_attributes
58+
}}
59+
60+
let handlePrimitiveInStru
61+
(self : Bs_ast_mapper.mapper)
62+
({pval_attributes;
63+
pval_prim;
64+
pval_type;
65+
pval_name;
66+
pval_loc} as prim : Parsetree.value_description)
67+
(str : Parsetree.structure_item)
68+
: Parsetree.structure_item =
69+
let pval_type = self.typ self pval_type in
70+
let pval_attributes = self.attributes self pval_attributes in
71+
let pval_type, pval_prim, pval_attributes =
72+
match pval_prim with
73+
| [ v] ->
74+
External_process.handle_attributes_as_string
75+
pval_loc
76+
pval_name.txt
77+
pval_type pval_attributes v
78+
79+
| _ -> Location.raise_errorf
80+
~loc:pval_loc "only a single string is allowed in bs external" in
81+
{str with
82+
pstr_desc =
83+
Pstr_primitive
84+
{prim with
85+
pval_type ;
86+
pval_prim;
87+
pval_attributes
88+
}}

jscomp/syntax/ast_primitive.mli

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(* Copyright (C) 2018 Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
26+
val handlePrimitiveInSig:
27+
Bs_ast_mapper.mapper ->
28+
Parsetree.value_description ->
29+
Parsetree.signature_item ->
30+
Parsetree.signature_item
31+
32+
val handlePrimitiveInStru:
33+
Bs_ast_mapper.mapper ->
34+
Parsetree.value_description ->
35+
Parsetree.structure_item ->
36+
Parsetree.structure_item
37+

jscomp/syntax/ppx_entry.ml

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -192,38 +192,10 @@ let rec unsafe_mapper : Bs_ast_mapper.mapper =
192192
match sigi.psig_desc with
193193
| Psig_type (_ :: _ as tdcls) ->
194194
Ast_tdcls.handleTdclsInSigi self sigi tdcls
195-
| Psig_value
196-
({pval_attributes;
197-
pval_type;
198-
pval_loc;
199-
pval_prim;
200-
pval_name ;
201-
} as prim)
202-
when Ast_attributes.process_external pval_attributes
195+
| Psig_value prim
196+
when Ast_attributes.process_external prim.pval_attributes
203197
->
204-
let pval_type = self.typ self pval_type in
205-
let pval_attributes = self.attributes self pval_attributes in
206-
let pval_type, pval_prim, pval_attributes =
207-
match pval_prim with
208-
| [ v ] ->
209-
External_process.handle_attributes_as_string
210-
pval_loc
211-
pval_name.txt
212-
pval_type
213-
pval_attributes v
214-
| _ ->
215-
Location.raise_errorf
216-
~loc:pval_loc
217-
"only a single string is allowed in bs external" in
218-
{sigi with
219-
psig_desc =
220-
Psig_value
221-
{prim with
222-
pval_type ;
223-
pval_prim ;
224-
pval_attributes
225-
}}
226-
198+
Ast_primitive.handlePrimitiveInSig self prim sigi
227199
| _ -> Bs_ast_mapper.default_mapper.signature_item self sigi
228200
end;
229201
pat = begin fun self (pat : Parsetree.pattern) ->
@@ -241,34 +213,10 @@ let rec unsafe_mapper : Bs_ast_mapper.mapper =
241213
Ast_util.handle_raw_structure loc payload
242214
| Pstr_type (_ :: _ as tdcls ) (* [ {ptype_attributes} as tdcl ] *)->
243215
Ast_tdcls.handleTdclsInStru self str tdcls
244-
| Pstr_primitive
245-
({pval_attributes;
246-
pval_prim;
247-
pval_type;
248-
pval_name;
249-
pval_loc} as prim)
250-
when Ast_attributes.process_external pval_attributes
216+
| Pstr_primitive prim
217+
when Ast_attributes.process_external prim.pval_attributes
251218
->
252-
let pval_type = self.typ self pval_type in
253-
let pval_attributes = self.attributes self pval_attributes in
254-
let pval_type, pval_prim, pval_attributes =
255-
match pval_prim with
256-
| [ v] ->
257-
External_process.handle_attributes_as_string
258-
pval_loc
259-
pval_name.txt
260-
pval_type pval_attributes v
261-
262-
| _ -> Location.raise_errorf
263-
~loc:pval_loc "only a single string is allowed in bs external" in
264-
{str with
265-
pstr_desc =
266-
Pstr_primitive
267-
{prim with
268-
pval_type ;
269-
pval_prim;
270-
pval_attributes
271-
}}
219+
Ast_primitive.handlePrimitiveInStru self prim str
272220
| _ -> Bs_ast_mapper.default_mapper.structure_item self str
273221
end
274222
end

lib/bsdep.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
../lib/bsdep.ml : ./ext/string_hash_set.mli
7676
../lib/bsdep.ml : ./syntax/ast_core_type.ml
7777
../lib/bsdep.ml : ./syntax/ast_exp_apply.ml
78+
../lib/bsdep.ml : ./syntax/ast_primitive.ml
7879
../lib/bsdep.ml : ./syntax/ast_signature.ml
7980
../lib/bsdep.ml : ./syntax/ast_structure.ml
8081
../lib/bsdep.ml : ./syntax/bs_ast_mapper.ml
@@ -92,6 +93,7 @@
9293
../lib/bsdep.ml : ./syntax/ast_attributes.ml
9394
../lib/bsdep.ml : ./syntax/ast_core_type.mli
9495
../lib/bsdep.ml : ./syntax/ast_exp_apply.mli
96+
../lib/bsdep.ml : ./syntax/ast_primitive.mli
9597
../lib/bsdep.ml : ./syntax/ast_signature.mli
9698
../lib/bsdep.ml : ./syntax/ast_structure.mli
9799
../lib/bsdep.ml : ./syntax/bs_ast_mapper.mli

0 commit comments

Comments
 (0)