src/Pure/General/name_space.ML
changeset 23086 12320f6e2523
parent 22057 d7c91b2f5a9e
child 23668 8b5a2a79a6e3
equal deleted inserted replaced
23085:fd30d75a6614 23086:12320f6e2523
    51   val sticky_prefix: string -> naming -> naming
    51   val sticky_prefix: string -> naming -> naming
    52   val set_policy: (string -> bstring -> string) * (string list -> string list list) ->
    52   val set_policy: (string -> bstring -> string) * (string list -> string list list) ->
    53     naming -> naming
    53     naming -> naming
    54   type 'a table (*= T * 'a Symtab.table*)
    54   type 'a table (*= T * 'a Symtab.table*)
    55   val empty_table: 'a table
    55   val empty_table: 'a table
    56   val extend_table: naming -> 'a table * (bstring * 'a) list -> 'a table
    56   val extend_table: naming -> (bstring * 'a) list -> 'a table -> 'a table
    57   val merge_tables: ('a * 'a -> bool) -> 'a table * 'a table -> 'a table
    57   val merge_tables: ('a * 'a -> bool) -> 'a table * 'a table -> 'a table
    58   val dest_table: 'a table -> (string * 'a) list
    58   val dest_table: 'a table -> (string * 'a) list
    59   val extern_table: 'a table -> (xstring * 'a) list
    59   val extern_table: 'a table -> (xstring * 'a) list
    60 end;
    60 end;
    61 
    61 
   167 
   167 
   168 
   168 
   169 (* basic operations *)
   169 (* basic operations *)
   170 
   170 
   171 fun map_space f xname (NameSpace tab) =
   171 fun map_space f xname (NameSpace tab) =
   172   let val entry' =
   172   NameSpace (Symtab.map_default (xname, (([], []), stamp ()))
   173     (case Symtab.lookup tab xname of
   173     (fn (entry, _) => (f entry, stamp ())) tab);
   174       NONE => f ([], [])
       
   175     | SOME (entry, _) => f entry)
       
   176   in NameSpace (Symtab.update (xname, (entry', stamp ())) tab) end;
       
   177 
   174 
   178 fun del (name: string) = remove (op =) name;
   175 fun del (name: string) = remove (op =) name;
   179 fun add name names = name :: del name names;
   176 fun add name names = name :: del name names;
   180 
   177 
   181 val del_name = map_space o apfst o del;
   178 val del_name = map_space o apfst o del;
   268 
   265 
   269 type 'a table = T * 'a Symtab.table;
   266 type 'a table = T * 'a Symtab.table;
   270 
   267 
   271 val empty_table = (empty, Symtab.empty);
   268 val empty_table = (empty, Symtab.empty);
   272 
   269 
   273 fun extend_table naming ((space, tab), bentries) =
   270 fun extend_table naming bentries (space, tab) =
   274   let val entries = map (apfst (full naming)) bentries
   271   let val entries = map (apfst (full naming)) bentries
   275   in (fold (declare naming o #1) entries space, Symtab.extend (tab, entries)) end;
   272   in (fold (declare naming o #1) entries space, Symtab.extend (tab, entries)) end;
   276 
   273 
   277 fun merge_tables eq ((space1, tab1), (space2, tab2)) =
   274 fun merge_tables eq ((space1, tab1), (space2, tab2)) =
   278   (merge (space1, space2), Symtab.merge eq (tab1, tab2));
   275   (merge (space1, space2), Symtab.merge eq (tab1, tab2));