Skip to content

Commit 6c4514c

Browse files
committed
Refactor/format gentype.
1 parent 6a58feb commit 6c4514c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3172
-3171
lines changed
File renamed without changes.

jscomp/bsb_exe/.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable

jscomp/bsb_helper/.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable

jscomp/bsb_helper_exe/.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable

jscomp/bsc/.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable

jscomp/cmij/.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable

jscomp/common/.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable

jscomp/core/.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable

jscomp/depends/.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable

jscomp/ext/.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable

jscomp/frontend/.ocamlformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable

jscomp/gentype/Annotation.ml

Lines changed: 99 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type import = { name : string; importPath : ImportPath.t }
1+
type import = {name: string; importPath: ImportPath.t}
22

33
type attributePayload =
44
| BoolPayload of bool
@@ -39,64 +39,61 @@ let tagIsInternLocal s = s = "internal.local"
3939
let rec getAttributePayload checkText (attributes : Typedtree.attributes) =
4040
let rec fromExpr (expr : Parsetree.expression) =
4141
match expr with
42-
| { pexp_desc = Pexp_constant (Pconst_string (s, _)) } ->
43-
Some (StringPayload s)
44-
| { pexp_desc = Pexp_constant (Pconst_integer (n, _)) } ->
45-
Some (IntPayload n)
46-
| { pexp_desc = Pexp_constant (Pconst_float (s, _)) } ->
47-
Some (FloatPayload s)
42+
| {pexp_desc = Pexp_constant (Pconst_string (s, _))} ->
43+
Some (StringPayload s)
44+
| {pexp_desc = Pexp_constant (Pconst_integer (n, _))} -> Some (IntPayload n)
45+
| {pexp_desc = Pexp_constant (Pconst_float (s, _))} -> Some (FloatPayload s)
4846
| {
49-
pexp_desc = Pexp_construct ({ txt = Lident (("true" | "false") as s) }, _);
47+
pexp_desc = Pexp_construct ({txt = Lident (("true" | "false") as s)}, _);
5048
_;
5149
} ->
52-
Some (BoolPayload (s = "true"))
53-
| { pexp_desc = Pexp_tuple exprs } ->
54-
let payloads =
55-
exprs |> List.rev
56-
|> List.fold_left
57-
(fun payloads expr ->
58-
match expr |> fromExpr with
59-
| Some payload -> payload :: payloads
60-
| None -> payloads)
61-
[]
62-
in
63-
Some (TuplePayload payloads)
64-
| { pexp_desc = Pexp_ident { txt } } -> Some (IdentPayload txt)
50+
Some (BoolPayload (s = "true"))
51+
| {pexp_desc = Pexp_tuple exprs} ->
52+
let payloads =
53+
exprs |> List.rev
54+
|> List.fold_left
55+
(fun payloads expr ->
56+
match expr |> fromExpr with
57+
| Some payload -> payload :: payloads
58+
| None -> payloads)
59+
[]
60+
in
61+
Some (TuplePayload payloads)
62+
| {pexp_desc = Pexp_ident {txt}} -> Some (IdentPayload txt)
6563
| _ -> None
6664
in
6765
match attributes with
6866
| [] -> None
69-
| ({ Asttypes.txt }, payload) :: _tl when checkText txt -> (
70-
match payload with
71-
| PStr [] -> Some UnrecognizedPayload
72-
| PStr ({ pstr_desc = Pstr_eval (expr, _) } :: _) -> expr |> fromExpr
73-
| PStr ({ pstr_desc = Pstr_extension _ } :: _) -> Some UnrecognizedPayload
74-
| PStr ({ pstr_desc = Pstr_value _ } :: _) -> Some UnrecognizedPayload
75-
| PStr ({ pstr_desc = Pstr_primitive _ } :: _) -> Some UnrecognizedPayload
76-
| PStr ({ pstr_desc = Pstr_type _ } :: _) -> Some UnrecognizedPayload
77-
| PStr ({ pstr_desc = Pstr_typext _ } :: _) -> Some UnrecognizedPayload
78-
| PStr ({ pstr_desc = Pstr_exception _ } :: _) -> Some UnrecognizedPayload
79-
| PStr ({ pstr_desc = Pstr_module _ } :: _) -> Some UnrecognizedPayload
80-
| PStr ({ pstr_desc = Pstr_recmodule _ } :: _) -> Some UnrecognizedPayload
81-
| PStr ({ pstr_desc = Pstr_modtype _ } :: _) -> Some UnrecognizedPayload
82-
| PStr ({ pstr_desc = Pstr_open _ } :: _) -> Some UnrecognizedPayload
83-
| PStr ({ pstr_desc = Pstr_class _ } :: _) -> Some UnrecognizedPayload
84-
| PStr ({ pstr_desc = Pstr_class_type _ } :: _) ->
85-
Some UnrecognizedPayload
86-
| PStr ({ pstr_desc = Pstr_include _ } :: _) -> Some UnrecognizedPayload
87-
| PStr ({ pstr_desc = Pstr_attribute _ } :: _) -> Some UnrecognizedPayload
88-
| PPat _ -> Some UnrecognizedPayload
89-
| PSig _ -> Some UnrecognizedPayload
90-
| PTyp _ -> Some UnrecognizedPayload)
67+
| ({Asttypes.txt}, payload) :: _tl when checkText txt -> (
68+
match payload with
69+
| PStr [] -> Some UnrecognizedPayload
70+
| PStr ({pstr_desc = Pstr_eval (expr, _)} :: _) -> expr |> fromExpr
71+
| PStr ({pstr_desc = Pstr_extension _} :: _) -> Some UnrecognizedPayload
72+
| PStr ({pstr_desc = Pstr_value _} :: _) -> Some UnrecognizedPayload
73+
| PStr ({pstr_desc = Pstr_primitive _} :: _) -> Some UnrecognizedPayload
74+
| PStr ({pstr_desc = Pstr_type _} :: _) -> Some UnrecognizedPayload
75+
| PStr ({pstr_desc = Pstr_typext _} :: _) -> Some UnrecognizedPayload
76+
| PStr ({pstr_desc = Pstr_exception _} :: _) -> Some UnrecognizedPayload
77+
| PStr ({pstr_desc = Pstr_module _} :: _) -> Some UnrecognizedPayload
78+
| PStr ({pstr_desc = Pstr_recmodule _} :: _) -> Some UnrecognizedPayload
79+
| PStr ({pstr_desc = Pstr_modtype _} :: _) -> Some UnrecognizedPayload
80+
| PStr ({pstr_desc = Pstr_open _} :: _) -> Some UnrecognizedPayload
81+
| PStr ({pstr_desc = Pstr_class _} :: _) -> Some UnrecognizedPayload
82+
| PStr ({pstr_desc = Pstr_class_type _} :: _) -> Some UnrecognizedPayload
83+
| PStr ({pstr_desc = Pstr_include _} :: _) -> Some UnrecognizedPayload
84+
| PStr ({pstr_desc = Pstr_attribute _} :: _) -> Some UnrecognizedPayload
85+
| PPat _ -> Some UnrecognizedPayload
86+
| PSig _ -> Some UnrecognizedPayload
87+
| PTyp _ -> Some UnrecognizedPayload)
9188
| _hd :: tl -> getAttributePayload checkText tl
9289

