xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mor...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/dom DOMAdapter.java DOMImpl.java MultiDOM.java
Date Fri, 21 Sep 2001 09:39:38 GMT
morten      01/09/21 02:39:38

  Modified:    java/src/org/apache/xalan/xsltc DOM.java
               java/src/org/apache/xalan/xsltc/compiler LastCall.java
                        PositionCall.java
               java/src/org/apache/xalan/xsltc/dom DOMAdapter.java
                        DOMImpl.java MultiDOM.java
  Log:
  Fixed the getTypedPosition() and getTypedLast() methods of the DOM. These
  were used to implement XPath patterns such as /foo/bar[8]/baz.
  PR:		bugzilla 2803
  Obtained from:	n/a
  Submitted by:	morten@xml.apache.org
  Reviewed by:	morten@xml.apache.org
  
  Revision  Changes    Path
  1.4       +3 -3      xml-xalan/java/src/org/apache/xalan/xsltc/DOM.java
  
  Index: DOM.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/DOM.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DOM.java	2001/08/27 09:07:19	1.3
  +++ DOM.java	2001/09/21 09:39:38	1.4
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: DOM.java,v 1.3 2001/08/27 09:07:19 morten Exp $
  + * @(#)$Id: DOM.java,v 1.4 2001/09/21 09:39:38 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -121,8 +121,8 @@
       public String getLanguage(int node);
       public int getSize();
       public String getDocumentURI(int node);
  -    public int getTypedPosition(NodeIterator iterator, int type, int node);
  -    public int getTypedLast(NodeIterator iterator, int type, int node);
  +    public int getTypedPosition(int type, int node);
  +    public int getTypedLast(int type, int node);
       public void setFilter(StripFilter filter);
       public void setupMapping(String[] names, String[] namespaces);
   }
  
  
  
  1.4       +5 -8      xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LastCall.java
  
  Index: LastCall.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LastCall.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LastCall.java	2001/09/19 17:54:15	1.3
  +++ LastCall.java	2001/09/21 09:39:38	1.4
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: LastCall.java,v 1.3 2001/09/19 17:54:15 morten Exp $
  + * @(#)$Id: LastCall.java,v 1.4 2001/09/21 09:39:38 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -140,17 +140,14 @@
   	    il.append(new INVOKEINTERFACE(last, 1));
   	}
   	else {
  -	    // public int getTypedPosition(NodeIterator iterator, int type) {
  +	    // public int getTypedLast(int type, int node) {
   	    final int last = cpg.addInterfaceMethodref(DOM_INTF,
   						       "getTypedLast",
  -						       "("+
  -						       NODE_ITERATOR_SIG+
  -						       "II)I");
  +						       "(II)I");
   	    il.append(methodGen.loadDOM());
  -	    il.append(methodGen.loadIterator());
   	    il.append(new PUSH(cpg, _type));
  -	    il.append(methodGen.loadCurrentNode());
  -	    il.append(new INVOKEINTERFACE(last, 4));
  +	    il.append(methodGen.loadContextNode());
  +	    il.append(new INVOKEINTERFACE(last, 3));
   
   	}
       }
  
  
  
  1.4       +16 -14    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/PositionCall.java
  
  Index: PositionCall.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/PositionCall.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PositionCall.java	2001/09/19 17:54:15	1.3
  +++ PositionCall.java	2001/09/21 09:39:38	1.4
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: PositionCall.java,v 1.3 2001/09/19 17:54:15 morten Exp $
  + * @(#)$Id: PositionCall.java,v 1.4 2001/09/21 09:39:38 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -86,16 +86,20 @@
   
   	final InstructionList il = methodGen.getInstructionList();
   
  -	// If we're a part of an expression's preficate we want to know what
  +	SyntaxTreeNode parent = getParent();
  +	SyntaxTreeNode granny = parent.getParent();
  +
  +	// If we're a part of an expression's predicate we want to know what
   	// type of node we want to be looking for
  -	if (getParent() instanceof Expression) {
  -	    if (getParent().getParent() instanceof Predicate) {
  -		Predicate pred = (Predicate)getParent().getParent();
  -		_type = pred.getPosType();
  -		if ((_type==DOM.ELEMENT) || (_type==DOM.ATTRIBUTE)) _type = -1;
  -	    }
  +	if ((parent instanceof Expression) && (granny instanceof Predicate)) {
  +	    _type = ((Predicate)granny).getPosType();
  +	    if ((_type == DOM.ELEMENT) || (_type == DOM.ATTRIBUTE))
  +		_type = -1;
   	}
  -
  +    
  +	if ((parent instanceof Predicate) && (granny instanceof StepPattern)){ 
  +	    _type = ((StepPattern)granny).getNodeType();
  +	}
   
   	if (methodGen instanceof CompareGenerator) {
   	    il.append(((CompareGenerator)methodGen).loadCurrentNode());
  @@ -114,15 +118,13 @@
   	else {
   	    final ConstantPoolGen cpg = classGen.getConstantPool();
   	    // public int getTypedPosition(NodeIterator iterator, int type) {
  -	    final String params = "("+NODE_ITERATOR_SIG+"II)I";
   	    final int pos = cpg.addInterfaceMethodref(DOM_INTF,
   						      "getTypedPosition",
  -						      params);
  +						      "(II)I");
   	    il.append(methodGen.loadDOM());
  -	    il.append(methodGen.loadIterator());
   	    il.append(new PUSH(cpg, _type));
  -	    il.append(methodGen.loadCurrentNode());
  -	    il.append(new INVOKEINTERFACE(pos, 4));
  +	    il.append(methodGen.loadContextNode());
  +	    il.append(new INVOKEINTERFACE(pos, 3));
   	}
       }
   }
  
  
  
  1.4       +5 -5      xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMAdapter.java
  
  Index: DOMAdapter.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMAdapter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DOMAdapter.java	2001/08/27 09:07:21	1.3
  +++ DOMAdapter.java	2001/09/21 09:39:38	1.4
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: DOMAdapter.java,v 1.3 2001/08/27 09:07:21 morten Exp $
  + * @(#)$Id: DOMAdapter.java,v 1.4 2001/09/21 09:39:38 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -173,12 +173,12 @@
   	return _domImpl.getParent(node);
       }
   
  -    public int getTypedPosition(NodeIterator iterator, int type, int node) {
  -	return _domImpl.getTypedPosition(iterator, _reverse[type], node);
  +    public int getTypedPosition(int type, int node) {
  +	return _domImpl.getTypedPosition(_reverse[type], node);
       }
   
  -    public int getTypedLast(NodeIterator iterator, int type, int node) {
  -	return _domImpl.getTypedLast(iterator, _reverse[type], node);
  +    public int getTypedLast(int type, int node) {
  +	return _domImpl.getTypedLast(_reverse[type], node);
       }
   
       public int getAttributeNode(final int type, final int element) {
  
  
  
  1.28      +20 -14    xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java
  
  Index: DOMImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- DOMImpl.java	2001/09/20 14:21:07	1.27
  +++ DOMImpl.java	2001/09/21 09:39:38	1.28
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: DOMImpl.java,v 1.27 2001/09/20 14:21:07 morten Exp $
  + * @(#)$Id: DOMImpl.java,v 1.28 2001/09/21 09:39:38 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -1697,37 +1697,43 @@
       /**
        * Returns a node's position amongst other nodes of the same type
        */
  -    public int getTypedPosition(NodeIterator iterator, int type, int node) {
  -
  +    public int getTypedPosition(int type, int node) {
   	// Just return the basic position if no type is specified
   	if (type == -1) type = _type[node];
   
  -	int match = 1;
  -	int curr  = 0;
  -	iterator.reset();
  +	// Initialize with the first sbiling of the current node
  +	int match = 0;
  +	int curr  = _offsetOrChild[_parent[node]];
  +	if (_type[curr] == type) match++;
   
  -	while ( ((curr = iterator.next()) != NULL) && (curr != node)) {
  +	// Then traverse all other siblings up until the current node
  +	while (curr != node) {
  +	    curr = _nextSibling[curr];
   	    if (_type[curr] == type) match++;
   	}
  +
  +	// And finally return number of matches
   	return match;         
       }
   
       /**
        * Returns an iterator's last node of a given type
        */
  -    public int getTypedLast(NodeIterator iterator, int type, int node) {
  +    public int getTypedLast(int type, int node) {
   	// Just return the basic position if no type is specified
  -	if (type == -1) return(iterator.getLast());
  +	if (type == -1) type = _type[node];
   
  +	// Initialize with the first sbiling of the current node
   	int match = 0;
  -	int curr  = 0;
  -	iterator.setMark();
  -	iterator.reset();
  +	int curr  = _offsetOrChild[_parent[node]];
  +	if (_type[curr] == type) match++;
   
  -	while ((curr = iterator.next()) != NULL) {
  +	// Then traverse all other siblings up until the very last one
  +	while (curr != NULL) {
  +	    curr = _nextSibling[curr];
   	    if (_type[curr] == type) match++;
   	}
  -	iterator.gotoMark();
  +
   	return match;         
       }
   
  
  
  
  1.6       +5 -5      xml-xalan/java/src/org/apache/xalan/xsltc/dom/MultiDOM.java
  
  Index: MultiDOM.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/MultiDOM.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MultiDOM.java	2001/08/27 09:07:21	1.5
  +++ MultiDOM.java	2001/09/21 09:39:38	1.6
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: MultiDOM.java,v 1.5 2001/08/27 09:07:21 morten Exp $
  + * @(#)$Id: MultiDOM.java,v 1.6 2001/09/21 09:39:38 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -260,12 +260,12 @@
   	return _adapters[node>>>24].getParent(node & CLR) | node&SET;
       }
       
  -    public int getTypedPosition(NodeIterator iterator, int type, int node) {
  -	return _adapters[node>>>24].getTypedPosition(iterator, type, node&CLR);
  +    public int getTypedPosition(int type, int node) {
  +	return _adapters[node>>>24].getTypedPosition(type, node&CLR);
       }
   
  -    public int getTypedLast(NodeIterator iterator, int type, int node) {
  -	return _adapters[node>>>24].getTypedLast(iterator, type, node&CLR);
  +    public int getTypedLast(int type, int node) {
  +	return _adapters[node>>>24].getTypedLast(type, node&CLR);
       }
   
       public int getAttributeNode(final int type, final int el) {
  
  
  

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


Mime
View raw message