Package org.jboss.byteman.rule.type

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


    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

    public Type typeCheck(Type expected) throws TypeException {
        // if the expected type is numeric then we know this must be an arithmetic plus
        // if it is string then this could still be an arithmetic plus so we will
        // have to rely on the type of the first argument to guide us

        Type type1 = getOperand(0).typeCheck((expected.isNumeric() ? expected : Type.UNDEFINED));
        Type type2;

        if (type1.isNumeric()) {
            type2 = getOperand(1).typeCheck(Type.N);
            type = Type.promote(type1, type2);
        } else if (type1.isString()) {
View Full Code Here

            iterator.next().bind();
        }
    }

    public Type typeCheck(Type expected) throws TypeException {
        Type arrayType = arrayRef.typeCheck(Type.UNDEFINED);
        Type nextType = arrayType;
        for (Expression expr : idxList) {
            if (!nextType.isArray()) {
                throw new TypeException("ArrayExpression.typeCheck : invalid type for array dereference " + nextType.getName() + getPos());
            }
            nextType = nextType.getBaseType();
            expr.typeCheck(Type.N);
        }
        type = nextType;
        if (Type.dereference(expected).isDefined() && !expected.isAssignableFrom(type)) {
            throw new TypeException("ArrayExpression.typeCheck : invalid expected result type " + expected.getName() + getPos());
View Full Code Here

        // evaluate the array expression then evaluate each index expression in turn and
        // dereference to access the array element

        try {
            Object value = arrayRef.interpret(helper);
            Type nextType = arrayRef.getType();
            for (Expression expr : idxList) {
                int idx = ((Number) expr.interpret(helper)).intValue();
                if (value == null) {
                    throw new ExecuteException("ArrayExpression.interpret : attempted array indirection through null value " + arrayRef.token.getText() + getPos());
                }
                value = Array.get(value, idx);
                nextType = nextType.getBaseType();
            }

            return value;
        } catch (ExecuteException e) {
            throw e;
View Full Code Here

        }
    }

    public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException
    {
        Type valueType = arrayRef.getType().getBaseType();
        int currentStack = compileContext.getStackCount();
        int expected = 0;

        // compile load of array reference -- adds 1 to stack height
        arrayRef.compile(mv, compileContext);
        // for each index expression compile the expression and the do an array load
        Iterator<Expression> iterator = idxList.iterator();

        while (iterator.hasNext()) {
            Expression idxExpr = iterator.next();
            // compile expression index -- adds 1 to height
            idxExpr.compile(mv, compileContext);
            // make sure the index is an integer
            compileTypeConversion(idxExpr.getType(), Type.I, mv, compileContext);

            if (valueType.isObject() || valueType.isArray()) {
                // compile load object - pops 2 and adds 1
                mv.visitInsn(Opcodes.AALOAD);
                expected = 1;
            } else if (valueType == Type.Z || valueType == Type.B) {
                // compile load byte - pops 2 and adds 1
                mv.visitInsn(Opcodes.BALOAD);
                expected = 1;
            } else if (valueType == Type.S) {
                // compile load short - pops 2 and adds 1
                mv.visitInsn(Opcodes.SALOAD);
                expected = 1;
            } else if (valueType == Type.C) {
                // compile load char - pops 2 and adds 1
                mv.visitInsn(Opcodes.CALOAD);
                expected = 1;
            } else if (valueType == Type.I) {
                // compile load int - pops 2 and adds 1
                mv.visitInsn(Opcodes.IALOAD);
                expected = 1;
            } else if (valueType == Type.J) {
                // compile load long - pops 2 and adds 2
                mv.visitInsn(Opcodes.LALOAD);
                expected = 2;
            } else if (valueType == Type.F) {
                // compile load float - pops 2 and adds 1
                mv.visitInsn(Opcodes.FALOAD);
                expected = 1;
            } else if (valueType == Type.D) {
                // compile load double - pops 2 and adds 2
                mv.visitInsn(Opcodes.DALOAD);
                expected = 2;
            }
            compileContext.addStackCount(expected - 2);
            if (iterator.hasNext()) {
                assert valueType.isArray();
                valueType =valueType.getBaseType();
            }
        }

        // check stack height
        if (compileContext.getStackCount() != currentStack + expected) {
View Full Code Here

        // and dereference to access the array at that index. finally evaluate the final index expression
        // and use it as the position at which to install the supplied value in the dereferenced array

        try {
            Object array = arrayRef.interpret(helper);
            Type nextType = arrayRef.getType();
            int count = idxList.size() - 1;
            for (Expression expr : idxList) {
                int idx = ((Number) expr.interpret(helper)).intValue();
                if (array == null) {
                    throw new ExecuteException("ArrayExpression.interpret : attempted array indirection through null value " + arrayRef.token.getText() + getPos());
                }
                if (count-- >  0)  {
                    array = Array.get(array, idx);
                    nextType = nextType.getBaseType();
                } else {
                    Array.set(array, idx, value);
                }
            }
            return value;
View Full Code Here

        }
    }

    @Override
    public void compileAssign(MethodVisitor mv, CompileContext compileContext) throws CompileException {
        Type valueType = arrayRef.getType().getBaseType();
        int currentStack = compileContext.getStackCount();
        boolean isTwoWords = (valueType.getNBytes() > 4);
        int toPop = 0;
        int size = (isTwoWords ? 2 : 1);

        // value to be assigned is TOS and will already be coerced to the correct value type
        // copy it so we can install the copy and leave the original as a a return value on the stack
        if (isTwoWords) {
            // [... val1 val2 ==> ... val1 val2 val1 val2]
            mv.visitInsn(Opcodes.DUP2);
        } else {
            // [... val ==> ... val val]
            mv.visitInsn(Opcodes.DUP);
        }
        compileContext.addStackCount(size);

        // compile load of array reference -- adds 1 to stack height
        arrayRef.compile(mv, compileContext);
        // for each index expression compile the expression and the do an array load
        Iterator<Expression> iterator = idxList.iterator();

        while (iterator.hasNext()) {
            Expression idxExpr = iterator.next();
            if (iterator.hasNext()) {
                // dereference the array to get an embedded array
                // compile expression index -- adds 1 to height
                idxExpr.compile(mv, compileContext);
                // make sure the index is an integer
                compileTypeConversion(idxExpr.getType(), Type.I, mv, compileContext);
                // fetch embedded array pop 2 and add 1
                mv.visitInsn(Opcodes.AALOAD);
                compileContext.addStackCount(-1);
                valueType = valueType.getBaseType();
            } else {
                if (isTwoWords) {
                    // stack is [..., val1, val2, val1, val2, aref ] and we want [..., val1, val2, aref, val1, val2 ]
                    mv.visitInsn(Opcodes.DUP_X2);     // ==>  [..., val1, val2, aref. val1, val2, aref ]
                    compileContext.addStackCount(1);
                    mv.visitInsn(Opcodes.POP);        // ==> [..., val1, val2, aref. val1, val2 ]
                    compileContext.addStackCount(-1);
                } else {
                    // stack is [..., val, val, aref ] and we want [..., val, aref, val ]
                    mv.visitInsn(Opcodes.SWAP);
                }
                // compile expression index -- adds 1 to height
                idxExpr.compile(mv, compileContext);
                // make sure the index is an integer
                compileTypeConversion(idxExpr.getType(), Type.I, mv, compileContext);
                if (isTwoWords) {
                    // stack is [..., val1, val2, aref, val1, val2, idx] and we want [..., val1, val2, aref, idx, val1, val2 ]
                    mv.visitInsn(Opcodes.DUP_X2);     // ==> [..., val1, val2, aref, idx, val1, val2, idx]
                    compileContext.addStackCount(1);
                    mv.visitInsn(Opcodes.POP);        // ==> [..., val1, val2, aref, idx, val1, val2 ]
                    compileContext.addStackCount(-1);
                } else {
                    // stack is [..., val, aref, val, idx] and we want [..., val, aref, idx, val ]
                    mv.visitInsn(Opcodes.SWAP);
                }
                // now we can do the array store
                if (valueType.isObject() || valueType.isArray()) {
                    // compile load object - pops 3
                    mv.visitInsn(Opcodes.AASTORE);
                    toPop =- 3;
                } else if (valueType == Type.Z || valueType == Type.B) {
                    // compile load byte - pops 3
                    mv.visitInsn(Opcodes.BASTORE);
                    toPop = -3;
                } else if (valueType == Type.S) {
                    // compile load short - pops 3
                    mv.visitInsn(Opcodes.SASTORE);
                    toPop = -3;
                } else if (valueType == Type.C) {
                    // compile load char - pops 3
                    mv.visitInsn(Opcodes.CASTORE);
                    toPop = -3;
                } else if (valueType == Type.I) {
                    // compile load int - pops 3
                    mv.visitInsn(Opcodes.IASTORE);
                    toPop = -3;
                } else if (valueType == Type.J) {
                    // compile load long - pops 4
                    mv.visitInsn(Opcodes.LASTORE);
                    toPop = -4;
                } else if (valueType == Type.F) {
                    // compile load float - pops 3
                    mv.visitInsn(Opcodes.FASTORE);
                    toPop = -3;
                } else if (valueType == Type.D) {
                    // compile load double - pops 4
                    mv.visitInsn(Opcodes.DASTORE);
                    toPop = -4;
                }
                compileContext.addStackCount(toPop);
                if (iterator.hasNext()) {
                    assert valueType.isArray();
                    valueType =valueType.getBaseType();
                }
            }
        }

        // check stack height
View Full Code Here

    }

    public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException
    {
        Expression oper = getOperand(0);
        Type operType = oper.getType();

        int currentStack = compileContext.getStackCount();
        int expected = 1;

        // compile code to execute the operand -- adds 1
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.