condor.classad
Class Expr

java.lang.Object
  |
  +--condor.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, of the form [.]identifier[.identifier], or
Constant
a constant (literal) value

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

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 BRIEF
          A combination of option flags for toString().
static int CALL
          A type flag indicating that this is a function call
static int COMPACT
          A combination of option flags for toString().
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
protected static int formatFlags
          Flags to control the formatting of expressions by toString().
static String formatIndent
          A standing indent for all expressions whose string representation spans multiple lines.
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 MINIMAL_PARENTHESES
          An option flag for toString().
static int MINUS
          Token ID corresponding to the operator -
static int MOD
          Token ID corresponding to the operator %
static int MULTI_LINE_ADS
          An option flag for toString().
static int MULTI_LINE_LISTS
          An option flag for toString().
static int NO_ESCAPE_STRINGS
          An option flag for toString().
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 int OR
          Token ID corresponding to the operator ||
static int PLUS
          Token ID corresponding to the operator +
static int READABLE
          A combination of option flags for toString().
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 SHOW_ERROR_DETAIL
          An option flag for toString().
static int SHOW_INSTANCES
          An option flag for toString().
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 >>>
 
Method Summary
static void db(boolean newline, Object msg)
          Debugging print.
static void db(Object msg)
          Debugging print.
static void disableFormatFlags(int flags)
          Turn off options for converting expressions to strings.
static void enableFormatFlags(int flags)
          Turn on options for converting expressions to strings.
 Expr eval(Context ctx)
          Evaluate this Expr.
static int getFormatFlags()
          Get existing options for converting expressions to strings.
protected  boolean isConstant()
          Indicate whether this is a constant.
protected  boolean isNormalForm()
          Indicate whether this is a normal-form expression.
protected  String mark()
          Conditionally return an indication of the unique instance represented by this expression.
protected  String mark(boolean on)
          Conditionally return an indication of the unique instance represented by this expression.
protected static String mark(Expr expr)
          Return an indication of the unique instance of the argument.
protected abstract  int prec()
          The precedence of the operator in this expression node.
protected  Expr reEval(Context ctx)
          Evalutate this expression.
 SelectExpr select(String selector)
          A convenience function for creating a SelectExpression corresponding to ``this.selector''
static void setFormatFlags(int flags)
          Set options for converting expressions to strings.
abstract  String toString()
          Convert this Expr to a string.
 String toString(int flags)
          Convert this Expr to a string.
protected  String typeName()
          Determine the type of this expression (for printing messages).
 
Methods inherited from class java.lang.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. Note that these values are all less than zero.


COND

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

OP

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

CALL

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

SELECTION

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

SUBSCRIPT

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

ATTRIBUTE

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

LIST

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

RECORD

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

UNDEFINED

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

ERROR

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

BOOLEAN

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

INTEGER

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

REAL

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

STRING

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

ABSOLUTE_TIME

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

RELATIVE_TIME

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

formatIndent

public static String formatIndent
A standing indent for all expressions whose string representation spans multiple lines. This string is appended to the start of all lines but the first.

formatFlags

protected static int formatFlags
Flags to control the formatting of expressions by toString(). A value of zero creates a representation that is unambiguous and easy to parse but not very readable. Each bit turns on a formatting feature that makes the string more readable, but perhaps more verbose and/or ambiguous.
See Also:
NO_ESCAPE_STRINGS, SHOW_ERROR_DETAIL, MINIMAL_PARENTHESES, MULTI_LINE_ADS, MULTI_LINE_LISTS, SHOW_INSTANCES, BRIEF, COMPACT, READABLE

NO_ESCAPE_STRINGS

public static final int NO_ESCAPE_STRINGS
An option flag for toString(). Don't surround strings with quotes or escape special characters in the string.

WARNING: Strings created with this flag cannot be parsed to recover the expressions that created them.

See Also:
formatFlags

SHOW_ERROR_DETAIL

public static final int SHOW_ERROR_DETAIL
An option flag for toString(). Print the ERROR value as ``ERROR(reason)'' rather than just ``ERROR''.
See Also:
formatFlags

