|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object scale.common.Root scale.score.Note scale.score.expr.Expr scale.score.expr.BinaryExpr scale.score.expr.CompareExpr
public class CompareExpr
This class represents three-valued comparison functions.
$Id: CompareExpr.java,v 1.26 2007-04-27 18:04:35 burrill Exp $
Copyright 2008 by the
Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.
If the left argument is less than the right argument, a -1 is returned. If the left argument is greater than the right argument, a 1 is returned. Otherwise, a 0 is returned. If the arguments are floating point and either is Nan, then either a -1 or a 1 is returned depending on the mode setting.
We use instances of this class instead of generating comparisons and IfThenElseChords directly in the CFG. There is no benefit to generating the decision points in the CFG and doing so makes the CFG unnecessarily complex. Also, there is no easy way to test for a NaN in C code so a function call would have to be made to do that test anyway.
By using this class, Scribble2C can generate a function call for floating point arguments and use the C conditional operator inline for integer arguments.
When going direct to machine code, an instance of this class can be converted directly into machine instructions that test for NaN.
Field Summary | |
---|---|
static int |
FloatG
If either argument is Nan, return 1. |
static int |
FloatL
If either argument is Nan, return -1. |
static java.lang.String[] |
modes
String representation of the compare mode. |
static int |
Normal
Use normal compare. |
Fields inherited from class scale.score.expr.Expr |
---|
fpReorder, SE_DOMAIN, SE_NONE, SE_OVERFLOW, SE_STATE |
Constructor Summary | |
---|---|
CompareExpr(Expr la,
Expr ra,
int mode)
The expression type is integer two's complement. |
|
CompareExpr(Type type,
Expr la,
Expr ra,
int mode)
|
Method Summary | |
---|---|
Expr |
copy()
Perform a deep copy of the expression tree. |
Literal |
getConstantValue()
Return the constant value of the expression. |
Literal |
getConstantValue(HashMap<Expr,Literal> cvMap)
Return the constant value of the expression. |
java.lang.String |
getDisplayLabel()
Return a String suitable for labeling this node in a graphical display. |
int |
getMode()
Return the mode of the comparison operation. |
void |
visit(Predicate p)
Process a node by calling its associated routine. |
Methods inherited from class scale.score.Note |
---|
getChord, getEssentialUse, setAnnotationLevel, setReportLevel, toString |
Methods inherited from class scale.common.Root |
---|
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, hashCode, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass, trace, trace, trace |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int Normal
public static final int FloatL
public static final int FloatG
public static final java.lang.String[] modes
Constructor Detail |
---|
public CompareExpr(Type type, Expr la, Expr ra, int mode)
type
- is the expression typela
- is the left operandra
- is the right operandmode
- determines the type of comparisonpublic CompareExpr(Expr la, Expr ra, int mode)
la
- is the left operandra
- is the right operandmode
- determines the type of comparisonMethod Detail |
---|
public Expr copy()
Expr
copy
in class Expr
public int getMode()
public void visit(Predicate p)
Note
Each class has a visit(Predicate p)
method. For
example, in class ABC
:
public void visit(Predicate p) { p.visitABC(this); }and the class that implements
Predicate
has a method
public void visitABC(Note n) { ABC a = (ABC) n; ... }Thus, the class that implements
Predicate
can call
n.visit(this);where
n
is a Note
sub-class without
determining which specific sub-class n
is.
The visit pattern basically avoids implementing a large
switch
statement or defining different methods
in each class for some purpose.
visit
in class Note
Predicate
public java.lang.String getDisplayLabel()
Expr
getDisplayLabel
in interface DisplayNode
getDisplayLabel
in class Expr
public Literal getConstantValue(HashMap<Expr,Literal> cvMap)
getConstantValue
in class Expr
Lattice
public Literal getConstantValue()
getConstantValue
in class Expr
Lattice
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |