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
})
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)
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))
}
}
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]) {
+ }
}