sboag       01/05/25 10:37:09

  Modified:    java/src/org/apache/xml/dtm Tag: DTM_EXP Axis.java
               java/src/org/apache/xml/dtm/ref Tag: DTM_EXP
                        DTMDefaultBaseTraversers.java
               java/src/org/apache/xpath Tag: DTM_EXP XPathContext.java
               java/src/org/apache/xpath/axes Tag: DTM_EXP
                        MatchPatternIterator.java WalkerFactory.java
               java/src/org/apache/xpath/compiler Tag: DTM_EXP
                        Compiler.java
               java/src/org/apache/xpath/functions Tag: DTM_EXP
                        FuncCurrent.java
               java/src/org/apache/xpath/patterns Tag: DTM_EXP
                        ContextMatchStepPattern.java NodeTest.java
                        StepPattern.java
  Log:
  I finally got inverted select patterns passing for 100% of
  the test suite, except I have them turned off for
  namespaces, which simply can't be done
  because of our broken parantage of namespace
  nodes, and functions, which are easy enough,
  I've just had it for the time being.
  
  This was really nasty, though the code itself isn't
  too bad.  Inverted select patterns and match
  patterns share exactly the same code, though
  the construction is, of course, different.  I think I
  found a few bugs in the original match code, so
  hopefully match patterns will be somewhat more
  robust in general now.
  
  In reality, though I have them working for
  everything, these will only be used in limited
  circumstances, i.e. criss-crossed patterns, and a
  few other things.  They are horribly inefficient for
  some types of selections.
  
  Right now the MatchIterator creation is turned off
  in the WalkerFactory, since blanket enabling of this
  makes thing several times slower.  Also, I didn't want
  to cause any unneeded instability for Myriam and
  Joe.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.4   +15 -8     xml-xalan/java/src/org/apache/xml/dtm/Attic/Axis.java
  
  Index: Axis.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/Attic/Axis.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- Axis.java 2001/05/23 02:55:43     1.1.2.3
  +++ Axis.java 2001/05/25 17:36:24     1.1.2.4
  @@ -156,6 +156,12 @@
      *  root, descendants, attributes, and namespace node decls.
      */
     public static final int ALLFROMNODE = 14;
  +
  +  /**
  +   * A non-xpath axis, traversing the the preceding and the ancestor nodes, 
  +   * needed for inverseing select patterns to match patterns.
  +   */
  +  public static final int PRECEDINGANDANCESTOR = 15;
     
     // ===========================================
     // All axis past this are absolute.
  @@ -164,23 +170,23 @@
      * A non-xpath axis, returns all nodes in the tree from and including the 
      * root.
      */
  -  public static final int ALL = 15;
  +  public static final int ALL = 16;
   
     /**
      * A non-xpath axis, returns all nodes that aren't namespaces or 
attributes, 
      * from and including the root.
      */
  -  public static final int DESCENDANTSFROMROOT = 16;
  +  public static final int DESCENDANTSFROMROOT = 17;
   
     /**
      * A non-xpath axis, returns root only.
      */
  -  public static final int ROOT = 17;
  +  public static final int ROOT = 18;
   
     /**
      * A non-xpath axis, for functions.
      */
  -  public static final int FILTEREDLIST = 18;
  +  public static final int FILTEREDLIST = 19;
   
   
     /** The names of the axes for diagnostic purposes. */
  @@ -201,9 +207,10 @@
       "preceding-sibling",  // 12
       "self",  // 13
       "all-from-node",  // 14
  -    "all",  // 15
  -    "descendants-from-root",  // 16
  -    "root",  // 17
  -    "filtered-list"  // 18
  +    "preceding-and-ancestor",  // 15
  +    "all",  // 16
  +    "descendants-from-root",  // 17
  +    "root",  // 18
  +    "filtered-list"  // 19
     };
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +68 -0     
xml-xalan/java/src/org/apache/xml/dtm/ref/Attic/DTMDefaultBaseTraversers.java
  
  Index: DTMDefaultBaseTraversers.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/Attic/DTMDefaultBaseTraversers.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- DTMDefaultBaseTraversers.java     2001/05/23 18:18:04     1.1.2.2
  +++ DTMDefaultBaseTraversers.java     2001/05/25 17:36:31     1.1.2.3
  @@ -162,6 +162,9 @@
       case Axis.ALLFROMNODE :
         traverser = new AllFromNodeTraverser();
         break;
  +    case Axis.PRECEDINGANDANCESTOR :
  +      traverser = new PrecedingAndAncestorTraverser();
  +      break;
       case Axis.DESCENDANTSFROMROOT :
         traverser = new DescendantFromRootTraverser();
         break;
  @@ -870,6 +873,71 @@
         return NULL;
       }
     }
  +  
  +  /**
  +   * Implements traversal of the Ancestor and the Preceding axis, 
  +   * in reverse document order.
  +   */
  +  private class PrecedingAndAncestorTraverser extends DTMAxisTraverser
  +  {
  +
  +    /**
  +     * Traverse to the next node after the current node.
  +     *
  +     * @param context The context node of this iteration.
  +     * @param current The current node of the iteration.
  +     *
  +     * @return the next node in the iteration, or DTM.NULL.
  +     */
  +    public int next(int context, int current)
  +    {
  +
  +      int subtreeRootIdent = context & m_mask;
  +
  +      for (current = (current & m_mask) - 1; current >= 0; current--)
  +      {
  +        int exptype = m_exptype[current];
  +        int type = ExpandedNameTable.getType(exptype);
  +
  +        if (ATTRIBUTE_NODE == type || NAMESPACE_NODE == type)
  +          continue;
  +
  +        return (current | m_dtmIdent);  // make handle.
  +      }
  +
  +      return NULL;
  +    }
  +
  +    /**
  +     * Traverse to the next node after the current node that is matched
  +     * by the extended type ID.
  +     *
  +     * @param context The context node of this iteration.
  +     * @param current The current node of the iteration.
  +     * @param extendedTypeID The extended type ID that must match.
  +     *
  +     * @return the next node in the iteration, or DTM.NULL.
  +     */
  +    public int next(int context, int current, int extendedTypeID)
  +    {
  +
  +      int subtreeRootIdent = context & m_mask;
  +
  +      for (current = (current & m_mask) - 1; current >= 0; current--)
  +      {
  +        int exptype = m_exptype[current];
  +        int type = ExpandedNameTable.getType(exptype);
  +
  +        if (exptype != extendedTypeID)
  +          continue;
  +
  +        return (current | m_dtmIdent);  // make handle.
  +      }
  +
  +      return NULL;
  +    }
  +  }
  +
   
     /**
      * Implements traversal of the Ancestor access, in reverse document order.
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.20.2.10 +17 -0     xml-xalan/java/src/org/apache/xpath/XPathContext.java
  
  Index: XPathContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPathContext.java,v
  retrieving revision 1.20.2.9
  retrieving revision 1.20.2.10
  diff -u -r1.20.2.9 -r1.20.2.10
  --- XPathContext.java 2001/05/23 18:16:25     1.20.2.9
  +++ XPathContext.java 2001/05/25 17:36:37     1.20.2.10
  @@ -780,6 +780,23 @@
     
     public NodeVector getCurrentExpressionNodeStack() { return 
m_currentExpressionNodes; }
     public void setCurrentExpressionNodeStack(NodeVector nv) { 
m_currentExpressionNodes = nv; }
  +  
  +  private IntStack m_predicatePos = new IntStack();
  +  
  +  public final int getPredicatePos()
  +  {
  +    return m_predicatePos.peek();
  +  }
  +
  +  public final void pushPredicatePos(int n)
  +  {
  +    m_predicatePos.push(n);
  +  }
  +
  +  public final void popPredicatePos()
  +  {
  +    m_predicatePos.pop();
  +  }
   
     /**
      * Get the current node that is the expression's context (i.e. for 
current() support).
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +48 -8     
xml-xalan/java/src/org/apache/xpath/axes/Attic/MatchPatternIterator.java
  
  Index: MatchPatternIterator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/Attic/MatchPatternIterator.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- MatchPatternIterator.java 2001/05/23 18:16:38     1.1.2.1
  +++ MatchPatternIterator.java 2001/05/25 17:36:43     1.1.2.2
  @@ -96,7 +96,9 @@
     protected DTMAxisTraverser m_traverser;
     
     /** DEBUG flag for diagnostic dumps. */
  -  private static final boolean DEBUG = true;
  +  private static final boolean DEBUG = false;
  +  
  +//  protected int m_nsElemBase = DTM.NULL;
   
     /**
      * Create a LocPathIterator object, including creation
  @@ -189,27 +191,42 @@
                 & (WalkerFactory.BIT_ATTRIBUTE | WalkerFactory.BIT_NAMESPACE)))
         walkAttributes = true;
         
  -    if(DEBUG)
  -      System.out.println("analysis: "+Integer.toBinaryString(analysis));
  +    if(false || DEBUG)
  +    {
  +      System.out.print("analysis: "+Integer.toBinaryString(analysis));
  +      System.out.println(", "+WalkerFactory.getAnalysisString(analysis));
  +    }
         
       if(fromRoot || walkBack)
       {
         if(walkAttributes)
  +      {
           m_superAxes = Axis.ALL;
  +      }
         else
  +      {
           m_superAxes = Axis.DESCENDANTSFROMROOT;
  +      }
       }
       else if(walkDescendants)
       {
         if(walkAttributes)
  +      {
           m_superAxes = Axis.ALLFROMNODE;
  +      }
         else
  +      {
           m_superAxes = Axis.DESCENDANTORSELF;
  +      }
       }
       else
       {
         m_superAxes = Axis.ALL;
       }
  +    if(false || DEBUG)
  +    {
  +      System.out.println("axis: "+Axis.names[m_superAxes]);
  +    }
       
     }
     
  @@ -232,6 +249,33 @@
      */
     protected int getNextNode()
     {
  +//    if(m_superAxes == Axis.ALL || m_superAxes == Axis.ALLFROMNODE)
  +//    {
  +//      if(DTM.NULL != m_nsElemBase)
  +//      {
  +//        m_lastFetched = m_cdtm.getNextNamespaceNode(m_nsElemBase, 
m_lastFetched, true);
  +//        if(DTM.NULL != m_lastFetched)
  +//        {
  +//          return m_lastFetched;
  +//        }
  +//        else
  +//        {
  +//          m_lastFetched = m_nsElemBase;
  +//          m_nsElemBase = DTM.NULL;
  +//        }
  +//      }
  +//      else if(DTM.NULL != m_lastFetched 
  +//           && DTM.ELEMENT_NODE == m_cdtm.getNodeType(m_lastFetched))
  +//      {
  +//        int ns = m_cdtm.getFirstNamespaceNode(m_lastFetched, true);
  +//        if(DTM.NULL != ns)
  +//        {
  +//          m_nsElemBase = m_lastFetched;
  +//          m_lastFetched = ns;
  +//          return m_lastFetched;
  +//        }
  +//      }
  +//    }
       m_lastFetched = (DTM.NULL == m_lastFetched)
                        ? m_traverser.first(m_context)
                        : m_traverser.next(m_context, m_lastFetched);
  @@ -364,11 +408,7 @@
           System.out.println("traverser: "+m_traverser);
           System.out.print("node: "+n);
           System.out.println(", "+m_cdtm.getNodeName(n));
  -        if(m_cdtm.getNodeName(n).equals("near-east"))
  -        {
  -          int x = 1;
  -          x++;
  -        }
  +        // if(m_cdtm.getNodeName(n).equals("near-east"))
           System.out.println("pattern: "+m_pattern.toString());
           m_pattern.debugWhatToShow(m_pattern.getWhatToShow());
         }
  
  
  
  1.13.2.4  +180 -13   
