Skip to content
Snippets Groups Projects
Commit 8a5336b2 authored by Philippe Suter's avatar Philippe Suter
Browse files

No commit message

No commit message
parent c480f00b
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment