com.sun.org.apache.xalan.internal.xsltc.runtime.Operators Java Examples

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.runtime.Operators. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EqualityExpr.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #2
Source File: EqualityExpr.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #3
Source File: EqualityExpr.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #4
Source File: EqualityExpr.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #5
Source File: EqualityExpr.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #6
Source File: EqualityExpr.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #7
Source File: EqualityExpr.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #8
Source File: EqualityExpr.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #9
Source File: EqualityExpr.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #10
Source File: EqualityExpr.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #11
Source File: EqualityExpr.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #12
Source File: EqualityExpr.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public boolean getOp() {
    return (_op != Operators.NE);
}
 
Example #13
Source File: Predicate.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Type check a predicate expression. If the type of the expression is
 * number convert it to boolean by adding a comparison with position().
 * Note that if the expression is a parameter, we cannot distinguish
 * at compile time if its type is number or not. Hence, expressions of
 * reference type are always converted to booleans.
 *
 * This method may be called twice, before and after calling
 * <code>dontOptimize()</code>. If so, the second time it should honor
 * the new value of <code>_canOptimize</code>.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    Type texp = _exp.typeCheck(stable);

    // We need explicit type information for reference types - no good!
    if (texp instanceof ReferenceType) {
        _exp = new CastExpr(_exp, texp = Type.Real);
    }

    // A result tree fragment should not be cast directly to a number type,
    // but rather to a boolean value, and then to a numer (0 or 1).
    // Ref. section 11.2 of the XSLT 1.0 spec
    if (texp instanceof ResultTreeType) {
        _exp = new CastExpr(_exp, Type.Boolean);
        _exp = new CastExpr(_exp, Type.Real);
        texp = _exp.typeCheck(stable);
    }

    // Numerical types will be converted to a position filter
    if (texp instanceof NumberType) {
        // Cast any numerical types to an integer
        if (texp instanceof IntType == false) {
            _exp = new CastExpr(_exp, Type.Int);
        }

        if (_canOptimize) {
            // Nth position optimization. Expression must not depend on context
            _nthPositionFilter =
                !_exp.hasLastCall() && !_exp.hasPositionCall();

            // _nthDescendant optimization - only if _nthPositionFilter is on
            if (_nthPositionFilter) {
                SyntaxTreeNode parent = getParent();
                _nthDescendant = (parent instanceof Step) &&
                    (parent.getParent() instanceof AbsoluteLocationPath);
                return _type = Type.NodeSet;
            }
        }

       // Reset optimization flags
        _nthPositionFilter = _nthDescendant = false;

       // Otherwise, expand [e] to [position() = e]
       final QName position =
            getParser().getQNameIgnoreDefaultNs("position");
       final PositionCall positionCall =
            new PositionCall(position);
       positionCall.setParser(getParser());
       positionCall.setParent(this);

       _exp = new EqualityExpr(Operators.EQ, positionCall,
                                _exp);
       if (_exp.typeCheck(stable) != Type.Boolean) {
           _exp = new CastExpr(_exp, Type.Boolean);
       }
       return _type = Type.Boolean;
    }
    else {
        // All other types will be handled as boolean values
        if (texp instanceof BooleanType == false) {
            _exp = new CastExpr(_exp, Type.Boolean);
        }
        return _type = Type.Boolean;
    }
}
 
Example #14
Source File: EqualityExpr.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public String toString() {
    return Operators.getOpNames(_op) + '(' + _left + ", " + _right + ')';
}
 
Example #15
Source File: RelationalExpr.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    if (hasNodeSetArgs() || hasReferenceArgs()) {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
    else {
        BranchInstruction bi = null;
        final InstructionList il = methodGen.getInstructionList();

        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        // TODO: optimize if one of the args is 0

        boolean tozero = false;
        Type tleft = _left.getType();

        if (tleft instanceof RealType) {
    il.append(tleft.CMP(_op == Operators.LT || _op == Operators.LE));
            tleft = Type.Int;
            tozero = true;
        }

        switch (_op) {
    case Operators.LT:
            bi = tleft.GE(tozero);
            break;

    case Operators.GT:
            bi = tleft.LE(tozero);
            break;

    case Operators.LE:
            bi = tleft.GT(tozero);
            break;

    case Operators.GE:
            bi = tleft.LT(tozero);
            break;

        default:
            ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_RELAT_OP_ERR,this);
            getParser().reportError(Constants.FATAL, msg);
        }

        _falseList.add(il.append(bi));              // must be backpatched
    }
}
 
