| author | haftmann |
| Mon, 16 Nov 2009 10:16:40 +0100 | |
| changeset 33708 | b45d3b8cc74e |
| parent 33671 | 4b0f2599ed48 |
| child 34068 | a78307d72e58 |
| permissions | -rw-r--r-- |
| 33419 | 1 |
(* Title: HOL/Boogie/Tools/boogie_commands.ML |
2 |
Author: Sascha Boehme, TU Muenchen |
|
3 |
||
4 |
Isar commands to create a Boogie environment simulation. |
|
5 |
*) |
|
6 |
||
7 |
signature BOOGIE_COMMANDS = |
|
8 |
sig |
|
9 |
val setup: theory -> theory |
|
10 |
end |
|
11 |
||
12 |
structure Boogie_Commands: BOOGIE_COMMANDS = |
|
13 |
struct |
|
14 |
||
15 |
fun boogie_load (verbose, base_name) thy = |
|
16 |
let |
|
17 |
val path = Path.explode (base_name ^ ".b2i") |
|
18 |
val _ = File.exists path orelse |
|
19 |
error ("Unable to find file " ^ quote (Path.implode path))
|
|
20 |
val _ = Boogie_VCs.is_closed thy orelse |
|
21 |
error ("Found the beginning of a new Boogie environment, " ^
|
|
22 |
"but another Boogie environment is still open.") |
|
23 |
in Boogie_Loader.load_b2i verbose path thy end |
|
24 |
||
25 |
fun boogie_status thy = |
|
26 |
let |
|
27 |
fun pretty_vc_name (name, _, proved) = |
|
28 |
let val s = if proved then "proved" else "not proved" |
|
29 |
in Pretty.str (name ^ " (" ^ s ^ ")") end
|
|
30 |
in |
|
31 |
Pretty.writeln (Pretty.big_list "Boogie verification conditions:" |
|
32 |
(map pretty_vc_name (Boogie_VCs.as_list thy))) |
|
33 |
end |
|
34 |
||
35 |
fun boogie_vc name lthy = |
|
36 |
(case Boogie_VCs.lookup (ProofContext.theory_of lthy) name of |
|
37 |
NONE => error ("There is no verification condition " ^ quote name ^ ".")
|
|
38 |
| SOME vc => |
|
39 |
let |
|
40 |
fun store thm = Boogie_VCs.discharge (name, thm) |
|
| 33671 | 41 |
fun after_qed [[thm]] = Local_Theory.theory (store thm) |
| 33419 | 42 |
| after_qed _ = I |
|
33445
f0c78a28e18e
shorter names for variables and verification conditions,
boehmes
parents:
33419
diff
changeset
|
43 |
in |
|
f0c78a28e18e
shorter names for variables and verification conditions,
boehmes
parents:
33419
diff
changeset
|
44 |
lthy |
|
f0c78a28e18e
shorter names for variables and verification conditions,
boehmes
parents:
33419
diff
changeset
|
45 |
|> Variable.auto_fixes vc |
|
f0c78a28e18e
shorter names for variables and verification conditions,
boehmes
parents:
33419
diff
changeset
|
46 |
|> Proof.theorem_i NONE after_qed [[(vc, [])]] |
|
f0c78a28e18e
shorter names for variables and verification conditions,
boehmes
parents:
33419
diff
changeset
|
47 |
end) |
| 33419 | 48 |
|
49 |
fun boogie_end thy = |
|
50 |
let |
|
51 |
fun not_proved (name, _, proved) = if not proved then SOME name else NONE |
|
52 |
val unproved = map_filter not_proved (Boogie_VCs.as_list thy) |
|
53 |
in |
|
54 |
if null unproved then Boogie_VCs.close thy |
|
55 |
else error (Pretty.string_of (Pretty.big_list |
|
56 |
"The following verification conditions have not been proved:" |
|
57 |
(map Pretty.str unproved))) |
|
58 |
end |
|
59 |
||
60 |
val _ = |
|
61 |
OuterSyntax.command "boogie_open" |
|
62 |
"Open a new Boogie environment and load a Boogie-generated .b2i file." |
|
63 |
OuterKeyword.thy_decl |
|
64 |
(Scan.optional (Args.parens (Args.$$$ "quiet") >> K false) true -- |
|
65 |
OuterParse.name >> (Toplevel.theory o boogie_load)) |
|
66 |
||
67 |
val _ = |
|
68 |
OuterSyntax.improper_command "boogie_status" |
|
69 |
"Show the name and state of all loaded verification conditions." |
|
70 |
OuterKeyword.diag |
|
71 |
(Scan.succeed (Toplevel.no_timing o Toplevel.keep (fn state => |
|
72 |
boogie_status (Toplevel.theory_of state)))) |
|
73 |
||
74 |
val _ = |
|
75 |
OuterSyntax.command "boogie_vc" |
|
76 |
"Enter the proof mode for a specific verification condition." |
|
77 |
OuterKeyword.thy_goal |
|
78 |
(OuterParse.name >> (fn name => Toplevel.print o |
|
79 |
Toplevel.local_theory_to_proof NONE (boogie_vc name))) |
|
80 |
||
81 |
val _ = |
|
82 |
OuterSyntax.command "boogie_end" |
|
83 |
"Close the current Boogie environment." |
|
84 |
OuterKeyword.thy_decl |
|
85 |
(Scan.succeed (Toplevel.theory boogie_end)) |
|
86 |
||
87 |
val setup = Theory.at_end (fn thy => |
|
88 |
let |
|
89 |
val _ = Boogie_VCs.is_closed thy |
|
90 |
orelse error ("Found the end of the theory, " ^
|
|
91 |
"but the last Boogie environment is still open.") |
|
92 |
in NONE end) |
|
93 |
||
94 |
end |