condor.classad
Class Expr

Object
  extended bycondor.classad.Expr
Direct Known Subclasses:
AttrRef, CondExpr, Constant, FuncCall, ListExpr, Op, RecordExpr, SelectExpr, SubscriptExpr

public abstract class Expr
extends Object

A node of an expression tree. An Expr is one of

RecordExpr
a "classad" of the form [name = expr, ... ],
SelectExpr
a selection from a record as in a.b,
ListExpr
a list of the form { expr1, expr2, ... },
SubscriptExpr
a selection from a list as in a[i],
CondExpr
a ternary conditional expression as in a ? b : c,
Op
a binary or unary operator applied to operand(s),
FuncCall
a call to a function with a list of argument expressions,
AttrRef
a reference to an attribute of a ClassAd in the form an identifier, or
Constant
a constant (literal) value

Version:
2.1
Author:
Marvin Solomon
See Also:
RecordExpr, SelectExpr, ListExpr, SubscriptExpr, CondExpr, Op, FuncCall, AttrRef, Constant

Nested Class Summary
protected static class Expr.Env
          An environment for evaluating expressions.
 
Field Summary
static int ABSOLUTE_TIME
          A type flag indicating that this is an absolute time value.
static int AND
          Token ID corresponding to the operator &&.
static int ATTRIBUTE
          A type flag indicating that this is an attribute reference.
static int BIT_COMPLEMENT
          Token ID corresponding to the operator unary ~.
static int BITAND
          Token ID corresponding to the operator &.
static int BITOR
          Token ID corresponding to the operator |.
static int BITXOR
          Token ID corresponding to the operator ^.
static int BOOLEAN
          A type flag indicating that this is a boolean value.
static int CALL
          A type flag indicating that this is a function call.
static int COND
          A type flag indicating that this is a conditional expression.
static int dblevel
          Flag to control level of verbosity of debugging input.
static int DIFFERENT
          Token ID corresponding to the operator isnt .
static int DIV
          Token ID corresponding to the operator /.
static int EQUAL
          Token ID corresponding to the operator ==.
static int ERROR
          A type flag indicating that this is an error value.
static int GREATER
          Token ID corresponding to the operator >.
static int GREATER_EQ
          Token ID corresponding to the operator >=.
static int INTEGER
          A type flag indicating that this is an integer value.
static int LEFT_SHIFT
          Token ID corresponding to the operator <<.
static int LESS
          Token ID corresponding to the operator <.
static int LESS_EQ
          Token ID corresponding to the operator <=.
static int LIST
          A type flag indicating that this is a list.
protected static int MAXPREC
          The maximum precedence in the grammar for ClassAd expressions.
static int MINUS
          Token ID corresponding to the operator -.
static int MOD
          Token ID corresponding to the operator %.
static int NOT
          Token ID corresponding to the operator unary !.
static int NOT_EQUAL
          Token ID corresponding to the operator !=.
static int OP
          A type flag indicating that this is a unary or binary operator.
static String[] opName
          A table mapping operator codes to character-string names.
static String[] opNameXML
          A table mapping operator codes to character-string names, escaped for XML.
static int OR
          Token ID corresponding to the operator ||.
static int PLUS
          Token ID corresponding to the operator +.
static int REAL
          A type flag indicating that this is a real value.
static int RECORD
          A type flag indicating that this is a record (classad).
static int RELATIVE_TIME
          A type flag indicating that this is a relative time value.
static int RIGHT_SHIFT
          Token ID corresponding to the operator >>.
static int SAME
          Token ID corresponding to the operator is .
static int SELECTION
          A type flag indicating that this is a selection (a.b).
static int STRING
          A type flag indicating that this is a string value.
static int SUBSCRIPT
          A type flag indicating that this is a selection (a.b).
static int TIMES
          Token ID corresponding to the operator *.
 int type
          The "type" of this expression.
static int UMINUS
          Token ID corresponding to the operator unary -.
static int UNDEFINED
          A type flag indicating that this is an undefined value.
