Skip to content

Commit fb65194

Browse files
committed
fixing the header rewriting
1 parent e679a17 commit fb65194

19 files changed

Lines changed: 252 additions & 174 deletions

File tree

key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/po/AbstractInfFlowPO.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import de.uka.ilkd.key.informationflow.proof.InfFlowCheckInfo;
1010
import de.uka.ilkd.key.informationflow.proof.InfFlowProof;
1111
import de.uka.ilkd.key.logic.JTerm;
12+
import de.uka.ilkd.key.nparser.KeyAst;
1213
import de.uka.ilkd.key.proof.Proof;
1314
import de.uka.ilkd.key.proof.StrategyInfoUndoMethod;
1415
import de.uka.ilkd.key.proof.init.AbstractOperationPO;
@@ -18,6 +19,7 @@
1819

1920
import org.key_project.prover.sequent.SequentFormula;
2021

22+
import org.jspecify.annotations.Nullable;
2123
import org.slf4j.LoggerFactory;
2224

2325
import static de.uka.ilkd.key.informationflow.proof.InfFlowCheckInfo.INF_FLOW_CHECK_TRUE;
@@ -45,7 +47,8 @@ public Proof createProof(String proofName, JTerm poTerm, InitConfig proofConfig)
4547
}
4648

4749
@Override
48-
public InfFlowProof createProofObject(String proofName, String proofHeader, JTerm poTerm,
50+
public InfFlowProof createProofObject(String proofName,
51+
KeyAst.@Nullable Declarations proofHeader, JTerm poTerm,
4952
InitConfig proofConfig) {
5053
final InfFlowProof proof = new InfFlowProof(proofName, poTerm, proofHeader, proofConfig);
5154

key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/proof/InfFlowProof.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import de.uka.ilkd.key.informationflow.po.InfFlowProofSymbols;
99
import de.uka.ilkd.key.logic.JTerm;
10+
import de.uka.ilkd.key.nparser.KeyAst;
1011
import de.uka.ilkd.key.proof.BuiltInRuleIndex;
1112
import de.uka.ilkd.key.proof.Proof;
1213
import de.uka.ilkd.key.proof.Statistics;
@@ -20,6 +21,8 @@
2021
import org.key_project.prover.sequent.SequentFormula;
2122
import org.key_project.util.collection.ImmutableList;
2223

24+
import org.jspecify.annotations.Nullable;
25+
2326
/**
2427
* The proof object used by Information Flow Proofs.
2528
*
@@ -39,12 +42,14 @@ public class InfFlowProof extends Proof {
3942
*/
4043
private SideProofStatistics sideProofStatistics = null;
4144

42-
public InfFlowProof(String name, Sequent sequent, String header, TacletIndex rules,
45+
public InfFlowProof(String name, Sequent sequent, KeyAst.@Nullable Declarations header,
46+
TacletIndex rules,
4347
BuiltInRuleIndex builtInRules, InitConfig initConfig) {
4448
super(name, sequent, header, rules, builtInRules, initConfig);
4549
}
4650

47-
public InfFlowProof(String name, JTerm problem, String header, InitConfig initConfig) {
51+
public InfFlowProof(String name, JTerm problem, KeyAst.@Nullable Declarations header,
52+
InitConfig initConfig) {
4853
super(name, problem, header, initConfig);
4954
}
5055

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

Lines changed: 135 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: GPL-2.0-only */
44
package de.uka.ilkd.key.nparser;
55

6+
import java.io.PrintWriter;
67
import java.net.URI;
78
import java.net.URISyntaxException;
89
import java.net.URL;
@@ -170,20 +171,9 @@ public ProblemInformation getProblemInformation() {
170171
* declarations of sorts, program variables, schema variables, predicates, and more.
171172
* See the grammar (KeYParser.g4) for more possible elements.
172173
*/
173-
public String getProblemHeader() {
174+
public KeyAst.@Nullable Declarations getProblemHeader() {
174175
final KeYParser.DeclsContext decls = ctx.decls();
175-
if (decls != null && decls.getChildCount() > 0) {
176-
final Token start = decls.start;
177-
final Token stop = decls.stop;
178-
if (start != null && stop != null) {
179-
int a = start.getStartIndex();
180-
int b = stop.getStopIndex();
181-
Interval interval = new Interval(a, b);
182-
CharStream input = ctx.start.getInputStream();
183-
return input.getText(interval);
184-
}
185-
}
186-
return "";
176+
return new KeyAst.Declarations(decls);
187177
}
188178
}
189179

@@ -319,4 +309,136 @@ private static List<ScriptCommandAst> asAst(URI file,
319309
return new ScriptCommandAst(it.cmd.getText(), nargs, pargs, loc);
320310
}
321311
}
312+
313+
/// Represents the user declarations in a KeY file.
314+
///
315+
/// @author weigl
316+
public static class Declarations extends KeyAst<KeYParser.DeclsContext> {
317+
protected Declarations(KeYParser.DeclsContext ctx) {
318+
super(ctx);
319+
}
320+
321+
public java.io.@Nullable File getJavaSourceLocation() {
322+
try {
323+
KeYParser.String_valueContext value =
324+
ctx.javaSource(0).oneJavaSource().string_value(0);
325+
String v = ParsingFacade.getValueDocumentation(value);
326+
return new java.io.File(v);
327+
} catch (NullPointerException | IndexOutOfBoundsException e) {
328+
{
329+
return null;
330+
}
331+
}
332+
}
333+
334+
/// Prints the definitions, independent of paths, to the given {@link PrintWriter}.
335+
public void printDefinitions(PrintWriter out) {
336+
ctx.accept(new KeYParserBaseVisitor<@Nullable Object>() {
337+
@Override
338+
public @Nullable Object visitOne_include(KeYParser.One_includeContext ctx) {
339+
if (ctx.absfile != null) {
340+
out.printf("\\include %s;", ctx.absfile.getText());
341+
}
342+
return null;
343+
}
344+
345+
@Override
346+
public @Nullable Object visitOptions_choice(KeYParser.Options_choiceContext ctx) {
347+
printAsIs(ctx);
348+
return null;
349+
}
350+
351+
@Override
352+
public @Nullable Object visitOption_decls(KeYParser.Option_declsContext ctx) {
353+
printAsIs(ctx);
354+
return null;
355+
}
356+
357+
@Override
358+
public @Nullable Object visitSort_decls(KeYParser.Sort_declsContext ctx) {
359+
printAsIs(ctx);
360+
return null;
361+
}
362+
363+
@Override
364+
public @Nullable Object visitProg_var_decls(KeYParser.Prog_var_declsContext ctx) {
365+
printAsIs(ctx);
366+
return null;
367+
}
368+
369+
@Override
370+
public @Nullable Object visitSchema_var_decls(
371+
KeYParser.Schema_var_declsContext ctx) {
372+
printAsIs(ctx);
373+
return null;
374+
}
375+
376+
@Override
377+
public @Nullable Object visitPred_decls(KeYParser.Pred_declsContext ctx) {
378+
printAsIs(ctx);
379+
return null;
380+
}
381+
382+
@Override
383+
public @Nullable Object visitFunc_decls(KeYParser.Func_declsContext ctx) {
384+
printAsIs(ctx);
385+
return null;
386+
}
387+
388+
@Override
389+
public @Nullable Object visitTransform_decls(KeYParser.Transform_declsContext ctx) {
390+
printAsIs(ctx);
391+
return null;
392+
}
393+
394+
@Override
395+
public @Nullable Object visitDatatype_decls(KeYParser.Datatype_declsContext ctx) {
396+
printAsIs(ctx);
397+
return null;
398+
}
399+
400+
401+
@Override
402+
public @Nullable Object visitRuleset_decls(KeYParser.Ruleset_declsContext ctx) {
403+
printAsIs(ctx);
404+
return null;
405+
}
406+
407+
408+
@Override
409+
public @Nullable Object visitContracts(KeYParser.ContractsContext ctx) {
410+
printAsIs(ctx);
411+
return null;
412+
}
413+
414+
@Override
415+
public @Nullable Object visitInvariants(KeYParser.InvariantsContext ctx) {
416+
printAsIs(ctx);
417+
return null;
418+
}
419+
420+
@Override
421+
public @Nullable Object visitRulesOrAxioms(KeYParser.RulesOrAxiomsContext ctx) {
422+
printAsIs(ctx);
423+
return null;
424+
}
425+
426+
private void printAsIs(ParserRuleContext ctx) {
427+
if (ctx != null) {
428+
final Token start = ctx.start;
429+
final Token stop = ctx.stop;
430+
if (start != null && stop != null) {
431+
int a = start.getStartIndex();
432+
int b = stop.getStopIndex();
433+
Interval interval = new Interval(a, b);
434+
CharStream input = ctx.start.getInputStream();
435+
out.println(input.getText(interval));
436+
}
437+
}
438+
}
439+
});
440+
441+
442+
}
443+
}
322444
}

key.core/src/main/java/de/uka/ilkd/key/proof/Proof.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import de.uka.ilkd.key.java.Services;
1616
import de.uka.ilkd.key.logic.JTerm;
1717
import de.uka.ilkd.key.logic.NamespaceSet;
18+
import de.uka.ilkd.key.nparser.KeyAst;
1819
import de.uka.ilkd.key.pp.AbbrevMap;
1920
import de.uka.ilkd.key.proof.calculus.JavaDLSequentKit;
2021
import de.uka.ilkd.key.proof.event.ProofDisposedEvent;
@@ -43,7 +44,6 @@
4344
import org.key_project.util.collection.ImmutableSLList;
4445
import org.key_project.util.lookup.Lookup;
4546

46-
import org.jspecify.annotations.NonNull;
4747
import org.jspecify.annotations.NullMarked;
4848
import org.jspecify.annotations.Nullable;
4949

@@ -96,7 +96,7 @@ public class Proof implements ProofObject<Goal>, Named {
9696
/**
9797
* declarations &c, read from a problem file or otherwise
9898
*/
99-
private String problemHeader = "";
99+
private KeyAst.@Nullable Declarations problemHeader = null;
100100

101101
/**
102102
* the proof environment (optional)
@@ -136,7 +136,7 @@ public class Proof implements ProofObject<Goal>, Named {
136136

137137
private long autoModeTime = 0;
138138

139-
private @Nullable Strategy<@NonNull Goal> activeStrategy;
139+
private @Nullable Strategy<Goal> activeStrategy;
140140

141141
private PropertyChangeListener settingsListener;
142142

@@ -238,15 +238,17 @@ private Proof(String name, Sequent problem, TacletIndex rules, BuiltInRuleIndex
238238
}
239239
}
240240

241-
public Proof(String name, Sequent problem, String header, InitConfig initConfig,
241+
public Proof(String name, Sequent problem, KeyAst.@Nullable Declarations header,
242+
InitConfig initConfig,
242243
Path proofFile) {
243244
this(name, problem, initConfig.createTacletIndex(), initConfig.createBuiltInRuleIndex(),
244245
initConfig);
245246
problemHeader = header;
246247
this.proofFile = proofFile;
247248
}
248249

249-
public Proof(String name, JTerm problem, String header, InitConfig initConfig) {
250+
public Proof(String name, JTerm problem, KeyAst.@Nullable Declarations header,
251+
InitConfig initConfig) {
250252
this(name,
251253
JavaDLSequentKit
252254
.createSuccSequent(ImmutableSLList.singleton(new SequentFormula(problem))),
@@ -255,7 +257,8 @@ public Proof(String name, JTerm problem, String header, InitConfig initConfig) {
255257
}
256258

257259

258-
public Proof(String name, Sequent sequent, String header, TacletIndex rules,
260+
public Proof(String name, Sequent sequent, KeyAst.@Nullable Declarations header,
261+
TacletIndex rules,
259262
BuiltInRuleIndex builtInRules, InitConfig initConfig) {
260263
this(name, sequent, rules, builtInRules, initConfig);
261264
problemHeader = header;
@@ -325,7 +328,7 @@ public Name name() {
325328
}
326329

327330

328-
public String header() {
331+
public KeyAst.@Nullable Declarations header() {
329332
return problemHeader;
330333
}
331334

@@ -389,15 +392,15 @@ public AbbrevMap abbreviations() {
389392
}
390393

391394

392-
public Strategy<@NonNull Goal> getActiveStrategy() {
395+
public Strategy<Goal> getActiveStrategy() {
393396
if (activeStrategy == null) {
394397
initStrategy();
395398
}
396399
return activeStrategy;
397400
}
398401

399402

400-
public void setActiveStrategy(Strategy<@NonNull Goal> activeStrategy) {
403+
public void setActiveStrategy(Strategy<Goal> activeStrategy) {
401404
this.activeStrategy = activeStrategy;
402405
getSettings().getStrategySettings().setStrategy(activeStrategy.name());
403406
updateStrategyOnGoals();
@@ -409,7 +412,7 @@ public void setActiveStrategy(Strategy<@NonNull Goal> activeStrategy) {
409412

410413

411414
private void updateStrategyOnGoals() {
412-
Strategy<@NonNull Goal> ourStrategy = getActiveStrategy();
415+
Strategy<Goal> ourStrategy = getActiveStrategy();
413416

414417
for (Goal goal : openGoals()) {
415418
goal.setGoalStrategy(ourStrategy);
@@ -776,7 +779,7 @@ public void breadthFirstSearch(Node startNode, ProofVisitor visitor) {
776779
* @param pred non-null test function
777780
* @return a node fulfilling {@code pred} or null
778781
*/
779-
public @Nullable Node findAny(@NonNull Predicate<Node> pred) {
782+
public @Nullable Node findAny(Predicate<Node> pred) {
780783
Queue<Node> queue = new LinkedList<>();
781784
queue.add(root);
782785
while (!queue.isEmpty()) {
@@ -974,7 +977,7 @@ public boolean isOpenGoal(Node node) {
974977
*
975978
* @return the goal that belongs to the given node or null if the node is an inner one
976979
*/
977-
public Goal getOpenGoal(@NonNull Node node) {
980+
public Goal getOpenGoal(Node node) {
978981
for (final Goal result : openGoals) {
979982
if (result.node() == node) {
980983
return result;
@@ -1317,7 +1320,7 @@ public <T> void deregister(T obj, Class<T> service) {
13171320
*
13181321
* @return the associated lookup
13191322
*/
1320-
public @NonNull Lookup getUserData() {
1323+
public Lookup getUserData() {
13211324
if (userData == null) {
13221325
userData = new Lookup();
13231326
}

0 commit comments

Comments
 (0)