Java Code Examples for org.apache.bcel.Const#DCMPG

The following examples show how to use org.apache.bcel.Const#DCMPG . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpcodeStack.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void handleDcmp(int opcode) {
    Item it = pop();
    Item it2 = pop();

    if ((it.getConstant() != null) && it2.getConstant() != null) {
        double d = constantToDouble(it);
        double d2 = constantToDouble(it2);
        if (Double.isNaN(d) || Double.isNaN(d2)) {
            if (opcode == Const.DCMPG) {
                push(new Item("I", Integer.valueOf(1)));
            } else {
                push(new Item("I", Integer.valueOf(-1)));
            }
        }
        if (d2 < d) {
            push(new Item("I", Integer.valueOf(-1)));
        } else if (d2 > d) {
            push(new Item("I", Integer.valueOf(1)));
        } else {
            push(new Item("I", Integer.valueOf(0)));
        }
    } else {
        push(new Item("I"));
    }
}
 
Example 2
Source File: FindComparatorProblems.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (getStack().getStackDepth() == 0) {
        this.lastEmptyStackPC = getPC();
    }
    if ((seen == Const.DCMPG || seen == Const.DCMPL || seen == Const.FCMPL || seen == Const.FCMPG) && getStack().getStackDepth() == 2) {
        int[] startEnd = new int[] { this.lastEmptyStackPC, getPC() };
        for (Iterator<int[]> iterator = twoDoublesInStack.iterator(); iterator.hasNext();) {
            int[] oldStartEnd = iterator.next();
            if (codeEquals(oldStartEnd, startEnd)) {
                Item item1 = getStack().getStackItem(0);
                Item item2 = getStack().getStackItem(1);
                accumulator.accumulateBug(
                        new BugInstance("CO_COMPARETO_INCORRECT_FLOATING", NORMAL_PRIORITY).addClassAndMethod(this)
                                .addType(item1.getSignature())
                                .addMethod(item1.getSignature().equals("D") ? DOUBLE_DESCRIPTOR : FLOAT_DESCRIPTOR).describe(
                                        MethodAnnotation.SHOULD_CALL)
                                .addValueSource(item1, this)
                                .addValueSource(item2, this), this);
                iterator.remove();
                return;
            }
        }
        twoDoublesInStack.add(startEnd);
    }
    if (seen == Const.IRETURN) {
        OpcodeStack.Item top = stack.getStackItem(0);
        Object o = top.getConstant();
        if (o instanceof Integer && ((Integer) o).intValue() == Integer.MIN_VALUE) {
            accumulator.accumulateBug(
                    new BugInstance(this, "CO_COMPARETO_RESULTS_MIN_VALUE", NORMAL_PRIORITY).addClassAndMethod(this), this);
        }
    }
}
 
Example 3
Source File: FindFloatEquality.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    switch (seen) {
    case Const.FCMPG:
    case Const.FCMPL:
    case Const.DCMPG:
    case Const.DCMPL:
        if (stack.getStackDepth() >= 2) {
            OpcodeStack.Item first = stack.getStackItem(0);
            OpcodeStack.Item second = stack.getStackItem(1);

            if (first.getRegisterNumber() == second.getRegisterNumber() && first.getRegisterNumber() != -1) {
                break;
            }
            if (first.isInitialParameter() && second.isInitialParameter()) {
                break;
            }
            if (sameField(first, second)) {
                break;
            }

            Number n1 = (Number) first.getConstant();
            Number n2 = (Number) second.getConstant();
            if (n1 != null && Double.isNaN(n1.doubleValue()) || n2 != null && Double.isNaN(n2.doubleValue())) {
                BugInstance bug = new BugInstance(this, "FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER", HIGH_PRIORITY)
                        .addClassAndMethod(this);
                bugAccumulator.accumulateBug(bug, this);
                state = SAW_NOTHING;
                break;
            }
            if (first.getSpecialKind() == OpcodeStack.Item.NASTY_FLOAT_MATH && !isZero(n2)
                    || second.getSpecialKind() == OpcodeStack.Item.NASTY_FLOAT_MATH && !isZero(n1)
                    || first.getSpecialKind() == OpcodeStack.Item.FLOAT_MATH && !okValueToCompareAgainst(n2)
                    || second.getSpecialKind() == OpcodeStack.Item.FLOAT_MATH && !okValueToCompareAgainst(n1)) {
                if (priority != HIGH_PRIORITY) {
                    found.clear();
                }
                priority = HIGH_PRIORITY;
                state = SAW_COMP;
                break;
            }
            if (priority == HIGH_PRIORITY) {
                break;
            }
            // if (first.isInitialParameter() && n2 != null) break;
            // if (second.isInitialParameter() && n1 != null) break;
            if (n1 != null && n2 != null) {
                break;
            }

            if (okValueToCompareAgainst(n1) || okValueToCompareAgainst(n2)) {
                break;
            }
            if (n1 != null && !second.isInitialParameter() || n2 != null && !first.isInitialParameter()) {
                if (priority == LOW_PRIORITY) {
                    found.clear();
                }
                priority = NORMAL_PRIORITY;

            } else if (priority == NORMAL_PRIORITY) {
                break;
            }
            state = SAW_COMP;
        }
        break;

    case Const.IFEQ:
    case Const.IFNE:
        if (state == SAW_COMP) {
            SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this,
                    getPC());
            if (sourceLineAnnotation != null) {
                found.add(sourceLineAnnotation);
            }
        }
        state = SAW_NOTHING;
        break;

    default:
        state = SAW_NOTHING;
        break;
    }
}