src/Pure/PIDE/document_status.scala
changeset 83160 bc86832bd2fd
parent 83158 7e94f31b6d6c
child 83161 87ceb18f23f3
equal deleted inserted replaced
83159:d120974ad1d6 83160:bc86832bd2fd
    10 object Document_Status {
    10 object Document_Status {
    11   /* command status */
    11   /* command status */
    12 
    12 
    13   object Command_Status {
    13   object Command_Status {
    14     object Theory_Status extends Enumeration {
    14     object Theory_Status extends Enumeration {
    15       val NONE, INITIALIZED, CONSOLIDATING, CONSOLIDATED = Value
    15       val NONE, INITIALIZED, FINALIZED, CONSOLIDATING, CONSOLIDATED = Value
    16 
    16 
    17       def initialized(t: Value): Boolean = t >= INITIALIZED
    17       def initialized(t: Value): Boolean = t >= INITIALIZED
       
    18       def finalized(t: Value): Boolean = t >= FINALIZED
    18       def consolidating(t: Value): Boolean = t >= CONSOLIDATING
    19       def consolidating(t: Value): Boolean = t >= CONSOLIDATING
    19       def consolidated(t: Value): Boolean = t >= CONSOLIDATED
    20       def consolidated(t: Value): Boolean = t >= CONSOLIDATED
    20 
    21 
    21       def merge(t1: Value, t2: Value): Value = if (t1 >= t2) t1 else t2
    22       def merge(t1: Value, t2: Value): Value = if (t1 >= t2) t1 else t2
    22     }
    23     }
    37       var touched = false
    38       var touched = false
    38       var accepted = false
    39       var accepted = false
    39       var warned1 = warned
    40       var warned1 = warned
    40       var failed1 = failed
    41       var failed1 = failed
    41       var canceled = false
    42       var canceled = false
    42       var finalized = false
       
    43       var forks = 0
    43       var forks = 0
    44       var runs = 0
    44       var runs = 0
    45       for (markup <- markups) {
    45       for (markup <- markups) {
    46         markup.name match {
    46         markup.name match {
    47           case Markup.INITIALIZED =>
    47           case Markup.INITIALIZED =>
    48             theory_status = Theory_Status.merge(theory_status, Theory_Status.INITIALIZED)
    48             theory_status = Theory_Status.merge(theory_status, Theory_Status.INITIALIZED)
       
    49           case Markup.FINALIZED =>
       
    50             theory_status = Theory_Status.merge(theory_status, Theory_Status.FINALIZED)
    49           case Markup.CONSOLIDATING =>
    51           case Markup.CONSOLIDATING =>
    50             theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATING)
    52             theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATING)
    51           case Markup.CONSOLIDATED =>
    53           case Markup.CONSOLIDATED =>
    52             theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATED)
    54             theory_status = Theory_Status.merge(theory_status, Theory_Status.CONSOLIDATED)
    53           case Markup.ACCEPTED => accepted = true
    55           case Markup.ACCEPTED => accepted = true
    56           case Markup.RUNNING => touched = true; runs += 1
    58           case Markup.RUNNING => touched = true; runs += 1
    57           case Markup.FINISHED => runs -= 1
    59           case Markup.FINISHED => runs -= 1
    58           case Markup.WARNING | Markup.LEGACY => warned1 = true
    60           case Markup.WARNING | Markup.LEGACY => warned1 = true
    59           case Markup.FAILED | Markup.ERROR => failed1 = true
    61           case Markup.FAILED | Markup.ERROR => failed1 = true
    60           case Markup.CANCELED => canceled = true
    62           case Markup.CANCELED => canceled = true
    61           case Markup.FINALIZED => finalized = true
       
    62           case _ =>
    63           case _ =>
    63         }
    64         }
    64       }
    65       }
    65       new Command_Status(
    66       new Command_Status(
    66         theory_status = theory_status,
    67         theory_status = theory_status,
    67         touched = touched,
    68         touched = touched,
    68         accepted = accepted,
    69         accepted = accepted,
    69         warned = warned1,
    70         warned = warned1,
    70         failed = failed1,
    71         failed = failed1,
    71         canceled = canceled,
    72         canceled = canceled,
    72         finalized = finalized,
       
    73         forks = forks,
    73         forks = forks,
    74         runs = runs)
    74         runs = runs)
    75     }
    75     }
    76 
    76 
    77     val empty: Command_Status = make(Nil)
    77     val empty: Command_Status = make(Nil)
    85     private val touched: Boolean,
    85     private val touched: Boolean,
    86     private val accepted: Boolean,
    86     private val accepted: Boolean,
    87     private val warned: Boolean,
    87     private val warned: Boolean,
    88     private val failed: Boolean,
    88     private val failed: Boolean,
    89     private val canceled: Boolean,
    89     private val canceled: Boolean,
    90     private val finalized: Boolean,
       
    91     val forks: Int,
    90     val forks: Int,
    92     val runs: Int
    91     val runs: Int
    93   ) {
    92   ) {
    94     override def toString: String =
    93     override def toString: String =
    95       if (is_empty) "Command_Status.empty"
    94       if (is_empty) "Command_Status.empty"
    97       else if (warned) "Command_Status(warned)"
    96       else if (warned) "Command_Status(warned)"
    98       else "Command_Status(...)"
    97       else "Command_Status(...)"
    99 
    98 
   100     def is_empty: Boolean =
    99     def is_empty: Boolean =
   101       !Command_Status.Theory_Status.initialized(theory_status) &&
   100       !Command_Status.Theory_Status.initialized(theory_status) &&
   102       !touched && !accepted && !warned && !failed && !canceled && !finalized &&
   101       !touched && !accepted && !warned && !failed && !canceled &&
   103       forks == 0 && runs == 0
   102       forks == 0 && runs == 0
   104 
   103 
   105     def + (that: Command_Status): Command_Status =
   104     def + (that: Command_Status): Command_Status =
   106       if (is_empty) that
   105       if (is_empty) that
   107       else if (that.is_empty) this
   106       else if (that.is_empty) this
   111           touched = touched || that.touched,
   110           touched = touched || that.touched,
   112           accepted = accepted || that.accepted,
   111           accepted = accepted || that.accepted,
   113           warned = warned || that.warned,
   112           warned = warned || that.warned,
   114           failed = failed || that.failed,
   113           failed = failed || that.failed,
   115           canceled = canceled || that.canceled,
   114           canceled = canceled || that.canceled,
   116           finalized = finalized || that.finalized,
       
   117           forks = forks + that.forks,
   115           forks = forks + that.forks,
   118           runs = runs + that.runs)
   116           runs = runs + that.runs)
   119       }
   117       }
   120 
   118 
   121     def initialized: Boolean = Command_Status.Theory_Status.initialized(theory_status)
   119     def initialized: Boolean = Command_Status.Theory_Status.initialized(theory_status)
       
   120     def finalized: Boolean = Command_Status.Theory_Status.finalized(theory_status)
   122     def consolidating: Boolean = Command_Status.Theory_Status.consolidating(theory_status)
   121     def consolidating: Boolean = Command_Status.Theory_Status.consolidating(theory_status)
   123     def consolidated: Boolean = Command_Status.Theory_Status.consolidated(theory_status)
   122     def consolidated: Boolean = Command_Status.Theory_Status.consolidated(theory_status)
   124     def maybe_consolidated: Boolean = touched && forks == 0 && runs == 0
   123     def maybe_consolidated: Boolean = touched && forks == 0 && runs == 0
   125 
   124 
   126     def is_unprocessed: Boolean = accepted && !failed && (!touched || (forks != 0 && runs == 0))
   125     def is_unprocessed: Boolean = accepted && !failed && (!touched || (forks != 0 && runs == 0))
   127     def is_running: Boolean = runs != 0
   126     def is_running: Boolean = runs != 0
   128     def is_warned: Boolean = warned
   127     def is_warned: Boolean = warned
   129     def is_failed: Boolean = failed
   128     def is_failed: Boolean = failed
   130     def is_finished: Boolean = !failed && touched && forks == 0 && runs == 0
   129     def is_finished: Boolean = !failed && touched && forks == 0 && runs == 0
   131     def is_canceled: Boolean = canceled
   130     def is_canceled: Boolean = canceled
   132     def is_finalized: Boolean = finalized
       
   133     def is_terminated: Boolean = canceled || touched && forks == 0 && runs == 0
   131     def is_terminated: Boolean = canceled || touched && forks == 0 && runs == 0
   134   }
   132   }
   135 
   133 
   136 
   134 
   137   /* node status */
   135   /* node status */
   176         else if (status.is_finished) finished += 1
   174         else if (status.is_finished) finished += 1
   177         else unprocessed += 1
   175         else unprocessed += 1
   178 
   176 
   179         if (status.is_canceled) canceled = true
   177         if (status.is_canceled) canceled = true
   180         if (!status.is_terminated) terminated = false
   178         if (!status.is_terminated) terminated = false
   181         if (status.is_finalized) finalized = true
   179         if (status.finalized) finalized = true
   182       }
   180       }
   183       val initialized = state.node_initialized(version, name)
   181       val initialized = state.node_initialized(version, name)
   184       val consolidated = state.node_consolidated(version, name)
   182       val consolidated = state.node_consolidated(version, name)
   185 
   183 
   186       Node_Status(
   184       Node_Status(