179 const_syntax: string -> Code_Printer.const_syntax option } |
179 const_syntax: string -> Code_Printer.const_syntax option } |
180 -> Code_Symbol.T list |
180 -> Code_Symbol.T list |
181 -> Code_Thingol.program |
181 -> Code_Thingol.program |
182 -> serialization; |
182 -> serialization; |
183 |
183 |
184 datatype description = |
184 type fundamental = { serializer: serializer, literals: literals, |
185 Fundamental of { serializer: serializer, |
185 check: { env_var: string, make_destination: Path.T -> Path.T, make_command: string -> string } }; |
186 literals: literals, |
186 |
187 check: { env_var: string, make_destination: Path.T -> Path.T, |
187 datatype language = Fundamental of fundamental |
188 make_command: string -> string } } |
188 | Extension of string * (Code_Thingol.program -> Code_Thingol.program); |
189 | Extension of string * |
|
190 (Code_Thingol.program -> Code_Thingol.program); |
|
191 |
189 |
192 |
190 |
193 (** theory data **) |
191 (** theory data **) |
194 |
192 |
195 datatype target = Target of { |
193 datatype target = Target of { |
196 serial: serial, |
194 serial: serial, |
197 description: description, |
195 language: language, |
198 reserved: string list, |
196 reserved: string list, |
199 identifiers: identifier_data, |
197 identifiers: identifier_data, |
200 printings: (Code_Printer.const_syntax, Code_Printer.tyco_syntax, string, unit, unit, |
198 printings: (Code_Printer.const_syntax, Code_Printer.tyco_syntax, string, unit, unit, |
201 (Pretty.T * string list)) Code_Symbol.data |
199 (Pretty.T * string list)) Code_Symbol.data |
202 }; |
200 }; |
203 |
201 |
204 fun make_target ((serial, description), (reserved, (identifiers, printings))) = |
202 fun make_target ((serial, language), (reserved, (identifiers, printings))) = |
205 Target { serial = serial, description = description, reserved = reserved, |
203 Target { serial = serial, language = language, reserved = reserved, |
206 identifiers = identifiers, printings = printings }; |
204 identifiers = identifiers, printings = printings }; |
207 fun map_target f (Target { serial, description, reserved, identifiers, printings }) = |
205 fun map_target f (Target { serial, language, reserved, identifiers, printings }) = |
208 make_target (f ((serial, description), (reserved, (identifiers, printings)))); |
206 make_target (f ((serial, language), (reserved, (identifiers, printings)))); |
209 fun merge_target strict target (Target { serial = serial1, description = description, |
207 fun merge_target strict target_name (Target { serial = serial1, language = language, |
210 reserved = reserved1, identifiers = identifiers1, printings = printings1 }, |
208 reserved = reserved1, identifiers = identifiers1, printings = printings1 }, |
211 Target { serial = serial2, description = _, |
209 Target { serial = serial2, language = _, |
212 reserved = reserved2, identifiers = identifiers2, printings = printings2 }) = |
210 reserved = reserved2, identifiers = identifiers2, printings = printings2 }) = |
213 if serial1 = serial2 orelse not strict then |
211 if serial1 = serial2 orelse not strict then |
214 make_target ((serial1, description), (merge (op =) (reserved1, reserved2), |
212 make_target ((serial1, language), (merge (op =) (reserved1, reserved2), |
215 (Code_Symbol.merge_data (identifiers1, identifiers2), |
213 (Code_Symbol.merge_data (identifiers1, identifiers2), |
216 Code_Symbol.merge_data (printings1, printings2)))) |
214 Code_Symbol.merge_data (printings1, printings2)))) |
217 else |
215 else |
218 error ("Incompatible targets: " ^ quote target); |
216 error ("Incompatible targets: " ^ quote target_name); |
219 |
217 |
220 fun the_description (Target { description, ... }) = description; |
218 fun the_language (Target { language, ... }) = language; |
221 fun the_reserved (Target { reserved, ... }) = reserved; |
219 fun the_reserved (Target { reserved, ... }) = reserved; |
222 fun the_identifiers (Target { identifiers , ... }) = identifiers; |
220 fun the_identifiers (Target { identifiers , ... }) = identifiers; |
223 fun the_printings (Target { printings, ... }) = printings; |
221 fun the_printings (Target { printings, ... }) = printings; |
224 |
222 |
225 structure Targets = Theory_Data |
223 structure Targets = Theory_Data |
229 val extend = I; |
227 val extend = I; |
230 fun merge ((target1, width1), (target2, width2)) : T = |
228 fun merge ((target1, width1), (target2, width2)) : T = |
231 (Symtab.join (merge_target true) (target1, target2), Int.max (width1, width2)); |
229 (Symtab.join (merge_target true) (target1, target2), Int.max (width1, width2)); |
232 ); |
230 ); |
233 |
231 |
234 fun assert_target ctxt target = |
232 fun assert_target ctxt target_name = |
235 if Symtab.defined (fst (Targets.get (Proof_Context.theory_of ctxt))) target |
233 if Symtab.defined (fst (Targets.get (Proof_Context.theory_of ctxt))) target_name |
236 then target |
234 then target_name |
237 else error ("Unknown code target language: " ^ quote target); |
235 else error ("Unknown code target language: " ^ quote target_name); |
238 |
236 |
239 fun put_target (target, seri) thy = |
237 fun put_target (target_name, target_language) thy = |
240 let |
238 let |
241 val lookup_target = Symtab.lookup (fst (Targets.get thy)); |
239 val lookup_target = Symtab.lookup (fst (Targets.get thy)); |
242 val _ = case seri |
240 val _ = case target_language |
243 of Extension (super, _) => if is_some (lookup_target super) then () |
241 of Extension (super, _) => if is_some (lookup_target super) then () |
244 else error ("Unknown code target language: " ^ quote super) |
242 else error ("Unknown code target language: " ^ quote super) |
245 | _ => (); |
243 | _ => (); |
246 val overwriting = case (Option.map the_description o lookup_target) target |
244 val overwriting = case (Option.map the_language o lookup_target) target_name |
247 of NONE => false |
245 of NONE => false |
248 | SOME (Extension _) => true |
246 | SOME (Extension _) => true |
249 | SOME (Fundamental _) => (case seri |
247 | SOME (Fundamental _) => (case target_language |
250 of Extension _ => error ("Will not overwrite existing target " ^ quote target) |
248 of Extension _ => error ("Illegal attempt to overwrite existing target " ^ quote target_name) |
251 | _ => true); |
249 | _ => true); |
252 val _ = if overwriting |
250 val _ = if overwriting |
253 then warning ("Overwriting existing target " ^ quote target) |
251 then warning ("Overwriting existing target " ^ quote target_name) |
254 else (); |
252 else (); |
255 in |
253 in |
256 thy |
254 thy |
257 |> (Targets.map o apfst o Symtab.update) |
255 |> (Targets.map o apfst o Symtab.update) |
258 (target, make_target ((serial (), seri), |
256 (target_name, make_target ((serial (), target_language), |
259 ([], (Code_Symbol.empty_data, Code_Symbol.empty_data)))) |
257 ([], (Code_Symbol.empty_data, Code_Symbol.empty_data)))) |
260 end; |
258 end; |
261 |
259 |
262 fun add_target (target, seri) = put_target (target, Fundamental seri); |
260 fun add_target (target_name, fundamental) = put_target (target_name, Fundamental fundamental); |
263 fun extend_target (target, (super, modify)) = |
261 fun extend_target (target_name, (super, modify)) = |
264 put_target (target, Extension (super, modify)); |
262 put_target (target_name, Extension (super, modify)); |
265 |
263 |
266 fun map_target_data target f thy = |
264 fun map_target_data target_name f thy = |
267 let |
265 let |
268 val _ = assert_target (Proof_Context.init_global thy) target; |
266 val _ = assert_target (Proof_Context.init_global thy) target_name; |
269 in |
267 in |
270 thy |
268 thy |
271 |> (Targets.map o apfst o Symtab.map_entry target o map_target o apsnd) f |
269 |> (Targets.map o apfst o Symtab.map_entry target_name o map_target o apsnd) f |
272 end; |
270 end; |
273 |
271 |
274 fun map_reserved target = |
272 fun map_reserved target_name = |
275 map_target_data target o apfst; |
273 map_target_data target_name o apfst; |
276 fun map_identifiers target = |
274 fun map_identifiers target_name = |
277 map_target_data target o apsnd o apfst; |
275 map_target_data target_name o apsnd o apfst; |
278 fun map_printings target = |
276 fun map_printings target_name = |
279 map_target_data target o apsnd o apsnd; |
277 map_target_data target_name o apsnd o apsnd; |
280 |
278 |
281 fun set_default_code_width k = (Targets.map o apsnd) (K k); |
279 fun set_default_code_width k = (Targets.map o apsnd) (K k); |
282 |
280 |
283 |
281 |
284 (** serializer usage **) |
282 (** serializer usage **) |
286 (* montage *) |
284 (* montage *) |
287 |
285 |
288 fun the_fundamental ctxt = |
286 fun the_fundamental ctxt = |
289 let |
287 let |
290 val (targets, _) = Targets.get (Proof_Context.theory_of ctxt); |
288 val (targets, _) = Targets.get (Proof_Context.theory_of ctxt); |
291 fun fundamental target = case Symtab.lookup targets target |
289 fun fundamental target_name = case Symtab.lookup targets target_name |
292 of SOME data => (case the_description data |
290 of SOME target => (case the_language target |
293 of Fundamental data => data |
291 of Fundamental fundamental => fundamental |
294 | Extension (super, _) => fundamental super) |
292 | Extension (super, _) => fundamental super) |
295 | NONE => error ("Unknown code target language: " ^ quote target); |
293 | NONE => error ("Unknown code target language: " ^ quote target_name); |
296 in fundamental end; |
294 in fundamental end; |
297 |
295 |
298 fun the_literals ctxt = #literals o the_fundamental ctxt; |
296 fun the_literals ctxt = #literals o the_fundamental ctxt; |
299 |
297 |
300 fun collapse_hierarchy ctxt = |
298 fun collapse_hierarchy ctxt = |
301 let |
299 let |
302 val (targets, _) = Targets.get (Proof_Context.theory_of ctxt); |
300 val (targets, _) = Targets.get (Proof_Context.theory_of ctxt); |
303 fun collapse target = |
301 fun collapse target_name = |
304 let |
302 let |
305 val data = case Symtab.lookup targets target |
303 val target = case Symtab.lookup targets target_name |
306 of SOME data => data |
304 of SOME target => target |
307 | NONE => error ("Unknown code target language: " ^ quote target); |
305 | NONE => error ("Unknown code target language: " ^ quote target_name); |
308 in case the_description data |
306 in case the_language target |
309 of Fundamental _ => (I, data) |
307 of Fundamental _ => (I, target) |
310 | Extension (super, modify) => let |
308 | Extension (super, modify) => let |
311 val (modify', data') = collapse super |
309 val (modify', target') = collapse super |
312 in (modify' #> modify, merge_target false target (data', data)) end |
310 in (modify' #> modify, merge_target false target_name (target', target)) end |
313 end; |
311 end; |
314 in collapse end; |
312 in collapse end; |
315 |
313 |
316 local |
314 local |
317 |
315 |
318 fun activate_target ctxt target = |
316 fun activate_target ctxt target_name = |
319 let |
317 let |
320 val thy = Proof_Context.theory_of ctxt; |
318 val thy = Proof_Context.theory_of ctxt; |
321 val (_, default_width) = Targets.get thy; |
319 val (_, default_width) = Targets.get thy; |
322 val (modify, data) = collapse_hierarchy ctxt target; |
320 val (modify, target) = collapse_hierarchy ctxt target_name; |
323 in (default_width, data, modify) end; |
321 in (default_width, target, modify) end; |
324 |
322 |
325 fun project_program ctxt syms_hidden syms1 program2 = |
323 fun project_program ctxt syms_hidden syms1 program2 = |
326 let |
324 let |
327 val syms2 = subtract (op =) syms_hidden syms1; |
325 val syms2 = subtract (op =) syms_hidden syms1; |
328 val program3 = Code_Symbol.Graph.restrict (not o member (op =) syms_hidden) program2; |
326 val program3 = Code_Symbol.Graph.restrict (not o member (op =) syms_hidden) program2; |
354 tyco_syntax = Code_Symbol.lookup_type_constructor_data printings, |
352 tyco_syntax = Code_Symbol.lookup_type_constructor_data printings, |
355 class_syntax = Code_Symbol.lookup_type_class_data printings }, |
353 class_syntax = Code_Symbol.lookup_type_class_data printings }, |
356 (subtract (op =) syms_hidden syms, program)) |
354 (subtract (op =) syms_hidden syms, program)) |
357 end; |
355 end; |
358 |
356 |
359 fun mount_serializer ctxt target some_width module_name args program syms = |
357 fun mount_serializer ctxt target_name some_width module_name args program syms = |
360 let |
358 let |
361 val (default_width, data, modify) = activate_target ctxt target; |
359 val (default_width, target, modify) = activate_target ctxt target_name; |
362 val serializer = case the_description data |
360 val serializer = case the_language target |
363 of Fundamental seri => #serializer seri; |
361 of Fundamental seri => #serializer seri; |
364 val (prepared_serializer, (prepared_syms, prepared_program)) = |
362 val (prepared_serializer, (prepared_syms, prepared_program)) = |
365 prepare_serializer ctxt serializer |
363 prepare_serializer ctxt serializer |
366 (the_reserved data) (the_identifiers data) (the_printings data) |
364 (the_reserved target) (the_identifiers target) (the_printings target) |
367 module_name args (modify program) syms |
365 module_name args (modify program) syms |
368 val width = the_default default_width some_width; |
366 val width = the_default default_width some_width; |
369 in (fn program => fn syms => prepared_serializer syms program width, (prepared_syms, prepared_program)) end; |
367 in (fn program => fn syms => prepared_serializer syms program width, (prepared_syms, prepared_program)) end; |
370 |
368 |
371 fun invoke_serializer ctxt target some_width raw_module_name args program all_public syms = |
369 fun invoke_serializer ctxt target_name some_width raw_module_name args program all_public syms = |
372 let |
370 let |
373 val module_name = if raw_module_name = "" then "" |
371 val module_name = if raw_module_name = "" then "" |
374 else (check_name true raw_module_name; raw_module_name) |
372 else (check_name true raw_module_name; raw_module_name) |
375 val (mounted_serializer, (prepared_syms, prepared_program)) = |
373 val (mounted_serializer, (prepared_syms, prepared_program)) = |
376 mount_serializer ctxt target some_width module_name args program syms; |
374 mount_serializer ctxt target_name some_width module_name args program syms; |
377 in mounted_serializer prepared_program (if all_public then [] else prepared_syms) end; |
375 in mounted_serializer prepared_program (if all_public then [] else prepared_syms) end; |
378 |
376 |
379 fun assert_module_name "" = error "Empty module name not allowed here" |
377 fun assert_module_name "" = error "Empty module name not allowed here" |
380 | assert_module_name module_name = module_name; |
378 | assert_module_name module_name = module_name; |
381 |
379 |
385 |
383 |
386 in |
384 in |
387 |
385 |
388 val generatedN = "Generated_Code"; |
386 val generatedN = "Generated_Code"; |
389 |
387 |
390 fun export_code_for ctxt some_path target some_width module_name args = |
388 fun export_code_for ctxt some_path target_name some_width module_name args = |
391 export (using_master_directory ctxt some_path) |
389 export (using_master_directory ctxt some_path) |
392 ooo invoke_serializer ctxt target some_width module_name args; |
390 ooo invoke_serializer ctxt target_name some_width module_name args; |
393 |
391 |
394 fun produce_code_for ctxt target some_width module_name args = |
392 fun produce_code_for ctxt target_name some_width module_name args = |
395 let |
393 let |
396 val serializer = invoke_serializer ctxt target some_width (assert_module_name module_name) args; |
394 val serializer = invoke_serializer ctxt target_name some_width (assert_module_name module_name) args; |
397 in fn program => fn all_public => fn syms => |
395 in fn program => fn all_public => fn syms => |
398 produce (serializer program all_public syms) |> apsnd (fn deresolve => map deresolve syms) |
396 produce (serializer program all_public syms) |> apsnd (fn deresolve => map deresolve syms) |
399 end; |
397 end; |
400 |
398 |
401 fun present_code_for ctxt target some_width module_name args = |
399 fun present_code_for ctxt target_name some_width module_name args = |
402 let |
400 let |
403 val serializer = invoke_serializer ctxt target some_width (assert_module_name module_name) args; |
401 val serializer = invoke_serializer ctxt target_name some_width (assert_module_name module_name) args; |
404 in fn program => fn (syms, selects) => |
402 in fn program => fn (syms, selects) => |
405 present selects (serializer program false syms) |
403 present selects (serializer program false syms) |
406 end; |
404 end; |
407 |
405 |
408 fun check_code_for ctxt target strict args program all_public syms = |
406 fun check_code_for ctxt target_name strict args program all_public syms = |
409 let |
407 let |
410 val { env_var, make_destination, make_command } = |
408 val { env_var, make_destination, make_command } = |
411 (#check o the_fundamental ctxt) target; |
409 (#check o the_fundamental ctxt) target_name; |
412 fun ext_check p = |
410 fun ext_check p = |
413 let |
411 let |
414 val destination = make_destination p; |
412 val destination = make_destination p; |
415 val _ = export (SOME destination) (invoke_serializer ctxt target (SOME 80) |
413 val _ = export (SOME destination) (invoke_serializer ctxt target_name (SOME 80) |
416 generatedN args program all_public syms); |
414 generatedN args program all_public syms); |
417 val cmd = make_command generatedN; |
415 val cmd = make_command generatedN; |
418 in |
416 in |
419 if Isabelle_System.bash ("cd " ^ File.shell_path p ^ " && " ^ cmd ^ " 2>&1") <> 0 |
417 if Isabelle_System.bash ("cd " ^ File.shell_path p ^ " && " ^ cmd ^ " 2>&1") <> 0 |
420 then error ("Code check failed for " ^ target ^ ": " ^ cmd) |
418 then error ("Code check failed for " ^ target_name ^ ": " ^ cmd) |
421 else () |
419 else () |
422 end; |
420 end; |
423 in |
421 in |
424 if getenv env_var = "" |
422 if getenv env_var = "" |
425 then if strict |
423 then if strict |
426 then error (env_var ^ " not set; cannot check code for " ^ target) |
424 then error (env_var ^ " not set; cannot check code for " ^ target_name) |
427 else warning (env_var ^ " not set; skipped checking code for " ^ target) |
425 else warning (env_var ^ " not set; skipped checking code for " ^ target_name) |
428 else Isabelle_System.with_tmp_dir "Code_Test" ext_check |
426 else Isabelle_System.with_tmp_dir "Code_Test" ext_check |
429 end; |
427 end; |
430 |
428 |
431 fun subevaluator mounted_serializer prepared_program syms all_public ((vs, ty), t) = |
429 fun subevaluator mounted_serializer prepared_program syms all_public ((vs, ty), t) = |
432 let |
430 let |
461 |
459 |
462 fun export_code ctxt all_public cs seris = |
460 fun export_code ctxt all_public cs seris = |
463 let |
461 let |
464 val thy = Proof_Context.theory_of ctxt; |
462 val thy = Proof_Context.theory_of ctxt; |
465 val program = Code_Thingol.consts_program thy cs; |
463 val program = Code_Thingol.consts_program thy cs; |
466 val _ = map (fn (((target, module_name), some_path), args) => |
464 val _ = map (fn (((target_name, module_name), some_path), args) => |
467 export_code_for ctxt some_path target NONE module_name args program all_public (map Constant cs)) seris; |
465 export_code_for ctxt some_path target_name NONE module_name args program all_public (map Constant cs)) seris; |
468 in () end; |
466 in () end; |
469 |
467 |
470 fun export_code_cmd all_public raw_cs seris ctxt = |
468 fun export_code_cmd all_public raw_cs seris ctxt = |
471 export_code ctxt all_public |
469 export_code ctxt all_public |
472 (Code_Thingol.read_const_exprs ctxt raw_cs) |
470 (Code_Thingol.read_const_exprs ctxt raw_cs) |
473 ((map o apfst o apsnd) prep_destination seris); |
471 ((map o apfst o apsnd) prep_destination seris); |
474 |
472 |
475 fun produce_code ctxt all_public cs target some_width some_module_name args = |
473 fun produce_code ctxt all_public cs target_name some_width some_module_name args = |
476 let |
474 let |
477 val thy = Proof_Context.theory_of ctxt; |
475 val thy = Proof_Context.theory_of ctxt; |
478 val program = Code_Thingol.consts_program thy cs; |
476 val program = Code_Thingol.consts_program thy cs; |
479 in produce_code_for ctxt target some_width some_module_name args program all_public (map Constant cs) end; |
477 in produce_code_for ctxt target_name some_width some_module_name args program all_public (map Constant cs) end; |
480 |
478 |
481 fun present_code ctxt cs syms target some_width some_module_name args = |
479 fun present_code ctxt cs syms target_name some_width some_module_name args = |
482 let |
480 let |
483 val thy = Proof_Context.theory_of ctxt; |
481 val thy = Proof_Context.theory_of ctxt; |
484 val program = Code_Thingol.consts_program thy cs; |
482 val program = Code_Thingol.consts_program thy cs; |
485 in present_code_for ctxt target some_width some_module_name args program (map Constant cs, syms) end; |
483 in present_code_for ctxt target_name some_width some_module_name args program (map Constant cs, syms) end; |
486 |
484 |
487 fun check_code ctxt all_public cs seris = |
485 fun check_code ctxt all_public cs seris = |
488 let |
486 let |
489 val thy = Proof_Context.theory_of ctxt; |
487 val thy = Proof_Context.theory_of ctxt; |
490 val program = Code_Thingol.consts_program thy cs; |
488 val program = Code_Thingol.consts_program thy cs; |
491 val _ = map (fn ((target, strict), args) => |
489 val _ = map (fn ((target_name, strict), args) => |
492 check_code_for ctxt target strict args program all_public (map Constant cs)) seris; |
490 check_code_for ctxt target_name strict args program all_public (map Constant cs)) seris; |
493 in () end; |
491 in () end; |
494 |
492 |
495 fun check_code_cmd all_public raw_cs seris ctxt = |
493 fun check_code_cmd all_public raw_cs seris ctxt = |
496 check_code ctxt all_public |
494 check_code ctxt all_public |
497 (Code_Thingol.read_const_exprs ctxt raw_cs) seris; |
495 (Code_Thingol.read_const_exprs ctxt raw_cs) seris; |
525 val antiq_setup = |
523 val antiq_setup = |
526 Thy_Output.antiquotation @{binding code_stmts} |
524 Thy_Output.antiquotation @{binding code_stmts} |
527 (parse_const_terms -- |
525 (parse_const_terms -- |
528 Scan.repeat (parse_consts || parse_types || parse_classes || parse_instances) |
526 Scan.repeat (parse_consts || parse_types || parse_classes || parse_instances) |
529 -- Scan.lift (Args.parens (Args.name -- Scan.option Parse.int))) |
527 -- Scan.lift (Args.parens (Args.name -- Scan.option Parse.int))) |
530 (fn {context = ctxt, ...} => fn ((mk_cs, mk_stmtss), (target, some_width)) => |
528 (fn {context = ctxt, ...} => fn ((mk_cs, mk_stmtss), (target_name, some_width)) => |
531 present_code ctxt (mk_cs ctxt) |
529 present_code ctxt (mk_cs ctxt) |
532 (maps (fn f => f ctxt) mk_stmtss) |
530 (maps (fn f => f ctxt) mk_stmtss) |
533 target some_width "Example" []); |
531 target_name some_width "Example" []); |
534 |
532 |
535 end; |
533 end; |
536 |
534 |
537 |
535 |
538 (** serializer configuration **) |
536 (** serializer configuration **) |
539 |
537 |
540 (* reserved symbol names *) |
538 (* reserved symbol names *) |
541 |
539 |
542 fun add_reserved target sym thy = |
540 fun add_reserved target_name sym thy = |
543 let |
541 let |
544 val (_, data) = collapse_hierarchy (Proof_Context.init_global thy) target; |
542 val (_, target) = collapse_hierarchy (Proof_Context.init_global thy) target_name; |
545 val _ = if member (op =) (the_reserved data) sym |
543 val _ = if member (op =) (the_reserved target) sym |
546 then error ("Reserved symbol " ^ quote sym ^ " already declared") |
544 then error ("Reserved symbol " ^ quote sym ^ " already declared") |
547 else (); |
545 else (); |
548 in |
546 in |
549 thy |
547 thy |
550 |> map_reserved target (insert (op =) sym) |
548 |> map_reserved target_name (insert (op =) sym) |
551 end; |
549 end; |
552 |
550 |
553 |
551 |
554 (* checking of syntax *) |
552 (* checking of syntax *) |
555 |
553 |
556 fun check_const_syntax ctxt target c syn = |
554 fun check_const_syntax ctxt target_name c syn = |
557 if Code_Printer.requires_args syn > Code.args_number (Proof_Context.theory_of ctxt) c |
555 if Code_Printer.requires_args syn > Code.args_number (Proof_Context.theory_of ctxt) c |
558 then error ("Too many arguments in syntax for constant " ^ quote c) |
556 then error ("Too many arguments in syntax for constant " ^ quote c) |
559 else Code_Printer.prep_const_syntax (Proof_Context.theory_of ctxt) (the_literals ctxt target) c syn; |
557 else Code_Printer.prep_const_syntax (Proof_Context.theory_of ctxt) (the_literals ctxt target_name) c syn; |
560 |
558 |
561 fun check_tyco_syntax ctxt target tyco syn = |
559 fun check_tyco_syntax ctxt target_name tyco syn = |
562 if fst syn <> Sign.arity_number (Proof_Context.theory_of ctxt) tyco |
560 if fst syn <> Sign.arity_number (Proof_Context.theory_of ctxt) tyco |
563 then error ("Number of arguments mismatch in syntax for type constructor " ^ quote tyco) |
561 then error ("Number of arguments mismatch in syntax for type constructor " ^ quote tyco) |
564 else syn; |
562 else syn; |
565 |
563 |
566 |
564 |
591 (* custom printings *) |
589 (* custom printings *) |
592 |
590 |
593 fun arrange_printings prep_const ctxt = |
591 fun arrange_printings prep_const ctxt = |
594 let |
592 let |
595 fun arrange check (sym, target_syns) = |
593 fun arrange check (sym, target_syns) = |
596 map (fn (target, some_syn) => (target, (sym, Option.map (check ctxt target sym) some_syn))) target_syns; |
594 map (fn (target_name, some_syn) => |
|
595 (target_name, (sym, Option.map (check ctxt target_name sym) some_syn))) target_syns; |
597 in |
596 in |
598 Code_Symbol.maps_attr' |
597 Code_Symbol.maps_attr' |
599 (arrange check_const_syntax) (arrange check_tyco_syntax) |
598 (arrange check_const_syntax) (arrange check_tyco_syntax) |
600 (arrange ((K o K o K) I)) (arrange ((K o K o K) I)) (arrange ((K o K o K) I)) |
599 (arrange ((K o K o K) I)) (arrange ((K o K o K) I)) (arrange ((K o K o K) I)) |
601 (arrange (fn ctxt => fn _ => fn _ => fn (raw_content, raw_cs) => |
600 (arrange (fn ctxt => fn _ => fn _ => fn (raw_content, raw_cs) => |