org.apache.xalan.xsltc.compiler
Class Predicate

java.lang.Object
  extended by org.apache.xalan.xsltc.compiler.SyntaxTreeNode
      extended by org.apache.xalan.xsltc.compiler.Expression
          extended by org.apache.xalan.xsltc.compiler.Predicate
All Implemented Interfaces:
Closure, Constants

final class Predicate
extends Expression
implements Closure


Field Summary
private  boolean _canOptimize
          This flag indicates if optimizations are turned on.
private  java.lang.String _className
          Name of the inner class.
private  java.util.ArrayList _closureVars
          List of variables in closure.
private  Expression _exp
          The predicate's expression.
private  boolean _nthDescendant
          Flag indicatig if the nth position descendant is on.
private  boolean _nthPositionFilter
          Flag indicatig if the nth position optimization is on.
private  Closure _parentClosure
          Reference to parent closure.
(package private)  int _ptype
          Cached node type of the expression that owns this predicate.
private  Step _step
          Cached value of method getCompareValue().
private  Expression _value
          Cached value of method getCompareValue().
 
Fields inherited from class org.apache.xalan.xsltc.compiler.Expression
_falseList, _trueList, _type
 
Fields inherited from class org.apache.xalan.xsltc.compiler.SyntaxTreeNode
_attributes, _parent, _qname, Dummy, IndentIncrement, UNKNOWN_STYLESHEET_NODE_ID
 
