aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scalam/m/ast/statements.scala
blob: 5c39fb990c1b0ab9c1d316dedf221b85b1924550 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package scalam.m.ast

/**
 * A matlab statement.
 * @define construct statement
 */
trait Statement extends Mable with Root {
  def m: String = this match {
    case Assign(id, value) => id.m + " = " + value.m
    case AssignMatrixIndex(id, indices, value) =>
      id.m + indices.map(_.m).mkString("(", ",", ")") + " = " + value.m

    case _ => throw new IllegalArgumentException("unkown statement: " + this)
  }
}

/**
 * Variable assignment.
 * @param variable identifer of variable
 * @param value value to assign
 *
 * @define construct assignment
 */
case class Assign(variable: Identifier, value: Expression) extends Statement

/**
 * Variable (matrix) index assignment.
 * @param variable identifer of variable
 * @param indices indices of variable
 * @param value value to assign
 *
 * @define construct variable (matrix) assignment
 */
case class AssignMatrixIndex(variable: Identifier, indices: Seq[Expression], value: Expression) extends Statement