Example #16
Source File: Predicate.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Type check a predicate expression. If the type of the expression is
 * number convert it to boolean by adding a comparison with position().
 * Note that if the expression is a parameter, we cannot distinguish
 * at compile time if its type is number or not. Hence, expressions of
 * reference type are always converted to booleans.
 *
 * This method may be called twice, before and after calling
 * <code>dontOptimize()</code>. If so, the second time it should honor
 * the new value of <code>_canOptimize</code>.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    Type texp = _exp.typeCheck(stable);

    // We need explicit type information for reference types - no good!
    if (texp instanceof ReferenceType) {
        _exp = new CastExpr(_exp, texp = Type.Real);
    }

    // A result tree fragment should not be cast directly to a number type,
    // but rather to a boolean value, and then to a numer (0 or 1).
    // Ref. section 11.2 of the XSLT 1.0 spec
    if (texp instanceof ResultTreeType) {
        _exp = new CastExpr(_exp, Type.Boolean);
        _exp = new CastExpr(_exp, Type.Real);
        texp = _exp.typeCheck(stable);
    }

    // Numerical types will be converted to a position filter
    if (texp instanceof NumberType) {
        // Cast any numerical types to an integer
        if (texp instanceof IntType == false) {
            _exp = new CastExpr(_exp, Type.Int);
        }

        if (_canOptimize) {
            // Nth position optimization. Expression must not depend on context
            _nthPositionFilter =
                !_exp.hasLastCall() && !_exp.hasPositionCall();

            // _nthDescendant optimization - only if _nthPositionFilter is on
            if (_nthPositionFilter) {
                SyntaxTreeNode parent = getParent();
                _nthDescendant = (parent instanceof Step) &&
                    (parent.getParent() instanceof AbsoluteLocationPath);
                return _type = Type.NodeSet;
            }
        }

       // Reset optimization flags
        _nthPositionFilter = _nthDescendant = false;

       // Otherwise, expand [e] to [position() = e]
       final QName position =
            getParser().getQNameIgnoreDefaultNs("position");
       final PositionCall positionCall =
            new PositionCall(position);
       positionCall.setParser(getParser());
       positionCall.setParent(this);

       _exp = new EqualityExpr(Operators.EQ, positionCall,
                                _exp);
       if (_exp.typeCheck(stable) != Type.Boolean) {
           _exp = new CastExpr(_exp, Type.Boolean);
       }
       return _type = Type.Boolean;
    }
    else {
        // All other types will be handled as boolean values
        if (texp instanceof BooleanType == false) {
            _exp = new CastExpr(_exp, Type.Boolean);
        }
        return _type = Type.Boolean;
    }
}
 
Example #17
Source File: EqualityExpr.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public boolean getOp() {
    return (_op != Operators.NE);
}
 
Example #18
Source File: RelationalExpr.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public String toString() {
    return Operators.getOpNames(_op) + '(' + _left + ", " + _right + ')';
}
 
Example #19
Source File: EqualityExpr.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public String toString() {
    return Operators.getOpNames(_op) + '(' + _left + ", " + _right + ')';
}
 
Example #20
Source File: EqualityExpr.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public String toString() {
    return Operators.getOpNames(_op) + '(' + _left + ", " + _right + ')';
}
 
