org.checkerframework.checker.index.IndexAbstractTransfer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checker Show documentation
Show all versions of checker Show documentation
The Checker Framework enhances Java's type system to
make it more powerful and useful. This lets software developers
detect and prevent errors in their Java programs.
The Checker Framework includes compiler plug-ins ("checkers")
that find bugs or verify their absence. It also permits you to
write your own compiler plug-ins.
package org.checkerframework.checker.index;
import javax.lang.model.element.AnnotationMirror;
import org.checkerframework.dataflow.analysis.TransferInput;
import org.checkerframework.dataflow.analysis.TransferResult;
import org.checkerframework.dataflow.cfg.node.GreaterThanNode;
import org.checkerframework.dataflow.cfg.node.GreaterThanOrEqualNode;
import org.checkerframework.dataflow.cfg.node.LessThanNode;
import org.checkerframework.dataflow.cfg.node.LessThanOrEqualNode;
import org.checkerframework.dataflow.cfg.node.Node;
import org.checkerframework.framework.flow.CFAnalysis;
import org.checkerframework.framework.flow.CFStore;
import org.checkerframework.framework.flow.CFTransfer;
import org.checkerframework.framework.flow.CFValue;
/**
* This class provides methods shared by the Index Checker's internal checkers in their transfer
* functions. In particular, it provides a common framework for visiting comparison operators.
*/
@SuppressWarnings("ArgumentSelectionDefectChecker") // TODO: apply suggested error-prone fixes
public abstract class IndexAbstractTransfer extends CFTransfer {
protected IndexAbstractTransfer(CFAnalysis analysis) {
super(analysis);
}
@Override
public TransferResult visitGreaterThan(
GreaterThanNode node, TransferInput in) {
TransferResult result = super.visitGreaterThan(node, in);
IndexRefinementInfo rfi = new IndexRefinementInfo(result, analysis, node);
if (rfi.leftAnno == null || rfi.rightAnno == null) {
return result;
}
// Refine the then branch.
refineGT(rfi.left, rfi.leftAnno, rfi.right, rfi.rightAnno, rfi.thenStore, in);
// Refine the else branch, which is the inverse of the then branch.
refineGTE(rfi.right, rfi.rightAnno, rfi.left, rfi.leftAnno, rfi.elseStore, in);
return rfi.newResult;
}
@Override
public TransferResult visitGreaterThanOrEqual(
GreaterThanOrEqualNode node, TransferInput in) {
TransferResult result = super.visitGreaterThanOrEqual(node, in);
IndexRefinementInfo rfi = new IndexRefinementInfo(result, analysis, node);
if (rfi.leftAnno == null || rfi.rightAnno == null) {
return result;
}
// Refine the then branch.
refineGTE(rfi.left, rfi.leftAnno, rfi.right, rfi.rightAnno, rfi.thenStore, in);
// Refine the else branch.
refineGT(rfi.right, rfi.rightAnno, rfi.left, rfi.leftAnno, rfi.elseStore, in);
return rfi.newResult;
}
@Override
public TransferResult visitLessThanOrEqual(
LessThanOrEqualNode node, TransferInput in) {
TransferResult result = super.visitLessThanOrEqual(node, in);
IndexRefinementInfo rfi = new IndexRefinementInfo(result, analysis, node);
if (rfi.leftAnno == null || rfi.rightAnno == null) {
return result;
}
// Refine the then branch. A <= is just a flipped >=.
refineGTE(rfi.right, rfi.rightAnno, rfi.left, rfi.leftAnno, rfi.thenStore, in);
// Refine the else branch.
refineGT(rfi.left, rfi.leftAnno, rfi.right, rfi.rightAnno, rfi.elseStore, in);
return rfi.newResult;
}
@Override
public TransferResult visitLessThan(
LessThanNode node, TransferInput in) {
TransferResult result = super.visitLessThan(node, in);
IndexRefinementInfo rfi = new IndexRefinementInfo(result, analysis, node);
if (rfi.leftAnno == null || rfi.rightAnno == null) {
return result;
}
// Refine the then branch. A < is just a flipped >.
refineGT(rfi.right, rfi.rightAnno, rfi.left, rfi.leftAnno, rfi.thenStore, in);
// Refine the else branch.
refineGTE(rfi.left, rfi.leftAnno, rfi.right, rfi.rightAnno, rfi.elseStore, in);
return rfi.newResult;
}
protected abstract void refineGT(
Node left,
AnnotationMirror leftAnno,
Node right,
AnnotationMirror rightAnno,
CFStore store,
TransferInput in);
protected abstract void refineGTE(
Node left,
AnnotationMirror leftAnno,
Node right,
AnnotationMirror rightAnno,
CFStore store,
TransferInput in);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy