| author | wenzelm | 
| Tue, 09 Jan 2024 16:04:21 +0100 | |
| changeset 79451 | ef867bf3e6c9 | 
| parent 77992 | 1de3db73618e | 
| child 80298 | f3bfec3b02f0 | 
| permissions | -rw-r--r-- | 
| 6118 | 1  | 
(* Title: Pure/General/name_space.ML  | 
| 77984 | 2  | 
Author: Makarius  | 
| 5012 | 3  | 
|
| 77984 | 4  | 
Generic name spaces with authentic declarations, hidden names and aliases.  | 
| 16137 | 5  | 
*)  | 
6  | 
||
| 77984 | 7  | 
type xstring = string; (*external names with partial qualification*)  | 
| 5012 | 8  | 
|
9  | 
signature NAME_SPACE =  | 
|
10  | 
sig  | 
|
| 
77970
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
11  | 
type T  | 
| 
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
12  | 
val empty: string -> T  | 
| 
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
13  | 
val kind_of: T -> string  | 
| 
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
14  | 
val markup: T -> string -> Markup.T  | 
| 
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
15  | 
val markup_def: T -> string -> Markup.T  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
16  | 
val get_names: T -> string list  | 
| 
77970
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
17  | 
val the_entry: T -> string ->  | 
| 
74261
 
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
 
wenzelm 
parents: 
74183 
diff
changeset
 | 
18  | 
   {concealed: bool,
 | 
| 
77960
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
19  | 
suppress: bool list,  | 
| 
77819
 
d2645d3ad9e9
minor performance tuning: more compact persistent data;
 
wenzelm 
parents: 
77815 
diff
changeset
 | 
20  | 
group: serial,  | 
| 
74261
 
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
 
wenzelm 
parents: 
74183 
diff
changeset
 | 
21  | 
theory_long_name: string,  | 
| 
 
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
 
wenzelm 
parents: 
74183 
diff
changeset
 | 
22  | 
pos: Position.T,  | 
| 
 
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
 
wenzelm 
parents: 
74183 
diff
changeset
 | 
23  | 
serial: serial}  | 
| 77967 | 24  | 
  val theory_name: {long: bool} -> T -> string -> string
 | 
| 70586 | 25  | 
val entry_ord: T -> string ord  | 
| 
33157
 
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
 
wenzelm 
parents: 
33097 
diff
changeset
 | 
26  | 
val is_concealed: T -> string -> bool  | 
| 16137 | 27  | 
val intern: T -> xstring -> string  | 
| 
42669
 
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
 
wenzelm 
parents: 
42493 
diff
changeset
 | 
28  | 
val names_long: bool Config.T  | 
| 
 
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
 
wenzelm 
parents: 
42493 
diff
changeset
 | 
29  | 
val names_short: bool Config.T  | 
| 
 
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
 
wenzelm 
parents: 
42493 
diff
changeset
 | 
30  | 
val names_unique: bool Config.T  | 
| 
42358
 
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
 
wenzelm 
parents: 
42327 
diff
changeset
 | 
31  | 
val extern: Proof.context -> T -> string -> xstring  | 
| 70586 | 32  | 
val extern_ord: Proof.context -> T -> string ord  | 
| 
55672
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
33  | 
val extern_shortest: Proof.context -> T -> string -> xstring  | 
| 
51510
 
b4f7e6734acc
tuned print_classes: more standard order, markup, formatting;
 
wenzelm 
parents: 
50301 
diff
changeset
 | 
34  | 
val markup_extern: Proof.context -> T -> string -> Markup.T * xstring  | 
| 53539 | 35  | 
val pretty: Proof.context -> T -> string -> Pretty.T  | 
| 69185 | 36  | 
val completion: Context.generic -> T -> (string -> bool) -> xstring * Position.T -> Completion.T  | 
| 5012 | 37  | 
val merge: T * T -> T  | 
| 16137 | 38  | 
type naming  | 
| 59912 | 39  | 
val get_scopes: naming -> Binding.scope list  | 
| 59886 | 40  | 
val get_scope: naming -> Binding.scope option  | 
41  | 
val new_scope: naming -> Binding.scope * naming  | 
|
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
42  | 
val restricted: bool -> Position.T -> naming -> naming  | 
| 
59923
 
b21c82422d65
support private scope for individual local theory commands;
 
wenzelm 
parents: 
59917 
diff
changeset
 | 
43  | 
val private_scope: Binding.scope -> naming -> naming  | 
| 
 
b21c82422d65
support private scope for individual local theory commands;
 
wenzelm 
parents: 
59917 
diff
changeset
 | 
44  | 
val private: Position.T -> naming -> naming  | 
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
45  | 
val qualified_scope: Binding.scope -> naming -> naming  | 
| 
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
46  | 
val qualified: Position.T -> naming -> naming  | 
| 59859 | 47  | 
val concealed: naming -> naming  | 
| 33724 | 48  | 
val get_group: naming -> serial option  | 
49  | 
val set_group: serial option -> naming -> naming  | 
|
| 71257 | 50  | 
val set_theory_long_name: string -> naming -> naming  | 
| 33724 | 51  | 
val new_group: naming -> naming  | 
52  | 
val reset_group: naming -> naming  | 
|
| 16137 | 53  | 
val add_path: string -> naming -> naming  | 
| 
30418
 
b5044aca0729
add_path: discontinued special meaning of "//", "/", "..";
 
wenzelm 
parents: 
30412 
diff
changeset
 | 
54  | 
val root_path: naming -> naming  | 
| 
 
b5044aca0729
add_path: discontinued special meaning of "//", "/", "..";
 
wenzelm 
parents: 
30412 
diff
changeset
 | 
55  | 
val parent_path: naming -> naming  | 
| 30469 | 56  | 
val mandatory_path: string -> naming -> naming  | 
| 
35200
 
aaddb2b526d6
more systematic treatment of qualified names derived from binding;
 
wenzelm 
parents: 
33724 
diff
changeset
 | 
57  | 
val qualified_path: bool -> binding -> naming -> naming  | 
| 58668 | 58  | 
val global_naming: naming  | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
59  | 
val local_naming: naming  | 
| 59887 | 60  | 
val transform_naming: naming -> naming -> naming  | 
| 
33281
 
223ef9bc399a
let naming transform binding beforehand -- covering only the "conceal" flag for now;
 
wenzelm 
parents: 
33164 
diff
changeset
 | 
61  | 
val transform_binding: naming -> binding -> binding  | 
| 
33157
 
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
 
wenzelm 
parents: 
33097 
diff
changeset
 | 
62  | 
val full_name: naming -> binding -> string  | 
| 
47021
 
f35f654f297d
clarified Binding.name_of vs Name_Space.base_name vs Variable.check_name (see also 9bd8d4addd6e, 3305f573294e);
 
wenzelm 
parents: 
47005 
diff
changeset
 | 
63  | 
val base_name: binding -> string  | 
| 
56168
 
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
 
wenzelm 
parents: 
56164 
diff
changeset
 | 
64  | 
val hide: bool -> string -> T -> T  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
65  | 
val alias: naming -> binding -> string -> T -> T  | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
66  | 
val naming_of: Context.generic -> naming  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
67  | 
val map_naming: (naming -> naming) -> Context.generic -> Context.generic  | 
| 68163 | 68  | 
val declared: T -> string -> bool  | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
69  | 
val declare: Context.generic -> bool -> binding -> T -> string * T  | 
| 56025 | 70  | 
type 'a table  | 
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
71  | 
val change_base: bool -> 'a table -> 'a table  | 
| 
56139
 
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
 
wenzelm 
parents: 
56056 
diff
changeset
 | 
72  | 
val change_ignore: 'a table -> 'a table  | 
| 56025 | 73  | 
val space_of_table: 'a table -> T  | 
| 
55922
 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 