9390
let getGenTypeAsRenaming attributes =
9491
match attributes |> getAttributePayload tagIsGenTypeAs with
9592
| Some (StringPayload s) -> Some s
9693
| None -> (
97-
match attributes |> getAttributePayload tagIsGenType with
98-
| Some (StringPayload s) -> Some s
99-
| _ -> None)
94+
match attributes |> getAttributePayload tagIsGenType with
95+
| Some (StringPayload s) -> Some s
96+
| _ -> None)
10097
| _ -> None
10198

10299
let getBsAsRenaming attributes =
@@ -107,20 +104,19 @@ let getBsAsRenaming attributes =
107104
let getBsAsInt attributes =
108105
match attributes |> getAttributePayload tagIsBsAs with
109106
| Some (IntPayload s) -> (
110-
try Some (int_of_string s) with Failure _ -> None)
107+
try Some (int_of_string s) with Failure _ -> None)
111108
| _ -> None
112109

113110
let getAttributeImportRenaming attributes =
114111
let attributeImport = attributes |> getAttributePayload tagIsGenTypeImport in
115112
let genTypeAsRenaming = attributes |> getGenTypeAsRenaming in
116113
match (attributeImport, genTypeAsRenaming) with
117114
| Some (StringPayload importString), _ ->
118-
(Some importString, genTypeAsRenaming)
115+
(Some importString, genTypeAsRenaming)
119116
| ( Some
120-
(TuplePayload
121-
[ StringPayload importString; StringPayload renameString ]),
117+
(TuplePayload [StringPayload importString; StringPayload renameString]),
122118
_ ) ->
123-
(Some importString, Some renameString)
119+
(Some importString, Some renameString)
124120
| _ -> (None, genTypeAsRenaming)
125121

