com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError Java Examples

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError. 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 Project: jdk1.8-source-analysis   Author: raysonfang   File: Variable.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Runs a type check on either the variable element body or the
 * expression in the 'select' attribute
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {

    // Type check the 'select' expression if present
    if (_select != null) {
        _type = _select.typeCheck(stable);
    }
    // Type check the element contents otherwise
    else if (hasContents()) {
        typeCheckContents(stable);
        _type = Type.ResultTree;
    }
    else {
        _type = Type.Reference;
    }
    // The return type is void as the variable element does not leave
    // anything on the JVM's stack. The '_type' global will be returned
    // by the references to this variable, and not by the variable itself.
    return Type.Void;
}
 
Example #2
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: NameBase.java    License: Apache License 2.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 #3
Source Project: TencentKona-8   Author: Tencent   File: ApplyTemplates.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_select != null) {
        _type = _select.typeCheck(stable);
        if (_type instanceof NodeType || _type instanceof ReferenceType) {
            _select = new CastExpr(_select, Type.NodeSet);
            _type = Type.NodeSet;
        }
        if (_type instanceof NodeSetType||_type instanceof ResultTreeType) {
            typeCheckContents(stable); // with-params
            return Type.Void;
        }
        throw new TypeCheckError(this);
    }
    else {
        typeCheckContents(stable);          // with-params
        return Type.Void;
    }
}
 
Example #4
Source Project: TencentKona-8   Author: Tencent   File: Parser.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Instanciates a SAX2 parser and generate the AST from the input.
 */
public void createAST(Stylesheet stylesheet) {
    try {
        if (stylesheet != null) {
            stylesheet.parseContents(this);
            final Iterator<SyntaxTreeNode> elements = stylesheet.elements();
            while (elements.hasNext()) {
                SyntaxTreeNode child = elements.next();
                if (child instanceof Text) {
                    final int l = getLineNumber();
                    ErrorMsg err =
                        new ErrorMsg(ErrorMsg.ILLEGAL_TEXT_NODE_ERR,l,null);
                    reportError(ERROR, err);
                }
            }
            if (!errorsFound()) {
                stylesheet.typeCheck(_symbolTable);
            }
        }
    }
    catch (TypeCheckError e) {
        reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
    }
}
 
Example #5
Source Project: TencentKona-8   Author: Tencent   File: BinOpExpr.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type tleft = _left.typeCheck(stable);
    final Type tright = _right.typeCheck(stable);
    final MethodType ptype = lookupPrimop(stable, Ops[_op],
                                          new MethodType(Type.Void,
                                                         tleft, tright));
    if (ptype != null) {
        final Type arg1 = (Type) ptype.argsType().elementAt(0);
        if (!arg1.identicalTo(tleft)) {
            _left = new CastExpr(_left, arg1);
        }
        final Type arg2 = (Type) ptype.argsType().elementAt(1);
        if (!arg2.identicalTo(tright)) {
            _right = new CastExpr(_right, arg1);
        }
        return _type = ptype.resultType();
    }
    throw new TypeCheckError(this);
}
 
Example #6
Source Project: TencentKona-8   Author: Tencent   File: CastExpr.java    License: 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 #7
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ContainsCall.java    License: Apache License 2.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) {
        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 #8
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: LogicalExpr.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Type-check this expression, and possibly child expressions.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    // Get the left and right operand types
    Type tleft = _left.typeCheck(stable);
    Type tright = _right.typeCheck(stable);

    // Check if the operator supports the two operand types
    MethodType wantType = new MethodType(Type.Void, tleft, tright);
    MethodType haveType = lookupPrimop(stable, Ops[_op], wantType);

    // Yes, the operation is supported
    if (haveType != null) {
        // Check if left-hand side operand must be type casted
        Type arg1 = (Type)haveType.argsType().elementAt(0);
        if (!arg1.identicalTo(tleft))
            _left = new CastExpr(_left, arg1);
        // Check if right-hand side operand must be type casted
        Type arg2 = (Type) haveType.argsType().elementAt(1);
        if (!arg2.identicalTo(tright))
            _right = new CastExpr(_right, arg1);
        // Return the result type for the operator we will use
        return _type = haveType.resultType();
    }
    throw new TypeCheckError(this);
}
 
