Java Code Examples for com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#Boolean

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#Boolean . 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: ContainsCall.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Type check the two parameters for this function
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {

    // Check that the function was passed exactly two arguments
    if (argumentCount() != 2) {
        throw new TypeCheckError(ErrorMsg.ILLEGAL_ARG_ERR, getName(), this);
    }

    // The first argument must be a String, or cast to a String
    _base = argument(0);
    Type baseType = _base.typeCheck(stable);
    if (baseType != Type.String)
        _base = new CastExpr(_base, Type.String);

    // The second argument must also be a String, or cast to a String
    _token = argument(1);
    Type tokenType = _token.typeCheck(stable);
    if (tokenType != Type.String)
        _token = new CastExpr(_token, Type.String);

    return _type = Type.Boolean;
}
 
Example 2
Source File: FunctionCall.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compile the function call and treat as an expression
 * Update true/false-lists.
 */
@Override
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen)
{
    Type type = Type.Boolean;
    if (_chosenMethodType != null)
        type = _chosenMethodType.resultType();

    final InstructionList il = methodGen.getInstructionList();
    translate(classGen, methodGen);

    if ((type instanceof BooleanType) || (type instanceof IntType)) {
        _falseList.add(il.append(new IFEQ(null)));
    }
}
 
Example 3
Source File: FunctionCall.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compile the function call and treat as an expression
 * Update true/false-lists.
 */
@Override
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen)
{
    Type type = Type.Boolean;
    if (_chosenMethodType != null)
        type = _chosenMethodType.resultType();

    final InstructionList il = methodGen.getInstructionList();
    translate(classGen, methodGen);

    if ((type instanceof BooleanType) || (type instanceof IntType)) {
        _falseList.add(il.append(new IFEQ(null)));
    }
}
 
Example 4
Source File: FunctionCall.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compile the function call and treat as an expression
 * Update true/false-lists.
 */
@Override
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen)
{
    Type type = Type.Boolean;
    if (_chosenMethodType != null)
        type = _chosenMethodType.resultType();

    final InstructionList il = methodGen.getInstructionList();
    translate(classGen, methodGen);

    if ((type instanceof BooleanType) || (type instanceof IntType)) {
        _falseList.add(il.append(new IFEQ(null)));
    }
}
 
Example 5
Source File: CastExpr.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a cast expression and check that the conversion is
 * valid by calling typeCheck().
 */
public CastExpr(Expression left, Type type) throws TypeCheckError {
    _left = left;
    _type = type;           // use inherited field

    if ((_left instanceof Step) && (_type == Type.Boolean)) {
        Step step = (Step)_left;
        if ((step.getAxis() == Axis.SELF) && (step.getNodeType() != -1))
            _typeTest = true;
    }

    // check if conversion is valid
    setParser(left.getParser());
    setParent(left.getParent());
    left.setParent(this);
    typeCheck(left.getParser().getSymbolTable());
}
 
Example 6
Source File: StartsWithCall.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Type check the two parameters for this function
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {

    // Check that the function was passed exactly two arguments
    if (argumentCount() != 2) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR,
                                    getName(), this);
        throw new TypeCheckError(err);
    }

    // The first argument must be a String, or cast to a String
    _base = argument(0);
    Type baseType = _base.typeCheck(stable);
    if (baseType != Type.String)
        _base = new CastExpr(_base, Type.String);

    // The second argument must also be a String, or cast to a String
    _token = argument(1);
    Type tokenType = _token.typeCheck(stable);
    if (tokenType != Type.String)
        _token = new CastExpr(_token, Type.String);

    return _type = Type.Boolean;
}
 
Example 7
Source File: When.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Type-check this when element. The test should always be type checked,
 * while we do not bother with the contents if we know the test fails.
 * This is important in cases where the "test" expression tests for
 * the support of a non-available element, and the <xsl:when> body contains
 * this non-available element.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    // Type-check the test expression
    if (_test.typeCheck(stable) instanceof BooleanType == false) {
        _test = new CastExpr(_test, Type.Boolean);
    }
    // Type-check the contents (if necessary)
    if (!_ignore) {
        typeCheckContents(stable);
    }

    return Type.Void;
}
 
