Package org.jboss.byteman.rule.type

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


        // where          new_expr_idx = ^(EXPR) |
        //                               ^(NOTHING)
        // and we also have the constraints that any EXPR is expected to have an int type andthat
        // once we see the first NOTHING we only expect NOTHING from then onwards

        Type type =  Type.I;

        List<Expression> exprList = new ArrayList<Expression>();
        List<TypeException> exceptions = new ArrayList<TypeException>();
        boolean foundEmptyDim = false;
        int arrayDimCount = 0;
View Full Code Here


    }

    private void installParameters(boolean isStatic, String className)
            throws TypeException
    {
        Type type;
        // add a binding for the helper so we can call builtin static methods
        type = typeGroup.create(helperClass.getName());
        Binding ruleBinding = bindings.lookup("$$");
        if (ruleBinding != null) {
            ruleBinding.setType(type);
        } else {
            bindings.append(new Binding(this, "$$", type));
        }

        if (!isStatic) {
            Binding recipientBinding = bindings.lookup("$0");
            if (recipientBinding != null) {
                type = typeGroup.create(className);
                if (type.isUndefined()) {
                    throw new TypeException("Rule.installParameters : Rule " + name + " unable to load class " + className);
                }
                recipientBinding.setType(type);
            }
        }

        String returnTypeName = Type.parseMethodReturnType(triggerDescriptor);

        returnType = typeGroup.create(returnTypeName);

        Iterator<Binding> iterator = bindings.iterator();

        while (iterator.hasNext()) {
            Binding binding = iterator.next();
            // these bindings are typed via the descriptor installed during trigger injection
            // note that the return type has to be done this way because it may represent the
            // trigger method return type or the invoke method return type
            if (binding.isParam() || binding.isLocalVar() || binding.isReturn()) {
                String typeName = binding.getDescriptor();
                String[] typeAndArrayBounds = typeName.split("\\[");
                Type baseType = typeGroup.create(typeAndArrayBounds[0]);
                Type fullType = baseType;
                if (baseType.isUndefined()) {
                    throw new TypeException("Rule.installParameters : Rule " + name + " unable to load class " + baseType);
                }
                for (int i = 1; i < typeAndArrayBounds.length ; i++) {
                    fullType = typeGroup.createArray(fullType);
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

        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 either arg 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

        if (recipient == null && pathList != null) {
            // treat the pathlist as a typename or a static field dereference possibly combined with
            // further field dereferences

            // factor off a typename from the path
            Type rootType = typeGroup.match(pathList);
            if (rootType == null) {
                throw new TypeException("MethodExpression.typeCheck : invalid path " + getPath(pathList.length) + " to static method " + name + 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
                // enough field references to use up all the path

                String fieldName = pathList[idx++];
                Expression recipient = new StaticExpression(rule, Type.UNDEFINED, token, fieldName, rootTypeName);
                while (idx < pathList.length) {
                    recipient = new FieldExpression(rule, Type.UNDEFINED, token, pathList[idx++], recipient, null);
                }
                this.recipient = recipient;
            } else {
                // ok, this method reference is actually a static method call -- record the root type for later
                this.recipient = null;
                this.rootType = rootType;
            }
            // get rid of the path list now
            this.pathList = null;
            // not strictly necessary?
            if (this.recipient != null) {
                this.recipient.bind();
            }
        }

        // if we don't have a recipient and we didn't find a static class for the method then this is
        // a builtin

        boolean isBuiltIn = false;

        if (recipient == null) {
            if (rootType == null) {
                isBuiltIn = true;
                Type ruleType = typeGroup.create(rule.getHelperClass().getCanonicalName());
                recipient = new DollarExpression(rule, ruleType, token, DollarExpression.HELPER_IDX);
                recipient.bind();

                rootType = recipient.typeCheck(Type.UNDEFINED);
            }
View Full Code Here

                    if (candidates.isEmpty()) {
                        // no more possible matches
                        break;
                    }
                    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 methods to choose from
                        candidates = pruneCandidates(candidates, i, argType.getTargetClass());
                    }
                }

                // see if we have a unique best fit
View Full Code Here

                extraParams += 1;
            }

            for (int i = 0; i < argCount; i++) {
                Expression argument = arguments.get(i);
                Type argType = argumentTypes.get(i);
                Type paramType = paramTypes.get(i);
                // compile code to stack argument and type convert if necessary
                argument.compile(mv, compileContext);
                compileTypeConversion(argType, paramType, mv, compileContext);
                // allow for stacked paramType value
                extraParams += (paramType.getNBytes() > 4 ? 2 : 1);
            }

            // enable triggering before we call the method
            // this adds an extra value to the stack so modify the compile context to ensure
            // we increase the maximum height if necessary
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "org/jboss/byteman/rule/Rule", "enableTriggersInternal", "()Z");
            compileContext.addStackCount(1);
            mv.visitInsn(Opcodes.POP);
            compileContext.addStackCount(-1);

            // ok, now just call the method -- removes extraParams words

            String ownerName = Type.internalName(method.getDeclaringClass());

            if (recipient == null) {
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, ownerName, method.getName(), getDescriptor());
            } else if (method.getDeclaringClass().isInterface()) {
                mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, ownerName, method.getName(), getDescriptor());
            } else {
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ownerName, method.getName(), getDescriptor());
            }
            // decrement the stack height to account for stacked param values (removed) and return value (added)
            compileContext.addStackCount(expected - extraParams);

            // now disable triggering again
            // this temporarily adds an extra value to the stack -- n.b. we *must* increment and
            // then decrement the stack height even though we bumped the max before the call. in
            // some cases the stack may be larger after the method call than before e.g. calling
            // a static which returns a value or calling a non-static which returns a long/double

            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "org/jboss/byteman/rule/Rule", "disableTriggersInternal", "()Z");
            compileContext.addStackCount(1);
            mv.visitInsn(Opcodes.POP);
            compileContext.addStackCount(-1);
        } else {
            // if we are calling a method by reflection then we need to stack the current helper then
            // the recipient or null if there is none and then build an object array on the stack
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            compileContext.addStackCount(1);
            if (recipient != null) {
                // compile code for recipient
                recipient.compile(mv, compileContext);
            } else {
                mv.visitInsn(Opcodes.ACONST_NULL);
                compileContext.addStackCount(1);
            }

            // stack arg count then create a new array
            mv.visitLdcInsn(argCount);
            compileContext.addStackCount(1);
            // this just swaps one word for another
            mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");

            // duplicate the array, stack the index, compile code to generate the arg and the do an array put
            for (int i = 0; i < argCount; i++) {
                mv.visitInsn(Opcodes.DUP);
                mv.visitLdcInsn(i);
                // that was two extra words
                compileContext.addStackCount(2);
                Expression argument = arguments.get(i);
                Type argType = argumentTypes.get(i);
                Type paramType = paramTypes.get(i);
                // compile code to stack argument and type convert/box if necessary
                argument.compile(mv, compileContext);
                compileTypeConversion(argType, paramType, mv, compileContext);
                compileBox(paramType, mv, compileContext);
                // that's 3 extra words which now get removed
View Full Code Here

        compileContext.addStackCount(2);
        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

        comparable = false;
    }

    public Type typeCheck(Type expected) throws TypeException {
        // TODO allow comparison of non-numeric values
        Type type1 = getOperand(0).typeCheck(Type.UNDEFINED);
        Type type2 = getOperand(1).typeCheck(Type.UNDEFINED);
        if (type1.isNumeric() || type2.isNumeric()) {
            comparisonType = Type.promote(type1,  type2);
            comparable = true;
        } else if (type1.isAssignableFrom(type2)) {
            comparisonType = type1;
            comparable = Comparable.class.isAssignableFrom(comparisonType.getTargetClass());
        } else if (type2.isAssignableFrom(type1)) {
            comparisonType = type2;
            comparable = Comparable.class.isAssignableFrom(comparisonType.getTargetClass());
        } else {
            throw new TypeException("ComparisonExpression.typeCheck : incomparable argument types " + type1.getName() + " and " + type2.getName() + " for comparison expression"  + getPos());
        }

        // we have to implement anything other than EQ or NE using Comparable
       
        if (oper != EQ && oper != NE && !comparable) {
View Full Code Here

            // if this is not already a numeric type then generate a cast
            if (!fromType.isNumeric()) {
                compileObjectConversion(fromType, Type.NUMBER, mv, compileContext);
            }
            if (box) {
                Type midType = Type.boxType(toType);
                compileUnbox(fromType, midType, mv, compileContext);
                compileBox(midType, mv, compileContext);
            } else {
                compileUnbox(fromType, toType, mv, compileContext);
            }
        } else if (box) {
            Type midType = Type.boxType(toType);
            if (fromType != midType) {
                compilePrimitiveConversion(fromType, midType, mv, compileContext);
            }
            compileBox(toType, mv, compileContext);
        } else {
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.