src/Tools/code/code_target.ML
changeset 30648 17365ef082f3
parent 30513 1796b8ea88aa
child 30767 16c689643a7a
equal deleted inserted replaced
30647:ef8f46c3158a 30648:17365ef082f3
    80   | mk_serialization target _ _ string code (String _) = SOME (string code);
    80   | mk_serialization target _ _ string code (String _) = SOME (string code);
    81 
    81 
    82 
    82 
    83 (** theory data **)
    83 (** theory data **)
    84 
    84 
    85 structure StringPairTab = Code_Name.StringPairTab;
       
    86 
       
    87 datatype name_syntax_table = NameSyntaxTable of {
    85 datatype name_syntax_table = NameSyntaxTable of {
    88   class: string Symtab.table,
    86   class: string Symtab.table,
    89   instance: unit StringPairTab.table,
    87   instance: unit Symreltab.table,
    90   tyco: tyco_syntax Symtab.table,
    88   tyco: tyco_syntax Symtab.table,
    91   const: const_syntax Symtab.table
    89   const: const_syntax Symtab.table
    92 };
    90 };
    93 
    91 
    94 fun mk_name_syntax_table ((class, instance), (tyco, const)) =
    92 fun mk_name_syntax_table ((class, instance), (tyco, const)) =
    97   mk_name_syntax_table (f ((class, instance), (tyco, const)));
    95   mk_name_syntax_table (f ((class, instance), (tyco, const)));
    98 fun merge_name_syntax_table (NameSyntaxTable { class = class1, instance = instance1, tyco = tyco1, const = const1 },
    96 fun merge_name_syntax_table (NameSyntaxTable { class = class1, instance = instance1, tyco = tyco1, const = const1 },
    99     NameSyntaxTable { class = class2, instance = instance2, tyco = tyco2, const = const2 }) =
    97     NameSyntaxTable { class = class2, instance = instance2, tyco = tyco2, const = const2 }) =
   100   mk_name_syntax_table (
    98   mk_name_syntax_table (
   101     (Symtab.join (K snd) (class1, class2),
    99     (Symtab.join (K snd) (class1, class2),
   102        StringPairTab.join (K snd) (instance1, instance2)),
   100        Symreltab.join (K snd) (instance1, instance2)),
   103     (Symtab.join (K snd) (tyco1, tyco2),
   101     (Symtab.join (K snd) (tyco1, tyco2),
   104        Symtab.join (K snd) (const1, const2))
   102        Symtab.join (K snd) (const1, const2))
   105   );
   103   );
   106 
   104 
   107 type serializer =
   105 type serializer =
   192       else (); 
   190       else (); 
   193   in
   191   in
   194     thy
   192     thy
   195     |> (CodeTargetData.map o apfst oo Symtab.map_default)
   193     |> (CodeTargetData.map o apfst oo Symtab.map_default)
   196           (target, mk_target ((serial (), seri), (([], Symtab.empty),
   194           (target, mk_target ((serial (), seri), (([], Symtab.empty),
   197             (mk_name_syntax_table ((Symtab.empty, StringPairTab.empty), (Symtab.empty, Symtab.empty)),
   195             (mk_name_syntax_table ((Symtab.empty, Symreltab.empty), (Symtab.empty, Symtab.empty)),
   198               Symtab.empty))))
   196               Symtab.empty))))
   199           ((map_target o apfst o apsnd o K) seri)
   197           ((map_target o apfst o apsnd o K) seri)
   200   end;
   198   end;
   201 
   199 
   202 fun add_target (target, seri) = put_target (target, Serializer seri);
   200 fun add_target (target, seri) = put_target (target, Serializer seri);
   260   let
   258   let
   261     val inst = (prep_class thy raw_class, prep_tyco thy raw_tyco);
   259     val inst = (prep_class thy raw_class, prep_tyco thy raw_tyco);
   262   in if add_del then
   260   in if add_del then
   263     thy
   261     thy
   264     |> (map_name_syntax target o apfst o apsnd)
   262     |> (map_name_syntax target o apfst o apsnd)
   265         (StringPairTab.update (inst, ()))
   263         (Symreltab.update (inst, ()))
   266   else
   264   else
   267     thy
   265     thy
   268     |> (map_name_syntax target o apfst o apsnd)
   266     |> (map_name_syntax target o apfst o apsnd)
   269         (StringPairTab.delete_safe inst)
   267         (Symreltab.delete_safe inst)
   270   end;
   268   end;
   271 
   269 
   272 fun gen_add_syntax_tyco prep_tyco target raw_tyco raw_syn thy =
   270 fun gen_add_syntax_tyco prep_tyco target raw_tyco raw_syn thy =
   273   let
   271   let
   274     val tyco = prep_tyco thy raw_tyco;
   272     val tyco = prep_tyco thy raw_tyco;
   405            of SOME name => (SOME name, Symtab.update_new (name, the (Symtab.lookup src_tab thing_identifier)) tab)
   403            of SOME name => (SOME name, Symtab.update_new (name, the (Symtab.lookup src_tab thing_identifier)) tab)
   406             | NONE => (NONE, tab)) (Symtab.keys src_tab)
   404             | NONE => (NONE, tab)) (Symtab.keys src_tab)
   407       |>> map_filter I;
   405       |>> map_filter I;
   408     val (names_class, class') = distill_names Code_Thingol.lookup_class class;
   406     val (names_class, class') = distill_names Code_Thingol.lookup_class class;
   409     val names_inst = map_filter (Code_Thingol.lookup_instance naming)
   407     val names_inst = map_filter (Code_Thingol.lookup_instance naming)
   410       (StringPairTab.keys instance);
   408       (Symreltab.keys instance);
   411     val (names_tyco, tyco') = distill_names Code_Thingol.lookup_tyco tyco;
   409     val (names_tyco, tyco') = distill_names Code_Thingol.lookup_tyco tyco;
   412     val (names_const, const') = distill_names Code_Thingol.lookup_const const;
   410     val (names_const, const') = distill_names Code_Thingol.lookup_const const;
   413     val names_hidden = names_class @ names_inst @ names_tyco @ names_const;
   411     val names_hidden = names_class @ names_inst @ names_tyco @ names_const;
   414     val names2 = subtract (op =) names_hidden names1;
   412     val names2 = subtract (op =) names_hidden names1;
   415     val program3 = Graph.subgraph (not o member (op =) names_hidden) program2;
   413     val program3 = Graph.subgraph (not o member (op =) names_hidden) program2;