src/Tools/code/code_name.ML
changeset 27303 d6fef33c5c69
parent 27103 d8549f4d900b
child 27365 91a7041a5a64
equal deleted inserted replaced
27302:8d12ac6a3e1c 27303:d6fef33c5c69
   164 end;
   164 end;
   165 
   165 
   166 
   166 
   167 (* theory name lookup *)
   167 (* theory name lookup *)
   168 
   168 
   169 fun thyname_of thy f errmsg x =
   169 fun thyname_of thy f x = the (AList.lookup (op =) (f x) Markup.theory_nameN);
       
   170 
       
   171 fun thyname_of' thy f errmsg x =
   170   let
   172   let
   171     fun thy_of thy =
   173     fun thy_of thy =
   172       if f thy x then case get_first thy_of (Theory.parents_of thy)
   174       if f thy x then case get_first thy_of (Theory.parents_of thy)
   173         of NONE => SOME thy
   175         of NONE => SOME thy
   174          | thy => thy
   176          | thy => thy
   176   in case thy_of thy
   178   in case thy_of thy
   177    of SOME thy => Context.theory_name thy
   179    of SOME thy => Context.theory_name thy
   178     | NONE => error (errmsg x) end;
   180     | NONE => error (errmsg x) end;
   179 
   181 
   180 fun thyname_of_class thy =
   182 fun thyname_of_class thy =
   181   thyname_of thy (fn thy => member (op =) (Sign.all_classes thy))
   183   thyname_of' thy (fn thy => member (op =) (Sign.all_classes thy))
   182     (fn class => "thyname_of_class: no such class: " ^ quote class);
   184     (fn class => "thyname_of_class: no such class: " ^ quote class);
   183 
   185 
   184 fun thyname_of_tyco thy =
   186 fun thyname_of_tyco thy = thyname_of thy (Type.the_tags (Sign.tsig_of thy));
   185   thyname_of thy Sign.declared_tyname
       
   186     (fn tyco => "thyname_of_tyco: no such type constructor: " ^ quote tyco);
       
   187 
   187 
   188 fun thyname_of_instance thy =
   188 fun thyname_of_instance thy =
   189   let
   189   let
   190     fun test_instance thy (class, tyco) =
   190     fun test_instance thy (class, tyco) =
   191       can (Sorts.mg_domain (Sign.classes_of thy) tyco) [class]
   191       can (Sorts.mg_domain (Sign.classes_of thy) tyco) [class]
   192   in thyname_of thy test_instance
   192   in thyname_of' thy test_instance
   193     (fn (class, tyco) => "thyname_of_instance: no such instance: "
   193     (fn (class, tyco) => "thyname_of_instance: no such instance: "
   194       ^ (quote o string_of_instance) (class, tyco))
   194       ^ (quote o string_of_instance) (class, tyco))
   195   end;
   195   end;
   196 
   196 
   197 fun thyname_of_const thy =
   197 fun thyname_of_const thy = thyname_of thy (Consts.the_tags (Sign.consts_of thy));
   198   thyname_of thy Sign.declared_const
       
   199     (fn c => "thyname_of_const: no such constant: " ^ quote c);
       
   200 
   198 
   201 
   199 
   202 (* naming policies *)
   200 (* naming policies *)
   203 
   201 
   204 val purify_prefix =
   202 val purify_prefix =