avrora.core.isdl.ast
Class Expr

java.lang.Object
  extended byavrora.core.isdl.ast.Expr
Direct Known Subclasses:
Arith, BitExpr, BitRangeExpr, CallExpr, ConversionExpr, Literal, Logical, MapExpr, VarExpr

public abstract class Expr
extends java.lang.Object

The Expr class represents an expression in the IR. Expressions are evaluated and produce a value that can be assigned to locals, globalMap, maps, used in if statements, and passed as parameters.


Field Summary
static int PREC_A_ADD
           
static int PREC_A_AND
           
static int PREC_A_MUL
           
static int PREC_A_OR
           
static int PREC_A_SHIFT
           
static int PREC_A_XOR
           
static int PREC_L_AND
           
static int PREC_L_EQU
           
static int PREC_L_OR
           
static int PREC_L_REL
           
static int PREC_L_XOR
           
static int PREC_TERM
           
static int PREC_UN
           
 
Constructor Summary
Expr()
           
 
Method Summary
abstract  Expr accept(CodeRebuilder r, java.lang.Object env)
          The accept() method implements one half of the visitor pattern for rebuilding of expressions.
abstract  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.
abstract  void accept(ExprVisitor v)
          The accept() method implements half of the visitor pattern for expression visitors.
 int getBitWidth()
          The getBitWidth() method gets the number of bits needed to represent this value.
abstract  int getPrecedence()
          The getPrecedence() method gets the binding precedence for this expression.
 java.lang.String innerString(Expr e)
          The innerString() method is a utility to embed an expression in parentheses only if its precedence is less than the precedence of this expression.
 boolean isBitRangeExpr()
          The isBitRangeExpr() method tests whether the expression is an access of a range of bits.
 boolean isConstantExpr()
          The isConstantExpr() method tests whether this expression is a constant expression (i.e.
 boolean isLiteral()
          The isLiteral() method tests whether this expression is a known constant directly (i.e. a literal).
 boolean isMap()
          The isMap() method tests whether this expression is a reference to an element of a map.
 boolean isVariable()
          The isVariable() method tests whether this expression is a single variable use.
static boolean tokenToBool(Token i)
          The tokenToBool() static method is a utility to evaluate a token as a boolean literal.
static int tokenToInt(Token i)
          The tokenToInt() static method is a utility to evaluate a token as an integer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PREC_L_OR

public static final int PREC_L_OR
See Also:
Constant Field Values

PREC_L_XOR

public static final int PREC_L_XOR
See Also:
Constant Field Values

PREC_L_AND

public static final int PREC_L_AND
See Also:
Constant Field Values

PREC_A_OR

public static final int PREC_A_OR
See Also:
Constant Field Values

PREC_A_XOR

public static final int PREC_A_XOR
See Also:
Constant Field Values

PREC_A_AND

public static final int PREC_A_AND
See Also:
Constant Field Values

PREC_L_EQU

public static final int PREC_L_EQU
See Also:
Constant Field Values

PREC_L_REL

public static final int PREC_L_REL
See Also:
Constant Field Values

PREC_A_SHIFT

public static final int PREC_A_SHIFT
See Also:
Constant Field Values

PREC_A_ADD

public static final int PREC_A_ADD
See Also:
Constant Field Values

PREC_A_MUL

public static final int PREC_A_MUL
See Also:
Constant Field Values

PREC_UN

public static final int PREC_UN
See Also:
Constant Field Values

PREC_TERM

public static final int PREC_TERM
See Also:
Constant Field Values
Constructor Detail

Expr

public Expr()
Method Detail

isVariable

public boolean isVariable()
The isVariable() method tests whether this expression is a single variable use.

Returns:
true if this expression is a direct use of a variable; false otherwise

isLiteral

public boolean isLiteral()
The isLiteral() method tests whether this expression is a known constant directly (i.e. a literal).

Returns:
true if this expression is a literal; false otherwise

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).

Returns:
true if this expression can be evaluated to a constant; false otherwise

isMap

public boolean isMap()
The isMap() method tests whether this expression is a reference to an element of a map. This is used in pattern matching in some parts of the tools that work on abstract syntax trees.

Returns:
true if this expression is a reference to a map element; false otherwise

isBitRangeExpr

public boolean isBitRangeExpr()
The isBitRangeExpr() method tests whether the expression is an access of a range of bits. This is used in pattern matching in some parts of the code.

Returns:
true if this expression is a bit range expression; false otherwise

getBitWidth

public int getBitWidth()
The getBitWidth() method gets the number of bits needed to represent this value. This is needed in the case of encoding formats, which need to compute the size of an instruction based on the width of its internal fields.

Returns:
the number of bits that this expression occupies

getPrecedence

public abstract 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.

Returns:
an integer representing the precedence of this expression; higher numbers are higher precedence

tokenToInt

public static int tokenToInt(Token i)
The tokenToInt() static method is a utility to evaluate a token as an integer.

Parameters:
i - the value of the integer as a token
Returns:
the integer value of the token if it exists

tokenToBool

public static boolean tokenToBool(Token i)
The tokenToBool() static method is a utility to evaluate a token as a boolean literal.

Parameters:
i - the value of the boolean as a token
Returns:
the boolean value of the token if it exists

accept

public abstract void accept(ExprVisitor v)
The accept() method implements half of the visitor pattern for expression visitors.

Parameters:
v - the visitor to accept

accept

public abstract 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.

Parameters:
v - the visitor to accept

accept

public abstract 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.

Parameters:
r - the rebuilder to accept
Returns:
the result of calling the appropriate visit() method of the rebuilder

innerString

public java.lang.String innerString(Expr e)
The innerString() method is a utility to embed an expression in parentheses only if its precedence is less than the precedence of this expression. This is useful in converting nested expressions into strings

Parameters:
e - the expression nested inside of this expression
Returns:
a string that is the result of converting the specified expression to a string and nesting it in parentheses if necessary