equal
deleted
inserted
replaced
1 (* Title: Pure/General/name_space.ML |
1 (* Title: Pure/General/name_space.ML |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: Markus Wenzel, TU Muenchen |
3 Author: Markus Wenzel, TU Muenchen |
4 |
4 |
5 Generic name spaces with declared and hidden entries. Unknown names |
5 Generic name spaces with declared and hidden entries. Unknown names |
6 are considered as global; no support for absolute addressing. |
6 are considered global; no support for absolute addressing. |
7 *) |
7 *) |
8 |
8 |
9 type bstring = string; (*names to be bound / internalized*) |
9 type bstring = string; (*names to be bound / internalized*) |
10 type xstring = string; (*externalized names / to be printed*) |
10 type xstring = string; (*externalized names / to be printed*) |
11 |
11 |
35 type T |
35 type T |
36 val empty: T |
36 val empty: T |
37 val valid_accesses: T -> string -> xstring list |
37 val valid_accesses: T -> string -> xstring list |
38 val intern: T -> xstring -> string |
38 val intern: T -> xstring -> string |
39 val extern: T -> string -> xstring |
39 val extern: T -> string -> xstring |
40 val extern_table: T -> 'a Symtab.table -> (xstring * 'a) list |
|
41 val hide: bool -> string -> T -> T |
40 val hide: bool -> string -> T -> T |
42 val merge: T * T -> T |
41 val merge: T * T -> T |
43 val dest: T -> (string * xstring list) list |
42 val dest: T -> (string * xstring list) list |
44 type naming |
43 type naming |
45 val path_of: naming -> string |
44 val path_of: naming -> string |
50 val qualified_names: naming -> naming |
49 val qualified_names: naming -> naming |
51 val no_base_names: naming -> naming |
50 val no_base_names: naming -> naming |
52 val custom_accesses: (string list -> string list list) -> naming -> naming |
51 val custom_accesses: (string list -> string list list) -> naming -> naming |
53 val set_policy: (string -> bstring -> string) * (string list -> string list list) -> |
52 val set_policy: (string -> bstring -> string) * (string list -> string list list) -> |
54 naming -> naming |
53 naming -> naming |
|
54 type 'a table = T * 'a Symtab.table |
|
55 val empty_table: 'a table |
|
56 val extend_table: naming -> 'a table * (bstring * 'a) list -> 'a table |
|
57 val merge_tables: ('a * 'a -> bool) -> 'a table * 'a table -> 'a table |
|
58 val extern_table: 'a table -> (xstring * 'a) list |
55 end; |
59 end; |
56 |
60 |
57 structure NameSpace: NAME_SPACE = |
61 structure NameSpace: NAME_SPACE = |
58 struct |
62 struct |
59 |
63 |
140 in |
144 in |
141 if ! long_names then name |
145 if ! long_names then name |
142 else if ! short_names then base name |
146 else if ! short_names then base name |
143 else ex (accesses' name) |
147 else ex (accesses' name) |
144 end; |
148 end; |
145 |
|
146 fun extern_table space tab = |
|
147 Library.sort_wrt #1 (map (apfst (extern space)) (Symtab.dest tab)); |
|
148 |
149 |
149 |
150 |
150 (* basic operations *) |
151 (* basic operations *) |
151 |
152 |
152 fun map_space f xname (NameSpace tab) = |
153 fun map_space f xname (NameSpace tab) = |
242 |
243 |
243 fun custom_accesses accs (Naming (path, (qualify, _))) = Naming (path, (qualify, accs)); |
244 fun custom_accesses accs (Naming (path, (qualify, _))) = Naming (path, (qualify, accs)); |
244 fun set_policy policy (Naming (path, _)) = Naming (path, policy); |
245 fun set_policy policy (Naming (path, _)) = Naming (path, policy); |
245 |
246 |
246 |
247 |
|
248 |
|
249 (** name spaces coupled with symbol tables **) |
|
250 |
|
251 type 'a table = T * 'a Symtab.table; |
|
252 |
|
253 val empty_table = (empty, Symtab.empty); |
|
254 |
|
255 fun extend_table naming ((space, tab), bentries) = |
|
256 let val entries = map (apfst (full naming)) bentries |
|
257 in (fold (declare naming o #1) entries space, Symtab.extend (tab, entries)) end; |
|
258 |
|
259 fun merge_tables eq ((space1, tab1), (space2, tab2)) = |
|
260 (merge (space1, space2), (Symtab.merge eq (tab1, tab2))); |
|
261 |
|
262 fun extern_table (space, tab) = |
|
263 Library.sort_wrt #1 (map (apfst (extern space)) (Symtab.dest tab)); |
|
264 |
247 end; |
265 end; |
248 |
266 |
249 structure BasicNameSpace: BASIC_NAME_SPACE = NameSpace; |
267 structure BasicNameSpace: BASIC_NAME_SPACE = NameSpace; |
250 open BasicNameSpace; |
268 open BasicNameSpace; |