Example 8
Source File: ElementAvailableCall.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Force the argument to this function to be a literal string.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (argument() instanceof LiteralExpr) {
        return _type = Type.Boolean;
    }
    ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
                                "element-available", this);
    throw new TypeCheckError(err);
}
 
Example 9
Source File: LangCall.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    _langType = _lang.typeCheck(stable);
    if (!(_langType instanceof StringType)) {
        _lang = new CastExpr(_lang, Type.String);
    }
    return Type.Boolean;
}
 
Example 10
Source File: FunctionAvailableCall.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Argument of function-available call must be literal, typecheck
 * returns the type of function-available to be boolean.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_type != null) {
       return _type;
    }
    if (_arg instanceof LiteralExpr) {
        return _type = Type.Boolean;
    }
    ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
                    "function-available", this);
    throw new TypeCheckError(err);
}
 
Example 11
Source File: ElementAvailableCall.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Force the argument to this function to be a literal string.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (argument() instanceof LiteralExpr) {
        return _type = Type.Boolean;
    }
    ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
                                "element-available", this);
    throw new TypeCheckError(err);
}
 
Example 12
Source File: If.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Type-check the "test" expression and contents of this element.
 * The contents will be ignored if we know the test will always fail.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    // Type-check the "test" expression
    if (_test.typeCheck(stable) instanceof BooleanType == false) {
        _test = new CastExpr(_test, Type.Boolean);
    }
    // Type check the element contents
    if (!_ignore) {
        typeCheckContents(stable);
    }
    return Type.Void;
}
 
Example 13
Source File: When.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Type-check this when element. The test should always be type checked,
 * while we do not bother with the contents if we know the test fails.
 * This is important in cases where the "test" expression tests for
 * the support of a non-available element, and the <xsl:when> body contains
 * this non-available element.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    // Type-check the test expression
    if (_test.typeCheck(stable) instanceof BooleanType == false) {
        _test = new CastExpr(_test, Type.Boolean);
    }
    // Type-check the contents (if necessary)
    if (!_ignore) {
        typeCheckContents(stable);
    }

    return Type.Void;
}
 
Example 14
Source File: ElementAvailableCall.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Force the argument to this function to be a literal string.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (argument() instanceof LiteralExpr) {
        return _type = Type.Boolean;
    }
    ErrorMsg err = new ErrorMsg(ErrorMsg.NEED_LITERAL_ERR,
                                "element-available", this);
    throw new TypeCheckError(err);
}
 
Example 15
Source File: BooleanCall.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    _arg.typeCheck(stable);
    return _type = Type.Boolean;
}
 
Example 16
Source File: LangCall.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 */
public Type getType() {
    return(Type.Boolean);
}
 
