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 ...@@ -2,6 +2,10 @@ import scala.collection.immutable.Set
object ParseMe { 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 = { def fromSet(i: Set[Set[Boolean]]) : Int = {
5 5
} }
......
...@@ -68,22 +68,24 @@ trait CodeExtraction extends Extractors { ...@@ -68,22 +68,24 @@ trait CodeExtraction extends Extractors {
var objectDefs: List[ObjectDef] = Nil var objectDefs: List[ObjectDef] = Nil
var funDefs: List[FunDef] = Nil var funDefs: List[FunDef] = Nil
tmpl.body.foreach(tree => { tmpl.body.foreach(
//println("[[[ " + tree + "]]]\n"); _ match {
tree match { case ExCaseClassSyntheticJunk() => ;
case ExObjectDef(o2, t2) => { objectDefs = extractObjectDef(o2, t2) :: objectDefs } 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 ExConstructorDef() => ;
case ExMainFunctionDef() => ; case ExMainFunctionDef() => ;
case ExFunctionDef(n,p,t,b) => { funDefs = extractFunDef(n,p,t,b) :: funDefs } 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) // 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 // we register the tree associated to the symbol to be able to fill in
// the rest later // the rest later
// symbolDefMap(theSym) = tmpl // symbolDefMap(theSym) = tmpl
val theDef = new ObjectDef(name, objectDefs.reverse ::: classDefs.reverse ::: funDefs.reverse, Nil) val theDef = new ObjectDef(name, objectDefs.reverse ::: classDefs.reverse ::: funDefs.reverse, Nil)
theDef theDef
} }
......
...@@ -54,7 +54,7 @@ trait Extractors { ...@@ -54,7 +54,7 @@ trait Extractors {
* visibility. Does not match on the automatically generated companion * visibility. Does not match on the automatically generated companion
* objects of case classes (or any synthetic class). */ * objects of case classes (or any synthetic class). */
def unapply(cd: ClassDef): Option[(String,Template)] = cd match { 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)) Some((name.toString, impl))
} }
case _ => None case _ => None
...@@ -66,16 +66,40 @@ trait Extractors { ...@@ -66,16 +66,40 @@ trait Extractors {
* constrctor args (in the case of a class), no implementation details, * constrctor args (in the case of a class), no implementation details,
* no abstract members. */ * no abstract members. */
def unapply(cd: ClassDef): Option[(String)] = cd match { def unapply(cd: ClassDef): Option[(String)] = cd match {
case ClassDef(_, name, tparams, impl) if (cd.symbol.isTrait && tparams.isEmpty && impl.body.length == 2) => { // trait
println(name + " seems to be a cool trait") // case ClassDef(_, name, tparams, impl) if (cd.symbol.isTrait && tparams.isEmpty && impl.body.isEmpty) => Some(name.toString)
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 case _ => None
} }
} }
object ExCaseClass { 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 { object ExConstructorDef {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment