diff --git a/src/funcheck/CodeExtraction.scala b/src/funcheck/CodeExtraction.scala index c63e61cd43709e0ffc9fd76d82fd2839ac94c5e0..1b07c9f9717a2ff7c67f33048e5b1e949f797507 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 078ef10b1a75f0a65f26fb3299558cdaa549ede0..c950db3625493d60f94f5d1ad190f2f00a6f0115 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 }