MINIMAL_PARENTHESES

public static final int MINIMAL_PARENTHESES
An option flag for toString(). Use only as many parentheses are are required to override the default precendence of operators.
See Also:
formatFlags

MULTI_LINE_ADS

public static final int MULTI_LINE_ADS
An option flag for toString(). Display classads with one attribute per line.
See Also:
formatFlags

MULTI_LINE_LISTS

public static final int MULTI_LINE_LISTS
An option flag for toString(). Display lists with one member per line.
See Also:
formatFlags

SHOW_INSTANCES

public static final int SHOW_INSTANCES
An option flag for toString(). Flag certain kinds of expressions with a marker indicating unique instances. This is a temporary debugging feature that may be removed from future revisions of this package.
See Also:
formatFlags

BRIEF

public static final int BRIEF
A combination of option flags for toString(). Produce a concise version (both MINIMAL_PARENTHESES and NO_ESCAPE_STRINGS)
See Also:
formatFlags, MINIMAL_PARENTHESES, NO_ESCAPE_STRINGS

COMPACT

public static final int COMPACT
A combination of option flags for toString(). Produce a compact but parsable version (currently, the same as MINIMAL_PARENTHESES).
See Also:
formatFlags, MINIMAL_PARENTHESES

READABLE

public static final int READABLE
A combination of option flags for toString(). Produce a maximally-readable version (all flags other than SHOW_INSTANCES).
See Also:
formatFlags, SHOW_INSTANCES

MAXPREC

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

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] = "!=".

OR

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

AND

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

BITOR

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

BITXOR

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

BITAND

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

EQUAL

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

NOT_EQUAL

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

SAME

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

DIFFERENT

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

LESS

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

GREATER

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

LESS_EQ

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

GREATER_EQ

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

LEFT_SHIFT

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

RIGHT_SHIFT

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

URIGHT_SHIFT

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

PLUS

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

MINUS

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

TIMES

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

DIV

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

MOD

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

UPLUS

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

UMINUS

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

BIT_COMPLEMENT

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

NOT

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

typeName

protected String typeName()
Determine the type of this expression (for printing messages).
Returns:
a string identifing the type of this constant.

mark

protected String mark(boolean on)
Conditionally return an indication of the unique instance represented by this expression. This is a temporary debugging feature that may be removed from future revisions of this package.
Parameters:
on - indicates whether to indicate the particular instance.
Returns:
if on is true, a string of the form <nn>, where nn is a decimal integer, otherwise an empty string.

mark

protected String mark()
Conditionally return an indication of the unique instance represented by this expression. This is a temporary debugging feature that may be removed from future revisions of this package.
Returns:
if Expr.formatFlags includes the flag Expr.SHOW_INSTANCES, a string of the form <nn>, where nn is a decimal integer, otherwise an empty string.

mark

protected static String mark(Expr expr)
Return an indication of the unique instance of the argument. This is a temporary debugging feature that may be removed from future revisions of this package.
Parameters:
expr - an expression instance or null
Returns:
the string <> if expr==null, otherwise expr.mark().
See Also:
mark()

eval

public Expr eval(Context ctx)
Evaluate this Expr. The model is ``evalutate until normal form''. A normal form expression (currently a Constant, ListExpr, or RecordExpr) evaluates to itself. Any other expression is evaluated by evaluating its operand(s) as necessary and then applying its top-level operator to the results. If the types of the evaluated operands are wrong, for example if the top-level operator is + and an operand evaluates to a RecordExpr, the result is an ErrorConstant, which is in normal form. If the result of applying the operator is not in normal form, it is re-evaluated.

The Context records a mapping from non-normal-form expressions to their values. It speeds up evaluation and guarentees termination.

Theorem: Evaluation is linear-time in the size of the original Expr.

