use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class NullnessTransfer method makeNonNull.
/**
* Sets a given {@link Node} to non-null in the given {@code store}. Calls to this method
* implement case 2.
*/
protected void makeNonNull(NullnessStore store, Node node) {
Receiver internalRepr = FlowExpressions.internalReprOf(analysis.getTypeFactory(), node);
store.insertValue(internalRepr, NONNULL);
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class RegexTransfer method handleRegexUtil.
private TransferResult<CFValue, CFStore> handleRegexUtil(MethodInvocationNode n, ExecutableElement method, TransferResult<CFValue, CFStore> result) {
RegexAnnotatedTypeFactory factory = (RegexAnnotatedTypeFactory) analysis.getTypeFactory();
if (ElementUtils.matchesElement(method, IS_REGEX_METHOD_NAME, String.class, int.class)) {
// RegexUtil.isRegex(s, groups) method
// (No special case is needed for isRegex(String) because of
// the annotation on that method's definition.)
CFStore thenStore = result.getRegularStore();
CFStore elseStore = thenStore.copy();
ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
Receiver firstParam = FlowExpressions.internalReprOf(factory.getContext().getAnnotationProvider(), n.getArgument(0));
// add annotation with correct group count (if possible,
// regex annotation without count otherwise)
Node count = n.getArgument(1);
int groupCount;
if (count instanceof IntegerLiteralNode) {
IntegerLiteralNode iln = (IntegerLiteralNode) count;
groupCount = iln.getValue();
} else {
groupCount = 0;
}
AnnotationMirror regexAnnotation = factory.createRegexAnnotation(groupCount);
thenStore.insertValue(firstParam, regexAnnotation);
return newResult;
} else if (ElementUtils.matchesElement(method, AS_REGEX_METHOD_NAME, String.class, int.class)) {
// RegexUtil.asRegex(s, groups) method
// (No special case is needed for asRegex(String) because of
// the annotation on that method's definition.)
// add annotation with correct group count (if possible,
// regex annotation without count otherwise)
AnnotationMirror regexAnnotation;
Node count = n.getArgument(1);
int groupCount;
if (count instanceof IntegerLiteralNode) {
IntegerLiteralNode iln = (IntegerLiteralNode) count;
groupCount = iln.getValue();
} else {
groupCount = 0;
}
regexAnnotation = factory.createRegexAnnotation(groupCount);
CFValue newResultValue = analysis.createSingleAnnotationValue(regexAnnotation, result.getResultValue().getUnderlyingType());
return new RegularTransferResult<>(newResultValue, result.getRegularStore());
}
return result;
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class I18nFormatterTransfer method visitMethodInvocation.
@Override
public TransferResult<CFValue, CFStore> visitMethodInvocation(MethodInvocationNode node, TransferInput<CFValue, CFStore> in) {
I18nFormatterAnnotatedTypeFactory atypeFactory = (I18nFormatterAnnotatedTypeFactory) analysis.getTypeFactory();
TransferResult<CFValue, CFStore> result = super.visitMethodInvocation(node, in);
I18nFormatterTreeUtil tu = atypeFactory.treeUtil;
// If hasFormat is called, make sure that the format string is annotated correctly
if (tu.isHasFormatCall(node, atypeFactory)) {
CFStore thenStore = result.getRegularStore();
CFStore elseStore = thenStore.copy();
ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
Result<I18nConversionCategory[]> cats = tu.getHasFormatCallCategories(node);
if (cats.value() == null) {
tu.failure(cats, "i18nformat.indirect.arguments");
} else {
Receiver firstParam = FlowExpressions.internalReprOf(atypeFactory, node.getArgument(0));
AnnotationMirror anno = atypeFactory.treeUtil.categoriesToFormatAnnotation(cats.value());
thenStore.insertValue(firstParam, anno);
}
return newResult;
}
// If isFormat is called, annotate the format string with I18nInvalidFormat
if (tu.isIsFormatCall(node, atypeFactory)) {
CFStore thenStore = result.getRegularStore();
CFStore elseStore = thenStore.copy();
ConditionalTransferResult<CFValue, CFStore> newResult = new ConditionalTransferResult<>(result.getResultValue(), thenStore, elseStore);
Receiver firstParam = FlowExpressions.internalReprOf(atypeFactory, node.getArgument(0));
AnnotationBuilder builder = new AnnotationBuilder(tu.processingEnv, I18nInvalidFormat.class.getCanonicalName());
// No need to set a value of @I18nInvalidFormat
builder.setValue("value", "");
elseStore.insertValue(firstParam, builder.build());
return newResult;
}
// corresponding key's value
if (tu.isMakeFormatCall(node, atypeFactory)) {
Result<I18nConversionCategory[]> cats = tu.makeFormatCallCategories(node, atypeFactory);
if (cats.value() == null) {
tu.failure(cats, "i18nformat.key.not.found");
} else {
AnnotationMirror anno = atypeFactory.treeUtil.categoriesToFormatAnnotation(cats.value());
CFValue newResultValue = analysis.createSingleAnnotationValue(anno, result.getResultValue().getUnderlyingType());
return new RegularTransferResult<>(newResultValue, result.getRegularStore());
}
}
return result;
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class LessThanTransfer method refineGT.
/**
* Case 1.
*/
@Override
protected void refineGT(Node left, AnnotationMirror leftAnno, Node right, AnnotationMirror rightAnno, CFStore store, TransferInput<CFValue, CFStore> in) {
LessThanAnnotatedTypeFactory factory = (LessThanAnnotatedTypeFactory) analysis.getTypeFactory();
// left > right so right < left
// Refine right to @LessThan("left")
Receiver leftRec = FlowExpressions.internalReprOf(factory, left);
if (leftRec != null && leftRec.isUnmodifiableByOtherCode()) {
List<String> lessThanExpressions = LessThanAnnotatedTypeFactory.getLessThanExpressions(rightAnno);
if (lessThanExpressions == null) {
// right is already bottom, nothing to refine.
return;
}
lessThanExpressions.add(leftRec.toString());
Receiver rightRec = FlowExpressions.internalReprOf(analysis.getTypeFactory(), right);
store.insertValue(rightRec, factory.createLessThanQualifier(lessThanExpressions));
}
}
use of org.checkerframework.dataflow.analysis.FlowExpressions.Receiver in project checker-framework by typetools.
the class LowerBoundTransfer method refineGTE.
/**
* Refines left to exactly the level of right, since in the worst case they're equal. Modifies
* an existing type in the store, but has to be careful not to overwrite a more precise existing
* type.
*
* <p>This implements parts of cases 1, 2, 3, and 4 using the decomposition strategy described
* in this class's Javadoc.
*/
@Override
protected void refineGTE(Node left, AnnotationMirror leftAnno, Node right, AnnotationMirror rightAnno, CFStore store, TransferInput<CFValue, CFStore> in) {
if (rightAnno == null || leftAnno == null) {
return;
}
Receiver leftRec = FlowExpressions.internalReprOf(aTypeFactory, left);
AnnotationMirror newLBType = aTypeFactory.getQualifierHierarchy().greatestLowerBound(rightAnno, leftAnno);
store.insertValue(leftRec, newLBType);
}
Aggregations