From f90df3199dd05f8332b7cdd3d7c5e5ebf4e18bc9 Mon Sep 17 00:00:00 2001 From: d367wang Date: Sun, 31 May 2020 20:31:26 +0000 Subject: [PATCH 1/3] refine exception type of try-catch edges --- .../dataflow/cfg/CFGBuilder.java | 167 +++++++++++------- 1 file changed, 105 insertions(+), 62 deletions(-) diff --git a/dataflow/src/main/java/org/checkerframework/dataflow/cfg/CFGBuilder.java b/dataflow/src/main/java/org/checkerframework/dataflow/cfg/CFGBuilder.java index 48ebdfbbb0cd..ed6d9da8d94d 100644 --- a/dataflow/src/main/java/org/checkerframework/dataflow/cfg/CFGBuilder.java +++ b/dataflow/src/main/java/org/checkerframework/dataflow/cfg/CFGBuilder.java @@ -391,18 +391,21 @@ protected static class NodeWithExceptionsHolder extends ExtendedNode { protected final Node node; /** - * Map from exception type to labels of successors that may be reached as a result of that - * exception. + * Map from delcared thrown exception type to all pairs of the actual caught type and the + * corresponding target's label that may be reached as a result of that exception. */ - protected final Map> exceptions; + protected final Map>> exceptions; /** * Construct a NodeWithExceptionsHolder for the given node and exceptions. * * @param node the node to hold - * @param exceptions the exceptions to hold + * @param exceptions map from declared thrown exception to set of all pairs of actual caught + * type and corresponding successor's label for the node, to hold in field {@code + * exceptions} */ - public NodeWithExceptionsHolder(Node node, Map> exceptions) { + public NodeWithExceptionsHolder( + Node node, Map>> exceptions) { super(ExtendedNodeType.EXCEPTION_NODE); this.node = node; this.exceptions = exceptions; @@ -411,9 +414,10 @@ public NodeWithExceptionsHolder(Node node, Map> exception /** * Get the exceptions for the node. * - * @return exceptions for the node + * @return map from declared thrown exception to set of all pairs of actual caught type and + * corresponding successor's label for the node */ - public Map> getExceptions() { + public Map>> getExceptions() { return exceptions; } @@ -571,11 +575,19 @@ private static String uniqueName() { */ protected static interface TryFrame { /** - * Given a type of thrown exception, add the set of possible control flow successor {@link - * Label}s to the argument set. Return true if the exception is known to be caught by one of - * those labels and false if it may propagate still further. + * Given a type of thrown exception, add the set of all possible pairs of actual caught type + * {@link TypeMirror} and its control flow successor {@link Label} to the argument set. + * Return true if the exception is known to be caught by one of those labels and false if it + * may propagate still further. + * + * @param thrown the declared type of thrown exception + * @param causeLabelPairs the set of all possible pairs of the actual caught exception type + * and the corresponding target label + * @return true if {@code thrown} is known to be caught by one of those labels and false if + * it may propagate still further */ - public boolean possibleLabels(TypeMirror thrown, Set