Fields inherited from interface org.apache.xalan.xsltc.compiler.Constants
ABSOLUTE_ITERATOR, ACC_FINAL, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_SUPER, ADD_ATTRIBUTE, ADD_ATTRIBUTE_SIG, ADD_ITERATOR, ADD_ITERATOR_SIG, ADD_PARAMETER, ADD_PARAMETER_SIG, APPLY_TEMPLATES, ATTR_SET_SIG, ATTRIBUTE_LIST_FIELD, ATTRIBUTE_LIST_IMPL_CLASS, ATTRIBUTE_LIST_IMPL_SIG, ATTRIBUTES_SIG, BASIS_LIBRARY_CLASS, BOOLEAN_CLASS, BOOLEAN_VALUE, BOOLEAN_VALUE_SIG, CACHED_NODE_LIST_ITERATOR_CLASS, CHARACTERS, CHARACTERS_SIG, CHARACTERSW, CHARACTERSW_SIG, CLEAR_ATTRIBUTES, CLEAR_ATTRIBUTES_SIG, COLLATOR_CLASS, COLLATOR_SIG, COMPILER_PACKAGE, CURRENT_NODE_LIST_FILTER, CURRENT_NODE_LIST_FILTER_SIG, CURRENT_NODE_LIST_ITERATOR, CURRENT_NODE_LIST_ITERATOR_SIG, DEFAULT_NODE_COUNTER, DEFAULT_NODE_COUNTER_SIG, DOCUMENT_PNAME, DOM_ADAPTER_CLASS, DOM_ADAPTER_SIG, DOM_FIELD, DOM_IMPL, DOM_IMPL_CLASS, DOM_IMPL_SIG, DOM_INTF, DOM_INTF_SIG, DOM_PNAME, DOUBLE_CLASS, DOUBLE_SIG, DOUBLE_VALUE, DOUBLE_VALUE_SIG, DUP_FILTERED_ITERATOR, EMPTYATTR_FIELD, EMPTYSTRING, ERROR, EXPAND_STYLESHEET_QNAME_REF, EXPAND_STYLESHEET_QNAME_SIG, FALLBACK_CLASS, FATAL, FILTER_INTERFACE, FILTER_INTERFACE_SIG, FILTER_ITERATOR, FILTER_STEP_ITERATOR, FORMAT_SYMBOLS_FIELD, GET_ATTRIBUTE_VALUE, GET_ATTRIBUTE_VALUE_SIG, GET_CHILDREN, GET_CHILDREN_SIG, GET_ELEMENT_VALUE, GET_ELEMENT_VALUE_SIG, GET_ITERATOR_SIG, GET_NODE_NAME, GET_NODE_NAME_SIG, GET_NODE_TYPE, GET_NODE_TYPE_SIG, GET_NODE_VALUE, GET_NODE_VALUE_ITERATOR, GET_NODE_VALUE_ITERATOR_SIG, GET_NODE_VALUE_SIG, GET_PARAMETER, GET_PARAMETER_SIG, GET_PARENT, GET_PARENT_SIG, GET_TYPED_CHILDREN, GET_TYPED_CHILDREN_SIG, GET_UNPARSED_ENTITY_URI, GET_UNPARSED_ENTITY_URI_SIG, HAS_ATTRIBUTE, HAS_ATTRIBUTE_SIG, HASIDCALL_INDEX, HASIDCALL_INDEX_SIG, INT_VALUE, INT_VALUE_SIG, INTEGER_CLASS, INTEGER_SIG, INTERNAL, INVOKE_METHOD, ITERATOR_FIELD_SIG, ITERATOR_PNAME, KEY_INDEX_CLASS, KEY_INDEX_ITERATOR_SIG, KEY_INDEX_SIG, LAST_INDEX, LOAD_DOCUMENT_CLASS, LOCALE_CLASS, LOCALE_SIG, LOOKUP_STYLESHEET_QNAME_NS_REF, LOOKUP_STYLESHEET_QNAME_NS_SIG, MAKE_NODE, MAKE_NODE_LIST, MAKE_NODE_LIST_SIG, MAKE_NODE_LIST_SIG2, MAKE_NODE_SIG, MAKE_NODE_SIG2, MATCHING_ITERATOR, MATH_CLASS, MULTI_DOM_CLASS, MULTI_DOM_SIG, NAMES_INDEX, NAMES_INDEX_SIG, NAMESPACE_FEATURE, NAMESPACE_INDEX, NAMESPACE_INDEX_SIG, NEXT, NEXT_SIG, NEXTID, NODE, NODE_COUNTER, NODE_COUNTER_SIG, NODE_FIELD, NODE_FIELD_SIG, NODE_ITERATOR, NODE_ITERATOR_BASE, NODE_ITERATOR_SIG, NODE_PNAME, NODE_SIG, NODE_SORT_FACTORY, NODE_SORT_FACTORY_SIG, NODE_SORT_RECORD, NODE_SORT_RECORD_SIG, NS_ANCESTORS_INDEX_SIG, NTH_ITERATOR_CLASS, OBJECT_CLASS, OBJECT_SIG, ORDER_ITERATOR, ORDER_ITERATOR_SIG, OUTPUT_BASE, OUTPUT_HANDLER, OUTPUT_HANDLER_SIG, POP_PARAM_FRAME, POP_PARAM_FRAME_SIG, POSITION_INDEX, PREFIX_URIS_ARRAY_SIG, PREFIX_URIS_IDX_SIG, PUSH_PARAM_FRAME, PUSH_PARAM_FRAME_SIG, REDIRECT_URI, RESET, RESET_SIG, RTF_INITIAL_SIZE, RUNTIME_NODE_CLASS, RUNTIME_PACKAGE, SAX_IMPL, SAX_IMPL_CLASS, SAX_IMPL_SIG, SET_START_NODE, SET_START_NODE_SIG, SINGLETON_ITERATOR, SORT_ITERATOR, SORT_ITERATOR_SIG, STATIC_CHAR_DATA_FIELD, STATIC_CHAR_DATA_FIELD_SIG, STATIC_NAMES_ARRAY_FIELD, STATIC_NAMESPACE_ARRAY_FIELD, STATIC_NS_ANCESTORS_ARRAY_FIELD, STATIC_PREFIX_URIS_ARRAY_FIELD, STATIC_PREFIX_URIS_IDX_ARRAY_FIELD, STATIC_TYPES_ARRAY_FIELD, STATIC_URIS_ARRAY_FIELD, STEP_ITERATOR_CLASS, STREAM_XML_OUTPUT, STRING, STRING_BUFFER_CLASS, STRING_BUFFER_SIG, STRING_CLASS, STRING_SIG, STRING_TO_INT, STRING_TO_INT_SIG, STRING_TO_REAL, STRING_TO_REAL_SIG, STRING_VALUE_HANDLER, STRING_VALUE_HANDLER_SIG, STRING_WRITER, STRIP_SPACE, STRIP_SPACE_INTF, STRIP_SPACE_PARAMS, STRIP_SPACE_SIG, TRANSLET_CLASS, TRANSLET_FIELD, TRANSLET_FIELD_SIG, TRANSLET_INTF, TRANSLET_INTF_SIG, TRANSLET_OUTPUT_BASE, TRANSLET_OUTPUT_INTERFACE, TRANSLET_OUTPUT_PNAME, TRANSLET_OUTPUT_SIG, TRANSLET_PNAME, TRANSLET_SIG, TRANSLET_URI, TRANSLET_VERSION_INDEX, TRANSLET_VERSION_INDEX_SIG, TYPES_INDEX, TYPES_INDEX_SIG, UNION_ITERATOR_CLASS, UNION_ITERATOR_SIG, UNSUPPORTED, URIS_INDEX, URIS_INDEX_SIG, WARNING, WRITER_SIG, XHTML_URI, XMLNS_PREFIX, XMLNS_STRING, XMLNS_URI, XSLT_PACKAGE, XSLT_URI
 
