--- /dev/null
+package ofc.codegen
+import ofc.LogicError
+
+class AllocateStatement(array: Expression[_], size: Seq[Expression[IntType]]) extends Statement {
+ val arrayType = array.getType match {
+ case (at: ArrayType[_]) => at
+ case _ => throw new LogicError("Can only allocate an array expression.")
+ }
+
+ if (size.length != arrayType.getRank)
+ throw new LogicError("Incorrect rank for array allocation.")
+
+ def getArray : Expression[_] = array
+ def getSize : Seq[Expression[IntType]] = size
+}
--- /dev/null
+package ofc.codegen
+import ofc.LogicError
+
+class DeallocateStatement(array: Expression[_]) extends Statement {
+ array.getType match {
+ case (_: ArrayType[_]) => ()
+ case _ => throw new LogicError("Can only deallocate an array expression.")
+ }
+
+ def getArray : Expression[_] = array
+}
case (x : ForLoop) => processForLoop(x)
case (a : Assignment) => processAssignment(a)
case (i : IfStatement) => processIf(i)
+ case (a : AllocateStatement) => processAllocate(a)
+ case (d : DeallocateStatement) => processDeallocate(d)
case x => throw new UnimplementedException("Unknown statement type in FORTRAN generator: " + x.toString)
}
}
addLine("endif")
}
+ private def processAllocate(allocate: AllocateStatement) {
+ addLine("allocate(%s(%s))".format(buildExpression(allocate.getArray), allocate.getSize.map(buildExpression(_)).mkString(",")))
+ }
+
+ private def processDeallocate(deallocate: DeallocateStatement) {
+ addLine("deallocate(%s)".format(buildExpression(deallocate.getArray)))
+ }
+
private def addLine(line: String) {
buffer += " "*indentLevel + line
}