Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typecheck Fix #35

Open
wants to merge 154 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
8772985
adapt pico to CF and CFI master
baoruiz Mar 20, 2019
c8e412f
fix pico per changes in upstream CF and CFI
baoruiz Mar 28, 2019
9e27922
remove incorrect aliasing and unnecessary method check
baoruiz Apr 2, 2019
0298a5f
remove wrong test diagnostic
baoruiz Apr 18, 2019
5ddc6ae
adapt to upstream changes
baoruiz Apr 18, 2019
c4e9ed4
fix extends and implements check
baoruiz Apr 24, 2019
8b8bd6b
tweak travis build script
baoruiz Apr 30, 2019
e3bc7a5
Remove useless separators.
xingweitian Jul 3, 2019
21d2fae
Unify the name of test files.
xingweitian Jul 10, 2019
8b69770
Fix typo.
xingweitian Jul 24, 2019
dd4717a
Fix typo.
xingweitian Jul 24, 2019
e468c1e
Fix typo.
xingweitian Jul 26, 2019
0391e9d
Complete the messages.
xingweitian Jul 27, 2019
0ee8410
Merge pull request #3 from xingweitian/adapt-to-cf-master
wmdietl Jul 27, 2019
fb54eb2
Use all dirs and jar file to fix the issue that "messages.properties"…
xingweitian Jul 28, 2019
6a29832
Merge remote-tracking branch 'origin/adapt-to-cf-master' into adapt-t…
xingweitian Jul 28, 2019
6c07c6c
Tweaks.
xingweitian Jul 28, 2019
cab2d60
Merge remote-tracking branch 'upstream/adapt-to-cf-master' into adapt…
xingweitian Jul 28, 2019
10613ac
Use the correct error key.
xingweitian Jul 30, 2019
147db8d
Merge pull request #4 from xingweitian/adapt-to-cf-master
xingweitian Aug 17, 2019
505dcf8
Merge pull request #6 from xingweitian/xwt-fix-test-cases
xingweitian Aug 17, 2019
ab8af46
Fix typo (CompatabilityBEI2.java -> CompatibilityBEI2.java) and make …
xingweitian Aug 18, 2019
a19d94f
Update.
xingweitian Sep 10, 2019
236d0f4
Update.
xingweitian Sep 7, 2019
b74dc2a
api updates
Nov 21, 2019
32c6852
typo
Nov 21, 2019
e630ebd
Merge remote-tracking branch 'xwt/adapt-to-cf-master' into ls-dev
Nov 21, 2019
e6892fa
default-for annotator, default bottom on null, allow readonly as uppe…
lnsun Dec 2, 2019
de0969f
Implement super constructor call check.
xingweitian Jul 30, 2019
d823dcf
Improve code and javadoc.
xingweitian Aug 19, 2019
0676e7d
clean debug messages and comment
lnsun Dec 5, 2019
09f6f01
fixed HashCodeSafetyExample, addMissingAnnotations->replaceAnnotation
lnsun Dec 5, 2019
0b34f3a
fixed CompatibilityBEI2 + ReceiverTypeOutsideConstructor: pull defaul…
lnsun Dec 5, 2019
cfc4054
milestone: all typecheck tests passed
lnsun Dec 9, 2019
85d0945
add anno invalid check in local variables; add RDM extends/implements…
lnsun Dec 19, 2019
afff4ed
override cf default extends/implements checks
lnsun Dec 19, 2019
f514775
fix anonymous type of new clause and test case
lnsun Jan 17, 2020
3210749
reuse test cases for typecheck and infer initial typecheck
lnsun Jan 17, 2020
2087d9a
fix a accidentally disabled test case
lnsun Jan 20, 2020
257f732
fix additional tests' errors
lnsun Feb 28, 2020
d5909e9
test vpa over imp
lnsun Apr 6, 2020
9b33196
TODO: resolve path issues, remove this when fixed
lnsun Apr 6, 2020
2bd7c5e
default class bound and super clause
lnsun Apr 7, 2020
08d136f
default class bound and super clause enhanced
lnsun Apr 8, 2020
52fa126
implicit immutable class bound + cast.unsafe
lnsun Apr 15, 2020
45f4c0f
remove wrong cast.unsafe keys
lnsun Apr 15, 2020
90074b2
bound of array fixed to READONLY. VPA not needed here because any typ…
lnsun Apr 16, 2020
857050e
bottom workaround + vpa interface
lnsun Apr 17, 2020
4dab7b1
enum default immutable. TODO: fix constructor check in mutable enum decl
lnsun Apr 18, 2020
a42c289
fix enum default in inference
lnsun Apr 21, 2020
761655d
doc
lnsun Apr 23, 2020
bdcbb4c
relocate common interface and annotator
lnsun Apr 23, 2020
5c42ad4
bound
lnsun Apr 24, 2020
4e72db6
enum & super clause
lnsun May 5, 2020
ba48fda
test case update
lnsun May 5, 2020
b853156
tweaks on generic
lnsun May 6, 2020
2e1c6b0
fix anno
lnsun May 7, 2020
3f66342
Merge branch 'tmp' into typecheck-amend
lnsun May 7, 2020
461c86a
poly workaround
lnsun May 8, 2020
c7b7d08
update test cases (typecheck 100%, inference-init-tc 100%)
lnsun May 8, 2020
14ad936
API update: report
lnsun May 8, 2020
42cc297
API update: remove @DefaultInUncheckedCodeFor
lnsun May 8, 2020
765fc99
remove @SPM
lnsun May 12, 2020
54dc0de
Revert "remove @SPM"
lnsun May 13, 2020
9c31c35
@SPM for static moved to new api
lnsun May 18, 2020
adf2c17
exclude decl when checking static RDM (TC: 100%, INF: 6 fail)
lnsun May 18, 2020
2e2ffd0
small tweaks
lnsun May 18, 2020
6277e02
tc cast.unsafe (TC: 100%, INF: 4 fail)
lnsun May 19, 2020
b90d5f9
inf-> workaround for anonymous class
lnsun May 19, 2020
13555c6
a small tweak
lnsun May 19, 2020
a4339f9
update test cases (TC all pass)
lnsun May 19, 2020
5da659f
re-remove @SPM
lnsun May 21, 2020
a954e32
add CF all-systems test
lnsun May 22, 2020
e53f3fb
small tweaks on test drivers
lnsun May 22, 2020
d3e571c
interface
lnsun Jun 10, 2020
9879f05
isSubtype use native api
lnsun Jul 2, 2020
ab48c6a
infer atf + get bound
lnsun Jul 2, 2020
9885f10
tweaks
lnsun Jul 2, 2020
df3f2dd
checker.report update
lnsun Jul 3, 2020
a6df8de
checker.report update
lnsun Jul 3, 2020
0209864
tc
lnsun Oct 9, 2020
12e4a8c
tc
lnsun Oct 15, 2020
f04a5bb
ignore rdm on fields
lnsun Oct 15, 2020
aa240ec
rdm field logic + tc
lnsun Nov 20, 2020
06da98a
VPA post check
lnsun Nov 24, 2020
0d63613
vpa post check
lnsun Nov 24, 2020
d47daa5
field rdm default
lnsun Nov 26, 2020
ab44c1e
check anno
lnsun Dec 2, 2020
ef44406
tc update
lnsun Dec 2, 2020
5a67d2e
transitive (needs fix)
lnsun Dec 16, 2020
fc6cf0b
class bound != PM
lnsun Jan 14, 2021
d8e1195
receiver != BOTTOM
lnsun Jan 14, 2021
f5972fd
stop assign immutable constant slot to enum usage. enum could be mutable
lnsun Jan 15, 2021
f1acb77
PICO does not need existential slot on class decl anno
lnsun Jan 15, 2021
a2f5726
use constant slot for explicit class decl anno
lnsun Jan 20, 2021
10d1e17
update init bound extraction function
lnsun Jan 20, 2021
6c31de8
update call to init bound extraction function
lnsun Jan 20, 2021
0254063
prevent poly infer
lnsun Jan 20, 2021
31ff749
bound handling for anonymous class
lnsun Jan 22, 2021
4f41dc4
anonymous class method receiver workaround
lnsun Jan 22, 2021
a152323
workarounds for anonymous class for getTypeOfExtendsImplements
lnsun Jan 23, 2021
1c17437
extract method
lnsun Jan 25, 2021
cf64586
do not apply real anno to atm during infer
lnsun Jan 25, 2021
df55010
not apply immutable constant to enum during infer-typecheck
lnsun Jan 26, 2021
e4cbe5f
add init bound extraction function
lnsun Jan 27, 2021
50e3cea
update tc
lnsun Feb 23, 2021
5a9e8ca
array bound -> RDM (TC)
lnsun Feb 24, 2021
11834c1
exclude static inner class decl from static scope
lnsun Feb 27, 2021
75e7d94
don't check with default during inference
lnsun Feb 27, 2021
536326e
add immutable alias for real type factory
lnsun Feb 27, 2021
00c72b0
array decl method
lnsun Feb 28, 2021
1302fbd
implicit shallow immutable warning (TC)
lnsun Feb 28, 2021
e135891
tune up vpa
lnsun Mar 9, 2021
0dcb75a
better logic to check anonymous
lnsun Mar 9, 2021
8951f83
enum heck
lnsun Mar 9, 2021
a33647d
enforce check without refinement
lnsun Mar 23, 2021
2df57a3
workaround for implicit lib type param
lnsun Mar 23, 2021
ab295d5
disable alias
lnsun Mar 23, 2021
2758917
workaround: vpa decl w/o anno
lnsun Mar 23, 2021
b4fb4b3
consistency infer and tc
lnsun Mar 23, 2021
beae801
ext and imp clause logic
lnsun Mar 23, 2021
c0167a1
override base ext/imp clause check
lnsun Mar 23, 2021
d73db45
override base check on ext/imp clauses
lnsun Mar 23, 2021
ba2f6a0
anonymous class logic
lnsun Mar 23, 2021
b39968e
receiver cannot infer to poly
lnsun Mar 25, 2021
631d7fe
allow explicit poly on receiver
lnsun Mar 25, 2021
a634bfb
class bound for infer
lnsun Mar 25, 2021
afd4505
allow factory to get class decl slot
lnsun Mar 25, 2021
e834b11
annotator: handle decl bound
lnsun Mar 25, 2021
f1d8652
annotator: skip null
lnsun Mar 25, 2021
c5f3b1d
annotator: replace real anno
lnsun Mar 25, 2021
0462aff
annotator: not infer to poly
lnsun Mar 25, 2021
4158e72
annotator: drop super decl constraints
lnsun Mar 25, 2021
e0e742f
visitor: skip uses w/o slot
lnsun Mar 25, 2021
b5e214d
rdm-field: field uses be both rdm or mutable
lnsun Mar 25, 2021
c201bd5
comments
lnsun Mar 25, 2021
c060dc1
notes
lnsun Mar 25, 2021
c1c8703
tweaks
lnsun Mar 25, 2021
de054ce
stubs
lnsun Mar 25, 2021
78aef48
reim test cases
lnsun Mar 25, 2021
bb9678c
glacier test cases
lnsun Mar 25, 2021
64122f6
temp ignore all systems test
lnsun Mar 25, 2021
c96f3fa
stub path problem
lnsun Mar 25, 2021
34e9a74
+useOptimisticUncheckedDefaults
lnsun Apr 9, 2021
2cd3276
import issue
lnsun Apr 20, 2021
472e75c
import issue
lnsun Apr 20, 2021
6e4e3c6
update pico, fix CF api rename, update gradle version
Feb 9, 2022
e4ced88
commits for fixing PICO-TypeCheck and part of PICO-Infer
AndrewShf Jul 13, 2022
4d3e9b1
merge opprop master with all_commits
AndrewShf Jul 13, 2022
3b09267
merge with opprop master
AndrewShf Jul 14, 2022
c6dcc1b
resolve new array problems
AndrewShf Jul 17, 2022
8044c38
Merge remote-tracking branch 'opprop/master' into all_commits
AndrewShf Sep 8, 2022
fa7f0eb
override isSafeDowncast in PICO
AndrewShf Sep 21, 2022
d73d3c3
fix java.util.MissingFormatArgumentException in commonAssignmentCheck
AndrewShf Sep 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
commits for fixing PICO-TypeCheck and part of PICO-Infer
  • Loading branch information