Example 17
Source File: EqualityExpr.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Typing rules: see XSLT Reference by M. Kay page 345.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type tleft = _left.typeCheck(stable);
    final Type tright = _right.typeCheck(stable);

    if (tleft.isSimple() && tright.isSimple()) {
        if (tleft != tright) {
            if (tleft instanceof BooleanType) {
                _right = new CastExpr(_right, Type.Boolean);
            }
            else if (tright instanceof BooleanType) {
                _left = new CastExpr(_left, Type.Boolean);
            }
            else if (tleft instanceof NumberType ||
                     tright instanceof NumberType) {
                _left = new CastExpr(_left, Type.Real);
                _right = new CastExpr(_right, Type.Real);
            }
            else {          // both compared as strings
                _left = new CastExpr(_left,   Type.String);
                _right = new CastExpr(_right, Type.String);
            }
        }
    }
    else if (tleft instanceof ReferenceType) {
        _right = new CastExpr(_right, Type.Reference);
    }
    else if (tright instanceof ReferenceType) {
        _left = new CastExpr(_left, Type.Reference);
    }
    // the following 2 cases optimize @attr|.|.. = 'string'
    else if (tleft instanceof NodeType && tright == Type.String) {
        _left = new CastExpr(_left, Type.String);
    }
    else if (tleft == Type.String && tright instanceof NodeType) {
        _right = new CastExpr(_right, Type.String);
    }
    // optimize node/node
    else if (tleft instanceof NodeType && tright instanceof NodeType) {
        _left = new CastExpr(_left, Type.String);
        _right = new CastExpr(_right, Type.String);
    }
    else if (tleft instanceof NodeType && tright instanceof NodeSetType) {
        // compare(Node, NodeSet) will be invoked
    }
    else if (tleft instanceof NodeSetType && tright instanceof NodeType) {
        swapArguments();    // for compare(Node, NodeSet)
    }
    else {
        // At least one argument is of type node, node-set or result-tree

        // Promote an expression of type node to node-set
        if (tleft instanceof NodeType) {
            _left = new CastExpr(_left, Type.NodeSet);
        }
        if (tright instanceof NodeType) {
            _right = new CastExpr(_right, Type.NodeSet);
        }

        // If one arg is a node-set then make it the left one
        if (tleft.isSimple() ||
            tleft instanceof ResultTreeType &&
            tright instanceof NodeSetType) {
            swapArguments();
        }

        // Promote integers to doubles to have fewer compares
        if (_right.getType() instanceof IntType) {
            _right = new CastExpr(_right, Type.Real);
        }
    }
    return _type = Type.Boolean;
}
 
Example 18
Source File: EqualityExpr.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Typing rules: see XSLT Reference by M. Kay page 345.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type tleft = _left.typeCheck(stable);
    final Type tright = _right.typeCheck(stable);

    if (tleft.isSimple() && tright.isSimple()) {
        if (tleft != tright) {
            if (tleft instanceof BooleanType) {
                _right = new CastExpr(_right, Type.Boolean);
            }
            else if (tright instanceof BooleanType) {
                _left = new CastExpr(_left, Type.Boolean);
            }
            else if (tleft instanceof NumberType ||
                     tright instanceof NumberType) {
                _left = new CastExpr(_left, Type.Real);
                _right = new CastExpr(_right, Type.Real);
            }
            else {          // both compared as strings
                _left = new CastExpr(_left,   Type.String);
                _right = new CastExpr(_right, Type.String);
            }
        }
    }
    else if (tleft instanceof ReferenceType) {
        _right = new CastExpr(_right, Type.Reference);
    }
    else if (tright instanceof ReferenceType) {
        _left = new CastExpr(_left, Type.Reference);
    }
    // the following 2 cases optimize @attr|.|.. = 'string'
    else if (tleft instanceof NodeType && tright == Type.String) {
        _left = new CastExpr(_left, Type.String);
    }
    else if (tleft == Type.String && tright instanceof NodeType) {
        _right = new CastExpr(_right, Type.String);
    }
    // optimize node/node
    else if (tleft instanceof NodeType && tright instanceof NodeType) {
        _left = new CastExpr(_left, Type.String);
        _right = new CastExpr(_right, Type.String);
    }
    else if (tleft instanceof NodeType && tright instanceof NodeSetType) {
        // compare(Node, NodeSet) will be invoked
    }
    else if (tleft instanceof NodeSetType && tright instanceof NodeType) {
        swapArguments();    // for compare(Node, NodeSet)
    }
    else {
        // At least one argument is of type node, node-set or result-tree

        // Promote an expression of type node to node-set
        if (tleft instanceof NodeType) {
            _left = new CastExpr(_left, Type.NodeSet);
        }
        if (tright instanceof NodeType) {
            _right = new CastExpr(_right, Type.NodeSet);
        }

        // If one arg is a node-set then make it the left one
        if (tleft.isSimple() ||
            tleft instanceof ResultTreeType &&
            tright instanceof NodeSetType) {
            swapArguments();
        }

        // Promote integers to doubles to have fewer compares
        if (_right.getType() instanceof IntType) {
            _right = new CastExpr(_right, Type.Real);
        }
    }
    return _type = Type.Boolean;
}
 
Example 19
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 20
Source File: LangCall.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 */
public Type getType() {
    return(Type.Boolean);
}