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

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type#String . 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: NameBase.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that we either have no parameters or one parameter that is
 * either a node or a node-set.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {

    // Check the argument type (if any)
    switch(argumentCount()) {
    case 0:
        _paramType = Type.Node;
        break;
    case 1:
        _paramType = _param.typeCheck(stable);
        break;
    default:
        throw new TypeCheckError(this);
    }

    // The argument has to be a node, a node-set or a node reference
    if ((_paramType != Type.NodeSet) &&
        (_paramType != Type.Node) &&
        (_paramType != Type.Reference)) {
        throw new TypeCheckError(this);
    }

    return (_type = Type.String);
}
 
Example 2
Source File: StartsWithCall.java    From openjdk-8-source 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 3
Source File: AttributeValueTemplate.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final List<SyntaxTreeNode> contents = getContents();
    final int n = contents.size();
    for (int i = 0; i < n; i++) {
        final Expression exp = (Expression)contents.get(i);
        if (!exp.typeCheck(stable).identicalTo(Type.String)) {
            contents.set(i, new CastExpr(exp, Type.String));
        }
    }
    return _type = Type.String;
}
 
Example 4
Source File: Sort.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Run type checks on the attributes; expression must return a string
 * which we will use as a sort key
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type tselect = _select.typeCheck(stable);

    // If the sort data-type is not set we use the natural data-type
    // of the data we will sort
    if (!(tselect instanceof StringType)) {
        _select = new CastExpr(_select, Type.String);
    }

    _order.typeCheck(stable);
    _caseOrder.typeCheck(stable);
    _dataType.typeCheck(stable);
    return Type.Void;
}
 
Example 5
Source File: ConcatCall.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    for (int i = 0; i < argumentCount(); i++) {
        final Expression exp = argument(i);
        if (!exp.typeCheck(stable).identicalTo(Type.String)) {
            setArgument(i, new CastExpr(exp, Type.String));
        }
    }
    return _type = Type.String;
}
 
Example 6
Source File: CopyOf.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type tselect = _select.typeCheck(stable);
    if (tselect instanceof NodeType ||
        tselect instanceof NodeSetType ||
        tselect instanceof ReferenceType ||
        tselect instanceof ResultTreeType) {
        // falls through
    }
    else {
        _select = new CastExpr(_select, Type.String);
    }
    return Type.Void;
}
 
Example 7
Source File: FormatNumberCall.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {

        // Inform stylesheet to instantiate a DecimalFormat object
        getStylesheet().numberFormattingUsed();

        final Type tvalue = _value.typeCheck(stable);
        if (tvalue instanceof RealType == false) {
            _value = new CastExpr(_value, Type.Real);
        }
        final Type tformat = _format.typeCheck(stable);
        if (tformat instanceof StringType == false) {
            _format = new CastExpr(_format, Type.String);
        }
        if (argumentCount() == 3) {
            final Type tname = _name.typeCheck(stable);

            if (_name instanceof LiteralExpr) {
                final LiteralExpr literal = (LiteralExpr) _name;
                _resolvedQName =
                    getParser().getQNameIgnoreDefaultNs(literal.getValue());
            }
            else if (tname instanceof StringType == false) {
                _name = new CastExpr(_name, Type.String);
            }
        }
        return _type = Type.String;
    }
 
Example 8
Source File: AttributeValueTemplate.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final List<SyntaxTreeNode> contents = getContents();
    final int n = contents.size();
    for (int i = 0; i < n; i++) {
        final Expression exp = (Expression)contents.get(i);
        if (!exp.typeCheck(stable).identicalTo(Type.String)) {
            contents.set(i, new CastExpr(exp, Type.String));
        }
    }
    return _type = Type.String;
}
 
Example 9
Source File: TransletOutput.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Type checks the 'file' attribute (must be able to convert it to a str).
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type type = _filename.typeCheck(stable);
    if (type instanceof StringType == false) {
        _filename = new CastExpr(_filename, Type.String);
    }
    typeCheckContents(stable);
    return Type.Void;
}
 
Example 10
Source File: StringCall.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final int argc = argumentCount();
    if (argc > 1) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ILLEGAL_ARG_ERR, this);
        throw new TypeCheckError(err);
    }

    if (argc > 0) {
        argument().typeCheck(stable);
    }
    return _type = Type.String;
}
 