Example #9
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ApplyTemplates.java    License: Apache License 2.0 6 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_select != null) {
        _type = _select.typeCheck(stable);
        if (_type instanceof NodeType || _type instanceof ReferenceType) {
            _select = new CastExpr(_select, Type.NodeSet);
            _type = Type.NodeSet;
        }
        if (_type instanceof NodeSetType||_type instanceof ResultTreeType) {
            typeCheckContents(stable); // with-params
            return Type.Void;
        }
        throw new TypeCheckError(this);
    }
    else {
        typeCheckContents(stable);          // with-params
        return Type.Void;
    }
}
 
Example #10
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: UnaryOpExpr.java    License: Apache License 2.0 6 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type tleft = _left.typeCheck(stable);
    final MethodType ptype = lookupPrimop(stable, "u-",
                                          new MethodType(Type.Void,
                                                         tleft));

    if (ptype != null) {
        final Type arg1 = (Type) ptype.argsType().elementAt(0);
        if (!arg1.identicalTo(tleft)) {
            _left = new CastExpr(_left, arg1);
        }
        return _type = ptype.resultType();
    }

    throw new TypeCheckError(this);
}
 
Example #11
Source Project: TencentKona-8   Author: Tencent   File: ContainsCall.java    License: 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) {
        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 #12
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Parser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Instanciates a SAX2 parser and generate the AST from the input.
 */
public void createAST(Stylesheet stylesheet) {
    try {
        if (stylesheet != null) {
            stylesheet.parseContents(this);
            final int precedence = stylesheet.getImportPrecedence();
            final Iterator<SyntaxTreeNode> elements = stylesheet.elements();
            while (elements.hasNext()) {
                SyntaxTreeNode child = elements.next();
                if (child instanceof Text) {
                    final int l = getLineNumber();
                    ErrorMsg err =
                        new ErrorMsg(ErrorMsg.ILLEGAL_TEXT_NODE_ERR,l,null);
                    reportError(ERROR, err);
                }
            }
            if (!errorsFound()) {
                stylesheet.typeCheck(_symbolTable);
            }
        }
    }
    catch (TypeCheckError e) {
        reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
    }
}
 
Example #13
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ValueOf.java    License: Apache License 2.0 6 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    Type type = _select.typeCheck(stable);

    // Prefer to handle the value as a node; fall back to String, otherwise
    if (type != null && !type.identicalTo(Type.Node)) {
        /***
         *** %HZ% Would like to treat result-tree fragments in the same
         *** %HZ% way as node sets for value-of, but that's running into
         *** %HZ% some snags.  Instead, they'll be converted to String
        if (type.identicalTo(Type.ResultTree)) {
            _select = new CastExpr(new CastExpr(_select, Type.NodeSet),
                                   Type.Node);
        } else
        ***/
        if (type.identicalTo(Type.NodeSet)) {
            _select = new CastExpr(_select, Type.Node);
        } else {
            _isString = true;
            if (!type.identicalTo(Type.String)) {
                _select = new CastExpr(_select, Type.String);
            }
            _isString = true;
        }
    }
    return Type.Void;
}
 
Example #14
Source Project: TencentKona-8   Author: Tencent   File: NameBase.java    License: 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 #15
Source Project: TencentKona-8   Author: Tencent   File: Param.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Type-checks the parameter. The parameter type is determined by the
 * 'select' expression (if present) or is a result tree if the parameter
 * element has a body and no 'select' expression.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_select != null) {
        _type = _select.typeCheck(stable);
        if (_type instanceof ReferenceType == false && !(_type instanceof ObjectType)) {
            _select = new CastExpr(_select, Type.Reference);
        }
    }
    else if (hasContents()) {
        typeCheckContents(stable);
    }
    _type = Type.Reference;

    // This element has no type (the parameter does, but the parameter
    // element itself does not).
    return Type.Void;
}
 
