From 70da94aff155570a8b455d79f4ae6735c62ec375 Mon Sep 17 00:00:00 2001
From: Philippe Suter <philippe.suter@gmail.com>
Date: Sat, 22 May 2010 23:39:43 +0000
Subject: [PATCH] stuff

---
 src/funcheck/CodeExtraction.scala | 29 +++++++++++++++++++++++++++--
 src/funcheck/Extractors.scala     | 21 +++------------------
 src/purescala/PrettyPrinter.scala |  2 +-
 3 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/src/funcheck/CodeExtraction.scala b/src/funcheck/CodeExtraction.scala
index 3fd4b0397..b9877ef63 100644
--- a/src/funcheck/CodeExtraction.scala
+++ b/src/funcheck/CodeExtraction.scala
@@ -83,12 +83,15 @@ trait CodeExtraction extends Extractors {
             scalaClassSyms += (sym -> o2)
             scalaClassNames += o2
           }
-          case ExCaseClass(o2, sym) => {
+          case ExCaseClass(o2, sym, tpl) => {
             if(scalaClassNames.contains(o2)) {
               unit.error(t.pos, "A class with the same name already exists.")
             }
             scalaClassSyms += (sym -> o2)
             scalaClassNames += o2
+            // println("***")
+            // println(tpl)
+            // println("***")
           }
           case _ => ;
         }
@@ -107,6 +110,28 @@ trait CodeExtraction extends Extractors {
           }
       })
 
+      classesToClasses.foreach(p => {
+        println(p._1)
+        val superC: List[ClassTypeDef] = p._1.tpe.baseClasses.filter(bcs => scalaClassSyms.exists(pp => pp._1 == bcs) && bcs != p._1).map(s => classesToClasses(s)).toList
+
+        val superAC: List[AbstractClassDef] = superC.map(c => {
+            if(!c.isInstanceOf[AbstractClassDef]) {
+                unit.error(p._1.pos, "Class is inheriting from non-abstract class.")
+                null
+            } else {
+                c.asInstanceOf[AbstractClassDef]
+            }
+        }).filter(_ != null)
+
+        if(superAC.length > 1) {
+            unit.error(p._1.pos, "Multiple inheritance.")
+        }
+
+        if(superAC.length == 1) {
+            p._2.parent = Some(superAC.head)
+        }
+      })
+
       // TODO
       // resolve all inheritance links (look at 
       // add all fields to case classes
@@ -118,7 +143,7 @@ trait CodeExtraction extends Extractors {
           case ExCaseClassSyntheticJunk() => ;
           case ExObjectDef(o2, t2) => { objectDefs = extractObjectDef(o2, t2) :: objectDefs }
           case ExAbstractClass(o2,sym) => ; //println("That seems to be an abstract class: [[" + o2  + "]]")
-          case ExCaseClass(o2,sym) => ; //println(o2)
+          case ExCaseClass(_,_,_) => ; //println(o2)
           case ExConstructorDef() => ;
           case ExMainFunctionDef() => ;
           case ExFunctionDef(n,p,t,b) => { funDefs = extractFunDef(n,p,t,b) :: funDefs }
diff --git a/src/funcheck/Extractors.scala b/src/funcheck/Extractors.scala
index 6d17be38a..b0e1c8d08 100644
--- a/src/funcheck/Extractors.scala
+++ b/src/funcheck/Extractors.scala
@@ -74,25 +74,10 @@ trait Extractors {
     }
 
     object ExCaseClass {
-      def unapply(cd: ClassDef): Option[(String,Symbol)] = cd match {
+      def unapply(cd: ClassDef): Option[(String,Symbol,Tree)] = 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")
-          // cd.symbol.tpe match {
-          //   case TypeRef(_, sym, Nil) => {
-          //     println("It's a typeref, of course")
-          //     println(sym.tpe)
-          //     println(debugString(sym.tpe))
-          //     println(sym.tpe.baseTypeSeq)
-          //     println(sym.tpe.baseClasses)
-          //   }
-          //   case ClassInfoType(prts, decls, cls) => {
-          //     println("## " + prts)
-          //     println("## " + decls)
-          //     println("## " + cls)
-          //   }
-          //   case _ => ;
-          // }
-          Some((name.toString, cd.symbol))
+          
+          Some((name.toString, cd.symbol, impl))
         }
         case _ => None
       }
diff --git a/src/purescala/PrettyPrinter.scala b/src/purescala/PrettyPrinter.scala
index a46028e52..597d11232 100644
--- a/src/purescala/PrettyPrinter.scala
+++ b/src/purescala/PrettyPrinter.scala
@@ -148,7 +148,7 @@ object PrettyPrinter {
         ind(nsb)
         nsb.append("sealed abstract class ")
         nsb.append(id)
-        parent.foreach(p => nsb.append("extends " + p.id + " "))
+        parent.foreach(p => nsb.append(" extends " + p.id))
         nsb
       }
 
-- 
GitLab