org.apache.xalan.xsltc.compiler
Class Mode

java.lang.Object
  extended by org.apache.xalan.xsltc.compiler.Mode
All Implemented Interfaces:
Constants

final class Mode
extends java.lang.Object
implements Constants

Mode gathers all the templates belonging to a given mode; it is responsible for generating an appropriate applyTemplates + (mode name) method in the translet.


Field Summary
private  java.util.Vector _attribNodeGroup
          Group for patterns with node()-type kernel and attribute axis.
private  TestSeq _attribNodeTestSeq
          Test sequence for patterns with node()-type kernel and attribute axis.
private  java.util.Vector _childNodeGroup
          Group for patterns with node()-type kernel and child axis.
private  TestSeq _childNodeTestSeq
          Test sequence for patterns with node()-type kernel and child axis.
private  int _currentIndex
          Variable index for the current node used in code generation.
private  java.util.Vector _idxGroup
          Group for patterns with id() or key()-type kernel.
private  TestSeq _idxTestSeq
          Test sequence for patterns with id() or key()-type kernel.
private  java.util.Hashtable _importLevels
          Stores ranges of template precendences for the compilation of apply-imports (a Hashtable for historical reasons).
private  java.util.Hashtable _keys
          A mapping between key names and keys.
private  java.lang.String _methodName
          The name of the method in which this mode is compiled.
private  QName _name
          The name of this mode as defined in the stylesheet.
private  java.util.Hashtable _namedTemplates
          A mapping between named templates and Mode objects.
private  java.util.Hashtable _neededTemplates
          A mapping between templates and test sequences.
private  java.util.Vector[] _patternGroups
          Group for patterns with any other kernel type.
private  LocationPathPattern _rootPattern
          A reference to the pattern matching the root node.
private  Stylesheet _stylesheet
          A reference to the stylesheet object that owns this mode.
private  java.util.Hashtable _templateIHs
          A mapping between templates and instruction handles.
private  java.util.Hashtable _templateILs
          A mapping between templates and instruction lists.
private  java.util.Vector _templates
          A vector of all the templates in this mode.
private  TestSeq[] _testSeq
          Test sequence for patterns with any other kernel type.
 
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
Mode(QName name, Stylesheet stylesheet, java.lang.String suffix)
          Creates a new Mode.
 
Method Summary
private  void addPattern(int kernelType, LocationPathPattern pattern)
          Adds a pattern to a pattern group
private  void addPatternToGroup(LocationPathPattern lpp)
          Group patterns by NodeTests of their last Step Keep them sorted by priority within group
 void addTemplate(Template template)
           
private  void appendTemplateCode(InstructionList body)
           
private  void appendTestSequences(InstructionList body)
           
 void compileApplyImports(ClassGenerator classGen, int min, int max)
           
 void compileApplyTemplates(ClassGenerator classGen)
          Compiles the applyTemplates() method and adds it to the translet.
private  InstructionList compileDefaultRecursion(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next)
          Compiles the default handling for DOM elements: traverse all children
private  InstructionList compileDefaultText(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next)
          Compiles the default action for DOM text nodes and attribute nodes: output the node's text value
static void compileGetChildren(ClassGenerator classGen, MethodGenerator methodGen, int node)
           
private  void compileNamedTemplate(Template template, ClassGenerator classGen)
           
private  InstructionList compileNamespaces(ClassGenerator classGen, MethodGenerator methodGen, boolean[] isNamespace, boolean[] isAttribute, boolean attrFlag, InstructionHandle defaultTarget)
           
private  void compileTemplateCalls(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next, int min, int max)
           
private  void compileTemplates(ClassGenerator classGen, MethodGenerator methodGen, InstructionHandle next)
           
private  void completeTestSequences(int nodeType, java.util.Vector patterns)
          Complete test sequences of a given type by adding all patterns from a given group.