Example #16
Source Project: TencentKona-8   Author: Tencent   File: When.java    License: 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 #17
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: If.java    License: Apache License 2.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 #18
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: AttributeSet.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Type check the contents of this element
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {

    if (_ignore) return (Type.Void);

    // _mergeSet Point to any previous definition of this attribute set
    _mergeSet = stable.addAttributeSet(this);

    _method = AttributeSetPrefix + getXSLTC().nextAttributeSetSerial();

    if (_useSets != null) _useSets.typeCheck(stable);
    typeCheckContents(stable);
    return Type.Void;
}
 
Example #19
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Copy.java    License: Apache License 2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_useSets != null) {
        _useSets.typeCheck(stable);
    }
    typeCheckContents(stable);
    return Type.Void;
}
 
Example #20
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: FormatNumberCall.java    License: Apache License 2.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 #21
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ForEach.java    License: Apache License 2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    _type = _select.typeCheck(stable);

    if (_type instanceof ReferenceType || _type instanceof NodeType) {
        _select = new CastExpr(_select, Type.NodeSet);
        typeCheckContents(stable);
        return Type.Void;
    }
    if (_type instanceof NodeSetType||_type instanceof ResultTreeType) {
        typeCheckContents(stable);
        return Type.Void;
    }
    throw new TypeCheckError(this);
}
 
Example #22
Source Project: TencentKona-8   Author: Tencent   File: UnionPathExpr.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final int length = _components.length;
    for (int i = 0; i < length; i++) {
        if (_components[i].typeCheck(stable) != Type.NodeSet) {
            _components[i] = new CastExpr(_components[i], Type.NodeSet);
        }
    }
    return _type = Type.NodeSet;
}
 
Example #23
Source Project: TencentKona-8   Author: Tencent   File: Stylesheet.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Type check all the children of this node.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final int count = _globals.size();
    for (int i = 0; i < count; i++) {
        final VariableBase var = (VariableBase)_globals.elementAt(i);
        var.typeCheck(stable);
    }
    return typeCheckContents(stable);
}
 
Example #24
Source Project: TencentKona-8   Author: Tencent   File: StringCall.java    License: 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 #25
Source Project: TencentKona-8   Author: Tencent   File: XslElement.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Run type check on element name & contents
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (!_ignore) {
        _name.typeCheck(stable);
        if (_namespace != null) {
            _namespace.typeCheck(stable);
        }
    }
    typeCheckContents(stable);
    return Type.Void;
}
 
Example #26
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Template.java    License: Apache License 2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_pattern != null) {
        _pattern.typeCheck(stable);
    }

    return typeCheckContents(stable);
}
 
Example #27
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Number.java    License: Apache License 2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_value != null) {
        Type tvalue = _value.typeCheck(stable);
        if (tvalue instanceof RealType == false) {
            _value = new CastExpr(_value, Type.Real);
        }
    }
    if (_count != null) {
        _count.typeCheck(stable);
    }
    if (_from != null) {
        _from.typeCheck(stable);
    }
    if (_format != null) {
        _format.typeCheck(stable);
    }
    if (_lang != null) {
        _lang.typeCheck(stable);
    }
    if (_letterValue != null) {
        _letterValue.typeCheck(stable);
    }
    if (_groupingSeparator != null) {
        _groupingSeparator.typeCheck(stable);
    }
    if (_groupingSize != null) {
        _groupingSize.typeCheck(stable);
    }
    return Type.Void;
}
 
Example #28
Source Project: TencentKona-8   Author: Tencent   File: CopyOf.java    License: 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 #29
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: AbsoluteLocationPath.java    License: Apache License 2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_path != null) {
        final Type ptype = _path.typeCheck(stable);
        if (ptype instanceof NodeType) {            // promote to node-set
            _path = new CastExpr(_path, Type.NodeSet);
        }
    }
    return _type = Type.NodeSet;
}
 
Example #30
Source Project: TencentKona-8   Author: Tencent   File: XslAttribute.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (!_ignore) {
        _name.typeCheck(stable);
        if (_namespace != null) {
            _namespace.typeCheck(stable);
        }
        typeCheckContents(stable);
    }
    return Type.Void;
}