Constructor Summary
Predicate(Expression exp)
          Initializes a predicate.
 
Method Summary
 void addVariable(VariableRefBase variableRef)
          Add new variable to the closure.
private  void compileFilter(ClassGenerator classGen, MethodGenerator methodGen)
          Create a new "Filter" class implementing CurrentNodeListFilter.
 void dontOptimize()
          Turns off all optimizations for this predicate.
 Expression getCompareValue()
          Returns the value in an expression of the form 'step = value'.
 Expression getExpr()
           
 java.lang.String getInnerClassName()
          Returns the name of the auxiliary class or null if this predicate is compiled inside the Translet.
 Closure getParentClosure()
          Returns a reference to its parent closure or null if outermost.
 int getPosType()
          Returns the node type of the expression owning this predicate.
 Step getStep()
          Returns the step in an expression of the form 'step = value'.
 boolean hasLastCall()
          Returns true if the expression in this predicate contains a call to last().
 boolean hasPositionCall()
          Returns true if the expression in this predicate contains a call to position().
 boolean inInnerClass()
          Returns true if this closure is compiled in an inner class (i.e.
 boolean isBooleanTest()
          Returns true if the predicate is a test for the existance of an element or attribute.
 boolean isNodeValueTest()
          Method to see if we can optimise the predicate by using a specialised iterator for expressions like '/foo/bar[@attr = $var]', which are very common in many stylesheets
 boolean isNthDescendant()
          Returns a boolean value indicating if the nth descendant optimization is on.
 boolean isNthPositionFilter()
          Returns a boolean value indicating if the nth position optimization is on.
 boolean parentIsPattern()
           
 void setParser(Parser parser)
          Set the parser for this expression.
 java.lang.String toString()
           
 void translate(ClassGenerator classGen, MethodGenerator methodGen)
          Translate a predicate expression.
 void translateFilter(ClassGenerator classGen, MethodGenerator methodGen)
          Translate a predicate expression.
 Type typeCheck(SymbolTable stable)
          Type check a predicate expression.
 
Methods inherited from class org.apache.xalan.xsltc.compiler.Expression
backPatchFalseList, backPatchTrueList, compile, desynthesize, evaluateAtCompileTime, getFalseList, getTrueList, getType, lookupPrimop, startIterator, synthesize, translateDesynthesized
 
Methods inherited from class org.apache.xalan.xsltc.compiler.SyntaxTreeNode
addAttribute, addElement, addPrefixMapping, compileResultTree, contextDependent, dependentContents, display, displayContents, elementAt, elementCount, elements, getAttribute, getAttribute, getAttributes, getContents, getImportPrecedence, getLineNumber, getNodeIDForStylesheetNSLookup, getParent, getParser, getPrefixMapping, getQName, getStylesheet, getSymbolTable, getTemplate, getXSLTC, hasAttribute, hasContents, indent, isDummy, lastChild, lookupNamespace, lookupPrefix, parseChildren, parseContents, removeElement, reportError, reportWarning, setAttributes, setFirstElement, setLineNumber, setParent, setPrefixMapping, setQName, setQName, translateContents, typeCheckContents, updateScope
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_exp

private Expression _exp
The predicate's expression.


_canOptimize

private boolean _canOptimize
This flag indicates if optimizations are turned on. The method dontOptimize() can be called to turn optimizations off.


_nthPositionFilter

private boolean _nthPositionFilter
Flag indicatig if the nth position optimization is on. It is set in typeCheck().


_nthDescendant

private boolean _nthDescendant
Flag indicatig if the nth position descendant is on. It is set in typeCheck().


_ptype

int _ptype
Cached node type of the expression that owns this predicate.


_className

private java.lang.String _className
Name of the inner class.


_closureVars

private java.util.ArrayList _closureVars
List of variables in closure.


_parentClosure

private Closure _parentClosure
Reference to parent closure.


_value

private Expression _value
Cached value of method getCompareValue().


_step

private Step _step
Cached value of method getCompareValue().

Constructor Detail

Predicate

public Predicate(Expression exp)
Initializes a predicate.

Method Detail

setParser

public void setParser(Parser parser)
Set the parser for this expression.

Overrides:
setParser in class SyntaxTreeNode
Parameters:
parser - The XSLT parser.

isNthPositionFilter

public boolean isNthPositionFilter()
Returns a boolean value indicating if the nth position optimization is on. Must be call after type checking!


isNthDescendant

public boolean isNthDescendant()
Returns a boolean value indicating if the nth descendant optimization is on. Must be call after type checking!


dontOptimize

public void dontOptimize()
Turns off all optimizations for this predicate.


hasPositionCall

public boolean hasPositionCall()
Returns true if the expression in this predicate contains a call to position().

Overrides:
hasPositionCall in class Expression

hasLastCall

public boolean hasLastCall()
Returns true if the expression in this predicate contains a call to last().

Overrides:
hasLastCall in class Expression

inInnerClass

public boolean inInnerClass()
Returns true if this closure is compiled in an inner class (i.e. if this is a real closure).

Specified by:
inInnerClass in interface Closure

getParentClosure

public Closure getParentClosure()
Returns a reference to its parent closure or null if outermost.

Specified by:
getParentClosure in interface Closure

getInnerClassName

public java.lang.String getInnerClassName()
Returns the name of the auxiliary class or null if this predicate is compiled inside the Translet.

Specified by:
getInnerClassName in interface Closure

addVariable

public void addVariable(VariableRefBase variableRef)
Add new variable to the closure.

Specified by:
addVariable in interface Closure

getPosType

public int getPosType()
Returns the node type of the expression owning this predicate. The return value is cached in _ptype.


parentIsPattern

public boolean parentIsPattern()

getExpr

public Expression getExpr()

toString

public java.lang.String toString()
Specified by:
toString in class Expression

typeCheck

public Type typeCheck(SymbolTable stable)
               throws TypeCheckError
Type check a predicate expression. If the type of the expression is number convert it to boolean by adding a comparison with position(). Note that if the expression is a parameter, we cannot distinguish at compile time if its type is number or not. Hence, expressions of reference type are always converted to booleans. This method may be called twice, before and after calling dontOptimize(). If so, the second time it should honor the new value of _canOptimize.

Overrides:
typeCheck in class Expression
Parameters:
stable - The compiler/parser's symbol table
Throws:
TypeCheckError

compileFilter

private void compileFilter(ClassGenerator classGen,
                           MethodGenerator methodGen)
Create a new "Filter" class implementing CurrentNodeListFilter. Allocate registers for local variables and local parameters passed in the closure to test(). Notice that local variables need to be "unboxed".


isBooleanTest

public boolean isBooleanTest()
Returns true if the predicate is a test for the existance of an element or attribute. All we have to do is to get the first node from the step, check if it is there, and then return true/false.


isNodeValueTest

public boolean isNodeValueTest()
Method to see if we can optimise the predicate by using a specialised iterator for expressions like '/foo/bar[@attr = $var]', which are very common in many stylesheets


getStep

public Step getStep()
Returns the step in an expression of the form 'step = value'. Null is returned if the expression is not of the right form. Optimization if off if null is returned.


getCompareValue

public Expression getCompareValue()
Returns the value in an expression of the form 'step = value'. A value may be either a literal string or a variable whose type is string. Optimization if off if null is returned.


translateFilter

public void translateFilter(ClassGenerator classGen,
                            MethodGenerator methodGen)
Translate a predicate expression. This translation pushes two references on the stack: a reference to a newly created filter object and a reference to the predicate's closure.


translate

public void translate(ClassGenerator classGen,
                      MethodGenerator methodGen)
Translate a predicate expression. If non of the optimizations apply then this translation pushes two references on the stack: a reference to a newly created filter object and a reference to the predicate's closure. See class Step for further details.

Overrides:
translate in class Expression
Parameters:
classGen - BCEL Java class generator
methodGen - BCEL Java method generator