src/Pure/Thy/export_theory.scala
author wenzelm
Fri, 31 Aug 2018 15:48:37 +0200
changeset 68862 47e9912c53c3
parent 68835 2e59da922630
child 68864 1dacce27bc25
permissions -rw-r--r--
export locale content; read_theory_names: proper classrel, arities; tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Thy/export_theory.scala
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     3
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     4
Export foundational theory content.
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     5
*/
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     6
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     7
package isabelle
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     8
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     9
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    10
object Export_Theory
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    11
{
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    12
  /** session content **/
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    13
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    14
  sealed case class Session(name: String, theory_graph: Graph[String, Theory])
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    15
  {
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    16
    override def toString: String = name
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    17
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    18
    def theory(theory_name: String): Theory =
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    19
      if (theory_graph.defined(theory_name)) theory_graph.get_node(theory_name)
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    20
      else error("Bad theory " + quote(theory_name))
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    21
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    22
    def theories: List[Theory] =
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    23
      theory_graph.topological_order.map(theory_graph.get_node(_))
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    24
  }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    25
68209
aeffd8f1f079 support Store with options;
wenzelm
parents: 68208
diff changeset
    26
  def read_session(store: Sessions.Store,
aeffd8f1f079 support Store with options;
wenzelm
parents: 68208
diff changeset
    27
    session_name: String,
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    28
    types: Boolean = true,
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
    29
    consts: Boolean = true,
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
    30
    axioms: Boolean = true,
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
    31
    facts: Boolean = true,
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
    32
    classes: Boolean = true,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    33
    locales: Boolean = true,
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
    34
    classrel: Boolean = true,
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
    35
    arities: Boolean = true,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    36
    typedefs: Boolean = true,
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    37
    cache: Term.Cache = Term.make_cache()): Session =
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    38
  {
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    39
    val thys =
68210
65f79c0ddb0d tuned signature;
wenzelm
parents: 68209
diff changeset
    40
      using(store.open_database(session_name))(db =>
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    41
      {
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    42
        db.transaction {
68222
3c1a716e7f59 tuned queries;
wenzelm
parents: 68210
diff changeset
    43
          Export.read_theory_names(db, session_name).map((theory_name: String) =>
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
    44
            read_theory(Export.Provider.database(db, session_name, theory_name),
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
    45
              session_name, theory_name, types = types, consts = consts,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    46
              axioms = axioms, facts = facts, classes = classes, locales = locales,
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    47
              classrel = classrel, arities = arities, typedefs = typedefs,
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    48
              cache = Some(cache)))
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    49
        }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    50
      })
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    51
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    52
    val graph0 =
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    53
      (Graph.string[Theory] /: thys) { case (g, thy) => g.new_node(thy.name, thy) }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    54
    val graph1 =
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    55
      (graph0 /: thys) { case (g0, thy) =>
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    56
        (g0 /: thy.parents) { case (g1, parent) =>
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    57
          g1.default_node(parent, empty_theory(parent)).add_edge_acyclic(parent, thy.name) } }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    58
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    59
    Session(session_name, graph1)
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    60
  }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    61
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    62
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    63
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
    64
  /** theory content **/
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
    65
68346
b44010800a19 tuned signature;
wenzelm
parents: 68295
diff changeset
    66
  val export_prefix: String = "theory/"
b44010800a19 tuned signature;
wenzelm
parents: 68295
diff changeset
    67
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
    68
  sealed case class Theory(name: String, parents: List[String],
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
    69
    types: List[Type],
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
    70
    consts: List[Const],
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
    71
    axioms: List[Fact_Single],
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
    72
    facts: List[Fact_Multi],
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
    73
    classes: List[Class],
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    74
    locales: List[Locale],
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
    75
    classrel: List[Classrel],
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    76
    arities: List[Arity],
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    77
    typedefs: List[Typedef])
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    78
  {
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    79
    override def toString: String = name
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    80
68711
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    81
    lazy val entities: Set[Long] =
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    82
      Set.empty[Long] ++
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    83
        types.iterator.map(_.entity.serial) ++
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    84
        consts.iterator.map(_.entity.serial) ++
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    85
        axioms.iterator.map(_.entity.serial) ++
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    86
        facts.iterator.map(_.entity.serial) ++
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    87
        classes.iterator.map(_.entity.serial) ++
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    88
        locales.iterator.map(_.entity.serial)
68711
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    89
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    90
    def cache(cache: Term.Cache): Theory =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    91
      Theory(cache.string(name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    92
        parents.map(cache.string(_)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    93
        types.map(_.cache(cache)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    94
        consts.map(_.cache(cache)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    95
        axioms.map(_.cache(cache)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    96
        facts.map(_.cache(cache)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    97
        classes.map(_.cache(cache)),
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    98
        locales.map(_.cache(cache)),
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
    99
        classrel.map(_.cache(cache)),
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   100
        arities.map(_.cache(cache)),
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   101
        typedefs.map(_.cache(cache)))
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   102
  }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   103
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   104
  def empty_theory(name: String): Theory =
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   105
    Theory(name, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil)
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   106
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   107
  def read_theory(provider: Export.Provider, session_name: String, theory_name: String,
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   108
    types: Boolean = true,
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   109
    consts: Boolean = true,
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   110
    axioms: Boolean = true,
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   111
    facts: Boolean = true,
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   112
    classes: Boolean = true,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   113
    locales: Boolean = true,
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   114
    classrel: Boolean = true,
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   115
    arities: Boolean = true,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   116
    typedefs: Boolean = true,
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   117
    cache: Option[Term.Cache] = None): Theory =
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   118
  {
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   119
    val parents =
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   120
      provider(export_prefix + "parents") match {
68231
0004e7a9fa10 clarified encoding;
wenzelm
parents: 68222
diff changeset
   121
        case Some(entry) => split_lines(entry.uncompressed().text)
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   122
        case None =>
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   123
          error("Missing theory export in session " + quote(session_name) + ": " +
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   124
            quote(theory_name))
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   125
      }
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   126
    val theory =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   127
      Theory(theory_name, parents,
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   128
        if (types) read_types(provider) else Nil,
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   129
        if (consts) read_consts(provider) else Nil,
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   130
        if (axioms) read_axioms(provider) else Nil,
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   131
        if (facts) read_facts(provider) else Nil,
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   132
        if (classes) read_classes(provider) else Nil,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   133
        if (locales) read_locales(provider) else Nil,
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   134
        if (classrel) read_classrel(provider) else Nil,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   135
        if (arities) read_arities(provider) else Nil,
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   136
        if (typedefs) read_typedefs(provider) else Nil)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   137
    if (cache.isDefined) theory.cache(cache.get) else theory
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   138
  }
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   139
68711
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
   140
  def read_pure_theory(store: Sessions.Store, cache: Option[Term.Cache] = None): Theory =
68710
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   141
  {
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   142
    val session_name = Thy_Header.PURE
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   143
    val theory_name = Thy_Header.PURE
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   144
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   145
    using(store.open_database(session_name))(db =>
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   146
    {
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   147
      db.transaction {
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   148
        read_theory(Export.Provider.database(db, session_name, theory_name),
68711
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
   149
          session_name, theory_name, cache = cache)
68710
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   150
      }
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   151
    })
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   152
  }
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   153
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   154
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   155
  /* entities */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   156
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   157
  object Kind extends Enumeration
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   158
  {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   159
    val TYPE = Value("type")
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   160
    val CONST = Value("const")
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   161
    val AXIOM = Value("axiom")
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   162
    val FACT = Value("fact")
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   163
    val CLASS = Value("class")
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   164
    val LOCALE = Value("locale")
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   165
  }
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   166
68835
2e59da922630 more robust: Pure entities may lack id;
wenzelm
parents: 68830
diff changeset
   167
  sealed case class Entity(
2e59da922630 more robust: Pure entities may lack id;
wenzelm
parents: 68830
diff changeset
   168
    kind: Kind.Value, name: String, pos: Position.T, id: Option[Long], serial: Long)
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   169
  {
68718
ce18a3924864 tuned output;
wenzelm
parents: 68717
diff changeset
   170
    override def toString: String = kind.toString + " " + quote(name)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   171
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   172
    def cache(cache: Term.Cache): Entity =
68830
44ec6fdaacf8 retain original id, which is command_id/exec_id for PIDE;
wenzelm
parents: 68726
diff changeset
   173
      Entity(kind, cache.string(name), cache.position(pos), id, serial)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   174
  }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   175
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   176
  def decode_entity(kind: Kind.Value, tree: XML.Tree): (Entity, XML.Body) =
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   177
  {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   178
    def err(): Nothing = throw new XML.XML_Body(List(tree))
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   179
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   180
    tree match {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   181
      case XML.Elem(Markup(Markup.ENTITY, props), body) =>
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   182
        val name = Markup.Name.unapply(props) getOrElse err()
68830
44ec6fdaacf8 retain original id, which is command_id/exec_id for PIDE;
wenzelm
parents: 68726
diff changeset
   183
        val pos = props.filter({ case (a, _) => Markup.POSITION_PROPERTIES(a) && a != Markup.ID })
68835
2e59da922630 more robust: Pure entities may lack id;
wenzelm
parents: 68830
diff changeset
   184
        val id = Position.Id.unapply(props)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   185
        val serial = Markup.Serial.unapply(props) getOrElse err()
68830
44ec6fdaacf8 retain original id, which is command_id/exec_id for PIDE;
wenzelm
parents: 68726
diff changeset
   186
        (Entity(kind, name, pos, id, serial), body)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   187
      case _ => err()
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   188
    }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   189
  }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   190
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   191
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   192
  /* types */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   193
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   194
  sealed case class Type(entity: Entity, args: List[String], abbrev: Option[Term.Typ])
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   195
  {
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   196
    def cache(cache: Term.Cache): Type =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   197
      Type(entity.cache(cache),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   198
        args.map(cache.string(_)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   199
        abbrev.map(cache.typ(_)))
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   200
  }
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   201
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   202
  def read_types(provider: Export.Provider): List[Type] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   203
    provider.uncompressed_yxml(export_prefix + "types").map((tree: XML.Tree) =>
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   204
      {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   205
        val (entity, body) = decode_entity(Kind.TYPE, tree)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   206
        val (args, abbrev) =
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   207
        {
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   208
          import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   209
          pair(list(string), option(Term_XML.Decode.typ))(body)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   210
        }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   211
        Type(entity, args, abbrev)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   212
      })
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   213
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   214
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   215
  /* consts */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   216
68173
7ed88a534bb6 more uniform types vs. consts;
wenzelm
parents: 68172
diff changeset
   217
  sealed case class Const(
7ed88a534bb6 more uniform types vs. consts;
wenzelm
parents: 68172
diff changeset
   218
    entity: Entity, typargs: List[String], typ: Term.Typ, abbrev: Option[Term.Term])
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   219
  {
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   220
    def cache(cache: Term.Cache): Const =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   221
      Const(entity.cache(cache),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   222
        typargs.map(cache.string(_)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   223
        cache.typ(typ),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   224
        abbrev.map(cache.term(_)))
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   225
  }
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   226
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   227
  def read_consts(provider: Export.Provider): List[Const] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   228
    provider.uncompressed_yxml(export_prefix + "consts").map((tree: XML.Tree) =>
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   229
      {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   230
        val (entity, body) = decode_entity(Kind.CONST, tree)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   231
        val (args, typ, abbrev) =
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   232
        {
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   233
          import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   234
          triple(list(string), Term_XML.Decode.typ, option(Term_XML.Decode.term))(body)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   235
        }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   236
        Const(entity, args, typ, abbrev)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   237
      })
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   238
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   239
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   240
  /* facts */
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   241
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   242
  sealed case class Prop(
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   243
    typargs: List[(String, Term.Sort)],
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   244
    args: List[(String, Term.Typ)],
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   245
    term: Term.Term)
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   246
  {
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   247
    def cache(cache: Term.Cache): Prop =
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   248
      Prop(
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   249
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   250
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   251
        cache.term(term))
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   252
  }
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   253
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   254
  def decode_prop(body: XML.Body): Prop =
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   255
  {
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   256
    val (typargs, args, t) =
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   257
    {
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   258
      import XML.Decode._
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   259
      import Term_XML.Decode._
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   260
      triple(list(pair(string, sort)), list(pair(string, typ)), term)(body)
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   261
    }
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   262
    Prop(typargs, args, t)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   263
  }
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   264
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   265
  sealed case class Fact_Single(entity: Entity, prop: Prop)
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   266
  {
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   267
    def cache(cache: Term.Cache): Fact_Single =
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   268
      Fact_Single(entity.cache(cache), prop.cache(cache))
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   269
  }
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   270
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   271
  sealed case class Fact_Multi(entity: Entity, props: List[Prop])
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   272
  {
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   273
    def cache(cache: Term.Cache): Fact_Multi =
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   274
      Fact_Multi(entity.cache(cache), props.map(_.cache(cache)))
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   275
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   276
    def split: List[Fact_Single] =
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   277
      props match {
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   278
        case List(prop) => List(Fact_Single(entity, prop))
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   279
        case _ =>
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   280
          for ((prop, i) <- props.zipWithIndex)
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   281
          yield Fact_Single(entity.copy(name = entity.name + "(" + (i + 1) + ")"), prop)
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   282
      }
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   283
  }
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   284
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   285
  def read_axioms(provider: Export.Provider): List[Fact_Single] =
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   286
    provider.uncompressed_yxml(export_prefix + "axioms").map((tree: XML.Tree) =>
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   287
      {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   288
        val (entity, body) = decode_entity(Kind.AXIOM, tree)
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   289
        val prop = decode_prop(body)
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   290
        Fact_Single(entity, prop)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   291
      })
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   292
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   293
  def read_facts(provider: Export.Provider): List[Fact_Multi] =
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   294
    provider.uncompressed_yxml(export_prefix + "facts").map((tree: XML.Tree) =>
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   295
      {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   296
        val (entity, body) = decode_entity(Kind.FACT, tree)
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   297
        val props = XML.Decode.list(decode_prop)(body)
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   298
        Fact_Multi(entity, props)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   299
      })
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   300
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   301
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   302
  /* type classes */
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   303
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   304
  sealed case class Class(
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   305
    entity: Entity, params: List[(String, Term.Typ)], axioms: List[Term.Term])
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   306
  {
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   307
    def cache(cache: Term.Cache): Class =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   308
      Class(entity.cache(cache),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   309
        params.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   310
        axioms.map(cache.term(_)))
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   311
  }
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   312
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   313
  def read_classes(provider: Export.Provider): List[Class] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   314
    provider.uncompressed_yxml(export_prefix + "classes").map((tree: XML.Tree) =>
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   315
      {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   316
        val (entity, body) = decode_entity(Kind.CLASS, tree)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   317
        val (params, axioms) =
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   318
        {
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   319
          import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   320
          import Term_XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   321
          pair(list(pair(string, typ)), list(term))(body)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   322
        }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   323
        Class(entity, params, axioms)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   324
      })
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   325
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   326
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   327
  /* locales */
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   328
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   329
  sealed case class Locale(
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   330
    entity: Entity, type_params: List[(String, Term.Sort)], params: List[(String, Term.Typ)],
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   331
      asm: Option[Term.Term], defs: List[Term.Term])
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   332
  {
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   333
    def cache(cache: Term.Cache): Locale =
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   334
      Locale(entity.cache(cache),
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   335
        type_params.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   336
        params.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   337
        asm.map(cache.term(_)),
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   338
        defs.map(cache.term(_)))
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   339
  }
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   340
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   341
  def read_locales(provider: Export.Provider): List[Locale] =
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   342
    provider.uncompressed_yxml(export_prefix + "locales").map((tree: XML.Tree) =>
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   343
      {
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   344
        val (entity, body) = decode_entity(Kind.LOCALE, tree)
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   345
        val (type_params, (params, (asm, defs))) =
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   346
        {
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   347
          import XML.Decode._
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   348
          import Term_XML.Decode._
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   349
          pair(list(pair(string, sort)),
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   350
            pair(list(pair(string, typ)),
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   351
              pair(option(term), list(term))))(body)
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   352
        }
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   353
        Locale(entity, type_params, params, asm, defs)
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   354
      })
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   355
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   356
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   357
  /* sort algebra */
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   358
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   359
  sealed case class Classrel(class_name: String, super_names: List[String])
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   360
  {
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   361
    def cache(cache: Term.Cache): Classrel =
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   362
      Classrel(cache.string(class_name), super_names.map(cache.string(_)))
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   363
  }
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   364
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   365
  def read_classrel(provider: Export.Provider): List[Classrel] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   366
  {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   367
    val body = provider.uncompressed_yxml(export_prefix + "classrel")
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   368
    val classrel =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   369
    {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   370
      import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   371
      list(pair(string, list(string)))(body)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   372
    }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   373
    for ((c, cs) <- classrel) yield Classrel(c, cs)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   374
  }
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   375
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   376
  sealed case class Arity(type_name: String, domain: List[Term.Sort], codomain: String)
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   377
  {
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   378
    def cache(cache: Term.Cache): Arity =
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   379
      Arity(cache.string(type_name), domain.map(cache.sort(_)), cache.string(codomain))
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   380
  }
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   381
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   382
  def read_arities(provider: Export.Provider): List[Arity] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   383
  {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   384
    val body = provider.uncompressed_yxml(export_prefix + "arities")
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   385
    val arities =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   386
    {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   387
      import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   388
      import Term_XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   389
      list(triple(string, list(sort), string))(body)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   390
    }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   391
    for ((a, b, c) <- arities) yield Arity(a, b, c)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   392
  }
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   393
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   394
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   395
  /* HOL typedefs */
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   396
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   397
  sealed case class Typedef(name: String,
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   398
    rep_type: Term.Typ, abs_type: Term.Typ, rep_name: String, abs_name: String, axiom_name: String)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   399
  {
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   400
    def cache(cache: Term.Cache): Typedef =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   401
      Typedef(cache.string(name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   402
        cache.typ(rep_type),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   403
        cache.typ(abs_type),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   404
        cache.string(rep_name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   405
        cache.string(abs_name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   406
        cache.string(axiom_name))
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   407
  }
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   408
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   409
  def read_typedefs(provider: Export.Provider): List[Typedef] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   410
  {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   411
    val body = provider.uncompressed_yxml(export_prefix + "typedefs")
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   412
    val typedefs =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   413
    {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   414
      import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   415
      import Term_XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   416
      list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   417
    }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   418
    for { (name, (rep_type, (abs_type, (rep_name, (abs_name, axiom_name))))) <- typedefs }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   419
    yield Typedef(name, rep_type, abs_type, rep_name, abs_name, axiom_name)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   420
  }
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   421
}