static int UPLUS
          Token ID corresponding to the operator unary +.
static int URIGHT_SHIFT
          Token ID corresponding to the operator >>>.
 
Constructor Summary
protected Expr(int type)
          Create an Expr node of a given type.
 
Method Summary
static void db(boolean newline, Object msg)
          Debugging print.
static void db(Object msg)
          Debugging print.
 Expr eval()
          Evaluate this Expr in a "top-level" (empty) environment.
 Expr eval(Expr.Env env)
          Evaluate this Expr in a given environment.
protected abstract  Expr eval1(Expr.Env env)
          Evaluate this Expr.
 int intValue()
          Convert to an integer constant if possible.
protected  boolean isConstant()
          Check whether this Expr is a constant.
 boolean isTrue()
          Convert to a boolean value.
(package private) abstract  int prec()
          The precedence of the operator in this expression node.
 double realValue()
          Convert to a double value if possible.
 SelectExpr selectExpr(String selector)
          A convenience function for creating a SelectExpression corresponding to ``this.selector''.
 String stringValue()
          Convert to a String value, if possible.
 SubscriptExpr subExpr(int subscript)
          A convenience function for creating a SubscriptExpression corresponding to ``this[subscript]''.
 String toString()
          Convert this Expr to a string.
abstract  StringBuffer toString(StringBuffer sb)
          Convert this Expr to a string, appending the result to the end of "sb".
protected  String typeName()
          Determine the type of this expression (for printing messages).
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

public final int type
The "type" of this expression. For constants, the type is one of UNDEFINED, ERROR, BOOLEAN, INTEGER, REAL, STRING, ABSOLUTE_TIME, or RELATIVE_TIME.

For non-atomic values, the type is one of COND, OP, CALL, SELECTION, SUBSCRIPT, ATTRIBUTE, LIST, or RECORD.

The values of these constants are chosen to facilitate classifying an expression as a constant, constructed value (LIST or RECORD) or other expression.

See Also:
isConstant(), eval(condor.classad.Expr.Env)

COND

public static final int COND
A type flag indicating that this is a conditional expression.

See Also:
Constant Field Values

OP

public static final int OP
A type flag indicating that this is a unary or binary operator.

See Also:
Constant Field Values

CALL

public static final int CALL
A type flag indicating that this is a function call.

See Also:
Constant Field Values

SELECTION

public static final int SELECTION
A type flag indicating that this is a selection (a.b).

See Also:
Constant Field Values

SUBSCRIPT

public static final int SUBSCRIPT
A type flag indicating that this is a selection (a.b).

See Also:
Constant Field Values

ATTRIBUTE

public static final int ATTRIBUTE
A type flag indicating that this is an attribute reference.

See Also:
Constant Field Values

LIST

public static final int LIST
A type flag indicating that this is a list.

See Also:
Constant Field Values

RECORD

public static final int RECORD
A type flag indicating that this is a record (classad).

See Also:
Constant Field Values

UNDEFINED

public static final int UNDEFINED
A type flag indicating that this is an undefined value.

See Also:
Constant Field Values

ERROR

public static final int ERROR
A type flag indicating that this is an error value.

See Also:
Constant Field Values

BOOLEAN

public static final int BOOLEAN
A type flag indicating that this is a boolean value.

See Also:
Constant Field Values

INTEGER

public static final int INTEGER
A type flag indicating that this is an integer value.

See Also:
Constant Field Values

REAL

public static final int REAL
A type flag indicating that this is a real value.

See Also:
Constant Field Values

STRING

public static final int STRING
A type flag indicating that this is a string value.

See Also:
Constant Field Values

ABSOLUTE_TIME

public static final int ABSOLUTE_TIME
A type flag indicating that this is an absolute time value.

See Also:
Constant Field Values

RELATIVE_TIME

public static final int RELATIVE_TIME
A type flag indicating that this is a relative time value.

See Also:
Constant Field Values

MAXPREC

protected static final int MAXPREC
The maximum precedence in the grammar for ClassAd expressions.

