avrora.core.isdl.ast
Class VarExpr

java.lang.Object
  extended byavrora.core.isdl.ast.Expr
      extended byavrora.core.isdl.ast.VarExpr

public class VarExpr
extends Expr

The VarExpr class represents an expression in the IR that is a use of a local or global variable.


Field Summary
 Token variable
          The variable field stores a reference to the token representing the name of the variable being accessed.
 
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
VarExpr(java.lang.String v)
          The constructor for the VarExpr class simply initializes the reference to the name of the variable.
VarExpr(Token v)
          The constructor for the VarExpr class simply initializes the reference to the name of the variable.
 
Method Summary
 Expr accept(CodeRebuilder r, java.lang.Object env)
          The accept() method implements one half of the visitor pattern for rebuilding of expressions.
 void accept(CodeVisitor 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.
 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 isVariable()
          The isVariable() method tests whether this expression is a direct variable use and is used in copy propagation.
 java.lang.String toString()
          The toString() method recursively converts this expression to a string.
 
Methods inherited from class avrora.core.isdl.ast.Expr
getBitWidth, innerString, isBitRangeExpr, isConstantExpr, isLiteral, isMap, tokenToBool, tokenToInt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

variable

public final Token variable
The variable field stores a reference to the token representing the name of the variable being accessed.

Constructor Detail

VarExpr

public VarExpr(Token v)
The constructor for the VarExpr class simply initializes the reference to the name of the variable.

Parameters:
v - the string name of the variable as a token

VarExpr

public VarExpr(java.lang.String v)
The constructor for the VarExpr class simply initializes the reference to the name of the variable.

Parameters:
v - the string name of the variable as a token
Method Detail

isVariable

public boolean isVariable()
The isVariable() method tests whether this expression is a direct variable use and is used in copy propagation. For instances of VarExpr, this method returns true. For all other instances, it returns false.

Overrides:
isVariable in class Expr
Returns:
true because this expression is the direct use of a variable

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

accept

public void accept(CodeVisitor 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

accept

public Expr accept(CodeRebuilder r,
                   java.lang.Object env)
The accept() method implements one half of the visitor pattern for rebuilding of expressions. This visitor allows code to be slightly modified while only writing visit methods for the parts of the syntax tree affected.

Specified by:
accept in class Expr
Parameters:
r - the rebuilder to accept
Returns:
the result of calling the appropriate visit() method of the rebuilder

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