Skip to content

Commit

Permalink
Simplify if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Ao-senXiong committed Jun 1, 2024
1 parent 6f242e7 commit 861fb05
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/main/java/pico/inference/PICOInferenceVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -747,25 +747,23 @@ private void checkMutation(ExpressionTree node, ExpressionTree variable) {
private void checkAssignableField(ExpressionTree node, ExpressionTree variable, AnnotatedTypeMirror receiverType) {
Element fieldElement = TreeUtils.elementFromUse(variable);
assert fieldElement != null;
if (fieldElement != null) {//TODO Can this bu null?
AnnotatedTypeMirror fieldType = atypeFactory.getAnnotatedType(fieldElement);
assert fieldType != null;
if (infer) {
// Break the combination of readonly receiver + rdm assignable field
ConstraintManager constraintManager = InferenceMain.getInstance().getConstraintManager();
SlotManager slotManager = InferenceMain.getInstance().getSlotManager();
Slot receiverSlot = slotManager.getSlot(receiverType);
Slot fieldSlot = slotManager.getSlot(fieldType);
Slot readonly = slotManager.getSlot(READONLY);
Slot receiver_dependant_mutable = slotManager.getSlot(RECEIVER_DEPENDANT_MUTABLE);
Constraint receiverReadOnly = constraintManager.createEqualityConstraint(receiverSlot, readonly);
Constraint fieldNotRDM = constraintManager.createInequalityConstraint(fieldSlot, receiver_dependant_mutable);
// receiver = READONLY
constraintManager.addImplicationConstraint(Collections.singletonList(receiverReadOnly), fieldNotRDM);
} else {
if (receiverType.hasAnnotation(READONLY) && fieldType.hasAnnotation(RECEIVER_DEPENDANT_MUTABLE)) {
reportFieldOrArrayWriteError(node, variable, receiverType);
}
AnnotatedTypeMirror fieldType = atypeFactory.getAnnotatedType(fieldElement);
assert fieldType != null;
if (infer) {
// Break the combination of readonly receiver + rdm assignable field
ConstraintManager constraintManager = InferenceMain.getInstance().getConstraintManager();
SlotManager slotManager = InferenceMain.getInstance().getSlotManager();
Slot receiverSlot = slotManager.getSlot(receiverType);
Slot fieldSlot = slotManager.getSlot(fieldType);
Slot readonly = slotManager.getSlot(READONLY);
Slot receiver_dependant_mutable = slotManager.getSlot(RECEIVER_DEPENDANT_MUTABLE);
Constraint receiverReadOnly = constraintManager.createEqualityConstraint(receiverSlot, readonly);
Constraint fieldNotRDM = constraintManager.createInequalityConstraint(fieldSlot, receiver_dependant_mutable);
// receiver = READONLY
constraintManager.addImplicationConstraint(Collections.singletonList(receiverReadOnly), fieldNotRDM);
} else {
if (receiverType.hasAnnotation(READONLY) && fieldType.hasAnnotation(RECEIVER_DEPENDANT_MUTABLE)) {
reportFieldOrArrayWriteError(node, variable, receiverType);
}
}
}
Expand Down

0 comments on commit 861fb05

Please sign in to comment.