Package org.cojen.classfile

Examples of org.cojen.classfile.Label


            if (goodLabel == null) {
                goodLabel = builder.createLabel();
                locateGoodLabel = true;
            }

            Label tryStart = builder.createLabel().setLocation();
            builder.loadLocal(a);
            builder.checkCast(comparableType);
            builder.loadLocal(b);
            builder.checkCast(comparableType);
            Label tryEnd = builder.createLabel().setLocation();
            builder.invoke(compareToMethod);
            builder.branch(goodLabel);

            builder.exceptionHandler(tryStart, tryEnd,
                                     ClassCastException.class.getName());
View Full Code Here


        }

        if (isEqualsMethod) {
            b.loadThis();
            b.loadLocal(b.getParameter(0));
            Label notEqual = b.createLabel();
            b.ifEqualBranch(notEqual, false);
            b.loadConstant(true);
            b.returnValue(TypeDesc.BOOLEAN);

            notEqual.setLocation();

            // Check if object is our type.
            b.loadLocal(b.getParameter(0));
            b.instanceOf(cf.getType());
            Label isInstance = b.createLabel();
            b.ifZeroComparisonBranch(isInstance, "!=");

            b.loadConstant(false);
            b.returnValue(TypeDesc.BOOLEAN);

            isInstance.setLocation();
        }

        final TypeDesc atomicRefType = TypeDesc.forClass(AtomicReference.class);

        // Load wrapped object...
View Full Code Here

                }

                return;
            }

            Label noMatch = mBuilder.createLabel();

            if (c >= 0) {
                if (tempChar != null) {
                    mBuilder.loadLocal(tempChar);
                    mTempLocals.push(tempChar);
                } else {
                    mBuilder.loadLocal(mLookupLocal);
                    mBuilder.loadLocal(mIndexLocal);
                    if (depth > 0) {
                        mBuilder.loadConstant(depth);
                        mBuilder.math(Opcode.IADD);
                    }
                    mBuilder.loadFromArray(TypeDesc.CHAR);
                }
               
                mBuilder.loadConstant((char)c);
                mBuilder.ifComparisonBranch(noMatch, "!=");
            }
           
            if (subNodes != null) {
                int size = subNodes.size();
                for (int i=0; i<size; i++) {
                    generateBranches
                        ((PatternNode)subNodes.get(i), depth + 1, posIndex);
                }
            }
           
            if (node.mPattern != null) {
                // Matched pattern; save results.
                generateAddMatchResult(node);
            }

            noMatch.setLocation();
        }
View Full Code Here

            noMatch.setLocation();
        }
       
        private void generateWildcard(PatternNode node, int depth,
                                      int posIndex) {
            Label loopStart = mBuilder.createLabel().setLocation();
            Label loopEnd = mBuilder.createLabel();
            Label loopContinue = mBuilder.createLabel();

            // Save position of wildcard end.
            mBuilder.loadLocal(mPositionsLocal);
            mBuilder.loadConstant(posIndex - 1);
            mBuilder.loadLocal(mIndexLocal);
            if (depth > 0) {
                mBuilder.loadConstant(depth);
                mBuilder.math(Opcode.IADD);
            }
            mBuilder.storeToArray(TypeDesc.INT);

            mBuilder.loadLocal(mLookupLocal);
            mBuilder.loadLocal(mIndexLocal);
            if (depth > 0) {
                mBuilder.loadConstant(depth);
                mBuilder.math(Opcode.IADD);
            }
            mBuilder.loadFromArray(TypeDesc.CHAR);

            if (node == null) {
                mBuilder.loadConstant('\uffff');
                mBuilder.ifComparisonBranch(loopEnd, "==");
            } else {
                LocalVariable tempChar;
                if (mTempLocals.isEmpty()) {
                    tempChar =
                        mBuilder.createLocalVariable("temp", mIntType);
                } else {
                    tempChar = (LocalVariable)mTempLocals.pop();
                }
                mBuilder.storeLocal(tempChar);
                mBuilder.loadLocal(tempChar);

                mBuilder.loadConstant('\uffff');
                mBuilder.ifComparisonBranch(loopEnd, "==");

                generateBranches(node, depth, posIndex, tempChar);
            }

            loopContinue.setLocation();
            mBuilder.integerIncrement(mIndexLocal, 1);
            mBuilder.branch(loopStart);
            loopEnd.setLocation();
        }