See Also:
Constant Field Values

dblevel

public static int dblevel
Flag to control level of verbosity of debugging input. Higher values are more verbose. If the value is zero, no debugging output is printed.


opName

public static final String[] opName
A table mapping operator codes to character-string names. For example, opName[NOT_EQUAL] = "!=".


opNameXML

public static final String[] opNameXML
A table mapping operator codes to character-string names, escaped for XML. For example, opName[LEFT_SHIFT] = "&lt;&lt;".


OR

public static final int OR
Token ID corresponding to the operator ||.

See Also:
Constant Field Values

AND

public static final int AND
Token ID corresponding to the operator &&.

See Also:
Constant Field Values

BITOR

public static final int BITOR
Token ID corresponding to the operator |.

See Also:
Constant Field Values

BITXOR

public static final int BITXOR
Token ID corresponding to the operator ^.

See Also:
Constant Field Values

BITAND

public static final int BITAND
Token ID corresponding to the operator &.

See Also:
Constant Field Values

EQUAL

public static final int EQUAL
Token ID corresponding to the operator ==.

See Also:
Constant Field Values

NOT_EQUAL

public static final int NOT_EQUAL
Token ID corresponding to the operator !=.

See Also:
Constant Field Values

SAME

public static final int SAME
Token ID corresponding to the operator is .

See Also:
Constant Field Values

DIFFERENT

public static final int DIFFERENT
Token ID corresponding to the operator isnt .

See Also:
Constant Field Values

LESS

public static final int LESS
Token ID corresponding to the operator <.

See Also:
Constant Field Values

GREATER

public static final int GREATER
Token ID corresponding to the operator >.

See Also:
Constant Field Values

LESS_EQ

public static final int LESS_EQ
Token ID corresponding to the operator <=.

See Also:
Constant Field Values

GREATER_EQ

public static final int GREATER_EQ
Token ID corresponding to the operator >=.

See Also:
Constant Field Values

LEFT_SHIFT

public static final int LEFT_SHIFT
Token ID corresponding to the operator <<.

See Also:
Constant Field Values

RIGHT_SHIFT

public static final int RIGHT_SHIFT
Token ID corresponding to the operator >>.

See Also:
Constant Field Values

URIGHT_SHIFT

public static final int URIGHT_SHIFT
Token ID corresponding to the operator >>>.

See Also:
Constant Field Values

PLUS

public static final int PLUS
Token ID corresponding to the operator +.

See Also:
Constant Field Values

MINUS

public static final int MINUS
Token ID corresponding to the operator -.

See Also:
Constant Field Values

TIMES

public static final int TIMES
Token ID corresponding to the operator *.

See Also:
Constant Field Values

DIV

public static final int DIV
Token ID corresponding to the operator /.

See Also:
Constant Field Values

MOD

public static final int MOD
Token ID corresponding to the operator %.

See Also:
Constant Field Values

UPLUS

public static final int UPLUS
Token ID corresponding to the operator unary +.

See Also:
Constant Field Values

UMINUS

public static final int UMINUS
Token ID corresponding to the operator unary -.

See Also:
Constant Field Values

BIT_COMPLEMENT

public static final int BIT_COMPLEMENT
Token ID corresponding to the operator unary ~.

See Also:
Constant Field Values

NOT

public static final int NOT
Token ID corresponding to the operator unary !.

See Also:
Constant Field Values
Constructor Detail

Expr

protected Expr(int type)
Create an Expr node of a given type. Used in constructors of subclasses.

Parameters:
type - the type of Expr to create.
Method Detail

typeName

protected String typeName()
Determine the type of this expression (for printing messages).

Returns:
a string identifing the type of this constant.

eval1

protected abstract Expr eval1(Expr.Env env)
Evaluate this Expr. This is the internal method used to implement eval(). Each type of expression implements it differently. Lists, records, and constants evaluate to themselves. Function calls and operators evaluate to the result of applying the operartor or function to the (recursively evaluated) arguments. Attribute references are evaluated by looking up the reference in the env.

Parameters:
env - an environment consisting of a list of RecordExprs (innermost first) used to resolve AttrRefs. In the case of AttrRef, env is updated to remove all scopes preceding the one where the reference was resovled.
Returns:
a Constant, AttrRef, ListExpr, or RecordExpr representing the value.

eval

public Expr eval(Expr.Env env)
Evaluate this Expr in a given environment. Lists, records, and constants evaluate to themselves. Function calls and operators evaluate to the result of applying the operartor or function to the (recursively evaluated) arguments. Attribute references are evaluated by looking up the reference in the env. If the result is an AttrRef, it is re-evalutated. If this re-evaluation leads to a cycle (an attribute defined in terms of itself), the result is the UNDEFINED constant.

Parameters:
env - an environment consisting of a list of RecordExprs (innermost first) used to resolve AttrRefs. In the case of AttrRef, env is updated to remove all scopes preceding the one where the reference was resovled.
Returns:
a Constant, ListExpr, or RecordExpr representing the value.

eval

public Expr eval()
Evaluate this Expr in a "top-level" (empty) environment. Lists, records, and constants evaluate to themselves. Function calls and operators evaluate to the result of applying the operartor or function to the (recursively evaluated) arguments. Attribute references evaluate to the UNDEFINED constant.

Returns:
a Constant, ListExpr, or RecordExpr representing the value.

selectExpr

public SelectExpr selectExpr(String selector)
A convenience function for creating a SelectExpression corresponding to ``this.selector''.

Parameters:
selector - a selector.
Returns:
a new SelectExpr corresponding to ``this.selector''.

subExpr

public SubscriptExpr subExpr(int subscript)
A convenience function for creating a SubscriptExpression corresponding to ``this[subscript]''.

Parameters:
subscript - a subscript.
Returns:
a new SelectExpr corresponding to ``this[subscript]''.

isConstant

protected final boolean isConstant()
Check whether this Expr is a constant.

Returns:
true if this Expr is a constant.

toString

public String toString()
Convert this Expr to a string. The representation is the "canonical native format". Use a ClassAdWriter for other representations and for finer conctrol over formatting.

Returns:
a string representation of this Expr
See Also:
ClassAdWriter

toString

public abstract StringBuffer toString(StringBuffer sb)
Convert this Expr to a string, appending the result to the end of "sb". The representation is the "canonical native format".

Parameters:
sb - a place to put the result.
Returns:
sb.
See Also:
ClassAdWriter

intValue

public int intValue()
             throws ArithmeticException
Convert to an integer constant if possible.

Returns:
the integer value of this Expr.
Throws:
ArithmeticException - if this Expr is not an integer Constant.

realValue

public double realValue()
                 throws ArithmeticException
Convert to a double value if possible.

Returns:
the value of of this Expr, converted to double.
Throws:
ArithmeticException - if this Expr is not an integer or real constant.

stringValue

public String stringValue()
                   throws ArithmeticException
Convert to a String value, if possible.

Returns:
the string value of this Expr.
Throws:
ArithmeticException - if this Expr is not an String Constant.

isTrue

public boolean isTrue()
Convert to a boolean value. Note that unlike intValue, etc., this method never throws an exception.

Returns:
true if this Expr is a constant of type boolean with value true, and false in all other cases.

prec

abstract int prec()
The precedence of the operator in this expression node. Used to print expressions without superfluous parentheses.

Returns:
the precendence of this node.
See Also:
ClassAdWriter.MINIMAL_PARENTHESES

db

public static void db(Object msg)
Debugging print. The message is printed to System.out, followed by a newline. Intended usage is something like
    if (dblevel > 1) db("The value of foo is " +foo);
 

Parameters:
msg - the message to be printed.
See Also:
dblevel

db

public static void db(boolean newline,
                      Object msg)
Debugging print. The message is printed to System.out.

Parameters:
newline - if true, terminate the message with a newline.
msg - the message to be printed.
See Also:
db(java.lang.Object)