From 8a5336b21cd5fa6d4446e2d00411cc3401a5f9f5 Mon Sep 17 00:00:00 2001
From: Philippe Suter <philippe.suter@gmail.com>
Date: Wed, 17 Jun 2009 13:33:50 +0000
Subject: [PATCH]

---
 src/funcheck/CodeExtraction.scala    | 20 ++++++++++++++++++++
 src/funcheck/purescala/Symbols.scala | 10 +++++-----
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/src/funcheck/CodeExtraction.scala b/src/funcheck/CodeExtraction.scala
index c63e61cd4..1b07c9f97 100644
--- a/src/funcheck/CodeExtraction.scala
+++ b/src/funcheck/CodeExtraction.scala
@@ -7,6 +7,7 @@ import purescala.Definitions._
 import purescala.Trees._
 import purescala.TypeTrees._
 import purescala.Common._
+import purescala.Symbols._
 
 trait CodeExtraction extends Extractors {
   self: AnalysisComponent =>
@@ -16,6 +17,11 @@ trait CodeExtraction extends Extractors {
   import ExpressionExtractors._
 
   def extractCode(unit: CompilationUnit): Program = { 
+    import scala.collection.mutable.HashMap
+
+    // register where the symbols where extracted from
+    val symbolDefMap = new HashMap[Symbol,Tree]
+
     def s2ps(tree: Tree): Expr = toPureScala(unit)(tree) match {
       case Some(ex) => ex
       case None => stopIfErrors; throw new Error("unreachable")
@@ -38,6 +44,12 @@ trait CodeExtraction extends Extractors {
 //      case _ => ;
 //    }
 
+    /** Populates the symbolDefMap and returns the symbol corresponding to
+     * the expected single top-level object. */
+    def extractSymbols: ObjectSymbol = {
+      null
+    }
+
     def extractObject(name: Identifier, tmpl: Template): ObjectDef = {
       var funDefs: List[FunDef] = Nil
       var valDefs: List[ValDef] = Nil
@@ -84,6 +96,14 @@ trait CodeExtraction extends Extractors {
     // Extraction of the expressions.
 
 //    (new ForeachTreeTraverser(trav)).traverse(unit.body)
+
+    // Step-by-step algo:
+    // 1) extract class and object symbols (will already be nested)
+    // 2) extract function and val symbols (can now have a type, since we
+    //    have full class hierarchy)
+    // 3) extract val and function bodies (can do it, since we have all
+    //    definitions, hence we can resolve all symbols)
+
     stopIfErrors
 
     program.get
diff --git a/src/funcheck/purescala/Symbols.scala b/src/funcheck/purescala/Symbols.scala
index 078ef10b1..c950db362 100644
--- a/src/funcheck/purescala/Symbols.scala
+++ b/src/funcheck/purescala/Symbols.scala
@@ -3,23 +3,23 @@ package funcheck.purescala
 import Common._
 import TypeTrees._
 
+/** There's a need for symbols, as we have purely functional trees with
+ * potential recursive calls, and we want references to be resolved once and
+ * for all. */
 object Symbols {
   trait Symbolic {
     self =>
 
     private var __s: Option[Symbol] = None
 
-    def symbol: Symbol = __s.getOrElse(throw new Exception("Undefined symbol!"))
+    def symbol: Symbol = __s.getOrElse(throw new Exception("Undefined symbol."))
 
     def setSymbol(s: Symbol): self.type = __s match {
-      case Some(_) => throw new Exception("Symbol already set!")
+      case Some(_) => throw new Exception("Symbol already set.")
       case None => { __s = Some(s); this }
     }
   }
 
-  /** There's a need for symbols, as we have purely functional trees with
-   * potential recursive calls, and we want references to be resolved once
-   * and for all. */
   sealed abstract class Symbol {
     val id: Identifier
   }
-- 
GitLab