View Full Code Here

            for (int i=0; i<caseCount; i++) {
                cases[i] = i;
            }

            Label[] switchLabels = new Label[caseCount];
            Label noMatch = b.createLabel();
            List[] caseMethods = caseMethods(caseCount, properties);
           
            for (int i=0; i<caseCount; i++) {
                List matches = caseMethods[i];
                if (matches == null || matches.size() == 0) {
                    switchLabels[i] = noMatch;
                } else {
                    switchLabels[i] = b.createLabel();
                }
            }

            if (properties.length > 1) {
                b.loadLocal(propertyVar);
                b.invokeVirtual(String.class.getName(), "hashCode", TypeDesc.INT, null);
                b.loadConstant(0x7fffffff);
                b.math(Opcode.IAND);
                b.loadConstant(caseCount);
                b.math(Opcode.IREM);
           
                b.switchBranch(cases, switchLabels, noMatch);
            }
           
            // Params to invoke String.equals.
            TypeDesc[] params = {TypeDesc.OBJECT};
           
            for (int i=0; i<caseCount; i++) {
                List matches = caseMethods[i];
                if (matches == null || matches.size() == 0) {
                    continue;
                }
               
                switchLabels[i].setLocation();
               
                int matchCount = matches.size();
                for (int j=0; j<matchCount; j++) {
                    BeanProperty bp = (BeanProperty)matches.get(j);
                   
                    // Test against name to find exact match.
                   
                    b.loadConstant(bp.getName());
                    b.loadLocal(propertyVar);
                    b.invokeVirtual(String.class.getName(), "equals", TypeDesc.BOOLEAN, params);
                   
                    Label notEqual;
                   
                    if (j == matchCount - 1) {
                        notEqual = null;
                        b.ifZeroComparisonBranch(noMatch, "==");
                    } else {
                        notEqual = b.createLabel();
                        b.ifZeroComparisonBranch(notEqual, "==");
                    }
                   
                    switch (methodType) {
                    case READ_METHOD: case TRY_READ_METHOD: default: {
                        b.loadLocal(beanVar);
                        b.invoke(bp.getReadMethod());
                        TypeDesc type = TypeDesc.forClass(bp.getType());
                        b.convert(type, type.toObjectType());
                        b.returnValue(TypeDesc.OBJECT);
                        break;
                    }
                    case WRITE_METHOD: case TRY_WRITE_METHOD: {
                        b.loadLocal(beanVar);
                        b.loadLocal(valueVar);
                        TypeDesc type = TypeDesc.forClass(bp.getType());
                        b.checkCast(type.toObjectType());
                        b.convert(type.toObjectType(), type);
                        b.invoke(bp.getWriteMethod());
                        if (methodType == WRITE_METHOD) {
                            b.returnVoid();
                        } else {
                            b.loadConstant(true);
                            b.returnValue(TypeDesc.BOOLEAN);
                        }
                        break;
                    }
                    case HAS_READ_METHOD: case HAS_WRITE_METHOD: {
                        b.loadConstant(true);
                        b.returnValue(TypeDesc.BOOLEAN);
                        break;
                    }
                    }
                   
                    if (notEqual != null) {
                        notEqual.setLocation();
                    }
                }
            }
           
            noMatch.setLocation();
View Full Code Here

        LocalVariable valueVar = b.getParameter(1);

        // If search value is null, only check properties which might be null.
        b.loadLocal(valueVar);
        Label searchNotNull = b.createLabel();
        b.ifNullBranch(searchNotNull, false);

        for (BeanProperty bp : properties) {
            if (bp.getType().isPrimitive()) {
                continue;
            }

            b.loadLocal(beanVar);
            b.invoke(bp.getReadMethod());

            Label noMatch = b.createLabel();
            b.ifNullBranch(noMatch, false);
            b.loadConstant(true);
            b.returnValue(TypeDesc.BOOLEAN);

            noMatch.setLocation();
        }

        b.loadConstant(false);
        b.returnValue(TypeDesc.BOOLEAN);

        searchNotNull.setLocation();

        // Handle search for non-null value. Search non-primitive properties
        // first, to avoid object conversion.

        // Params to invoke Object.equals.
        TypeDesc[] params = {TypeDesc.OBJECT};

        for (int pass = 1; pass <= 2; pass++) {
            for (BeanProperty bp : properties) {
                boolean primitive = bp.getType().isPrimitive();
                if (pass == 1 && primitive) {
                    continue;
                } else if (pass == 2 && !primitive) {
                    continue;
                }

                b.loadLocal(valueVar);
                b.loadLocal(beanVar);
                b.invoke(bp.getReadMethod());
                b.convert(TypeDesc.forClass(bp.getType()), TypeDesc.OBJECT);
                b.invokeVirtual(Object.class.getName(), "equals", TypeDesc.BOOLEAN, params);

                Label noMatch = b.createLabel();
                b.ifZeroComparisonBranch(noMatch, "==");
                b.loadConstant(true);
                b.returnValue(TypeDesc.BOOLEAN);

                noMatch.setLocation();
            }
        }

        b.loadConstant(false);
        b.returnValue(TypeDesc.BOOLEAN);
View Full Code Here

TOP

Related Classes of org.cojen.classfile.Label

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.