Example #21
Source File: Predicate.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Type check a predicate expression. If the type of the expression is
 * number convert it to boolean by adding a comparison with position().
 * Note that if the expression is a parameter, we cannot distinguish
 * at compile time if its type is number or not. Hence, expressions of
 * reference type are always converted to booleans.
 *
 * This method may be called twice, before and after calling
 * <code>dontOptimize()</code>. If so, the second time it should honor
 * the new value of <code>_canOptimize</code>.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    Type texp = _exp.typeCheck(stable);

    // We need explicit type information for reference types - no good!
    if (texp instanceof ReferenceType) {
        _exp = new CastExpr(_exp, texp = Type.Real);
    }

    // A result tree fragment should not be cast directly to a number type,
    // but rather to a boolean value, and then to a numer (0 or 1).
    // Ref. section 11.2 of the XSLT 1.0 spec
    if (texp instanceof ResultTreeType) {
        _exp = new CastExpr(_exp, Type.Boolean);
        _exp = new CastExpr(_exp, Type.Real);
        texp = _exp.typeCheck(stable);
    }

    // Numerical types will be converted to a position filter
    if (texp instanceof NumberType) {
        // Cast any numerical types to an integer
        if (texp instanceof IntType == false) {
            _exp = new CastExpr(_exp, Type.Int);
        }

        if (_canOptimize) {
            // Nth position optimization. Expression must not depend on context
            _nthPositionFilter =
                !_exp.hasLastCall() && !_exp.hasPositionCall();

            // _nthDescendant optimization - only if _nthPositionFilter is on
            if (_nthPositionFilter) {
                SyntaxTreeNode parent = getParent();
                _nthDescendant = (parent instanceof Step) &&
                    (parent.getParent() instanceof AbsoluteLocationPath);
                return _type = Type.NodeSet;
            }
        }

       // Reset optimization flags
        _nthPositionFilter = _nthDescendant = false;

       // Otherwise, expand [e] to [position() = e]
       final QName position =
            getParser().getQNameIgnoreDefaultNs("position");
       final PositionCall positionCall =
            new PositionCall(position);
       positionCall.setParser(getParser());
       positionCall.setParent(this);

       _exp = new EqualityExpr(Operators.EQ, positionCall,
                                _exp);
       if (_exp.typeCheck(stable) != Type.Boolean) {
           _exp = new CastExpr(_exp, Type.Boolean);
       }
       return _type = Type.Boolean;
    }
    else {
        // All other types will be handled as boolean values
        if (texp instanceof BooleanType == false) {
            _exp = new CastExpr(_exp, Type.Boolean);
        }
        return _type = Type.Boolean;
    }
}
 
Example #22
Source File: EqualityExpr.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean getOp() {
    return (_op != Operators.NE);
}
 
Example #23
Source File: EqualityExpr.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public boolean getOp() {
    return (_op != Operators.NE);
}
 
Example #24
Source File: RelationalExpr.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public String toString() {
    return Operators.getOpNames(_op) + '(' + _left + ", " + _right + ')';
}
 
Example #25
Source File: RelationalExpr.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    if (hasNodeSetArgs() || hasReferenceArgs()) {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
    else {
        BranchInstruction bi = null;
        final InstructionList il = methodGen.getInstructionList();

        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        // TODO: optimize if one of the args is 0

        boolean tozero = false;
        Type tleft = _left.getType();

        if (tleft instanceof RealType) {
    il.append(tleft.CMP(_op == Operators.LT || _op == Operators.LE));
            tleft = Type.Int;
            tozero = true;
        }

        switch (_op) {
    case Operators.LT:
            bi = tleft.GE(tozero);
            break;

    case Operators.GT:
            bi = tleft.LE(tozero);
            break;

    case Operators.LE:
            bi = tleft.GT(tozero);
            break;

    case Operators.GE:
            bi = tleft.LT(tozero);
            break;

        default:
            ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_RELAT_OP_ERR,this);
            getParser().reportError(Constants.FATAL, msg);
        }

        _falseList.add(il.append(bi));              // must be backpatched
    }
}
 
Example #26
Source File: XPathParser.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * This method is similar to findNodeType(int, Object) except that it
 * creates a StepPattern instead of just returning a node type. It also
 * differs in the way it handles "{uri}:*" and "{uri}:@*". The last two
 * patterns are expanded as "*[namespace-uri() = 'uri']" and
 * "@*[namespace-uri() = 'uri']", respectively. This expansion considerably
 * simplifies the grouping of patterns in the Mode class. For this expansion
 * to be correct, the priority of the pattern/template must be set to -0.25
 * (when no other predicates are present).
 */
