src/Pure/Thy/export_theory.scala
changeset 68726 782d6b89fb19
parent 68718 ce18a3924864
child 68830 44ec6fdaacf8
equal deleted inserted replaced
68725:367e60d9aa1b 68726:782d6b89fb19
    64   val export_prefix: String = "theory/"
    64   val export_prefix: String = "theory/"
    65 
    65 
    66   sealed case class Theory(name: String, parents: List[String],
    66   sealed case class Theory(name: String, parents: List[String],
    67     types: List[Type],
    67     types: List[Type],
    68     consts: List[Const],
    68     consts: List[Const],
    69     axioms: List[Axiom],
    69     axioms: List[Fact_Single],
    70     facts: List[Fact],
    70     facts: List[Fact_Multi],
    71     classes: List[Class],
    71     classes: List[Class],
    72     typedefs: List[Typedef],
    72     typedefs: List[Typedef],
    73     classrel: List[Classrel],
    73     classrel: List[Classrel],
    74     arities: List[Arity])
    74     arities: List[Arity])
    75   {
    75   {
   225         }
   225         }
   226         Const(entity, args, typ, abbrev)
   226         Const(entity, args, typ, abbrev)
   227       })
   227       })
   228 
   228 
   229 
   229 
   230   /* axioms and facts */
   230   /* facts */
   231 
   231 
   232   def decode_props(body: XML.Body):
   232   sealed case class Prop(
   233     (List[(String, Term.Sort)], List[(String, Term.Typ)], List[Term.Term]) =
       
   234   {
       
   235     import XML.Decode._
       
   236     import Term_XML.Decode._
       
   237     triple(list(pair(string, sort)), list(pair(string, typ)), list(term))(body)
       
   238   }
       
   239 
       
   240   sealed case class Axiom(
       
   241     entity: Entity,
       
   242     typargs: List[(String, Term.Sort)],
   233     typargs: List[(String, Term.Sort)],
   243     args: List[(String, Term.Typ)],
   234     args: List[(String, Term.Typ)],
   244     prop: Term.Term)
   235     term: Term.Term)
   245   {
   236   {
   246     def cache(cache: Term.Cache): Axiom =
   237     def cache(cache: Term.Cache): Prop =
   247       Axiom(entity.cache(cache),
   238       Prop(
   248         typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
   239         typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
   249         args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
   240         args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
   250         cache.term(prop))
   241         cache.term(term))
   251   }
   242   }
   252 
   243 
   253   def read_axioms(provider: Export.Provider): List[Axiom] =
   244   def decode_prop(body: XML.Body): Prop =
       
   245   {
       
   246     val (typargs, args, t) =
       
   247     {
       
   248       import XML.Decode._
       
   249       import Term_XML.Decode._
       
   250       triple(list(pair(string, sort)), list(pair(string, typ)), term)(body)
       
   251     }
       
   252     Prop(typargs, args, t)
       
   253   }
       
   254 
       
   255   sealed case class Fact_Single(entity: Entity, prop: Prop)
       
   256   {
       
   257     def cache(cache: Term.Cache): Fact_Single =
       
   258       Fact_Single(entity.cache(cache), prop.cache(cache))
       
   259   }
       
   260 
       
   261   sealed case class Fact_Multi(entity: Entity, props: List[Prop])
       
   262   {
       
   263     def cache(cache: Term.Cache): Fact_Multi =
       
   264       Fact_Multi(entity.cache(cache), props.map(_.cache(cache)))
       
   265 
       
   266     def split: List[Fact_Single] =
       
   267       props match {
       
   268         case List(prop) => List(Fact_Single(entity, prop))
       
   269         case _ =>
       
   270           for ((prop, i) <- props.zipWithIndex)
       
   271           yield Fact_Single(entity.copy(name = entity.name + "(" + (i + 1) + ")"), prop)
       
   272       }
       
   273   }
       
   274 
       
   275   def read_axioms(provider: Export.Provider): List[Fact_Single] =
   254     provider.uncompressed_yxml(export_prefix + "axioms").map((tree: XML.Tree) =>
   276     provider.uncompressed_yxml(export_prefix + "axioms").map((tree: XML.Tree) =>
   255       {
   277       {
   256         val (entity, body) = decode_entity(Kind.AXIOM, tree)
   278         val (entity, body) = decode_entity(Kind.AXIOM, tree)
   257         val (typargs, args, List(prop)) = decode_props(body)
   279         val prop = decode_prop(body)
   258         Axiom(entity, typargs, args, prop)
   280         Fact_Single(entity, prop)
   259       })
   281       })
   260 
   282 
   261   sealed case class Fact(
   283   def read_facts(provider: Export.Provider): List[Fact_Multi] =
   262     entity: Entity,
       
   263     typargs: List[(String, Term.Sort)],
       
   264     args: List[(String, Term.Typ)],
       
   265     props: List[Term.Term])
       
   266   {
       
   267     def cache(cache: Term.Cache): Fact =
       
   268       Fact(entity.cache(cache),
       
   269         typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
       
   270         args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
       
   271         props.map(cache.term(_)))
       
   272   }
       
   273 
       
   274   def read_facts(provider: Export.Provider): List[Fact] =
       
   275     provider.uncompressed_yxml(export_prefix + "facts").map((tree: XML.Tree) =>
   284     provider.uncompressed_yxml(export_prefix + "facts").map((tree: XML.Tree) =>
   276       {
   285       {
   277         val (entity, body) = decode_entity(Kind.FACT, tree)
   286         val (entity, body) = decode_entity(Kind.FACT, tree)
   278         val (typargs, args, props) = decode_props(body)
   287         val props = XML.Decode.list(decode_prop)(body)
   279         Fact(entity, typargs, args, props)
   288         Fact_Multi(entity, props)
   280       })
   289       })
   281 
   290 
   282 
   291 
   283   /* type classes */
   292   /* type classes */
   284 
   293