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

The following examples show how to use com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type. These examples are extracted from open source projects. 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: Bytecoder   Author: mirkosertic   File: CastExpr.java    License: 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 #2
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: FilterExpr.java    License: 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 #3
Source Project: Bytecoder   Author: mirkosertic   File: Sort.java    License: 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 #4
Source Project: openjdk-8   Author: bpupadhyaya   File: Variable.java    License: 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 #5
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: StartsWithCall.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) {
        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 #6
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 #7
Source Project: openjdk-8-source   Author: keerath   File: StartsWithCall.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) {
        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 #8
Source Project: openjdk-8-source   Author: keerath   File: Sort.java    License: 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 #9
Source Project: openjdk-8   Author: bpupadhyaya   File: ValueOf.java    License: 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 #10
Source Project: Bytecoder   Author: mirkosertic   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 #11
Source Project: openjdk-8-source   Author: keerath   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: 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 #13
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Param.java    License: 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 #14
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   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 #15
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: CastExpr.java    License: 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 #16
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   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 #17
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: EqualityExpr.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void translateDesynthesized(ClassGenerator classGen,
                                   MethodGenerator methodGen) {
    final Type tleft = _left.getType();
    final InstructionList il = methodGen.getInstructionList();

    if (tleft instanceof BooleanType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);
    _falseList.add(il.append(_op == Operators.EQ ?
                                 (BranchInstruction)new IF_ICMPNE(null) :
                                 (BranchInstruction)new IF_ICMPEQ(null)));
    }
    else if (tleft instanceof NumberType) {
        _left.translate(classGen, methodGen);
        _right.translate(classGen, methodGen);

        if (tleft instanceof RealType) {
            il.append(DCMPG);
    _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IFNE(null) :
                                     (BranchInstruction)new IFEQ(null)));
        }
        else {
        _falseList.add(il.append(_op == Operators.EQ ?
                                     (BranchInstruction)new IF_ICMPNE(null) :
                                     (BranchInstruction)new IF_ICMPEQ(null)));
        }
    }
    else {
        translate(classGen, methodGen);
        desynthesize(classGen, methodGen);
    }
}
 
Example #18
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   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 #19
Source Project: openjdk-8   Author: bpupadhyaya   File: UnsupportedElement.java    License: GNU General Public License v2.0 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 #20
Source Project: hottub   Author: dsrg-uoft   File: Copy.java    License: GNU General Public License v2.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 #21
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 #22
Source Project: Bytecoder   Author: mirkosertic   File: StringCall.java    License: Apache License 2.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 #23
Source Project: openjdk-8   Author: bpupadhyaya   File: AttributeValueTemplate.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    final Vector contents = getContents();
    final int n = contents.size();
    for (int i = 0; i < n; i++) {
        final Expression exp = (Expression)contents.elementAt(i);
        if (!exp.typeCheck(stable).identicalTo(Type.String)) {
            contents.setElementAt(new CastExpr(exp, Type.String), i);
        }
    }
    return _type = Type.String;
}
 
Example #24
Source Project: hottub   Author: dsrg-uoft   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: JDKSourceCode1.8   Author: wupeixuan   File: BooleanCall.java    License: MIT License 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 #26
Source Project: hottub   Author: dsrg-uoft   File: WithParam.java    License: 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 #27
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: CastExpr.java    License: GNU General Public License v2.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 #28
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: ConcatCall.java    License: 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 #29
Source Project: TencentKona-8   Author: Tencent   File: WithParam.java    License: 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 Project: JDKSourceCode1.8   Author: wupeixuan   File: UnsupportedElement.java    License: 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;
}