Proof: When evaluation of an expression is started, the Context maps it to an UndefinedConstant. If the evaluation process recursively requests the value of the same expression, the result is that UndefinedConstant. When the evaluation of a particular subexpression is complete, the Context replaces the UndefinedConstant with a reference to the computed value. This value may be either a sub-expression of the original expression or a newly created Expr value, but in any case, it will be in normal form. Thus a value found in the Context will never require re-evaluation.

In short, a top-level call to eval will never attempt to evaluate any node more than once, and the total number of new nodes created is bounded by the number of nodes in the original expression. QED

Parameters:
ctx - an evaluation context for evaluating this expression
Returns:
a Constant, ListExpr, or RecordExpr representing the value.
See Also:
Context

isNormalForm

protected final boolean isNormalForm()
Indicate whether this is a normal-form expression.
Returns:
true if this Expr is in normal form (a Constant, RecordExpr, or ListExpr)

isConstant

protected final boolean isConstant()
Indicate whether this is a constant.
Returns:
true if this Expr is a constant.

reEval

protected Expr reEval(Context ctx)
Evalutate this expression. This method is only called for expressions that are not in normal form.
Parameters:
ctx - an evaluation context for evaluating this expression
Returns:
a Constant, ListExpr, or RecordExpr representing the value.
See Also:
eval(condor.classad.Context)

select

public SelectExpr select(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''.

setFormatFlags

public static void setFormatFlags(int flags)
Set options for converting expressions to strings.
Parameters:
flag - the new flag values.
See Also:
NO_ESCAPE_STRINGS, SHOW_ERROR_DETAIL, MINIMAL_PARENTHESES, MULTI_LINE_ADS, MULTI_LINE_LISTS, BRIEF, COMPACT, READABLE

getFormatFlags

public static int getFormatFlags()
Get existing options for converting expressions to strings.
Returns:
the current option flags.
See Also:
NO_ESCAPE_STRINGS, SHOW_ERROR_DETAIL, MINIMAL_PARENTHESES, MULTI_LINE_ADS, MULTI_LINE_LISTS, BRIEF, COMPACT, READABLE

enableFormatFlags

public static void enableFormatFlags(int flags)
Turn on options for converting expressions to strings.
Parameters:
flag - the flag values to be enabled
See Also:
NO_ESCAPE_STRINGS, SHOW_ERROR_DETAIL, MINIMAL_PARENTHESES, MULTI_LINE_ADS, MULTI_LINE_LISTS, BRIEF, COMPACT, READABLE

disableFormatFlags

public static void disableFormatFlags(int flags)
Turn off options for converting expressions to strings.
Parameters:
flag - the flag values to be disabled
See Also:
NO_ESCAPE_STRINGS, SHOW_ERROR_DETAIL, MINIMAL_PARENTHESES, MULTI_LINE_ADS, MULTI_LINE_LISTS, BRIEF, COMPACT, READABLE

toString

public abstract String toString()
Convert this Expr to a string. The exact format of the result is controled by the static fields Expr.formatFlags and Expr.formatIndent. The result may be multiple lines long (it may include embedded newlines and tabs), but it never ends with a newline.
Overrides:
toString in class Object
Returns:
a string representation of the this Context
See Also:
formatFlags, formatIndent, NO_ESCAPE_STRINGS, SHOW_ERROR_DETAIL, MINIMAL_PARENTHESES, MULTI_LINE_ADS, MULTI_LINE_LISTS, BRIEF, COMPACT, READABLE

toString

public String toString(int flags)
Convert this Expr to a string. This is a convenience function that temporarily sets the static flags Expr.formatFlags for the duration of a single call of the no-argument version.
Parameters:
flags - the new flags to set.
Returns:
a string representation of the this Context
See Also:
toString(), formatFlags, formatIndent, NO_ESCAPE_STRINGS, SHOW_ERROR_DETAIL, MINIMAL_PARENTHESES, MULTI_LINE_ADS, MULTI_LINE_LISTS, BRIEF, COMPACT

prec

protected 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:
MINIMAL_PARENTHESES

db

public static void db(Object msg)
Debugging print. The message is printed to System.out. 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)