Skip to content

Commit 0ea6348

Browse files
committed
Adding the possibility to have a Profile-dependent option panel
# Conflicts: # key.ui/src/main/java/de/uka/ilkd/key/gui/RecentFileMenu.java # Conflicts: # key.ui/src/main/java/de/uka/ilkd/key/gui/extension/api/KeYGuiExtension.java # Conflicts: # key.core/src/main/java/de/uka/ilkd/key/proof/init/ProblemInitializer.java
1 parent 29e129b commit 0ea6348

32 files changed

Lines changed: 753 additions & 323 deletions

File tree

key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/profile/SymbolicExecutionJavaProfile.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,9 @@ public static boolean isTruthValueEvaluationEnabled(Profile profile) {
325325
return false;
326326
}
327327
}
328+
329+
@Override
330+
public String displayName() {
331+
return NAME;
332+
}
328333
}

key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/util/SymbolicExecutionSideProofUtil.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import de.uka.ilkd.key.rule.BuiltInRule;
2828
import de.uka.ilkd.key.rule.OneStepSimplifier;
2929
import de.uka.ilkd.key.rule.Taclet;
30-
import de.uka.ilkd.key.rule.tacletbuilder.TacletBuilder;
3130
import de.uka.ilkd.key.settings.ProofSettings;
3231
import de.uka.ilkd.key.strategy.StrategyProperties;
3332
import de.uka.ilkd.key.symbolic_execution.profile.SimplifyTermProfile;
@@ -818,8 +817,7 @@ protected ImmutableList<TermLabelConfiguration> computeTermLabelConfiguration()
818817
: null;
819818
initConfig.setSettings(clonedSettings);
820819
initConfig.setTaclet2Builder(
821-
(HashMap<Taclet, TacletBuilder<? extends Taclet>>) sourceInitConfig.getTaclet2Builder()
822-
.clone());
820+
new HashMap<>(sourceInitConfig.getTaclet2Builder()));
823821
initConfig.setTaclets(sourceInitConfig.getTaclets());
824822
// Create new ProofEnvironment and initialize it with values from initial one.
825823
ProofEnvironment env = new ProofEnvironment(initConfig);

key.core.wd/src/main/java/de/uka/ilkd/key/wd/WdProfile.java

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
package de.uka.ilkd.key.wd;
55

66
import java.net.URL;
7+
import java.util.ArrayList;
8+
import java.util.List;
79
import java.util.Objects;
10+
import java.util.stream.Collectors;
811

912
import de.uka.ilkd.key.java.Services;
1013
import de.uka.ilkd.key.proof.Proof;
@@ -15,21 +18,30 @@
1518
import de.uka.ilkd.key.proof.io.RuleSourceFactory;
1619
import de.uka.ilkd.key.proof.mgt.SpecificationRepository;
1720
import de.uka.ilkd.key.rule.*;
21+
import de.uka.ilkd.key.settings.Configuration;
1822
import de.uka.ilkd.key.util.KeYResourceManager;
1923

24+
import org.key_project.logic.Choice;
2025
import org.key_project.logic.Name;
2126
import org.key_project.util.collection.ImmutableList;
2227

