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 NodeSortRecord.java
Date Mon, 05 Nov 2001 15:47:35 GMT
morten      01/11/05 07:47:35

  Modified:    java/src/org/apache/xalan/xsltc DOM.java
               java/src/org/apache/xalan/xsltc/compiler PositionCall.java
                        StepPattern.java
               java/src/org/apache/xalan/xsltc/dom DOMAdapter.java
                        DOMImpl.java MultiDOM.java NodeSortRecord.java
  Removed:     java/src/org/apache/xalan/xsltc/compiler Mode.java.old
  Log:
  Fix for patterns on the format "/foo/*/bar" and "/foo/*[n]/bar".
  PR:		bugzilla 4604
  Obtained from:	n/a
  Submitted by:	morten@xml.apache.org
  Reviewed by:	morten@xml.apache.org
  
  Revision  Changes    Path
  1.8       +3 -1      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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DOM.java	2001/10/16 10:58:59	1.7
  +++ DOM.java	2001/11/05 15:47:34	1.8
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: DOM.java,v 1.7 2001/10/16 10:58:59 morten Exp $
  + * @(#)$Id: DOM.java,v 1.8 2001/11/05 15:47:34 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -129,4 +129,6 @@
       public int getTypedLast(int type, int node);
       public void setFilter(StripFilter filter);
       public void setupMapping(String[] names, String[] namespaces);
  +    public boolean isElement(final int node);
  +    public boolean isAttribute(final int node);
   }
  
  
  
  1.6       +3 -5      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PositionCall.java	2001/11/02 11:31:28	1.5
  +++ PositionCall.java	2001/11/05 15:47:34	1.6
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: PositionCall.java,v 1.5 2001/11/02 11:31:28 morten Exp $
  + * @(#)$Id: PositionCall.java,v 1.6 2001/11/05 15:47:34 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -93,8 +93,6 @@
   	// type of node we want to be looking for
   	if ((parent instanceof Expression) && (granny instanceof Predicate)) {
   	    _type = ((Predicate)granny).getPosType();
  -	    if ((_type == DOM.ELEMENT) || (_type == DOM.ATTRIBUTE))
  -		_type = -1;
   	}
   	else {
   	    while ((granny != null) && !(granny instanceof StepPattern)) {
  @@ -102,7 +100,7 @@
   		granny = granny.getParent();
   	    }
   	    if ((parent instanceof Predicate) &&
  -		(granny instanceof StepPattern)){ 
  +		(granny instanceof StepPattern)){
   		_type = ((StepPattern)granny).getNodeType();
   	    }
   	}
  @@ -123,7 +121,7 @@
   	}
   	else {
   	    final ConstantPoolGen cpg = classGen.getConstantPool();
  -	    // public int getTypedPosition(NodeIterator iterator, int type) {
  +	    // public int getTypedPosition(int type, int node)
   	    final int pos = cpg.addInterfaceMethodref(DOM_INTF,
   						      "getTypedPosition",
   						      "(II)I");
  
  
  
  1.10      +24 -8     xml-xalan/java/src/org/apache/xalan/xsltc/compiler/StepPattern.java
  
  Index: StepPattern.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/StepPattern.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- StepPattern.java	2001/10/31 07:29:38	1.9
  +++ StepPattern.java	2001/11/05 15:47:34	1.10
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: StepPattern.java,v 1.9 2001/10/31 07:29:38 morten Exp $
  + * @(#)$Id: StepPattern.java,v 1.10 2001/11/05 15:47:34 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -208,13 +208,29 @@
   	final ConstantPoolGen cpg = classGen.getConstantPool();
   	final InstructionList il = methodGen.getInstructionList();
   	
  -	if ((_nodeType == DOM.ELEMENT) && (hasPredicates())) {
  -	    // TODO: insert check to see if current node is element
  -	    il.append(POP);
  -	}
  -	else if ((_nodeType == DOM.ATTRIBUTE) && (hasPredicates())) {
  -	    // TODO: insert check to see if current node is attribute
  -	    il.append(POP);
  +	if (_nodeType == DOM.ELEMENT) {
  +	    final int check = cpg.addInterfaceMethodref(DOM_INTF,
  +							"isElement", "(I)Z");
  +	    il.append(methodGen.loadDOM());
  +	    il.append(SWAP);
  +	    il.append(new INVOKEINTERFACE(check, 2));
  +	
  +	    // Need to allow for long jumps here
  +	    final BranchHandle icmp = il.append(new IFNE(null));
  +	    _falseList.add(il.append(new GOTO_W(null)));
  +	    icmp.setTarget(il.append(NOP));
  +	}
  +	else if (_nodeType == DOM.ATTRIBUTE) {
  +	    final int check = cpg.addInterfaceMethodref(DOM_INTF,
  +							"isAttribute", "(I)Z");
  +	    il.append(methodGen.loadDOM());
  +	    il.append(SWAP);
  +	    il.append(new INVOKEINTERFACE(check, 2));
  +	
  +	    // Need to allow for long jumps here
  +	    final BranchHandle icmp = il.append(new IFNE(null));
  +	    _falseList.add(il.append(new GOTO_W(null)));
  +	    icmp.setTarget(il.append(NOP));
   	}
   	else {
   	    // context node is on the stack
  
  
  
  1.10      +9 -1      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DOMAdapter.java	2001/10/16 10:58:59	1.9
  +++ DOMAdapter.java	2001/11/05 15:47:34	1.10
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: DOMAdapter.java,v 1.9 2001/10/16 10:58:59 morten Exp $
  + * @(#)$Id: DOMAdapter.java,v 1.10 2001/11/05 15:47:34 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -264,6 +264,14 @@
   
       public String getDocumentURI(int node) {
   	return(_domImpl.getDocumentURI());
  +    }
  +
  +    public boolean isElement(final int node) {
  +	return(_domImpl.isElement(node));
  +    }
  +
  +    public boolean isAttribute(final int node) {
  +	return(_domImpl.isAttribute(node));
       }
   
   }
  
  
  
  1.58      +50 -5     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.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- DOMImpl.java	2001/11/05 11:27:04	1.57
  +++ DOMImpl.java	2001/11/05 15:47:35	1.58
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: DOMImpl.java,v 1.57 2001/11/05 11:27:04 morten Exp $
  + * @(#)$Id: DOMImpl.java,v 1.58 2001/11/05 15:47:35 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -172,13 +172,20 @@
       /**
        * Returns 'true' if a specific node is an element (of any type)
        */
  -    private boolean isElement(final int node) {
  +    public boolean isElement(final int node) {
   	final int type = _type[node];
  -	if ((node < _firstAttributeNode) && (type >= NTYPES)) return true;
  -	return false;
  +	return ((node < _firstAttributeNode) && (type >= NTYPES));
       }
   
       /**
  +     * Returns 'true' if a specific node is an element (of any type)
  +     */
  +    public boolean isAttribute(final int node) {
  +	final int type = _type[node];
  +	return ((node >= _firstAttributeNode) && (type >= NTYPES));
  +    }
  +
  +    /**
        * Returns the number of nodes in the tree (used for indexing)
        */
       public int getSize() {
  @@ -1803,12 +1810,50 @@
   	return _parent[node];
       }
   
  +    public int getElementPosition(int node) {
  +	// Initialize with the first sbiling of the current node
  +	int match = 0;
  +	int curr  = _offsetOrChild[_parent[node]];
  +	if (isElement(curr)) match++;
  +
  +	// Then traverse all other siblings up until the current node
  +	while (curr != node) {
  +	    curr = _nextSibling[curr];
  +	    if (isElement(curr)) match++;
  +	}
  +
  +	// And finally return number of matches
  +	return match;         
  +    }
  +
  +    public int getAttributePosition(int attr) {
  +	// Initialize with the first sbiling of the current node
  +	int match = 1;
  +	int curr  = _lengthOrAttr[_parent[attr]];
  +
  +	// Then traverse all other siblings up until the current node
  +	while (curr != attr) {
  +	    curr = _nextSibling[curr];
  +	    match++;
  +	}
  +
  +	// And finally return number of matches
  +	return match;         
  +    }
  +
       /**
        * Returns a node's position amongst other nodes of the same type
        */
       public int getTypedPosition(int type, int node) {
   	// Just return the basic position if no type is specified
  -	if (type == -1) type = _type[node];
  +	switch(type) {
  +	case ELEMENT:
  +	    return getElementPosition(node);
  +	case ATTRIBUTE:
  +	    return getAttributePosition(node);
  +	case -1:
  +	    type = _type[node];
  +	}
   
   	// Initialize with the first sbiling of the current node
   	int match = 0;
  
  
  
  1.13      +10 -1     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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- MultiDOM.java	2001/10/30 15:49:32	1.12
  +++ MultiDOM.java	2001/11/05 15:47:35	1.13
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: MultiDOM.java,v 1.12 2001/10/30 15:49:32 morten Exp $
  + * @(#)$Id: MultiDOM.java,v 1.13 2001/11/05 15:47:35 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -433,4 +433,13 @@
       public String getDocumentURI(int node) {
   	return _adapters[node>>>24].getDocumentURI(0);
       }
  +
  +    public boolean isElement(final int node) {
  +	return(_adapters[node>>>24].isElement(node & CLR));
  +    }
  +
  +    public boolean isAttribute(final int node) {
  +	return(_adapters[node>>>24].isAttribute(node & CLR));
  +    }
  +
   }
  
  
  
  1.7       +2 -2      xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecord.java
  
  Index: NodeSortRecord.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecord.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NodeSortRecord.java	2001/11/05 13:51:58	1.6
  +++ NodeSortRecord.java	2001/11/05 15:47:35	1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: NodeSortRecord.java,v 1.6 2001/11/05 13:51:58 morten Exp $
  + * @(#)$Id: NodeSortRecord.java,v 1.7 2001/11/05 15:47:35 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -82,8 +82,8 @@
       public static int COMPARE_DESCENDING = 1;
   
       protected static Collator _collator = Collator.getInstance();
  -    protected static int _levels = 1;
   
  +    protected static int _levels = 1;
       protected int[] _compareType;
       protected int[] _sortOrder;
   
  
  
  

---------------------------------------------------------------------
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