From d5807b8ccea36d55ff110cfe805b673200de411a Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Tue, 10 Apr 2012 10:55:07 +0100 Subject: [PATCH] Add if statement generation. --- src/ofc/codegen/FortranGenerator.scala | 9 +++++++++ src/ofc/codegen/IfStatement.scala | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ofc/codegen/FortranGenerator.scala b/src/ofc/codegen/FortranGenerator.scala index 3524a29..f424243 100644 --- a/src/ofc/codegen/FortranGenerator.scala +++ b/src/ofc/codegen/FortranGenerator.scala @@ -142,6 +142,7 @@ class FortranGenerator { case (x : ProducerStatement) => processStatement(x.toConcrete) case (x : ForLoop) => processForLoop(x) case (a : Assignment) => processAssignment(a) + case (i : IfStatement) => processIf(i) case x => throw new UnimplementedException("Unknown statement type in FORTRAN generator: " + x.toString) } } @@ -245,6 +246,14 @@ class FortranGenerator { addLine("%s = %s".format(buildExpression(assignment.getLHS), buildExpression(assignment.getRHS))) } + private def processIf(ifStatement: IfStatement) { + addLine("if (%s) then".format(buildExpression(ifStatement.getPredicate))) + in + processScope(ifStatement) + out + addLine("endif") + } + private def addLine(line: String) { buffer += " "*indentLevel + line } diff --git a/src/ofc/codegen/IfStatement.scala b/src/ofc/codegen/IfStatement.scala index 84ae5b0..2c97a53 100644 --- a/src/ofc/codegen/IfStatement.scala +++ b/src/ofc/codegen/IfStatement.scala @@ -1,3 +1,5 @@ package ofc.codegen -class IfStatement(predicate: Expression[BoolType]) extends ScopeStatement +class IfStatement(predicate: Expression[BoolType]) extends ScopeStatement { + def getPredicate : Expression[BoolType] = predicate +} -- 2.47.3