| author | wenzelm |
| Wed, 17 Sep 2025 17:29:29 +0200 | |
| changeset 83187 | 2b9457f5ffef |
| parent 83186 | 887f1eac24d1 |
| child 83188 | 481c3e1cb957 |
| permissions | -rw-r--r-- |
| 68758 | 1 |
/* Title: Pure/PIDE/document_status.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Document status based on markup information. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
| 75393 | 10 |
object Document_Status {
|
| 83161 | 11 |
/* theory status: via 'theory' or 'end' commands */ |
12 |
||
13 |
object Theory_Status extends Enumeration {
|
|
14 |
val NONE, INITIALIZED, FINALIZED, CONSOLIDATING, CONSOLIDATED = Value |
|
15 |
||
16 |
def initialized(t: Value): Boolean = t >= INITIALIZED |
|
17 |
def finalized(t: Value): Boolean = t >= FINALIZED |
|
18 |
def consolidating(t: Value): Boolean = t >= CONSOLIDATING |
|
19 |
def consolidated(t: Value): Boolean = t >= CONSOLIDATED |
|
20 |
||
21 |
def merge(t1: Value, t2: Value): Value = if (t1 >= t2) t1 else t2 |
|
22 |
} |
|
23 |
||
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
24 |
trait Theory_Status {
|
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
25 |
def theory_status: Theory_Status.Value |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
26 |
def initialized: Boolean = Theory_Status.initialized(theory_status) |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
27 |
def finalized: Boolean = Theory_Status.finalized(theory_status) |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
28 |
def consolidating: Boolean = Theory_Status.consolidating(theory_status) |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
29 |
def consolidated: Boolean = Theory_Status.consolidated(theory_status) |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
30 |
} |
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
31 |
|
| 83161 | 32 |
|
| 68758 | 33 |
/* command status */ |
34 |
||
| 75393 | 35 |
object Command_Status {
|
| 68758 | 36 |
val proper_elements: Markup.Elements = |
37 |
Markup.Elements(Markup.ACCEPTED, Markup.FORKED, Markup.JOINED, Markup.RUNNING, |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
38 |
Markup.FINISHED, Markup.FAILED, Markup.CANCELED) |
| 68758 | 39 |
|
40 |
val liberal_elements: Markup.Elements = |
|
41 |
proper_elements + Markup.WARNING + Markup.LEGACY + Markup.ERROR |
|
42 |
||
| 83157 | 43 |
def make( |
| 83185 | 44 |
markups: List[Markup] = Nil, |
| 83157 | 45 |
warned: Boolean = false, |
46 |
failed: Boolean = false |
|
47 |
): Command_Status = {
|
|
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
48 |
var theory_status = Theory_Status.NONE |
| 68758 | 49 |
var touched = false |
50 |
var accepted = false |
|
| 83157 | 51 |
var warned1 = warned |
52 |
var failed1 = failed |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
53 |
var canceled = false |
| 68758 | 54 |
var forks = 0 |
55 |
var runs = 0 |
|
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
56 |
var timing = Timing.zero |
| 83155 | 57 |
for (markup <- markups) {
|
| 68758 | 58 |
markup.name match {
|
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
59 |
case Markup.INITIALIZED => |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
60 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.INITIALIZED) |
|
83160
bc86832bd2fd
clarified Theory_Status.FINALIZED: it belongs to this linear row, too;
wenzelm
parents:
83158
diff
changeset
|
61 |
case Markup.FINALIZED => |
|
bc86832bd2fd
clarified Theory_Status.FINALIZED: it belongs to this linear row, too;
wenzelm
parents:
83158
diff
changeset
|
62 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.FINALIZED) |
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
63 |
case Markup.CONSOLIDATING => |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
64 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATING) |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
65 |
case Markup.CONSOLIDATED => |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
66 |
theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATED) |
| 68758 | 67 |
case Markup.ACCEPTED => accepted = true |
68 |
case Markup.FORKED => touched = true; forks += 1 |
|
69 |
case Markup.JOINED => forks -= 1 |
|
70 |
case Markup.RUNNING => touched = true; runs += 1 |
|
71 |
case Markup.FINISHED => runs -= 1 |
|
| 83157 | 72 |
case Markup.WARNING | Markup.LEGACY => warned1 = true |
73 |
case Markup.FAILED | Markup.ERROR => failed1 = true |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
74 |
case Markup.CANCELED => canceled = true |
| 68758 | 75 |
case _ => |
76 |
} |
|
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
77 |
markup match {
|
|
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
78 |
case Markup.Timing(t) => timing += t |
|
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
79 |
case _ => |
|
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
80 |
} |
| 68758 | 81 |
} |
| 83155 | 82 |
new Command_Status( |
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
83 |
theory_status = theory_status, |
| 68887 | 84 |
touched = touched, |
85 |
accepted = accepted, |
|
| 83157 | 86 |
warned = warned1, |
87 |
failed = failed1, |
|
| 68887 | 88 |
canceled = canceled, |
89 |
forks = forks, |
|
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
90 |
runs = runs, |
|
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
91 |
timing = timing) |
| 68758 | 92 |
} |
93 |
||
|
83183
6e03fb945baf
more scalable Command.State.document_status: prefer incremental update;
wenzelm
parents:
83181
diff
changeset
|
94 |
val empty: Command_Status = make() |
| 68758 | 95 |
|
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
96 |
def merge(args: IterableOnce[Command_Status]): Command_Status = |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
97 |
args.iterator.foldLeft(empty)(_ + _) |
| 68758 | 98 |
} |
99 |
||
| 83155 | 100 |
final class Command_Status private( |
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
101 |
val theory_status: Theory_Status.Value, |
| 68758 | 102 |
private val touched: Boolean, |
103 |
private val accepted: Boolean, |
|
104 |
private val warned: Boolean, |
|
105 |
private val failed: Boolean, |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
106 |
private val canceled: Boolean, |
| 83155 | 107 |
val forks: Int, |
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
108 |
val runs: Int, |
|
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
109 |
val timing: Timing |
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
110 |
) extends Theory_Status {
|
| 83155 | 111 |
override def toString: String = |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
112 |
if (is_empty) "Command_Status.empty" |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
113 |
else if (failed) "Command_Status(failed)" |
| 83155 | 114 |
else if (warned) "Command_Status(warned)" |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
115 |
else "Command_Status(...)" |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
116 |
|
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
117 |
def is_empty: Boolean = |
| 83161 | 118 |
!Theory_Status.initialized(theory_status) && |
|
83160
bc86832bd2fd
clarified Theory_Status.FINALIZED: it belongs to this linear row, too;
wenzelm
parents:
83158
diff
changeset
|
119 |
!touched && !accepted && !warned && !failed && !canceled && |
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
120 |
forks == 0 && runs == 0 && timing.is_zero |
| 83155 | 121 |
|
| 68758 | 122 |
def + (that: Command_Status): Command_Status = |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
123 |
if (is_empty) that |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
124 |
else if (that.is_empty) this |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
125 |
else {
|
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
126 |
new Command_Status( |
| 83161 | 127 |
theory_status = Theory_Status.merge(theory_status, that.theory_status), |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
128 |
touched = touched || that.touched, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
129 |
accepted = accepted || that.accepted, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
130 |
warned = warned || that.warned, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
131 |
failed = failed || that.failed, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
132 |
canceled = canceled || that.canceled, |
|
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
133 |
forks = forks + that.forks, |
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
134 |
runs = runs + that.runs, |
|
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
135 |
timing = timing + that.timing) |
|
83156
6bc5835bc794
clarified signature, following e.g. Command.Markups;
wenzelm
parents:
83155
diff
changeset
|
136 |
} |
| 68758 | 137 |
|
| 83185 | 138 |
def update( |
139 |
markups: List[Markup] = Nil, |
|
140 |
warned: Boolean = false, |
|
141 |
failed: Boolean = false |
|
142 |
): Command_Status = {
|
|
143 |
if (markups.isEmpty) {
|
|
144 |
val warned1 = this.warned || warned |
|
145 |
val failed1 = this.failed || failed |
|
146 |
if (this.warned == warned1 && this.failed == failed1) this |
|
147 |
else {
|
|
148 |
new Command_Status( |
|
149 |
theory_status = theory_status, |
|
150 |
touched = touched, |
|
151 |
accepted = accepted, |
|
152 |
warned = warned1, |
|
153 |
failed = failed1, |
|
154 |
canceled = canceled, |
|
155 |
forks = forks, |
|
|
83186
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
156 |
runs = runs, |
|
887f1eac24d1
more scalable timing, as part of incremental document_status;
wenzelm
parents:
83185
diff
changeset
|
157 |
timing = timing) |
| 83185 | 158 |
} |
| 83184 | 159 |
} |
| 83185 | 160 |
else this + Command_Status.make(markups = markups, warned = warned, failed = failed) |
| 83184 | 161 |
} |
162 |
||
|
83158
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
163 |
def maybe_consolidated: Boolean = touched && forks == 0 && runs == 0 |
|
7e94f31b6d6c
clarified signature: more explicit type Theory_Status;
wenzelm
parents:
83157
diff
changeset
|
164 |
|
| 68758 | 165 |
def is_unprocessed: Boolean = accepted && !failed && (!touched || (forks != 0 && runs == 0)) |
166 |
def is_running: Boolean = runs != 0 |
|
167 |
def is_warned: Boolean = warned |
|
168 |
def is_failed: Boolean = failed |
|
169 |
def is_finished: Boolean = !failed && touched && forks == 0 && runs == 0 |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
170 |
def is_canceled: Boolean = canceled |
| 68881 | 171 |
def is_terminated: Boolean = canceled || touched && forks == 0 && runs == 0 |
| 68758 | 172 |
} |
173 |
||
174 |
||
175 |
/* node status */ |
|
176 |
||
| 75393 | 177 |
object Node_Status {
|
| 83167 | 178 |
val empty: Node_Status = Node_Status() |
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
179 |
|
| 68758 | 180 |
def make( |
181 |
state: Document.State, |
|
182 |
version: Document.Version, |
|
| 76714 | 183 |
name: Document.Node.Name |
184 |
): Node_Status = {
|
|
| 68758 | 185 |
var unprocessed = 0 |
186 |
var running = 0 |
|
187 |
var warned = 0 |
|
188 |
var failed = 0 |
|
189 |
var finished = 0 |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
190 |
var canceled = false |
| 68892 | 191 |
var terminated = true |
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
192 |
var theory_status = Document_Status.Theory_Status.NONE |
|
83178
952c1ca9b842
clarified signature: more uniform Node_Status.make vs. Overall_Timing.make;
wenzelm
parents:
83176
diff
changeset
|
193 |
for (command <- version.nodes(name).commands.iterator) {
|
| 83164 | 194 |
val status = state.command_status(version, command) |
| 68758 | 195 |
|
196 |
if (status.is_running) running += 1 |
|
197 |
else if (status.is_failed) failed += 1 |
|
198 |
else if (status.is_warned) warned += 1 |
|
199 |
else if (status.is_finished) finished += 1 |
|
200 |
else unprocessed += 1 |
|
|
68871
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
201 |
|
|
f5c76072db55
more explicit status for "canceled" command within theory node;
wenzelm
parents:
68770
diff
changeset
|
202 |
if (status.is_canceled) canceled = true |
| 68892 | 203 |
if (!status.is_terminated) terminated = false |
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
204 |
|
|
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
205 |
theory_status = Theory_Status.merge(theory_status, status.theory_status) |
| 68758 | 206 |
} |
207 |
||
| 68887 | 208 |
Node_Status( |
| 83163 | 209 |
suppressed = version.nodes.suppressed(name), |
| 68887 | 210 |
unprocessed = unprocessed, |
211 |
running = running, |
|
212 |
warned = warned, |
|
213 |
failed = failed, |
|
214 |
finished = finished, |
|
215 |
canceled = canceled, |
|
216 |
terminated = terminated, |
|
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
217 |
theory_status = theory_status) |
| 68758 | 218 |
} |
219 |
} |
|
220 |
||
221 |
sealed case class Node_Status( |
|
| 83167 | 222 |
suppressed: Boolean = false, |
223 |
unprocessed: Int = 0, |
|
224 |
running: Int = 0, |
|
225 |
warned: Int = 0, |
|
226 |
failed: Int = 0, |
|
227 |
finished: Int = 0, |
|
228 |
canceled: Boolean = false, |
|
229 |
terminated: Boolean = false, |
|
230 |
theory_status: Theory_Status.Value = Theory_Status.NONE |
|
|
83165
9f3f723938fc
more uniform Command_Status.theory_status vs. Node_Status.theory_status: cover all command_states, without special cases;
wenzelm
parents:
83164
diff
changeset
|
231 |
) extends Theory_Status {
|
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
232 |
def is_empty: Boolean = this == Node_Status.empty |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
233 |
|
| 68758 | 234 |
def ok: Boolean = failed == 0 |
235 |
def total: Int = unprocessed + running + warned + failed + finished |
|
236 |
||
| 83163 | 237 |
def quasi_consolidated: Boolean = !suppressed && !finalized && terminated |
| 68897 | 238 |
|
| 68898 | 239 |
def percentage: Int = |
240 |
if (consolidated) 100 |
|
241 |
else if (total == 0) 0 |
|
242 |
else (((total - unprocessed).toDouble / total) * 100).toInt min 99 |
|
243 |
||
| 68758 | 244 |
def json: JSON.Object.T = |
245 |
JSON.Object("ok" -> ok, "total" -> total, "unprocessed" -> unprocessed,
|
|
246 |
"running" -> running, "warned" -> warned, "failed" -> failed, "finished" -> finished, |
|
| 68898 | 247 |
"canceled" -> canceled, "consolidated" -> consolidated, |
248 |
"percentage" -> percentage) |
|
| 68758 | 249 |
} |
250 |
||
251 |
||
| 69863 | 252 |
/* overall timing */ |
| 68758 | 253 |
|
| 75393 | 254 |
object Overall_Timing {
|
| 83154 | 255 |
val empty: Overall_Timing = Overall_Timing() |
| 68758 | 256 |
|
257 |
def make( |
|
258 |
state: Document.State, |
|
259 |
version: Document.Version, |
|
|
83178
952c1ca9b842
clarified signature: more uniform Node_Status.make vs. Overall_Timing.make;
wenzelm
parents:
83176
diff
changeset
|
260 |
name: Document.Node.Name, |
| 83176 | 261 |
threshold: Time = Time.zero |
| 75393 | 262 |
): Overall_Timing = {
|
| 83180 | 263 |
var total = Time.zero |
264 |
var command_timings = Map.empty[Command, Time] |
|
|
83178
952c1ca9b842
clarified signature: more uniform Node_Status.make vs. Overall_Timing.make;
wenzelm
parents:
83176
diff
changeset
|
265 |
for (command <- version.nodes(name).commands.iterator) {
|
| 83175 | 266 |
val timing = state.command_timing(version, command) |
| 83180 | 267 |
total += timing.elapsed |
268 |
if (timing.is_notable(threshold)) command_timings += (command -> timing.elapsed) |
|
| 68758 | 269 |
} |
| 83179 | 270 |
Overall_Timing(total = total, threshold = threshold, command_timings = command_timings) |
| 68758 | 271 |
} |
272 |
} |
|
273 |
||
| 83154 | 274 |
sealed case class Overall_Timing( |
| 83180 | 275 |
total: Time = Time.zero, |
| 83179 | 276 |
threshold: Time = Time.zero, |
| 83181 | 277 |
command_timings: Map[Command, Time] = Map.empty) |
| 68759 | 278 |
|
279 |
||
280 |
/* nodes status */ |
|
281 |
||
| 83169 | 282 |
enum Overall_Status { case ok, failed, pending }
|
| 68759 | 283 |
|
| 75393 | 284 |
object Nodes_Status {
|
| 68903 | 285 |
val empty: Nodes_Status = new Nodes_Status(Map.empty, Document.Nodes.empty) |
| 68759 | 286 |
} |
287 |
||
| 68903 | 288 |
final class Nodes_Status private( |
289 |
private val rep: Map[Document.Node.Name, Node_Status], |
|
| 75393 | 290 |
nodes: Document.Nodes |
291 |
) {
|
|
|
68770
add44e2b8cb0
optional notification of nodes_status (via progress);
wenzelm
parents:
68769
diff
changeset
|
292 |
def is_empty: Boolean = rep.isEmpty |
|
83187
2b9457f5ffef
more robust: total "apply", with subtle change of semantics;
wenzelm
parents:
83186
diff
changeset
|
293 |
def apply(name: Document.Node.Name): Node_Status = rep.getOrElse(name, Node_Status.empty) |
| 68759 | 294 |
def get(name: Document.Node.Name): Option[Node_Status] = rep.get(name) |
295 |
||
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
296 |
def present( |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
297 |
domain: Option[List[Document.Node.Name]] = None |
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
298 |
): List[(Document.Node.Name, Node_Status)] = {
|
|
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
299 |
for (name <- domain.getOrElse(nodes.topological_order)) |
|
83187
2b9457f5ffef
more robust: total "apply", with subtle change of semantics;
wenzelm
parents:
83186
diff
changeset
|
300 |
yield name -> apply(name) |
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76714
diff
changeset
|
301 |
} |
| 68903 | 302 |
|
|
68884
9b97d0b20d95
clarified quasi_consolidated state: ensure that exports are present for ok nodes;
wenzelm
parents:
68883
diff
changeset
|
303 |
def quasi_consolidated(name: Document.Node.Name): Boolean = |
| 83170 | 304 |
get(name) match {
|
| 68897 | 305 |
case Some(st) => st.quasi_consolidated |
|
68883
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
306 |
case None => false |
|
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
307 |
} |
|
3653b3ad729e
clarified Thy_Resources.Session.use_theories: "terminated" node status is sufficient;
wenzelm
parents:
68881
diff
changeset
|
308 |
|
| 83169 | 309 |
def overall_status(name: Document.Node.Name): Overall_Status = |
| 83170 | 310 |
get(name) match {
|
| 68759 | 311 |
case Some(st) if st.consolidated => |
| 83169 | 312 |
if (st.ok) Overall_Status.ok else Overall_Status.failed |
313 |
case _ => Overall_Status.pending |
|
| 68759 | 314 |
} |
315 |
||
| 68763 | 316 |
def update( |
|
69255
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
wenzelm
parents:
68904
diff
changeset
|
317 |
resources: Resources, |
| 68763 | 318 |
state: Document.State, |
319 |
version: Document.Version, |
|
| 68769 | 320 |
domain: Option[Set[Document.Node.Name]] = None, |
| 75393 | 321 |
trim: Boolean = false |
322 |
): (Boolean, Nodes_Status) = {
|
|
| 68903 | 323 |
val nodes1 = version.nodes |
| 68763 | 324 |
val update_iterator = |
325 |
for {
|
|
| 68903 | 326 |
name <- domain.getOrElse(nodes1.domain).iterator |
| 82918 | 327 |
if !Resources.hidden_node(name) && !resources.loaded_theory(name) |
| 68763 | 328 |
st = Document_Status.Node_Status.make(state, version, name) |
|
83187
2b9457f5ffef
more robust: total "apply", with subtle change of semantics;
wenzelm
parents:
83186
diff
changeset
|
329 |
if apply(name) != st |
| 68763 | 330 |
} yield (name -> st) |
331 |
val rep1 = rep ++ update_iterator |
|
| 68903 | 332 |
val rep2 = if (trim) rep1 -- rep1.keysIterator.filterNot(nodes1.domain) else rep1 |
| 68764 | 333 |
|
| 68903 | 334 |
(rep != rep2, new Nodes_Status(rep2, nodes1)) |
| 68763 | 335 |
} |
| 68761 | 336 |
|
| 68759 | 337 |
override def hashCode: Int = rep.hashCode |
338 |
override def equals(that: Any): Boolean = |
|
339 |
that match {
|
|
340 |
case other: Nodes_Status => rep == other.rep |
|
341 |
case _ => false |
|
342 |
} |
|
| 68765 | 343 |
|
| 75393 | 344 |
override def toString: String = {
|
| 68765 | 345 |
var ok = 0 |
346 |
var failed = 0 |
|
347 |
var pending = 0 |
|
| 68873 | 348 |
var canceled = 0 |
| 68765 | 349 |
for (name <- rep.keysIterator) {
|
| 83169 | 350 |
overall_status(name) match {
|
351 |
case Overall_Status.ok => ok += 1 |
|
352 |
case Overall_Status.failed => failed += 1 |
|
353 |
case Overall_Status.pending => pending += 1 |
|
| 68765 | 354 |
} |
| 68873 | 355 |
if (apply(name).canceled) canceled += 1 |
| 68765 | 356 |
} |
| 68873 | 357 |
"Nodes_Status(ok = " + ok + ", failed = " + failed + ", pending = " + pending + |
358 |
", canceled = " + canceled + ")" |
|
| 68765 | 359 |
} |
| 68759 | 360 |
} |
| 68758 | 361 |
} |