Skip to content

Commit

Permalink
fix: only codegen make functions for records
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Nov 14, 2023
1 parent a5f8a68 commit db1d452
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions src/compilerlib/pb_codegen_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ let gen_record ?and_ ({ Ot.r_name; _ } as r) sc : unit =

F.line sc "}"

let gen_unit ?and_ { Ot.er_name } sc =
F.linep sc "%s make_%s = ()" (let_decl_of_and and_) er_name

let gen_struct ?and_ t sc =
let { Ot.spec; _ } = t in

Expand All @@ -53,12 +50,9 @@ let gen_struct ?and_ t sc =
| Ot.Record r ->
gen_record ?and_ r sc;
true
| Ot.Const_variant _ | Ot.Variant _ ->
| Ot.Const_variant _ | Ot.Variant _ | Ot.Unit _ ->
(* nothing for variants *)
false
| Ot.Unit u ->
gen_unit ?and_ u sc;
true
in
has_encoded

Expand All @@ -79,35 +73,15 @@ let gen_sig_record sc ({ Ot.r_name; _ } as r) =
let rn = r_name in
F.linep sc "(** [make_%s … ()] is a builder for type [%s] *)" rn rn

let gen_sig_unit sc { Ot.er_name } =
F.linep sc "val make_%s : unit" er_name;

let rn = er_name in
F.linep sc "(** [make_%s ()] is a builder for type [%s] *)" rn rn

let gen_sig ?and_:_ t sc =
let f type_name =
F.linep sc "val make_%s : unit -> %s" type_name type_name;
F.linep sc "(** [make_%s … ()] is a builder for type [%s] *)" type_name
type_name
in

let { Ot.spec; _ } = t in

let has_encoded =
match spec with
| Ot.Record r ->
gen_sig_record sc r;
true
| Ot.Variant v ->
f v.Ot.v_name;
true
| Ot.Const_variant { Ot.cv_name; _ } ->
f cv_name;
true
| Ot.Unit u ->
gen_sig_unit sc u;
true
| Ot.Variant _ | Ot.Const_variant _ | Ot.Unit _ -> false
in

has_encoded
Expand Down

0 comments on commit db1d452

Please sign in to comment.