]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Add if statement generation.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Tue, 10 Apr 2012 09:55:07 +0000 (10:55 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Tue, 10 Apr 2012 09:55:07 +0000 (10:55 +0100)
src/ofc/codegen/FortranGenerator.scala
src/ofc/codegen/IfStatement.scala

index 3524a2990a4417dce0535aa3a289fd159392a68f..f424243515105668a59079c3e3eb4300684d1669 100644 (file)
@@ -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
   }
index 84ae5b0f5c860b92add27689c2397f9069e45544..2c97a53e6b8009adb6690c769c264d2d00443378 100644 (file)
@@ -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
+}