-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Print real condition in if labels (#3222)
This PR modifies the labels in the proof tree to show the actual condition of ifs instead of the boolean variable introduced by the unfold taclet. With this change, the branch labels in the proof tree are much more useful. |previous|now| :-------------------------:|:-------------------------: ![Sum_pre](https://github.com/KeYProject/key/assets/12560461/2b274dbe-579f-4b39-82b3-29dc4e989381) | ![Sum_post](https://github.com/KeYProject/key/assets/12560461/8179dc72-76e1-49e3-8c03-57001ef36aa2) ![Contains_pre](https://github.com/KeYProject/key/assets/12560461/01157e0d-b360-40b7-a519-55cd31be36ad) | ![Contains_post](https://github.com/KeYProject/key/assets/12560461/c0d5cd54-f453-4cf4-a5d9-da323526d6a9)
- Loading branch information
Showing
8 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
key.core/src/main/java/de/uka/ilkd/key/logic/OpCollectorJavaBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* This file is part of KeY - https://key-project.org | ||
* KeY is licensed under the GNU General Public License Version 2 | ||
* SPDX-License-Identifier: GPL-2.0-only */ | ||
package de.uka.ilkd.key.logic; | ||
|
||
import de.uka.ilkd.key.java.ProgramElement; | ||
import de.uka.ilkd.key.java.visitor.JavaASTCollector; | ||
import de.uka.ilkd.key.logic.op.LocationVariable; | ||
|
||
/** | ||
* Extended {@link OpCollector} that also descends into Java blocks | ||
* and collects all {@link LocationVariable} there. | ||
* | ||
* @author Arne Keller | ||
*/ | ||
public class OpCollectorJavaBlock extends OpCollector { | ||
@Override | ||
public void visit(Term t) { | ||
super.visit(t); | ||
if (t.javaBlock() != JavaBlock.EMPTY_JAVABLOCK) { | ||
var collect = new JavaASTCollector(t.javaBlock().program(), LocationVariable.class); | ||
collect.start(); | ||
for (ProgramElement programElement : collect.getNodes()) { | ||
if (programElement instanceof LocationVariable locationVariable) { | ||
ops.add(locationVariable); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
key.core/src/main/java/org/key_project/proof/LocationVariableTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* This file is part of KeY - https://key-project.org | ||
* KeY is licensed under the GNU General Public License Version 2 | ||
* SPDX-License-Identifier: GPL-2.0-only */ | ||
package org.key_project.proof; | ||
|
||
import java.util.Map; | ||
import java.util.WeakHashMap; | ||
|
||
import de.uka.ilkd.key.logic.OpCollectorJavaBlock; | ||
import de.uka.ilkd.key.logic.op.LocationVariable; | ||
import de.uka.ilkd.key.proof.Proof; | ||
import de.uka.ilkd.key.proof.ProofEvent; | ||
import de.uka.ilkd.key.proof.RuleAppListener; | ||
import de.uka.ilkd.key.rule.RuleApp; | ||
|
||
/** | ||
* Tracks which rule application introduced each {@link LocationVariable} in a proof. | ||
* Currently only checks for {@code ifElseUnfold} rules. | ||
* | ||
* @author Arne Keller | ||
*/ | ||
public class LocationVariableTracker implements RuleAppListener { | ||
/** | ||
* The "origin" of the variables. Used to indicate which | ||
* {@link de.uka.ilkd.key.rule.TacletApp} created a new program variable. | ||
*/ | ||
private final Map<LocationVariable, RuleApp> createdBy = new WeakHashMap<>(); | ||
|
||
/** | ||
* Register a new tracker on the provided proof. | ||
* | ||
* @param proof proof to track | ||
*/ | ||
public static void handleProofLoad(Proof proof) { | ||
if (proof.lookup(LocationVariableTracker.class) != null) { | ||
return; | ||
} | ||
LocationVariableTracker self = new LocationVariableTracker(); | ||
proof.register(self, LocationVariableTracker.class); | ||
proof.addRuleAppListener(self); | ||
} | ||
|
||
/** | ||
* @param locationVariable some location variable | ||
* @return the rule app that created it, or null | ||
*/ | ||
public RuleApp getCreatedBy(LocationVariable locationVariable) { | ||
return createdBy.get(locationVariable); | ||
} | ||
|
||
@Override | ||
public void ruleApplied(ProofEvent e) { | ||
var rai = e.getRuleAppInfo(); | ||
if (rai.getRuleApp().rule().displayName().equals("ifElseUnfold")) { | ||
rai.getReplacementNodes().forEach(x -> { | ||
var it = x.getNodeChanges(); | ||
while (it.hasNext()) { | ||
var change = it.next(); | ||
var sf = change.getPos().sequentFormula(); | ||
var collect = new OpCollectorJavaBlock(); | ||
sf.formula().execPreOrder(collect); | ||
for (var op : collect.ops()) { | ||
if (!(op instanceof LocationVariable) || createdBy.containsKey(op)) { | ||
continue; | ||
} | ||
createdBy.put((LocationVariable) op, rai.getRuleApp()); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters