avrora.core.isdl.ast
Class Arith.BinOp

java.lang.Object
  extended byavrora.core.isdl.ast.Expr
      extended byavrora.core.isdl.ast.Arith
          extended byavrora.core.isdl.ast.Arith.BinOp
Direct Known Subclasses:
Arith.AddExpr, Arith.AndExpr, Arith.DivExpr, Arith.MulExpr, Arith.OrExpr, Arith.ShiftLeftExpr, Arith.ShiftRightExpr, Arith.SubExpr, Arith.XorExpr
Enclosing class:
Arith

public abstract static class Arith.BinOp
extends Arith

The BinOp inner class represents an operation on two integers with an infix binary operation. For example, addition, multiplication, bitwise and, and such operations are binary infix and therefore subclasses of this class.


Nested Class Summary
 
Nested classes inherited from class avrora.core.isdl.ast.Arith
Arith.AddExpr, Arith.AndExpr, Arith.BinOp, Arith.CompExpr, Arith.DivExpr, Arith.MulExpr, Arith.NegExpr, Arith.OrExpr, Arith.ShiftLeftExpr, Arith.ShiftRightExpr, Arith.SubExpr, Arith.UnOp, Arith.XorExpr
 
Field Summary
 Expr left
          The left field stores a reference to the expression that is the left operand of the binary operation.
 java.lang.String operation
          The operation field stores the string name of the operation of this binary operation.
 int precedence
          The precedence field stores the precedence level of this binary operation.
 Expr right
          The left field stores a reference to the expression that is the right operand of the binary operation.
 
Fields inherited from class avrora.core.isdl.ast.Expr
PREC_A_ADD, PREC_A_AND, PREC_A_MUL, PREC_A_OR, PREC_A_SHIFT, PREC_A_XOR, PREC_L_AND, PREC_L_EQU, PREC_L_OR, PREC_L_REL, PREC_L_XOR, PREC_TERM, PREC_UN
 
Constructor Summary
Arith.BinOp(int p, Expr l, java.lang.String o, Expr r)
          The constructor of the BinOp class initializes the public final fields that form the structure of this expression.
 
Method Summary
 void accept(ExprVisitor v)
          The accept() method implements one half of the visitor pattern so that client visitors can traverse the syntax tree easily and in an extensible way.
 int getPrecedence()
          The getPrecedence() method gets the binding precedence for this expression.
 boolean isConstantExpr()
          The isConstantExpr() method tests whether this expression is a constant expression (i.e. it is reducable to a constant and has no references to variables, maps, etc).
 java.lang.String toString()
          The toString() method recursively converts this expression to a string.
 
Methods inherited from class avrora.core.isdl.ast.Expr
accept, accept, getBitWidth, innerString, isBitRangeExpr, isLiteral, isMap, isVariable, tokenToBool, tokenToInt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

operation

public final java.lang.String operation
The operation field stores the string name of the operation of this binary operation. For example, '+' represents addition.


left

public final Expr left
The left field stores a reference to the expression that is the left operand of the binary operation.


right

public final Expr right
The left field stores a reference to the expression that is the right operand of the binary operation.


precedence

public final int precedence
The precedence field stores the precedence level of this binary operation. This is used to compute when to surround inner expressions with parentheses when printing code in infix notation.

Constructor Detail

Arith.BinOp

public Arith.BinOp(int p,
                   Expr l,
                   java.lang.String o,
                   Expr r)
The constructor of the BinOp class initializes the public final fields that form the structure of this expression.

Parameters:
p - the precedence of this expression
l - the left expression operand
o - the string name of the operation
r - the right expression operand
Method Detail

isConstantExpr

public boolean isConstantExpr()
The isConstantExpr() method tests whether this expression is a constant expression (i.e. it is reducable to a constant and has no references to variables, maps, etc).

Overrides:
isConstantExpr in class Expr
Returns:
true if this expression can be evaluated to a constant; false otherwise

accept

public void accept(ExprVisitor v)
The accept() method implements one half of the visitor pattern so that client visitors can traverse the syntax tree easily and in an extensible way.

Specified by:
accept in class Expr
Parameters:
v - the visitor to accept

toString

public java.lang.String toString()
The toString() method recursively converts this expression to a string. For binary operations, inner expressions will be nested within parentheses if their precedence is lower than the precedence of the parent expression.

Returns:
a string representation of this expression

getPrecedence

public int getPrecedence()
The getPrecedence() method gets the binding precedence for this expression. This is used to compute when inner expressions must be nested within parentheses in order to preserve the implied order of evaluation.

Specified by:
getPrecedence in class Expr
Returns:
an integer representing the precedence of this expression; higher numbers are higher precedence