determine source dependencies, relatively to preloaded theories;
authorwenzelm
Sun, 22 Jul 2012 00:00:22 +0200
changeset 48422 9613780a805b
parent 48421 c4d337782de4
child 48423 0ccf143a2a69
determine source dependencies, relatively to preloaded theories; tuned signature;
src/Pure/ROOT
src/Pure/System/build.scala
src/Pure/System/session.scala
src/Pure/Thy/thy_load.scala
src/Tools/jEdit/src/jedit_thy_load.scala
--- a/src/Pure/ROOT	Sat Jul 21 22:13:50 2012 +0200
+++ b/src/Pure/ROOT	Sun Jul 22 00:00:22 2012 +0200
@@ -20,5 +20,6 @@
     "ML-Systems/use_context.ML"
 
 session Pure in "." =
+  theories Pure
   files "ROOT.ML"  (* FIXME *)
 
--- a/src/Pure/System/build.scala	Sat Jul 21 22:13:50 2012 +0200
+++ b/src/Pure/System/build.scala	Sun Jul 22 00:00:22 2012 +0200
@@ -97,8 +97,8 @@
         new Queue(keys1, graph1)
       }
 
-      def topological_order: List[(Key, Info)] =
-        graph.topological_order.map(key => (key, graph.get_node(key)))
+      def topological_order: List[(String, Info)] =
+        graph.topological_order.map(key => (key.name, graph.get_node(key)))
     }
   }
 
@@ -266,6 +266,44 @@
   }
 
 
+  /* dependencies */
+
+  sealed case class Node(
+    loaded_theories: Set[String],
+    sources: List[Path])
+
+  def dependencies(queue: Session.Queue): Map[String, Node] =
+    (Map.empty[String, Node] /: queue.topological_order)(
+      { case (deps, (name, info)) =>
+          val preloaded =
+            info.parent match {
+              case None => Set.empty[String]
+              case Some(parent) => deps(parent).loaded_theories
+            }
+          val thy_info = new Thy_Info(new Thy_Load(preloaded))
+
+          val thy_deps =
+            thy_info.dependencies(
+              info.theories.map(_._2).flatten.
+                map(thy => Document.Node.Name(info.dir + Thy_Load.thy_path(thy))))
+
+          val loaded_theories = preloaded ++ thy_deps.map(_._1.theory)
+          val sources =
+            thy_deps.map({ case (n, h) =>
+              val thy = Path.explode(n.node).expand
+              val uses =
+                h match {
+                  case Exn.Res(d) =>
+                    d.uses.map(p => (Path.explode(n.dir) + Path.explode(p._1)).expand)
+                  case _ => Nil
+                }
+              thy :: uses
+            }).flatten ::: info.files.map(file => info.dir + file)
+
+          deps + (name -> Node(loaded_theories, sources))
+      })
+
+
 
   /** build **/
 
@@ -350,10 +388,8 @@
 
     // run jobs
     val rcs =
-      for ((key, info) <- queue.topological_order) yield
+      for ((name, info) <- queue.topological_order) yield
       {
-        val name = key.name
-
         if (list_only) { echo(name + " in " + info.dir); 0 }
         else {
           val save = build_images || queue.is_inner(name)
--- a/src/Pure/System/session.scala	Sat Jul 21 22:13:50 2012 +0200
+++ b/src/Pure/System/session.scala	Sun Jul 22 00:00:22 2012 +0200
@@ -37,7 +37,7 @@
 }
 
 
-class Session(thy_load: Thy_Load = new Thy_Load)
+class Session(thy_load: Thy_Load = new Thy_Load())
 {
   /* global flags */
 
--- a/src/Pure/Thy/thy_load.scala	Sat Jul 21 22:13:50 2012 +0200
+++ b/src/Pure/Thy/thy_load.scala	Sun Jul 22 00:00:22 2012 +0200
@@ -10,12 +10,17 @@
 import java.io.{File => JFile}
 
 
+object Thy_Load
+{
+  def thy_path(path: Path): Path = path.ext("thy")
+}
 
-class Thy_Load
+
+class Thy_Load(preloaded: Set[String] = Set.empty)
 {
   /* loaded theories provided by prover */
 
-  private var loaded_theories: Set[String] = Set()
+  private var loaded_theories: Set[String] = preloaded
 
   def register_thy(thy_name: String): Unit =
     synchronized { loaded_theories += thy_name }
@@ -39,15 +44,13 @@
 
   /* theory files */
 
-  def thy_path(path: Path): Path = path.ext("thy")
-
   private def import_name(dir: String, s: String): Document.Node.Name =
   {
     val theory = Thy_Header.base_name(s)
     if (is_loaded(theory)) Document.Node.Name(theory, "", theory)
     else {
       val path = Path.explode(s)
-      val node = append(dir, thy_path(path))
+      val node = append(dir, Thy_Load.thy_path(path))
       val dir1 = append(dir, path.dir)
       Document.Node.Name(node, dir1, theory)
     }
@@ -60,7 +63,8 @@
     // FIXME val uses = header.uses.map(p => (append(name.dir, Path.explode(p._1)), p._2))
     val uses = header.uses
     if (name.theory != name1)
-      error("Bad file name " + thy_path(Path.basic(name.theory)) + " for theory " + quote(name1))
+      error("Bad file name " + Thy_Load.thy_path(Path.basic(name.theory)) +
+        " for theory " + quote(name1))
     Document.Node.Deps(imports, header.keywords, uses)
   }
 
--- a/src/Tools/jEdit/src/jedit_thy_load.scala	Sat Jul 21 22:13:50 2012 +0200
+++ b/src/Tools/jEdit/src/jedit_thy_load.scala	Sun Jul 22 00:00:22 2012 +0200
@@ -17,7 +17,7 @@
 import org.gjt.sp.jedit.View
 
 
-class JEdit_Thy_Load extends Thy_Load
+class JEdit_Thy_Load extends Thy_Load()
 {
   override def append(dir: String, source_path: Path): String =
   {