126122
let getDocString attributes =
@@ -139,41 +135,41 @@ let fromAttributes ~loc (attributes : Typedtree.attributes) =
139135
(match attributes |> getAttributePayload tagIsGenType with
140136
| Some UnrecognizedPayload -> ()
141137
| Some _ ->
142-
Log_.Color.setup ();
143-
Log_.info ~loc ~name:"Warning genType" (fun ppf () ->
144-
Format.fprintf ppf "Annotation payload is ignored")
138+
Log_.Color.setup ();
139+
Log_.info ~loc ~name:"Warning genType" (fun ppf () ->
140+
Format.fprintf ppf "Annotation payload is ignored")
145141
| _ -> ());
146142
GenType)
147143
else NoGenType
148144

149145
let rec moduleTypeCheckAnnotation ~checkAnnotation
150-
({ mty_desc } : Typedtree.module_type) =
146+
({mty_desc} : Typedtree.module_type) =
151147
match mty_desc with
152148
| Tmty_signature signature ->
153-
signature |> signatureCheckAnnotation ~checkAnnotation
149+
signature |> signatureCheckAnnotation ~checkAnnotation
154150
| Tmty_ident _ | Tmty_functor _ | Tmty_with _ | Tmty_typeof _ | Tmty_alias _
155151
->
156-
false
152+
false
157153

158154
and moduleDeclarationCheckAnnotation ~checkAnnotation
159-
({ md_attributes; md_type; md_loc = loc } : Typedtree.module_declaration) =
155+
({md_attributes; md_type; md_loc = loc} : Typedtree.module_declaration) =
160156
md_attributes |> checkAnnotation ~loc
161157
|| md_type |> moduleTypeCheckAnnotation ~checkAnnotation
162158

163159
and signatureItemCheckAnnotation ~checkAnnotation
164160
(signatureItem : Typedtree.signature_item) =
165161
match signatureItem with
166-
| { Typedtree.sig_desc = Typedtree.Tsig_type (_, typeDeclarations) } ->
167-
typeDeclarations
168-
|> List.exists
169-
(fun ({ typ_attributes; typ_loc = loc } : Typedtree.type_declaration)
170-
-> typ_attributes |> checkAnnotation ~loc)
171-
| { sig_desc = Tsig_value { val_attributes; val_loc = loc } } ->
172-
val_attributes |> checkAnnotation ~loc
173-
| { sig_desc = Tsig_module moduleDeclaration } ->
174-
moduleDeclaration |> moduleDeclarationCheckAnnotation ~checkAnnotation
175-
| { sig_desc = Tsig_attribute attribute; sig_loc = loc } ->
176-
[ attribute ] |> checkAnnotation ~loc
162+
| {Typedtree.sig_desc = Typedtree.Tsig_type (_, typeDeclarations)} ->
163+
typeDeclarations
164+
|> List.exists
165+
(fun ({typ_attributes; typ_loc = loc} : Typedtree.type_declaration) ->
166+
typ_attributes |> checkAnnotation ~loc)
167+
| {sig_desc = Tsig_value {val_attributes; val_loc = loc}} ->
168+
val_attributes |> checkAnnotation ~loc
169+
| {sig_desc = Tsig_module moduleDeclaration} ->
170+
moduleDeclaration |> moduleDeclarationCheckAnnotation ~checkAnnotation
171+
| {sig_desc = Tsig_attribute attribute; sig_loc = loc} ->
172+
[attribute] |> checkAnnotation ~loc
177173
| _ -> false
178174

