162 |
162 |
163 |
163 |
164 (* extend logical part of a theory *) |
164 (* extend logical part of a theory *) |
165 |
165 |
166 fun err_dup_axms names = |
166 fun err_dup_axms names = |
167 error ("Duplicate axiom name(s) " ^ commas_quote names); |
167 error ("Duplicate axiom name(s): " ^ commas_quote names); |
168 |
168 |
169 fun err_dup_oras names = |
169 fun err_dup_oras names = |
170 error ("Duplicate oracles " ^ commas_quote names); |
170 error ("Duplicate oracles: " ^ commas_quote names); |
171 |
171 |
172 fun ext_theory thy ext_sg ext_deps new_axms new_oras = |
172 fun ext_theory thy ext_sg ext_deps new_axms new_oras = |
173 let |
173 let |
174 val Theory {sign, const_deps, axioms, oracles, parents, ancestors} = thy; |
174 val Theory {sign, const_deps, axioms, oracles, parents, ancestors} = thy; |
175 val draft = Sign.is_draft sign; |
175 val draft = Sign.is_draft sign; |
382 in foldl declare (deps, c :: cs) |> Graph.add_deps_acyclic (c, cs) end; |
382 in foldl declare (deps, c :: cs) |> Graph.add_deps_acyclic (c, cs) end; |
383 |
383 |
384 |
384 |
385 fun check_defn sg overloaded ((deps, axms), def as (name, tm)) = |
385 fun check_defn sg overloaded ((deps, axms), def as (name, tm)) = |
386 let |
386 let |
387 fun show_const (c, ty) = quote (Pretty.string_of (Pretty.block |
387 fun pretty_const (c, ty) = [Pretty.str c, Pretty.str " ::", Pretty.brk 1, |
388 [Pretty.str (c ^ " ::"), Pretty.brk 1, Sign.pretty_typ sg ty])); |
388 Pretty.quote (Sign.pretty_typ sg (#1 (Type.freeze_thaw_type ty)))]; |
389 |
389 |
390 fun def_txt c_ty = "Definition of " ^ show_const c_ty; |
390 fun def_txt (c_ty, txt) = Pretty.block |
391 fun show_defn c (dfn, ty') = show_const (c, ty') ^ " in " ^ dfn; |
391 (Pretty.str "Definition of " :: pretty_const c_ty @ |
392 fun show_defns c = cat_lines o map (show_defn c); |
392 (if txt = "" then [] else [Pretty.str txt])); |
|
393 |
|
394 fun show_defn c (dfn, ty') = Pretty.block |
|
395 (Pretty.str " " :: pretty_const (c, ty') @ [Pretty.str " in ", Pretty.str dfn]); |
393 |
396 |
394 val (c_ty as (c, ty), rhs) = dest_defn tm |
397 val (c_ty as (c, ty), rhs) = dest_defn tm |
395 handle TERM (msg, _) => err_in_defn sg name msg; |
398 handle TERM (msg, _) => err_in_defn sg name msg; |
396 val c_decl = |
399 val c_decl = |
397 (case Sign.const_type sg c of Some T => T |
400 (case Sign.const_type sg c of Some T => T |
398 | None => err_in_defn sg name ("Undeclared constant " ^ quote c)); |
401 | None => err_in_defn sg name ("Undeclared constant " ^ quote c)); |
399 |
402 |
400 val clashed = clash_defns c_ty axms; |
403 val clashed = clash_defns c_ty axms; |
401 in |
404 in |
402 if not (null clashed) then |
405 if not (null clashed) then |
403 err_in_defn sg name (def_txt c_ty ^"\nclashes with "^ show_defns c clashed) |
406 err_in_defn sg name (Pretty.string_of (Pretty.chunks |
|
407 (def_txt (c_ty, " clashes with") :: map (show_defn c) clashed))) |
404 else |
408 else |
405 (case overloading sg c_decl ty of |
409 (case overloading sg c_decl ty of |
406 NoOverloading => |
410 NoOverloading => |
407 (add_deps (c, Term.add_term_consts (rhs, [])) deps |
411 (add_deps (c, Term.add_term_consts (rhs, [])) deps |
408 handle Graph.CYCLES namess => err_in_defn sg name (cycle_msg namess), |
412 handle Graph.CYCLES namess => err_in_defn sg name (cycle_msg namess), |
409 def :: axms) |
413 def :: axms) |
410 | Useless => |
414 | Useless => |
411 err_in_defn sg name (Library.setmp show_sorts true def_txt c_ty ^ |
415 err_in_defn sg name (Pretty.string_of (Pretty.chunks |
412 "\nimposes additional sort constraints on the declared type of the constant.") |
416 [Library.setmp show_sorts true def_txt (c_ty, ""), Pretty.str |
|
417 "imposes additional sort constraints on the declared type of the constant"])) |
413 | Plain => |
418 | Plain => |
414 (if not overloaded then |
419 (if not overloaded then warning (Pretty.string_of (Pretty.chunks |
415 warning (def_txt c_ty ^ "\nis strictly less general than the declared type (see " |
420 [def_txt (c_ty, ""), Pretty.str ("is strictly less general than the declared type (see " |
416 ^ quote (Sign.full_name sg name) ^ ")") |
421 ^ quote (Sign.full_name sg name) ^ ")")])) |
417 else (); (deps, def :: axms))) |
422 else (); (deps, def :: axms))) |
418 end; |
423 end; |
419 |
424 |
420 |
425 |
421 (* add_defs *) |
426 (* add_defs *) |