AndrewShf committed Jul 13, 2022
commit e4ced889969a8efdb200f3111da9a7aa7b02638e
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -50,6 +50,8 @@ sourceSets {
main {
java {
srcDirs = ["src/main/java"]
exclude "pico/inference/**"

}

resources {
@@ -62,6 +64,8 @@ sourceSets {
java {
// TODO: we shouldn't need source level dependency on CFITest
srcDirs = ["src/test/java", "${cfiPath}/tests/checkers/inference/test"]
exclude "pico/ImmutabilityInferenceInitialTypecheckTest.java","pico/ImmutabilityReImInferenceTest.java",
"pico/ImmutabilityInferenceTest.java"
}
}
}
9 changes: 2 additions & 7 deletions src/main/java/pico/inference/PICOInferenceChecker.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package pico.inference;

import checkers.inference.BaseInferrableChecker;
import checkers.inference.InferenceAnnotatedTypeFactory;
import checkers.inference.InferenceChecker;
import checkers.inference.InferenceVisitor;
import checkers.inference.InferrableChecker;
import checkers.inference.SlotManager;
import checkers.inference.*;
import checkers.inference.model.ConstraintManager;
import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory;
import org.checkerframework.framework.source.SupportedOptions;
@@ -24,7 +19,7 @@ public void initChecker() {
}

@Override
public BaseAnnotatedTypeFactory createRealTypeFactory() {
public BaseInferenceRealTypeFactory createRealTypeFactory(boolean infer) {
return new PICOInferenceRealTypeFactory(this, true);
}

Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;

import checkers.inference.BaseInferenceRealTypeFactory;
import com.sun.tools.javac.tree.JCTree;
import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory;
import org.checkerframework.common.basetype.BaseTypeChecker;
@@ -58,7 +59,7 @@
* to InitializationAnnotatedTypeFactory as if there is only one mutability qualifier hierarchy.
* This class has lots of copied code from PICOAnnotatedTypeFactory. The two should be in sync.
*/
public class PICOInferenceRealTypeFactory extends BaseAnnotatedTypeFactory implements ViewpointAdapterGettable {
public class PICOInferenceRealTypeFactory extends BaseInferenceRealTypeFactory implements ViewpointAdapterGettable {

private static final List<String> IMMUTABLE_ALIASES = Arrays.asList(
"com.google.errorprone.annotations.Immutable",
@@ -226,7 +227,7 @@ public AnnotatedTypeMirror getTypeOfExtendsImplements(Tree clause) {

}
AnnotationMirror mainBound = enclosing.getAnnotationInHierarchy(READONLY);
AnnotatedTypeMirror fromTypeTree = this.fromTypeTree(clause);
AnnotatedTypeMirror fromTypeTree = this.getAnnotatedTypeFromTypeTree(clause);
if (!fromTypeTree.isAnnotatedInHierarchy(READONLY)) {
fromTypeTree.addAnnotation(mainBound);
}
28 changes: 22 additions & 6 deletions src/main/java/pico/inference/PICOInferenceVisitor.java
Original file line number Diff line number Diff line change
@@ -148,6 +148,7 @@ private boolean isAdaptedSubtype(AnnotatedTypeMirror lhs, AnnotatedTypeMirror rh
if (extractVarAnnot(lhs).equals(extractVarAnnot(rhs))) {
return true;
}
// todo: haifeng we should do the viewpointAdapt in baseTypeValidator.java#visitDeclared 299 function:getTypeDeclarationBounds
ExtendedViewpointAdapter vpa = ((ViewpointAdapterGettable)atypeFactory).getViewpointAdapter();
AnnotatedTypeMirror adapted = vpa.rawCombineAnnotationWithType(extractVarAnnot(lhs),
rhs);
@@ -494,7 +495,22 @@ public Void visitMethod(MethodTree node, Void p) {
// TODO Object identity check
return super.visitMethod(node, p);
}

/*
* @RDM
* class A <T> {
*
* void foo(T) {
*
* }
* }
* class B extends @Immutable A<@X String> {
*
* @Override
* void foo(@Y String) { // string is compatible to bound of T. Adapt the signature of Class A to the use of class B.
* }
* }
*
* */
private void flexibleOverrideChecker(MethodTree node) {
// Method overriding checks
// TODO Copied from super, hence has lots of duplicate code with super. We need to
@@ -520,7 +536,7 @@ private void flexibleOverrideChecker(MethodTree node) {
types, atypeFactory, enclosingType, pair.getValue());
// Viewpoint adapt super method executable type to current class bound(is this always class bound?)
// to allow flexible overriding
atypeFactory.getViewpointAdapter().viewpointAdaptMethod(enclosingType, pair.getValue() , overriddenMethod);
atypeFactory.getViewpointAdapter().viewpointAdaptMethod(enclosingType, pair.getValue() , overriddenMethod); // todo: should we cast it?
AnnotatedExecutableType overrider = atypeFactory.getAnnotatedType(node);
if (!checkOverride(node, overrider, enclosingType, overriddenMethod, overriddenType)) {
// Stop at the first mismatch; this makes a difference only if
@@ -707,7 +723,7 @@ private void checkAssignableField(ExpressionTree node, ExpressionTree variable,
}
}

private void checkInitializingObject(ExpressionTree node, ExpressionTree variable, AnnotatedTypeMirror receiverType) {
private void checkInitializingObject(ExpressionTree node, ExpressionTree variable, AnnotatedTypeMirror receiverType) { // todo: haifeng we only need to do this in one statement
// TODO rm infer after mainIsNot returns bool
if (infer) {
// Can be anything from mutable, immutable or receiverdependantmutable
@@ -718,7 +734,7 @@ private void checkInitializingObject(ExpressionTree node, ExpressionTree variabl
}
}
}

// todo: haifeng: the deciding factor seems to be if it is array or not. Not infer.
private void checkMutableReceiverCase(ExpressionTree node, ExpressionTree variable, AnnotatedTypeMirror receiverType) {
// TODO rm infer after mainIs returns bool
if (infer) {
@@ -1004,7 +1020,7 @@ private boolean checkCompatabilityBetweenBoundAndSuperClassesBounds(ClassTree no
*/
@Override
protected void commonAssignmentCheck(
Tree varTree, ExpressionTree valueExp, String errorKey) {
Tree varTree, ExpressionTree valueExp, String errorKey, Object... extraArgs) {
AnnotatedTypeMirror var = atypeFactory.getAnnotatedTypeLhs(varTree);
assert var != null : "no variable found for tree: " + varTree;

@@ -1043,7 +1059,7 @@ protected void commonAssignmentCheck(
@Override
protected void commonAssignmentCheck(AnnotatedTypeMirror varType,
AnnotatedTypeMirror valueType, Tree valueTree,
String errorKey) {
String errorKey, Object... extraArgs) {
// TODO: WORKAROUND: anonymous class handling
if (TypesUtils.isAnonymous(valueType.getUnderlyingType())) {
AnnotatedTypeMirror newValueType = varType.deepCopy();
177 changes: 87 additions & 90 deletions src/main/java/pico/inference/PICOVariableAnnotator.java
Original file line number Diff line number Diff line change
@@ -45,80 +45,80 @@ public PICOVariableAnnotator(InferenceAnnotatedTypeFactory typeFactory, Annotate
super(typeFactory, realTypeFactory, realChecker, slotManager, constraintManager);
}

@Override
protected void handleClassDeclaration(AnnotatedDeclaredType classType, ClassTree classTree) {
super.handleClassDeclaration(classType, classTree);
int interfaceIndex = 1;
for(Tree implementsTree : classTree.getImplementsClause()) {
final AnnotatedTypeMirror implementsType = inferenceTypeFactory.getAnnotatedTypeFromTypeTree(implementsTree);
AnnotatedTypeMirror supertype = classType.directSuperTypes().get(interfaceIndex);
assert supertype.getUnderlyingType() == implementsType.getUnderlyingType();
visit(supertype, implementsTree);
interfaceIndex++;
}
}

@Override
protected void handleClassDeclarationBound(AnnotatedDeclaredType classType) {
TypeElement classElement = (TypeElement) classType.getUnderlyingType().asElement();
if (classDeclAnnos.containsKey(classElement)) {
classType.addAnnotation(slotManager.getAnnotation(classDeclAnnos.get(classElement)));
classType.addAnnotation(READONLY);
return;
}
AnnotatedDeclaredType bound = inferenceTypeFactory.fromElement(classElement);

VariableSlot boundSlot;

// Insert @Immutable VarAnnot directly to enum bound
// if (PICOTypeUtil.isEnumOrEnumConstant(bound)) {
// boundSlot = slotManager.createConstantSlot(IMMUTABLE);
// classType.addAnnotation(slotManager.getAnnotation(boundSlot));
// classDeclAnnos.put(classElement, boundSlot);
// @Override
// protected void handleClassDeclaration(AnnotatedDeclaredType classType, ClassTree classTree) {
// super.handleClassDeclaration(classType, classTree);
// int interfaceIndex = 1;
// for(Tree implementsTree : classTree.getImplementsClause()) {
// final AnnotatedTypeMirror implementsType = inferenceTypeFactory.getAnnotatedTypeFromTypeTree(implementsTree);
// AnnotatedTypeMirror supertype = classType.directSupertypes().get(interfaceIndex);
// assert supertype.getUnderlyingType() == implementsType.getUnderlyingType();
// visit(supertype, implementsTree);
// interfaceIndex++;
// }
// }

// @Override
// protected void handleClassDeclarationBound(AnnotatedDeclaredType classType) {
// TypeElement classElement = (TypeElement) classType.getUnderlyingType().asElement();
// if (classDeclAnnos.containsKey(classElement)) {
// classType.addAnnotation(slotManager.getAnnotation(classDeclAnnos.get(classElement)));
// classType.addAnnotation(READONLY);
// return;
// }

Tree classTree = inferenceTypeFactory.declarationFromElement(classElement);
if (classTree != null) {
// Have source tree
if (bound.isAnnotatedInHierarchy(READONLY)) {
// Have bound annotation -> convert to equivalent ConstantSlot
boundSlot = slotManager.createConstantSlot(bound.getAnnotationInHierarchy(READONLY));
} else {
// No existing annotation -> create new VariableSlot
boundSlot = createVariable(treeToLocation(classTree));
}
} else {
// No source tree: bytecode classes
if (bound.isAnnotatedInHierarchy(READONLY)) {
// Have bound annotation in stub file
boundSlot = slotManager.createConstantSlot(bound.getAnnotationInHierarchy(READONLY));
} else {
// No stub file
if (PICOTypeUtil.isImplicitlyImmutableType(classType)) {
// Implicitly immutable
boundSlot = slotManager.createConstantSlot(IMMUTABLE);
} else {
// None of the above applies: use conservative @Mutable
boundSlot = slotManager.createConstantSlot(MUTABLE);
}
}
}
classType.addAnnotation(slotManager.getAnnotation(boundSlot));
classDeclAnnos.put(classElement, boundSlot);
}
// AnnotatedDeclaredType bound = inferenceTypeFactory.fromElement(classElement);
//
// VariableSlot boundSlot;
//
// // Insert @Immutable VarAnnot directly to enum bound
//// if (PICOTypeUtil.isEnumOrEnumConstant(bound)) {
//// boundSlot = slotManager.createConstantSlot(IMMUTABLE);
//// classType.addAnnotation(slotManager.getAnnotation(boundSlot));
//// classDeclAnnos.put(classElement, boundSlot);
//// return;
//// }
//
// Tree classTree = inferenceTypeFactory.declarationFromElement(classElement);
// if (classTree != null) {
// // Have source tree
// if (bound.isAnnotatedInHierarchy(READONLY)) {
// // Have bound annotation -> convert to equivalent ConstantSlot
// boundSlot = slotManager.createConstantSlot(bound.getAnnotationInHierarchy(READONLY));
// } else {
// // No existing annotation -> create new VariableSlot
// boundSlot = createVariable(treeToLocation(classTree));
// }
// } else {
// // No source tree: bytecode classes
// if (bound.isAnnotatedInHierarchy(READONLY)) {
// // Have bound annotation in stub file
// boundSlot = slotManager.createConstantSlot(bound.getAnnotationInHierarchy(READONLY));
// } else {
// // No stub file
// if (PICOTypeUtil.isImplicitlyImmutableType(classType)) {
// // Implicitly immutable
// boundSlot = slotManager.createConstantSlot(IMMUTABLE);
// } else {
// // None of the above applies: use conservative @Mutable
// boundSlot = slotManager.createConstantSlot(MUTABLE);
// }
// }
// }
// classType.addAnnotation(slotManager.getAnnotation(boundSlot));
// classDeclAnnos.put(classElement, boundSlot);
// }

@Override
protected VariableSlot getOrCreateDeclBound(AnnotatedDeclaredType type) {
TypeElement classDecl = (TypeElement) type.getUnderlyingType().asElement();

VariableSlot declSlot = classDeclAnnos.get(classDecl);
AnnotationMirror declSlot = getClassDeclVarAnnot(classDecl);
if (declSlot == null) {
// if a explicit annotation presents on the class DECL, use that directly
if (type.isDeclaration() && type.isAnnotatedInHierarchy(READONLY) && !type.hasAnnotation(READONLY)) {
VariableSlot constantSlot = (VariableSlot) slotManager.getSlot(type.getAnnotationInHierarchy(READONLY));
// TypeElement classDecl = (TypeElement) type.getUnderlyingType().asElement();
classDeclAnnos.put(classDecl, constantSlot);
super.getOrCreateDeclBound(type);
// // avoid duplicate annos
// type.removeAnnotationInHierarchy(READONLY);
return constantSlot;
@@ -134,21 +134,21 @@ protected VariableSlot getOrCreateDeclBound(AnnotatedDeclaredType type) {
return (VariableSlot) slotManager.getSlot(type.getAnnotation(VarAnnot.class));
}
}
return super.getOrCreateDeclBound(type);
return (VariableSlot) super.getOrCreateDeclBound(type);
}

@Override
protected void handleExplicitExtends(Tree extendsTree) {
// PICO cannot use base extends handling: not simply subtype relationship because of RDM
// Constraints already generated in processClassTree
}
// @Override
// protected void handleExplicitExtends(Tree extendsTree) {
// // PICO cannot use base extends handling: not simply subtype relationship because of RDM
// // Constraints already generated in processClassTree
// }

@Override
public void storeElementType(Element element, AnnotatedTypeMirror atm) {
// this method is override the behavior of super.handleClassDeclaration before storing
// find a better way

Slot slot = slotManager.getVariableSlot(atm);
Slot slot = slotManager.getSlot(atm);
// do not use potential slot generated on the class decl annotation
// PICO always have a annotation on the class bound, so Existential should always exist
// TODO make VariableAnnotator::getOrCreateDeclBound protected and override that instead of this method
@@ -167,22 +167,22 @@ public void storeElementType(Element element, AnnotatedTypeMirror atm) {
}

// Don't generate subtype constraint between use type and bound type
@Override
protected void handleInstantiationConstraint(AnnotatedTypeMirror.AnnotatedDeclaredType adt, VariableSlot instantiationSlot, Tree tree) {
return;
}

@Override
protected VariableSlot addPrimaryVariable(AnnotatedTypeMirror atm, Tree tree) {
// if (PICOTypeUtil.isEnumOrEnumConstant(atm)) {
// // Don't add new VarAnnot to type use of enum type
// PICOTypeUtil.applyConstant(atm, IMMUTABLE);
// @Override
// protected void handleInstantiationConstraint(AnnotatedTypeMirror.AnnotatedDeclaredType adt, VariableSlot instantiationSlot, Tree tree) {
// return;
// }

// @Override
// protected VariableSlot addPrimaryVariable(AnnotatedTypeMirror atm, Tree tree) {
//// if (PICOTypeUtil.isEnumOrEnumConstant(atm)) {
//// // Don't add new VarAnnot to type use of enum type
//// PICOTypeUtil.applyConstant(atm, IMMUTABLE);
//// }
// if (atm instanceof AnnotatedTypeMirror.AnnotatedNullType) {
// PICOTypeUtil.applyConstant(atm, BOTTOM);
// }
if (atm instanceof AnnotatedTypeMirror.AnnotatedNullType) {
PICOTypeUtil.applyConstant(atm, BOTTOM);
}
return super.addPrimaryVariable(atm, tree);
}
// return super.addPrimaryVariable(atm, tree);
// }

// Generates inequality constraint between every strict VariableSlot and @Bottom so that @Bottom is not inserted
// back to source code, but can be within the internal state because of dataflow refinement
@@ -285,7 +285,7 @@ public Void visitWildcard(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType

@Override
public void handleBinaryTree(AnnotatedTypeMirror atm, BinaryTree binaryTree) {
if (atm.isAnnotatedInHierarchy(varAnnot)) {
if (atm.isAnnotatedInHierarchy(inferenceTypeFactory.getVarAnnot())) {
// Happens for binary trees whose atm is implicitly immutable and already handled by
// PICOInferencePropagationTreeAnnotator
return;
@@ -294,15 +294,12 @@ public void handleBinaryTree(AnnotatedTypeMirror atm, BinaryTree binaryTree) {
}

public AnnotationMirror getClassDeclAnno(Element ele) {
if (classDeclAnnos.get(ele) != null) {
return slotManager.getAnnotation(classDeclAnnos.get(ele));
}
return null;
return getClassDeclVarAnnot((TypeElement) ele); // todo: solved
}


@Override
protected void addDeclarationConstraints(VariableSlot declSlot, VariableSlot instanceSlot) {
protected void addDeclarationConstraints(Slot declSlot, Slot instanceSlot) {
// RDM-related constraints cannot use subtype.
// Necessary constraints added in visitor instead.
}
Loading