From 0eb5253478dbe4264ba262f0375163849a4a3c68 Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Wed, 4 Jan 2012 19:30:23 +0000 Subject: [PATCH] Add created variables to dictionary. --- src/ofc/generators/Onetep.scala | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/ofc/generators/Onetep.scala b/src/ofc/generators/Onetep.scala index 5ffe37b..90adbad 100644 --- a/src/ofc/generators/Onetep.scala +++ b/src/ofc/generators/Onetep.scala @@ -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]) { + } } -- 2.47.3