Skip to content
Snippets Groups Projects
Commit d072e872 authored by Philippe Suter's avatar Philippe Suter
Browse files

some changes on case classes

parent 6e755bdd
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,10 @@ import scala.collection.immutable.Set
object ParseMe {
sealed abstract class Tree
case class Node(left: Tree, value: Int, right: Tree) extends Tree
case class Leaf() extends Tree
def fromSet(i: Set[Set[Boolean]]) : Int = {
5
}
......
......@@ -68,22 +68,24 @@ trait CodeExtraction extends Extractors {
var objectDefs: List[ObjectDef] = Nil
var funDefs: List[FunDef] = Nil
tmpl.body.foreach(tree => {
//println("[[[ " + tree + "]]]\n");
tree match {
tmpl.body.foreach(
_ match {
case ExCaseClassSyntheticJunk() => ;
case ExObjectDef(o2, t2) => { objectDefs = extractObjectDef(o2, t2) :: objectDefs }
case ExAbstractClass(o2) => ;
case ExAbstractClass(o2) => println("That seems to be an abstract class: [[" + o2 + "]]")
case ExCaseClass(o2) => println(o2)
case ExConstructorDef() => ;
case ExMainFunctionDef() => ;
case ExFunctionDef(n,p,t,b) => { funDefs = extractFunDef(n,p,t,b) :: funDefs }
case _ => ;
}})
case tree => { println("Something else: "); println("[[[ " + tree + "]]]\n") }
})
// val theSym = new purescala.Symbols.ObjectSymbol(name, classSyms.reverse, objectSyms.reverse)
// we register the tree associated to the symbol to be able to fill in
// the rest later
// symbolDefMap(theSym) = tmpl
val theDef = new ObjectDef(name, objectDefs.reverse ::: classDefs.reverse ::: funDefs.reverse, Nil)
theDef
}
......
......@@ -54,7 +54,7 @@ trait Extractors {
* visibility. Does not match on the automatically generated companion
* objects of case classes (or any synthetic class). */
def unapply(cd: ClassDef): Option[(String,Template)] = cd match {
case ClassDef(_, name, tparams, impl) if (cd.symbol.isModuleClass && tparams.isEmpty && !cd.symbol.hasFlag(symtab.Flags.SYNTHETIC)) => {
case ClassDef(_, name, tparams, impl) if (cd.symbol.isModuleClass && tparams.isEmpty && !cd.symbol.isSynthetic) => {
Some((name.toString, impl))
}
case _ => None
......@@ -66,16 +66,40 @@ trait Extractors {
* constrctor args (in the case of a class), no implementation details,
* no abstract members. */
def unapply(cd: ClassDef): Option[(String)] = cd match {
case ClassDef(_, name, tparams, impl) if (cd.symbol.isTrait && tparams.isEmpty && impl.body.length == 2) => {
println(name + " seems to be a cool trait")
Some(name.toString)
}
// trait
// case ClassDef(_, name, tparams, impl) if (cd.symbol.isTrait && tparams.isEmpty && impl.body.isEmpty) => Some(name.toString)
// abstract class
case ClassDef(_, name, tparams, impl) if (cd.symbol.isAbstractClass && tparams.isEmpty && impl.body.size == 1) => Some(name.toString)
case _ => None
}
}
object ExCaseClass {
def unapply(cd: ClassDef): Option[(String)] = cd match {
case ClassDef(_, name, tparams, impl) if (cd.symbol.isCase && !cd.symbol.isAbstractClass && tparams.isEmpty && impl.body.size >= 8) => {
println("I think I have something here")
println(impl.body.size)
cd.symbol.tpe match {
case ClassInfoType(prts, decls, cls) => {
println("## " + prts)
println("## " + decls)
println("## " + cls)
}
case _ => ;
}
Some(name.toString)
}
case _ => None
}
}
object ExCaseClassSyntheticJunk {
def unapply(cd: ClassDef): Boolean = cd match {
case ClassDef(_, _, _, _) if (cd.symbol.isSynthetic && cd.symbol.isFinal) => true
case _ => false
}
}
object ExConstructorDef {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment