-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfact_printer.ml
129 lines (113 loc) · 2.96 KB
/
fact_printer.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
(* Printers for facts, ids, and frames. Used when debugging *)
(* Copyright (C) 2019 The MITRE Corporation
This program is free software: you can redistribute it and/or
modify it under the terms of the BSD License as published by the
University of California. *)
open Format
open Sym
open Fact
open Structure
open Solve
open Formula
open Unflatten
(* Printer for an id *)
let print_sym ctx f x =
pp_print_string f (pname ctx x)
(* Facts *)
let print_commas pp f xs =
let commas f () =
pp_print_string f ",";
pp_print_space f () in
pp_print_list ~pp_sep:commas pp f xs
let print_args pp f xs =
pp_print_string f "(";
pp_open_box f 0;
print_commas pp f xs;
pp_print_string f ")";
pp_close_box f ()
(* Printer for a fact *)
let print_fact ctx f = function
| Q (s, []) ->
print_sym ctx f s
| Q (s, xs) ->
print_sym ctx f s;
print_args (print_sym ctx) f xs
| G (s, [], a) ->
print_sym ctx f s;
pp_print_string f " = ";
print_sym ctx f a
| G (s, xs, a) ->
pp_open_box f 2;
print_sym ctx f s;
print_args (print_sym ctx) f xs;
pp_print_space f ();
pp_print_string f "= ";
print_sym ctx f a;
pp_close_box f ()
(* Frames *)
(* Printer for a frame *)
let print_a_frame pr f {label; parent; structure; status; cause; _} =
pp_open_box f 2;
pp_print_string f "(";
pp_print_int f label;
(match parent with
| None -> ()
| Some p ->
pp_print_string f ",";
pp_print_int f p);
pp_print_string f ")";
(match cause with
| None -> ()
| Some c ->
pp_print_string f "{";
pp_print_int f c;
pp_print_string f "}");
if status = Sat then
pp_print_string f "!"
else if status = Aborted then
pp_print_string f "?";
pp_print_string f "[";
pr @@ facts structure;
pp_print_string f "]";
pp_close_box f ();
pp_print_newline f ()
(* Standard printer *)
let print_frame ctx f fr =
let pr facts =
print_commas (print_fact ctx) f facts in
print_a_frame pr f fr
(* Print a frame with an unflattened structure *)
let rec print_term ctx f = function
| C x -> print_sym ctx f x
| V _ -> assert false
| F (s, []) -> print_sym ctx f s
| F (s, xs) ->
print_sym ctx f s;
print_args (print_term ctx) f xs
(* Printer for an atom *)
let print_atom ctx f = function
| P (s, []) ->
print_sym ctx f s
| P (s, xs) ->
print_sym ctx f s;
print_args (print_term ctx) f xs
| E (x, y) ->
pp_open_box f 2;
print_term ctx f x;
pp_print_space f ();
pp_print_string f "= ";
print_term ctx f y;
pp_close_box f ()
| U x ->
pp_open_box f 2;
print_term ctx f x;
pp_print_space f ();
pp_print_string f "= ";
print_term ctx f x;
pp_close_box f ()
let print_unflattened_atoms ctx f facts =
let atoms = unflatten facts in
print_commas (print_atom ctx) f atoms
(* Print frame with an unflattened structure *)
let print_unflattened ctx f fr =
print_a_frame (print_unflattened_atoms ctx f) f fr