]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Add created variables to dictionary.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Wed, 4 Jan 2012 19:30:23 +0000 (19:30 +0000)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Wed, 4 Jan 2012 19:30:23 +0000 (19:30 +0000)
src/ofc/generators/Onetep.scala

index 5ffe37b87e9d5826d3309211bc30227a4ebb2ff7..90adbad563529b46da28329e2e8e94b06b42efc2 100644 (file)
@@ -8,22 +8,30 @@ import scala.reflect.Manifest.singleType
 
 trait Matrix
 trait FunctionSet
-trait Index
+
+class SPAM3(name : String)  extends Matrix
+class PPDFunctionSet(basis : String, data : String) extends FunctionSet
+class NamedIndex(name : String)
 
 class Dictionary {
   var matrices = new HashMap[parser.Identifier, Matrix]
   var functionSets = new HashMap[parser.Identifier, FunctionSet]
-  var indices = new HashMap[parser.Identifier, Index]
+
+  var indices = new HashMap[parser.Identifier, NamedIndex]
 }
 
 class Onetep extends Generator {
+
+  var dictionary = new Dictionary
+
   def acceptInput(program : List[parser.Statement]) = {
     println(program.mkString("\n") + "\n")
     buildDictionary(program)
+    buildDefinition(program)
   }
 
   def filterStatements[T <: parser.Statement](statements : List[parser.Statement])(implicit m: Manifest[T]) =
-    statements.foldLeft(Nil : List[T])((list, item) => item match {
+    statements.foldLeft(List[T]())((list, item) => item match {
       case s if (singleType(s) <:< m) =>  s.asInstanceOf[T] :: list
       case _ => list
     })
@@ -41,7 +49,8 @@ class Onetep extends Generator {
 
     call match {
       case Some(FunctionCall(matType, params)) => (matType, params) match {
-        case (Identifier("SPAM3"), ParameterList(StringParameter(name))) => println(name)
+        case (Identifier("SPAM3"), ParameterList(StringParameter(name))) => 
+          dictionary.matrices += (id -> new SPAM3(name))
         case _ => throw new InvalidInputException("Unknown usage of type: "+matType.name)
       }
       case _ => throw new InvalidInputException("Undefined concrete type for matrix: "+id.name)
@@ -53,17 +62,18 @@ class Onetep extends Generator {
 
     call match {
       case Some(FunctionCall(fSetType, params)) => (fSetType, params) match {
-        case (Identifier("PPDFunctionSet"), ParameterList(StringParameter(basis), StringParameter(data))) => println(basis)
+        case (Identifier("PPDFunctionSet"), ParameterList(StringParameter(basis), StringParameter(data))) => 
+          dictionary.functionSets += (id -> new PPDFunctionSet(basis, data))
         case _ => throw new InvalidInputException("Unknown usage of type: "+fSetType.name)
       }
       case _ => throw new InvalidInputException("Undefined concrete type for function set: "+id.name)
     }
   }
 
-  def buildIndex(id: parser.Identifier, call : Option[parser.FunctionCall]) {
+  def buildNamedIndex(id: parser.Identifier, call : Option[parser.FunctionCall]) {
     call match {
       case Some(_) => throw new InvalidInputException("Index "+id.name+" cannot have concrete type.")
-      case None => ()
+      case None => dictionary.indices += (id -> new NamedIndex(id.name))
     }
   }
 
@@ -83,8 +93,11 @@ class Onetep extends Generator {
       d match {
         case (id, parser.Matrix()) => buildMatrix(id, targetDeclarationCall)
         case (id, parser.FunctionSet()) => buildFunctionSet(id, targetDeclarationCall)
-        case (id, parser.Index()) => buildIndex(id, targetDeclarationCall)
+        case (id, parser.Index()) => buildNamedIndex(id, targetDeclarationCall)
       }
     }
   }
+
+  def buildDefinition(statements : List[parser.Statement]) {
+  }
 }