You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mo...@apache.org on 2001/11/08 11:23:39 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler AttributeValueTemplate.java Constants.java FilterParentPath.java LiteralAttribute.java LiteralElement.java LiteralExpr.java Mode.java ParentLocationPath.java Parser.java SimpleAttributeValue.java SyntaxTreeNode.java Text.java UnionPathExpr.java

morten      01/11/08 02:23:39

  Modified:    java/src/org/apache/xalan/xsltc/compiler
                        AttributeValueTemplate.java Constants.java
                        FilterParentPath.java LiteralAttribute.java
                        LiteralElement.java LiteralExpr.java Mode.java
                        ParentLocationPath.java Parser.java
                        SimpleAttributeValue.java SyntaxTreeNode.java
                        Text.java UnionPathExpr.java
  Log:
  A bit of a code cleanup. I also added a small fix for ensuring document order
  of node sets returned by union expressions.
  PR:		bugzilla 4677
  Obtained from:	n/a
  Submitted by:	morten@xml.apache.org
  Reviewed by:	morten@xml.apache.org
  
  Revision  Changes    Path
  1.4       +5 -7      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/AttributeValueTemplate.java
  
  Index: AttributeValueTemplate.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/AttributeValueTemplate.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AttributeValueTemplate.java	2001/10/30 08:42:55	1.3
  +++ AttributeValueTemplate.java	2001/11/08 10:23:39	1.4
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: AttributeValueTemplate.java,v 1.3 2001/10/30 08:42:55 morten Exp $
  + * @(#)$Id: AttributeValueTemplate.java,v 1.4 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -195,10 +195,6 @@
   	}
       }
   
  -    private void reportError(String value, Parser parser) {
  -	reportError(getParent(), parser, ErrorMsg.ATTR_VAL_TEMPLATE_ERR, value);
  -    }
  -
       private boolean check(String value, Parser parser) {
   	// !!! how about quoted/escaped braces?
   	if (value == null) return true;
  @@ -227,12 +223,14 @@
   	    case 1:
   		continue;
   	    default:
  -		reportError(value, parser);
  +		reportError(getParent(), parser,
  +			    ErrorMsg.ATTR_VAL_TEMPLATE_ERR, value);
   		return false;
   	    }
   	}
   	if (level != 0) {
  -	    reportError(value, parser);
  +	    reportError(getParent(), parser,
  +			ErrorMsg.ATTR_VAL_TEMPLATE_ERR, value);
   	    return false;
   	}
   	return true;
  
  
  
  1.15      +6 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Constants.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Constants.java	2001/09/21 11:55:55	1.14
  +++ Constants.java	2001/11/08 10:23:39	1.15
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Constants.java,v 1.14 2001/09/21 11:55:55 morten Exp $
  + * @(#)$Id: Constants.java,v 1.15 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -406,6 +406,11 @@
   	
       public static final String ADD_ITERATOR_SIG   
   	= "(" + NODE_ITERATOR_SIG +")" + UNION_ITERATOR_SIG;
  +
  +    public static final String ORDER_ITERATOR
  +	= "orderNodes";
  +    public static final String ORDER_ITERATOR_SIG
  +	= "("+NODE_ITERATOR_SIG+"I)"+NODE_ITERATOR_SIG;
   	
       public static final String SET_START_NODE_SIG   
   	= "(" + NODE_SIG + ")" + NODE_ITERATOR_SIG;
  
  
  
  1.8       +3 -4      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FilterParentPath.java
  
  Index: FilterParentPath.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/FilterParentPath.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- FilterParentPath.java	2001/10/18 10:57:41	1.7
  +++ FilterParentPath.java	2001/11/08 10:23:39	1.8
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: FilterParentPath.java,v 1.7 2001/10/18 10:57:41 morten Exp $
  + * @(#)$Id: FilterParentPath.java,v 1.8 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -157,10 +157,9 @@
   
   	if (!(getParent() instanceof RelativeLocationPath) &&
   	    !(getParent() instanceof FilterParentPath)) {
  -	    String params = "("+NODE_ITERATOR_SIG+"I)"+NODE_ITERATOR_SIG;
   	    final int order = cpg.addInterfaceMethodref(DOM_INTF,
  -							"orderNodes",
  -							params);
  +							ORDER_ITERATOR,
  +							ORDER_ITERATOR_SIG);
   	    il.append(methodGen.loadDOM());
   	    il.append(SWAP);
   	    il.append(methodGen.loadContextNode());
  
  
  
  1.3       +11 -4     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralAttribute.java
  
  Index: LiteralAttribute.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralAttribute.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LiteralAttribute.java	2001/06/06 10:45:08	1.2
  +++ LiteralAttribute.java	2001/11/08 10:23:39	1.3
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: LiteralAttribute.java,v 1.2 2001/06/06 10:45:08 morten Exp $
  + * @(#)$Id: LiteralAttribute.java,v 1.3 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -69,9 +69,16 @@
   import org.apache.xalan.xsltc.compiler.util.*;
   
   final class LiteralAttribute extends Instruction {
  -    private final String  _name;
  -    private final AttributeValue _value;
   
  +    private final String  _name;         // Attribute name (incl. prefix)
  +    private final AttributeValue _value; // Attribute value
  +
  +    /**
  +     * Creates a new literal attribute (but does not insert it into the AST).
  +     * @param name the attribute name (incl. prefix) as a String.
  +     * @param value the attribute value.
  +     * @param parser the XSLT parser (wraps XPath parser).
  +     */
       public LiteralAttribute(String name, String value, Parser parser) {
   	_name = name;
   	_value = AttributeValue.create(this, value, parser);
  @@ -88,7 +95,7 @@
   	return Type.Void;
       }
   
  -    public boolean contextDependent() {
  +    protected boolean contextDependent() {
   	return _value.contextDependent();
       }
   
  
  
  
  1.13      +3 -6      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java
  
  Index: LiteralElement.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralElement.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- LiteralElement.java	2001/10/17 09:43:12	1.12
  +++ LiteralElement.java	2001/11/08 10:23:39	1.13
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: LiteralElement.java,v 1.12 2001/10/17 09:43:12 morten Exp $
  + * @(#)$Id: LiteralElement.java,v 1.13 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -103,7 +103,7 @@
       /**
        * Returns the namespace URI for which a prefix is pointing to
        */
  -    public String accessedNamespace(String prefix) {
  +    private String accessedNamespace(String prefix) {
   	if (_accessedPrefixes == null)
   	    return(null);
   	else
  @@ -337,10 +337,7 @@
   	}
       }
   
  -    /**
  -     * 
  -     */
  -    public boolean contextDependent() {
  +    protected boolean contextDependent() {
   	return dependentContents();
       }
   
  
  
  
  1.3       +13 -4     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralExpr.java
  
  Index: LiteralExpr.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LiteralExpr.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LiteralExpr.java	2001/06/06 10:45:11	1.2
  +++ LiteralExpr.java	2001/11/08 10:23:39	1.3
  @@ -1,6 +1,6 @@
   
   /*
  - * @(#)$Id: LiteralExpr.java,v 1.2 2001/06/06 10:45:11 morten Exp $
  + * @(#)$Id: LiteralExpr.java,v 1.3 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -72,11 +72,20 @@
       private final String _value;
       private final String _namespace;
   
  +    /**
  +     * Creates a new literal expression node.
  +     * @param value the literal expression content/value.
  +     */
       public LiteralExpr(String value) {
   	_value = value;
   	_namespace = null;
       }
   
  +    /**
  +     * Creates a new literal expression node.
  +     * @param value the literal expression content/value.
  +     * @param namespace the namespace in which the expression exists.
  +     */
       public LiteralExpr(String value, String namespace) {
   	_value = value;
   	if (namespace.equals(Constants.EMPTYSTRING))
  @@ -93,15 +102,15 @@
   	return "literal-expr(" + _value + ')';
       }
   
  -    public boolean contextDependent() {
  +    protected boolean contextDependent() {
   	return false;
       }
   
  -    public String getValue() {
  +    protected String getValue() {
   	return _value;
       }
   
  -    public String getNamespace() {
  +    protected String getNamespace() {
   	return _namespace;
       }
   
  
  
  
  1.17      +2 -2      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Mode.java
  
  Index: Mode.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Mode.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Mode.java	2001/10/31 16:00:10	1.16
  +++ Mode.java	2001/11/08 10:23:39	1.17
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Mode.java,v 1.16 2001/10/31 16:00:10 morten Exp $
  + * @(#)$Id: Mode.java,v 1.17 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -84,7 +84,7 @@
       private final QName      _name;       // The QName of this mode
       private final Stylesheet _stylesheet; // The owning stylesheet
       private final String     _methodName; // The method name for this mode
  -    private Vector     _templates;  // All templates in this mode
  +    private Vector           _templates;  // All templates in this mode
   
       // Pattern/test sequence for pattern with node()-type kernel
       private Vector    _nodeGroup = null;
  
  
  
  1.13      +3 -4      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParentLocationPath.java
  
  Index: ParentLocationPath.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParentLocationPath.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ParentLocationPath.java	2001/10/15 09:13:22	1.12
  +++ ParentLocationPath.java	2001/11/08 10:23:39	1.13
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: ParentLocationPath.java,v 1.12 2001/10/15 09:13:22 morten Exp $
  + * @(#)$Id: ParentLocationPath.java,v 1.13 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -232,10 +232,9 @@
   	 * and prevent returning a single node multiple times.
   	 */
   	if (_orderNodes) {
  -	    final String params = "("+NODE_ITERATOR_SIG+"I)"+NODE_ITERATOR_SIG;
   	    final int order = cpg.addInterfaceMethodref(DOM_INTF,
  -							"orderNodes",
  -							params);
  +							ORDER_ITERATOR,
  +							ORDER_ITERATOR_SIG);
   	    il.append(methodGen.loadDOM());
   	    il.append(SWAP);
   	    il.append(methodGen.loadContextNode());
  
  
  
  1.33      +3 -1      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Parser.java	2001/11/01 10:53:25	1.32
  +++ Parser.java	2001/11/08 10:23:39	1.33
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Parser.java,v 1.32 2001/11/01 10:53:25 morten Exp $
  + * @(#)$Id: Parser.java,v 1.33 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -967,6 +967,8 @@
   	SyntaxTreeNode.Dummy.setParser(this);
           return SyntaxTreeNode.Dummy; 
       }
  +
  +    /************************ ERROR HANDLING SECTION ************************/
   
       /**
        * Returns true if there were any errors during compilation
  
  
  
  1.2       +20 -6     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SimpleAttributeValue.java
  
  Index: SimpleAttributeValue.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SimpleAttributeValue.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimpleAttributeValue.java	2001/04/17 18:51:46	1.1
  +++ SimpleAttributeValue.java	2001/11/08 10:23:39	1.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: SimpleAttributeValue.java,v 1.1 2001/04/17 18:51:46 sboag Exp $
  + * @(#)$Id: SimpleAttributeValue.java,v 1.2 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -68,12 +68,21 @@
   import de.fub.bytecode.generic.*;
   
   final class SimpleAttributeValue extends AttributeValue {
  -    private String _value;
  -		
  +
  +    private String _value; // The attributes value (literate string).
  +
  +    /**
  +     * Creates a new simple attribute value.
  +     * @param value the attribute value.
  +     */
       public SimpleAttributeValue(String value) {
   	_value = value;
       }
  -		
  +
  +    /**
  +     * Returns this attribute value's type (String).
  +     * @param stable The compiler/parser's symbol table
  +     */
       public Type typeCheck(SymbolTable stable) throws TypeCheckError {
   	return _type = Type.String;
       }
  @@ -82,14 +91,19 @@
   	return _value;
       }
   	
  -    public boolean contextDependent() {
  +    protected boolean contextDependent() {
   	return false;
       }
   
  +    /**
  +     * Translate this attribute value into JVM bytecodes that pushes the
  +     * attribute value onto the JVM's stack.
  +     * @param classGen BCEL Java class generator
  +     * @param methodGen BCEL Java method generator
  +     */
       public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
   	final ConstantPoolGen cpg = classGen.getConstantPool();
   	final InstructionList il = methodGen.getInstructionList();
   	il.append(new PUSH(cpg, _value));
  -	display(0);
       }
   }
  
  
  
  1.15      +323 -117  xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java
  
  Index: SyntaxTreeNode.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- SyntaxTreeNode.java	2001/10/25 10:23:32	1.14
  +++ SyntaxTreeNode.java	2001/11/08 10:23:39	1.15
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: SyntaxTreeNode.java,v 1.14 2001/10/25 10:23:32 morten Exp $
  + * @(#)$Id: SyntaxTreeNode.java,v 1.15 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -87,61 +87,112 @@
       // Reference to the AST parser
       private Parser _parser;
   
  -    // This node's line number in the input file (not obtainable!!!!)
  -    private int _line;
  +    // AST navigation pointers
  +    protected SyntaxTreeNode _parent;          // Parent node
  +    private Stylesheet       _stylesheet;      // Stylesheet ancestor node
  +    private Template         _template;        // Template ancestor node
  +    private final Vector _contents = new Vector(2); // Child nodes
  +
  +    // Element description data
  +    protected QName _qname;                    // The element QName
  +    private int _line;                         // Source file line number
  +    protected Attributes _attributes = null;   // Attributes of this element
  +    private   Hashtable _prefixMapping = null; // Namespace declarations
   
  -    // Reference to this node's parent node
  -    protected SyntaxTreeNode _parent;
  -    // Contains all child nodes of this node
  -    private final Vector   _contents = new Vector(2);
  -
  -    // The QName of this element (contains uri, prefix and localname)
  -    protected QName      _qname;
  -    // The attributes (if any) of this element
  -    protected Attributes _attributes = null;
  -    // The namespace declarations (if any) of this element
  -    private   Hashtable _prefixMapping = null;
  +    // Sentinel - used to denote unrecognised syntaxt tree nodes.
  +    protected static final SyntaxTreeNode Dummy = new AbsolutePathPattern(null);
   
  -    // Sentinel
  -    public static final SyntaxTreeNode Dummy = new AbsolutePathPattern(null);
  -
       // These two are used for indenting nodes in the AST (debug output)
  +    protected static final int IndentIncrement = 4;
       private static final char[] _spaces = 
   	"                                                       ".toCharArray();
  -    protected static final int IndentIncrement = 4;
   
  +    /**
  +     * Creates a new SyntaxTreeNode with a 'null' QName and no source file
  +     * line number reference.
  +     */
       public SyntaxTreeNode() {
   	_line = 0;
   	_qname = null;
       }
   
  +    /**
  +     * Creates a new SyntaxTreeNode with a 'null' QName.
  +     * @param line Source file line number reference
  +     */
       public SyntaxTreeNode(int line) {
   	_line = line;
   	_qname = null;
       }
   
  -    public SyntaxTreeNode(String uri, String prefix, String localname) {
  +    /**
  +     * Creates a new SyntaxTreeNode with no source file line number reference.
  +     * @param uri The element's namespace URI
  +     * @param prefix The element's namespace prefix
  +     * @param local The element's local name
  +     */
  +    public SyntaxTreeNode(String uri, String prefix, String local) {
   	_line = 0;
  -	setQName(uri, prefix, localname);
  +	setQName(uri, prefix, local);
  +    }
  +
  +    /**
  +     * Set the source file line number for this element
  +     * @param line The source file line number.
  +     */
  +    protected final void setLineNumber(int line) {
  +	_line = line;
  +    }
  +
  +    /**
  +     * Get the source file line number for this element
  +     * @return The source file line number.
  +     */
  +    public final int getLineNumber() {
  +	return _line;
       }
   
  -    public void setQName(QName qname) {
  +    /**
  +     * Set the QName for the syntax tree node.
  +     * @param qname The QName for the syntax tree node
  +     */
  +    protected void setQName(QName qname) {
   	_qname = qname;
       }
   
  -    public void setQName(String uri, String prefix, String localname) {
  +    /**
  +     * Set the QName for the SyntaxTreeNode
  +     * @param uri The element's namespace URI
  +     * @param prefix The element's namespace prefix
  +     * @param local The element's local name
  +     */
  +    protected void setQName(String uri, String prefix, String localname) {
   	_qname = new QName(uri, prefix, localname);
       }
   
  -    public QName getQName() {
  +    /**
  +     * Set the QName for the SyntaxTreeNode
  +     * @param qname The QName for the syntax tree node
  +     */
  +    protected QName getQName() {
   	return(_qname);
       }
   
  -    public void setAttributes(Attributes attributes) {
  +    /**
  +     * Set the attributes for this SyntaxTreeNode.
  +     * @param attributes Attributes for the element. Must be passed in as an
  +     *                   implementation of org.xml.sax.Attributes.
  +     */
  +    protected void setAttributes(Attributes attributes) {
   	_attributes = attributes;
       }
   
  -    public String getAttribute(String qname) {
  +    /**
  +     * Returns a value for an attribute from the source element.
  +     * @param qname The QName of the attribute to return.
  +     * @return The value of the attribute of name 'qname'.
  +     */
  +    protected String getAttribute(String qname) {
   	if (_attributes == null)
   	    return(Constants.EMPTYSTRING);
   	final String value = _attributes.getValue(qname);
  @@ -151,25 +202,58 @@
   	    return(value);
       }
   
  -    public Attributes getAttributes() {
  +    /**
  +     * Returns a list of all attributes declared for the element represented by
  +     * this syntax tree node.
  +     * @return Attributes for this syntax tree node
  +     */
  +    protected Attributes getAttributes() {
   	return(_attributes);
       }
   
  -    public void setPrefixMapping(Hashtable mapping) {
  +    /**
  +     * Sets the prefix mapping for the namespaces that were declared in this
  +     * element. This does not include all prefix mappings in scope, so one
  +     * may have to check ancestor elements to get all mappings that are in
  +     * in scope. The prefixes must be passed in as a Hashtable that maps
  +     * namespace prefixes (String objects) to namespace URIs (also String).
  +     * @param mapping The Hashtable containing the mappings.
  +     */
  +    protected void setPrefixMapping(Hashtable mapping) {
   	_prefixMapping = mapping;
       }
   
  -    public Hashtable getPrefixMapping() {
  +    /**
  +     * Returns a Hashtable containing the prefix mappings that were declared
  +     * for this element. This does not include all prefix mappings in scope,
  +     * so one may have to check ancestor elements to get all mappings that are
  +     * in in scope. 
  +     * @return Prefix mappings (for this element only).
  +     */
  +    protected Hashtable getPrefixMapping() {
   	return _prefixMapping;
       }
   
  -    public void addPrefixMapping(String prefix, String uri) {
  +    /**
  +     * Adds a single prefix mapping to this syntax tree node.
  +     * @param prefix Namespace prefix.
  +     * @param uri Namespace URI.
  +     */
  +    protected void addPrefixMapping(String prefix, String uri) {
   	if (_prefixMapping == null)
   	    _prefixMapping = new Hashtable();
   	_prefixMapping.put(prefix, uri);
       }
   
  -    public String lookupNamespace(String prefix) {
  +    /**
  +     * Returns any namespace URI that is in scope for a given prefix. This
  +     * method checks namespace mappings for this element, and if necessary
  +     * for ancestor elements as well (ie. if the prefix maps to an URI in this
  +     * scope then you'll definately get the URI from this method).
  +     * @param prefix Namespace prefix.
  +     * @return Namespace URI.
  +     */
  +    protected String lookupNamespace(String prefix) {
   	// Initialise the output (default is 'null' for undefined)
   	String uri = null;
   
  @@ -186,7 +270,17 @@
   	return(uri);
       }
   
  -    public String lookupPrefix(String uri) {
  +    /**
  +     * Returns any namespace prefix that is mapped to a prefix in the current
  +     * scope. This method checks namespace mappings for this element, and if
  +     * necessary for ancestor elements as well (ie. if the URI is declared
  +     * within the current scope then you'll definately get the prefix from
  +     * this method). Note that this is a very slow method and consequentially
  +     * it should only be used strictly when needed.
  +     * @param uri Namespace URI.
  +     * @return Namespace prefix.
  +     */
  +    protected String lookupPrefix(String uri) {
   	// Initialise the output (default is 'null' for undefined)
   	String prefix = null;
   
  @@ -209,55 +303,106 @@
   	return(prefix);
       }
   
  -    public void setParser(Parser parser) {
  +    /**
  +     * Set this node's parser. The parser (the XSLT parser) gives this
  +     * syntax tree node access to the symbol table and XPath parser.
  +     * @param parser The XSLT parser.
  +     */
  +    protected void setParser(Parser parser) {
   	_parser = parser;
       }
   
  +    /**
  +     * Returns this node's XSLT parser.
  +     * @return The XSLT parser.
  +     */
  +    public final Parser getParser() {
  +	return _parser;
  +    }
  +
  +    /**
  +     * Set this syntax tree node's parent node
  +     * @param parent The parent node.
  +     */
       protected void setParent(SyntaxTreeNode parent) {
   	if (_parent == null)
   	    _parent = parent;
       }
  -    
  -    public final SyntaxTreeNode getParent() {
  +
  +    /**
  +     * Returns this syntax tree node's parent node.
  +     * @return The parent syntax tree node.
  +     */
  +    protected final SyntaxTreeNode getParent() {
   	return _parent;
       }
   
  -    public Stylesheet getStylesheet() {
  -	SyntaxTreeNode parent = this;
  -	while (parent != null) {
  -	    if (parent instanceof Stylesheet)
  -		return((Stylesheet)parent);
  -	    parent = parent.getParent();
  -	}
  -	return((Stylesheet)parent);
  +    /**
  +     * Returns 'true' if this syntax tree node is the Sentinal node.
  +     * @return 'true' if this syntax tree node is the Sentinal node.
  +     */
  +    protected final boolean isDummy() {
  +        return this == Dummy;
       }
   
  -    public int getImportPrecedence() {
  +    /**
  +     * Get the import precedence of this element. The import precedence equals
  +     * the import precedence of the stylesheet in which this element occured.
  +     * @return The import precedence of this syntax tree node.
  +     */
  +    protected int getImportPrecedence() {
   	Stylesheet stylesheet = getStylesheet();
  -	if (stylesheet == null) return -666;
  +	if (stylesheet == null) return Integer.MIN_VALUE;
   	return stylesheet.getImportPrecedence();
       }
  -
  -    protected Template getTemplate() {
  -	SyntaxTreeNode parent = this;
  -	while ((parent != null) && (!(parent instanceof Template)))
  -	    parent = parent.getParent();
  -	return((Template)parent);
  -    }
   
  -    public final boolean isDummy() {
  -        return this == Dummy;
  +    /**
  +     * Get the Stylesheet node that represents the <xsl:stylesheet/> element
  +     * that this node occured under.
  +     * @return The Stylesheet ancestor node of this node.
  +     */
  +    public Stylesheet getStylesheet() {
  +	if (_stylesheet == null) {
  +	    SyntaxTreeNode parent = this;
  +	    while (parent != null) {
  +		if (parent instanceof Stylesheet)
  +		    return((Stylesheet)parent);
  +		parent = parent.getParent();
  +	    }
  +	    _stylesheet = (Stylesheet)parent;
  +	}
  +	return(_stylesheet);
       }
   
  -    public final Parser getParser() {
  -	return _parser;
  +    /**
  +     * Get the Template node that represents the <xsl:template/> element
  +     * that this node occured under. Note that this method will return 'null'
  +     * for nodes that represent top-level elements.
  +     * @return The Template ancestor node of this node or 'null'.
  +     */
  +    protected Template getTemplate() {
  +	if (_template == null) {
  +	    SyntaxTreeNode parent = this;
  +	    while ((parent != null) && (!(parent instanceof Template)))
  +		parent = parent.getParent();
  +	    _template = (Template)parent;
  +	}
  +	return(_template);
       }
   
  -    public final XSLTC getXSLTC() {
  +    /**
  +     * Returns a reference to the XSLTC (XSLT compiler) in use.
  +     * @return XSLTC - XSLT compiler.
  +     */
  +    protected final XSLTC getXSLTC() {
   	return _parser.getXSLTC();
       }
   
  -    public final SymbolTable getSymbolTable() {
  +    /**
  +     * Returns the XSLT parser's symbol table.
  +     * @return Symbol table.
  +     */
  +    protected final SymbolTable getSymbolTable() {
   	if (_parser != null)
   	    return _parser.getSymbolTable();
   	else
  @@ -265,26 +410,35 @@
       }
   
       /**
  -     * To be overridden in nodes implemented by code outside of applyTemplates
  -     * eg. in Predicates
  +     * Local variables that are accessible from a given syntax tree node will
  +     * be put on the JVM's stack. A closure is a record that contains a pointer
  +     * to a node's outer variable frame (not only global variables, but also
  +     * variables in parent nodes). This method returns true if this node's code
  +     * is implemented by code outside of ApplyTemplates (the only such case is
  +     * the Predicates class). This methid is only called by the VariableRef).
  +     * @return 'true' if node's code is implemented outside of ApplyTemplates
        */
       protected boolean isClosureBoundary() {
   	return false;
       }
   
       /**
  -     * This method is normally overriden by subclasses.
  -     * By default, it parses all the children of <tt>element</tt>.
  +     * Parse the contents of this syntax tree nodes (child nodes, XPath
  +     * expressions, patterns and functions). The default behaviour is to parser
  +     * the syntax tree node's children (since there are no common expressions,
  +     * patterns, etc. that can be handled in this base class.
  +     * @param parser reference to the XSLT parser
        */
       public void parseContents(Parser parser) {
   	parseChildren(parser);
       }
   
       /**
  -     * Parse all the children of <tt>element</tt>.
  -     * XSLT commands are recognized by the XSLT namespace
  +     * Parse all children of this syntax tree node. This method is normally
  +     * called by the parseContents() method.
  +     * @param parser reference to the XSLT parser
        */
  -    public final void parseChildren(Parser parser) {
  +    protected final void parseChildren(Parser parser) {
   
   	Vector locals = null;	// only create when needed
   	
  @@ -337,13 +491,15 @@
       /**
        * Type check the children of this node. The type check phase may add
        * coercions (CastExpr) to the AST.
  +     * @param stable The compiler/parser's symbol table
        */
       public abstract Type typeCheck(SymbolTable stable) throws TypeCheckError;
   
       /**
  -     * Call typeCheck() on every children of this node.
  +     * Call typeCheck() on all child syntax tree nodes.
  +     * @param stable The compiler/parser's symbol table
        */
  -    public Type typeCheckContents(SymbolTable stable) throws TypeCheckError {
  +    protected Type typeCheckContents(SymbolTable stable) throws TypeCheckError {
   	final int n = elementCount();
   	for (int i = 0; i < n; i++) {
   	    SyntaxTreeNode item = (SyntaxTreeNode)_contents.elementAt(i);
  @@ -353,29 +509,32 @@
       }
   
       /**
  -     * Translate this node into JVM bytecodes.
  +     * Translate this abstract syntax tree node into JVM bytecodes.
  +     * @param classGen BCEL Java class generator
  +     * @param methodGen BCEL Java method generator
        */
       public abstract void translate(ClassGenerator classGen,
   				   MethodGenerator methodGen);
   
       /**
  -     * Call translate() on every children of this node.
  -     */
  -    public void translateContents(ClassGenerator classGen,
  -				  MethodGenerator methodGen) {
  +     * Call translate() on all child syntax tree nodes.
  +     * @param classGen BCEL Java class generator
  +     * @param methodGen BCEL Java method generator
  +     */
  +    protected void translateContents(ClassGenerator classGen,
  +				     MethodGenerator methodGen) {
  +	// Call translate() on all child nodes
   	final int n = elementCount();
   	for (int i = 0; i < n; i++) {
   	    final SyntaxTreeNode item = (SyntaxTreeNode)_contents.elementAt(i);
   	    item.translate(classGen, methodGen);
   	}
   
  -	/**
  -	 * After translation, unmap any registers for any variables/parameters
  -	 * that were declared in this scope. Performing this unmapping in the
  -	 * same AST scope as the declaration deals with the problems of
  -	 * references falling out-of-scope inside the for-each element.
  -	 * (the cause of which being 'lazy' register allocation for references)
  -	 */
  +	// After translation, unmap any registers for any variables/parameters
  +	// that were declared in this scope. Performing this unmapping in the
  +	// same AST scope as the declaration deals with the problems of
  +	// references falling out-of-scope inside the for-each element.
  +	// (the cause of which being 'lazy' register allocation for references)
   	for (int i = 0; i < n; i++) {
   	    if( _contents.elementAt(i) instanceof VariableBase) {
   		final VariableBase var = (VariableBase)_contents.elementAt(i);
  @@ -386,9 +545,11 @@
   
       /**
        * Utility method used by parameters and variables to store result trees
  +     * @param classGen BCEL Java class generator
  +     * @param methodGen BCEL Java method generator
        */
  -    public void compileResultTree(ClassGenerator classGen,
  -				  MethodGenerator methodGen) {
  +    protected void compileResultTree(ClassGenerator classGen,
  +				     MethodGenerator methodGen) {
   
   	final ConstantPoolGen cpg = classGen.getConstantPool();
   	final InstructionList il = methodGen.getInstructionList();
  @@ -443,20 +604,6 @@
   	    il.append(new ANEWARRAY(cpg.addClass(STRING)));
   	    il.append(DUP);
   	    il.append(new INVOKESPECIAL(index)); // leave DOMAdapter on stack
  -	    
  -	    // Must we wrap the DOMAdapter object in a MultiDOM object?
  -	    /* Not needed with new design using DOM interface instead of
  -	       referencing DOM classes directly
  -	    if (DOM_CLASS.equals(MULTI_DOM_CLASS)) {
  -		// new org.apache.xalan.xsltc.dom.MultiDOM(DOMAdapter);
  -		index = cpg.addMethodref(MULTI_DOM_CLASS, "<init>",
  -					 "("+DOM_INTF_SIG+")V");
  -		il.append(new NEW(cpg.addClass(MULTI_DOM_CLASS)));
  -		il.append(new DUP_X1());
  -		il.append(SWAP);
  -		il.append(new INVOKESPECIAL(index)); // leave MultiDOM on stack
  -	    }
  -	    */
   	}
   
   	// Restore old handler base from stack
  @@ -468,17 +615,19 @@
        * Returns true if this expression/instruction depends on the context. By 
        * default, every expression/instruction depends on the context unless it 
        * overrides this method. Currently used to determine if result trees are 
  -     * compiled using procedures or little DOMs.
  +     * compiled using procedures or little DOMs (result tree fragments).
  +     * @return 'true' if this node depends on the context.
        */
  -    public boolean contextDependent() {
  +    protected boolean contextDependent() {
   	return true;
       }
   
       /**
        * Return true if any of the expressions/instructions in the contents of
        * this node is context dependent.
  +     * @return 'true' if the contents of this node is context dependent.
        */
  -    public boolean dependentContents() {
  +    protected boolean dependentContents() {
   	final int n = elementCount();
   	for (int i = 0; i < n; i++) {
   	    final SyntaxTreeNode item = (SyntaxTreeNode)_contents.elementAt(i);
  @@ -489,45 +638,90 @@
   	return false;
       }
   
  -    public final void addElement(SyntaxTreeNode element) {
  +    /**
  +     * Adds a child node to this syntax tree node.
  +     * @param element is the new child node.
  +     */
  +    protected final void addElement(SyntaxTreeNode element) {
   	_contents.addElement(element);
   	element.setParent(this);
       }
   
  -    public final void setFirstElement(SyntaxTreeNode element) {
  +    /**
  +     * Inserts the first child node of this syntax tree node. The existing
  +     * children are shifted back one position.
  +     * @param element is the new child node.
  +     */
  +    protected final void setFirstElement(SyntaxTreeNode element) {
   	_contents.insertElementAt(element,0);
   	element.setParent(this);
       }
   
  -    public final void removeElement(SyntaxTreeNode element) {
  +    /**
  +     * Removed a child node of this syntax tree node.
  +     * @param element is the child node to remove.
  +     */
  +    protected final void removeElement(SyntaxTreeNode element) {
   	_contents.remove(element);
   	element.setParent(null);
       }
   
  -    public final Vector getContents() {
  +    /**
  +     * Returns a Vector containing all the child nodes of this node.
  +     * @return A Vector containing all the child nodes of this node.
  +     */
  +    protected final Vector getContents() {
   	return _contents;
       }
   
  -    public final boolean hasContents() {
  +    /**
  +     * Tells you if this node has any child nodes.
  +     * @return 'true' if this node has any children.
  +     */
  +    protected final boolean hasContents() {
   	return elementCount() > 0;
       }
   
  -    public final int elementCount() {
  +    /**
  +     * Returns the number of children this node has.
  +     * @return Number of child nodes.
  +     */
  +    protected final int elementCount() {
   	return _contents.size();
       }
  -	
  -    public final Enumeration elements() {
  +
  +    /**
  +     * Returns an Enumeration of all child nodes of this node.
  +     * @return An Enumeration of all child nodes of this node.
  +     */
  +    protected final Enumeration elements() {
   	return _contents.elements();
       }
   
  -    public final Object elementAt(int i) {
  -	return _contents.elementAt(i);
  +    /**
  +     * Returns a child node at a given position.
  +     * @param pos The child node's position.
  +     * @return The child node.
  +     */
  +    protected final Object elementAt(int pos) {
  +	return _contents.elementAt(pos);
       }
   
  +    /**
  +     * Displays the contents of this syntax tree node (to stdout).
  +     * This method is intended for debugging _only_, and should be overridden
  +     * by all syntax tree node implementations.
  +     * @param indent Indentation level for syntax tree levels.
  +     */
       public void display(int indent) {
   	displayContents(indent);
       }
   
  +    /**
  +     * Displays the contents of this syntax tree node (to stdout).
  +     * This method is intended for debugging _only_ !!!
  +     * @param indent Indentation level for syntax tree levels.
  +     */
       protected void displayContents(int indent) {
   	final int n = elementCount();
   	for (int i = 0; i < n; i++) {
  @@ -536,27 +730,39 @@
   	}
       }
   
  +    /**
  +     * Set the indentation level for debug output.
  +     * @param indent Indentation level for syntax tree levels.
  +     */
       protected final void indent(int indent) {
   	System.out.print(new String(_spaces, 0, indent));
       }
  -
  -    public final void setLineNumber(int line) {
  -	_line = line;
  -    }
  -
  -    public final int getLineNumber() {
  -	return _line;
  -    }
   
  +    /**
  +     * Report an error to the parser.
  +     * @param element The element in which the error occured (normally 'this'
  +     * but it could also be an expression/pattern/etc.)
  +     * @param parser The XSLT parser to report the error to.
  +     * @param error The error code (from util/ErrorMsg).
  +     * @param message Any additional error message.
  +     */
       protected void reportError(SyntaxTreeNode element, Parser parser,
   			       int errorCode, String message) {
  -	final ErrorMsg error = new ErrorMsg(errorCode, message, this);
  +	final ErrorMsg error = new ErrorMsg(errorCode, message, element);
           parser.reportError(Constants.ERROR, error);
       }
   
  +    /**
  +     * Report a recoverable error to the parser.
  +     * @param element The element in which the error occured (normally 'this'
  +     * but it could also be an expression/pattern/etc.)
  +     * @param parser The XSLT parser to report the error to.
  +     * @param error The error code (from util/ErrorMsg).
  +     * @param message Any additional error message.
  +     */
       protected  void reportWarning(SyntaxTreeNode element, Parser parser,
   				  int errorCode, String message) {
  -	final ErrorMsg error = new ErrorMsg(errorCode, message, this);
  +	final ErrorMsg error = new ErrorMsg(errorCode, message, element);
           parser.reportError(Constants.WARNING, error);
       }
   
  
  
  
  1.7       +24 -7     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Text.java
  
  Index: Text.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Text.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Text.java	2001/10/02 11:17:32	1.6
  +++ Text.java	2001/11/08 10:23:39	1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Text.java,v 1.6 2001/10/02 11:17:32 morten Exp $
  + * @(#)$Id: Text.java,v 1.7 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -74,21 +74,38 @@
       private String _text;
       private boolean _escaping = true;
   
  -    public Text() {}
  +    /**
  +     * Create a blank Text syntax tree node.
  +     */
  +    public Text() {
  +    }
   
  +    /**
  +     * Create text syntax tree node.
  +     * @param text is the text to put in the node.
  +     */
       public Text(String text) {
   	_text = text;
       }
   
  -    public String getText() {
  +    /**
  +     * Returns the text wrapped inside this node
  +     * @return The text wrapped inside this node
  +     */
  +    protected String getText() {
   	return _text;
       }
   
  -    public void setText(String text) {
  +    /**
  +     * Set the text for this node. Appends the given text to any already
  +     * existing text (using string concatenation, so use only when needed).
  +     * @param text is the text to wrap inside this node.
  +     */
  +    protected void setText(String text) {
   	if (_text == null)
   	    _text = text;
   	else
  -	    _text = _text + text; // compliation phase, so OK (well, maybe not)
  +	    _text = _text + text;
       }
   
       public void display(int indent) {
  @@ -105,8 +122,8 @@
   	}
   	parseChildren(parser);
       }
  -	
  -    public boolean contextDependent() {
  +
  +    protected boolean contextDependent() {
   	return false;
       }
   
  
  
  
  1.5       +38 -17    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnionPathExpr.java
  
  Index: UnionPathExpr.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnionPathExpr.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- UnionPathExpr.java	2001/08/13 10:49:52	1.4
  +++ UnionPathExpr.java	2001/11/08 10:23:39	1.5
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: UnionPathExpr.java,v 1.4 2001/08/13 10:49:52 morten Exp $
  + * @(#)$Id: UnionPathExpr.java,v 1.5 2001/11/08 10:23:39 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -74,8 +74,10 @@
   import org.apache.xalan.xsltc.compiler.util.*;
   
   final class UnionPathExpr extends Expression {
  +
       private final Expression _pathExpr;
       private final Expression _rest;
  +    private boolean _reverse = false;
   
       // linearization for top level UnionPathExprs
       private Expression[] _components;
  @@ -84,7 +86,7 @@
   	_pathExpr = pathExpr;
   	_rest     = rest;
       }
  -    
  +
       public void setParser(Parser parser) {
   	super.setParser(parser);
   	// find all expressions in this Union
  @@ -96,14 +98,20 @@
   	    _components[i].setParser(parser);
   	    _components[i].setParent(this);
   	    if (_components[i] instanceof Step) {
  -		Step step = (Step)_components[i];
  -		if ((step.getAxis() == Axis.ATTRIBUTE) ||
  -		    (step.getNodeType() == DOM.ATTRIBUTE)) {
  +		final Step step = (Step)_components[i];
  +		final int axis = step.getAxis();
  +		final int type = step.getNodeType();
  +		// Put attribute iterators first
  +		if ((axis == Axis.ATTRIBUTE) || (type == DOM.ATTRIBUTE)) {
   		    _components[i] = _components[0];
   		    _components[0] = step;
   		}
  +		// Check if the union contains a reverse iterator
  +		if (Axis.isReverse[axis]) _reverse = true;
   	    }
   	}
  +	// No need to reverse anything if another expression lies on top of this
  +	if (getParent() instanceof Expression) _reverse = false;
       }
       
       public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  @@ -135,24 +143,37 @@
       public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
   	final ConstantPoolGen cpg = classGen.getConstantPool();
   	final InstructionList il = methodGen.getInstructionList();
  -	final Instruction addIterator =
  -	    new INVOKEVIRTUAL(cpg.addMethodref(UNION_ITERATOR_CLASS,
  -					       ADD_ITERATOR,
  -					       ADD_ITERATOR_SIG));
  -	// create new UnionIterator
  +
  +	final int init = cpg.addMethodref(UNION_ITERATOR_CLASS,
  +					  "<init>",
  +					  "("+DOM_INTF_SIG+")V");
  +	final int iter = cpg.addMethodref(UNION_ITERATOR_CLASS,
  +					  ADD_ITERATOR,
  +					  ADD_ITERATOR_SIG);
  +
  +	// Create the UnionIterator and leave it on the stack
   	il.append(new NEW(cpg.addClass(UNION_ITERATOR_CLASS)));
   	il.append(DUP);
   	il.append(methodGen.loadDOM());
  -	il.append(new INVOKESPECIAL(cpg.addMethodref(UNION_ITERATOR_CLASS,
  -						     "<init>",
  -						     "("
  -						     + DOM_INTF_SIG
  -						     + ")V")));
  -	// UnionIterator is on the stack
  +	il.append(new INVOKESPECIAL(init));
  +
  +	// Add the various iterators to the UnionIterator
   	final int length = _components.length;
   	for (int i = 0; i < length; i++) {
   	    _components[i].translate(classGen, methodGen);
  -	    il.append(addIterator);
  +	    il.append(new INVOKEVIRTUAL(iter));
  +	}
  +
  +	// Order the iterator only if strictly needed
  +	if (_reverse) {
  +	    final int order = cpg.addInterfaceMethodref(DOM_INTF,
  +							ORDER_ITERATOR,
  +							ORDER_ITERATOR_SIG);
  +	    il.append(methodGen.loadDOM());
  +	    il.append(SWAP);
  +	    il.append(methodGen.loadContextNode());
  +	    il.append(new INVOKEINTERFACE(order, 3));
  +
   	}
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org