1 /* Title: Pure/Thy/thy_info.scala
4 Theory and file dependencies.
12 /* protocol messages */
14 object Loaded_Theory {
15 def unapply(msg: XML.Tree): Option[String] =
17 case XML.Elem(Markup(Markup.LOADED_THEORY, List((Markup.NAME, name))), _) => Some(name)
24 class Thy_Info(thy_load: Thy_Load)
28 private def show_path(names: List[String]): String =
29 names.map(quote).mkString(" via ")
31 private def cycle_msg(names: List[String]): String =
32 "Cyclic dependency of " + show_path(names)
34 private def required_by(s: String, initiators: List[String]): String =
35 if (initiators.isEmpty) ""
36 else s + "(required by " + show_path(initiators.reverse) + ")"
41 type Deps = Map[String, Document.Node_Header]
43 private def require_thys(initiators: List[String],
44 deps: Deps, thys: List[(String, String)]): Deps =
45 (deps /: thys)(require_thy(initiators, _, _))
47 private def require_thy(initiators: List[String], deps: Deps, thy: (String, String)): Deps =
50 val path = Path.explode(str)
51 val thy_name = path.base.implode
52 val node_name = thy_load.append(dir, Thy_Header.thy_path(path))
54 if (deps.isDefinedAt(node_name) || thy_load.is_loaded(thy_name)) deps
56 val dir1 = thy_load.append(dir, path.dir)
58 if (initiators.contains(node_name)) error(cycle_msg(initiators))
60 try { thy_load.check_thy(node_name) }
63 cat_error(msg, "The error(s) above occurred while examining theory file " +
64 quote(node_name) + required_by("\n", initiators))
66 val thys = header.imports.map(str => (dir1, str))
67 require_thys(node_name :: initiators, deps + (node_name -> Exn.Res(header)), thys)
69 catch { case e: Throwable => deps + (node_name -> Exn.Exn(e)) }
73 def dependencies(thys: List[(String, String)]): Deps =
74 require_thys(Nil, Map.empty, thys)