src/Pure/Tools/codegen_names.ML
changeset 20456 42be3a46dcd8
parent 20389 8b6ecb22ef35
child 20585 3fe913d70177
equal deleted inserted replaced
20455:e671d9eac6c8 20456:42be3a46dcd8
    79   fun map_const f = map_names
    79   fun map_const f = map_names
    80     (fn (class, tyco, inst, const) => (class, tyco, inst, f const));
    80     (fn (class, tyco, inst, const) => (class, tyco, inst, f const));
    81 
    81 
    82 end; (*local*)
    82 end; (*local*)
    83 
    83 
    84 structure CodegenNamesData = TheoryDataFun
    84 structure CodeName = TheoryDataFun
    85 (struct
    85 (struct
    86   val name = "Pure/codegen_names";
    86   val name = "Pure/codegen_names";
    87   type T = names ref;
    87   type T = names ref;
    88   val empty = ref empty_names;
    88   val empty = ref empty_names;
    89   fun copy (ref names) = ref names;
    89   fun copy (ref names) = ref names;
    90   val extend = copy;
    90   val extend = copy;
    91   fun merge _ (ref names1, ref names2) = ref (merge_names (names1, names2));
    91   fun merge _ (ref names1, ref names2) = ref (merge_names (names1, names2));
    92   fun print _ _ = ();
    92   fun print _ _ = ();
    93 end);
    93 end);
    94 
    94 
    95 val _ = Context.add_setup CodegenNamesData.init;
    95 val _ = Context.add_setup CodeName.init;
    96 
    96 
    97 
    97 
    98 (* forward lookup with cache update *)
    98 (* forward lookup with cache update *)
    99 
    99 
   100 fun get thy get_tabs get upd_names upd policy x =
   100 fun get thy get_tabs get upd_names upd policy x =
   101   let
   101   let
   102     val names_ref = CodegenNamesData.get thy
   102     val names_ref = CodeName.get thy
   103     val (Names names) = ! names_ref;
   103     val (Names names) = ! names_ref;
   104     fun mk_unique used name =
   104     fun mk_unique used name =
   105       let
   105       let
   106         fun mk_name 0 = name
   106         fun mk_name 0 = name
   107           | mk_name i = name ^ "_" ^ string_of_int i
   107           | mk_name i = name ^ "_" ^ string_of_int i
   133 
   133 
   134 (* backward lookup *)
   134 (* backward lookup *)
   135 
   135 
   136 fun rev thy get_tabs errname name =
   136 fun rev thy get_tabs errname name =
   137   let
   137   let
   138     val names_ref = CodegenNamesData.get thy
   138     val names_ref = CodeName.get thy
   139     val (Names names) = ! names_ref;
   139     val (Names names) = ! names_ref;
   140     val tab = (snd o get_tabs) names;
   140     val tab = (snd o get_tabs) names;
   141   in case Symtab.lookup tab name
   141   in case Symtab.lookup tab name
   142    of SOME x => x
   142    of SOME x => x
   143     | NONE => error ("No such " ^ errname ^ ": " ^ quote name)
   143     | NONE => error ("No such " ^ errname ^ ": " ^ quote name)
   235     val _ = if (base' = base) andalso forall (op =) (prefix' ~~ prefix)
   235     val _ = if (base' = base) andalso forall (op =) (prefix' ~~ prefix)
   236       then ()
   236       then ()
   237       else
   237       else
   238         error ("Name violates naming conventions: " ^ quote name
   238         error ("Name violates naming conventions: " ^ quote name
   239           ^ "; perhaps try with " ^ quote (NameSpace.pack (prefix' @ [base'])))
   239           ^ "; perhaps try with " ^ quote (NameSpace.pack (prefix' @ [base'])))
   240     val names_ref = CodegenNamesData.get thy;
   240     val names_ref = CodeName.get thy;
   241     val (Names names) = ! names_ref;
   241     val (Names names) = ! names_ref;
   242     val (tycotab, tycorev) = #tyco names;
   242     val (tycotab, tycorev) = #tyco names;
   243     val _ = if Symtab.defined tycotab tyco
   243     val _ = if Symtab.defined tycotab tyco
   244       then error ("Type constructor already named: " ^ quote tyco)
   244       then error ("Type constructor already named: " ^ quote tyco)
   245       else ();
   245       else ();
   261     val _ = if (base' = base) andalso forall (op =) (prefix' ~~ prefix)
   261     val _ = if (base' = base) andalso forall (op =) (prefix' ~~ prefix)
   262       then ()
   262       then ()
   263       else
   263       else
   264         error ("Name violates naming conventions: " ^ quote name
   264         error ("Name violates naming conventions: " ^ quote name
   265           ^ "; perhaps try with " ^ quote (NameSpace.pack (prefix' @ [base'])))
   265           ^ "; perhaps try with " ^ quote (NameSpace.pack (prefix' @ [base'])))
   266     val names_ref = CodegenNamesData.get thy;
   266     val names_ref = CodeName.get thy;
   267     val (Names names) = ! names_ref;
   267     val (Names names) = ! names_ref;
   268     val (const, constrev) = #const names;
   268     val (const, constrev) = #const names;
   269     val c_tys as (c, _) = CodegenConsts.norminst_of_typ thy c_ty;
   269     val c_tys as (c, _) = CodegenConsts.norminst_of_typ thy c_ty;
   270     val _ = if Consttab.defined const c_tys
   270     val _ = if Consttab.defined const c_tys
   271       then error ("Constant already named: " ^ quote (CodegenConsts.string_of_const thy c_tys))
   271       then error ("Constant already named: " ^ quote (CodegenConsts.string_of_const thy c_tys))