Skip to content

Commit

Permalink
camlp4: Printers are warning free
Browse files Browse the repository at this point in the history
* Turn some constant values into constant methods
* Remove some unused variables

git-svn-id: http://caml.inria.fr/svn/ocaml/version/3.12@10562 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information
pouillar committed Jun 12, 2010
1 parent 2350ab3 commit 375c832
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
1 change: 0 additions & 1 deletion _tags
Expand Up @@ -35,7 +35,6 @@ true: use_stdlib
"camlp4/Camlp4_import.ml": -warn_Z
<camlp4/build/*> or <camlp4/boot/*> or "camlp4/Camlp4/Struct/Lexer.ml": -camlp4boot, -warn_Z, warn_a
<camlp4/Camlp4Bin.{byte,native}> or <camlp4/{mkcamlp4,boot/camlp4boot}.byte>: use_dynlink
"camlp4/Camlp4/Printers/OCaml.ml" or "camlp4/Camlp4/Printers/OCamlr.ml": -warn_Z, warn_v
<camlp4/Camlp4Printers/**.ml>: include_unix
"camlp4/Camlp4/Struct/DynLoader.ml" or "camlp4/boot/Camlp4.ml": include_dynlink
<camlp4/Camlp4Top/**>: include_toplevel
Expand Down
33 changes: 17 additions & 16 deletions camlp4/Camlp4/Printers/OCaml.ml
Expand Up @@ -56,7 +56,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
fun
[ Ast.LNil -> []
| Ast.LCons x xs -> [x :: list_of_meta_list xs]
| Ast.LAnt x -> assert False ];
| Ast.LAnt _ -> assert False ];

value meta_list elt sep f mxs =
let xs = list_of_meta_list mxs in
Expand Down Expand Up @@ -169,13 +169,14 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
method reset = {< pipe = False; semi = False >};

value semisep : sep = ";;";
value andsep : sep = "@]@ @[<2>and@ ";
value value_val = "val";
value value_let = "let";
value mode = if comments then `comments else `no_comments;
value curry_constr = init_curry_constr;
value var_conversion = False;

method andsep : sep = "@]@ @[<2>and@ ";
method value_val = "val";
method value_let = "let";

method semisep = semisep;
method set_semisep s = {< semisep = s >};
method set_comments b = {< mode = if b then `comments else `no_comments >};
Expand Down Expand Up @@ -299,7 +300,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
match bi with
[ <:binding<>> -> ()
| <:binding< $b1$ and $b2$ >> ->
do { o#binding f b1; pp f andsep; o#binding f b2 }
do { o#binding f b1; pp f o#andsep; o#binding f b2 }
| <:binding< $p$ = $e$ >> ->
let (pl, e) =
match p with
Expand Down Expand Up @@ -399,7 +400,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
pp f "@[<2>%a :@ %a@]" o#var s o#module_type mt
| <:module_binding< $mb1$ and $mb2$ >> ->
do { o#module_rec_binding f mb1;
pp f andsep;
pp f o#andsep;
o#module_rec_binding f mb2 }
| <:module_binding< $anti:s$ >> -> o#anti f s ];

Expand Down Expand Up @@ -803,7 +804,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
pp f "@[<hv0>@[<hv2>type %a@]%(%)@]" o#ctyp t semisep
| <:sig_item< value $s$ : $t$ >> ->
pp f "@[<2>%s %a :@ %a%(%)@]"
value_val o#var s o#ctyp t semisep
o#value_val o#var s o#ctyp t semisep
| <:sig_item< include $mt$ >> ->
pp f "@[<2>include@ %a%(%)@]" o#module_type mt semisep
| <:sig_item< class type $ct$ >> ->
Expand Down Expand Up @@ -855,7 +856,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| <:str_item< type $t$ >> ->
pp f "@[<hv0>@[<hv2>type %a@]%(%)@]" o#ctyp t semisep
| <:str_item< value $rec:r$ $bi$ >> ->
pp f "@[<2>%s %a%a%(%)@]" value_let o#rec_flag r o#binding bi semisep
pp f "@[<2>%s %a%a%(%)@]" o#value_let o#rec_flag r o#binding bi semisep
| <:str_item< $exp:e$ >> ->
pp f "@[<2>let _ =@ %a%(%)@]" o#expr e semisep
| <:str_item< include $me$ >> ->
Expand Down Expand Up @@ -898,7 +899,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| <:with_constr< module $i1$ := $i2$ >> ->
pp f "@[<2>module@ %a :=@ %a@]" o#ident i1 o#ident i2
| <:with_constr< $wc1$ and $wc2$ >> ->
do { o#with_constraint f wc1; pp f andsep; o#with_constraint f wc2 }
do { o#with_constraint f wc1; pp f o#andsep; o#with_constraint f wc2 }
| <:with_constr< $anti:s$ >> -> o#anti f s ];

method module_expr f me =
Expand All @@ -925,9 +926,9 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| <:module_expr< ( $me$ : $mt$ ) >> ->
pp f "@[<1>(%a :@ %a)@]" o#module_expr me o#module_type mt
| <:module_expr< (value $e$ : $mt$ ) >> ->
pp f "@[<1>(%s %a :@ %a)@]" value_val o#expr e o#module_type mt
pp f "@[<1>(%s %a :@ %a)@]" o#value_val o#expr e o#module_type mt
| <:module_expr< (value $e$ ) >> ->
pp f "@[<1>(%s %a)@]" value_val o#expr e
pp f "@[<1>(%s %a)@]" o#value_val o#expr e
];

method class_expr f ce =
Expand Down Expand Up @@ -957,7 +958,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
pp f "@[<1>(%a :@ %a)@]" o#class_expr ce o#class_type ct
| <:class_expr< $anti:s$ >> -> o#anti f s
| <:class_expr< $ce1$ and $ce2$ >> ->
do { o#class_expr f ce1; pp f andsep; o#class_expr f ce2 }
do { o#class_expr f ce1; pp f o#andsep; o#class_expr f ce2 }
| <:class_expr< $ce1$ = fun $p$ -> $ce2$ >> when is_irrefut_patt p ->
pp f "@[<2>%a@ %a" o#class_expr ce1
o#patt_class_expr_fun_args (p, ce2)
Expand Down Expand Up @@ -985,7 +986,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
o#ctyp t o#class_sig_item csg
| <:class_type< $anti:s$ >> -> o#anti f s
| <:class_type< $ct1$ and $ct2$ >> ->
do { o#class_type f ct1; pp f andsep; o#class_type f ct2 }
do { o#class_type f ct1; pp f o#andsep; o#class_type f ct2 }
| <:class_type< $ct1$ : $ct2$ >> ->
pp f "%a :@ %a" o#class_type ct1 o#class_type ct2
| <:class_type< $ct1$ = $ct2$ >> ->
Expand Down Expand Up @@ -1013,7 +1014,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
o#private_flag pr o#var s o#ctyp t semisep
| <:class_sig_item< value $mutable:mu$ $virtual:vi$ $s$ : $t$ >> ->
pp f "@[<2>%s %a%a%a :@ %a%(%)@]"
value_val o#mutable_flag mu o#virtual_flag vi o#var s o#ctyp t
o#value_val o#mutable_flag mu o#virtual_flag vi o#var s o#ctyp t
semisep
| <:class_sig_item< $anti:s$ >> ->
pp f "%a%(%)" o#anti s semisep ];
Expand Down Expand Up @@ -1046,10 +1047,10 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
o#private_flag pr o#var s o#ctyp t semisep
| <:class_str_item< value virtual $mutable:mu$ $s$ : $t$ >> ->
pp f "@[<2>%s virtual %a%a :@ %a%(%)@]"
value_val o#mutable_flag mu o#var s o#ctyp t semisep
o#value_val o#mutable_flag mu o#var s o#ctyp t semisep
| <:class_str_item< value $override:ov$ $mutable:mu$ $s$ = $e$ >> ->
pp f "@[<2>%s%a %a%a =@ %a%(%)@]"
value_val o#override_flag ov o#mutable_flag mu o#var s o#expr e semisep
o#value_val o#override_flag ov o#mutable_flag mu o#var s o#expr e semisep
| <:class_str_item< $anti:s$ >> ->
pp f "%a%(%)" o#anti s semisep ];

Expand Down
5 changes: 3 additions & 2 deletions camlp4/Camlp4/Printers/OCaml.mli
Expand Up @@ -68,8 +68,9 @@ module Make (Syntax : Sig.Camlp4Syntax) : sig
value pipe : bool;
value semi : bool;
value semisep : sep;
value value_val : string;
value value_let : string;
method value_val : string;
method value_let : string;
method andsep : sep;
method anti : formatter -> string -> unit;
method class_declaration :
formatter -> Ast.class_expr -> unit;
Expand Down
8 changes: 4 additions & 4 deletions camlp4/Camlp4/Printers/OCamlr.ml
Expand Up @@ -43,14 +43,14 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
object (o)
inherit PP_o.printer ~curry_constr:init_curry_constr ~comments () as super;

value semisep : sep = ";";
value andsep : sep = "@]@ @[<2>and@ ";
value value_val = "value";
value value_let = "value";
value! semisep : sep = ";";
value mode = if comments then `comments else `no_comments;
value curry_constr = init_curry_constr;
value first_match_case = True;

method andsep : sep = "@]@ @[<2>and@ ";
method value_val = "value";
method value_let = "value";
method under_pipe = o;
method under_semi = o;
method reset_semi = o;
Expand Down

0 comments on commit 375c832

Please sign in to comment.