From d072e8727f330216eb322f448ef14317ea24cc90 Mon Sep 17 00:00:00 2001 From: Philippe Suter <philippe.suter@gmail.com> Date: Tue, 18 May 2010 20:36:29 +0000 Subject: [PATCH] some changes on case classes --- ParseMe.scala | 4 ++++ src/funcheck/CodeExtraction.scala | 14 +++++++------ src/funcheck/Extractors.scala | 34 ++++++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/ParseMe.scala b/ParseMe.scala index c7f6dda03..62be61d75 100644 --- a/ParseMe.scala +++ b/ParseMe.scala @@ -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 } diff --git a/src/funcheck/CodeExtraction.scala b/src/funcheck/CodeExtraction.scala index 5cba1395e..fa6752e09 100644 --- a/src/funcheck/CodeExtraction.scala +++ b/src/funcheck/CodeExtraction.scala @@ -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 } diff --git a/src/funcheck/Extractors.scala b/src/funcheck/Extractors.scala index ae48a4976..d6041e3c7 100644 --- a/src/funcheck/Extractors.scala +++ b/src/funcheck/Extractors.scala @@ -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 { -- GitLab