private  void flattenAlternative(Pattern pattern, Template template, java.util.Hashtable keys)
          This method will break up alternative patterns (ie.
 java.lang.String functionName()
          Returns the name of the method (_not_ function) that will be compiled for this mode.
 java.lang.String functionName(int min, int max)
           
private  java.lang.String getClassName()
          Shortcut to get the class compiled for this mode (will be inlined).
 Stylesheet getStylesheet()
           
 InstructionHandle getTemplateInstructionHandle(Template template)
           
private static boolean isAttributeName(java.lang.String qname)
          Auxiliary method to determine if a qname is an attribute.
private static boolean isNamespaceName(java.lang.String qname)
          Auxiliary method to determine if a qname is a namespace qualified "*".
private  int partition(java.util.Vector templates, int p, int r)
           
private  void peepHoleOptimization(MethodGenerator methodGen)
          Peephole optimization.
private  void prepareTestSequences()
          Build test sequences.
 void processPatterns(java.util.Hashtable keys)
          Process all the test patterns in this mode
private  java.util.Vector quicksort(java.util.Vector templates, int p, int r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_name

private final QName _name
The name of this mode as defined in the stylesheet.


_stylesheet

private final Stylesheet _stylesheet
A reference to the stylesheet object that owns this mode.


_methodName

private final java.lang.String _methodName
The name of the method in which this mode is compiled.


_templates

private java.util.Vector _templates
A vector of all the templates in this mode.


_childNodeGroup

private java.util.Vector _childNodeGroup
Group for patterns with node()-type kernel and child axis.


_childNodeTestSeq

private TestSeq _childNodeTestSeq
Test sequence for patterns with node()-type kernel and child axis.


_attribNodeGroup

private java.util.Vector _attribNodeGroup
Group for patterns with node()-type kernel and attribute axis.


_attribNodeTestSeq

private TestSeq _attribNodeTestSeq
Test sequence for patterns with node()-type kernel and attribute axis.


_idxGroup

private java.util.Vector _idxGroup
Group for patterns with id() or key()-type kernel.


_idxTestSeq

private TestSeq _idxTestSeq
Test sequence for patterns with id() or key()-type kernel.


_patternGroups

private java.util.Vector[] _patternGroups
Group for patterns with any other kernel type.


_testSeq

private TestSeq[] _testSeq
Test sequence for patterns with any other kernel type.


_neededTemplates

private java.util.Hashtable _neededTemplates
A mapping between templates and test sequences.


_namedTemplates

private java.util.Hashtable _namedTemplates
A mapping between named templates and Mode objects.


_templateIHs

private java.util.Hashtable _templateIHs
A mapping between templates and instruction handles.


_templateILs

private java.util.Hashtable _templateILs
A mapping between templates and instruction lists.


_rootPattern

private LocationPathPattern _rootPattern
A reference to the pattern matching the root node.


_importLevels

private java.util.Hashtable _importLevels
Stores ranges of template precendences for the compilation of apply-imports (a Hashtable for historical reasons).


_keys

private java.util.Hashtable _keys
A mapping between key names and keys.


_currentIndex

private int _currentIndex
Variable index for the current node used in code generation.

Constructor Detail

Mode

public Mode(QName name,
            Stylesheet stylesheet,
            java.lang.String suffix)
Creates a new Mode.

Parameters:
name - A textual representation of the mode's QName
stylesheet - The Stylesheet in which the mode occured
suffix - A suffix to append to the method name for this mode (normally a sequence number - still in a String).
Method Detail

functionName

public java.lang.String functionName()
Returns the name of the method (_not_ function) that will be compiled for this mode. Normally takes the form 'applyTemplates()' or * 'applyTemplates2()'.

Returns:
Method name for this mode

functionName

public java.lang.String functionName(int min,
                                     int max)

getClassName

private java.lang.String getClassName()
Shortcut to get the class compiled for this mode (will be inlined).


getStylesheet

public Stylesheet getStylesheet()

addTemplate

public void addTemplate(Template template)

quicksort

private java.util.Vector quicksort(java.util.Vector templates,
                                   int p,
                                   int r)

partition

private int partition(java.util.Vector templates,
                      int p,
                      int r)

processPatterns

public void processPatterns(java.util.Hashtable keys)
Process all the test patterns in this mode


flattenAlternative

private void flattenAlternative(Pattern pattern,
                                Template template,
                                java.util.Hashtable keys)
This method will break up alternative patterns (ie. unions of patterns, such as match="A/B | C/B") and add the basic patterns to their respective pattern groups.


addPatternToGroup

private void addPatternToGroup(LocationPathPattern lpp)
Group patterns by NodeTests of their last Step Keep them sorted by priority within group


addPattern

private void addPattern(int kernelType,
                        LocationPathPattern pattern)
Adds a pattern to a pattern group


completeTestSequences

private void completeTestSequences(int nodeType,
                                   java.util.Vector patterns)
Complete test sequences of a given type by adding all patterns from a given group.


prepareTestSequences

private void prepareTestSequences()
Build test sequences. The first step is to complete the test sequences by including patterns of "*" and "node()" kernel to all element test sequences, and of "@*" to all attribute test sequences.


compileNamedTemplate

private void compileNamedTemplate(Template template,
                                  ClassGenerator classGen)

compileTemplates

private void compileTemplates(ClassGenerator classGen,
                              MethodGenerator methodGen,
                              InstructionHandle next)

appendTemplateCode

private void appendTemplateCode(InstructionList body)

appendTestSequences

private void appendTestSequences(InstructionList body)

compileGetChildren

public static void compileGetChildren(ClassGenerator classGen,
                                      MethodGenerator methodGen,
                                      int node)

compileDefaultRecursion

private InstructionList compileDefaultRecursion(ClassGenerator classGen,
                                                MethodGenerator methodGen,
                                                InstructionHandle next)
Compiles the default handling for DOM elements: traverse all children


compileDefaultText

private InstructionList compileDefaultText(ClassGenerator classGen,
                                           MethodGenerator methodGen,
                                           InstructionHandle next)
Compiles the default action for DOM text nodes and attribute nodes: output the node's text value


compileNamespaces

private InstructionList compileNamespaces(ClassGenerator classGen,
                                          MethodGenerator methodGen,
                                          boolean[] isNamespace,
                                          boolean[] isAttribute,
                                          boolean attrFlag,
                                          InstructionHandle defaultTarget)

compileApplyTemplates

public void compileApplyTemplates(ClassGenerator classGen)
Compiles the applyTemplates() method and adds it to the translet. This is the main dispatch method.


compileTemplateCalls

private void compileTemplateCalls(ClassGenerator classGen,
                                  MethodGenerator methodGen,
                                  InstructionHandle next,
                                  int min,
                                  int max)

compileApplyImports

public void compileApplyImports(ClassGenerator classGen,
                                int min,
                                int max)

peepHoleOptimization

private void peepHoleOptimization(MethodGenerator methodGen)
Peephole optimization.


getTemplateInstructionHandle

public InstructionHandle getTemplateInstructionHandle(Template template)

isAttributeName

private static boolean isAttributeName(java.lang.String qname)
Auxiliary method to determine if a qname is an attribute.


isNamespaceName

private static boolean isNamespaceName(java.lang.String qname)
Auxiliary method to determine if a qname is a namespace qualified "*".