179175
and signatureCheckAnnotation ~checkAnnotation (signature : Typedtree.signature)
@@ -183,46 +179,46 @@ and signatureCheckAnnotation ~checkAnnotation (signature : Typedtree.signature)
183179

184180
let rec structureItemCheckAnnotation ~checkAnnotation
185181
(structureItem : Typedtree.structure_item) =
186-
match structureItem with
187-
| { Typedtree.str_desc = Typedtree.Tstr_type (_, typeDeclarations) } ->
188-
typeDeclarations
189-
|> List.exists
190-
(fun ({ typ_attributes; typ_loc = loc } : Typedtree.type_declaration)
191-
-> typ_attributes |> checkAnnotation ~loc)
192-
| { str_desc = Tstr_value (_loc, valueBindings) } ->
193-
valueBindings
194-
|> List.exists
195-
(fun ({ vb_attributes; vb_loc = loc } : Typedtree.value_binding) ->
196-
vb_attributes |> checkAnnotation ~loc)
197-
| { str_desc = Tstr_primitive { val_attributes; val_loc = loc } } ->
198-
val_attributes |> checkAnnotation ~loc
199-
| { str_desc = Tstr_module moduleBinding } ->
200-
moduleBinding |> moduleBindingCheckAnnotation ~checkAnnotation
201-
| { str_desc = Tstr_recmodule moduleBindings } ->
202-
moduleBindings
203-
|> List.exists (moduleBindingCheckAnnotation ~checkAnnotation)
204-
| { str_desc = Tstr_include { incl_attributes; incl_mod; incl_loc = loc } } ->
205-
incl_attributes |> checkAnnotation ~loc
206-
|| incl_mod |> moduleExprCheckAnnotation ~checkAnnotation
182+
match structureItem.str_desc with
183+
| Tstr_type (_, typeDeclarations) ->
184+
typeDeclarations
185+
|> List.exists
186+
(fun ({typ_attributes; typ_loc = loc} : Typedtree.type_declaration) ->
187+
typ_attributes |> checkAnnotation ~loc)
188+
| Tstr_value (_loc, valueBindings) ->
189+
valueBindings
190+
|> List.exists
191+
(fun ({vb_attributes; vb_loc = loc} : Typedtree.value_binding) ->
192+
vb_attributes |> checkAnnotation ~loc)
193+
| Tstr_primitive {val_attributes; val_loc = loc} ->
194+
val_attributes |> checkAnnotation ~loc
195+
| Tstr_module moduleBinding ->
196+
moduleBinding |> moduleBindingCheckAnnotation ~checkAnnotation
197+
| Tstr_recmodule moduleBindings ->
198+
moduleBindings
199+
|> List.exists (moduleBindingCheckAnnotation ~checkAnnotation)
200+
| Tstr_include {incl_attributes; incl_mod; incl_loc = loc} ->
201+
incl_attributes |> checkAnnotation ~loc
202+
|| incl_mod |> moduleExprCheckAnnotation ~checkAnnotation
207203
| _ -> false
208204

209205
and moduleExprCheckAnnotation ~checkAnnotation
210206
(moduleExpr : Typedtree.module_expr) =
211207
match moduleExpr.mod_desc with
212208
| Tmod_structure structure ->
213-
structure |> structureCheckAnnotation ~checkAnnotation
209+
structure |> structureCheckAnnotation ~checkAnnotation
214210
| Tmod_constraint
215211
(moduleExpr, _moduleType, moduleTypeConstraint, _moduleCoercion) -> (
216-
moduleExpr |> moduleExprCheckAnnotation ~checkAnnotation
217-
||
218-
match moduleTypeConstraint with
219-
| Tmodtype_explicit moduleType ->
220-
moduleType |> moduleTypeCheckAnnotation ~checkAnnotation
221-
| Tmodtype_implicit -> false)
212+
moduleExpr |> moduleExprCheckAnnotation ~checkAnnotation
213+
||
214+
match moduleTypeConstraint with
215+
| Tmodtype_explicit moduleType ->
216+
moduleType |> moduleTypeCheckAnnotation ~checkAnnotation
217+
| Tmodtype_implicit -> false)
222218
| Tmod_ident _ | Tmod_functor _ | Tmod_apply _ | Tmod_unpack _ -> false
223219

