src/Pure/Tools/codegen_names.ML
author wenzelm
Thu, 05 Jul 2007 20:01:34 +0200
changeset 23597 ab67175ca8a5
parent 23229 492e2fd12767
child 23784 75e6b9dd5336
permissions -rw-r--r--
simplified has_meta_prems;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
     1
(*  Title:      Pure/Tools/codegen_names.ML
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
     2
    ID:         $Id$
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
     4
21461
51239d45247b forced name prefix for class operations
haftmann
parents: 21338
diff changeset
     5
Naming policies for code generation: prefixing any name by corresponding theory name,
22304
haftmann
parents: 22197
diff changeset
     6
conversion to alphanumeric representation.
20855
9f60d493c8fe clarified header comments
haftmann
parents: 20835
diff changeset
     7
Mappings are incrementally cached.
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
     8
*)
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
     9
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
    10
signature CODEGEN_NAMES =
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
    11
sig
22304
haftmann
parents: 22197
diff changeset
    12
  val purify_var: string -> string
haftmann
parents: 22197
diff changeset
    13
  val purify_tvar: string -> string
haftmann
parents: 22197
diff changeset
    14
  val check_modulename: string -> string
haftmann
parents: 22197
diff changeset
    15
  type var_ctxt;
haftmann
parents: 22197
diff changeset
    16
  val make_vars: string list -> var_ctxt;
haftmann
parents: 22197
diff changeset
    17
  val intro_vars: string list -> var_ctxt -> var_ctxt;
haftmann
parents: 22197
diff changeset
    18
  val lookup_var: var_ctxt -> string -> string;
haftmann
parents: 22197
diff changeset
    19
20386
d1cbe5aa6bf2 module restructuring
haftmann
parents: 20353
diff changeset
    20
  type tyco = string
d1cbe5aa6bf2 module restructuring
haftmann
parents: 20353
diff changeset
    21
  type const = string
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
    22
  val class: theory -> class -> class
20697
12952535fc2c added code_instname
haftmann
parents: 20585
diff changeset
    23
  val class_rev: theory -> class -> class option
21927
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
    24
  val classrel: theory -> class * class -> string
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
    25
  val classrel_rev: theory -> string -> (class * class) option
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
    26
  val tyco: theory -> tyco -> tyco
20697
12952535fc2c added code_instname
haftmann
parents: 20585
diff changeset
    27
  val tyco_rev: theory -> tyco -> tyco option
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
    28
  val instance: theory -> class * tyco -> string
20697
12952535fc2c added code_instname
haftmann
parents: 20585
diff changeset
    29
  val instance_rev: theory -> string -> (class * tyco) option
20585
3fe913d70177 cleanupdiff
haftmann
parents: 20456
diff changeset
    30
  val const: theory -> CodegenConsts.const -> const
20697
12952535fc2c added code_instname
haftmann
parents: 20585
diff changeset
    31
  val const_rev: theory -> const -> CodegenConsts.const option
22034
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    32
  val labelled_name: theory -> string -> string
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
    33
end;
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
    34
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
    35
structure CodegenNames: CODEGEN_NAMES =
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
    36
struct
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
    37
22034
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    38
(** purification **)
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    39
23063
haftmann
parents: 23039
diff changeset
    40
fun purify_name upper_else_lower =
22034
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    41
  let
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    42
    fun is_valid s = Symbol.is_ascii_letter s orelse Symbol.is_ascii_digit s orelse s = "'";
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    43
    val is_junk = not o is_valid andf Symbol.not_eof;
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    44
    val junk = Scan.many is_junk;
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    45
    val scan_valids = Symbol.scanner "Malformed input"
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    46
      ((junk |--
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    47
        (Scan.optional (Scan.one Symbol.is_ascii_letter) "x" ^^ (Scan.many is_valid >> implode)
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    48
        --| junk))
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    49
      -- Scan.repeat ((Scan.many1 is_valid >> implode) --| junk) >> op ::);
23063
haftmann
parents: 23039
diff changeset
    50
    fun upper_lower cs = if upper_else_lower then nth_map 0 Symbol.to_ascii_upper cs
haftmann
parents: 23039
diff changeset
    51
      else (if forall Symbol.is_ascii_upper cs
haftmann
parents: 23039
diff changeset
    52
        then map else nth_map 0) Symbol.to_ascii_lower cs;
haftmann
parents: 23039
diff changeset
    53
  in
