Package org.jboss.byteman.rule.type

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


            throws CompileException
    {
        // ensure any primitive type is boxed before we go any further

        if (fromType.isPrimitive()) {
            Type boxType = Type.boxType(fromType);
            compileBox(boxType, mv, compileContext);
            fromType = boxType;
        }

        if (toType.isAssignableFrom(fromType)) {
View Full Code Here


            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.internalName(HelperAdapter.class), "getBinding", "(Ljava/lang/String;)Ljava/lang/Object;");
            compileContext.addStackCount(-1);
            // perform any necessary type conversion
            if (type.isPrimitive()) {
                // cast down to the boxed type then do an unbox
                Type boxType = Type.boxType(type);
                compileObjectConversion(Type.OBJECT, boxType, mv, compileContext);
                compileUnbox(boxType, type,  mv, compileContext);
            } else {
                // cast down to the required type
                compileObjectConversion(Type.OBJECT, type, mv, compileContext);
View Full Code Here

        super(rule, oper, left.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 = type1;
        // if the type of operand1 is float or double we will convert it to long and
        // generate a long result so correct the promotion here
        if (type.isFloating()) {
            type = type.J;
View Full Code Here

        // then we type check the lhs ensuring that it can be assigned
        // with a value of this type. the resulting type has to be that
        // of the lhs.
        // if either operand cannot type check then it will throw an error

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

    private void checkIndirectStatic() throws TypeException
    {
        if (owner == null && pathList != null) {
            // factor off a typename from the path
            TypeGroup typeGroup = getTypeGroup();
            Type rootType = typeGroup.match(pathList);
            if (rootType == null) {
                throw new TypeException("FieldExpression.typeCheck : invalid path " + getPath(pathList.length) + " to static field " + fieldName + getPos());
            }

            // find out how many of the path elements are included in the type name

            String rootTypeName = rootType.getName();

            int idx = getPathCount(rootTypeName);

            if (idx < pathList.length) {
                // create a static field reference using the type name and the first field name and wrap it with
View Full Code Here

        return type;
    }

    private void typeCheckAny() 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;
    }
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
    {
        // make sure we are at the right source line
        compileContext.notifySourceLine(line);

        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 {
        // make sure we are at the right source line
        compileContext.notifySourceLine(line);

        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

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.