--- /dev/null
+package ofc.generators
+
+import ofc.parser
+import ofc.InvalidInputException
+import scala.collection.mutable.HashMap
+import scala.reflect.Manifest
+import scala.reflect.Manifest.singleType
+
+trait Matrix
+trait FunctionSet
+trait Index
+
+class Dictionary {
+ var matrices = new HashMap[parser.Identifier, Matrix]
+ var functionSets = new HashMap[parser.Identifier, FunctionSet]
+ var indices = new HashMap[parser.Identifier, Index]
+}
+
+class Onetep extends Generator {
+ def acceptInput(program : List[parser.Statement]) = {
+ println(program.mkString("\n") + "\n")
+ buildDictionary(program)
+ }
+
+ def filterStatements[T <: parser.Statement](statements : List[parser.Statement])(implicit m: Manifest[T]) =
+ statements.foldLeft(Nil : List[T])((list, item) => item match {
+ case s if (singleType(s) <:< m) => s.asInstanceOf[T] :: list
+ case _ => list
+ })
+
+ def getDeclarations(statements : List[parser.Statement]) : Map[parser.Identifier, parser.OFLType] = {
+ def getMappings(dl : parser.DeclarationList) =
+ for (name <- dl.names) yield
+ (name, dl.oflType)
+
+ filterStatements[parser.DeclarationList](statements).flatMap(getMappings(_)).toMap
+ }
+
+ def buildMatrix(id: parser.Identifier, call : Option[parser.FunctionCall]) = {
+ println(id + " " + call)
+ }
+
+ def buildFunctionSet(id: parser.Identifier, call : Option[parser.FunctionCall]) = {
+ println(id + " " + call)
+ }
+
+ def buildIndex(id: parser.Identifier, call : Option[parser.FunctionCall]) = {
+ println(id + " " + call)
+ }
+
+ def buildDictionary(statements : List[parser.Statement]) {
+ val targetDeclarations = filterStatements[parser.TargetAssignment](statements)
+ val declarations = getDeclarations(statements)
+
+ for(d <- declarations) {
+
+ // Find corresponding target-specific declaration if it exists.
+ val targetDeclarationCall = targetDeclarations.filter(_.id == d._1) match {
+ case List(x) => Some(x.value)
+ case List(_,_,_*) => throw new InvalidInputException("Invalid multiple target declarations for symbol " + d._1 + ".")
+ case Nil => None
+ }
+
+ d match {
+ case (id, parser.Matrix()) => buildMatrix(id, targetDeclarationCall)
+ case (id, parser.FunctionSet()) => buildFunctionSet(id, targetDeclarationCall)
+ case (id, parser.Index()) => buildIndex(id, targetDeclarationCall)
+ }
+ }
+ }
+}