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

Use .equals() for nodeValues if == does not work; fixes #3484 #3523

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
90cdc60
Routines to format AnalysisResult objects
mernst Jul 29, 2020
62376b7
Merge ../checker-framework-branch-master into analysisresult-repr
mernst Jul 29, 2020
c057cdf
Fix issues
mernst Jul 29, 2020
f420843
Use .equals() for nodeValues if == does not work
mernst Jul 29, 2020
fe18877
Javadoc fixes
mernst Jul 29, 2020
65d71dc
Merge ../checker-framework-fork-mernst-branch-analysisresult-repr int…
mernst Jul 29, 2020
c27c7b4
Remove commented-out code
mernst Jul 29, 2020
702f803
Add a repr() method for ControlFlowGraph
mernst Jul 29, 2020
2f6efa5
Add SystemUtil.sleep method
mernst Jul 29, 2020
d1045e1
Remove stray character
mernst Jul 29, 2020
4c9b3cd
Address code review feedback
mernst Jul 30, 2020
b4a3db7
Merge ../checker-framework-branch-master into analysisresult-repr
mernst Jul 30, 2020
3e37f6f
Merge ../checker-framework-fork-mernst-branch-javacutil-sleep into an…
mernst Jul 30, 2020
31f73b8
Fix import statement
mernst Jul 30, 2020
cf227e1
Merge ../checker-framework-branch-master into javacutil-sleep
mernst Jul 30, 2020
ffc8fc9
Fix typo, remove throw
mernst Jul 30, 2020
b5f101b
Merge ../checker-framework-fork-mernst-branch-javacutil-sleep into an…
mernst Jul 30, 2020
1f01fcd
Address code review feedback
mernst Jul 31, 2020
6b00d1e
Merge ../checker-framework-branch-master into analysisresult-repr
mernst Jul 31, 2020
6d76803
More changes from code review
mernst Jul 31, 2020
0453ce1
Merge ../checker-framework-branch-master into analysisresult-repr
mernst Jul 31, 2020
7cc2236
Merge ../checker-framework-fork-mernst-branch-analysisresult-repr int…
mernst Jul 31, 2020
20f244c
Merge ../checker-framework-branch-master into analysisresult-repr
mernst Jul 31, 2020
e45f915
Merge ../checker-framework-fork-mernst-branch-analysisresult-repr int…
mernst Jul 31, 2020
6b2cec3
Merge ../checker-framework-branch-master into analysisresult-repr
mernst Jul 31, 2020
a309b83
Add AnalysisResult.checkRep method
mernst Jul 31, 2020
ca60260
Remove AnalysisResult.checkRep
mernst Jul 31, 2020
6e10edb
Merge ../checker-framework-branch-master into analysisresult-repr
mernst Jul 31, 2020
6194e5c
Merge ../checker-framework-branch-master into analysisresult-checkrep…
mernst Jul 31, 2020
98fe42c
Merge ../checker-framework-fork-mernst-branch-analysisresult-repr int…
mernst Jul 31, 2020
c4bdb38
Merge ../checker-framework-fork-mernst-branch-analysisresult-checkrep…
mernst Jul 31, 2020
835d152
Explain repr()
mernst Jul 31, 2020
f3ebe6f
Don't use repr()
mernst Jul 31, 2020
f0fc6cc
Tweak wording
mernst Jul 31, 2020
cbdde4b
Fix HTML tag
mernst Aug 1, 2020
9c4209a
Merge ../checker-framework-branch-master into analysisresult-checkrep…
mernst Aug 1, 2020
4bcb7ef
Merge ../checker-framework-branch-master into analysisresult-repr
mernst Aug 1, 2020
c429f18
Merge ../checker-framework-fork-mernst-branch-analysisresult-repr int…
mernst Aug 1, 2020
5c39fb6
Merge ../checker-framework-fork-mernst-branch-analysisresult-checkrep…
mernst Aug 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion checker/tests/nullness/TryCatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ void unreachableCatch(String[] xs) {
t.toString();
try {
} catch (Throwable e) {
// :: error: (dereference.of.nullable)
t.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.sun.source.tree.Tree;
import com.sun.source.tree.UnaryTree;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;
import javax.lang.model.element.Element;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.cfg.block.Block;
Expand Down Expand Up @@ -166,7 +168,24 @@ public HashMap<Element, V> getFinalLocalValues() {
* available
*/
public @Nullable V getValue(Node n) {
return nodeValues.get(n);
V result = nodeValues.get(n);
if (result != null) {
return result;
}
List<Node> equalNodes = new ArrayList<>();
for (Node candidate : nodeValues.keySet()) {
if (n.equals(candidate)) {
equalNodes.add(candidate);
}
}
switch (equalNodes.size()) {
case 0:
return null;
case 1:
return nodeValues.get(equalNodes.get(0));
default:
return null;
}
}

/**
Expand Down Expand Up @@ -443,4 +462,83 @@ public static <V extends AbstractValue<V>, S extends Store<S>> S runAnalysisFor(
return transferInput.analysis.runAnalysisFor(
node, before, transferInput, nodeValues, analysisCaches);
}

/**
* Returns a verbose string representation of this, useful for debugging.
*
* @return a string representation of this
*/
public String repr() {
StringJoiner result =
new StringJoiner(
String.format("%n "),
String.format("AnalysisResult{%n "),
String.format("%n}"));
result.add("nodeValues = " + nodeValuesRepr(nodeValues));
result.add("treeLookup = " + treeLookupRepr(treeLookup));
result.add("unaryAssignNodeLookup = " + unaryAssignNodeLookup);
result.add("finalLocalValues = " + finalLocalValues);
result.add("stores = " + stores);
result.add("analysisCaches = " + analysisCaches);
return result.toString();
}

/**
* Returns a verbose printed representation, useful for debugging. The map has the same type as
* the {@code nodeValues} field.
*
* @param <V> the type of values in the map
* @param nodeValues a map to format
* @return a printed representation of the given map
*/
public static <V> String nodeValuesRepr(Map<Node, V> nodeValues) {
if (nodeValues.isEmpty()) {
return "{}";
}
StringJoiner result = new StringJoiner(String.format("%n "));
result.add("{");
for (Map.Entry<Node, V> entry : nodeValues.entrySet()) {
Node key = entry.getKey();
result.add(String.format("%s => %s", key.repr(), entry.getValue()));
}
result.add("}");
return result.toString();
}

/**
* Returns a verbose printed representation of a map, useful for debugging. The map has the same
* type as the {@code treeLookup} field.
*
* @param treeLookup a map to format
* @return a printed representation of the given map
*/
public static String treeLookupRepr(Map<Tree, Set<Node>> treeLookup) {
if (treeLookup.isEmpty()) {
return "{}";
}
StringJoiner result = new StringJoiner(String.format("%n "));
result.add("{");
for (Map.Entry<Tree, Set<Node>> entry : treeLookup.entrySet()) {
Tree key = entry.getKey();
String treeString = key.toString().replaceAll("[ \n\t]+", " ");
if (treeString.length() > 65) {
treeString = "\"" + treeString.substring(0, 60) + "...\"";
}
result.add(treeString + " => " + Node.nodeCollectionRepr(entry.getValue()));
}
result.add("}");
return result.toString();
}

/** Checks representation invariants on this. */
public void checkRep() {
// Require that each node in treeLookup exists in nodeValues.
for (Map.Entry<Tree, Set<Node>> entry : treeLookup.entrySet()) {
for (Node n : entry.getValue()) {
if (!nodeValues.containsKey(n)) {
throw new BugInCF("node %s is in treeLookup but not in nodeValues", n);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringJoiner;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.analysis.AnalysisResult;
import org.checkerframework.dataflow.cfg.block.Block;
import org.checkerframework.dataflow.cfg.block.Block.BlockType;
import org.checkerframework.dataflow.cfg.block.ConditionalBlock;
Expand Down Expand Up @@ -243,7 +245,8 @@ private Deque<Block> getSuccessors(Block cur) {
}

/**
* Returns the copied tree-lookup map.
* Returns the copied tree-lookup map. Ignores convertedTreeLookup, though {@link
* #getNodesCorrespondingToTree} uses that field.
*
* @return the copied tree-lookup map
*/
Expand Down Expand Up @@ -311,4 +314,32 @@ public String toString() {
String stringGraph = (String) res.get("stringGraph");
return stringGraph == null ? super.toString() : stringGraph;
}

/**
* Returns a verbose string representation of this, useful for debugging.
*
* @return a string representation of this
*/
public String repr() {
StringJoiner result =
new StringJoiner(
String.format("%n "),
String.format("ControlFlowGraph{%n "),
String.format("%n }"));
result.add("entryBlock=" + entryBlock);
result.add("regularExitBlock=" + regularExitBlock);
result.add("exceptionalExitBlock=" + exceptionalExitBlock);
String astString = underlyingAST.toString().replaceAll("[ \t\n]", " ");
if (astString.length() > 65) {
astString = "\"" + astString.substring(0, 60) + "\"";
}
result.add("underlyingAST=" + underlyingAST);
result.add("treeLookup=" + AnalysisResult.treeLookupRepr(treeLookup));
result.add("convertedTreeLookup=" + AnalysisResult.treeLookupRepr(convertedTreeLookup));
result.add("unaryAssignNodeLookup=" + unaryAssignNodeLookup);
result.add("returnNodes=" + Node.nodeCollectionRepr(returnNodes));
result.add("declaredClasses=" + declaredClasses);
result.add("declaredLambdas=" + declaredLambdas);
return result.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sun.source.tree.Tree;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.StringJoiner;
import javax.lang.model.type.TypeMirror;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.cfg.CFGBuilder;
Expand Down Expand Up @@ -157,4 +158,32 @@ public Collection<Node> getTransitiveOperands() {
}
return transitiveOperands;
}

/**
* Returns a verbose printed representation of this, useful for debugging.
*
* @return a printed representation of this
*/
public String repr() {
return String.format(
"%s [%s %s %s]",
this,
this.getClass().getSimpleName(),
this.hashCode(),
System.identityHashCode(this));
}

/**
* Returns a verbose printed representation of a collection of nodes, useful for debugging..
*
* @param nodes a collection of nodes to format
* @return a printed representation of the given collection
*/
public static String nodeCollectionRepr(Collection<? extends Node> nodes) {
StringJoiner result = new StringJoiner(", ", "[", "]");
for (Node n : nodes) {
result.add(n.repr());
}
return result.toString();
}
}
18 changes: 17 additions & 1 deletion docs/developer/developer-manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ <h1 id="Checker_Framework_developer_manual">Checker Framework developer manual</
<li><a href="#Directory_structure">Directory structure</a></li>
<li><a href="#Build_tasks">Build tasks</a></li>
<li><a href="#tests">Testing the Checker Framework</a></li>
<li><a href="#Code_style">Code style</a></li>
<li><a href="#Code_style">Code style</a>
<ul>
<li><a href="#repr_method">The <code>repr()</code> method</a></li>
</ul></li>
<li><a href="#IDE_configuration">IDE configuration</a></li>
<li><a href="#pull-requests">Pull requests</a>
<ul>
Expand Down Expand Up @@ -158,6 +161,19 @@ <h2 id="Code_style">Code style</h2>
</p>


<h3 id="repr_method">The <code>repr()</code> method</h3>

<p>
Some classes contain a <code>repr()</code> method, for use during
debugging or logging. It returns a string that shows the internal
representation of the receiver. It is like <code>toString()</code> in
that it returns a string, but its result gives lower-level, and more
verbose details. A client of the class can decide whether to see the
more concise and high-level <code>toString()</code> or the more verbose
and low-level <code>repr()</code>, or both.
</p>


<h2 id="IDE_configuration">IDE configuration</h2>

<p>
Expand Down