Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
ProofScriptParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
24
Issues
24
List
Boards
Labels
Service Desk
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sarah.grebing
ProofScriptParser
Commits
92266590
Commit
92266590
authored
Jun 29, 2018
by
Sarah Grebing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Further implemenmtation for interactive macros
parent
8b850649
Pipeline
#23338
passed with stages
in 3 minutes and 23 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
141 additions
and
41 deletions
+141
-41
rt-key/src/main/java/edu/kit/iti/formal/psdbg/interpreter/exceptions/ScriptCommandNotApplicableException.java
...reter/exceptions/ScriptCommandNotApplicableException.java
+4
-0
ui/src/main/java/edu/kit/iti/formal/psdbg/gui/controller/InteractiveModeController.java
...ormal/psdbg/gui/controller/InteractiveModeController.java
+137
-41
No files found.
rt-key/src/main/java/edu/kit/iti/formal/psdbg/interpreter/exceptions/ScriptCommandNotApplicableException.java
View file @
92266590
package
edu.kit.iti.formal.psdbg.interpreter.exceptions
;
package
edu.kit.iti.formal.psdbg.interpreter.exceptions
;
import
de.uka.ilkd.key.macros.scripts.AbstractCommand
;
import
de.uka.ilkd.key.macros.scripts.RuleCommand
;
import
de.uka.ilkd.key.macros.scripts.RuleCommand
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -13,6 +14,9 @@ public class ScriptCommandNotApplicableException extends InterpreterRuntimeExcep
...
@@ -13,6 +14,9 @@ public class ScriptCommandNotApplicableException extends InterpreterRuntimeExcep
public
ScriptCommandNotApplicableException
(
Exception
e
,
RuleCommand
c
)
{
public
ScriptCommandNotApplicableException
(
Exception
e
,
RuleCommand
c
)
{
System
.
out
.
println
(
"Call "
+
c
.
getName
()
+
" was not applicable"
);
System
.
out
.
println
(
"Call "
+
c
.
getName
()
+
" was not applicable"
);
}
}
public
ScriptCommandNotApplicableException
(
Exception
e
,
AbstractCommand
c
)
{
System
.
out
.
println
(
"Call "
+
c
.
getName
()
+
" was not applicable"
);
}
public
ScriptCommandNotApplicableException
(
Exception
e
,
RuleCommand
c
,
Map
<
String
,
Object
>
params
)
{
public
ScriptCommandNotApplicableException
(
Exception
e
,
RuleCommand
c
,
Map
<
String
,
Object
>
params
)
{
super
(
createMessage
(
c
,
params
),
e
);
super
(
createMessage
(
c
,
params
),
e
);
...
...
ui/src/main/java/edu/kit/iti/formal/psdbg/gui/controller/InteractiveModeController.java
View file @
92266590
...
@@ -6,9 +6,8 @@ import de.uka.ilkd.key.control.DefaultUserInterfaceControl;
...
@@ -6,9 +6,8 @@ import de.uka.ilkd.key.control.DefaultUserInterfaceControl;
import
de.uka.ilkd.key.java.Services
;
import
de.uka.ilkd.key.java.Services
;
import
de.uka.ilkd.key.logic.Sequent
;
import
de.uka.ilkd.key.logic.Sequent
;
import
de.uka.ilkd.key.logic.SequentFormula
;
import
de.uka.ilkd.key.logic.SequentFormula
;
import
de.uka.ilkd.key.macros.scripts.EngineState
;
import
de.uka.ilkd.key.macros.ProofMacro
;
import
de.uka.ilkd.key.macros.scripts.RuleCommand
;
import
de.uka.ilkd.key.macros.scripts.*
;
import
de.uka.ilkd.key.macros.scripts.ScriptException
;
import
de.uka.ilkd.key.proof.Goal
;
import
de.uka.ilkd.key.proof.Goal
;
import
de.uka.ilkd.key.proof.Node
;
import
de.uka.ilkd.key.proof.Node
;
import
de.uka.ilkd.key.proof.Proof
;
import
de.uka.ilkd.key.proof.Proof
;
...
@@ -27,6 +26,7 @@ import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
...
@@ -27,6 +26,7 @@ import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import
edu.kit.iti.formal.psdbg.interpreter.dbg.DebuggerFramework
;
import
edu.kit.iti.formal.psdbg.interpreter.dbg.DebuggerFramework
;
import
edu.kit.iti.formal.psdbg.interpreter.dbg.PTreeNode
;
import
edu.kit.iti.formal.psdbg.interpreter.dbg.PTreeNode
;
import
edu.kit.iti.formal.psdbg.interpreter.exceptions.ScriptCommandNotApplicableException
;
import
edu.kit.iti.formal.psdbg.interpreter.exceptions.ScriptCommandNotApplicableException
;
import
edu.kit.iti.formal.psdbg.interpreter.funchdl.MacroCommandHandler
;
import
edu.kit.iti.formal.psdbg.parser.PrettyPrinter
;
import
edu.kit.iti.formal.psdbg.parser.PrettyPrinter
;
import
edu.kit.iti.formal.psdbg.parser.ast.*
;
import
edu.kit.iti.formal.psdbg.parser.ast.*
;
import
edu.kit.iti.formal.psdbg.parser.data.Value
;
import
edu.kit.iti.formal.psdbg.parser.data.Value
;
...
@@ -47,6 +47,7 @@ import java.math.BigInteger;
...
@@ -47,6 +47,7 @@ import java.math.BigInteger;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Getter
@Getter
@Setter
@Setter
@RequiredArgsConstructor
@RequiredArgsConstructor
...
@@ -202,7 +203,7 @@ public class InteractiveModeController {
...
@@ -202,7 +203,7 @@ public class InteractiveModeController {
try
{
try
{
applyRule
(
call
,
g
);
applyRule
Helper
(
call
,
g
,
Type
.
RULE
);
// Insert into the right cases
// Insert into the right cases
// Node currentNode = g.node();
// Node currentNode = g.node();
// cases.get(findRoot(currentNode)).add(call);
// cases.get(findRoot(currentNode)).add(call);
...
@@ -234,56 +235,146 @@ public class InteractiveModeController {
...
@@ -234,56 +235,146 @@ public class InteractiveModeController {
@Subscribe
@Subscribe
public
void
handle
(
Events
.
MacroApplicationEvent
map
)
{
public
void
handle
(
Events
.
MacroApplicationEvent
map
)
{
/* LOGGER.debug("Handling {}", map);
LOGGER
.
debug
(
"Handling {}"
,
map
);
moreThanOneMatch = false;
Goal
g
=
map
.
getGoal
();
String tapName = map.getApp().taclet().name().toString();
MacroCommand
.
Parameters
params
=
new
MacroCommand
.
Parameters
();
Goal g = tap.getCurrentGoal();
Parameters
callp
=
new
Parameters
();
CallStatement
call
=
new
CallStatement
(
map
.
getMacroName
().
getScriptCommandName
(),
callp
);
try
{
applyRuleHelper
(
call
,
g
,
Type
.
MACRO
);
String
c
=
getCasesAsString
();
scriptArea
.
setText
(
""
+
"//Preview \n"
+
c
);
SequentFormula seqForm = tap.getPio().sequentFormula();
//transform term to parsable string representation
Sequent seq = g.sequent();
String sfTerm = Utils.printParsableTerm(seqForm.formula(), keYServices);
String onTerm = Utils.printParsableTerm(tap.getPio().subTerm(), keYServices);
}
catch
(
ScriptCommandNotApplicableException
e
)
{
StringBuilder
sb
=
new
StringBuilder
(
"The macro command "
);
sb
.
append
(
call
.
getCommand
()).
append
(
" was not applicable."
);
System
.
out
.
println
(
"e = "
+
e
);
//sb.append("\nSequent Formula: formula=").append(sfTerm);
//sb.append("\nOn Sub Term: on=").append(onTerm);
RuleCommand.Parameters params = new RuleCommand.Parameters();
Utils
.
showWarningDialog
(
"Proof Command was not applicable"
,
params.formula = seqForm.formula();
"Proof Command was not applicable."
,
params.rulename = tap.getApp().taclet().name().toString();
sb
.
toString
(),
e
);
params.on = tap.getPio().subTerm();
}
}
RuleCommandHelper rch = new RuleCommandHelper(g, params);
int occ = rch.getOccurence(tap.getApp());
Parameters callp = new Parameters();
private
void
applyRuleHelper
(
CallStatement
call
,
Goal
g
,
Type
t
)
throws
ScriptCommandNotApplicableException
{
callp.put(new Variable("formula"), TermLiteral.from(sfTerm));
callp.put(new Variable("occ"), new IntegerLiteral(BigInteger.valueOf(occ)));
callp.put(new Variable("on"), TermLiteral.from(onTerm));
VariableAssignment va = new VariableAssignment(null);
savepointslist
.
add
(
g
.
node
());
CallStatement call = new CallStatement(tapName, callp);
savepointsstatement
.
add
(
call
);
ObservableList
<
GoalNode
<
KeyData
>>
goals
=
model
.
getGoals
();
GoalNode
<
KeyData
>
expandedNode
;
List
<
GoalNode
<
KeyData
>>
collect
=
goals
.
stream
().
filter
(
keyDataGoalNode
->
keyDataGoalNode
.
getData
().
getGoal
().
equals
(
g
)).
collect
(
Collectors
.
toList
());
if
(
collect
.
isEmpty
()
||
collect
.
size
()
>
1
)
{
throw
new
RuntimeException
(
"Interactive Rule can not be applied, can not find goal in goal list"
);
}
else
{
expandedNode
=
collect
.
get
(
0
);
}
// KeyData kd = g.getData();
Evaluator
eval
=
new
Evaluator
(
expandedNode
.
getAssignments
(),
expandedNode
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
call
.
getParameters
().
forEach
((
variable
,
expression
)
->
{
Value
exp
=
eval
.
eval
(
expression
);
map
.
put
(
variable
.
getIdentifier
(),
exp
.
getData
());
});
LOGGER
.
info
(
"Execute {} with {}"
,
call
,
map
);
try
{
try
{
KeyData
kd
=
expandedNode
.
getData
();
map
.
put
(
"#2"
,
call
.
getCommand
());
EngineState
estate
=
new
EngineState
(
g
.
proof
());
estate
.
setGoal
(
g
);
//System.out.println("on = " + map.get("on"));
//System.out.println("formula = " + map.get("formula"));
//System.out.println("occ = " + map.get("occ"));
ValueInjector
valueInjector
=
ValueInjector
.
createDefault
(
kd
.
getNode
());
AbstractUserInterfaceControl
uiControl
=
new
DefaultUserInterfaceControl
();
applyRule(call, g);
switch
(
t
){
case
MACRO:
MacroCommand
.
Parameters
cc
=
new
MacroCommand
.
Parameters
();
MacroCommand
c
=
new
MacroCommand
();
cc
=
valueInjector
.
inject
(
c
,
cc
,
map
);
c
.
execute
(
uiControl
,
cc
,
estate
);
postStateHandler
(
call
,
g
,
goals
,
expandedNode
,
kd
);
break
;
case
RULE:
RuleCommand
.
Parameters
ccR
=
new
RuleCommand
.
Parameters
();
RuleCommand
cR
=
new
RuleCommand
();
ccR
=
valueInjector
.
inject
(
cR
,
ccR
,
map
);
cR
.
execute
(
uiControl
,
ccR
,
estate
);
postStateHandler
(
call
,
g
,
goals
,
expandedNode
,
kd
);
break
;
case
SCRIPT_COMMAND:
ScriptCommand
.
Parameters
ccS
=
new
ScriptCommand
.
Parameters
();
ScriptCommand
cS
=
new
ScriptCommand
();
ccS
=
valueInjector
.
inject
(
cS
,
ccS
,
map
);
cS
.
execute
(
uiControl
,
ccS
,
estate
);
postStateHandler
(
call
,
g
,
goals
,
expandedNode
,
kd
);
break
;
default
:
throw
new
Exception
(
"Command not found"
);
String c = getCasesAsString();
}
scriptArea.setText("" +
"//Preview \n" + c);
}
catch
(
Exception
e
)
{
if
(
e
.
getClass
().
equals
(
ScriptException
.
class
))
{
System
.
out
.
println
(
"e.getMessage() = "
+
e
.
getMessage
());
throw
new
ScriptCommandNotApplicableException
(
e
,
null
,
map
);
} catch (ScriptCommandNotApplicableException e) {
}
else
{
StringBuilder sb = new StringBuilder("The script command ");
throw
new
RuntimeException
(
e
);
sb.append(call.getCommand()).append(" was not applicable.");
}
sb.append("\nSequent Formula: formula=").append(sfTerm);
}
sb.append("\nOn Sub Term: on=").append(onTerm);
Utils.showWarningDialog("Proof Command was not applicable",
"Proof Command was not applicable.",
sb.toString(), e);
}
}
*/
private
void
postStateHandler
(
CallStatement
call
,
Goal
g
,
ObservableList
<
GoalNode
<
KeyData
>>
goals
,
GoalNode
<
KeyData
>
expandedNode
,
KeyData
kd
)
{
ImmutableList
<
Goal
>
ngoals
=
g
.
proof
().
getSubtreeGoals
(
expandedNode
.
getData
().
getNode
());
goals
.
remove
(
expandedNode
);
GoalNode
<
KeyData
>
last
=
null
;
if
(
ngoals
.
size
()
>
1
)
{
cases
.
get
(
findRoot
(
ngoals
.
get
(
0
).
node
())).
add
(
call
);
CasesStatement
inner
=
new
CasesStatement
();
cases
.
get
(
findRoot
(
ngoals
.
get
(
0
).
node
())).
add
(
inner
);
for
(
Goal
newGoalNode
:
ngoals
)
{
KeyData
kdn
=
new
KeyData
(
kd
,
newGoalNode
.
node
());
goals
.
add
(
last
=
new
GoalNode
<>(
expandedNode
,
kdn
,
kdn
.
getNode
().
isClosed
()));
val
caseForSubNode
=
new
GuardedCaseStatement
();
val
m
=
new
MatchExpression
();
m
.
setPattern
(
new
StringLiteral
(
format
(
LabelFactory
.
getBranchingLabel
(
newGoalNode
.
node
()))
));
caseForSubNode
.
setGuard
(
m
);
inner
.
getCases
().
add
(
caseForSubNode
);
cases
.
put
(
last
.
getData
().
getNode
(),
caseForSubNode
.
getBody
());
}
}
else
{
if
(
ngoals
.
size
()
==
0
)
{
cases
.
get
(
findRoot
(
expandedNode
.
getData
().
getNode
())).
add
(
call
);
}
else
{
KeyData
kdn
=
new
KeyData
(
kd
,
ngoals
.
get
(
0
).
node
());
goals
.
add
(
last
=
new
GoalNode
<>(
expandedNode
,
kdn
,
kdn
.
getNode
().
isClosed
()));
Node
currentNode
=
last
.
getData
().
getNode
();
cases
.
get
(
findRoot
(
currentNode
)).
add
(
call
);
}
}
if
(
last
!=
null
)
model
.
setSelectedGoalNodeToShow
(
last
);
}
}
...
@@ -301,7 +392,7 @@ public class InteractiveModeController {
...
@@ -301,7 +392,7 @@ public class InteractiveModeController {
casesStatement
.
accept
(
pp
);
casesStatement
.
accept
(
pp
);
return
pp
.
toString
();
return
pp
.
toString
();
}
}
/*
private void applyRule(CallStatement call, Goal g) throws ScriptCommandNotApplicableException {
private void applyRule(CallStatement call, Goal g) throws ScriptCommandNotApplicableException {
savepointslist.add(g.node());
savepointslist.add(g.node());
savepointsstatement.add(call);
savepointsstatement.add(call);
...
@@ -338,6 +429,7 @@ public class InteractiveModeController {
...
@@ -338,6 +429,7 @@ public class InteractiveModeController {
//System.out.println("formula = " + map.get("formula"));
//System.out.println("formula = " + map.get("formula"));
//System.out.println("occ = " + map.get("occ"));
//System.out.println("occ = " + map.get("occ"));
ValueInjector valueInjector = ValueInjector.createDefault(kd.getNode());
ValueInjector valueInjector = ValueInjector.createDefault(kd.getNode());
RuleCommand.Parameters cc = new RuleCommand.Parameters();
RuleCommand.Parameters cc = new RuleCommand.Parameters();
cc = valueInjector.inject(c, cc, map);
cc = valueInjector.inject(c, cc, map);
AbstractUserInterfaceControl uiControl = new DefaultUserInterfaceControl();
AbstractUserInterfaceControl uiControl = new DefaultUserInterfaceControl();
...
@@ -389,7 +481,7 @@ public class InteractiveModeController {
...
@@ -389,7 +481,7 @@ public class InteractiveModeController {
}
}
}
}
}
}
*/
private
String
format
(
String
branchingLabel
)
{
private
String
format
(
String
branchingLabel
)
{
// System.out.println("branchingLabel = " + branchingLabel);
// System.out.println("branchingLabel = " + branchingLabel);
...
@@ -419,4 +511,8 @@ public class InteractiveModeController {
...
@@ -419,4 +511,8 @@ public class InteractiveModeController {
}
}
static
enum
Type
{
MACRO
,
RULE
,
SCRIPT_COMMAND
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment