gov.llnl.babel.symbols

Class BinaryExpression


public class BinaryExpression
extends AssertionExpression

Field Summary

static int
BITWISE_AND
static int
BITWISE_OR
static int
BITWISE_XOR
static int
DIVIDE
static int
EQUALS
static int
GREATER_EQUAL
static int
GREATER_THAN
static int
IF_AND_ONLY_IF
static int
IMPLIES
static int
LESS_EQUAL
static int
LESS_THAN
static int
LOGICAL_AND
static int
LOGICAL_OR
static int
LOGICAL_XOR
static int
MAX_OP_VALUE
static int
MINUS
static int
MIN_OP_VALUE
static int
MODULUS
static int
MULTIPLY
static int
NOOP
static int
NOT_EQUAL
static int
PLUS
static int
POWER
static int
REMAINDER
static int
SHIFT_LEFT
static int
SHIFT_RIGHT

Fields inherited from class gov.llnl.babel.symbols.AssertionExpression

ERROR_SEMANTIC_VALIDATION, d_context

Constructor Summary

BinaryExpression(AssertionExpression lhs, int op, AssertionExpression rhs, Context context)
Construct a new object.

Method Summary

Object
accept(ExprVisitor ev, Object data)
Implement the "visitor pattern".
boolean
arrayOnLeft()
Return TRUE if an array appears on the LHS; otherwise, FALSE.
boolean
arrayOnRight()
Return TRUE if an array appears on the RHS; otherwise, FALSE.
String
cExpression(String epvVar, int[] startInd)
Return the C version of the expression.
ArrayList
getArrayIterMacros(String epvVar, int[] startInd)
Return the list of array iteration macro messages, if any.
String
getArrayRelation()
Return the array relation only.
String
getArrayRelationVariable(boolean onLeft)
Return the specified array relation's array variable.
AssertionExpression
getLeftExpression()
Return the left-hand expression.
int
getNumArrayIterMacrosByType(char type)
Returns the number of macros supported by this assertion of the specified type.
int
getOp()
Return the binary operator.
String
getOpSymbol()
Return the symbol associated with the operator.
AssertionExpression
getRightExpression()
Return the right-hand expression.
boolean
hasMethodCall()
Return TRUE if the expression has at least one method call; otherwise, return FALSE.
boolean
hasPure()
Return TRUE if the expression has an "is pure" clause; otherwise, return FALSE.
boolean
hasReservedMethod(int type)
Return TRUE if the expression is, or has, the specified reserved method call; otherwise, return FALSE.
boolean
hasResult()
Return TRUE if the expression uses the "result" keyword; otherwise, return FALSE.
boolean
hasUnreservedMethod(boolean any)
Return TRUE if the method is any unreserved method (when any is TRUE) or it is an unreserved method with a throws clause (if any is FALSE); otherwise, return FALSE.
boolean
isArrayRelationRequired()
Return TRUE if the array relation is required (during validation); otherwise, return FALSE.
boolean
requiresExtendableContext()
Return TRUE if extendable context is required to validate the expression; otherwise, return FALSE.
boolean
requiresMethodContext()
Return TRUE if method context is required to validate the expression; otherwise, return FALSE.
void
setArrayRelationRequired(boolean isReq)
Set the array relation required attribute.
String
toString()
Return the stringified version of the expression (in SIDL form).
protected void
validateSemantics(Extendable ext, Method m)
Validate the expression semantics, first ensuring both subexpressions are valid then that the binary expression is valid for the specified operator.

Methods inherited from class gov.llnl.babel.symbols.AssertionExpression

accept, cExpression, getArrayIterMacros, getExceptionPrefix, getExceptionPrefix, getNumArrayIterMacrosByType, getReturnType, getReturnTypeName, getReturnTypeValue, hasMethodCall, hasParens, hasPure, hasReservedMethod, hasResult, hasUnreservedMethod, isValid, leftAssociative, requiresExtendableContext, requiresMethodContext, returnIsArray, returnIsBoolean, returnIsCharacter, returnIsDComplex, returnIsDouble, returnIsFComplex, returnIsFloat, returnIsInteger, returnIsLong, returnIsNumericArray, returnIsOpaque, returnIsString, setParens, setReturnToBoolean, setReturnToCharacter, setReturnToDComplex, setReturnToDouble, setReturnToFComplex, setReturnToFloat, setReturnToInteger, setReturnToLong, setReturnToOpaque, setReturnToString, setReturnType, setReturnType, toString, validateExpression, validateSemantics

Field Details

BITWISE_AND

public static final int BITWISE_AND
Field Value:
21

BITWISE_OR

public static final int BITWISE_OR
Field Value:
22

BITWISE_XOR

public static final int BITWISE_XOR
Field Value:
23

DIVIDE

public static final int DIVIDE
Field Value:
2

EQUALS

public static final int EQUALS
Field Value:
3

GREATER_EQUAL

public static final int GREATER_EQUAL
Field Value:
4

GREATER_THAN

public static final int GREATER_THAN
Field Value:
5

IF_AND_ONLY_IF

public static final int IF_AND_ONLY_IF
Field Value:
6

IMPLIES

public static final int IMPLIES
Field Value:
7

LESS_EQUAL

public static final int LESS_EQUAL
Field Value:
8

LESS_THAN

public static final int LESS_THAN
Field Value:
9

LOGICAL_AND

public static final int LOGICAL_AND
Field Value:
1

LOGICAL_OR

public static final int LOGICAL_OR
Field Value:
14

LOGICAL_XOR

public static final int LOGICAL_XOR
Field Value:
20