28+
import org.jspecify.annotations.Nullable;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
31+
2332
/**
2433
* @author Alexander Weigl
2534
* @version 1 (7/27/25)
2635
*/
2736
public class WdProfile extends JavaProfile {
37+
private static final Logger LOGGER = LoggerFactory.getLogger(WdProfile.class);
38+
2839
public static final String PROFILE_ID = "java-wd";
2940
public static final String DISPLAY_NAME = "Java Profile + Well-Definedness Checks";
3041

3142
public static final WdProfile INSTANCE = new WdProfile();
3243

44+
3345
private final RuleCollection wdStandardRules;
3446

3547
public WdProfile() {
@@ -97,9 +109,54 @@ public RuleCollection getStandardRules() {
97109
return wdStandardRules;
98110
}
99111

112+
/// {@inheritDoc}
113+
///
114+
/// @param additionalProfileOptions a string representing the choice of `wdOperator`
115+
/// @return
100116
@Override
101-
public void prepareInitConfig(InitConfig baseConfig) {
102-
var wdChoice = baseConfig.choiceNS().lookup(new Name("wdChecks:on"));
103-
baseConfig.activateChoice(wdChoice);
117+
public List<String> prepareInitConfig(InitConfig baseConfig,
118+
@Nullable Configuration additionalProfileOptions) {
119+
var warnings = new ArrayList<String>(2);
120+
var wdChoiceOn = baseConfig.choiceNS().lookup(new Name("wdChecks:on"));
121+
var wdChoiceOff = baseConfig.choiceNS().lookup(new Name("wdChecks:off"));
122+
123+
if (baseConfig.isChoiceActive(wdChoiceOff)) {
124+
final var message =
125+
"wdChecks:off was set by in the init config, probably given in KeY file. This setting will be ignored";
126+
warnings.add(message);
127+
LOGGER.warn(message); // this logging is for finding the spot.
128+
}
129+
baseConfig.activateChoice(wdChoiceOn);
130+
131+
132+
if (additionalProfileOptions != null) {
133+
final var wdOperator = "wdOperator";
134+
final var selectedWdOperator = additionalProfileOptions.getString(wdOperator);
135+
if (selectedWdOperator == null) {
136+
return warnings;
137+
}
138+
139+
var wdOperatorChoice = baseConfig.choiceNS().lookup(selectedWdOperator);
140+
if (wdOperatorChoice == null) {
141+
var choices = baseConfig.choiceNS().allElements()
142+
.stream()
143+
.filter(it -> wdOperator.equals(it.category()))
144+
.map(Choice::toString)
145+
.collect(Collectors.joining(", "));
146+
147+
throw new IllegalStateException("Could not find choice for %s.\n Choices known %s."
148+
.formatted(additionalProfileOptions, choices));
149+
} else {
150+
if (baseConfig.isChoiceCategorySet(wdOperator)
151+
&& !baseConfig.isChoiceActive(wdOperatorChoice)) {
152+
final var message = "Choice for wdOperator will be overwritten " +
153+
"by profile as defined by user in the additional profile options.";
154+
warnings.add(message);
155+
LOGGER.warn(message); // this logging is for finding the spot.
156+
}
157+
baseConfig.activateChoice(wdOperatorChoice);
158+
}
159+
}
160+
return warnings;
104161
}
105162
}

key.core.wd/src/main/java/de/uka/ilkd/key/wd/WdWhileInvariantRule.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import org.jspecify.annotations.NonNull;
1919
import org.jspecify.annotations.NullMarked;
20-
import org.jspecify.annotations.Nullable;
2120

2221

2322
@NullMarked
@@ -38,10 +37,6 @@ public Name name() {
3837
return NAME;
3938
}
4039

41-
@Override
42-
public @Nullable String getOrigin() {
43-
return super.getOrigin();
44-
}
4540

4641
protected static class WdWhileInvariantRuleApplier extends WhileInvariantRuleApplier {
4742
public WdWhileInvariantRuleApplier(Goal goal, LoopInvariantBuiltInRuleApp<?> ruleApp) {

key.core/src/main/java/de/uka/ilkd/key/nparser/ChoiceInformation.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class ChoiceInformation {
4242
/**
4343
* This map contains the default option for every category.
4444
*/
45-
private final Map<String, String> defaultOptions = new TreeMap<>();
45+
private final Map<String, Choice> defaultOptions = new TreeMap<>();
4646

4747
public ChoiceInformation() {
4848
this(new Namespace<>());
@@ -68,11 +68,11 @@ public Namespace<Choice> getChoices() {
6868
return choices;
6969
}
7070

71-
public void setDefaultOption(String category, String choice) {
72-
defaultOptions.put(category, category + ":" + choice);
71+
public void setDefaultOption(String category, Choice choice) {
72+
defaultOptions.put(category, choice);
7373
}
7474

75-
public Map<String, String> getDefaultOptions() {
75+
public Map<String, Choice> getDefaultOptions() {
7676
return defaultOptions;
7777
}
7878
}

key.core/src/main/java/de/uka/ilkd/key/nparser/KeyAst.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ public Configuration asConfiguration() {
191191
throw new RuntimeException("Error in configuration. Source: "
192192
+ ctx.start.getTokenSource().getSourceName());
193193
}
194+
195+
public List<Configuration> asConfigurationList() {
196+
final var cfg = new ConfigurationBuilder();
197+
List<Object> res = cfg.visitCfile(ctx);
198+
if (!res.isEmpty())
199+
return (List<Configuration>) res.getFirst();
200+
else
201+
throw new RuntimeException("Error in configuration. Source: "
202+
+ ctx.start.getTokenSource().getSourceName());
203+
}
194204
}
195205

196206
public static class SetStatementContext extends KeyAst<JmlParser.Set_statementContext> {

key.core/src/main/java/de/uka/ilkd/key/nparser/builder/ChoiceFinder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ public Object visitChoice(KeYParser.ChoiceContext ctx) {
5656
}
5757

5858
seq().put(category, new HashSet<>(options));
59-
choiceInformation.setDefaultOption(category, options.get(0));
60-
options.forEach(it -> choices().add(new Choice(it, category)));
59+
var choices = options.stream().map(it -> new Choice(it, category)).toList();
60+
choices.forEach(it -> choices().add(it));
61+
choiceInformation.setDefaultOption(category, choices.getFirst());
6162
return null;
6263
}
6364

0 commit comments

Comments
 (0)