zongaro     2002/10/01 13:58:32

  Modified:    java/src/org/apache/xalan/xsltc/compiler Tag: XSLTC_DTM
                        StepPattern.java Predicate.java
  Log:
  ..\..\..\temp\step.txt
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.14.2.4  +40 -29    
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.14.2.3
  retrieving revision 1.14.2.4
  diff -u -r1.14.2.3 -r1.14.2.4
  --- StepPattern.java  1 Aug 2002 19:55:30 -0000       1.14.2.3
  +++ StepPattern.java  1 Oct 2002 20:58:32 -0000       1.14.2.4
  @@ -166,7 +166,8 @@
   
        for (int i = 0; i < n && noContext; i++) {
            final Predicate pred = (Predicate)_predicates.elementAt(i);
  -         if (pred.getExpr().hasPositionCall()) {
  +         if (pred.getExpr().hasPositionCall()
  +                || pred.isNthPositionFilter()) {
                noContext = false;
            }
        }
  @@ -185,33 +186,43 @@
       }
   
       public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  -     if (hasPredicates()) {
  -         // Type check all the predicates (e -> position() = e)
  -         final int n = _predicates.size();
  -         for (int i = 0; i < n; i++) {
  -             final Predicate pred = (Predicate)_predicates.elementAt(i);
  -             pred.typeCheck(stable);
  -         }
  +        if (hasPredicates()) {
  +            // Type check all the predicates (e -> position() = e)
  +            final int n = _predicates.size();
  +            for (int i = 0; i < n; i++) {
  +                final Predicate pred = (Predicate)_predicates.elementAt(i);
  +                pred.typeCheck(stable);
  +            }
   
  -         // Analyze context cases
  -         _contextCase = analyzeCases();
  +            // Analyze context cases
  +            _contextCase = analyzeCases();
   
  -         // Create an instance of Step to do the translation
  -         if (_contextCase == SIMPLE_CONTEXT) {
  -             _step = new Step(_axis, _nodeType, null);
  -             _step.setParser(getParser());
  -             _step.typeCheck(stable);
  -         }
  -         else if (_contextCase == GENERAL_CONTEXT) {
  -             final int len = _predicates.size();
  -             for (int i = 0; i < len; i++)
  -                 ((Predicate)_predicates.elementAt(i)).dontOptimize();
  -             _step = new Step(_axis, _nodeType, _predicates);
  -             _step.setParser(getParser());
  -             _step.typeCheck(stable);
  -         }
  -     }
  -     return _axis == Axis.CHILD ? Type.Element : Type.Attribute;
  +            Step step = null;
  +
  +            // Create an instance of Step to do the translation
  +            if (_contextCase == SIMPLE_CONTEXT) {
  +                Predicate pred = (Predicate)_predicates.elementAt(0);
  +                if (pred.isNthPositionFilter()) {
  +                    _contextCase = GENERAL_CONTEXT;
  +                    step = new Step(_axis, _nodeType, _predicates);
  +                } else {
  +                    step = new Step(_axis, _nodeType, null);
  +                }
  +            } else if (_contextCase == GENERAL_CONTEXT) {
  +                final int len = _predicates.size();
  +                for (int i = 0; i < len; i++) {
  +                    ((Predicate)_predicates.elementAt(i)).dontOptimize();
  +                }
  +
  +                step = new Step(_axis, _nodeType, _predicates);
  +            }
  +            if (step != null) {
  +                step.setParser(getParser());
  +                step.typeCheck(stable);
  +                _step = step;
  +            }
  +        }
  +        return _axis == Axis.CHILD ? Type.Element : Type.Attribute;
       }
   
       private void translateKernel(ClassGenerator classGen, 
  
  
  
  1.22.6.3  +25 -13    
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Predicate.java
  
  Index: Predicate.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Predicate.java,v
  retrieving revision 1.22.6.2
  retrieving revision 1.22.6.3
  diff -u -r1.22.6.2 -r1.22.6.3
  --- Predicate.java    12 Sep 2002 16:07:33 -0000      1.22.6.2
  +++ Predicate.java    1 Oct 2002 20:58:32 -0000       1.22.6.3
  @@ -250,18 +250,8 @@
                (parent instanceof Pattern) ||
                (parent instanceof FilterExpr)) {
   
  -             final QName position = 
getParser().getQNameIgnoreDefaultNs("position");
  -             final PositionCall positionCall = new PositionCall(position);
  -             positionCall.setParser(getParser());
  -             positionCall.setParent(this);
  -
  -             _exp = new EqualityExpr(EqualityExpr.EQ, positionCall, _exp);
  -             if (_exp.typeCheck(stable) != Type.Boolean) {
  -                 _exp = new CastExpr(_exp, Type.Boolean);
  -             }
  -
                if (parent instanceof Pattern) {
  -                 _nthPositionFilter = true;
  +                 _nthPositionFilter = _canOptimize;
                }
                else if (parent instanceof FilterExpr) {
                    FilterExpr filter = (FilterExpr)parent;
  @@ -282,7 +272,29 @@
                    if (_canOptimize)
                        _nthPositionFilter = true;
                }
  -             return _type = Type.Boolean;
  +
  +                // If this case can be optimized, leave the expression as
  +                // an integer.  Otherwise, turn it into a comparison with
  +                // the position() function.
  +                if (_nthPositionFilter) {
  +                   return _type = Type.NodeSet;
  +                } else {
  +                   final QName position =
  +                                
getParser().getQNameIgnoreDefaultNs("position");
  +
  +                   final PositionCall positionCall =
  +                                               new PositionCall(position);
  +                   positionCall.setParser(getParser());
  +                   positionCall.setParent(this);
  +
  +                   _exp = new EqualityExpr(EqualityExpr.EQ, positionCall,
  +                                            _exp);
  +                   if (_exp.typeCheck(stable) != Type.Boolean) {
  +                       _exp = new CastExpr(_exp, Type.Boolean);
  +                   }
  +
  +                   return _type = Type.Boolean;
  +                }
            }
            // Use NthPositionIterator to handle [position()] or [a]
            else {
  
  
  

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

Reply via email to