]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Have statements return the expressions they reference.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 7 Jun 2012 14:42:15 +0000 (15:42 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 7 Jun 2012 14:42:15 +0000 (15:42 +0100)
src/ofc/codegen/AllocateStatement.scala
src/ofc/codegen/AssignStatement.scala
src/ofc/codegen/Comment.scala
src/ofc/codegen/DeallocateStatement.scala
src/ofc/codegen/ForLoop.scala
src/ofc/codegen/FunctionCallStatement.scala
src/ofc/codegen/IfStatement.scala
src/ofc/codegen/IterationContext.scala
src/ofc/codegen/ScopeStatement.scala
src/ofc/codegen/Statement.scala

index b99840afc3daaedf3abd56c5934ace1fcd2fa659..3782f7a5590b955a2d44af6541c2094bc27da296 100644 (file)
@@ -12,4 +12,5 @@ class AllocateStatement(array: Expression[_], size: Seq[Expression[IntType]]) ex
 
   def getArray : Expression[_] = array
   def getSize : Seq[Expression[IntType]] = size
+  def getExpressions = array +: size
 }
index e0b4d0ce913fc06033c8d9f3a45e0c3b96c08970..791b24a236166c323a81d8506d63cd203f0cf261 100644 (file)
@@ -7,4 +7,5 @@ class AssignStatement(lhs: Expression[_ <: Type], rhs: Expression[_ <: Type]) ex
 
   def getLHS : Expression[_] = lhs
   def getRHS : Expression[_] = rhs
+  def getExpressions = List(lhs, rhs)
 }
index 56f4f1a179fecd585d40d0b1301f479d0f122f99..01be110087ebaf1d3f61d59e9725664726ab9c65 100644 (file)
@@ -2,4 +2,5 @@ package ofc.codegen
 
 class Comment(value: String) extends Statement {
   def getValue = value
+  def getExpressions = Nil
 }
index 41efd47624f5b4dc14a3c9a8f37af71937262ca3..39ddc210b3b9518f2f310342565a82953e3ece5f 100644 (file)
@@ -1,11 +1,12 @@
 package ofc.codegen
 import ofc.LogicError
 
-class DeallocateStatement(array: Expression[_]) extends Statement {
+class DeallocateStatement(array: Expression[_ <: Type]) extends Statement {
   array.getType match {
     case (_: ArrayType[_]) => ()
     case _ => throw new LogicError("Can only deallocate an array expression.")
   }
 
   def getArray : Expression[_] = array
+  def getExpressions = List(array)
 }
index 1468bed5fe3c3dd5463501cc1a00feab6855af3d..0e91e6cbe02b2964c1f71b6c4cfdb1f45815328e 100644 (file)
@@ -4,4 +4,5 @@ class ForLoop(index: VarSymbol[IntType], begin: Expression[IntType], end: Expres
   def getIndex = index
   def getBegin = begin
   def getEnd = end
+  def getExpressions = List(begin, end)
 }
index f4c7fd613be3fe4091726f0cc5b89da2891ece2c..8447ce37c8849ea326aa2f3b5625db75e99a5d89 100644 (file)
@@ -2,4 +2,5 @@ package ofc.codegen
 
 class FunctionCallStatement(call: FunctionCall[VoidType]) extends Statement {
   def getCall : FunctionCall[VoidType] = call
+  def getExpressions = call.getParams
 }
index 2c97a53e6b8009adb6690c769c264d2d00443378..b23ae16dc9cd36d7300f01485d9b5d9476cd4233 100644 (file)
@@ -2,4 +2,5 @@ package ofc.codegen
 
 class IfStatement(predicate: Expression[BoolType]) extends ScopeStatement {
   def getPredicate : Expression[BoolType] = predicate
+  def getExpressions = predicate
 }
index 355576f83475f588e69a51611bdcd35de261463c..9654090a013608391d49ad58443b3203c9a093f7 100644 (file)
@@ -173,4 +173,7 @@ class IterationContext extends Statement {
 
   def toConcrete : Statement = 
     toConcrete(new Comment("Placeholder statement for consumer."))
+
+  def getExpressions =
+    throw new LogicError("Call IterationContext::toConcrete() before trying to access expressions.")
 }
index 3c1162cf2c7937483dc8da92240651029c1de7b1..f83eac7ccde1d1ff5e5e797f17b565404706bf99 100644 (file)
@@ -18,4 +18,5 @@ abstract class ScopeStatement(initialStatements: Seq[Statement] = Nil) extends S
 }
 
 class BlockStatement(initialStatements: Seq[Statement] = Nil) extends ScopeStatement(initialStatements) {
+  def getExpressions = Nil
 }
index 4028f7d8895d1c4ba3f9da0ec698105344daafed..24e0f03980ef97718cb9e1f8ae5e88670fc3f5b2 100644 (file)
@@ -1,4 +1,9 @@
 package ofc.codegen
 
-trait Statement
-class NullStatement extends Statement
+trait Statement {
+  def getExpressions: Traversable[Expression[_]]
+}
+
+class NullStatement extends Statement {
+  def getExpressions = Nil
+}