wenzelm 
parents: 
55845 
diff
changeset
 | 
74  | 
val check_reports: Context.generic -> 'a table ->  | 
| 
55956
 
94d384d621b0
reject internal term names outright, and complete consts instead;
 
wenzelm 
parents: 
55923 
diff
changeset
 | 
75  | 
xstring * Position.T list -> (string * Position.report list) * 'a  | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
76  | 
val check: Context.generic -> 'a table -> xstring * Position.T -> string * 'a  | 
| 59883 | 77  | 
val defined: 'a table -> string -> bool  | 
| 59884 | 78  | 
val lookup: 'a table -> string -> 'a option  | 
| 56025 | 79  | 
val lookup_key: 'a table -> string -> (string * 'a) option  | 
| 42466 | 80  | 
val get: 'a table -> string -> 'a  | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
81  | 
val define: Context.generic -> bool -> binding * 'a -> 'a table -> string * 'a table  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
82  | 
val alias_table: naming -> binding -> string -> 'a table -> 'a table  | 
| 56025 | 83  | 
val hide_table: bool -> string -> 'a table -> 'a table  | 
84  | 
val del_table: string -> 'a table -> 'a table  | 
|
85  | 
  val map_table_entry: string -> ('a -> 'a) -> 'a table -> 'a table
 | 
|
86  | 
val fold_table: (string * 'a -> 'b -> 'b) -> 'a table -> 'b -> 'b  | 
|
| 68163 | 87  | 
val dest_table: 'a table -> (string * 'a) list  | 
| 33096 | 88  | 
val empty_table: string -> 'a table  | 
| 
33091
 
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
 
wenzelm 
parents: 
33049 
diff
changeset
 | 