xml-xalan/java/src/org/apache/xpath/axes/WalkerFactory.java
  
  Index: WalkerFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/WalkerFactory.java,v
  retrieving revision 1.13.2.3
  retrieving revision 1.13.2.4
  diff -u -r1.13.2.3 -r1.13.2.4
  --- WalkerFactory.java        2001/05/23 18:16:40     1.13.2.3
  +++ WalkerFactory.java        2001/05/25 17:36:45     1.13.2.4
  @@ -167,6 +167,11 @@
   
       return firstWalker;
     }
  +  
  +  public static boolean isSet(int analysis, int bit)
  +  {
  +    return (0 != (analysis & bit));
  +  }
   
     /**
      * Create a new LocPathIterator iterator.  The exact type of iterator
  @@ -276,13 +281,16 @@
         return new DescendantIterator(compiler, opPos, analysis);
       }
       else
  -    {
  -      if(true)
  +    { 
  +      if(true || isSet(analysis, BIT_NAMESPACE) || isSet(analysis, 
BIT_FILTER))
         {
  -        if (DEBUG_ITERATOR_CREATION)
  +        if (false || DEBUG_ITERATOR_CREATION)
  +        {
             System.out.println("new iterator:  LocPathIterator: "
                                + Integer.toBinaryString(analysis) + ", "
                                + compiler.toString());
  +          System.out.println("   "+getAnalysisString(analysis));
  +        }
     
           return new LocPathIterator(compiler, opPos, analysis, true);
         }
  @@ -378,7 +386,7 @@
           analysisResult |= BIT_DESCENDANT_OR_SELF;
           break;
         case OpCodes.FROM_FOLLOWING :
  -        analysisResult |= BIT_DESCENDANT_OR_SELF;
  +        analysisResult |= BIT_FOLLOWING;
           break;
         case OpCodes.FROM_FOLLOWING_SIBLINGS :
           analysisResult |= BIT_FOLLOWING_SIBLING;
  @@ -424,6 +432,25 @@
   
       return analysisResult;
     }
  +  
  +  /**
  +   * Tell if the given axis goes downword.  Bogus name, if you can think of 
  +   * a better one, please do tell.  This really has to do with inverting 
  +   * attribute axis.
  +   * @param axis One of Axis.XXX.
  +   * @return true if the axis is not a child axis and does not go up from 
  +   * the axis root.
  +   */
  +  public static boolean isDownwardAxisOfMany(int axis)
  +  {
  +    return ((Axis.DESCENDANTORSELF == axis) ||
  +          (Axis.DESCENDANT == axis) 
  +          || (Axis.FOLLOWING == axis) 
  +//          || (Axis.FOLLOWINGSIBLING == axis) 
  +          || (Axis.PRECEDING == axis) 
  +//          || (Axis.PRECEDINGSIBLING == axis)
  +          );
  +  }
   
     /**
      * Read a <a 
href="http://www.w3.org/TR/xpath#location-paths";>LocationPath</a>
  @@ -456,7 +483,10 @@
               throws javax.xml.transform.TransformerException
     {
       if (DEBUG_PATTERN_CREATION)
  +    {
  +      System.out.println("================");
         System.out.println("loadSteps for: "+compiler.getPatternString());
  +    }
       int stepType;
       StepPattern step = null;
       StepPattern firstStep = null, prevStep = null;
  @@ -495,7 +525,72 @@
         int nextAxis = pat.getAxis();
         int nextPaxis = pat.getPredicateAxis();
         pat.setAxis(axis);
  -      pat.setAxis(paxis);
  +      
  +      // The predicate axis can't be moved!!!  Test Axes103
  +      // pat.setPredicateAxis(paxis);
  +      
  +      // If we have an attribute or namespace axis that went up, then 
  +      // it won't find the attribute in the inverse, since the 
select-to-match
  +      // axes are not invertable (an element is a parent of an attribute, 
but 
  +      // and attribute is not a child of an element).
  +      // If we don't do the magic below, then "@*/ancestor-or-self::*" gets
  +      // inverted for match to 
