use of org.checkerframework.dataflow.cfg.node.Node in project bazel by bazelbuild.
the class Analysis method callTransferFunction.
/**
* Call the transfer function for node {@code node}, and set that node as
* current node first.
*/
protected TransferResult<A, S> callTransferFunction(Node node, TransferInput<A, S> store) {
if (node.isLValue()) {
// store.hasTwoStores()), or is the following correct?
return new RegularTransferResult<A, S>(null, store.getRegularStore());
}
store.node = node;
currentNode = node;
TransferResult<A, S> transferResult = node.accept(transferFunction, store);
currentNode = null;
if (node instanceof ReturnNode) {
// save a copy of the store to later check if some property held at
// a given return statement
storesAtReturnStatements.put((ReturnNode) node, transferResult);
}
if (node instanceof AssignmentNode) {
// store the flow-refined value for effectively final local variables
AssignmentNode assignment = (AssignmentNode) node;
Node lhst = assignment.getTarget();
if (lhst instanceof LocalVariableNode) {
LocalVariableNode lhs = (LocalVariableNode) lhst;
Element elem = lhs.getElement();
if (ElementUtils.isEffectivelyFinal(elem)) {
finalLocalValues.put(elem, transferResult.getResultValue());
}
}
}
return transferResult;
}
use of org.checkerframework.dataflow.cfg.node.Node in project bazel by bazelbuild.
the class FlowExpressions method internalReprOf.
/**
* We ignore operations such as widening and
* narrowing when computing the internal representation.
*
* @return The internal representation (as {@link Receiver}) of any
* {@link Node}. Might contain {@link Unknown}.
*/
public static Receiver internalReprOf(AnnotationProvider provider, Node receiverNode, boolean allowNonDeterminitic) {
Receiver receiver = null;
if (receiverNode instanceof FieldAccessNode) {
FieldAccessNode fan = (FieldAccessNode) receiverNode;
if (fan.getFieldName().equals("this")) {
// For some reason, "className.this" is considered a field access.
// We right this wrong here.
receiver = new ThisReference(fan.getReceiver().getType());
} else {
receiver = internalReprOfFieldAccess(provider, fan);
}
} else if (receiverNode instanceof ExplicitThisLiteralNode) {
receiver = new ThisReference(receiverNode.getType());
} else if (receiverNode instanceof ThisLiteralNode) {
receiver = new ThisReference(receiverNode.getType());
} else if (receiverNode instanceof SuperNode) {
receiver = new ThisReference(receiverNode.getType());
} else if (receiverNode instanceof LocalVariableNode) {
LocalVariableNode lv = (LocalVariableNode) receiverNode;
receiver = new LocalVariable(lv);
} else if (receiverNode instanceof ArrayAccessNode) {
ArrayAccessNode a = (ArrayAccessNode) receiverNode;
receiver = internalReprOfArrayAccess(provider, a);
} else if (receiverNode instanceof StringConversionNode) {
// ignore string conversion
return internalReprOf(provider, ((StringConversionNode) receiverNode).getOperand());
} else if (receiverNode instanceof WideningConversionNode) {
// ignore widening
return internalReprOf(provider, ((WideningConversionNode) receiverNode).getOperand());
} else if (receiverNode instanceof NarrowingConversionNode) {
// ignore narrowing
return internalReprOf(provider, ((NarrowingConversionNode) receiverNode).getOperand());
} else if (receiverNode instanceof ClassNameNode) {
ClassNameNode cn = (ClassNameNode) receiverNode;
receiver = new ClassName(cn.getType());
} else if (receiverNode instanceof ValueLiteralNode) {
ValueLiteralNode vn = (ValueLiteralNode) receiverNode;
receiver = new ValueLiteral(vn.getType(), vn);
} else if (receiverNode instanceof MethodInvocationNode) {
MethodInvocationNode mn = (MethodInvocationNode) receiverNode;
ExecutableElement invokedMethod = TreeUtils.elementFromUse(mn.getTree());
// check if this represents a boxing operation of a constant, in which
// case we treat the method call as deterministic, because there is no way
// to behave differently in two executions where two constants are being used.
boolean considerDeterministic = false;
if (invokedMethod.toString().equals("valueOf(long)") && mn.getTarget().getReceiver().toString().equals("Long")) {
Node arg = mn.getArgument(0);
if (arg instanceof ValueLiteralNode) {
considerDeterministic = true;
}
}
if (PurityUtils.isDeterministic(provider, invokedMethod) || allowNonDeterminitic || considerDeterministic) {
List<Receiver> parameters = new ArrayList<>();
for (Node p : mn.getArguments()) {
parameters.add(internalReprOf(provider, p));
}
Receiver methodReceiver;
if (ElementUtils.isStatic(invokedMethod)) {
methodReceiver = new ClassName(mn.getTarget().getReceiver().getType());
} else {
methodReceiver = internalReprOf(provider, mn.getTarget().getReceiver());
}
receiver = new PureMethodCall(mn.getType(), invokedMethod, methodReceiver, parameters);
}
}
if (receiver == null) {
receiver = new Unknown(receiverNode.getType());
}
return receiver;
}
use of org.checkerframework.dataflow.cfg.node.Node in project bazel by bazelbuild.
the class FlowExpressions method internalReprOfFieldAccess.
/**
* @return The internal representation (as {@link FieldAccess}) of a
* {@link FieldAccessNode}. Can contain {@link Unknown} as receiver.
*/
public static FieldAccess internalReprOfFieldAccess(AnnotationProvider provider, FieldAccessNode node) {
Receiver receiver;
Node receiverNode = node.getReceiver();
if (node.isStatic()) {
receiver = new ClassName(receiverNode.getType());
} else {
receiver = internalReprOf(provider, receiverNode);
}
return new FieldAccess(receiver, node);
}
use of org.checkerframework.dataflow.cfg.node.Node in project bazel by bazelbuild.
the class ConstantPropagationStore method equals.
@Override
public boolean equals(Object o) {
if (o == null)
return false;
if (!(o instanceof ConstantPropagationStore))
return false;
ConstantPropagationStore other = (ConstantPropagationStore) o;
// go through all of the information of the other object
for (Entry<Node, Constant> e : other.contents.entrySet()) {
Node n = e.getKey();
Constant otherVal = e.getValue();
if (otherVal.isBottom())
// no information
continue;
if (contents.containsKey(n)) {
if (!otherVal.equals(contents.get(n))) {
return false;
}
} else {
return false;
}
}
// go through all of the information of the this object
for (Entry<Node, Constant> e : contents.entrySet()) {
Node n = e.getKey();
Constant thisVal = e.getValue();
if (thisVal.isBottom())
// no information
continue;
if (other.contents.containsKey(n)) {
continue;
} else {
return false;
}
}
return true;
}
use of org.checkerframework.dataflow.cfg.node.Node in project bazel by bazelbuild.
the class ConstantPropagationTransfer method visitEqualTo.
@Override
public TransferResult<Constant, ConstantPropagationStore> visitEqualTo(EqualToNode n, TransferInput<Constant, ConstantPropagationStore> pi) {
ConstantPropagationStore p = pi.getRegularStore();
ConstantPropagationStore old = p.copy();
Node left = n.getLeftOperand();
Node right = n.getRightOperand();
process(p, left, right);
process(p, right, left);
return new ConditionalTransferResult<>(null, p, old);
}
Aggregations