89  | 
val merge_tables: 'a table * 'a table -> 'a table  | 
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
90  | 
val join_tables: (string -> 'a * 'a -> 'a) (*exception Change_Table.SAME*) ->  | 
| 
33097
 
9d501e11084a
maintain position of formal entities via name space;
 
wenzelm 
parents: 
33096 
diff
changeset
 | 
91  | 
'a table * 'a table -> 'a table  | 
| 
59917
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
92  | 
val extern_entries: bool -> Proof.context -> T -> (string * 'a) list ->  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
93  | 
((string * xstring) * 'a) list  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
94  | 
val markup_entries: bool -> Proof.context -> T -> (string * 'a) list ->  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
95  | 
((Markup.T * xstring) * 'a) list  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
96  | 
val extern_table: bool -> Proof.context -> 'a table -> ((string * xstring) * 'a) list  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
97  | 
val markup_table: bool -> Proof.context -> 'a table -> ((Markup.T * xstring) * 'a) list  | 
| 5012 | 98  | 
end;  | 
99  | 
||
| 
33095
 
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
 
wenzelm 
parents: 
33091 
diff
changeset
 | 
100  | 
structure Name_Space: NAME_SPACE =  | 
| 5012 | 101  | 
struct  | 
102  | 
||
| 
30412
 
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
 
wenzelm 
parents: 
30359 
diff
changeset
 | 
103  | 
|
| 
 
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
 
wenzelm 
parents: 
30359 
diff
changeset
 | 
104  | 
(** name spaces **)  | 
| 
 
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
 
wenzelm 
parents: 
30359 
diff
changeset
 | 
105  | 
|
| 
33091
 
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
 
wenzelm 
parents: 
33049 
diff
changeset
 | 
106  | 
(* datatype entry *)  | 
| 
 
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
 
wenzelm 
parents: 
33049 
diff
changeset
 | 
107  | 
|
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
108  | 
type entry =  | 
| 
35679
 
da87ffdcf7ea
added Name_Space.alias -- additional accesses for an existing entry;
 
wenzelm 
parents: 
35432 
diff
changeset
 | 
109  | 
 {concealed: bool,
 | 
| 
77960
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
110  | 
suppress: bool list,  | 
| 
77819
 
d2645d3ad9e9
minor performance tuning: more compact persistent data;
 
wenzelm 
parents: 
77815 
diff
changeset
 | 
111  | 
group: serial,  | 
| 71257 | 112  | 
theory_long_name: string,  | 
| 
33091
 
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
 
wenzelm 
parents: 
33049 
diff
changeset
 | 
113  | 
pos: Position.T,  | 
| 
57899
 
5867d1306712
clarified signature: entity serial number is not position id;
 
wenzelm 
parents: 
56438 
diff
changeset
 | 
114  | 
serial: serial};  | 
| 
33091
 
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
 
wenzelm 
parents: 
33049 
diff
changeset
 | 
115  | 
|
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
116  | 
fun markup_entry def kind (name, entry: entry) =  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
117  | 
Position.make_entity_markup def (#serial entry) kind (name, #pos entry);  | 
| 42135 | 118  | 
|
| 
49816
 
e63d6c55ad6d
more position information for hyperlink and placement of message;
 
wenzelm 
parents: 
49528 
diff
changeset
 | 
119  | 
fun print_entry_ref kind (name, entry) =  | 
| 
77970
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
120  | 
  quote (Markup.markup (markup_entry {def = false} kind (name, entry)) name);
 | 
| 
33091
 
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
 
wenzelm 
parents: 
33049 
diff
changeset
 | 
121  | 
|
| 
77970
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
122  | 
fun err_dup_entry kind entry1 entry2 pos =  | 
| 
56038
 
0e2dec666152
tuned messages -- in accordance to Isabelle/Scala;
 
wenzelm 
parents: 
56025 
diff
changeset
 | 
123  | 
  error ("Duplicate " ^ plain_words kind ^ " declaration " ^
 | 
| 
49816
 
e63d6c55ad6d
more position information for hyperlink and placement of message;
 
wenzelm 
parents: 
49528 
diff
changeset
 | 
124  | 
print_entry_ref kind entry1 ^ " vs. " ^ print_entry_ref kind entry2 ^ Position.here pos);  | 
| 33096 | 125  | 
|
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
126  | 
fun update_entry strict kind (name, entry: entry) entries =  | 
| 
77970
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
127  | 
(if strict then Change_Table.update_new else Change_Table.update) (name, entry) entries  | 
| 
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
128  | 
handle Change_Table.DUP _ =>  | 
| 
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
129  | 
let val old_entry = the (Change_Table.lookup entries name)  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
130  | 
in err_dup_entry kind (name, old_entry) (name, entry) (#pos entry) end;  | 
| 
77970
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
131  | 
|
| 
33091
 
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
 
wenzelm 
parents: 
33049 
diff
changeset
 | 
132  | 
|
| 56164 | 133  | 
(* internal names *)  | 
134  | 
||
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
135  | 
type internals = string list Long_Name.Chunks.T; (*external name -> internal names*)  | 
| 56164 | 136  | 
|
| 77992 | 137  | 
val merge_internals : internals * internals -> internals =  | 
138  | 
Long_Name.Chunks.merge_list (op =);  | 
|
| 77948 | 139  | 
|
| 77978 | 140  | 
fun add_internals name xname : internals -> internals =  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
141  | 
Long_Name.Chunks.update_list (op =) (xname, name);  | 
| 56164 | 142  | 
|
| 77978 | 143  | 
fun del_internals name xname : internals -> internals =  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
144  | 
Long_Name.Chunks.remove_list (op =) (xname, name);  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
145  | 
|
| 77978 | 146  | 
fun del_internals' name xname : internals -> internals =  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
147  | 
Long_Name.Chunks.map_default (xname, []) (fn [] => [] | x :: xs => x :: remove (op =) name xs);  | 
| 56164 | 148  | 
|
149  | 
||
| 77950 | 150  | 
(* accesses *)  | 
151  | 
||
152  | 
local  | 
|
153  | 
||
| 
77960
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
154  | 
fun suppress_prefixes1 [] = []  | 
| 
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
155  | 
| suppress_prefixes1 (s :: ss) =  | 
| 
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
156  | 
map (cons false) (if s then suppress_prefixes ss else suppress_prefixes1 ss)  | 
| 
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
157  | 
and suppress_prefixes ss = ss :: suppress_prefixes1 ss;  | 
| 77950 | 158  | 
|
| 
77960
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
159  | 
fun suppress_suffixes ss = map rev (suppress_prefixes (rev ss));  | 
| 
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
160  | 
|
| 
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
161  | 
fun make_chunks full_name m s =  | 
| 
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
162  | 
let val chunks = Long_Name.suppress_chunks 0 s full_name  | 
| 
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
163  | 
in if Long_Name.count_chunks chunks > m then SOME chunks else NONE end;  | 
| 
77956
 
948f5dc4d694
more complete accesses for hide operation (amending fcd85e04a948), e.g. relevant for AFP/thys/Jordan_Normal_Form/Matrix_Kernel.thy in AFP/4d8afd37b465;
 
wenzelm 
parents: 
77954 
diff
changeset
 | 
164  | 
|
| 77950 | 165  | 
in  | 
166  | 
||
| 77983 | 167  | 
fun make_accesses {intern} restriction (suppress, full_name) =
 | 
| 
77956
 
948f5dc4d694
more complete accesses for hide operation (amending fcd85e04a948), e.g. relevant for AFP/thys/Jordan_Normal_Form/Matrix_Kernel.thy in AFP/4d8afd37b465;
 
wenzelm 
parents: 
77954 
diff
changeset
 | 
168  | 
if restriction = SOME true then []  | 
| 
 
948f5dc4d694
more complete accesses for hide operation (amending fcd85e04a948), e.g. relevant for AFP/thys/Jordan_Normal_Form/Matrix_Kernel.thy in AFP/4d8afd37b465;
 
wenzelm 
parents: 
77954 
diff
changeset
 | 
169  | 
else  | 
| 
77960
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
170  | 
((if intern then suppress_prefixes suppress else []) @ suppress_suffixes suppress)  | 
| 
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
171  | 
|> map_filter (make_chunks full_name (if is_some restriction then 1 else 0))  | 
| 
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
172  | 
|> distinct Long_Name.eq_chunks;  | 
| 77950 | 173  | 
|
174  | 
end;  | 
|
175  | 
||
176  | 
||
| 5012 | 177  | 
(* datatype T *)  | 
178  | 
||
| 
77954
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
179  | 
datatype T =  | 
| 
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
180  | 
Name_Space of  | 
| 
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
181  | 
   {kind: string,
 | 
| 
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
182  | 
internals: internals,  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
183  | 
internals_hidden: internals,  | 
| 
77954
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
184  | 
entries: entry Change_Table.T,  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
185  | 
aliases: (bool list * string) list Symtab.table};  | 
| 33096 | 186  | 
|
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
187  | 
fun make_name_space (kind, internals, internals_hidden, entries, aliases) =  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
188  | 
  Name_Space {kind = kind, internals = internals, internals_hidden = internals_hidden,
 | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
189  | 
entries = entries, aliases = aliases};  | 
| 33096 | 190  | 
|
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
191  | 
fun map_name_space f (Name_Space {kind, internals, internals_hidden, entries, aliases}) =
 | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
192  | 
make_name_space (f (kind, internals, internals_hidden, entries, aliases));  | 
| 
77954
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
193  | 
|
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
194  | 
fun change_base_space begin =  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
195  | 
map_name_space (fn (kind, internals, internals_hidden, entries, aliases) =>  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
196  | 
(kind,  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
197  | 
Long_Name.Chunks.change_base begin internals,  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
198  | 
Long_Name.Chunks.change_base begin internals_hidden,  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
199  | 
Change_Table.change_base begin entries,  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
200  | 
aliases));  | 
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
201  | 
|
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
202  | 
val change_ignore_space =  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
203  | 
map_name_space (fn (kind, internals, internals_hidden, entries, aliases) =>  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
204  | 
(kind,  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
205  | 
Long_Name.Chunks.change_ignore internals,  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
206  | 
Long_Name.Chunks.change_ignore internals_hidden,  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
207  | 
Change_Table.change_ignore entries,  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
208  | 
aliases));  | 
| 
56139
 
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
 
wenzelm 
parents: 
56056 
diff
changeset
 | 
209  | 
|
| 5012 | 210  | 
|
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
211  | 
fun empty kind =  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
212  | 
make_name_space  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
213  | 
(kind, Long_Name.Chunks.empty, Long_Name.Chunks.empty, Change_Table.empty, Symtab.empty);  | 
| 33096 | 214  | 
|
215  | 
fun kind_of (Name_Space {kind, ...}) = kind;
 | 
|
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
216  | 
fun lookup_internals (Name_Space {internals, ...}) =
 | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
217  | 
Long_Name.Chunks.lookup_list internals;  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
218  | 
fun lookup_internals_hidden (Name_Space {internals_hidden, ...}) =
 | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
219  | 
Long_Name.Chunks.lookup_list internals_hidden;  | 
| 
77954
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
220  | 
fun lookup_entries (Name_Space {entries, ...}) = Change_Table.lookup entries;
 | 
| 77961 | 221  | 
fun lookup_aliases (Name_Space {aliases, ...}) = Symtab.lookup_list aliases;
 | 
222  | 
||
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
223  | 
|
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
224  | 
fun suppress_entry space name =  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
225  | 
(case lookup_entries space name of  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
226  | 
    SOME {suppress, ...} => (suppress, name)
 | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
227  | 
| NONE => ([], name));  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
228  | 
|
| 77961 | 229  | 
fun is_alias space c a =  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
230  | 
c = a orelse exists (fn (_, b) => b = a) (lookup_aliases space c);  | 
| 5012 | 231  | 
|
| 
77947
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
232  | 
fun get_aliases space name =  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
233  | 
lookup_aliases space name @ [suppress_entry space name];  | 
| 
77947
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
234  | 
|
| 77840 | 235  | 
fun gen_markup def space name =  | 
| 
77954
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
236  | 
(case lookup_entries space name of  | 
| 
50201
 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 
wenzelm 
parents: 
49816 
diff
changeset
 | 
237  | 
NONE => Markup.intensify  | 
| 
77970
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
238  | 
| SOME entry => markup_entry def (kind_of space) (name, entry));  | 
| 
62987
 
dc8a8a7559e7
highlighting of entity def/ref positions wrt. cursor;
 
wenzelm 
parents: 
62967 
diff
changeset
 | 
239  | 
|
| 74262 | 240  | 
val markup = gen_markup {def = false};
 | 
241  | 
val markup_def = gen_markup {def = true};
 | 
|
| 42135 | 242  | 
|
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
243  | 
fun undefined_entry (space as Name_Space {kind, entries, ...}) bad =
 | 
| 59889 | 244  | 
let  | 
245  | 
val (prfx, sfx) =  | 
|
246  | 
(case Long_Name.dest_hidden bad of  | 
|
247  | 
SOME name =>  | 
|
| 
77954
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
248  | 
if Change_Table.defined entries name  | 
| 59889 | 249  | 
          then ("Inaccessible", Markup.markup (markup space name) (quote name))
 | 
250  | 
          else ("Undefined", quote name)
 | 
|
251  | 
      | NONE => ("Undefined", quote bad));
 | 
|
252  | 
in prfx ^ " " ^ plain_words kind ^ ": " ^ sfx end;  | 
|
253  | 
||
| 77840 | 254  | 
fun the_entry space name =  | 
| 
77954
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
255  | 
(case lookup_entries space name of  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
256  | 
SOME entry => entry  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
257  | 
| _ => error (undefined_entry space name));  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
258  | 
|
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
259  | 
fun get_names (Name_Space {entries, ...}) =
 | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
260  | 
Change_Table.fold (cons o #1) entries [];  | 
| 59889 | 261  | 
|
| 77967 | 262  | 
fun theory_name {long} space name =
 | 
263  | 
#theory_long_name (the_entry space name)  | 
|
264  | 
|> not long ? Long_Name.base_name;  | 
|
| 71257 | 265  | 
|
| 59889 | 266  | 
fun entry_ord space = int_ord o apply2 (#serial o the_entry space);  | 
267  | 
||
| 
60282
 
496fa0fc91b1
more permissive operation: allow to print undeclared name space entries, e.g. print_simpset with "record" simproc;
 
wenzelm 
parents: 
59990 
diff
changeset
 | 
268  | 
fun is_concealed space name =  | 
| 
 
496fa0fc91b1
more permissive operation: allow to print undeclared name space entries, e.g. print_simpset with "record" simproc;
 
wenzelm 
parents: 
59990 
diff
changeset
 | 
269  | 
#concealed (the_entry space name) handle ERROR _ => false;  | 
| 33096 | 270  | 
|
271  | 
||
| 59884 | 272  | 
(* intern *)  | 
| 33096 | 273  | 
|
| 
77845
 
39007362ab7d
proforma use of Long_Name.chunks, without change of the representation of accesses yet;
 
wenzelm 
parents: 
77841 
diff
changeset
 | 
274  | 
fun intern_chunks space xname =  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
275  | 
(case lookup_internals space xname of  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
276  | 
    name :: rest => {name = name, full_name = name, unique = null rest}
 | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
277  | 
| [] =>  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
278  | 
(case lookup_internals_hidden space xname of  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
279  | 
        name' :: _ => {name = Long_Name.hidden name', full_name = "", unique = true}
 | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
280  | 
| [] =>  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
281  | 
         {name = Long_Name.hidden (Long_Name.implode_chunks xname),
 | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
282  | 
full_name = "",  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
283  | 
unique = true}));  | 
| 8728 | 284  | 
|
| 77946 | 285  | 
fun intern space = #name o intern_chunks space o Long_Name.make_chunks;  | 
| 59884 | 286  | 
|
| 8728 | 287  | 
|
| 
55672
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
288  | 
(* extern *)  | 
| 
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
289  | 
|
| 69575 | 290  | 
val names_long = Config.declare_option_bool ("names_long", \<^here>);
 | 
291  | 
val names_short = Config.declare_option_bool ("names_short", \<^here>);
 | 
|
292  | 
val names_unique = Config.declare_option_bool ("names_unique", \<^here>);
 | 
|
| 
42358
 
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
 
wenzelm 
parents: 
42327 
diff
changeset
 | 
293  | 
|
| 
 
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
 
wenzelm 
parents: 
42327 
diff
changeset
 | 
294  | 
fun extern ctxt space name =  | 
| 16137 | 295  | 
let  | 
| 
42669
 
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
 
wenzelm 
parents: 
42493 
diff
changeset
 | 
296  | 
val names_long = Config.get ctxt names_long;  | 
| 
 
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
 
wenzelm 
parents: 
42493 
diff
changeset
 | 
297  | 
val names_short = Config.get ctxt names_short;  | 
| 
 
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
 
wenzelm 
parents: 
42493 
diff
changeset
 | 
298  | 
val names_unique = Config.get ctxt names_unique;  | 
| 
42358
 
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
 
wenzelm 
parents: 
42327 
diff
changeset
 | 
299  | 
|
| 
77960
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
300  | 
fun extern_chunks require_unique a chunks =  | 
| 77961 | 301  | 
      let val {full_name = c, unique, ...} = intern_chunks space chunks in
 | 
302  | 
if (not require_unique orelse unique) andalso is_alias space c a  | 
|
| 
77947
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
303  | 
then SOME (Long_Name.implode_chunks chunks)  | 
| 
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
304  | 
else NONE  | 
| 
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
305  | 
end;  | 
| 8728 | 306  | 
|
| 77983 | 307  | 
fun extern_name (suppress, a) =  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
308  | 
get_first (extern_chunks names_unique a)  | 
| 77983 | 309  | 
        (make_accesses {intern = false} NONE (suppress, a));
 | 
| 
77947
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
310  | 
|
| 
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
311  | 
fun extern_names aliases =  | 
| 77983 | 312  | 
(case get_first extern_name aliases of  | 
| 
77947
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
313  | 
SOME xname => xname  | 
| 
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
314  | 
| NONE =>  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
315  | 
(case get_first (fn (_, a) => extern_chunks false a (Long_Name.make_chunks a)) aliases of  | 
| 
77947
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
316  | 
SOME xname => xname  | 
| 
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
317  | 
| NONE => Long_Name.hidden name));  | 
| 16137 | 318  | 
in  | 
| 
42669
 
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
 
wenzelm 
parents: 
42493 
diff
changeset
 | 
319  | 
if names_long then name  | 
| 
 
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
 
wenzelm 
parents: 
42493 
diff
changeset
 | 
320  | 
else if names_short then Long_Name.base_name name  | 
| 
77947
 
238307775d52
clarified extern vs. alias/hide: output alternative names, if possible;
 
wenzelm 
parents: 
77946 
diff
changeset
 | 
321  | 
else extern_names (get_aliases space name)  | 
| 16137 | 322  | 
end;  | 
323  | 
||
| 
59058
 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 
wenzelm 
parents: 
58668 
diff
changeset
 | 
324  | 
fun extern_ord ctxt space = string_ord o apply2 (extern ctxt space);  | 
| 
51510
 
b4f7e6734acc
tuned print_classes: more standard order, markup, formatting;
 
wenzelm 
parents: 
50301 
diff
changeset
 | 
325  | 
|
| 
55672
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
326  | 
fun extern_shortest ctxt =  | 
| 
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
327  | 
extern  | 
| 
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
328  | 
(ctxt  | 
| 
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
329  | 
|> Config.put names_long false  | 
| 
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
330  | 
|> Config.put names_short false  | 
| 
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
331  | 
|> Config.put names_unique false);  | 
| 
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
332  | 
|
| 
51510
 
b4f7e6734acc
tuned print_classes: more standard order, markup, formatting;
 
wenzelm 
parents: 
50301 
diff
changeset
 | 
333  | 
fun markup_extern ctxt space name = (markup space name, extern ctxt space name);  | 
| 
55672
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
334  | 
fun pretty ctxt space name = Pretty.mark_str (markup_extern ctxt space name);  | 
| 
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
335  | 
|
| 
51510
 
b4f7e6734acc
tuned print_classes: more standard order, markup, formatting;
 
wenzelm 
parents: 
50301 
diff
changeset
 | 
336  | 
|
| 
55672
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
337  | 
(* completion *)  | 
| 
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
338  | 
|
| 69185 | 339  | 
fun completion context space pred (xname, pos) =  | 
| 59812 | 340  | 
Completion.make (xname, pos) (fn completed =>  | 
| 
55672
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
341  | 
let  | 
| 66249 | 342  | 
fun result_ord ((pri1, (xname1, (_, name1))), (pri2, (xname2, (_, name2)))) =  | 
343  | 
(case int_ord (pri2, pri1) of  | 
|
| 
56162
 
ea6303e2261b
clarified completion ordering: prefer local names;
 
wenzelm 
parents: 
56160 
diff
changeset
 | 
344  | 
EQUAL =>  | 
| 
62967
 
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
 
wenzelm 
parents: 
62241 
diff
changeset
 | 
345  | 
(case bool_ord (apply2 (is_some o Long_Name.dest_local) (name2, name1)) of  | 
| 
 
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
 
wenzelm 
parents: 
62241 
diff
changeset
 | 
346  | 
EQUAL =>  | 
| 77854 | 347  | 
(case int_ord (apply2 Long_Name.count (xname1, xname2)) of  | 
| 
62967
 
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
 
wenzelm 
parents: 
62241 
diff
changeset
 | 
348  | 
EQUAL => string_ord (xname1, xname2)  | 
| 
 
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
 
wenzelm 
parents: 
62241 
diff
changeset
 | 
349  | 
| ord => ord)  | 
| 
56162
 
ea6303e2261b
clarified completion ordering: prefer local names;
 
wenzelm 
parents: 
56160 
diff
changeset
 | 
350  | 
| ord => ord)  | 
| 56024 | 351  | 
| ord => ord);  | 
| 55975 | 352  | 
      val Name_Space {kind, internals, ...} = space;
 | 
| 
55694
 
a1184dfb8e00
clarified semantic completion: retain kind.full_name as official item name for history;
 
wenzelm 
parents: 
55687 
diff
changeset
 | 
353  | 
val ext = extern_shortest (Context.proof_of context) space;  | 
| 63232 | 354  | 
val full = Name.clean xname = "";  | 
| 66247 | 355  | 
|
| 66249 | 356  | 
fun complete xname' name =  | 
357  | 
if (completed xname' orelse exists completed (Long_Name.explode xname')) andalso  | 
|
| 69185 | 358  | 
not (is_concealed space name) andalso pred name  | 
| 66249 | 359  | 
then  | 
360  | 
let  | 
|
361  | 
val xname'' = ext name;  | 
|
362  | 
val pri = (if xname' = xname'' then 1 else 0) + (if completed xname' then 1 else 0);  | 
|
363  | 
in  | 
|
| 66247 | 364  | 
if xname' <> xname'' andalso full then I  | 
| 66249 | 365  | 
else cons (pri, (xname', (kind, name)))  | 
| 66247 | 366  | 
end  | 
367  | 
else I;  | 
|
| 59812 | 368  | 
in  | 
| 
77845
 
39007362ab7d
proforma use of Long_Name.chunks, without change of the representation of accesses yet;
 
wenzelm 
parents: 
77841 
diff
changeset
 | 
369  | 
Long_Name.Chunks.fold  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
370  | 
(fn (xname', name :: _) => complete (Long_Name.implode_chunks xname') name | _ => I)  | 
| 
77845
 
39007362ab7d
proforma use of Long_Name.chunks, without change of the representation of accesses yet;
 
wenzelm 
parents: 
77841 
diff
changeset
 | 
371  | 
internals []  | 
| 59812 | 372  | 
|> sort_distinct result_ord  | 
| 
62967
 
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
 
wenzelm 
parents: 
62241 
diff
changeset
 | 
373  | 
|> map #2  | 
| 59812 | 374  | 
end);  | 
| 53539 | 375  | 
|
| 5012 | 376  | 
|
| 16137 | 377  | 
(* merge *)  | 
| 5012 | 378  | 
|
| 33096 | 379  | 
fun merge  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
380  | 
   (Name_Space {kind = kind1, internals = internals1, internals_hidden = internals_hidden1,
 | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
381  | 
entries = entries1, aliases = aliases1},  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
382  | 
    Name_Space {kind = kind2, internals = internals2, internals_hidden = internals_hidden2,
 | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
383  | 
entries = entries2, aliases = aliases2}) =  | 
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
384  | 
let  | 
| 33096 | 385  | 
val kind' =  | 
386  | 
if kind1 = kind2 then kind1  | 
|
387  | 
      else error ("Attempt to merge different kinds of name spaces " ^
 | 
|
388  | 
quote kind1 ^ " vs. " ^ quote kind2);  | 
|
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
389  | 
val internals' = merge_internals (internals1, internals2);  | 
| 
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
390  | 
val internals_hidden' = merge_internals (internals_hidden1, internals_hidden2);  | 
| 
77954
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
391  | 
val entries' = (entries1, entries2) |> Change_Table.join (fn name => fn (entry1, entry2) =>  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
392  | 
if op = (apply2 #serial (entry1, entry2)) then raise Change_Table.SAME  | 
| 
77970
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
393  | 
else err_dup_entry kind' (name, entry1) (name, entry2) Position.none);  | 
| 
77954
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
394  | 
val aliases' = Symtab.merge_list (op =) (aliases1, aliases2);  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
395  | 
in make_name_space (kind', internals', internals_hidden', entries', aliases') end;  | 
| 5012 | 396  | 
|
| 16137 | 397  | 
|
| 26440 | 398  | 
|
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
399  | 
(** naming context **)  | 
| 16137 | 400  | 
|
401  | 
(* datatype naming *)  | 
|
402  | 
||
| 
33164
 
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
 
wenzelm 
parents: 
33157 
diff
changeset
 | 
403  | 
datatype naming = Naming of  | 
| 59886 | 404  | 
 {scopes: Binding.scope list,
 | 
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
405  | 
restricted: (bool * Binding.scope) option,  | 
| 59859 | 406  | 
concealed: bool,  | 
| 
77819
 
d2645d3ad9e9
minor performance tuning: more compact persistent data;
 
wenzelm 
parents: 
77815 
diff
changeset
 | 
407  | 
group: serial,  | 
| 71257 | 408  | 
theory_long_name: string,  | 
| 
33164
 
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
 
wenzelm 
parents: 
33157 
diff
changeset
 | 
409  | 
path: (string * bool) list};  | 
| 
 
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
 
wenzelm 
parents: 
33157 
diff
changeset
 | 
410  | 
|
| 71257 | 411  | 
fun make_naming (scopes, restricted, concealed, group, theory_long_name, path) =  | 
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
412  | 
  Naming {scopes = scopes, restricted = restricted, concealed = concealed,
 | 
| 71257 | 413  | 
group = group, theory_long_name = theory_long_name, path = path};  | 
| 
33164
 
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
 
wenzelm 
parents: 
33157 
diff
changeset
 | 
414  | 
|
| 71257 | 415  | 
fun map_naming f (Naming {scopes, restricted, concealed, group, theory_long_name, path}) =
 | 
416  | 
make_naming (f (scopes, restricted, concealed, group, theory_long_name, path));  | 
|
| 16137 | 417  | 
|
| 
33164
 
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
 
wenzelm 
parents: 
33157 
diff
changeset
 | 
418  | 
|
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
419  | 
(* scope and access restriction *)  | 
| 
33164
 
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
 
wenzelm 
parents: 
33157 
diff
changeset
 | 
420  | 
|
| 59886 | 421  | 
fun get_scopes (Naming {scopes, ...}) = scopes;
 | 
422  | 
val get_scope = try hd o get_scopes;  | 
|
| 
33164
 
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
 
wenzelm 
parents: 
33157 
diff
changeset
 | 
423  | 
|
| 59886 | 424  | 
fun new_scope naming =  | 
425  | 
let  | 
|
426  | 
val scope = Binding.new_scope ();  | 
|
427  | 
val naming' =  | 
|
| 71257 | 428  | 
naming |> map_naming (fn (scopes, restricted, concealed, group, theory_long_name, path) =>  | 
429  | 
(scope :: scopes, restricted, concealed, group, theory_long_name, path));  | 
|
| 59886 | 430  | 
in (scope, naming') end;  | 
| 59858 | 431  | 
|
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
432  | 
fun restricted_scope strict scope =  | 
| 71257 | 433  | 
map_naming (fn (scopes, _, concealed, group, theory_long_name, path) =>  | 
434  | 
(scopes, SOME (strict, scope), concealed, group, theory_long_name, path));  | 
|
| 16137 | 435  | 
|
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
436  | 
fun restricted strict pos naming =  | 
| 
59923
 
b21c82422d65
support private scope for individual local theory commands;
 
wenzelm 
parents: 
59917 
diff
changeset
 | 
437  | 
(case get_scope naming of  | 
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
438  | 
SOME scope => restricted_scope strict scope naming  | 
| 
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
439  | 
  | NONE => error ("Missing local scope -- cannot restrict name space accesses" ^ Position.here pos));
 | 
| 
59939
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
440  | 
|
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
441  | 
val private_scope = restricted_scope true;  | 
| 
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
442  | 
val private = restricted true;  | 
| 
59939
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
443  | 
|
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
444  | 
val qualified_scope = restricted_scope false;  | 
| 
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
445  | 
val qualified = restricted false;  | 
| 
59923
 
b21c82422d65
support private scope for individual local theory commands;
 
wenzelm 
parents: 
59917 
diff
changeset
 | 
446  | 
|
| 71257 | 447  | 
val concealed = map_naming (fn (scopes, restricted, _, group, theory_long_name, path) =>  | 
448  | 
(scopes, restricted, true, group, theory_long_name, path));  | 
|
| 
59939
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
449  | 
|
| 59886 | 450  | 
|
| 
59939
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
451  | 
(* additional structural info *)  | 
| 
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
452  | 
|
| 71257 | 453  | 
fun set_theory_long_name theory_long_name =  | 
454  | 
map_naming (fn (scopes, restricted, concealed, group, _, path) =>  | 
|
455  | 
(scopes, restricted, concealed, group, theory_long_name, path));  | 
|
| 33724 | 456  | 
|
| 
77819
 
d2645d3ad9e9
minor performance tuning: more compact persistent data;
 
wenzelm 
parents: 
77815 
diff
changeset
 | 
457  | 
fun get_group (Naming {group, ...}) = if group = 0 then NONE else SOME group;
 | 
| 33724 | 458  | 
|
| 71257 | 459  | 
fun set_group group =  | 
460  | 
map_naming (fn (scopes, restricted, concealed, _, theory_long_name, path) =>  | 
|
| 
77819
 
d2645d3ad9e9
minor performance tuning: more compact persistent data;
 
wenzelm 
parents: 
77815 
diff
changeset
 | 
461  | 
(scopes, restricted, concealed, the_default 0 group, theory_long_name, path));  | 
| 33724 | 462  | 
|
463  | 
fun new_group naming = set_group (SOME (serial ())) naming;  | 
|
464  | 
val reset_group = set_group NONE;  | 
|
465  | 
||
| 
59939
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
466  | 
|
| 
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
467  | 
(* name entry path *)  | 
| 
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
468  | 
|
| 59874 | 469  | 
fun get_path (Naming {path, ...}) = path;
 | 
470  | 
||
| 71257 | 471  | 
fun map_path f =  | 
472  | 
map_naming (fn (scopes, restricted, concealed, group, theory_long_name, path) =>  | 
|
473  | 
(scopes, restricted, concealed, group, theory_long_name, f path));  | 
|
| 
59939
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
474  | 
|
| 
33157
 
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
 
wenzelm 
parents: 
33097 
diff
changeset
 | 
475  | 
fun add_path elems = map_path (fn path => path @ [(elems, false)]);  | 
| 
 
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
 
wenzelm 
parents: 
33097 
diff
changeset
 | 
476  | 
val root_path = map_path (fn _ => []);  | 
| 
 
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
 
wenzelm 
parents: 
33097 
diff
changeset
 | 
477  | 
val parent_path = map_path (perhaps (try (#1 o split_last)));  | 
| 
 
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
 
wenzelm 
parents: 
33097 
diff
changeset
 | 
478  | 
fun mandatory_path elems = map_path (fn path => path @ [(elems, true)]);  | 
| 
 
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
 
wenzelm 
parents: 
33097 
diff
changeset
 | 
479  | 
|
| 
35200
 
aaddb2b526d6
more systematic treatment of qualified names derived from binding;
 
wenzelm 
parents: 
33724 
diff
changeset
 | 
480  | 
fun qualified_path mandatory binding = map_path (fn path =>  | 
| 63003 | 481  | 
path @ Binding.path_of (Binding.qualify_name mandatory binding ""));  | 
| 
35200
 
aaddb2b526d6
more systematic treatment of qualified names derived from binding;
 
wenzelm 
parents: 
33724 
diff
changeset
 | 
482  | 
|
| 
77819
 
d2645d3ad9e9
minor performance tuning: more compact persistent data;
 
wenzelm 
parents: 
77815 
diff
changeset
 | 
483  | 
val global_naming = make_naming ([], NONE, false, 0, "", []);  | 
| 58668 | 484  | 
val local_naming = global_naming |> add_path Long_Name.localN;  | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
485  | 
|
| 28860 | 486  | 
|
| 
59939
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
487  | 
(* transform *)  | 
| 59887 | 488  | 
|
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
489  | 
fun transform_naming (Naming {restricted = restricted', concealed = concealed', ...}) =
 | 
| 
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
490  | 
(case restricted' of  | 
| 
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
491  | 
SOME (strict, scope) => restricted_scope strict scope  | 
| 
59939
 
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
 
wenzelm 
parents: 
59925 
diff
changeset
 | 
492  | 
| NONE => I) #>  | 
| 59887 | 493  | 
concealed' ? concealed;  | 
| 
30233
 
6eb726e43ed1
eliminated internal stamp equality, replaced by bare-metal pointer_eq;
 
wenzelm 
parents: 
30222 
diff
changeset
 | 
494  | 
|
| 
59990
 
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
 
wenzelm 
parents: 
59939 
diff
changeset
 | 
495  | 
fun transform_binding (Naming {restricted, concealed, ...}) =
 | 
| 62241 | 496  | 
Binding.restricted restricted #>  | 
| 59859 | 497  | 
concealed ? Binding.concealed;  | 
| 
33281
 
223ef9bc399a
let naming transform binding beforehand -- covering only the "conceal" flag for now;
 
wenzelm 
parents: 
33164 
diff
changeset
 | 
498  | 
|
| 59887 | 499  | 
|
500  | 
(* full name *)  | 
|
501  | 
||
| 59874 | 502  | 
fun name_spec naming binding =  | 
| 59886 | 503  | 
Binding.name_spec (get_scopes naming) (get_path naming) (transform_binding naming binding);  | 
| 
30412
 
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
 
wenzelm 
parents: 
30359 
diff
changeset
 | 
504  | 
|
| 77841 | 505  | 
val full_name = #full_name oo name_spec;  | 
506  | 
val base_name = Long_Name.base_name o full_name global_naming;  | 
|
| 
47021
 
f35f654f297d
clarified Binding.name_of vs Name_Space.base_name vs Variable.check_name (see also 9bd8d4addd6e, 3305f573294e);
 
wenzelm 
parents: 
47005 
diff
changeset
 | 
507  | 
|
| 
30412
 
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
 
wenzelm 
parents: 
30359 
diff
changeset
 | 
508  | 
|
| 
56168
 
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
 
wenzelm 
parents: 
56164 
diff
changeset
 | 
509  | 
(* hide *)  | 
| 
 
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
 
wenzelm 
parents: 
56164 
diff
changeset
 | 
510  | 
|
| 
 
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
 
wenzelm 
parents: 
56164 
diff
changeset
 | 
511  | 
fun hide fully name space =  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
512  | 
space |> map_name_space (fn (kind, internals, internals_hidden, entries, aliases) =>  | 
| 
56168
 
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
 
wenzelm 
parents: 
56164 
diff
changeset
 | 
513  | 
let  | 
| 59889 | 514  | 
val _ = the_entry space name;  | 
| 
77982
 
21cdcd120a78
hide names more thorougly, in contrast to 1d82061fbb12 and 00e9ca1e7261: e.g. relevant for overlapping accesses seen in 'inductive_set';
 
wenzelm 
parents: 
77979 
diff
changeset
 | 
515  | 
val hide_names = get_aliases space name;  | 
| 77957 | 516  | 
val accesses =  | 
| 77983 | 517  | 
        maps (make_accesses {intern = true} NONE) hide_names
 | 
| 77957 | 518  | 
|> not fully ? inter Long_Name.eq_chunks [Long_Name.base_chunks name];  | 
| 77983 | 519  | 
      val accesses' = maps (make_accesses {intern = false} NONE) hide_names;
 | 
| 
56168
 
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
 
wenzelm 
parents: 
56164 
diff
changeset
 | 
520  | 
val internals' = internals  | 
| 77978 | 521  | 
|> fold (del_internals name) accesses  | 
522  | 
|> fold (del_internals' name) accesses';  | 
|
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
523  | 
val internals_hidden' = internals_hidden  | 
| 77978 | 524  | 
|> add_internals name (Long_Name.make_chunks name);  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
525  | 
in (kind, internals', internals_hidden', entries, aliases) end);  | 
| 
56168
 
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
 
wenzelm 
parents: 
56164 
diff
changeset
 | 
526  | 
|
| 
 
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
 
wenzelm 
parents: 
56164 
diff
changeset
 | 
527  | 
|
| 47003 | 528  | 
(* alias *)  | 
529  | 
||
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
530  | 
fun alias naming binding name space =  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
531  | 
space |> map_name_space (fn (kind, internals, internals_hidden, entries, aliases) =>  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
532  | 
let  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
533  | 
val _ = the_entry space name;  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
534  | 
      val {restriction, suppress, full_name = alias_name, ...} = name_spec naming binding;
 | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
535  | 
val _ = alias_name = "" andalso error (Binding.bad binding);  | 
| 77983 | 536  | 
      val alias_accesses = make_accesses {intern = true} restriction (suppress, alias_name);
 | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
537  | 
val internals' = internals |> fold (add_internals name) alias_accesses;  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
538  | 
val aliases' = aliases |> Symtab.update_list (op =) (name, (suppress, alias_name));  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
539  | 
in (kind, internals', internals_hidden, entries, aliases') end);  | 
| 47003 | 540  | 
|
541  | 
||
542  | 
||
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
543  | 
(** context naming **)  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
544  | 
|
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
545  | 
structure Data_Args =  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
546  | 
struct  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
547  | 
type T = naming;  | 
| 58668 | 548  | 
val empty = global_naming;  | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
549  | 
fun init _ = local_naming;  | 
| 
72053
 
4ed33ea8d957
prefer conservative extend/merge of theory naming;
 
wenzelm 
parents: 
71674 
diff
changeset
 | 
550  | 
val merge = #1;  | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
551  | 
end;  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
552  | 
|
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
553  | 
structure Global_Naming = Theory_Data(Data_Args);  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
554  | 
structure Local_Naming = Proof_Data(Data_Args);  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
555  | 
|
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
556  | 
fun naming_of (Context.Theory thy) = Global_Naming.get thy  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
557  | 
| naming_of (Context.Proof ctxt) = Local_Naming.get ctxt;  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
558  | 
|
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
559  | 
fun map_naming f (Context.Theory thy) = Context.Theory (Global_Naming.map f thy)  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
560  | 
| map_naming f (Context.Proof ctxt) = Context.Proof (Local_Naming.map f ctxt);  | 
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
561  | 
|
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
562  | 
|
| 
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
563  | 
|
| 47003 | 564  | 
(** entry definition **)  | 
565  | 
||
| 
30233
 
6eb726e43ed1
eliminated internal stamp equality, replaced by bare-metal pointer_eq;
 
wenzelm 
parents: 
30222 
diff
changeset
 | 
566  | 
(* declaration *)  | 
| 28860 | 567  | 
|
| 
77954
 
8f3204e28783
minor performance tuning: more compact representation of only sparsely table;
 
wenzelm 
parents: 
77953 
diff
changeset
 | 
568  | 
fun declared (Name_Space {entries, ...}) = Change_Table.defined entries;
 | 
| 68163 | 569  | 
|
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
570  | 
fun declare context strict binding space =  | 
| 
30233
 
6eb726e43ed1
eliminated internal stamp equality, replaced by bare-metal pointer_eq;
 
wenzelm 
parents: 
30222 
diff
changeset
 | 
571  | 
let  | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
572  | 
val naming = naming_of context;  | 
| 71257 | 573  | 
    val Naming {group, theory_long_name, ...} = naming;
 | 
| 
77960
 
1d82061fbb12
more accurate treatment of traditional name space accesses (refining 948f5dc4d694, fcd85e04a948, 238307775d52);
 
wenzelm 
parents: 
77959 
diff
changeset
 | 
574  | 
    val name_spec as {restriction, suppress, full_name = name, ...} = name_spec naming binding;
 | 
| 59874 | 575  | 
val _ = name = "" andalso error (Binding.bad binding);  | 
| 77983 | 576  | 
    val accesses = make_accesses {intern = true} restriction (suppress, name);
 | 
| 
33157
 
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
 
wenzelm 
parents: 
33097 
diff
changeset
 | 
577  | 
|
| 
49528
 
789b73fcca72
report proper binding positions only -- avoid swamping document model with unspecific information;
 
wenzelm 
parents: 
49358 
diff
changeset
 | 
578  | 
val (proper_pos, pos) = Position.default (Binding.pos_of binding);  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
579  | 
val entry: entry =  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
580  | 
     {concealed = #concealed name_spec,
 | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
581  | 
suppress = suppress,  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
582  | 
group = group,  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
583  | 
theory_long_name = theory_long_name,  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
584  | 
pos = pos,  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
585  | 
serial = serial ()};  | 
| 56164 | 586  | 
val space' =  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
587  | 
space |> map_name_space (fn (kind, internals, internals_hidden, entries, aliases) =>  | 
| 56164 | 588  | 
let  | 
| 77978 | 589  | 
val internals' = internals |> fold (add_internals name) accesses;  | 
| 
77970
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
590  | 
val entries' = entries |> update_entry strict kind (name, entry);  | 
| 
77977
 
85811617efcd
clarified data representation: slightly more compact, since internals_hidden is sparesely populated and rarely changes;
 
wenzelm 
parents: 
77972 
diff
changeset
 | 
591  | 
in (kind, internals', internals_hidden, entries', aliases) end);  | 
| 
47005
 
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
 
wenzelm 
parents: 
47003 
diff
changeset
 | 
592  | 
val _ =  | 
| 56160 | 593  | 
if proper_pos andalso Context_Position.is_reported_generic context pos then  | 
| 
77970
 
31ea5c1f874d
more explicit entries for aliases, with proper checks in "strict" mode (e.g. for logical entities);
 
wenzelm 
parents: 
77969 
diff
changeset
 | 
594  | 
        Position.report pos (markup_entry {def = true} (kind_of space) (name, entry))
 | 
| 
49528
 
789b73fcca72
report proper binding positions only -- avoid swamping document model with unspecific information;
 
wenzelm 
parents: 
49358 
diff
changeset
 | 
595  | 
else ();  | 
| 
30233
 
6eb726e43ed1
eliminated internal stamp equality, replaced by bare-metal pointer_eq;
 
wenzelm 
parents: 
30222 
diff
changeset
 | 
596  | 
in (name, space') end;  | 
| 28860 | 597  | 
|
| 16137 | 598  | 
|
| 47003 | 599  | 
(* definition in symbol table *)  | 
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
600  | 
|
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
601  | 
datatype 'a table = Table of T * 'a Change_Table.T;  | 
| 
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
602  | 
|
| 
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
603  | 
fun change_base begin (Table (space, tab)) =  | 
| 
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
604  | 
Table (change_base_space begin space, Change_Table.change_base begin tab);  | 
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
605  | 
|
| 
56139
 
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
 
wenzelm 
parents: 
56056 
diff
changeset
 | 
606  | 
fun change_ignore (Table (space, tab)) =  | 
| 
 
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
 
wenzelm 
parents: 
56056 
diff
changeset
 | 
607  | 
Table (change_ignore_space space, Change_Table.change_ignore tab);  | 
| 
 
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
 
wenzelm 
parents: 
56056 
diff
changeset
 | 
608  | 
|
| 56025 | 609  | 
fun space_of_table (Table (space, _)) = space;  | 
610  | 
||
611  | 
fun check_reports context (Table (space, tab)) (xname, ps) =  | 
|
| 42466 | 612  | 
let val name = intern space xname in  | 
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
613  | 
(case Change_Table.lookup tab name of  | 
| 55696 | 614  | 
SOME x =>  | 
| 
55922
 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 
wenzelm 
parents: 
55845 
diff
changeset
 | 
615  | 
let  | 
| 
 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 
wenzelm 
parents: 
55845 
diff
changeset
 | 
616  | 
val reports =  | 
| 
55956
 
94d384d621b0
reject internal term names outright, and complete consts instead;
 
wenzelm 
parents: 
55923 
diff
changeset
 | 
617  | 
filter (Context_Position.is_reported_generic context) ps  | 
| 
 
94d384d621b0
reject internal term names outright, and complete consts instead;
 
wenzelm 
parents: 
55923 
diff
changeset
 | 
618  | 
|> map (fn pos => (pos, markup space name));  | 
| 
55922
 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 
wenzelm 
parents: 
55845 
diff
changeset
 | 
619  | 
in ((name, reports), x) end  | 
| 
55672
 
5e25cc741ab9
support for completion within the formal context;
 
wenzelm 
parents: 
55669 
diff
changeset
 | 
620  | 
| NONE =>  | 
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
621  | 
error (undefined_entry space name ^ Position.here_list ps ^  | 
| 69289 | 622  | 
Completion.markup_report  | 
623  | 
(map (fn pos => completion context space (K true) (xname, pos)) ps)))  | 
|
| 42466 | 624  | 
end;  | 
625  | 
||
| 
55956
 
94d384d621b0
reject internal term names outright, and complete consts instead;
 
wenzelm 
parents: 
55923 
diff
changeset
 | 
626  | 
fun check context table (xname, pos) =  | 
| 
55922
 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 
wenzelm 
parents: 
55845 
diff
changeset
 | 
627  | 
let  | 
| 
55956
 
94d384d621b0
reject internal term names outright, and complete consts instead;
 
wenzelm 
parents: 
55923 
diff
changeset
 | 
628  | 
val ((name, reports), x) = check_reports context table (xname, [pos]);  | 
| 71674 | 629  | 
val _ = Context_Position.reports_generic context reports;  | 
| 
55922
 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 
wenzelm 
parents: 
55845 
diff
changeset
 | 
630  | 
in (name, x) end;  | 
| 
 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 
wenzelm 
parents: 
55845 
diff
changeset
 | 
631  | 
|
| 59883 | 632  | 
fun defined (Table (_, tab)) name = Change_Table.defined tab name;  | 
| 59884 | 633  | 
fun lookup (Table (_, tab)) name = Change_Table.lookup tab name;  | 
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
634  | 
fun lookup_key (Table (_, tab)) name = Change_Table.lookup_key tab name;  | 
| 56025 | 635  | 
|
636  | 
fun get table name =  | 
|
637  | 
(case lookup_key table name of  | 
|
638  | 
SOME (_, x) => x  | 
|
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
639  | 
| NONE => error (undefined_entry (space_of_table table) name));  | 
| 42466 | 640  | 
|
| 56025 | 641  | 
fun define context strict (binding, x) (Table (space, tab)) =  | 
642  | 
let  | 
|
643  | 
val (name, space') = declare context strict binding space;  | 
|
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
644  | 
val tab' = Change_Table.update (name, x) tab;  | 
| 56025 | 645  | 
in (name, Table (space', tab')) end;  | 
646  | 
||
647  | 
||
648  | 
(* derived table operations *)  | 
|
649  | 
||
| 
77979
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
650  | 
fun alias_table naming binding name (Table (space, tab)) =  | 
| 
 
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
 
wenzelm 
parents: 
77978 
diff
changeset
 | 
651  | 
Table (alias naming binding name space, tab);  | 
| 56025 | 652  | 
|
653  | 
fun hide_table fully name (Table (space, tab)) =  | 
|
654  | 
Table (hide fully name space, tab);  | 
|
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
655  | 
|
| 56025 | 656  | 
fun del_table name (Table (space, tab)) =  | 
657  | 
let  | 
|
658  | 
val space' = hide true name space handle ERROR _ => space;  | 
|
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
659  | 
val tab' = Change_Table.delete_safe name tab;  | 
| 56025 | 660  | 
in Table (space', tab') end;  | 
| 28860 | 661  | 
|
| 56025 | 662  | 
fun map_table_entry name f (Table (space, tab)) =  | 
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
663  | 
Table (space, Change_Table.map_entry name f tab);  | 
| 56025 | 664  | 
|
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
665  | 
fun fold_table f (Table (_, tab)) = Change_Table.fold f tab;  | 
| 68163 | 666  | 
fun dest_table (Table (_, tab)) = Change_Table.dest tab;  | 
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
667  | 
|
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
668  | 
fun empty_table kind = Table (empty kind, Change_Table.empty);  | 
| 56025 | 669  | 
|
670  | 
fun merge_tables (Table (space1, tab1), Table (space2, tab2)) =  | 
|
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
671  | 
Table (merge (space1, space2), Change_Table.merge (K true) (tab1, tab2));  | 
| 28991 | 672  | 
|
| 56025 | 673  | 
fun join_tables f (Table (space1, tab1), Table (space2, tab2)) =  | 
| 
56056
 
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
 
wenzelm 
parents: 
56052 
diff
changeset
 | 
674  | 
Table (merge (space1, space2), Change_Table.join f (tab1, tab2));  | 
| 56025 | 675  | 
|
676  | 
||
677  | 
(* present table content *)  | 
|
678  | 
||
| 
59917
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
679  | 
fun extern_entries verbose ctxt space entries =  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
680  | 
fold (fn (name, x) =>  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
681  | 
(verbose orelse not (is_concealed space name)) ?  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
682  | 
cons ((name, extern ctxt space name), x)) entries []  | 
| 
60924
 
610794dff23c
tuned signature, in accordance to sortBy in Scala;
 
wenzelm 
parents: 
60284 
diff
changeset
 | 
683  | 
|> sort_by (#2 o #1);  | 
| 16848 | 684  | 
|
| 
59917
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
685  | 
fun markup_entries verbose ctxt space entries =  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
686  | 
extern_entries verbose ctxt space entries  | 
| 56025 | 687  | 
|> map (fn ((name, xname), x) => ((markup space name, xname), x));  | 
688  | 
||
| 
59917
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
689  | 
fun extern_table verbose ctxt (Table (space, tab)) =  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
690  | 
extern_entries verbose ctxt space (Change_Table.dest tab);  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
691  | 
|
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
692  | 
fun markup_table verbose ctxt (Table (space, tab)) =  | 
| 
 
9830c944670f
more uniform "verbose" option to print name space;
 
wenzelm 
parents: 
59912 
diff
changeset
 | 
693  | 
markup_entries verbose ctxt space (Change_Table.dest tab);  | 
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
694  | 
|
| 5012 | 695  | 
end;  |