From f43ccbb72a865a834d5670651386ace11d61355a Mon Sep 17 00:00:00 2001 From: d367wang Date: Sat, 19 Feb 2022 15:53:12 -0500 Subject: [PATCH 1/3] small tweaks --- src/checkers/inference/DefaultSlotManager.java | 13 +++++-------- src/checkers/inference/SlotManager.java | 2 +- .../inference/model/ArithmeticConstraint.java | 10 ++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/checkers/inference/DefaultSlotManager.java b/src/checkers/inference/DefaultSlotManager.java index a18e4a37..24b91be7 100644 --- a/src/checkers/inference/DefaultSlotManager.java +++ b/src/checkers/inference/DefaultSlotManager.java @@ -577,14 +577,11 @@ public ExistentialVariableSlot createExistentialVariableSlot(Slot potentialSlot, /** * Determine the type kind of an arithmetic operation, based on Binary Numeric Promotion in JLS 5.6.2. - * @param lhsAtm atm of left operand - * @param rhsAtm atm of right operand + * @param lhsType type of left operand + * @param rhsType type of right operand * @return type kind of the arithmetic operation */ - private TypeKind getArithmeticResultKind(AnnotatedTypeMirror lhsAtm, AnnotatedTypeMirror rhsAtm) { - TypeMirror lhsType = lhsAtm.getUnderlyingType(); - TypeMirror rhsType = rhsAtm.getUnderlyingType(); - + private TypeKind getArithmeticResultKind(TypeMirror lhsType, TypeMirror rhsType) { assert (TypesUtils.isPrimitiveOrBoxed(lhsType) && TypesUtils.isPrimitiveOrBoxed(rhsType)); if (TypesUtils.isFloatingPoint(lhsType) || TypesUtils.isFloatingPoint(rhsType)) { @@ -601,7 +598,7 @@ private TypeKind getArithmeticResultKind(AnnotatedTypeMirror lhsAtm, AnnotatedTy @Override public ArithmeticVariableSlot createArithmeticVariableSlot( - AnnotationLocation location, AnnotatedTypeMirror lhsAtm, AnnotatedTypeMirror rhsAtm) { + AnnotationLocation location, TypeMirror lhs, TypeMirror rhs) { if (location == null || location.getKind() == AnnotationLocation.Kind.MISSING) { throw new BugInCF( "Cannot create an ArithmeticVariableSlot with a missing annotation location."); @@ -612,7 +609,7 @@ public ArithmeticVariableSlot createArithmeticVariableSlot( } // create the arithmetic var slot if it doesn't exist for the given location - TypeKind kind = getArithmeticResultKind(lhsAtm, rhsAtm); + TypeKind kind = getArithmeticResultKind(lhs, rhs); ArithmeticVariableSlot slot = new ArithmeticVariableSlot(nextId(), location, kind); addToSlots(slot); arithmeticSlotCache.put(location, slot.getId()); diff --git a/src/checkers/inference/SlotManager.java b/src/checkers/inference/SlotManager.java index 37cea000..fc887f17 100644 --- a/src/checkers/inference/SlotManager.java +++ b/src/checkers/inference/SlotManager.java @@ -155,7 +155,7 @@ public interface SlotManager { * @return the ArithmeticVariableSlot for the given location */ ArithmeticVariableSlot createArithmeticVariableSlot( - AnnotationLocation location, AnnotatedTypeMirror lhsAtm, AnnotatedTypeMirror rhsAtm); + AnnotationLocation location, TypeMirror lhs, TypeMirror rhs); /** * Create new ComparisonVariableSlot at the given location and return a reference to it if no diff --git a/src/checkers/inference/model/ArithmeticConstraint.java b/src/checkers/inference/model/ArithmeticConstraint.java index 83074a7e..d38c7179 100644 --- a/src/checkers/inference/model/ArithmeticConstraint.java +++ b/src/checkers/inference/model/ArithmeticConstraint.java @@ -57,6 +57,16 @@ public static ArithmeticOperationKind fromTreeKind(Kind kind) { return OR; case XOR: return XOR; + case PLUS_ASSIGNMENT: + return PLUS; + case MINUS_ASSIGNMENT: + return MINUS; + case MULTIPLY_ASSIGNMENT: + return MULTIPLY; + case DIVIDE_ASSIGNMENT: + return DIVIDE; + case REMAINDER_ASSIGNMENT: + return REMAINDER; default: throw new BugInCF("There are no defined ArithmeticOperationKinds " + "for the given com.sun.source.tree.Tree.Kind: " + kind); From fa37174e8b62aaa3b19ffa07e70895625059022f Mon Sep 17 00:00:00 2001 From: d367wang <55197967+d367wang@users.noreply.github.com> Date: Sat, 5 Mar 2022 13:54:35 -0500 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Werner Dietl --- src/checkers/inference/DefaultSlotManager.java | 4 ++-- src/checkers/inference/SlotManager.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/checkers/inference/DefaultSlotManager.java b/src/checkers/inference/DefaultSlotManager.java index 24b91be7..d2d2407f 100644 --- a/src/checkers/inference/DefaultSlotManager.java +++ b/src/checkers/inference/DefaultSlotManager.java @@ -598,7 +598,7 @@ private TypeKind getArithmeticResultKind(TypeMirror lhsType, TypeMirror rhsType) @Override public ArithmeticVariableSlot createArithmeticVariableSlot( - AnnotationLocation location, TypeMirror lhs, TypeMirror rhs) { + AnnotationLocation location, TypeMirror lhsType, TypeMirror rhsType) { if (location == null || location.getKind() == AnnotationLocation.Kind.MISSING) { throw new BugInCF( "Cannot create an ArithmeticVariableSlot with a missing annotation location."); @@ -609,7 +609,7 @@ public ArithmeticVariableSlot createArithmeticVariableSlot( } // create the arithmetic var slot if it doesn't exist for the given location - TypeKind kind = getArithmeticResultKind(lhs, rhs); + TypeKind kind = getArithmeticResultKind(lhsType, rhsType); ArithmeticVariableSlot slot = new ArithmeticVariableSlot(nextId(), location, kind); addToSlots(slot); arithmeticSlotCache.put(location, slot.getId()); diff --git a/src/checkers/inference/SlotManager.java b/src/checkers/inference/SlotManager.java index fc887f17..65dfd967 100644 --- a/src/checkers/inference/SlotManager.java +++ b/src/checkers/inference/SlotManager.java @@ -155,7 +155,7 @@ public interface SlotManager { * @return the ArithmeticVariableSlot for the given location */ ArithmeticVariableSlot createArithmeticVariableSlot( - AnnotationLocation location, TypeMirror lhs, TypeMirror rhs); + AnnotationLocation location, TypeMirror lhsType, TypeMirror rhsType); /** * Create new ComparisonVariableSlot at the given location and return a reference to it if no From ddd327c44e7bdcc83137e507f0c66607a3a0f3d2 Mon Sep 17 00:00:00 2001 From: d367wang Date: Sat, 5 Mar 2022 16:28:15 -0500 Subject: [PATCH 3/3] add supported arithmetic operations in ArithmeticOperationKind.fromTreeKind --- .../inference/DefaultSlotManager.java | 13 +++++---- src/checkers/inference/SlotManager.java | 2 +- .../inference/model/ArithmeticConstraint.java | 27 ++++++++++++------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/checkers/inference/DefaultSlotManager.java b/src/checkers/inference/DefaultSlotManager.java index d2d2407f..a18e4a37 100644 --- a/src/checkers/inference/DefaultSlotManager.java +++ b/src/checkers/inference/DefaultSlotManager.java @@ -577,11 +577,14 @@ public ExistentialVariableSlot createExistentialVariableSlot(Slot potentialSlot, /** * Determine the type kind of an arithmetic operation, based on Binary Numeric Promotion in JLS 5.6.2. - * @param lhsType type of left operand - * @param rhsType type of right operand + * @param lhsAtm atm of left operand + * @param rhsAtm atm of right operand * @return type kind of the arithmetic operation */ - private TypeKind getArithmeticResultKind(TypeMirror lhsType, TypeMirror rhsType) { + private TypeKind getArithmeticResultKind(AnnotatedTypeMirror lhsAtm, AnnotatedTypeMirror rhsAtm) { + TypeMirror lhsType = lhsAtm.getUnderlyingType(); + TypeMirror rhsType = rhsAtm.getUnderlyingType(); + assert (TypesUtils.isPrimitiveOrBoxed(lhsType) && TypesUtils.isPrimitiveOrBoxed(rhsType)); if (TypesUtils.isFloatingPoint(lhsType) || TypesUtils.isFloatingPoint(rhsType)) { @@ -598,7 +601,7 @@ private TypeKind getArithmeticResultKind(TypeMirror lhsType, TypeMirror rhsType) @Override public ArithmeticVariableSlot createArithmeticVariableSlot( - AnnotationLocation location, TypeMirror lhsType, TypeMirror rhsType) { + AnnotationLocation location, AnnotatedTypeMirror lhsAtm, AnnotatedTypeMirror rhsAtm) { if (location == null || location.getKind() == AnnotationLocation.Kind.MISSING) { throw new BugInCF( "Cannot create an ArithmeticVariableSlot with a missing annotation location."); @@ -609,7 +612,7 @@ public ArithmeticVariableSlot createArithmeticVariableSlot( } // create the arithmetic var slot if it doesn't exist for the given location - TypeKind kind = getArithmeticResultKind(lhsType, rhsType); + TypeKind kind = getArithmeticResultKind(lhsAtm, rhsAtm); ArithmeticVariableSlot slot = new ArithmeticVariableSlot(nextId(), location, kind); addToSlots(slot); arithmeticSlotCache.put(location, slot.getId()); diff --git a/src/checkers/inference/SlotManager.java b/src/checkers/inference/SlotManager.java index 65dfd967..37cea000 100644 --- a/src/checkers/inference/SlotManager.java +++ b/src/checkers/inference/SlotManager.java @@ -155,7 +155,7 @@ public interface SlotManager { * @return the ArithmeticVariableSlot for the given location */ ArithmeticVariableSlot createArithmeticVariableSlot( - AnnotationLocation location, TypeMirror lhsType, TypeMirror rhsType); + AnnotationLocation location, AnnotatedTypeMirror lhsAtm, AnnotatedTypeMirror rhsAtm); /** * Create new ComparisonVariableSlot at the given location and return a reference to it if no diff --git a/src/checkers/inference/model/ArithmeticConstraint.java b/src/checkers/inference/model/ArithmeticConstraint.java index d38c7179..85992820 100644 --- a/src/checkers/inference/model/ArithmeticConstraint.java +++ b/src/checkers/inference/model/ArithmeticConstraint.java @@ -33,40 +33,47 @@ private ArithmeticOperationKind(String opSymbol) { this.opSymbol = opSymbol; } + /** + * Get the {@link ArithmeticOperationKind} corresponding to a {@link Tree.Kind}. For a compound + * assignment tree, get the {@link ArithmeticOperationKind} for the arithmetic operation of the RHS. + * @param kind a {@link Tree.Kind} for an arithmetic operation + * @return the corresponding {@link ArithmeticOperationKind} for the given arithmetic operation + */ public static ArithmeticOperationKind fromTreeKind(Kind kind) { switch (kind) { case PLUS: + case PLUS_ASSIGNMENT: return PLUS; case MINUS: + case MINUS_ASSIGNMENT: return MINUS; case MULTIPLY: + case MULTIPLY_ASSIGNMENT: return MULTIPLY; case DIVIDE: + case DIVIDE_ASSIGNMENT: return DIVIDE; case REMAINDER: + case REMAINDER_ASSIGNMENT: return REMAINDER; case LEFT_SHIFT: + case LEFT_SHIFT_ASSIGNMENT: return LEFT_SHIFT; case RIGHT_SHIFT: + case RIGHT_SHIFT_ASSIGNMENT: return RIGHT_SHIFT; case UNSIGNED_RIGHT_SHIFT: + case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT: return UNSIGNED_RIGHT_SHIFT; case AND: + case AND_ASSIGNMENT: return AND; case OR: + case OR_ASSIGNMENT: return OR; case XOR: + case XOR_ASSIGNMENT: return XOR; - case PLUS_ASSIGNMENT: - return PLUS; - case MINUS_ASSIGNMENT: - return MINUS; - case MULTIPLY_ASSIGNMENT: - return MULTIPLY; - case DIVIDE_ASSIGNMENT: - return DIVIDE; - case REMAINDER_ASSIGNMENT: - return REMAINDER; default: throw new BugInCF("There are no defined ArithmeticOperationKinds " + "for the given com.sun.source.tree.Tree.Kind: " + kind);