Package org.jboss.byteman.rule.type

Examples of org.jboss.byteman.rule.type.Type


            int argCount = arguments.size();

            // stack each of the arguments to the constructor
            for (int i = 0; i < argCount; i++) {
                Type argType = argumentTypes.get(i);
                Type paramType = paramTypes.get(i);
                int paramCount = (paramType.getNBytes() > 4 ? 2 : 1);

                // track extra storage used after type conversion
                extraParams += (paramCount);
                arguments.get(i).compile(mv, compileContext);
                compileTypeConversion(argType, paramType, mv, compileContext);
            }

            // construct the exception
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, instantiatedClassName, "<init>", getDescriptor());

            // modify the stack height to account for the removed exception and params
            compileContext.addStackCount(-(extraParams+1));
        } else {
            // TODO !!! implement compilation for array types !!!
            if (arrayDimCount == 1) {
                // we can use a NEWARRAY or ANEWARRAY
                Type baseType = type.getBaseType();
                // compile first array dimension adds 1 to stack
                arrayDims.get(0).compile(mv, compileContext);
                // compile new array op -- pops 1 and adds 1 to stack
                if (baseType.isObject()) {
                    mv.visitTypeInsn(Opcodes.ANEWARRAY, baseType.getInternalName());
                // } else if (baseType.isArray()) {  // cannot happen!!!
                } else {
                    int operand = 0;
                    if (baseType.equals(Type.Z)) {
                        operand = Opcodes.T_BOOLEAN;
                    } else if (baseType.equals(Type.B)) {
                        operand = Opcodes.T_BYTE;
                    } else if (baseType.equals(Type.S)) {
                        operand = Opcodes.T_SHORT;
                    } else if (baseType.equals(Type.C)) {
                        operand = Opcodes.T_CHAR;
                    } else if (baseType.equals(Type.I)) {
                        operand = Opcodes.T_INT;
                    } else if (baseType.equals(Type.J)) {
                        operand = Opcodes.T_LONG;
                    } else if (baseType.equals(Type.F)) {
                        operand = Opcodes.T_FLOAT;
                    } else if (baseType.equals(Type.D)) {
                        operand = Opcodes.T_DOUBLE;
                    }
                    mv.visitIntInsn(Opcodes.NEWARRAY, operand);
                }
            } else {
View Full Code Here


    {
        super(rule, oper, Type.promote(left.getType(), right.getType()), token, left, right);
    }

    public Type typeCheck(Type expected) throws TypeException {
        Type type1 = getOperand(0).typeCheck(Type.N);
        Type type2 = getOperand(1).typeCheck(Type.N);
        type = Type.promote(type1, type2);
        if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type) ) {
            throw new TypeException("ArithmenticExpression.typeCheck : invalid expected result type " + expected.getName() + getPos());
        }
View Full Code Here

    {
        int currentStack = compileContext.getStackCount();
        int expectedStack = 0;
        Expression operand0 = getOperand(0);
        Expression operand1 = getOperand(1);
        Type type0 = operand0.getType();
        Type type1 = operand1.getType();
        // compile lhs -- it adds 1 or 2 to the stack height
        operand0.compile(mv, compileContext);
        // do any required type conversion
        compileTypeConversion(type0, type, mv, compileContext);
        // compile rhs -- it adds 1 or 2 to the stack height
View Full Code Here

    public Type typeCheck(Type expected) throws TypeException {
        // we accept any type we are given and check the var type then we use its type to check the expression
        // if either operand cannot type check then it will throw an error

        Type type1 = lhs.typeCheck(expected);
        Type type2 = getOperand(1).typeCheck(type1);
        type = type1;
        return type;
    }
View Full Code Here

    {
        super(rule, COND, type, token, cond, if_expr, else_expr);
    }

    public Type typeCheck(Type expected) throws TypeException {
        Type condType = getOperand(0).typeCheck(Type.Z);
        Type type1 = getOperand(1).typeCheck(expected);
        Type type2 = getOperand(2).typeCheck(expected);
        // type1 must be defined and type2 must be the same as type 1 or assignable
        // to/from it.
        if (type2 != type1) {
            // ok check that the types are interassignable in at least one direction
            // but we have to treat numerics as special cases because we can assign in
            // many directions
            if (type1.isNumeric() && type2.isNumeric()) {
                type = Type.promote(type1,  type2);
            } else if (type2.isAssignableFrom(type1)) {
                type = type2;
            } else if (type1.isAssignableFrom(type2)) {
                type = type1;
            } else {
                throw new TypeException("ConditionalEvalExpression.typeCheck : incompatible argument types " + type1.getName() + " and " + type2.getName() + getPos());
            }
        } else {
            // use either type
            type = type1;
        }
View Full Code Here

    }

    public Type typeCheck(Type expected) throws TypeException {
        // first type must be a string -- second may be anything but expect
        // a string to indicate that it must be assignable evn if only by conversion
        Type type1 = getOperand(0).typeCheck(Type.STRING);
        Type type2 = getOperand(1).typeCheck(Type.STRING);
        // result will always be a String
        if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(Type.STRING)) {
            throw new TypeException("StringPlusExpression.typeCheck : invalid expected result type " + expected.getName() + getPos());
        }
        return type;
View Full Code Here

            // e.g. the parameter type may be int and the arg type float
            // or the parameter type may be String and the arg type class Foo
            // reimplement this using type inter-assignability to do the pruning

            Class candidateClass = getCandidateArgClass(candidates, i);
            Type candidateType;
            if (candidateClass != null) {
                candidateType = typeGroup.ensureType(candidateClass);
            } else {
                candidateType = Type.UNDEFINED;
            }
            Type argType = arguments.get(i).typeCheck(candidateType);
            argumentTypes.add(argType);
            if (candidateType == Type.UNDEFINED) {
                // we had several constructors to choose from
                candidates = pruneCandidates(candidates, i, argType.getTargetClass());
            }
        }

        if (candidates.isEmpty()) {
            throw new TypeException("ThrowExpression.typeCheck : invalid constructor for target class " + typeName + getPos());
        }

        if (candidates.size() > 1) {
            throw new TypeException("ThrowExpression.typeCheck : ambiguous constructor signature for target class " + typeName + getPos());
        }

        constructor = candidates.get(0);

        // make sure we know the formal parameter types and have included them in the typegroup

        paramTypes = new ArrayList<Type>();
        Class<?>[] paramClasses = constructor.getParameterTypes();

        for (int i = 0; i < arguments.size() ; i++) {
            paramTypes.add(typeGroup.ensureType(paramClasses[i]));
        }

        // expected type should always be void since throw can only occur as a top level action
        // however, we need to be sure that the trigering method throws this exception type or
        // else that it is a subtype of runtime exception

        if (RuntimeException.class.isAssignableFrom(type.getTargetClass())) {
            return type;
        } else {
            Iterator<Type> iterator = typeGroup.getExceptionTypes().iterator();
            while (iterator.hasNext()) {
                Type exceptionType = iterator.next();
                if (Type.dereference(exceptionType).isAssignableFrom(type)) {
                    // ok we foudn a suitable declaration for the exception
                    return type;
                }
            }
View Full Code Here

        int argCount = arguments.size();

        // stack each of the arguments to the constructor
        for (int i = 0; i < argCount; i++) {
            Type argType = argumentTypes.get(i);
            Type paramType = paramTypes.get(i);
            int paramCount = (paramType.getNBytes() > 4 ? 2 : 1);

            // track extra storage used after type conversion
            extraParams += (paramCount);
            arguments.get(i).compile(mv, compileContext);
            compileTypeConversion(argType, paramType, mv, compileContext);
View Full Code Here

            {
                throw new TypeException("ExpressionHelper.createExpression : unexpected token type " + tag + " for expression " + exprTree.getPos());
            }
        }

        Type exprType = Type.dereference(expr.getType());
        Type targetType = Type.dereference(type);
        if (exprType.isDefined() && targetType.isDefined() && !targetType.isAssignableFrom(exprType)) {
            // we already know this is an invalid type so notify an error and return null
            throw new TypeException("ExpressionHelper.createExpression : invalid expression type " + exprType.getName() + " expecting " + targetType.getName() + exprTree.getPos());
        } else if (targetType.isNumeric() && !exprType.isNumeric()) {
            // we already know this is an invalid type so notify an error and return null
            throw new TypeException("ExpressionHelper.createExpression : invalid expression type " + exprType.getName() + " expecting " + targetType.getName() + exprTree.getPos());
        }
        // don't do this here as it gets called recursively -- need to do it in Binding, Condition and Action
        /*
        if (!expr.bind()) {
            throw new TypeException("ExpressionHelper.createExpression : unknown reference in expression" + exprTree.getPos());
View Full Code Here

            {
                // the first argument must be a boolean expression
                Expression operand0 = createExpression(rule, bindings, child0, Type.BOOLEAN);
                Expression operand1 = createExpression(rule, bindings, child1, type);
                Expression operand2 = createExpression(rule, bindings, child2, type);
                Type type1 = Type.dereference(operand1.getType());
                Type type2 = Type.dereference(operand2.getType());
                if (type1.isNumeric() || type2.isNumeric()) {
                    if (!type.isUndefined() && !type.isVoid() && !type.isNumeric()) {
                        throw new TypeException("ExpressionHelper.createUnaryExpression : invalid numeric expression" + exprTree.getPos());
                    }
                    expr = new ConditionalEvalExpression(rule, Type.promote(type1, type2),  exprTree, operand0,  operand1, operand2);
                } else if (type1.isDefined() && type2.isDefined()) {
                    // since they are not numeric we have to have the same type
                    if (type1 == type2) {
                        // use this type
                        expr = new ConditionalEvalExpression(rule, type1,  exprTree, operand0,  operand1, operand2);
                    } else {
                        // mismatched types so don't generate a result
                        throw new TypeException("ExpressionHelper.createTernaryExpression : mismatched expression types " + type1.getName() + " and " + type2.getName()  + " in conditional expression " + exprTree.getText() + exprTree.getPos());
                    }
                } else {
                    // have to wait for type check to resolve types
                    expr = new ConditionalEvalExpression(rule, Type.UNDEFINED,  exprTree, operand0,  operand1, operand2);
                }
View Full Code Here

TOP

Related Classes of org.jboss.byteman.rule.type.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.