Example 11
Source File: ConcatCall.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    for (int i = 0; i < argumentCount(); i++) {
        final Expression exp = argument(i);
        if (!exp.typeCheck(stable).identicalTo(Type.String)) {
            setArgument(i, new CastExpr(exp, Type.String));
        }
    }
    return _type = Type.String;
}
 
Example 12
Source File: UnparsedEntityUriCall.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type entity = _entity.typeCheck(stable);
    if (entity instanceof StringType == false) {
        _entity = new CastExpr(_entity, Type.String);
    }
    return _type = Type.String;
}
 
Example 13
Source File: EqualityExpr.java    From JDKSourceCode1.8 with MIT License 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 14
Source File: EqualityExpr.java    From openjdk-8-source 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 15
Source File: Comment.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    typeCheckContents(stable);
    return Type.String;
}
 
Example 16
Source File: KeyCall.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Type check the parameters for the id() or key() function.
 * The index name (for key() call only) must be a string or convertable
 * to a string, and the lookup-value must be a string or a node-set.
 * @param stable The parser's symbol table
 * @throws TypeCheckError When the parameters have illegal type
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type returnType = super.typeCheck(stable);

    // Run type check on the key name (first argument) - must be a string,
    // and if it is not it must be converted to one using string() rules.
    if (_name != null) {
        final Type nameType = _name.typeCheck(stable);

        if (_name instanceof LiteralExpr) {
            final LiteralExpr literal = (LiteralExpr) _name;
            _resolvedQName =
                getParser().getQNameIgnoreDefaultNs(literal.getValue());
        }
        else if (nameType instanceof StringType == false) {
            _name = new CastExpr(_name, Type.String);
        }
    }

    // Run type check on the value for this key. This value can be of
    // any data type, so this should never cause any type-check errors.
    // If the value is a reference, then we have to defer the decision
    // of how to process it until run-time.
    // If the value is known not to be a node-set, then it should be
    // converted to a string before the lookup is done. If the value is
    // known to be a node-set then this process (convert to string, then
    // do lookup) should be applied to every node in the set, and the
    // result from all lookups should be added to the resulting node-set.
    _valueType = _value.typeCheck(stable);

    if (_valueType != Type.NodeSet
            && _valueType != Type.Reference
            && _valueType != Type.String) {
        _value = new CastExpr(_value, Type.String);
        _valueType = _value.typeCheck(stable);
    }

    // If in a top-level element, create dependency to the referenced key
    addParentDependency();

    return returnType;
}
 
Example 17
Source File: KeyCall.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Type check the parameters for the id() or key() function.
 * The index name (for key() call only) must be a string or convertable
 * to a string, and the lookup-value must be a string or a node-set.
 * @param stable The parser's symbol table
 * @throws TypeCheckError When the parameters have illegal type
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type returnType = super.typeCheck(stable);

    // Run type check on the key name (first argument) - must be a string,
    // and if it is not it must be converted to one using string() rules.
    if (_name != null) {
        final Type nameType = _name.typeCheck(stable);

        if (_name instanceof LiteralExpr) {
            final LiteralExpr literal = (LiteralExpr) _name;
            _resolvedQName =
                getParser().getQNameIgnoreDefaultNs(literal.getValue());
        }
        else if (nameType instanceof StringType == false) {
            _name = new CastExpr(_name, Type.String);
        }
    }

    // Run type check on the value for this key. This value can be of
    // any data type, so this should never cause any type-check errors.
    // If the value is a reference, then we have to defer the decision
    // of how to process it until run-time.
    // If the value is known not to be a node-set, then it should be
    // converted to a string before the lookup is done. If the value is
    // known to be a node-set then this process (convert to string, then
    // do lookup) should be applied to every node in the set, and the
    // result from all lookups should be added to the resulting node-set.
    _valueType = _value.typeCheck(stable);

    if (_valueType != Type.NodeSet
            && _valueType != Type.Reference
            && _valueType != Type.String) {
        _value = new CastExpr(_value, Type.String);
        _valueType = _value.typeCheck(stable);
    }

    // If in a top-level element, create dependency to the referenced key
    addParentDependency();

    return returnType;
}
 
Example 18
Source File: Comment.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    typeCheckContents(stable);
    return Type.String;
}
 
Example 19
Source File: LiteralExpr.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    return _type = Type.String;
}
 
Example 20
Source File: SimpleAttributeValue.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns this attribute value's type (String).
 * @param stable The compiler/parser's symbol table
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    return _type = Type.String;
}