From 3c0fa55426e61884a8a67661025cc7a32ecc77ac Mon Sep 17 00:00:00 2001 From: herbelin Date: Sat, 16 Jul 2011 20:35:26 +0000 Subject: This adds two option tables 'Printing Record' and 'Printing Constructor' that forces a given type to always be printed as a record, or with a constructor, regardless of the setting of 'Printing Records'. And this is that patch that controls printing by type. (patch from Tom Prince) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@14286 85f007b7-540e-0410-9357-904b9bb8a0f7 --- interp/constrextern.ml | 53 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'interp') diff --git a/interp/constrextern.ml b/interp/constrextern.ml index f23f9750cb..fa92f9221c 100644 --- a/interp/constrextern.ml +++ b/interp/constrextern.ml @@ -73,6 +73,49 @@ let with_universes f = Flags.with_option print_universes f let without_symbols f = Flags.with_option print_no_symbol f let with_meta_as_hole f = Flags.with_option print_meta_as_hole f +(**********************************************************************) +(* Control printing of records *) + +let is_record indsp = + try + let _ = Recordops.lookup_structure indsp in + true + with Not_found -> false + +let encode_record r = + let indsp = global_inductive r in + if not (is_record indsp) then + user_err_loc (loc_of_reference r,"encode_record", + str "This type is not a structure type."); + indsp + +module PrintingRecordRecord = + PrintingInductiveMake (struct + let encode = encode_record + let field = "Record" + let title = "Types leading to pretty-printing using record notation: " + let member_message s b = + str "Terms of " ++ s ++ + str + (if b then " are printed using record notation" + else " are not printed using record notation") + end) + +module PrintingRecordConstructor = + PrintingInductiveMake (struct + let encode = encode_record + let field = "Constructor" + let title = "Types leading to pretty-printing using constructor form: " + let member_message s b = + str "Terms of " ++ s ++ + str + (if b then " are printed using constructor form" + else " are not printed using constructor form") + end) + +module PrintingRecord = Goptions.MakeRefTable(PrintingRecordRecord) +module PrintingConstructor = Goptions.MakeRefTable(PrintingRecordConstructor) + (**********************************************************************) (* Various externalisation functions *) @@ -299,7 +342,7 @@ let rec extern_cases_pattern_in_scope (scopes:local_scopes) vars pat = let args = List.map (extern_cases_pattern_in_scope scopes vars) args in let p = try - if !Flags.raw_print then raise Exit; + if !Flags.raw_print then raise Exit; let projs = Recordops.lookup_projections (fst cstrsp) in let rec ip projs args acc = match projs with @@ -550,9 +593,15 @@ let rec extern inctx scopes vars r = extern_args (extern true) (snd scopes) vars args subscopes in begin try - if !Flags.raw_print or not !Flags.record_print then raise Exit; + if !Flags.raw_print then raise Exit; let cstrsp = match ref with ConstructRef c -> c | _ -> raise Not_found in let struc = Recordops.lookup_structure (fst cstrsp) in + if PrintingRecord.active (fst cstrsp) then + () + else if PrintingConstructor.active (fst cstrsp) then + raise Exit + else if not !Flags.record_print then + raise Exit; let projs = struc.Recordops.s_PROJ in let locals = struc.Recordops.s_PROJKIND in let rec cut args n = -- cgit v1.2.3