From: Francis Russell Date: Thu, 7 Jun 2012 14:42:15 +0000 (+0100) Subject: Have statements return the expressions they reference. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=502ad844dc3b1f7343ef613511cdd992bc67e595;p=francis%2Fofc.git Have statements return the expressions they reference. --- diff --git a/src/ofc/codegen/AllocateStatement.scala b/src/ofc/codegen/AllocateStatement.scala index b99840a..3782f7a 100644 --- a/src/ofc/codegen/AllocateStatement.scala +++ b/src/ofc/codegen/AllocateStatement.scala @@ -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 } diff --git a/src/ofc/codegen/AssignStatement.scala b/src/ofc/codegen/AssignStatement.scala index e0b4d0c..791b24a 100644 --- a/src/ofc/codegen/AssignStatement.scala +++ b/src/ofc/codegen/AssignStatement.scala @@ -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) } diff --git a/src/ofc/codegen/Comment.scala b/src/ofc/codegen/Comment.scala index 56f4f1a..01be110 100644 --- a/src/ofc/codegen/Comment.scala +++ b/src/ofc/codegen/Comment.scala @@ -2,4 +2,5 @@ package ofc.codegen class Comment(value: String) extends Statement { def getValue = value + def getExpressions = Nil } diff --git a/src/ofc/codegen/DeallocateStatement.scala b/src/ofc/codegen/DeallocateStatement.scala index 41efd47..39ddc21 100644 --- a/src/ofc/codegen/DeallocateStatement.scala +++ b/src/ofc/codegen/DeallocateStatement.scala @@ -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) } diff --git a/src/ofc/codegen/ForLoop.scala b/src/ofc/codegen/ForLoop.scala index 1468bed..0e91e6c 100644 --- a/src/ofc/codegen/ForLoop.scala +++ b/src/ofc/codegen/ForLoop.scala @@ -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) } diff --git a/src/ofc/codegen/FunctionCallStatement.scala b/src/ofc/codegen/FunctionCallStatement.scala index f4c7fd6..8447ce3 100644 --- a/src/ofc/codegen/FunctionCallStatement.scala +++ b/src/ofc/codegen/FunctionCallStatement.scala @@ -2,4 +2,5 @@ package ofc.codegen class FunctionCallStatement(call: FunctionCall[VoidType]) extends Statement { def getCall : FunctionCall[VoidType] = call + def getExpressions = call.getParams } diff --git a/src/ofc/codegen/IfStatement.scala b/src/ofc/codegen/IfStatement.scala index 2c97a53..b23ae16 100644 --- a/src/ofc/codegen/IfStatement.scala +++ b/src/ofc/codegen/IfStatement.scala @@ -2,4 +2,5 @@ package ofc.codegen class IfStatement(predicate: Expression[BoolType]) extends ScopeStatement { def getPredicate : Expression[BoolType] = predicate + def getExpressions = predicate } diff --git a/src/ofc/codegen/IterationContext.scala b/src/ofc/codegen/IterationContext.scala index 355576f..9654090 100644 --- a/src/ofc/codegen/IterationContext.scala +++ b/src/ofc/codegen/IterationContext.scala @@ -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.") } diff --git a/src/ofc/codegen/ScopeStatement.scala b/src/ofc/codegen/ScopeStatement.scala index 3c1162c..f83eac7 100644 --- a/src/ofc/codegen/ScopeStatement.scala +++ b/src/ofc/codegen/ScopeStatement.scala @@ -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 } diff --git a/src/ofc/codegen/Statement.scala b/src/ofc/codegen/Statement.scala index 4028f7d..24e0f03 100644 --- a/src/ofc/codegen/Statement.scala +++ b/src/ofc/codegen/Statement.scala @@ -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 +}