src/Pure/Thy/thy_load.scala
author wenzelm
Fri Jul 20 22:29:25 2012 +0200 (2012-07-20)
changeset 48409 0d2114eb412a
parent 46938 cda018294515
child 48422 9613780a805b
permissions -rw-r--r--
more explicit java.io.{File => JFile};
     1 /*  Title:      Pure/Thy/thy_load.scala
     2     Author:     Makarius
     3 
     4 Primitives for loading theory files.
     5 */
     6 
     7 package isabelle
     8 
     9 
    10 import java.io.{File => JFile}
    11 
    12 
    13 
    14 class Thy_Load
    15 {
    16   /* loaded theories provided by prover */
    17 
    18   private var loaded_theories: Set[String] = Set()
    19 
    20   def register_thy(thy_name: String): Unit =
    21     synchronized { loaded_theories += thy_name }
    22 
    23   def is_loaded(thy_name: String): Boolean =
    24     synchronized { loaded_theories.contains(thy_name) }
    25 
    26 
    27   /* file-system operations */
    28 
    29   def append(dir: String, source_path: Path): String =
    30     (Path.explode(dir) + source_path).implode
    31 
    32   def read_header(name: Document.Node.Name): Thy_Header =
    33   {
    34     val file = new JFile(name.node)
    35     if (!file.exists || !file.isFile) error("No such file: " + quote(file.toString))
    36     Thy_Header.read(file)
    37   }
    38 
    39 
    40   /* theory files */
    41 
    42   def thy_path(path: Path): Path = path.ext("thy")
    43 
    44   private def import_name(dir: String, s: String): Document.Node.Name =
    45   {
    46     val theory = Thy_Header.base_name(s)
    47     if (is_loaded(theory)) Document.Node.Name(theory, "", theory)
    48     else {
    49       val path = Path.explode(s)
    50       val node = append(dir, thy_path(path))
    51       val dir1 = append(dir, path.dir)
    52       Document.Node.Name(node, dir1, theory)
    53     }
    54   }
    55 
    56   def check_header(name: Document.Node.Name, header: Thy_Header): Document.Node.Deps =
    57   {
    58     val name1 = header.name
    59     val imports = header.imports.map(import_name(name.dir, _))
    60     // FIXME val uses = header.uses.map(p => (append(name.dir, Path.explode(p._1)), p._2))
    61     val uses = header.uses
    62     if (name.theory != name1)
    63       error("Bad file name " + thy_path(Path.basic(name.theory)) + " for theory " + quote(name1))
    64     Document.Node.Deps(imports, header.keywords, uses)
    65   }
    66 
    67   def check_thy(name: Document.Node.Name): Document.Node.Deps =
    68     check_header(name, read_header(name))
    69 }
    70