MAX_OP_VALUE

public static final int MAX_OP_VALUE
Field Value:
23

MINUS

public static final int MINUS
Field Value:
10

MIN_OP_VALUE

public static final int MIN_OP_VALUE
Field Value:
1

MODULUS

public static final int MODULUS
Field Value:
11

MULTIPLY

public static final int MULTIPLY
Field Value:
12

NOOP

public static final int NOOP
Field Value:
0

NOT_EQUAL

public static final int NOT_EQUAL
Field Value:
13

PLUS

public static final int PLUS
Field Value:
15

POWER

public static final int POWER
Field Value:
16

REMAINDER

public static final int REMAINDER
Field Value:
17

SHIFT_LEFT

public static final int SHIFT_LEFT
Field Value:
18

SHIFT_RIGHT

public static final int SHIFT_RIGHT
Field Value:
19

Constructor Details

BinaryExpression

public BinaryExpression(AssertionExpression lhs,
                        int op,
                        AssertionExpression rhs,
                        Context context)
            throws AssertionException
Construct a new object. An exception is thrown if an invalid binary operator is specified.
Parameters:
lhs - The expression on the left side of the operator.
op - The binary operator.
rhs - The expression on the right side of the operator.
Throws:
AssertionException - The exception raised if the specified return type is out of range, the operator invalid, or either the left or right expression is null.

Method Details

accept

public Object accept(ExprVisitor ev,
                     Object data)
Implement the "visitor pattern".
Overrides:
accept in interface AssertionExpression

arrayOnLeft

public boolean arrayOnLeft()
Return TRUE if an array appears on the LHS; otherwise, FALSE.

arrayOnRight

public boolean arrayOnRight()
Return TRUE if an array appears on the RHS; otherwise, FALSE.

cExpression

public String cExpression(String epvVar,
                          int[] startInd)
Return the C version of the expression. ToDo...Need to finish this. In particular, need to handle complex subexpressions properly -- at least under the assumption that the relevant complex struct has been declared!
Overrides:
cExpression in interface AssertionExpression

getArrayIterMacros

public ArrayList getArrayIterMacros(String epvVar,
                                    int[] startInd)
Return the list of array iteration macro messages, if any. Each message is a string where the first character indicates the return type associated with the iteration. The remaining characters will be the actual macro invocation.
Overrides:
getArrayIterMacros in interface AssertionExpression

getArrayRelation

public String getArrayRelation()
Return the array relation only. For relations with a single array, this is the operator and value being used for comparison. When both arrays are specified, this is only the operator.

getArrayRelationVariable

public String getArrayRelationVariable(boolean onLeft)
Return the specified array relation's array variable.

getLeftExpression

public AssertionExpression getLeftExpression()
Return the left-hand expression.

getNumArrayIterMacrosByType

public int getNumArrayIterMacrosByType(char type)
Returns the number of macros supported by this assertion of the specified type. Valid types are given in MethodCall.java.
Overrides:
getNumArrayIterMacrosByType in interface AssertionExpression

getOp

public int getOp()
Return the binary operator.

getOpSymbol

public String getOpSymbol()
Return the symbol associated with the operator. It is assumed the operator is valid thanks to the check in the constructor.

getRightExpression

public AssertionExpression getRightExpression()
Return the right-hand expression.

hasMethodCall

public boolean hasMethodCall()
Return TRUE if the expression has at least one method call; otherwise, return FALSE.
Overrides:
hasMethodCall in interface AssertionExpression

hasPure

public boolean hasPure()
Return TRUE if the expression has an "is pure" clause; otherwise, return FALSE.
Overrides:
hasPure in interface AssertionExpression

hasReservedMethod

public boolean hasReservedMethod(int type)
Return TRUE if the expression is, or has, the specified reserved method call; otherwise, return FALSE.
Overrides:
hasReservedMethod in interface AssertionExpression

hasResult

public boolean hasResult()
Return TRUE if the expression uses the "result" keyword; otherwise, return FALSE.
Overrides:
hasResult in interface AssertionExpression

hasUnreservedMethod

public boolean hasUnreservedMethod(boolean any)
Return TRUE if the method is any unreserved method (when any is TRUE) or it is an unreserved method with a throws clause (if any is FALSE); otherwise, return FALSE.
Overrides:
hasUnreservedMethod in interface AssertionExpression

isArrayRelationRequired

public boolean isArrayRelationRequired()
Return TRUE if the array relation is required (during validation); otherwise, return FALSE.

requiresExtendableContext

public boolean requiresExtendableContext()
Return TRUE if extendable context is required to validate the expression; otherwise, return FALSE.
Overrides:
requiresExtendableContext in interface AssertionExpression

requiresMethodContext

public boolean requiresMethodContext()
Return TRUE if method context is required to validate the expression; otherwise, return FALSE.
Overrides:
requiresMethodContext in interface AssertionExpression

setArrayRelationRequired

public void setArrayRelationRequired(boolean isReq)
Set the array relation required attribute.

toString

public String toString()
Return the stringified version of the expression (in SIDL form).
Overrides:
toString in interface AssertionExpression

validateSemantics

protected void validateSemantics(Extendable ext,
                                 Method m)
            throws AssertionException
Validate the expression semantics, first ensuring both subexpressions are valid then that the binary expression is valid for the specified operator. Set the return type of this binary expression accordingly.
Overrides:
validateSemantics in interface AssertionExpression
Parameters:
ext - The interface or class that owns this expression.
m - The method that owns this expression.
Throws:
AssertionException - The exception that can be raised during the validation.