src/Pure/sign.ML
changeset 402 16a8fe4f2250
parent 386 e9ba9f7e2542
child 410 c8171ee32744
equal deleted inserted replaced
401:324ad2e02826 402:16a8fe4f2250
    23        stamps: string ref list}
    23        stamps: string ref list}
    24     val subsig: sg * sg -> bool
    24     val subsig: sg * sg -> bool
    25     val eq_sg: sg * sg -> bool
    25     val eq_sg: sg * sg -> bool
    26     val is_draft: sg -> bool
    26     val is_draft: sg -> bool
    27     val const_type: sg -> string -> typ option
    27     val const_type: sg -> string -> typ option
       
    28     val classes: sg -> class list
       
    29     val subsort: sg -> sort * sort -> bool      (* FIXME move? *)
       
    30     val norm_sort: sg -> sort -> sort           (* FIXME move? *)
    28     val print_sg: sg -> unit
    31     val print_sg: sg -> unit
    29     val pprint_sg: sg -> pprint_args -> unit
    32     val pprint_sg: sg -> pprint_args -> unit
    30     val pretty_term: sg -> term -> Pretty.T
    33     val pretty_term: sg -> term -> Pretty.T
    31     val pretty_typ: sg -> typ -> Pretty.T
    34     val pretty_typ: sg -> typ -> Pretty.T
    32     val string_of_term: sg -> term -> string
    35     val string_of_term: sg -> term -> string
    90     const_tab: typ Symtab.table,    (*types of constants*)
    93     const_tab: typ Symtab.table,    (*types of constants*)
    91     syn: Syntax.syntax,             (*syntax for parsing and printing*)
    94     syn: Syntax.syntax,             (*syntax for parsing and printing*)
    92     stamps: string ref list};       (*unique theory indentifier*)
    95     stamps: string ref list};       (*unique theory indentifier*)
    93 
    96 
    94 fun rep_sg (Sg args) = args;
    97 fun rep_sg (Sg args) = args;
    95 
    98 val tsig_of = #tsig o rep_sg;
       
    99 
       
   100 
       
   101 (* stamps *)
    96 
   102 
    97 fun is_draft (Sg {stamps = ref "#" :: _, ...}) = true
   103 fun is_draft (Sg {stamps = ref "#" :: _, ...}) = true
    98   | is_draft _ = false;
   104   | is_draft _ = false;
    99 
   105 
   100 fun subsig (Sg {stamps = s1, ...}, Sg {stamps = s2, ...}) = s1 subset s2;
   106 fun subsig (Sg {stamps = s1, ...}, Sg {stamps = s2, ...}) = s1 subset s2;
   101 
   107 
   102 fun eq_sg (Sg {stamps = s1, ...}, Sg {stamps = s2, ...}) = eq_set (s1, s2);
   108 fun eq_sg (Sg {stamps = s1, ...}, Sg {stamps = s2, ...}) = eq_set (s1, s2);
   103 
   109 
   104 
   110 
       
   111 (* consts *)
       
   112 
   105 fun const_type (Sg {const_tab, ...}) c =
   113 fun const_type (Sg {const_tab, ...}) c =
   106   Symtab.lookup (const_tab, c);
   114   Symtab.lookup (const_tab, c);
       
   115 
       
   116 
       
   117 (* classes *)
       
   118 
       
   119 val classes = #classes o Type.rep_tsig o tsig_of;
       
   120 
       
   121 val subsort = Type.subsort o tsig_of;
       
   122 val norm_sort = Type.norm_sort o tsig_of;
   107 
   123 
   108 
   124 
   109 
   125 
   110 (** print signature **)
   126 (** print signature **)
   111 
   127 
   401   (Syntax.extend_trrules syn xrules, tsig, ctab);
   417   (Syntax.extend_trrules syn xrules, tsig, ctab);
   402 
   418 
   403 
   419 
   404 (* build signature *)
   420 (* build signature *)
   405 
   421 
   406 (* FIXME debug *)
       
   407 fun assert_stamps_ok stamps =
       
   408   let val names = map ! stamps;
       
   409   in
       
   410     if not (null (duplicates stamps)) then
       
   411       error "DEBUG dup stamps"
       
   412     else if not (null (duplicates names)) then
       
   413       error "DEBUG dup stamp names"
       
   414     else if not (null names) andalso exists (equal "#") (tl names) then
       
   415       error "DEBUG misplaced draft stamp name"
       
   416     else stamps
       
   417   end;
       
   418 
       
   419 fun ext_stamps stamps name =
   422 fun ext_stamps stamps name =
   420   let
   423   let
   421     val stmps = (case stamps of ref "#" :: ss => ss | ss => ss);
   424     val stmps = (case stamps of ref "#" :: ss => ss | ss => ss);
   422   in
   425   in
   423     if exists (equal name o !) stmps then
   426     if exists (equal name o !) stmps then
   424       error ("Theory already contains a " ^ quote name ^ " component")
   427       error ("Theory already contains a " ^ quote name ^ " component")
   425     else assert_stamps_ok (ref name :: stmps)
   428     else ref name :: stmps
   426   end;
   429   end;
   427 
       
   428 
   430 
   429 fun make_sign (syn, tsig, ctab) stamps name =
   431 fun make_sign (syn, tsig, ctab) stamps name =
   430   Sg {tsig = tsig, const_tab = ctab, syn = syn,
   432   Sg {tsig = tsig, const_tab = ctab, syn = syn,
   431     stamps = ext_stamps stamps name};
   433     stamps = ext_stamps stamps name};
   432 
   434 
   519         stamps = stamps1} = sg1;
   521         stamps = stamps1} = sg1;
   520       val Sg {tsig = tsig2, const_tab = const_tab2, syn = syn2,
   522       val Sg {tsig = tsig2, const_tab = const_tab2, syn = syn2,
   521         stamps = stamps2} = sg2;
   523         stamps = stamps2} = sg2;
   522 
   524 
   523 
   525 
       
   526       val stamps = merge_rev_lists stamps1 stamps2;
       
   527       val _ =
       
   528         (case duplicates (stamp_names stamps) of
       
   529           [] => ()
       
   530         | dups => raise_term ("Attempt to merge different versions of theories "
       
   531             ^ commas_quote dups) []);
       
   532 
   524       val tsig = merge_tsigs (tsig1, tsig2);
   533       val tsig = merge_tsigs (tsig1, tsig2);
   525 
   534 
   526       val const_tab = Symtab.merge (op =) (const_tab1, const_tab2)
   535       val const_tab = Symtab.merge (op =) (const_tab1, const_tab2)
   527         handle Symtab.DUPS cs =>
   536         handle Symtab.DUPS cs =>
   528           raise_term ("Incompatible types for constant(s) " ^ commas_quote cs) [];
   537           raise_term ("Incompatible types for constant(s) " ^ commas_quote cs) [];
   529 
   538 
   530       val syn = Syntax.merge_syntaxes syn1 syn2;
   539       val syn = Syntax.merge_syntaxes syn1 syn2;
   531 
       
   532       val stamps = merge_rev_lists stamps1 stamps2;
       
   533       val dups = duplicates (stamp_names stamps);
       
   534     in
   540     in
   535       if null dups then assert_stamps_ok stamps    (* FIXME debug *)
       
   536       else raise_term ("Attempt to merge different versions of theories " ^
       
   537         commas_quote dups) [];
       
   538       Sg {tsig = tsig, const_tab = const_tab, syn = syn, stamps = stamps}
   541       Sg {tsig = tsig, const_tab = const_tab, syn = syn, stamps = stamps}
   539     end;
   542     end;
   540 
   543 
   541 
   544 
   542 
   545