3333import de .uka .ilkd .key .speclang .njml .JmlParser .ProofArgContext ;
3434import de .uka .ilkd .key .speclang .njml .JmlParser .ProofCmdCaseContext ;
3535import de .uka .ilkd .key .speclang .njml .JmlParser .ProofCmdContext ;
36-
3736import de .uka .ilkd .key .util .MiscTools ;
37+
3838import org .key_project .logic .Term ;
3939import org .key_project .logic .op .Modality ;
4040import org .key_project .prover .engine .ProverTaskListener ;
@@ -90,12 +90,14 @@ JTerm resolve(Map<LocationVariable, JFunction> obtainMap, Services services) {
9090 return result ;
9191 }
9292
93- private void assertNoObtainVarsLeft (JTerm term , Map <LocationVariable , JFunction > obtainMap ) {
93+ private void assertNoObtainVarsLeft (JTerm term ,
94+ Map <LocationVariable , JFunction > obtainMap ) {
9495 var v = new DefaultVisitor () {
9596 @ Override
9697 public void visit (Term visited ) {
97- if (obtainMap .containsKey (term .op ())) {
98- throw new RuntimeException ("Use of obtain variable before it being obtained: " + term .op ());
98+ if (obtainMap .containsKey (term .op ())) {
99+ throw new RuntimeException (
100+ "Use of obtain variable before it being obtained: " + term .op ());
99101 }
100102 }
101103 };
@@ -133,17 +135,19 @@ private static JmlAssert getJmlAssert(Node node) {
133135 }
134136
135137 private static void collectUpdates (JTerm update , Map <JTerm , JTerm > updates , Services services ) {
136- switch (update .op ()) {
138+ switch (update .op ()) {
137139 case ElementaryUpdate eu ->
138- updates .put (services .getTermBuilder ().var ((ProgramVariable ) eu .lhs ()), update .sub (0 ));
140+ updates .put (services .getTermBuilder ().var ((ProgramVariable ) eu .lhs ()),
141+ update .sub (0 ));
139142
140- case UpdateJunctor uj -> {
143+ case UpdateJunctor uj -> {
141144 collectUpdates (update .sub (0 ), updates , services );
142145 collectUpdates (update .sub (1 ), updates , services );
143146 }
144147
145148 default ->
146- throw new IllegalStateException ("Unexpected update operation: " + update .op ().getClass ());
149+ throw new IllegalStateException (
150+ "Unexpected update operation: " + update .op ().getClass ());
147151 }
148152 }
149153
@@ -177,22 +181,27 @@ public ProofMacroFinishedInfo applyTo(UserInterfaceControl uic, Proof proof,
177181 "Running attached script from goal " + goal .node ().serialNr (), 0 ));
178182
179183 KeyAst .JMLProofScript proofScript = jmlAssert .getAssertionProof ();
180- Map <ParserRuleContext , JTerm > termMap = getTermMap (jmlAssert , getJavaBlock (goal ), proof .getServices ());
181- // We heavily rely on that variables have been computed before, otherwise this will raise an NPE.
182- Map <LocationVariable , JFunction > obtainMap = makeObtainVarMap (jmlAssert .collectVariablesInProof (null ));
183- @ Nullable OpReplacer updateReplacer = getUpdateReplacer (goal );
184+ Map <ParserRuleContext , JTerm > termMap =
185+ getTermMap (jmlAssert , getJavaBlock (goal ), proof .getServices ());
186+ // We heavily rely on that variables have been computed before, otherwise this will
187+ // raise an NPE.
188+ Map <LocationVariable , JFunction > obtainMap =
189+ makeObtainVarMap (jmlAssert .collectVariablesInProof (null ));
190+ @ Nullable
191+ OpReplacer updateReplacer = getUpdateReplacer (goal );
184192 List <ScriptCommandAst > renderedProof =
185193 renderProof (proofScript , termMap , updateReplacer , proof .getServices ());
186194 ProofScriptEngine pse = new ProofScriptEngine (proof );
187195 pse .setInitiallySelectedGoal (goal );
188196 pse .getStateMap ().putUserData ("jml.obtainVarMap" , obtainMap );
189197 pse .getStateMap ().getValueInjector ().addConverter (JTerm .class , ObtainAwareTerm .class ,
190- oat -> oat .resolve (obtainMap , goal .proof ().getServices ()));
198+ oat -> oat .resolve (obtainMap , goal .proof ().getServices ()));
191199 // TODO: Perhaps have holes also in JML?
192- pse .getStateMap ().getValueInjector ().addConverter (TermWithHoles .class , ObtainAwareTerm .class ,
193- oat -> new TermWithHoles (oat .resolve (obtainMap , goal .proof ().getServices ())));
200+ pse .getStateMap ().getValueInjector ().addConverter (TermWithHoles .class ,
201+ ObtainAwareTerm .class ,
202+ oat -> new TermWithHoles (oat .resolve (obtainMap , goal .proof ().getServices ())));
194203 pse .getStateMap ().getValueInjector ().addConverter (boolean .class , ObtainAwareTerm .class ,
195- oat -> Boolean .parseBoolean (oat .term .toString ()));
204+ oat -> Boolean .parseBoolean (oat .term .toString ()));
196205 LOGGER .debug ("---- Script" );
197206 LOGGER .debug (renderedProof .stream ().map (ScriptCommandAst ::asCommandLine )
198207 .collect (Collectors .joining ("\n " )));
@@ -216,7 +225,8 @@ public ProofMacroFinishedInfo applyTo(UserInterfaceControl uic, Proof proof,
216225 }
217226
218227
219- private Map <ParserRuleContext , JTerm > getTermMap (JmlAssert jmlAssert , JavaBlock javaBlock , Services services ) {
228+ private Map <ParserRuleContext , JTerm > getTermMap (JmlAssert jmlAssert , JavaBlock javaBlock ,
229+ Services services ) {
220230 SpecificationRepository .@ Nullable JmlStatementSpec jmlspec =
221231 services .getSpecificationRepository ().getStatementSpec (jmlAssert );
222232 if (jmlspec == null ) {
@@ -237,17 +247,20 @@ private Map<ParserRuleContext, JTerm> getTermMap(JmlAssert jmlAssert, JavaBlock
237247 }
238248
239249 /**
240- * For some reason, the self variable in the spec is not the same as the self variable and needs to
250+ * For some reason, the self variable in the spec is not the same as the self variable and needs
251+ * to
241252 * be corrected.
242253 */
243- private JTerm correctSelfVar (int index , JavaBlock javaBlock , SpecificationRepository .JmlStatementSpec spec , Services services ) {
254+ private JTerm correctSelfVar (int index , JavaBlock javaBlock ,
255+ SpecificationRepository .JmlStatementSpec spec , Services services ) {
244256 final MethodFrame frame = JavaTools .getInnermostMethodFrame (javaBlock , services );
245257 final JTerm self = MiscTools .getSelfTerm (frame , services );
246258 return spec .getTerm (services , self , index );
247259
248260 }
249261
250- private Map <LocationVariable , JFunction > makeObtainVarMap (ImmutableList <LocationVariable > locationVariables ) {
262+ private Map <LocationVariable , JFunction > makeObtainVarMap (
263+ ImmutableList <LocationVariable > locationVariables ) {
251264 HashMap <LocationVariable , JFunction > result = new HashMap <>();
252265 for (LocationVariable lv : locationVariables ) {
253266 result .put (lv , null );
@@ -256,7 +269,8 @@ private Map<LocationVariable, JFunction> makeObtainVarMap(ImmutableList<Location
256269 }
257270
258271 private static List <ScriptCommandAst > renderProof (KeyAst .JMLProofScript script ,
259- Map <ParserRuleContext , JTerm > termMap , @ Nullable OpReplacer update , Services services ) throws ScriptException {
272+ Map <ParserRuleContext , JTerm > termMap , @ Nullable OpReplacer update , Services services )
273+ throws ScriptException {
260274 List <ScriptCommandAst > result = new ArrayList <>();
261275 // Push current settings onto the settings stack
262276 result .add (new ScriptCommandAst ("set" , Map .of ("stack" , "push" ), List .of ()));
@@ -271,15 +285,15 @@ private static List<ScriptCommandAst> renderProof(KeyAst.JMLProofScript script,
271285 }
272286
273287 private static List <ScriptCommandAst > renderProofCmd (ProofCmdContext ctx ,
274- Map <ParserRuleContext , JTerm > termMap ,
275- @ Nullable OpReplacer update , Services services ) throws ScriptException {
288+ Map <ParserRuleContext , JTerm > termMap ,
289+ @ Nullable OpReplacer update , Services services ) throws ScriptException {
276290 List <ScriptCommandAst > result = new ArrayList <>();
277291
278292 // Push the current branch context
279293 result .add (new ScriptCommandAst ("branches" , Map .of (), List .of ("push" )));
280294
281295 // Compose the command itself
282- if (ctx .obtain != null ) {
296+ if (ctx .obtain != null ) {
283297 ScriptCommandAst command = renderObtainCommand (ctx , termMap , update , services );
284298 result .add (command );
285299 } else {
@@ -289,7 +303,7 @@ private static List<ScriptCommandAst> renderProofCmd(ProofCmdContext ctx,
289303
290304 // handle followup proofCmd if present
291305 JmlParser .ProofCmdSuffixContext suffix = ctx .proofCmdSuffix ();
292- if (suffix != null ) {
306+ if (suffix != null ) {
293307 if (!suffix .proofCmd ().isEmpty ()) {
294308 result .add (new ScriptCommandAst ("branches" , Map .of (), List .of ("single" )));
295309 for (ProofCmdContext proofCmdContext : suffix .proofCmd ()) {
@@ -301,7 +315,7 @@ private static List<ScriptCommandAst> renderProofCmd(ProofCmdContext ctx,
301315 for (ProofCmdCaseContext pcase : suffix .proofCmdCase ()) {
302316 String label = StringUtil .stripQuotes (pcase .label .getText ());
303317 result .add (new ScriptCommandAst ("branches" , Map .of ("branch" , label ),
304- List .of ("select" )));
318+ List .of ("select" )));
305319 for (ProofCmdContext proofCmdContext : pcase .proofCmd ()) {
306320 result .addAll (renderProofCmd (proofCmdContext , termMap , update , services ));
307321 }
@@ -314,11 +328,12 @@ private static List<ScriptCommandAst> renderProofCmd(ProofCmdContext ctx,
314328 return result ;
315329 }
316330
317- private static ScriptCommandAst renderObtainCommand (ProofCmdContext ctx , Map <ParserRuleContext , JTerm > termMap ,
318- @ Nullable OpReplacer update , Services services ) throws ScriptException {
331+ private static ScriptCommandAst renderObtainCommand (ProofCmdContext ctx ,
332+ Map <ParserRuleContext , JTerm > termMap ,
333+ @ Nullable OpReplacer update , Services services ) throws ScriptException {
319334 Map <String , Object > named = new HashMap <>();
320335
321- String argName = switch (ctx .obtKind .getType ()) {
336+ String argName = switch (ctx .obtKind .getType ()) {
322337 case JmlLexer .SUCH_THAT -> "such_that" ;
323338 case JmlLexer .EQUAL_SINGLE -> "equals" ;
324339 case JmlLexer .FROM_GOAL -> "from_goal" ;
@@ -327,7 +342,7 @@ private static ScriptCommandAst renderObtainCommand(ProofCmdContext ctx, Map<Par
327342
328343 named .put ("var" , ctx .var .getText ());
329344
330- if (ctx .expression () == null ) {
345+ if (ctx .expression () == null ) {
331346 named .put (argName , true );
332347 } else {
333348 JmlParser .ExpressionContext exp = ctx .expression ();
@@ -347,7 +362,8 @@ private static ScriptCommandAst renderObtainCommand(ProofCmdContext ctx, Map<Par
347362 return new ScriptCommandAst ("__obtain" , named , List .of (), Location .fromToken (ctx .start ));
348363 }
349364
350- private static @ NonNull ScriptCommandAst renderRegularCommand (ProofCmdContext ctx , Map <ParserRuleContext , JTerm > termMap , @ Nullable OpReplacer update , Services services ) {
365+ private static @ NonNull ScriptCommandAst renderRegularCommand (ProofCmdContext ctx ,
366+ Map <ParserRuleContext , JTerm > termMap , @ Nullable OpReplacer update , Services services ) {
351367 Map <String , Object > named = new HashMap <>();
352368 List <Object > positional = new ArrayList <>();
353369 for (ProofArgContext argContext : ctx .proofArg ()) {
@@ -372,7 +388,7 @@ private static ScriptCommandAst renderObtainCommand(ProofCmdContext ctx, Map<Par
372388 }
373389 }
374390 return new ScriptCommandAst (ctx .cmd .getText (), named , positional ,
375- Location .fromToken (ctx .start ));
391+ Location .fromToken (ctx .start ));
376392 }
377393
378394
0 commit comments