haftmann
parents: 23039
diff changeset
    54
    explode
haftmann
parents: 23039
diff changeset
    55
    #> scan_valids
haftmann
parents: 23039
diff changeset
    56
    #> space_implode "_"
haftmann
parents: 23039
diff changeset
    57
    #> explode
haftmann
parents: 23039
diff changeset
    58
    #> upper_lower
haftmann
parents: 23039
diff changeset
    59
    #> implode
haftmann
parents: 23039
diff changeset
    60
  end;
22034
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
    61
22304
haftmann
parents: 22197
diff changeset
    62
fun purify_var "" = "x"
23063
haftmann
parents: 23039
diff changeset
    63
  | purify_var v = purify_name false v;
22304
haftmann
parents: 22197
diff changeset
    64
haftmann
parents: 22197
diff changeset
    65
fun purify_tvar "" = "'a"
haftmann
parents: 22197
diff changeset
    66
  | purify_tvar v =
haftmann
parents: 22197
diff changeset
    67
      (unprefix "'" #> explode #> filter Symbol.is_ascii_letter #> cons "'" #> implode) v;
haftmann
parents: 22197
diff changeset
    68
haftmann
parents: 22197
diff changeset
    69
fun check_modulename mn =
haftmann
parents: 22197
diff changeset
    70
  let
haftmann
parents: 22197
diff changeset
    71
    val mns = NameSpace.explode mn;
23063
haftmann
parents: 23039
diff changeset
    72
    val mns' = map (purify_name true) mns;
22304
haftmann
parents: 22197
diff changeset
    73
  in
haftmann
parents: 22197
diff changeset
    74
    if mns' = mns then mn else error ("Invalid module name: " ^ quote mn ^ "\n"
haftmann
parents: 22197
diff changeset
    75
      ^ "perhaps try " ^ quote (NameSpace.implode mns'))
haftmann
parents: 22197
diff changeset
    76
  end;
haftmann
parents: 22197
diff changeset
    77
haftmann
parents: 22197
diff changeset
    78
haftmann
parents: 22197
diff changeset
    79
(** variable name contexts **)
haftmann
parents: 22197
diff changeset
    80
haftmann
parents: 22197
diff changeset
    81
type var_ctxt = string Symtab.table * Name.context;
haftmann
parents: 22197
diff changeset
    82
haftmann
parents: 22197
diff changeset
    83
fun make_vars names = (fold (fn name => Symtab.update_new (name, name)) names Symtab.empty,
haftmann
parents: 22197
diff changeset
    84
  Name.make_context names);
haftmann
parents: 22197
diff changeset
    85
haftmann
parents: 22197
diff changeset
    86
fun intro_vars names (namemap, namectxt) =
haftmann
parents: 22197
diff changeset
    87
  let
haftmann
parents: 22197
diff changeset
    88
    val (names', namectxt') = Name.variants names namectxt;
haftmann
parents: 22197
diff changeset
    89
    val namemap' = fold2 (curry Symtab.update) names names' namemap;
haftmann
parents: 22197
diff changeset
    90
  in (namemap', namectxt') end;
haftmann
parents: 22197
diff changeset
    91
haftmann
parents: 22197
diff changeset
    92
fun lookup_var (namemap, _) name = case Symtab.lookup namemap name
haftmann
parents: 22197
diff changeset
    93
 of SOME name' => name'
haftmann
parents: 22197
diff changeset
    94
  | NONE => error ("Invalid name in context: " ^ quote name);
haftmann
parents: 22197
diff changeset
    95
haftmann
parents: 22197
diff changeset
    96
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
    97
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
    98
(** global names (identifiers) **)
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
    99
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   100
(* identifier categories *)
22304
haftmann
parents: 22197
diff changeset
   101
haftmann
parents: 22197
diff changeset
   102
val idf_class = "class";
haftmann
parents: 22197
diff changeset
   103
val idf_classrel = "clsrel"
haftmann
parents: 22197
diff changeset
   104
val idf_tyco = "tyco";
haftmann
parents: 22197
diff changeset
   105
val idf_instance = "inst";
haftmann
parents: 22197
diff changeset
   106
val idf_const = "const";
haftmann
parents: 22197
diff changeset
   107
haftmann
parents: 22197
diff changeset
   108
fun string_of_classrel (class, superclass) = class ^ " < " ^ superclass;
haftmann
parents: 22197
diff changeset
   109
fun string_of_instance (class, tyco) = tyco ^ " :: " ^ class;
haftmann
parents: 22197
diff changeset
   110
haftmann
parents: 22197
diff changeset
   111
fun add_idf nsp name =
haftmann
parents: 22197
diff changeset
   112
  NameSpace.append name nsp;
haftmann
parents: 22197
diff changeset
   113
haftmann
parents: 22197
diff changeset
   114
fun dest_idf nsp name =
haftmann
parents: 22197
diff changeset
   115
  if NameSpace.base name = nsp
haftmann
parents: 22197
diff changeset
   116
  then SOME (NameSpace.qualifier name)
haftmann
parents: 22197
diff changeset
   117
  else NONE;
haftmann
parents: 22197
diff changeset
   118
haftmann
parents: 22197
diff changeset
   119
local
haftmann
parents: 22197
diff changeset
   120
haftmann
parents: 22197
diff changeset
   121
val name_mapping  = [
haftmann
parents: 22197
diff changeset
   122
  (idf_class,       "class"),
haftmann
parents: 22197
diff changeset
   123
  (idf_classrel,    "subclass relation"),
haftmann
parents: 22197
diff changeset
   124
  (idf_tyco,        "type constructor"),
haftmann
parents: 22197
diff changeset
   125
  (idf_instance,    "instance"),
haftmann
parents: 22197
diff changeset
   126
  (idf_const,       "constant")
haftmann
parents: 22197
diff changeset
   127
]
haftmann
parents: 22197
diff changeset
   128
haftmann
parents: 22197
diff changeset
   129
in
haftmann
parents: 22197
diff changeset
   130
haftmann
parents: 22197
diff changeset
   131
val category_of = the o AList.lookup (op =) name_mapping o NameSpace.base;
haftmann
parents: 22197
diff changeset
   132
haftmann
parents: 22197
diff changeset
   133
end;
haftmann
parents: 22197
diff changeset
   134
22034
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
   135
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   136
(* theory name lookup *)
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   137
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   138
fun thyname_of thy f errmsg x =
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   139
  let
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   140
    fun thy_of thy =
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   141
      if f thy x then case get_first thy_of (Theory.parents_of thy)
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   142
        of NONE => SOME thy
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   143
         | thy => thy
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   144
      else NONE;
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   145
  in case thy_of thy
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   146
   of SOME thy => Context.theory_name thy
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   147
    | NONE => error (errmsg x) end;
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   148
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   149
fun thyname_of_class thy =
21931
314f9e2a442c replaced Sign.classes by Sign.all_classes (topologically sorted);
wenzelm
parents: 21927
diff changeset
   150
  thyname_of thy (fn thy => member (op =) (Sign.all_classes thy))
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   151
    (fn class => "thyname_of_class: no such class: " ^ quote class);
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   152
21927
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   153
fun thyname_of_classrel thy =
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   154
  thyname_of thy (fn thy => fn (class1, class2) => Sign.subsort thy ([class1], [class2]))
22304
haftmann
parents: 22197
diff changeset
   155
    (fn (class1, class2) => "thyname_of_classrel: no such subclass relation: "
haftmann
parents: 22197
diff changeset
   156
      ^ (quote o string_of_classrel) (class1, class2));
21927
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   157
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   158
fun thyname_of_tyco thy =
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   159
  thyname_of thy Sign.declared_tyname
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   160
    (fn tyco => "thyname_of_tyco: no such type constructor: " ^ quote tyco);
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   161
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   162
fun thyname_of_instance thy =
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   163
  let
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   164
    fun test_instance thy (class, tyco) =
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   165
      can (Sorts.mg_domain (Sign.classes_of thy) tyco) [class]
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   166
  in thyname_of thy test_instance
22304
haftmann
parents: 22197
diff changeset
   167
    (fn (class, tyco) => "thyname_of_instance: no such instance: "
haftmann
parents: 22197
diff changeset
   168
      ^ (quote o string_of_instance) (class, tyco))
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   169
  end;
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   170
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   171
fun thyname_of_const thy =
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   172
  thyname_of thy Sign.declared_const
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   173
    (fn c => "thyname_of_const: no such constant: " ^ quote c);
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   174
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   175
22034
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
   176
(* naming policies *)
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   177
23063
haftmann
parents: 23039
diff changeset
   178
val purify_prefix =
21927
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   179
  explode
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   180
  (*should disappear as soon as hierarchical theory name spaces are available*)
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   181
  #> Symbol.scanner "Malformed name"
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   182
      (Scan.repeat ($$ "_" |-- $$ "_" >> (fn _ => ".") || Scan.one Symbol.not_eof))
23063
haftmann
parents: 23039
diff changeset
   183
  #> implode
haftmann
parents: 23039
diff changeset
   184
  #> NameSpace.explode
haftmann
parents: 23039
diff changeset
   185
  #> map (purify_name true);
21927
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   186
23063
haftmann
parents: 23039
diff changeset
   187
fun purify_base "op =" = "eq"
haftmann
parents: 23039
diff changeset
   188
  | purify_base "op &" = "and"
haftmann
parents: 23039
diff changeset
   189
  | purify_base "op |" = "or"
haftmann
parents: 23039
diff changeset
   190
  | purify_base "op -->" = "implies"
haftmann
parents: 23039
diff changeset
   191
  | purify_base "{}" = "empty"
haftmann
parents: 23039
diff changeset
   192
  | purify_base "op :" = "member"
haftmann
parents: 23039
diff changeset
   193
  | purify_base "op Int" = "intersect"
haftmann
parents: 23039
diff changeset
   194
  | purify_base "op Un" = "union"
haftmann
parents: 23039
diff changeset
   195
  | purify_base "*" = "product"
haftmann
parents: 23039
diff changeset
   196
  | purify_base "+" = "sum"
haftmann
parents: 23039
diff changeset
   197
  | purify_base s = purify_name false s;
haftmann
parents: 23039
diff changeset
   198
haftmann
parents: 23039
diff changeset
   199
fun default_policy thy get_basename get_thyname name =
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   200
  let
23063
haftmann
parents: 23039
diff changeset
   201
    val prefix = (purify_prefix o get_thyname thy) name;
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   202
    val base = (purify_base o get_basename) name;
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21461
diff changeset
   203
  in NameSpace.implode (prefix @ [base]) end;
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   204
23063
haftmann
parents: 23039
diff changeset
   205
fun class_policy thy = default_policy thy NameSpace.base thyname_of_class;
haftmann
parents: 23039
diff changeset
   206
fun classrel_policy thy = default_policy thy (fn (class1, class2) => 
22075
d52dab770767 reverted order of classrels
haftmann
parents: 22057
diff changeset
   207
  NameSpace.base class1 ^ "_" ^ NameSpace.base class2) thyname_of_classrel;
23063
haftmann
parents: 23039
diff changeset
   208
fun tyco_policy thy = default_policy thy NameSpace.base thyname_of_tyco;
haftmann
parents: 23039
diff changeset
   209
fun instance_policy thy = default_policy thy (fn (class, tyco) => 
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   210
  NameSpace.base class ^ "_" ^ NameSpace.base tyco) thyname_of_instance;
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   211
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22463
diff changeset
   212
fun force_thyname thy (const as (c, opt_tyco)) =
22807
715d01b34abb clarified naming policy
haftmann
parents: 22554
diff changeset
   213
  case CodegenData.get_datatype_of_constr thy const
21461
51239d45247b forced name prefix for class operations
haftmann
parents: 21338
diff changeset
   214
   of SOME dtco => SOME (thyname_of_tyco thy dtco)
22807
715d01b34abb clarified naming policy
haftmann
parents: 22554
diff changeset
   215
    | NONE => (case AxClass.class_of_param thy c
715d01b34abb clarified naming policy
haftmann
parents: 22554
diff changeset
   216
       of SOME class => (case opt_tyco
715d01b34abb clarified naming policy
haftmann
parents: 22554
diff changeset
   217
           of SOME tyco => SOME (thyname_of_instance thy (class, tyco))
715d01b34abb clarified naming policy
haftmann
parents: 22554
diff changeset
   218
            | NONE => SOME (thyname_of_class thy class))
715d01b34abb clarified naming policy
haftmann
parents: 22554
diff changeset
   219
        | NONE => NONE);
20386
d1cbe5aa6bf2 module restructuring
haftmann
parents: 20353
diff changeset
   220
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22463
diff changeset
   221
fun const_policy thy (const as (c, opt_tyco)) =
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22463
diff changeset
   222
  case force_thyname thy const
23063
haftmann
parents: 23039
diff changeset
   223
   of NONE => default_policy thy NameSpace.base thyname_of_const c
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   224
    | SOME thyname => let
23063
haftmann
parents: 23039
diff changeset
   225
        val prefix = purify_prefix thyname;
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22463
diff changeset
   226
        val tycos = the_list opt_tyco;
20386
d1cbe5aa6bf2 module restructuring
haftmann
parents: 20353
diff changeset
   227
        val base = map (purify_base o NameSpace.base) (c :: tycos);
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 21461
diff changeset
   228
      in NameSpace.implode (prefix @ [space_implode "_" base]) end;
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   229
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   230
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   231
(* theory and code data *)
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   232
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   233
type tyco = string;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   234
type const = string;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   235
structure Consttab = CodegenConsts.Consttab;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   236
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   237
structure StringPairTab =
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   238
  TableFun(
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   239
    type key = string * string;
23229
492e2fd12767 monomorphic equality: let ML work out the details;
wenzelm
parents: 23136
diff changeset
   240
    val ord = prod_ord fast_string_ord fast_string_ord;
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   241
  );
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   242
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   243
datatype names = Names of {
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   244
  class: class Symtab.table * class Symtab.table,
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   245
  classrel: string StringPairTab.table * (class * class) Symtab.table,
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   246
  tyco: tyco Symtab.table * tyco Symtab.table,
22463
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   247
  instance: string StringPairTab.table * (class * tyco) Symtab.table
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   248
}
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   249
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   250
val empty_names = Names {
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   251
  class = (Symtab.empty, Symtab.empty),
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   252
  classrel = (StringPairTab.empty, Symtab.empty),
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   253
  tyco = (Symtab.empty, Symtab.empty),
22463
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   254
  instance = (StringPairTab.empty, Symtab.empty)
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   255
};
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   256
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   257
local
22463
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   258
  fun mk_names (class, classrel, tyco, instance) =
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   259
    Names { class = class, classrel = classrel, tyco = tyco, instance = instance };
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   260
  fun map_names f (Names { class, classrel, tyco, instance }) =
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   261
    mk_names (f (class, classrel, tyco, instance));
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   262
in
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   263
  fun merge_names (Names { class = (class1, classrev1),
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   264
      classrel = (classrel1, classrelrev1), tyco = (tyco1, tycorev1),
22463
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   265
      instance = (instance1, instancerev1) },
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   266
    Names { class = (class2, classrev2),
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   267
      classrel = (classrel2, classrelrev2), tyco = (tyco2, tycorev2),
22463
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   268
      instance = (instance2, instancerev2) }) =
23229
492e2fd12767 monomorphic equality: let ML work out the details;
wenzelm
parents: 23136
diff changeset
   269
    mk_names ((Symtab.merge (op =) (class1, class2), Symtab.merge (op =) (classrev1, classrev2)),
492e2fd12767 monomorphic equality: let ML work out the details;
wenzelm
parents: 23136
diff changeset
   270
      (StringPairTab.merge (op =) (classrel1, classrel2), Symtab.merge (op =) (classrelrev1, classrelrev2)),
492e2fd12767 monomorphic equality: let ML work out the details;
wenzelm
parents: 23136
diff changeset
   271
      (Symtab.merge (op =) (tyco1, tyco2), Symtab.merge (op =) (tycorev1, tycorev2)),
492e2fd12767 monomorphic equality: let ML work out the details;
wenzelm
parents: 23136
diff changeset
   272
      (StringPairTab.merge (op =) (instance1, instance2), Symtab.merge (op =) (instancerev1, instancerev2)));
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   273
  fun map_class f = map_names
22463
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   274
    (fn (class, classrel, tyco, inst) => (f class, classrel, tyco, inst));
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   275
  fun map_classrel f = map_names
22463
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   276
    (fn (class, classrel, tyco, inst) => (class, f classrel, tyco, inst));
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   277
  fun map_tyco f = map_names
22463
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   278
    (fn (class, classrel, tyco, inst) => (class, classrel, f tyco, inst));
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   279
  fun map_instance f = map_names
22463
d0e12f0d4e44 dropping dead code
haftmann
parents: 22427
diff changeset
   280
    (fn (class, classrel, tyco, inst) => (class, classrel, tyco, f inst));
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   281
end; (*local*)
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   282
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   283
structure CodeName = TheoryDataFun
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22807
diff changeset
   284
(
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   285
  type T = names ref;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   286
  val empty = ref empty_names;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   287
  fun copy (ref names) = ref names;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   288
  val extend = copy;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   289
  fun merge _ (ref names1, ref names2) = ref (merge_names (names1, names2));
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22807
diff changeset
   290
);
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   291
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   292
structure ConstName = CodeDataFun
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22807
diff changeset
   293
(
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22463
diff changeset
   294
  type T = const Consttab.table * (string * string option) Symtab.table;
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   295
  val empty = (Consttab.empty, Symtab.empty);
23229
492e2fd12767 monomorphic equality: let ML work out the details;
wenzelm
parents: 23136
diff changeset
   296
  fun merge _ ((const1, constrev1), (const2, constrev2)) : T =
492e2fd12767 monomorphic equality: let ML work out the details;
wenzelm
parents: 23136
diff changeset
   297
    (Consttab.merge (op =) (const1, const2),
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   298
      Symtab.merge CodegenConsts.eq_const (constrev1, constrev2));
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   299
  fun purge _ NONE _ = empty
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   300
    | purge _ (SOME cs) (const, constrev) = (fold Consttab.delete_safe cs const,
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   301
        fold Symtab.delete (map_filter (Consttab.lookup const) cs) constrev);
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22807
diff changeset
   302
);
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   303
23136
5a0378eada70 simplified data setup
haftmann
parents: 23063
diff changeset
   304
val _ = Context.add_setup (CodeName.init);
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   305
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   306
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   307
(* forward lookup with cache update *)
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   308
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   309
fun get thy get_tabs get upd_names upd policy x =
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   310
  let
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   311
    val names_ref = CodeName.get thy;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   312
    val (Names names) = ! names_ref;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   313
    val tabs = get_tabs names;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   314
    fun declare name =
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   315
      let
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   316
        val names' = upd_names (K (upd (x, name) (fst tabs),
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   317
          Symtab.update_new (name, x) (snd tabs))) (Names names)
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   318
      in (names_ref := names'; name) end;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   319
  in case get (fst tabs) x
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   320
   of SOME name => name
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   321
    | NONE => 
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   322
        x
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   323
        |> policy thy
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   324
        |> Name.variant (Symtab.keys (snd tabs))
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   325
        |> declare
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   326
  end;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   327
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   328
fun get_const thy const =
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   329
  let
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   330
    val tabs = ConstName.get thy;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   331
    fun declare name =
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   332
      let
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   333
        val names' = (Consttab.update (const, name) (fst tabs),
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   334
          Symtab.update_new (name, const) (snd tabs))
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   335
      in (ConstName.change thy (K names'); name) end;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   336
  in case Consttab.lookup (fst tabs) const
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   337
   of SOME name => name
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   338
    | NONE => 
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   339
        const
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   340
        |> const_policy thy
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   341
        |> Name.variant (Symtab.keys (snd tabs))
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   342
        |> declare
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   343
  end;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   344
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   345
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   346
(* backward lookup *)
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   347
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   348
fun rev thy get_tabs name =
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   349
  let
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   350
    val names_ref = CodeName.get thy
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   351
    val (Names names) = ! names_ref;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   352
    val tab = (snd o get_tabs) names;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   353
  in case Symtab.lookup tab name
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   354
   of SOME x => x
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   355
    | NONE => error ("No such " ^ category_of name ^ ": " ^ quote name)
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   356
  end;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   357
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   358
fun rev_const thy name =
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   359
  let
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   360
    val tab = snd (ConstName.get thy);
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   361
  in case Symtab.lookup tab name
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   362
   of SOME const => const
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   363
    | NONE => error ("No such " ^ category_of name ^ ": " ^ quote name)
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   364
  end;
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   365
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   366
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   367
(* external interfaces *)
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   368
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   369
fun class thy =
20697
12952535fc2c added code_instname
haftmann
parents: 20585
diff changeset
   370
  get thy #class Symtab.lookup map_class Symtab.update class_policy
22304
haftmann
parents: 22197
diff changeset
   371
  #> add_idf idf_class;
21927
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   372
fun classrel thy =
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   373
  get thy #classrel StringPairTab.lookup map_classrel StringPairTab.update classrel_policy
22304
haftmann
parents: 22197
diff changeset
   374
  #> add_idf idf_classrel;
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   375
fun tyco thy =
20697
12952535fc2c added code_instname
haftmann
parents: 20585
diff changeset
   376
  get thy #tyco Symtab.lookup map_tyco Symtab.update tyco_policy
22304
haftmann
parents: 22197
diff changeset
   377
  #> add_idf idf_tyco;
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   378
fun instance thy =
22304
haftmann
parents: 22197
diff changeset
   379
  get thy #instance StringPairTab.lookup map_instance StringPairTab.update instance_policy
haftmann
parents: 22197
diff changeset
   380
  #> add_idf idf_instance;
21915
4e63c55f4cb4 different handling of type variable names
haftmann
parents: 21880
diff changeset
   381
fun const thy =
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22463
diff changeset
   382
  get_const thy
22304
haftmann
parents: 22197
diff changeset
   383
  #> add_idf idf_const;
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   384
20697
12952535fc2c added code_instname
haftmann
parents: 20585
diff changeset
   385
fun class_rev thy =
22304
haftmann
parents: 22197
diff changeset
   386
  dest_idf idf_class
haftmann
parents: 22197
diff changeset
   387
  #> Option.map (rev thy #class);
21927
9677abe5d374 added handling for explicit classrel witnesses
haftmann
parents: 21915
diff changeset
   388
fun classrel_rev thy =
22304
haftmann
parents: 22197
diff changeset
   389
  dest_idf idf_classrel
haftmann
parents: 22197
diff changeset
   390
  #> Option.map (rev thy #classrel);
20697
12952535fc2c added code_instname
haftmann
parents: 20585
diff changeset
   391
fun tyco_rev thy =
22304
haftmann
parents: 22197
diff changeset
   392
  dest_idf idf_tyco
haftmann
parents: 22197
diff changeset
   393
  #> Option.map (rev thy #tyco);
20697
12952535fc2c added code_instname
haftmann
parents: 20585
diff changeset
   394
fun instance_rev thy =
22304
haftmann
parents: 22197
diff changeset
   395
  dest_idf idf_instance
haftmann
parents: 22197
diff changeset
   396
  #> Option.map (rev thy #instance);
21915
4e63c55f4cb4 different handling of type variable names
haftmann
parents: 21880
diff changeset
   397
fun const_rev thy =
22304
haftmann
parents: 22197
diff changeset
   398
  dest_idf idf_const
22427
69ce2cb9e3e5 constant names now dependent on executable content
haftmann
parents: 22304
diff changeset
   399
  #> Option.map (rev_const thy);
22304
haftmann
parents: 22197
diff changeset
   400
haftmann
parents: 22197
diff changeset
   401
local
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   402
22304
haftmann
parents: 22197
diff changeset
   403
val f_mapping = [
haftmann
parents: 22197
diff changeset
   404
  (idf_class,       class_rev),
haftmann
parents: 22197
diff changeset
   405
  (idf_classrel,    Option.map string_of_classrel oo classrel_rev),
haftmann
parents: 22197
diff changeset
   406
  (idf_tyco,        tyco_rev),
haftmann
parents: 22197
diff changeset
   407
  (idf_instance,    Option.map string_of_instance oo instance_rev),
haftmann
parents: 22197
diff changeset
   408
  (idf_const,       fn thy => Option.map (CodegenConsts.string_of_const thy) o const_rev thy)
haftmann
parents: 22197
diff changeset
   409
];
haftmann
parents: 22197
diff changeset
   410
haftmann
parents: 22197
diff changeset
   411
in
haftmann
parents: 22197
diff changeset
   412
haftmann
parents: 22197
diff changeset
   413
fun labelled_name thy idf =
22034
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
   414
  let
22304
haftmann
parents: 22197
diff changeset
   415
    val category = category_of idf;
haftmann
parents: 22197
diff changeset
   416
    val name = NameSpace.qualifier idf;
haftmann
parents: 22197
diff changeset
   417
    val f = (the o AList.lookup (op =) f_mapping o NameSpace.base) idf
haftmann
parents: 22197
diff changeset
   418
  in case f thy idf
haftmann
parents: 22197
diff changeset
   419
   of SOME thing => category ^ " " ^ quote thing
haftmann
parents: 22197
diff changeset
   420
    | NONE => error ("Unknown name: " ^ quote name)
22034
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
   421
  end;
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
   422
22304
haftmann
parents: 22197
diff changeset
   423
end;
22034
44ab6c04b3dc moved variable environments here
haftmann
parents: 21931
diff changeset
   424
20353
d73e49780ef2 code generator refinements
haftmann
parents:
diff changeset
   425
end;