com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType

Here are the examples of the java api class com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType taken from open source projects.

1. LogicalExpr#typeCheck()

Project: openjdk
File: LogicalExpr.java
/**
     * 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);
}

2. UnaryOpExpr#typeCheck()

Project: openjdk
File: UnaryOpExpr.java
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);
}

3. BinOpExpr#typeCheck()

Project: openjdk
File: BinOpExpr.java
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);
}

4. FunctionCall#typeCheckStandard()

Project: openjdk
File: FunctionCall.java
/**
     * 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 {
    // HACK!!!
    _fname.clearNamespace();
    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);
                }
            }
        }
        _chosenMethodType = ptype;
        return _type = ptype.resultType();
    }
    throw new TypeCheckError(this);
}

5. RelationalExpr#typeCheck()

Project: openjdk
File: RelationalExpr.java
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
    Type tleft = _left.typeCheck(stable);
    Type tright = _right.typeCheck(stable);
    //bug fix # 2838, cast to reals if both are result tree fragments
    if (tleft instanceof ResultTreeType && tright instanceof ResultTreeType) {
        _right = new CastExpr(_right, Type.Real);
        _left = new CastExpr(_left, Type.Real);
        return _type = Type.Boolean;
    }
    // If one is of reference type, then convert the other too
    if (hasReferenceArgs()) {
        Type type = null;
        Type typeL = null;
        Type typeR = null;
        if (tleft instanceof ReferenceType) {
            if (_left instanceof VariableRefBase) {
                VariableRefBase ref = (VariableRefBase) _left;
                VariableBase var = ref.getVariable();
                typeL = var.getType();
            }
        }
        if (tright instanceof ReferenceType) {
            if (_right instanceof VariableRefBase) {
                VariableRefBase ref = (VariableRefBase) _right;
                VariableBase var = ref.getVariable();
                typeR = var.getType();
            }
        }
        // bug fix # 2838
        if (typeL == null)
            type = typeR;
        else if (typeR == null)
            type = typeL;
        else {
            type = Type.Real;
        }
        if (type == null)
            type = Type.Real;
        _right = new CastExpr(_right, type);
        _left = new CastExpr(_left, type);
        return _type = Type.Boolean;
    }
    if (hasNodeSetArgs()) {
        // Ensure that the node-set is the left argument
        if (tright instanceof NodeSetType) {
            final Expression temp = _right;
            _right = _left;
            _left = temp;
            _op = (_op == Operators.GT) ? Operators.LT : (_op == Operators.LT) ? Operators.GT : (_op == Operators.GE) ? Operators.LE : Operators.GE;
            tright = _right.getType();
        }
        // Promote nodes to node sets
        if (tright instanceof NodeType) {
            _right = new CastExpr(_right, Type.NodeSet);
        }
        // Promote integer to doubles to have fewer compares
        if (tright instanceof IntType) {
            _right = new CastExpr(_right, Type.Real);
        }
        // Promote result-trees to strings
        if (tright instanceof ResultTreeType) {
            _right = new CastExpr(_right, Type.String);
        }
        return _type = Type.Boolean;
    }
    // In the node-boolean case, convert node to boolean first
    if (hasNodeArgs()) {
        if (tleft instanceof BooleanType) {
            _right = new CastExpr(_right, Type.Boolean);
            tright = Type.Boolean;
        }
        if (tright instanceof BooleanType) {
            _left = new CastExpr(_left, Type.Boolean);
            tleft = Type.Boolean;
        }
    }
    // Lookup the table of primops to find the best match
    MethodType ptype = lookupPrimop(stable, Operators.getOpNames(_op), new MethodType(Type.Void, tleft, tright));
    if (ptype != null) {
        Type arg1 = (Type) ptype.argsType().elementAt(0);
        if (!arg1.identicalTo(tleft)) {
            _left = new CastExpr(_left, arg1);
        }
        Type arg2 = (Type) ptype.argsType().elementAt(1);
        if (!arg2.identicalTo(tright)) {
            _right = new CastExpr(_right, arg1);
        }
        return _type = ptype.resultType();
    }
    throw new TypeCheckError(this);
}

6. Expression#lookupPrimop()

Project: openjdk
File: Expression.java
/**
     * Search for a primop in the symbol table that matches the method type
     * <code>ctype</code>. Two methods match if they have the same arity.
     * If a primop is overloaded then the "closest match" is returned. The
     * first entry in the vector of primops that has the right arity is
     * considered to be the default one.
     */
public MethodType lookupPrimop(SymbolTable stable, String op, MethodType ctype) {
    MethodType result = null;
    final Vector primop = stable.lookupPrimop(op);
    if (primop != null) {
        final int n = primop.size();
        int minDistance = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            final MethodType ptype = (MethodType) primop.elementAt(i);
            // Skip if different arity
            if (ptype.argsCount() != ctype.argsCount()) {
                continue;
            }
            // The first method with the right arity is the default
            if (result == null) {
                // default method
                result = ptype;
            }
            // Check if better than last one found
            final int distance = ctype.distanceTo(ptype);
            if (distance < minDistance) {
                minDistance = distance;
                result = ptype;
            }
        }
    }
    return result;
}