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 File: Parser.java    From jdk1.8-source-analysis with 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 #2
Source File: ApplyTemplates.java    From TencentKona-8 with 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 #3
Source File: NameBase.java    From jdk1.8-source-analysis with 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 #4
Source File: Param.java    From TencentKona-8 with 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 #5
Source File: Variable.java    From jdk1.8-source-analysis with 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 #6
Source File: Parser.java    From TencentKona-8 with 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 #7
Source File: BinOpExpr.java    From TencentKona-8 with 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 #8
Source File: NameBase.java    From TencentKona-8 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 #9
Source File: LogicalExpr.java    From jdk1.8-source-analysis with 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 #10
Source File: ContainsCall.java    From jdk1.8-source-analysis with 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 #11
Source File: ContainsCall.java    From TencentKona-8 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) {
        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 File: UnaryOpExpr.java    From jdk1.8-source-analysis with 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 #13
Source File: ValueOf.java    From jdk1.8-source-analysis with 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 File: CastExpr.java    From TencentKona-8 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 #15
Source File: ApplyTemplates.java    From jdk1.8-source-analysis with 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 #16
Source File: FunctionAvailableCall.java    From jdk1.8-source-analysis with Apache License 2.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 #17
Source File: If.java    From jdk1.8-source-analysis with 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 File: When.java    From TencentKona-8 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 #19
Source File: TransletOutput.java    From TencentKona-8 with GNU General Public License v2.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 #20
Source File: LiteralElement.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Type-check the contents of this element. The element itself does not
 * need any type checking as it leaves nothign on the JVM's stack.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    // Type-check all attributes
    if (_attributeElements != null) {
        for (SyntaxTreeNode node : _attributeElements) {
            node.typeCheck(stable);
        }
    }
    typeCheckContents(stable);
    return Type.Void;
}
 
Example #21
Source File: FilteredAbsoluteLocationPath.java    From TencentKona-8 with GNU General Public License v2.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 #22
Source File: Template.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_pattern != null) {
        _pattern.typeCheck(stable);
    }

    return typeCheckContents(stable);
}
 
Example #23
Source File: Stylesheet.java    From jdk1.8-source-analysis with Apache License 2.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 File: CallTemplate.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that a template with this name exists.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Template template = stable.lookupTemplate(_name);
    if (template != null) {
        typeCheckContents(stable);
    }
    else {
        ErrorMsg err = new ErrorMsg(ErrorMsg.TEMPLATE_UNDEF_ERR,_name,this);
        throw new TypeCheckError(err);
    }
    return Type.Void;
}
 
Example #25
Source File: FilterParentPath.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Type check a FilterParentPath. If the filter is not a node-set add a
 * cast to node-set only if it is of reference type. This type coercion is
 * needed for expressions like $x/LINE where $x is a parameter reference.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Type ftype = _filterExpr.typeCheck(stable);
    if (ftype instanceof NodeSetType == false) {
        if (ftype instanceof ReferenceType)  {
            _filterExpr = new CastExpr(_filterExpr, Type.NodeSet);
        }
        /*
        else if (ftype instanceof ResultTreeType)  {
            _filterExpr = new CastExpr(_filterExpr, Type.NodeSet);
        }
        */
        else if (ftype instanceof NodeType)  {
            _filterExpr = new CastExpr(_filterExpr, Type.NodeSet);
        }
        else {
            throw new TypeCheckError(this);
        }
    }

    // Wrap single node path in a node set
    final Type ptype = _path.typeCheck(stable);
    if (!(ptype instanceof NodeSetType)) {
        _path = new CastExpr(_path, Type.NodeSet);
    }

    return _type = Type.NodeSet;
}
 
Example #26
Source File: AttributeSet.java    From jdk1.8-source-analysis with 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 #27
Source File: ForEach.java    From jdk1.8-source-analysis with 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 #28
Source File: XslAttribute.java    From TencentKona-8 with 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;
}
 
Example #29
Source File: ParentLocationPath.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    stype = _step.typeCheck(stable);
    _path.typeCheck(stable);

    if (_axisMismatch) enableNodeOrdering();

    return _type = Type.NodeSet;
}
 
Example #30
Source File: When.java    From jdk1.8-source-analysis with Apache License 2.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;
}