9 sig |
9 sig |
10 val pretty_const: Proof.context -> string * typ list -> Pretty.T |
10 val pretty_const: Proof.context -> string * typ list -> Pretty.T |
11 val plain_args: typ list -> bool |
11 val plain_args: typ list -> bool |
12 type T |
12 type T |
13 type spec = |
13 type spec = |
14 {def: string option, description: string, lhs: typ list, rhs: (string * typ list) list} |
14 {def: string option, |
|
15 description: string, |
|
16 pos: Position.T, |
|
17 lhs: typ list, |
|
18 rhs: (string * typ list) list} |
15 val all_specifications_of: T -> (string * spec list) list |
19 val all_specifications_of: T -> (string * spec list) list |
16 val specifications_of: T -> string -> spec list |
20 val specifications_of: T -> string -> spec list |
17 val dest: T -> |
21 val dest: T -> |
18 {restricts: ((string * typ list) * string) list, |
22 {restricts: ((string * typ list) * string) list, |
19 reducts: ((string * typ list) * (string * typ list) list) list} |
23 reducts: ((string * typ list) * (string * typ list) list) list} |
51 |
55 |
52 |
56 |
53 (* datatype defs *) |
57 (* datatype defs *) |
54 |
58 |
55 type spec = |
59 type spec = |
56 {def: string option, description: string, lhs: args, rhs: (string * args) list}; |
60 {def: string option, |
|
61 description: string, |
|
62 pos: Position.T, |
|
63 lhs: args, |
|
64 rhs: (string * args) list}; |
57 |
65 |
58 type def = |
66 type def = |
59 {specs: spec Inttab.table, (*source specifications*) |
67 {specs: spec Inttab.table, (*source specifications*) |
60 restricts: (args * string) list, (*global restrictions imposed by incomplete patterns*) |
68 restricts: (args * string) list, (*global restrictions imposed by incomplete patterns*) |
61 reducts: (args * (string * args) list) list}; (*specifications as reduction system*) |
69 reducts: (args * (string * args) list) list}; (*specifications as reduction system*) |
62 |
70 |
63 fun make_def (specs, restricts, reducts) = |
71 fun make_def (specs, restricts, reducts) = |
64 {specs = specs, restricts = restricts, reducts = reducts}: def; |
72 {specs = specs, restricts = restricts, reducts = reducts}: def; |
65 |
73 |
95 val empty = Defs Symtab.empty; |
103 val empty = Defs Symtab.empty; |
96 |
104 |
97 |
105 |
98 (* specifications *) |
106 (* specifications *) |
99 |
107 |
100 fun disjoint_specs c (i, {lhs = Ts, description = a, ...}: spec) = |
108 fun disjoint_specs c (i, {description = a, pos = pos_a, lhs = Ts, ...}: spec) = |
101 Inttab.forall (fn (j, {lhs = Us, description = b, ...}: spec) => |
109 Inttab.forall (fn (j, {description = b, pos = pos_b, lhs = Us, ...}: spec) => |
102 i = j orelse disjoint_args (Ts, Us) orelse |
110 i = j orelse disjoint_args (Ts, Us) orelse |
103 error ("Clash of specifications " ^ quote a ^ " and " ^ quote b ^ |
111 error ("Clash of specifications for constant " ^ quote c ^ ":\n" ^ |
104 " for constant " ^ quote c)); |
112 " " ^ quote a ^ Position.here pos_a ^ "\n" ^ |
|
113 " " ^ quote b ^ Position.here pos_b)); |
105 |
114 |
106 fun join_specs c ({specs = specs1, restricts, reducts}, {specs = specs2, ...}: def) = |
115 fun join_specs c ({specs = specs1, restricts, reducts}, {specs = specs2, ...}: def) = |
107 let |
116 let |
108 val specs' = |
117 val specs' = |
109 Inttab.fold (fn spec2 => (disjoint_specs c spec2 specs1; Inttab.update spec2)) specs2 specs1; |
118 Inttab.fold (fn spec2 => (disjoint_specs c spec2 specs1; Inttab.update spec2)) specs2 specs1; |
202 |
211 |
203 (* define *) |
212 (* define *) |
204 |
213 |
205 fun define ctxt unchecked def description (c, args) deps (Defs defs) = |
214 fun define ctxt unchecked def description (c, args) deps (Defs defs) = |
206 let |
215 let |
|
216 val pos = Position.thread_data (); |
207 val restr = |
217 val restr = |
208 if plain_args args orelse |
218 if plain_args args orelse |
209 (case args of [Type (_, rec_args)] => plain_args rec_args | _ => false) |
219 (case args of [Type (_, rec_args)] => plain_args rec_args | _ => false) |
210 then [] else [(args, description)]; |
220 then [] else [(args, description)]; |
211 val spec = |
221 val spec = |
212 (serial (), {def = def, description = description, lhs = args, rhs = deps}); |
222 (serial (), {def = def, description = description, pos = pos, lhs = args, rhs = deps}); |
213 val defs' = defs |> update_specs c spec; |
223 val defs' = defs |> update_specs c spec; |
214 in Defs (defs' |> (if unchecked then I else dependencies ctxt (c, args) restr deps)) end; |
224 in Defs (defs' |> (if unchecked then I else dependencies ctxt (c, args) restr deps)) end; |
215 |
225 |
216 end; |
226 end; |