diff options
author | Alain Frisch <alain@frisch.fr> | 2014-04-30 08:19:55 +0000 |
---|---|---|
committer | Alain Frisch <alain@frisch.fr> | 2014-04-30 08:19:55 +0000 |
commit | b791d666d824cf3dff297cf4e25bca1bde3a3109 (patch) | |
tree | 8c5ab4a3e5885c1aaa738de1245c8031a380179b | |
parent | 772a84381271f12426d5010be27c6f4bf6263b05 (diff) | |
download | ocaml-b791d666d824cf3dff297cf4e25bca1bde3a3109.tar.gz |
#6387: allow attributes on variants in polymorphic variant types.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14712 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | parsing/ast_mapper.ml | 3 | ||||
-rw-r--r-- | parsing/parser.mly | 12 | ||||
-rw-r--r-- | parsing/parsetree.mli | 4 | ||||
-rw-r--r-- | parsing/pprintast.ml | 2 | ||||
-rw-r--r-- | parsing/printast.ml | 3 | ||||
-rw-r--r-- | tools/depend.ml | 2 | ||||
-rw-r--r-- | tools/tast_iter.ml | 2 | ||||
-rw-r--r-- | tools/untypeast.ml | 4 | ||||
-rw-r--r-- | typing/printtyped.ml | 3 | ||||
-rw-r--r-- | typing/typedtree.ml | 2 | ||||
-rw-r--r-- | typing/typedtree.mli | 2 | ||||
-rw-r--r-- | typing/typedtreeIter.ml | 2 | ||||
-rw-r--r-- | typing/typedtreeMap.ml | 4 | ||||
-rw-r--r-- | typing/typetexp.ml | 4 |
14 files changed, 27 insertions, 22 deletions
diff --git a/parsing/ast_mapper.ml b/parsing/ast_mapper.ml index 4ccd13ae03..db8553807a 100644 --- a/parsing/ast_mapper.ml +++ b/parsing/ast_mapper.ml @@ -79,7 +79,8 @@ module T = struct (* Type expressions for the core language *) let row_field sub = function - | Rtag (l, b, tl) -> Rtag (l, b, List.map (sub.typ sub) tl) + | Rtag (l, attrs, b, tl) -> + Rtag (l, sub.attributes sub attrs, b, List.map (sub.typ sub) tl) | Rinherit t -> Rinherit (sub.typ sub t) let map sub {ptyp_desc = desc; ptyp_loc = loc; ptyp_attributes = attrs} = diff --git a/parsing/parser.mly b/parsing/parser.mly index f92048f9ce..ad7a47ab60 100644 --- a/parsing/parser.mly +++ b/parsing/parser.mly @@ -257,8 +257,8 @@ let varify_constructors var_names t = {t with ptyp_desc = desc} and loop_row_field = function - | Rtag(label,flag,lst) -> - Rtag(label,flag,List.map loop lst) + | Rtag(label,attrs,flag,lst) -> + Rtag(label,attrs,flag,List.map loop lst) | Rinherit t -> Rinherit (loop t) in @@ -1777,10 +1777,10 @@ row_field: | simple_core_type { Rinherit $1 } ; tag_field: - name_tag OF opt_ampersand amper_type_list - { Rtag ($1, $3, List.rev $4) } - | name_tag - { Rtag ($1, true, []) } + name_tag attributes OF opt_ampersand amper_type_list + { Rtag ($1, $2, $4, List.rev $5) } + | name_tag attributes + { Rtag ($1, $2, true, []) } ; opt_ampersand: AMPERSAND { true } diff --git a/parsing/parsetree.mli b/parsing/parsetree.mli index ce938dd897..9ecd496c83 100644 --- a/parsing/parsetree.mli +++ b/parsing/parsetree.mli @@ -115,7 +115,7 @@ and package_type = Longident.t loc * (Longident.t loc * core_type) list *) and row_field = - | Rtag of label * bool * core_type list + | Rtag of label * attributes * bool * core_type list (* [`A] ( true, [] ) [`A of T] ( false, [T] ) [`A of T1 & .. & Tn] ( false, [T1;...Tn] ) @@ -125,6 +125,8 @@ and row_field = constant (empty) constructor. - '&' occurs when several types are used for the same constructor (see 4.2 in the manual) + + - TODO: switch to a record representation, and keep location *) | Rinherit of core_type (* [ T ] *) diff --git a/parsing/pprintast.ml b/parsing/pprintast.ml index 8b156bafd1..dcc4218e66 100644 --- a/parsing/pprintast.ml +++ b/parsing/pprintast.ml @@ -286,7 +286,7 @@ class printer ()= object(self:'self) | Ptyp_variant (l, closed, low) -> let type_variant_helper f x = match x with - | Rtag (l, _, ctl) -> pp f "@[<2>%a%a@]" self#string_quot l + | Rtag (l, _attrs, _, ctl) -> pp f "@[<2>%a%a@]" self#string_quot l (fun f l -> match l with |[] -> () | _ -> pp f "@;of@;%a" diff --git a/parsing/printast.ml b/parsing/printast.ml index a8a1671b96..2b434cd160 100644 --- a/parsing/printast.ml +++ b/parsing/printast.ml @@ -823,8 +823,9 @@ and label_x_expression i ppf (l,e) = and label_x_bool_x_core_type_list i ppf x = match x with - Rtag (l, b, ctl) -> + Rtag (l, attrs, b, ctl) -> line i ppf "Rtag \"%s\" %s\n" l (string_of_bool b); + attributes (i+1) ppf attrs; list (i+1) core_type ppf ctl | Rinherit (ct) -> line i ppf "Rinherit\n"; diff --git a/tools/depend.ml b/tools/depend.ml index 5f300ae88a..a5de43737d 100644 --- a/tools/depend.ml +++ b/tools/depend.ml @@ -48,7 +48,7 @@ let rec add_type bv ty = | Ptyp_alias(t, s) -> add_type bv t | Ptyp_variant(fl, _, _) -> List.iter - (function Rtag(_,_,stl) -> List.iter (add_type bv) stl + (function Rtag(_,_,_,stl) -> List.iter (add_type bv) stl | Rinherit sty -> add_type bv sty) fl | Ptyp_poly(_, t) -> add_type bv t diff --git a/tools/tast_iter.ml b/tools/tast_iter.ml index e5bd5e56d1..4ed5c45eaf 100644 --- a/tools/tast_iter.ml +++ b/tools/tast_iter.ml @@ -302,7 +302,7 @@ let class_structure sub cs = let row_field sub rf = match rf with - | Ttag (_label, _bool, list) -> List.iter (sub # core_type) list + | Ttag (_label, _attrs, _bool, list) -> List.iter (sub # core_type) list | Tinherit ct -> sub # core_type ct let class_field sub cf = diff --git a/tools/untypeast.ml b/tools/untypeast.ml index eaf3aadf5c..caff88f299 100644 --- a/tools/untypeast.ml +++ b/tools/untypeast.ml @@ -554,8 +554,8 @@ and untype_class_structure cs = and untype_row_field rf = match rf with - Ttag (label, bool, list) -> - Rtag (label, bool, List.map untype_core_type list) + Ttag (label, attrs, bool, list) -> + Rtag (label, attrs, bool, List.map untype_core_type list) | Tinherit ct -> Rinherit (untype_core_type ct) and untype_class_field cf = diff --git a/typing/printtyped.ml b/typing/printtyped.ml index 47b637dbe1..550bb9af4b 100644 --- a/typing/printtyped.ml +++ b/typing/printtyped.ml @@ -804,8 +804,9 @@ and ident_x_loc_x_expression_def i ppf (l,_, e) = and label_x_bool_x_core_type_list i ppf x = match x with - Ttag (l, b, ctl) -> + Ttag (l, attrs, b, ctl) -> line i ppf "Rtag \"%s\" %s\n" l (string_of_bool b); + attributes (i+1) ppf attrs; list (i+1) core_type ppf ctl | Tinherit (ct) -> line i ppf "Rinherit\n"; diff --git a/typing/typedtree.ml b/typing/typedtree.ml index 76d6534a2b..5d3400d024 100644 --- a/typing/typedtree.ml +++ b/typing/typedtree.ml @@ -361,7 +361,7 @@ and package_type = { } and row_field = - Ttag of label * bool * core_type list + Ttag of label * attributes * bool * core_type list | Tinherit of core_type and value_description = diff --git a/typing/typedtree.mli b/typing/typedtree.mli index 3bc104fcce..fae6ddd334 100644 --- a/typing/typedtree.mli +++ b/typing/typedtree.mli @@ -360,7 +360,7 @@ and package_type = { } and row_field = - Ttag of label * bool * core_type list + Ttag of label * attributes * bool * core_type list | Tinherit of core_type and value_description = diff --git a/typing/typedtreeIter.ml b/typing/typedtreeIter.ml index 4681473d92..10dc7184b7 100644 --- a/typing/typedtreeIter.ml +++ b/typing/typedtreeIter.ml @@ -531,7 +531,7 @@ module MakeIterator(Iter : IteratorArgument) : sig and iter_row_field rf = match rf with - Ttag (label, bool, list) -> + Ttag (label, _attrs, bool, list) -> List.iter iter_core_type list | Tinherit ct -> iter_core_type ct diff --git a/typing/typedtreeMap.ml b/typing/typedtreeMap.ml index ddd3f5bd40..30a8e5fa3e 100644 --- a/typing/typedtreeMap.ml +++ b/typing/typedtreeMap.ml @@ -576,8 +576,8 @@ module MakeMap(Map : MapArgument) = struct and map_row_field rf = match rf with - Ttag (label, bool, list) -> - Ttag (label, bool, List.map map_core_type list) + Ttag (label, attrs, bool, list) -> + Ttag (label, attrs, bool, List.map map_core_type list) | Tinherit ct -> Tinherit (map_core_type ct) and map_class_field cf = diff --git a/typing/typetexp.ml b/typing/typetexp.ml index eacf977c65..7037380ac6 100644 --- a/typing/typetexp.ml +++ b/typing/typetexp.ml @@ -508,7 +508,7 @@ let rec transl_type env policy styp = Hashtbl.add hfields h (l,f) in let add_field = function - Rtag (l, c, stl) -> + Rtag (l, attrs, c, stl) -> name := None; let tl = List.map (transl_type env policy) stl in let f = match present with @@ -523,7 +523,7 @@ let rec transl_type env policy styp = Rpresent (Some st.ctyp_type) in add_typed_field styp.ptyp_loc l f; - Ttag (l,c,tl) + Ttag (l,attrs,c,tl) | Rinherit sty -> let cty = transl_type env policy sty in let ty = cty.ctyp_type in |