224220
and moduleBindingCheckAnnotation ~checkAnnotation
225-
({ mb_expr; mb_attributes; mb_loc = loc } : Typedtree.module_binding) =
221+
({mb_expr; mb_attributes; mb_loc = loc} : Typedtree.module_binding) =
226222
mb_attributes |> checkAnnotation ~loc
227223
|| mb_expr |> moduleExprCheckAnnotation ~checkAnnotation
228224

@@ -232,7 +228,10 @@ and structureCheckAnnotation ~checkAnnotation (structure : Typedtree.structure)
232228
|> List.exists (structureItemCheckAnnotation ~checkAnnotation)
233229

234230
let sanitizeVariableName name =
235-
name |> String.map (function '-' -> '_' | c -> c)
231+
name
232+
|> String.map (function
233+
| '-' -> '_'
234+
| c -> c)
236235

237236
let importFromString importString : import =
238237
let name =
@@ -241,4 +240,4 @@ let importFromString importString : import =
241240
|> sanitizeVariableName
242241
in
243242
let importPath = ImportPath.fromStringUnsafe importString in
244-
{ name; importPath }
243+
{name; importPath}

jscomp/gentype/CodeItem.ml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
open GenTypeCommon
22

33
type exportType = {
4-
loc : Location.t;
5-
nameAs : string option;
6-
opaque : bool option;
7-
type_ : type_;
8-
typeVars : string list;
9-
resolvedTypeName : ResolvedName.t;
4+
loc: Location.t;
5+
nameAs: string option;
6+
opaque: bool option;
7+
type_: type_;
8+
typeVars: string list;
9+
resolvedTypeName: ResolvedName.t;
1010
}
1111

1212
type importValue = {
13-
asPath : string;
14-
importAnnotation : Annotation.import;
15-
type_ : type_;
16-
valueName : string;
13+
asPath: string;
14+
importAnnotation: Annotation.import;
15+
type_: type_;
16+
valueName: string;
1717
}
1818

1919
type exportValue = {
20-
docString : string;
21-
moduleAccessPath : Runtime.moduleAccessPath;
22-
originalName : string;
23-
resolvedName : ResolvedName.t;
24-
type_ : type_;
20+
docString: string;
21+
moduleAccessPath: Runtime.moduleAccessPath;
22+
originalName: string;
23+
resolvedName: ResolvedName.t;
24+
type_: type_;
2525
}
2626

2727
type exportFromTypeDeclaration = {
28-
exportType : exportType;
29-
annotation : Annotation.t;
28+
exportType: exportType;
29+
annotation: Annotation.t;
3030
}
3131

3232
type importType = {
33-
typeName : string;
34-
asTypeName : string option;
35-
importPath : ImportPath.t;
33+
typeName: string;
34+
asTypeName: string option;
35+
importPath: ImportPath.t;
3636
}
3737

3838
type exportTypeItem = {
39-
typeVars : string list;
40-
type_ : type_;
41-
annotation : Annotation.t;
39+
typeVars: string list;
40+
type_: type_;
41+
annotation: Annotation.t;
4242
}
4343

4444
type exportTypeMap = exportTypeItem StringMap.t
4545

4646
type typeDeclaration = {
47-
exportFromTypeDeclaration : exportFromTypeDeclaration;
48-
importTypes : importType list;
47+
exportFromTypeDeclaration: exportFromTypeDeclaration;
48+
importTypes: importType list;
4949
}
5050

5151
type t = ExportValue of exportValue | ImportValue of importValue
5252

5353
type translation = {
54-
importTypes : importType list;
55-
codeItems : t list;
56-
typeDeclarations : typeDeclaration list;
54+
importTypes: importType list;
55+
codeItems: t list;
56+
typeDeclarations: typeDeclaration list;
5757
}

0 commit comments

Comments
 (0)