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

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type. 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: Variable.java    From openjdk-8 with GNU General Public License v2.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 File: CastExpr.java    From jdk1.8-source-analysis with Apache License 2.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 #3
Source File: ApplyTemplates.java    From openjdk-jdk9 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 #4
Source File: Param.java    From jdk1.8-source-analysis with Apache License 2.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: 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 #6
Source File: CastExpr.java    From Bytecoder with Apache License 2.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 File: CastExpr.java    From openjdk-jdk8u-backup 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 #8
Source File: ContainsCall.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) {
        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 #9
Source File: ApplyTemplates.java    From Bytecoder 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 #10
Source File: FilterExpr.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 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 where $x is a parameter reference.
 * All optimizations are turned off before type checking underlying
 * predicates.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    Type ptype = _primary.typeCheck(stable);
    boolean canOptimize = _primary instanceof KeyCall;

    if (ptype instanceof NodeSetType == false) {
        if (ptype instanceof ReferenceType)  {
            _primary = new CastExpr(_primary, Type.NodeSet);
        }
        else {
            throw new TypeCheckError(this);
        }
    }

    // Type check predicates and turn all optimizations off if appropriate
    int n = _predicates.size();
    for (int i = 0; i < n; i++) {
        Predicate pred = (Predicate) _predicates.elementAt(i);

        if (!canOptimize) {
            pred.dontOptimize();
        }
        pred.typeCheck(stable);
    }
    return _type = Type.NodeSet;
}
 
Example #11
Source File: ValueOf.java    From openjdk-8 with GNU General Public License v2.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 #12
Source File: Sort.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(Vector sortObjects,
                                       NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #13
Source File: Sort.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Create a constructor for the new class. Updates the reference to the
 * collator in the super calls only when the stylesheet specifies a new
 * language in xsl:sort.
 */
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
                                       ConstantPoolGen cpg,
                                       String className)
{
    final InstructionList il = new InstructionList();
    final MethodGenerator init =
        new MethodGenerator(ACC_PUBLIC,
                            com.sun.org.apache.bcel.internal.generic.Type.VOID,
                            null, null, "<init>", className,
                            il, cpg);

    // Call the constructor in the NodeSortRecord superclass
    il.append(ALOAD_0);
    il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                                                 "<init>", "()V")));



    il.append(RETURN);

    return init;
}
 
Example #14
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 #15
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 #16
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 #17
Source File: Sort.java    From jdk8u60 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 #18
Source File: CastExpr.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    final Type ltype = _left.getType();
    _left.translate(classGen, methodGen);
    if (_type.identicalTo(ltype) == false) {
        _left.startIterator(classGen, methodGen);
        ltype.translateTo(classGen, methodGen, _type);
    }
}
 
Example #19
Source File: LiteralElement.java    From openjdk-jdk8u 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 #20
Source File: Key.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    // Type check match pattern
    _match.typeCheck(stable);

    // Cast node values to string values (except for nodesets)
    _useType = _use.typeCheck(stable);
    if (_useType instanceof StringType == false &&
        _useType instanceof NodeSetType == false)
    {
        _use = new CastExpr(_use, Type.String);
    }

    return Type.Void;
}
 
Example #21
Source File: UnionPathExpr.java    From hottub with 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 #22
Source File: Whitespace.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Compiles the predicate method
 */
private static void compileDefault(int defaultAction,
                                   ClassGenerator classGen) {
    final ConstantPoolGen cpg = classGen.getConstantPool();
    final InstructionList il = new InstructionList();
    final XSLTC xsltc = classGen.getParser().getXSLTC();

    // private boolean Translet.stripSpace(int type) - cannot be static
    final MethodGenerator stripSpace =
        new MethodGenerator(ACC_PUBLIC | ACC_FINAL ,
                    com.sun.org.apache.bcel.internal.generic.Type.BOOLEAN,
                    new com.sun.org.apache.bcel.internal.generic.Type[] {
                        Util.getJCRefType(DOM_INTF_SIG),
                        com.sun.org.apache.bcel.internal.generic.Type.INT,
                        com.sun.org.apache.bcel.internal.generic.Type.INT
                    },
                    new String[] { "dom","node","type" },
                    "stripSpace",classGen.getClassName(),il,cpg);

    classGen.addInterface("com/sun/org/apache/xalan/internal/xsltc/StripFilter");

    if (defaultAction == STRIP_SPACE)
        il.append(ICONST_1);
    else
        il.append(ICONST_0);
    il.append(IRETURN);

    classGen.addMethod(stripSpace);
}
 
Example #23
Source File: If.java    From openjdk-8-source 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 #24
Source File: ElementAvailableCall.java    From openjdk-8-source 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 #25
Source File: Number.java    From openjdk-jdk8u-backup with GNU General Public License v2.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 #26
Source File: UnsupportedElement.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Run type check on the fallback element (if any).
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_fallbacks != null) {
        int count = _fallbacks.size();
        for (int i = 0; i < count; i++) {
            Fallback fallback = (Fallback)_fallbacks.elementAt(i);
            fallback.typeCheck(stable);
        }
    }
    return Type.Void;
}
 
Example #27
Source File: BooleanCall.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
    _arg.translate(classGen, methodGen);
    final Type targ = _arg.getType();
    if (!targ.identicalTo(Type.Boolean)) {
        _arg.startIterator(classGen, methodGen);
        targ.translateTo(classGen, methodGen, Type.Boolean);
    }
}
 
Example #28
Source File: FunctionCall.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Type check a call to a standard function. Insert CastExprs when needed.
 * If as a result of the insertion of a CastExpr a type check error is
 * thrown, then catch it and re-throw it with a new "this".
 */
public Type typeCheckStandard(SymbolTable stable) throws TypeCheckError {
    _fname.clearNamespace();        // HACK!!!

    final int n = _arguments.size();
    final Vector argsType = typeCheckArgs(stable);
    final MethodType args = new MethodType(Type.Void, argsType);
    final MethodType ptype =
        lookupPrimop(stable, _fname.getLocalPart(), args);

    if (ptype != null) {
        for (int i = 0; i < n; i++) {
            final Type argType = (Type) ptype.argsType().elementAt(i);
            final Expression exp = (Expression)_arguments.elementAt(i);
            if (!argType.identicalTo(exp.getType())) {
                try {
                    _arguments.setElementAt(new CastExpr(exp, argType), i);
                }
                catch (TypeCheckError e) {
                    throw new TypeCheckError(this); // invalid conversion
                }
            }
        }
        _chosenMethodType = ptype;
        return _type = ptype.resultType();
    }
    throw new TypeCheckError(this);
}
 
Example #29
Source File: WithParam.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Type-check either the select attribute or the element body, depending
 * on which is in use.
 */
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    if (_select != null) {
        final Type tselect = _select.typeCheck(stable);
        if (tselect instanceof ReferenceType == false) {
            _select = new CastExpr(_select, Type.Reference);
        }
    } else {
        typeCheckContents(stable);
    }
    return Type.Void;
}
 
Example #30
Source File: ConcatCall.java    From jdk1.8-source-analysis 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;
}