public StepPattern createStepPattern(int axis, Object test, List<Predicate> predicates) {
    int nodeType;

    if (test == null) {  // "*"
        nodeType = (axis == Axis.ATTRIBUTE) ? NodeTest.ATTRIBUTE
                : (axis == Axis.NAMESPACE) ? -1 : NodeTest.ELEMENT;

        return new StepPattern(axis, nodeType, predicates);
    } else if (test instanceof Integer) {
        nodeType = ((Integer) test);

        return new StepPattern(axis, nodeType, predicates);
    } else {
        QName name = (QName) test;
        boolean setPriority = false;

        if (axis == Axis.NAMESPACE) {
            nodeType = (name.toString().equals("*")) ? -1
                    : _xsltc.registerNamespacePrefix(name);;
        } else {
            final String uri = name.getNamespace();
            final String local = name.getLocalPart();
            final QName namespace_uri
                    = _parser.getQNameIgnoreDefaultNs("namespace-uri");

            // Expand {uri}:* to *[namespace-uri() = 'uri'] - same for @*
            if (uri != null && (local.equals("*") || local.equals("@*"))) {
                if (predicates == null) {
                    predicates = new ArrayList<>(2);
                }

                // Priority is set by hand if no other predicates exist
                setPriority = (predicates.size() == 0);

                predicates.add(
                        new Predicate(
                                new EqualityExpr(Operators.EQ,
                                        new NamespaceUriCall(namespace_uri),
                                        new LiteralExpr(uri))));
            }

            if (local.equals("*")) {
                nodeType = (axis == Axis.ATTRIBUTE) ? NodeTest.ATTRIBUTE
                        : NodeTest.ELEMENT;
            } else if (local.equals("@*")) {
                nodeType = NodeTest.ATTRIBUTE;
            } else {
                nodeType = (axis == Axis.ATTRIBUTE) ? _xsltc.registerAttribute(name)
                        : _xsltc.registerElement(name);
            }
        }

        final StepPattern result = new StepPattern(axis, nodeType, predicates);

        // Set priority for case prefix:* and prefix:@* (no predicates)
        if (setPriority) {
            result.setPriority(-0.25);
        }

        return result;
    }
}
 
Example #27
Source File: Predicate.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Type check a predicate expression. If the type of the expression is
 * number convert it to boolean by adding a comparison with position().
 * Note that if the expression is a parameter, we cannot distinguish
 * at compile time if its type is number or not. Hence, expressions of
 * reference type are always converted to booleans.
 *
 * This method may be called twice, before and after calling
 * <code>dontOptimize()</code>. If so, the second time it should honor
 * the new value of <code>_canOptimize</code>.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    Type texp = _exp.typeCheck(stable);

    // We need explicit type information for reference types - no good!
    if (texp instanceof ReferenceType) {
        _exp = new CastExpr(_exp, texp = Type.Real);
    }

    // A result tree fragment should not be cast directly to a number type,
    // but rather to a boolean value, and then to a numer (0 or 1).
    // Ref. section 11.2 of the XSLT 1.0 spec
    if (texp instanceof ResultTreeType) {
        _exp = new CastExpr(_exp, Type.Boolean);
        _exp = new CastExpr(_exp, Type.Real);
        texp = _exp.typeCheck(stable);
    }

    // Numerical types will be converted to a position filter
    if (texp instanceof NumberType) {
        // Cast any numerical types to an integer
        if (texp instanceof IntType == false) {
            _exp = new CastExpr(_exp, Type.Int);
        }

        if (_canOptimize) {
            // Nth position optimization. Expression must not depend on context
            _nthPositionFilter =
                !_exp.hasLastCall() && !_exp.hasPositionCall();

            // _nthDescendant optimization - only if _nthPositionFilter is on
            if (_nthPositionFilter) {
                SyntaxTreeNode parent = getParent();
                _nthDescendant = (parent instanceof Step) &&
                    (parent.getParent() instanceof AbsoluteLocationPath);
                return _type = Type.NodeSet;
            }
        }

       // Reset optimization flags
        _nthPositionFilter = _nthDescendant = false;

       // Otherwise, expand [e] to [position() = e]
       final QName position =
            getParser().getQNameIgnoreDefaultNs("position");
       final PositionCall positionCall =
            new PositionCall(position);
       positionCall.setParser(getParser());
       positionCall.setParent(this);

       _exp = new EqualityExpr(Operators.EQ, positionCall,
                                _exp);
       if (_exp.typeCheck(stable) != Type.Boolean) {
           _exp = new CastExpr(_exp, Type.Boolean);
       }
       return _type = Type.Boolean;
    }
    else {
        // All other types will be handled as boolean values
        if (texp instanceof BooleanType == false) {
            _exp = new CastExpr(_exp, Type.Boolean);
        }
        return _type = Type.Boolean;
    }
}
 
Example #28
Source File: EqualityExpr.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public boolean getOp() {
    return (_op != Operators.NE);
}
 
Example #29
Source File: EqualityExpr.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public String toString() {
    return Operators.getOpNames(_op) + '(' + _left + ", " + _right + ')';
}
 
Example #30
Source File: RelationalExpr.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public String toString() {
    return Operators.getOpNames(_op) + '(' + _left + ", " + _right + ')';
}