"self::*/descendant-or-self::@*/parent::node()",
  +      // which obviously won't work.
  +      // So we will rewrite this as:
  +      // "self::*/descendant-or-self::*/attribute::*/parent::node()"
  +      // Child has to be rewritten a little differently:
  +      // select: "@*/parent::*"
  +      // inverted match: "self::*/child::@*/parent::node()"
  +      // rewrite: "self::*/attribute::*/parent::node()"
  +      // Axes that go down in the select, do not have to have special 
treatment 
  +      // in the rewrite. The following inverted match will still not select 
  +      // anything.
  +      // select: "@*/child::*"
  +      // inverted match: "self::*/parent::@*/parent::node()"
  +      // Lovely business, this.
  +      // -sb
  +      int whatToShow = pat.getWhatToShow();
  +      if(whatToShow == DTMFilter.SHOW_ATTRIBUTE || 
  +         whatToShow == DTMFilter.SHOW_NAMESPACE)
  +      {
  +        int newAxis = (whatToShow == DTMFilter.SHOW_ATTRIBUTE) ? 
  +                       Axis.ATTRIBUTE : Axis.NAMESPACE;
  +        if(isDownwardAxisOfMany(axis))
  +        {
  +          StepPattern attrPat = new StepPattern(whatToShow, 
  +                                    pat.getNamespace(),
  +                                    pat.getLocalName(),
  +                                    newAxis, pat.getPredicateAxis());
  +          XNumber score = pat.getStaticScore();
  +          pat.setNamespace(null);
  +          pat.setLocalName(NodeTest.WILD);
  +          attrPat.setPredicates(pat.getPredicates());
  +          pat.setPredicates(null);
  +          pat.setWhatToShow(DTMFilter.SHOW_ELEMENT);
  +          StepPattern rel = pat.getRelativePathPattern();
  +          pat.setRelativePathPattern(attrPat);
  +          attrPat.setRelativePathPattern(rel);
  +          attrPat.setStaticScore(score);
  +          
  +          // This is needed to inverse a following pattern, because of the 
  +          // wacky Xalan rules for following from an attribute.  See axes108.
  +          // By these rules, following from an attribute is not strictly 
  +          // inverseable.
  +          if(Axis.PRECEDING == pat.getAxis())
  +            pat.setAxis(Axis.PRECEDINGANDANCESTOR);
  +            
  +          else if(Axis.DESCENDANT == pat.getAxis())
  +            pat.setAxis(Axis.DESCENDANTORSELF);
  +          
  +          pat = attrPat;
  +        }
  +        else if(Axis.CHILD == pat.getAxis())
  +        {
  +          // In this case just change the axis.
  +          // pat.setWhatToShow(whatToShow);
  +          pat.setAxis(Axis.ATTRIBUTE);
  +        }
  +      }
         axis = nextAxis;
         paxis = nextPaxis;
         tail = pat;
  @@ -556,7 +651,7 @@
       int whatToShow = compiler.getWhatToShow(opPos);
       StepPattern ai = null;
       int axis, predicateAxis;
  -
  +    
       switch (stepType)
       {
       case OpCodes.OP_VARIABLE :
  @@ -569,6 +664,9 @@
   
         switch (stepType)
         {
  +      case OpCodes.OP_VARIABLE :
  +      case OpCodes.OP_EXTFUNCTION :
  +      case OpCodes.OP_FUNCTION :
         case OpCodes.OP_GROUP :
           expr = compiler.compile(opPos);
           break;
  @@ -595,13 +693,13 @@
         whatToShow = DTMFilter.SHOW_ATTRIBUTE;
         axis = Axis.PARENT;
         predicateAxis = Axis.ATTRIBUTE;
  -      ai = new StepPattern(whatToShow, Axis.SELF, Axis.SELF);
  +      // ai = new StepPattern(whatToShow, Axis.SELF, Axis.SELF);
         break;
       case OpCodes.FROM_NAMESPACE :
         whatToShow = DTMFilter.SHOW_NAMESPACE;
         axis = Axis.PARENT;
         predicateAxis = Axis.NAMESPACE;
  -      ai = new StepPattern(whatToShow, axis, predicateAxis);
  +      // ai = new StepPattern(whatToShow, axis, predicateAxis);
         break;
       case OpCodes.FROM_ANCESTORS :
         axis = Axis.DESCENDANT;
  @@ -659,13 +757,12 @@
                                   axis, predicateAxis);
       }
      
  -    if (DEBUG_PATTERN_CREATION)
  +    if (false || DEBUG_PATTERN_CREATION)
       {
  -      System.out.print("new step: "+ ai + analysis);
  -      System.out.print(", pattern: " + compiler.toString());
  +      System.out.print("new step: "+ ai);
         System.out.print(", axis: " + Axis.names[ai.getAxis()]);
         System.out.print(", predAxis: " + Axis.names[ai.getAxis()]);
  -      System.out.println(", what: ");
  +      System.out.print(", what: ");
         System.out.print("    ");
         ai.debugWhatToShow(ai.getWhatToShow());
       }
  @@ -983,7 +1080,7 @@
                                | DTMFilter.SHOW_PROCESSING_INSTRUCTION)));
         */
         if ((0 == (whatToShow
  -                 & (DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_ELEMENT
  +                 & (DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_NAMESPACE | 
DTMFilter.SHOW_ELEMENT
                       | DTMFilter.SHOW_PROCESSING_INSTRUCTION))) || 
(whatToShow == DTMFilter.SHOW_ALL))
           ai.initNodeTest(whatToShow);
         else
  @@ -994,6 +1091,76 @@
       }
   
       return ai;
  +  }
  +  
  +  public static String getAnalysisString(int analysis)
  +  {
  +    StringBuffer buf = new StringBuffer();
  +    if((analysis & BIT_PREDICATE) != 0)
  +    {
  +      buf.append("PRED|");
  +    }
  +    if((analysis & BIT_ANCESTOR) != 0)
  +    {
  +      buf.append("ANC|");
  +    }
  +    if((analysis & BIT_ANCESTOR_OR_SELF) != 0)
  +    {
  +      buf.append("ANCOS|");
  +    }
  +    if((analysis & BIT_ATTRIBUTE) != 0)
  +    {
  +      buf.append("ATTR|");
  +    }
  +    if((analysis & BIT_CHILD) != 0)
  +    {
  +      buf.append("CH|");
  +    }
  +    if((analysis & BIT_DESCENDANT) != 0)
  +    {
  +      buf.append("DESC|");
  +    }
  +    if((analysis & BIT_DESCENDANT_OR_SELF) != 0)
  +    {
  +      buf.append("DESCOS|");
  +    }
  +    if((analysis & BIT_FOLLOWING) != 0)
  +    {
  +      buf.append("FOL|");
  +    }
  +    if((analysis & BIT_FOLLOWING_SIBLING) != 0)
  +    {
  +      buf.append("FOLS|");
  +    }
  +    if((analysis & BIT_NAMESPACE) != 0)
  +    {
  +      buf.append("NS|");
  +    }
  +    if((analysis & BIT_PARENT) != 0)
  +    {
  +      buf.append("P|");
  +    }
  +    if((analysis & BIT_PRECEDING) != 0)
  +    {
  +      buf.append("PREC|");
  +    }
  +    if((analysis & BIT_PRECEDING_SIBLING) != 0)
  +    {
  +      buf.append("PRECS|");
  +    }
  +    if((analysis & BIT_SELF) != 0)
  +    {
  +      buf.append(".|");
  +    }
  +    if((analysis & BIT_FILTER) != 0)
  +    {
  +      buf.append("FLT|");
  +    }
  +    if((analysis & BIT_ROOT) != 0)
  +    {
  +      buf.append("R|");
  +    }
  +    return buf.toString();
     }
   
     /** Set to true for diagnostics about walker creation */
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.23.2.4  +2 -2      
xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java
  
  Index: Compiler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java,v
  retrieving revision 1.23.2.3
  retrieving revision 1.23.2.4
  diff -u -r1.23.2.3 -r1.23.2.4
  --- Compiler.java     2001/05/23 02:57:48     1.23.2.3
  +++ Compiler.java     2001/05/25 17:36:51     1.23.2.4
  @@ -785,7 +785,7 @@
         switch (axesType)
         {
         case OpCodes.FROM_NAMESPACE:
  -        return DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_NAMESPACE;
  +        return DTMFilter.SHOW_NAMESPACE;
         case OpCodes.FROM_ATTRIBUTES :
         case OpCodes.MATCH_ATTRIBUTE :
           return DTMFilter.SHOW_ATTRIBUTE;
  @@ -809,7 +809,7 @@
         switch (axesType)
         {
         case OpCodes.FROM_NAMESPACE :
  -        return DTMFilter.SHOW_ATTRIBUTE | DTMFilter.SHOW_NAMESPACE;
  +        return DTMFilter.SHOW_NAMESPACE;
         case OpCodes.FROM_ATTRIBUTES :
         case OpCodes.MATCH_ATTRIBUTE :
           return DTMFilter.SHOW_ATTRIBUTE;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.5.2.4   +8 -2      
xml-xalan/java/src/org/apache/xpath/functions/FuncCurrent.java
  
  Index: FuncCurrent.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncCurrent.java,v
  retrieving revision 1.5.2.3
  retrieving revision 1.5.2.4
  diff -u -r1.5.2.3 -r1.5.2.4
  --- FuncCurrent.java  2001/05/16 05:33:44     1.5.2.3
  +++ FuncCurrent.java  2001/05/25 17:36:56     1.5.2.4
  @@ -92,14 +92,20 @@
     {
   
       // If we're in a predicate, then this will return non-null.
  -    PredicatedNodeTest iter = (PredicatedNodeTest) xctxt.getSubContextList();
  +    Object subContextList = xctxt.getSubContextList();
       int currentNode;
   
  -    if (null != iter)
  +    // %TBD% Hack city...
  +    if (null != subContextList && subContextList instanceof 
PredicatedNodeTest)
       {
  +      PredicatedNodeTest iter = (PredicatedNodeTest) 
xctxt.getSubContextList();
         LocPathIterator lpi = iter.getLocPathIterator();
   
         currentNode = lpi.getCurrentContextNode();
  +    }
  +    else if(xctxt.getIteratorRoot() != DTM.NULL)
  +    {
  +      currentNode = xctxt.getIteratorRoot();
       }
       else
       {
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +112 -0    
xml-xalan/java/src/org/apache/xpath/patterns/Attic/ContextMatchStepPattern.java
  
  Index: ContextMatchStepPattern.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/Attic/ContextMatchStepPattern.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- ContextMatchStepPattern.java      2001/05/23 18:16:52     1.1.2.1
  +++ ContextMatchStepPattern.java      2001/05/25 17:37:01     1.1.2.2
  @@ -59,8 +59,11 @@
   import org.apache.xpath.XPathContext;
   import org.apache.xpath.objects.XObject;
   
  +import org.apache.xml.dtm.DTM;
   import org.apache.xml.dtm.DTMFilter;
  +import org.apache.xml.dtm.DTMAxisTraverser;
   import org.apache.xml.dtm.Axis;
  +import org.apache.xpath.axes.WalkerFactory; // evil import.
   
   /**
    * Special context node pattern matcher.
  @@ -101,4 +104,113 @@
       else
         return this.SCORE_NONE;
     }
  +  
  +  /**
  +   * Execute the match pattern step relative to another step.
  +   *
  +   *
  +   * @param xctxt The XPath runtime context.
  +   * NEEDSDOC @param prevStep
  +   *
  +   * @return [EMAIL PROTECTED] 
org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
  +   *         [EMAIL PROTECTED] 
org.apache.xpath.patterns.NodeTest#SCORE_NONE},
  +   *         [EMAIL PROTECTED] 
org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
  +   *         [EMAIL PROTECTED] 
org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
  +   *         [EMAIL PROTECTED] 
org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
  +   *
  +   * @throws javax.xml.transform.TransformerException
  +   */
  +  public XObject executeRelativePathPattern(
  +          XPathContext xctxt, StepPattern prevStep)
  +            throws javax.xml.transform.TransformerException
  +  {
  +
  +    XObject score = NodeTest.SCORE_NONE;
  +    int context = xctxt.getCurrentNode();
  +    DTM dtm = xctxt.getDTM(context);
  +
  +    if (null != dtm)
  +    {
  +      int predContext = xctxt.getCurrentNode();
  +      DTMAxisTraverser traverser;
  +      
  +      int axis = m_axis;
  +      
  +      boolean needToTraverseAttrs = WalkerFactory.isDownwardAxisOfMany(axis);
  +      boolean iterRootIsAttr = (dtm.getNodeType(xctxt.getIteratorRoot()) 
  +                                 == DTM.ATTRIBUTE_NODE);
  +
  +      if((Axis.PRECEDING == axis) && iterRootIsAttr)
  +      {
  +        axis = Axis.PRECEDINGANDANCESTOR;
  +      }
  +      
  +      traverser = dtm.getAxisTraverser(axis);
  +
  +      for (int relative = traverser.first(context); DTM.NULL != relative;
  +              relative = traverser.next(context, relative))
  +      {
  +        try
  +        {
  +          xctxt.pushCurrentNode(relative);
  +
  +          score = execute(xctxt);
  +
  +          if (score != NodeTest.SCORE_NONE)
  +          {
  +            score = executePredicates( xctxt, prevStep, SCORE_OTHER, 
  +                       predContext, relative);
  +
  +            if (score != NodeTest.SCORE_NONE)
  +              return score;
  +          }
  +          
  +          if(needToTraverseAttrs && iterRootIsAttr
  +             && (DTM.ELEMENT_NODE == dtm.getNodeType(relative)))
  +          {
  +            int xaxis = Axis.ATTRIBUTE;
  +            for (int i = 0; i < 2; i++) 
  +            {            
  +              DTMAxisTraverser atraverser = dtm.getAxisTraverser(xaxis);
  +        
  +              for (int arelative = atraverser.first(relative); 
  +                      DTM.NULL != arelative;
  +                      arelative = atraverser.next(relative, arelative))
  +              {
  +                try
  +                {
  +                  xctxt.pushCurrentNode(arelative);
  +        
  +                  score = execute(xctxt);
  +        
  +                  if (score != NodeTest.SCORE_NONE)
  +                  {
  +                    score = executePredicates( xctxt, prevStep, SCORE_OTHER, 
  +                               predContext, arelative);
  +        
  +                    if (score != NodeTest.SCORE_NONE)
  +                      return score;
  +                  }
  +                }
  +                finally
  +                {
  +                  xctxt.popCurrentNode();
  +                }
  +              }
  +              xaxis = Axis.NAMESPACE;
  +            }
  +          }
  +
  +        }
  +        finally
  +        {
  +          xctxt.popCurrentNode();
  +        }
  +      }
  +
  +    }
  +
  +    return score;
  +  }
  +
   }
  
  
  
  1.20.2.6  +37 -2     
xml-xalan/java/src/org/apache/xpath/patterns/NodeTest.java
  
  Index: NodeTest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/NodeTest.java,v
  retrieving revision 1.20.2.5
  retrieving revision 1.20.2.6
  diff -u -r1.20.2.5 -r1.20.2.6
  --- NodeTest.java     2001/05/22 05:48:51     1.20.2.5
  +++ NodeTest.java     2001/05/25 17:37:02     1.20.2.6
  @@ -111,6 +111,18 @@
     {
       return m_whatToShow;
     }
  +  
  +  /**
  +   * This attribute determines which node types are accepted.
  +   * These constants are defined in the [EMAIL PROTECTED] 
org.w3c.dom.traversal.NodeFilter}
  +   * interface.
  +   *
  +   * @param what bitset mainly defined in [EMAIL PROTECTED] 
org.w3c.dom.traversal.NodeFilter}.
  +   */
  +  public void setWhatToShow(int what)
  +  {
  +    m_whatToShow = what;
  +  }
   
     /**
      * The namespace to be tested for, which may be null.
  @@ -129,15 +141,25 @@
     }
   
     /**
  +   * Set the namespace to be tested.
  +   *
  +   * @param ns The namespace to be tested for, or [EMAIL PROTECTED] #WILD}, 
or null.
  +   */
  +  public void setNamespace(String ns)
  +  {
  +    m_namespace = ns;
  +  }
  +
  +  /**
      * The local name to be tested for.
      *  @serial 
      */
     String m_name;
   
     /**
  -   * Return the local namespace to be tested.
  +   * Return the local name to be tested.
      *
  -   * @return the local namespace to be tested, or [EMAIL PROTECTED] #WILD}, 
or an empty string.
  +   * @return the local name to be tested, or [EMAIL PROTECTED] #WILD}, or an 
empty string.
      */
     public String getLocalName()
     {
  @@ -145,6 +167,16 @@
     }
   
     /**
  +   * Set the local name to be tested.
  +   *
  +   * @param name the local name to be tested, or [EMAIL PROTECTED] #WILD}, 
or an empty string.
  +   */
  +  public void setLocalName(String name)
  +  {
  +    m_name = name;
  +  }
  +
  +  /**
      * Statically calculated score for this test.  One of
      *  [EMAIL PROTECTED] #SCORE_NODETEST},
      *  [EMAIL PROTECTED] #SCORE_NONE},
  @@ -323,6 +355,9 @@
   
       if (0 != (whatToShow & DTMFilter.SHOW_ATTRIBUTE))
         v.addElement("SHOW_ATTRIBUTE");
  +      
  +    if (0 != (whatToShow & DTMFilter.SHOW_NAMESPACE))
  +      v.addElement("SHOW_NAMESPACE");
   
       if (0 != (whatToShow & DTMFilter.SHOW_CDATA_SECTION))
         v.addElement("SHOW_CDATA_SECTION");
  
  
  
  1.19.2.5  +164 -59   
xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java
  
  Index: StepPattern.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/patterns/StepPattern.java,v
  retrieving revision 1.19.2.4
  retrieving revision 1.19.2.5
  diff -u -r1.19.2.4 -r1.19.2.5
  --- StepPattern.java  2001/05/23 18:16:55     1.19.2.4
  +++ StepPattern.java  2001/05/25 17:37:05     1.19.2.5
  @@ -207,6 +207,24 @@
   
       return m_relativePathPattern;
     }
  +  
  +//  /**
  +//   * Set the list of predicate expressions for this pattern step.
  +//   * @param predicates List of expression objects.
  +//   */
  +//  public void setPredicates(Expression[] predicates)
  +//  {
  +//    m_predicates = predicates;
  +//  }
  +  
  +  /**
  +   * Set the list of predicate expressions for this pattern step.
  +   * @return List of expression objects.
  +   */
  +  public Expression[] getPredicates()
  +  {
  +    return m_predicates;
  +  }
   
   
     /**
  @@ -214,7 +232,7 @@
      *  @serial
      */
     Expression[] m_predicates;
  -
  +  
     /**
      * Tell if this expression or it's subexpressions can traverse outside
      * the current subtree.
  @@ -342,7 +360,7 @@
         // return executePredicates(xctxt, this, score, current, current);
       }
     }
  -
  +  
     /**
      * Get the proximity position index of the current node based on this
      * node test.
  @@ -353,63 +371,109 @@
      * @return the proximity position index of the current node based on the
      *         node test.
      */
  -  public int getProximityPosition(XPathContext xctxt)
  +  public int getProximityPosition(XPathContext xctxt, int predPos)
     {
   
       int context = xctxt.getCurrentNode();
       DTM dtm = xctxt.getDTM(context);
  +    int pos = 0;
   
       int parentContext = xctxt.getPredicateRoot();    
  +      
  +    try
       {
  +      xctxt.pushCurrentNode(parentContext);
   
  -      // System.out.println("parentContext: "+parentContext.getNodeName());
  -      try
  -      {
  -        xctxt.pushCurrentNode(parentContext);
  -
  -        int pos = 0;
  -        DTMAxisTraverser traverser = 
dtm.getAxisTraverser(m_axisForPredicate);
  +      DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axisForPredicate);
   
  -        for (int child = traverser.first(parentContext); DTM.NULL != child;
  -                child = traverser.next(parentContext, child))
  +      for (int child = traverser.first(parentContext); DTM.NULL != child;
  +              child = traverser.next(parentContext, child))
  +      {
  +        try
           {
  -          try
  +          xctxt.pushCurrentNode(child);
  +
  +          if (NodeTest.SCORE_NONE != super.execute(xctxt))
             {
  -            xctxt.pushCurrentNode(child);
  +            boolean pass = true;
  +            
  +            try
  +            {
  +              xctxt.pushSubContextList(this);
  +              xctxt.pushPredicateRoot(parentContext);
  +      
  +              for (int i = 0; i < predPos; i++)
  +              {
  +                XObject pred = m_predicates[i].execute(xctxt);
   
  -            if (NodeTest.SCORE_NONE != super.execute(xctxt))
  +                if (XObject.CLASS_NUMBER == pred.getType())
  +                {
  +                  if ((pos+1) != (int) pred.num())
  +                  {
  +                    pass = false;
  +                    break;
  +                  }
  +                }
  +                else if (!pred.bool())
  +                {
  +                  pass = false;
  +                  break;
  +                }
  +              }
  +            }
  +            finally
               {
  +              xctxt.popSubContextList();
  +              xctxt.popPredicateRoot();
  +            }              
  +            
  +            if(pass)
                 pos++;
   
  -              if (child == context)
  -              {
  -                return pos;
  -              }
  +            if (child == context)
  +            {
  +              return pos;
               }
             }
  -          finally
  -          {
  -            xctxt.popCurrentNode();
  -          }
  +        }
  +        finally
  +        {
  +          xctxt.popCurrentNode();
           }
         }
  -      catch (javax.xml.transform.TransformerException se)
  -      {
  +    }
  +    catch (javax.xml.transform.TransformerException se)
  +    {
   
  -        // TODO: should keep throw sax exception...
  -        throw new java.lang.RuntimeException(se.getMessage());
  -      }
  -      finally
  -      {
  -        xctxt.popCurrentNode();
  +      // TODO: should keep throw sax exception...
  +      throw new java.lang.RuntimeException(se.getMessage());
  +    }
  +    finally
  +    {
  +      xctxt.popCurrentNode();
   
  -        // xctxt.popContextNodeList();
  -      }
  +      // xctxt.popContextNodeList();
       }
   
  -    return 0;
  +    return pos;
     }
  +  
  +  /**
  +   * Get the proximity position index of the current node based on this
  +   * node test.
  +   *
  +   *
  +   * @param xctxt XPath runtime context.
  +   *
  +   * @return the proximity position index of the current node based on the
  +   *         node test.
  +   */
  +  public int getProximityPosition(XPathContext xctxt)
  +  {
   
  +    return getProximityPosition(xctxt, xctxt.getPredicatePos());
  +  }
  +
     /**
      * Get the count of the nodes that match the test, which is the proximity
      * position of the last node that can pass this test in the sub context
  @@ -499,8 +563,12 @@
   
       if (null != dtm)
       {
  -      DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis);
         int predContext = xctxt.getCurrentNode();
  +      DTMAxisTraverser traverser;
  +      
  +      int axis = m_axis;
  +      
  +      traverser = dtm.getAxisTraverser(axis);
   
         for (int relative = traverser.first(context); DTM.NULL != relative;
                 relative = traverser.next(context, relative))
  @@ -510,7 +578,7 @@
             xctxt.pushCurrentNode(relative);
   
             score = execute(xctxt);
  -
  +          
             if (score != NodeTest.SCORE_NONE)
             {
               score = executePredicates( xctxt, prevStep, SCORE_OTHER, 
  @@ -542,7 +610,7 @@
      *
      * @throws javax.xml.transform.TransformerException
      */
  -  private static XObject executePredicates(
  +  protected static XObject executePredicates(
             XPathContext xctxt, StepPattern prevStep, XObject score, 
             int context, int predicateRootContext)
               throws javax.xml.transform.TransformerException
  @@ -560,22 +628,31 @@
   
           for (int i = 0; i < n; i++)
           {
  -          XObject pred = prevStep.m_predicates[i].execute(xctxt);
  -
  -          if (XObject.CLASS_NUMBER == pred.getType())
  +          xctxt.pushPredicatePos(i);
  +          try
             {
  -            if (prevStep.getProximityPosition(xctxt) != (int) pred.num())
  +            XObject pred = prevStep.m_predicates[i].execute(xctxt);
  +  
  +            if (XObject.CLASS_NUMBER == pred.getType())
               {
  +              int pos = (int) pred.num();
  +              if (prevStep.getProximityPosition(xctxt, i) != pos)
  +              {
  +                score = NodeTest.SCORE_NONE;
  +  
  +                break;
  +              }
  +            }
  +            else if (!pred.bool())
  +            {
                 score = NodeTest.SCORE_NONE;
  -
  +  
                 break;
               }
             }
  -          else if (!pred.bool())
  +          finally
             {
  -            score = NodeTest.SCORE_NONE;
  -
  -            break;
  +            xctxt.popPredicatePos();
             }
           }
         }
  @@ -599,18 +676,8 @@
           buf.append("/");
         buf.append(Axis.names[pat.m_axis]);
         buf.append("::");
  -      if(null != pat.m_namespace)
  +      if(0x000005000 == pat.m_whatToShow)
         {
  -        buf.append("{");
  -        buf.append(pat.m_namespace);
  -        buf.append("}");
  -      }
  -      else if(null != pat.m_name)
  -      {
  -        buf.append(pat.m_name);
  -      }
  -      else if(0x000005000 == pat.m_whatToShow)
  -      {
           buf.append("doc()");
         }
         else if(DTMFilter.SHOW_BYFUNCTION == pat.m_whatToShow)
  @@ -627,15 +694,53 @@
         }
         else if(DTMFilter.SHOW_PROCESSING_INSTRUCTION == pat.m_whatToShow)
         {
  -        buf.append("processing-instruction()");
  +        buf.append("processing-instruction(");
  +        if(null != pat.m_name)
  +        {
  +          buf.append(pat.m_name);
  +        }
  +        buf.append(")");
         }
         else if(DTMFilter.SHOW_COMMENT == pat.m_whatToShow)
         {
           buf.append("comment()");
         }
  +      else if(null != pat.m_name)
  +      {
  +        if(DTMFilter.SHOW_ATTRIBUTE == pat.m_whatToShow)
  +        {
  +          buf.append("@");
  +        }
  +        if(null != pat.m_namespace)
  +        {
  +          buf.append("{");
  +          buf.append(pat.m_namespace);
  +          buf.append("}");
  +        }
  +        buf.append(pat.m_name);
  +      }
  +      else if(DTMFilter.SHOW_ATTRIBUTE == pat.m_whatToShow)
  +      {
  +        buf.append("@");
  +      }
  +      else if((DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT) 
  +              == pat.m_whatToShow)
  +      {
  +        buf.append("doc-root()");
  +      }
         else
  +      {
  +        buf.append("?"+Integer.toHexString(pat.m_whatToShow));
  +      }
  +      if(null != pat.m_predicates)
         {
  -        buf.append("??");
  +        for (int i = 0; i < pat.m_predicates.length; i++) 
  +        {
  +          buf.append("[");
  +          buf.append(pat.m_predicates[i]);
  +          buf.append("]");
  +        }
  +        
         }
       }
       return buf.toString();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to