Skip to content

Commit

Permalink
addDeepPreference to cfi
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewShf committed Dec 1, 2022
1 parent 1771984 commit c632f3d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/checkers/inference/InferenceVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
Expand Down Expand Up @@ -261,6 +262,48 @@ public void mainIsNoneOf(AnnotatedTypeMirror ty, AnnotationMirror[] mods, String
}
}

private void addDeepPreferenceImpl(AnnotatedTypeMirror ty, AnnotationMirror goal, int weight,
java.util.List<AnnotatedTypeMirror> visited, Tree node) {
if (infer) {
if (visited.contains(ty)) {
return;
}
visited.add(ty);

final SlotManager slotManager = InferenceMain.getInstance().getSlotManager();
Slot el = slotManager.getSlot(ty);

if (el == null) {
logger.warning("InferenceVisitor::addDeepPreferenceImpl: no annotation in type: " + ty);
} else {
addPreference(ty, goal, weight);
}

if (ty.getKind() == TypeKind.DECLARED) {
AnnotatedDeclaredType declaredType = (AnnotatedDeclaredType) ty;
for (AnnotatedTypeMirror typearg : declaredType.getTypeArguments()) {
addDeepPreferenceImpl(typearg, goal, weight, visited, node);
}
} else if (ty.getKind() == TypeKind.ARRAY) {
AnnotatedArrayType arrayType = (AnnotatedArrayType) ty;
addDeepPreferenceImpl(arrayType.getComponentType(), goal, weight, visited, node);
} else if (ty.getKind() == TypeKind.TYPEVAR) {
AnnotatedTypeVariable atv = (AnnotatedTypeVariable) ty;
if (atv.getUpperBound()!=null) {
addDeepPreferenceImpl(atv.getUpperBound(), goal, weight, visited, node);
}
if (atv.getLowerBound()!=null) {
addDeepPreferenceImpl(atv.getLowerBound(), goal, weight, visited, node);
}
}
}
// Else, do nothing
}

public void addDeepPreference(AnnotatedTypeMirror ty, AnnotationMirror goal, int weight, Tree node) {
addDeepPreferenceImpl(ty, goal, weight, new LinkedList<>(), node);
}

public void addPreference(AnnotatedTypeMirror type, AnnotationMirror anno, int weight) {
if (infer) {
ConstraintManager cManager = InferenceMain.getInstance().getConstraintManager();
Expand Down

0 comments on commit c632f3d

Please sign in to comment.