src/Tools/jEdit/src/simplifier_trace_window.scala
changeset 55553 99409ccbe04a
parent 55316 885500f4aa6a
child 55556 60ba93d8f9e5
equal deleted inserted replaced
55552:e4907b74a347 55553:99409ccbe04a
     8 
     8 
     9 
     9 
    10 import isabelle._
    10 import isabelle._
    11 
    11 
    12 import scala.annotation.tailrec
    12 import scala.annotation.tailrec
    13 
       
    14 import scala.collection.immutable.SortedMap
    13 import scala.collection.immutable.SortedMap
    15 
       
    16 import scala.swing.{BorderPanel, CheckBox, Component, Dimension, Frame, Label, TextField}
    14 import scala.swing.{BorderPanel, CheckBox, Component, Dimension, Frame, Label, TextField}
    17 import scala.swing.event.{Key, KeyPressed}
    15 import scala.swing.event.{Key, KeyPressed}
    18 
       
    19 import scala.util.matching.Regex
    16 import scala.util.matching.Regex
    20 
    17 
    21 import java.awt.BorderLayout
    18 import java.awt.BorderLayout
    22 import java.awt.event.{ComponentEvent, ComponentAdapter}
    19 import java.awt.event.{ComponentEvent, ComponentAdapter}
    23 
    20 
    24 import javax.swing.SwingUtilities
    21 import javax.swing.SwingUtilities
    25 
    22 
    26 import org.gjt.sp.jedit.View
    23 import org.gjt.sp.jedit.View
    27 
    24 
       
    25 
    28 private object Simplifier_Trace_Window
    26 private object Simplifier_Trace_Window
    29 {
    27 {
    30 
       
    31   import Markup.Simp_Trace_Item
       
    32 
       
    33   sealed trait Trace_Tree
    28   sealed trait Trace_Tree
    34   {
    29   {
    35     var children: SortedMap[Long, Elem_Tree] = SortedMap.empty
    30     var children: SortedMap[Long, Elem_Tree] = SortedMap.empty
    36     val serial: Long
    31     val serial: Long
    37     val parent: Option[Trace_Tree]
    32     val parent: Option[Trace_Tree]
    38     var hints: List[Simp_Trace_Item.Data]
    33     var hints: List[Simplifier_Trace.Item.Data]
    39     def set_interesting(): Unit
    34     def set_interesting(): Unit
    40   }
    35   }
    41 
    36 
    42   final class Root_Tree(val serial: Long) extends Trace_Tree
    37   final class Root_Tree(val serial: Long) extends Trace_Tree
    43   {
    38   {
    44     val parent = None
    39     val parent = None
    45     val hints = Nil
    40     val hints = Nil
    46     def hints_=(xs: List[Simp_Trace_Item.Data]) = throw new IllegalStateException("Root_Tree.hints")
    41     def hints_=(xs: List[Simplifier_Trace.Item.Data]) =
       
    42       throw new IllegalStateException("Root_Tree.hints")
    47     def set_interesting() = ()
    43     def set_interesting() = ()
    48 
    44 
    49     def format(regex: Option[Regex]): XML.Body =
    45     def format(regex: Option[Regex]): XML.Body =
    50       Pretty.separate(children.values.map(_.format(regex)._2)(collection.breakOut))
    46       Pretty.separate(children.values.map(_.format(regex)._2)(collection.breakOut))
    51   }
    47   }
    52 
    48 
    53   final class Elem_Tree(data: Simp_Trace_Item.Data, val parent: Option[Trace_Tree]) extends Trace_Tree
    49   final class Elem_Tree(data: Simplifier_Trace.Item.Data, val parent: Option[Trace_Tree])
       
    50     extends Trace_Tree
    54   {
    51   {
    55     val serial = data.serial
    52     val serial = data.serial
    56     var hints = List.empty[Simp_Trace_Item.Data]
    53     var hints = List.empty[Simplifier_Trace.Item.Data]
    57     var interesting: Boolean = false
    54     var interesting: Boolean = false
    58 
    55 
    59     def set_interesting(): Unit =
    56     def set_interesting(): Unit =
    60       if (!interesting)
    57       if (!interesting)
    61       {
    58       {
    74           None
    71           None
    75         case (true, res) =>
    72         case (true, res) =>
    76           Some(XML.Elem(Markup(Markup.ITEM, Nil), List(res)))
    73           Some(XML.Elem(Markup(Markup.ITEM, Nil), List(res)))
    77       }
    74       }
    78 
    75 
    79       def format_hint(data: Simp_Trace_Item.Data): XML.Tree =
    76       def format_hint(data: Simplifier_Trace.Item.Data): XML.Tree =
    80         Pretty.block(Pretty.separate(
    77         Pretty.block(Pretty.separate(
    81           XML.Text(data.text) ::
    78           XML.Text(data.text) ::
    82           data.content
    79           data.content
    83         ))
    80         ))
    84 
    81 
   109       (eligible || children_bodies != Nil, res)
   106       (eligible || children_bodies != Nil, res)
   110     }
   107     }
   111   }
   108   }
   112 
   109 
   113   @tailrec
   110   @tailrec
   114   def walk_trace(rest: List[Simp_Trace_Item.Data], lookup: Map[Long, Trace_Tree]): Unit =
   111   def walk_trace(rest: List[Simplifier_Trace.Item.Data], lookup: Map[Long, Trace_Tree]): Unit =
   115     rest match {
   112     rest match {
   116       case Nil =>
   113       case Nil =>
   117         ()
   114         ()
   118       case head :: tail =>
   115       case head :: tail =>
   119         lookup.get(head.parent) match {
   116         lookup.get(head.parent) match {
   120           case Some(parent) =>
   117           case Some(parent) =>
   121             if (head.markup == Simp_Trace_Item.HINT)
   118             if (head.markup == Markup.SIMP_TRACE_HINT)
   122             {
   119             {
   123               parent.hints ::= head
   120               parent.hints ::= head
   124               walk_trace(tail, lookup)
   121               walk_trace(tail, lookup)
   125             }
   122             }
   126             else if (head.markup == Simp_Trace_Item.IGNORE)
   123             else if (head.markup == Markup.SIMP_TRACE_IGNORE)
   127             {
   124             {
   128               parent.parent match {
   125               parent.parent match {
   129                 case None =>
   126                 case None =>
   130                   System.err.println("Simplifier_Trace_Window: malformed ignore message with parent " + head.parent)
   127                   System.err.println("Simplifier_Trace_Window: malformed ignore message with parent " + head.parent)
   131                 case Some(tree) =>
   128                 case Some(tree) =>
   135             }
   132             }
   136             else
   133             else
   137             {
   134             {
   138               val entry = new Elem_Tree(head, Some(parent))
   135               val entry = new Elem_Tree(head, Some(parent))
   139               parent.children += ((head.serial, entry))
   136               parent.children += ((head.serial, entry))
   140               if (head.markup == Simp_Trace_Item.STEP || head.markup == Simp_Trace_Item.LOG)
   137               if (head.markup == Markup.SIMP_TRACE_STEP || head.markup == Markup.SIMP_TRACE_LOG)
   141                 entry.set_interesting()
   138                 entry.set_interesting()
   142               walk_trace(tail, lookup + (head.serial -> entry))
   139               walk_trace(tail, lookup + (head.serial -> entry))
   143             }
   140             }
   144 
   141 
   145           case None =>
   142           case None =>