Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
sarah.grebing
ProofScriptParser
Commits
985b0a8b
Commit
985b0a8b
authored
May 21, 2017
by
Alexander Weigl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplifcations and fixes
parent
729fe9ca
Pipeline
#10650
passed with stage
in 2 minutes and 7 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
156 additions
and
264 deletions
+156
-264
src/main/java/edu/kit/formal/dbg/Debugger.java
src/main/java/edu/kit/formal/dbg/Debugger.java
+79
-120
src/main/java/edu/kit/formal/interpreter/Evaluator.java.orig
src/main/java/edu/kit/formal/interpreter/Evaluator.java.orig
+0
-123
src/main/java/edu/kit/formal/interpreter/HistoryListener.java
...main/java/edu/kit/formal/interpreter/HistoryListener.java
+1
-0
src/main/java/edu/kit/formal/interpreter/InterpreterBuilder.java
...n/java/edu/kit/formal/interpreter/InterpreterBuilder.java
+69
-16
src/main/java/edu/kit/formal/interpreter/funchdl/MacroCommandHandler.java
...u/kit/formal/interpreter/funchdl/MacroCommandHandler.java
+2
-1
src/main/java/edu/kit/formal/interpreter/funchdl/ProofScriptCommandBuilder.java
...formal/interpreter/funchdl/ProofScriptCommandBuilder.java
+5
-4
No files found.
src/main/java/edu/kit/formal/dbg/Debugger.java
View file @
985b0a8b
...
...
@@ -2,6 +2,7 @@ package edu.kit.formal.dbg;
import
edu.kit.formal.interpreter.*
;
import
edu.kit.formal.interpreter.funchdl.BuiltinCommands
;
import
edu.kit.formal.interpreter.funchdl.CommandHandler
;
import
edu.kit.formal.interpreter.funchdl.DefaultLookup
;
import
edu.kit.formal.proofscriptparser.*
;
import
edu.kit.formal.proofscriptparser.ast.*
;
...
...
@@ -10,6 +11,7 @@ import org.antlr.v4.runtime.CharStreams;
import
java.io.*
;
import
java.math.BigInteger
;
import
java.util.List
;
import
java.util.function.BiConsumer
;
/**
* @author Alexander Weigl
...
...
@@ -36,14 +38,28 @@ public class Debugger {
interpreter
.
getEntryListeners
().
add
(
new
CommandLogger
());
//TODO install debugger functions
debuggerFunctions
.
getBuilders
().
add
(
new
Step
());
debuggerFunctions
.
getBuilders
().
add
(
new
Printer
());
debuggerFunctions
.
getBuilders
().
add
(
new
ChgSel
());
debuggerFunctions
.
getBuilders
().
add
(
new
Start
());
debuggerFunctions
.
getBuilders
().
add
(
new
Pause
());
debuggerFunctions
.
getBuilders
().
add
(
new
BrkPnt
());
debuggerFunctions
.
getBuilders
().
add
(
new
Status
());
registerDebuggerFunction
(
"step"
,
this
::
step
);
registerDebuggerFunction
(
"b"
,
this
::
setBreakpoint
);
registerDebuggerFunction
(
"start"
,
this
::
start
);
registerDebuggerFunction
(
"pause"
,
this
::
pause
);
registerDebuggerFunction
(
"chgsel"
,
this
::
changeSelected
);
registerDebuggerFunction
(
"psel"
,
this
::
psel
);
registerDebuggerFunction
(
"status"
,
this
::
status
);
}
private
void
registerDebuggerFunction
(
final
String
step
,
BiConsumer
<
CallStatement
,
VariableAssignment
>
func
)
{
debuggerFunctions
.
getBuilders
().
add
(
new
CommandHandler
()
{
@Override
public
boolean
handles
(
CallStatement
call
)
throws
IllegalArgumentException
{
return
step
.
equals
(
call
.
getCommand
());
}
@Override
public
void
evaluate
(
Interpreter
i
,
CallStatement
call
,
VariableAssignment
params
)
{
func
.
accept
(
call
,
params
);
}
});
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
...
...
@@ -64,11 +80,11 @@ public class Debugger {
while
(
true
)
{
System
.
out
.
printf
(
"dbg (%03d)> "
,
++
counter
);
String
input
=
br
.
readLine
();
execu
a
te
(
input
);
execute
(
input
);
}
}
private
void
execu
a
te
(
String
input
)
{
private
void
execute
(
String
input
)
{
input
=
input
.
trim
();
if
(
input
.
isEmpty
())
{
return
;
...
...
@@ -90,14 +106,7 @@ public class Debugger {
}
private
class
Step
implements
edu
.
kit
.
formal
.
interpreter
.
funchdl
.
CommandHandler
{
@Override
public
boolean
handles
(
CallStatement
call
)
throws
IllegalArgumentException
{
return
call
.
getCommand
().
equals
(
"step"
);
}
@Override
public
void
evaluate
(
Interpreter
interpreter
,
CallStatement
call
,
VariableAssignment
params
)
{
public
void
step
(
CallStatement
call
,
VariableAssignment
params
)
{
IntegerLiteral
il
=
(
IntegerLiteral
)
call
.
getParameters
().
get
(
new
Variable
(
"#1"
));
int
steps
=
1
;
if
(
il
!=
null
)
...
...
@@ -106,16 +115,8 @@ public class Debugger {
//LockSupport.unpark(interpreterThread);
blocker
.
unlock
();
}
}
private
class
Printer
implements
edu
.
kit
.
formal
.
interpreter
.
funchdl
.
CommandHandler
{
@Override
public
boolean
handles
(
CallStatement
call
)
throws
IllegalArgumentException
{
return
call
.
getCommand
().
equals
(
"psel"
);
}
@Override
public
void
evaluate
(
Interpreter
interpreter
,
CallStatement
call
,
VariableAssignment
params
)
{
public
void
psel
(
CallStatement
call
,
VariableAssignment
params
)
{
AbstractState
state
=
interpreter
.
getCurrentState
();
int
i
=
0
;
GoalNode
sel
;
...
...
@@ -133,59 +134,25 @@ public class Debugger {
g
.
getAssignments
().
asMap
());
}
}
}
private
class
Start
implements
edu
.
kit
.
formal
.
interpreter
.
funchdl
.
CommandHandler
{
@Override
public
boolean
handles
(
CallStatement
call
)
throws
IllegalArgumentException
{
return
call
.
getCommand
().
equals
(
"start"
);
}
@Override
public
void
evaluate
(
Interpreter
interpreter
,
CallStatement
call
,
VariableAssignment
params
)
{
public
void
start
(
CallStatement
call
,
VariableAssignment
params
)
{
interpreterThread
.
start
();
}
}
private
class
Pause
implements
edu
.
kit
.
formal
.
interpreter
.
funchdl
.
CommandHandler
{
@Override
public
boolean
handles
(
CallStatement
call
)
throws
IllegalArgumentException
{
return
call
.
getCommand
().
equals
(
"pause"
);
}
@Override
public
void
evaluate
(
Interpreter
interpreter
,
CallStatement
call
,
VariableAssignment
params
)
{
public
void
pause
(
CallStatement
call
,
VariableAssignment
params
)
{
blocker
.
stepUntilBlock
.
set
(
1
);
// block at next statement
}
}
private
class
BrkPnt
implements
edu
.
kit
.
formal
.
interpreter
.
funchdl
.
CommandHandler
{
@Override
public
boolean
handles
(
CallStatement
call
)
throws
IllegalArgumentException
{
return
call
.
getCommand
().
equals
(
"b"
);
}
@Override
public
void
evaluate
(
Interpreter
interpreter
,
CallStatement
call
,
VariableAssignment
params
)
{
public
void
setBreakpoint
(
CallStatement
call
,
VariableAssignment
params
)
{
IntegerLiteral
il
=
(
IntegerLiteral
)
call
.
getParameters
().
get
(
new
Variable
(
"#1"
));
blocker
.
addBreakpoint
(
il
.
getValue
().
intValue
());
System
.
out
.
println
(
"brkpnts: "
+
blocker
.
brkpnts
);
}
}
private
class
Status
implements
edu
.
kit
.
formal
.
interpreter
.
funchdl
.
CommandHandler
{
@Override
public
boolean
handles
(
CallStatement
call
)
throws
IllegalArgumentException
{
return
call
.
getCommand
().
equals
(
"status"
);
}
@Override
public
void
evaluate
(
Interpreter
interpreter
,
CallStatement
call
,
VariableAssignment
params
)
{
public
void
status
(
CallStatement
call
,
VariableAssignment
params
)
{
System
.
out
.
format
(
"name: %s, p: %s, state: %s, alive:%s, daemon:%s, interrupted:%s %n"
,
interpreterThread
.
getName
(),
interpreterThread
.
getPriority
(),
...
...
@@ -204,16 +171,8 @@ public class Debugger {
// states.get(i).getSelectedGoalNode().getAssignments().asMap());
}
}
}
private
class
ChgSel
implements
edu
.
kit
.
formal
.
interpreter
.
funchdl
.
CommandHandler
{
@Override
public
boolean
handles
(
CallStatement
call
)
throws
IllegalArgumentException
{
return
call
.
getCommand
().
equals
(
"chgsel"
);
}
@Override
public
void
evaluate
(
Interpreter
interpreter
,
CallStatement
call
,
VariableAssignment
params
)
{
public
void
changeSelected
(
CallStatement
call
,
VariableAssignment
params
)
{
AbstractState
state
=
interpreter
.
getCurrentState
();
params
=
interpreter
.
evaluateParameters
(
call
.
getParameters
());
Value
<
BigInteger
>
v
=
params
.
getValues
().
get
(
"#1"
);
...
...
@@ -222,7 +181,7 @@ public class Debugger {
state
.
getGoals
().
get
(
v
.
getData
().
intValue
()));
}
}
private
class
CommandLogger
extends
DefaultASTVisitor
<
Void
>
{
public
void
suffix
(
ASTNode
node
)
{
...
...
src/main/java/edu/kit/formal/interpreter/Evaluator.java.orig
deleted
100644 → 0
View file @
729fe9ca
package
edu
.
kit
.
formal
.
interpreter
;
import
edu
.
kit
.
formal
.
proofscriptparser
.
DefaultASTVisitor
;
import
edu
.
kit
.
formal
.
proofscriptparser
.
ast
.*;
import
lombok
.
Getter
;
import
lombok
.
Setter
;
import
java
.
util
.
List
;
/**
*
Class
handling
evaluation
of
expressions
(
visitor
for
expressions
)
*
*
@
author
S
.
Grebing
*/
public
class
Evaluator
extends
DefaultASTVisitor
<
Value
>
{
<<<<<<<
Updated
upstream
private
State
currentState
;
private
Stack
<
List
<
GoalNode
>>
matchedGoals
=
new
Stack
<>();
private
EvaluatorABI
abi
;
=======
private
GoalNode
currentState
;
private
List
<
VariableAssignment
>
matchedVariables
=
new
ArrayList
<>();
@
Getter
@
Setter
private
MatcherApi
matcher
;
>>>>>>>
Stashed
changes
public
Evaluator
(
State
s
)
{
this
.
currentState
=
s
;
}
/**
*
Evaluation
of
an
expression
.
*
*
@
param
truth
*
@
return
*/
public
Value
eval
(
Expression
truth
)
{
return
(
Value
)
truth
.
accept
(
this
);
}
@
Override
public
Value
visit
(
BinaryExpression
e
)
{
Value
v1
=
(
Value
)
e
.
getLeft
().
accept
(
this
);
Value
v2
=
(
Value
)
e
.
getRight
().
accept
(
this
);
Operator
op
=
e
.
getOperator
();
return
op
.
evaluate
(
v1
,
v2
);
}
/**
*
TODO
Connect
with
KeY
*
*
@
param
match
*
@
return
*/
@
Override
public
Value
visit
(
MatchExpression
match
)
{
<<<<<<<
Updated
upstream
=======
Value
pattern
=
(
Value
)
match
.
getPattern
().
accept
(
this
);
>>>>>>>
Stashed
changes
List
<
VariableAssignment
>
va
=
null
;
if
(
pattern
.
getType
()
==
Type
.
STRING
)
{
va
=
matcher
.
matchLabel
(
currentState
,
(
String
)
pattern
.
getData
());
}
else
if
(
pattern
.
getType
()
==
Type
.
TERM
)
{
va
=
matcher
.
matchSeq
(
currentState
,
(
String
)
pattern
.
getData
());
}
return
va
!= null && va.size() > 0 ? Value.TRUE : Value.FALSE;
}
/**
*
TODO
Connect
with
KeY
*
*
@
param
term
*
@
return
*/
@
Override
public
Value
visit
(
TermLiteral
term
)
{
return
null
;
}
@
Override
public
Value
visit
(
StringLiteral
string
)
{
return
Value
.
from
(
string
);
}
@
Override
public
Value
visit
(
Variable
variable
)
{
//
get
variable
value
String
id
=
variable
.
getIdentifier
();
Value
v
=
currentState
.
lookupVarValue
(
id
);
if
(
v
!= null) {
return
v
;
}
else
{
throw
new
RuntimeException
(
"Variable "
+
variable
+
" was not initialized"
);
}
}
@
Override
public
Value
visit
(
BooleanLiteral
bool
)
{
return
bool
.
isValue
()
?
Value
.
TRUE
:
Value
.
FALSE
;
}
@
Override
public
Value
visit
(
IntegerLiteral
integer
)
{
return
Value
.
from
(
integer
);
}
@
Override
public
Value
visit
(
UnaryExpression
e
)
{
Operator
op
=
e
.
getOperator
();
Expression
expr
=
e
.
getExpression
();
Value
exValue
=
(
Value
)
expr
.
accept
(
this
);
return
op
.
evaluate
(
exValue
);
}
}
src/main/java/edu/kit/formal/interpreter/HistoryListener.java
View file @
985b0a8b
...
...
@@ -4,6 +4,7 @@ import edu.kit.formal.proofscriptparser.DefaultASTVisitor;
import
edu.kit.formal.proofscriptparser.ast.ASTNode
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.Setter
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
src/main/java/edu/kit/formal/interpreter/InterpreterBuilder.java
View file @
985b0a8b
package
edu.kit.formal.interpreter
;
import
de.uka.ilkd.key.api.KeYApi
;
import
de.uka.ilkd.key.api.ProofApi
;
import
de.uka.ilkd.key.api.ProofManagementApi
;
import
de.uka.ilkd.key.control.KeYEnvironment
;
import
de.uka.ilkd.key.macros.ProofMacro
;
import
de.uka.ilkd.key.macros.scripts.ProofScriptCommand
;
import
de.uka.ilkd.key.proof.Proof
;
import
edu.kit.formal.ScopeLogger
;
import
edu.kit.formal.interpreter.funchdl.*
;
import
edu.kit.formal.proofscriptparser.Facade
;
import
edu.kit.formal.proofscriptparser.Visitor
;
import
edu.kit.formal.proofscriptparser.ast.ProofScript
;
import
lombok.Getter
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.List
;
/**
* @author Alexander Weigl
* @version 1 (21.05.17)
*/
public
class
InterpreterBuilder
{
private
ProofScriptHandler
psh
=
new
ProofScriptHandler
();
private
MacroCommandHandler
pmh
=
new
MacroCommandHandler
();
private
RuleCommandHandler
pmr
=
new
RuleCommandHandler
();
@Getter
private
final
ProofScriptHandler
psh
=
new
ProofScriptHandler
();
@Getter
private
final
MacroCommandHandler
pmh
=
new
MacroCommandHandler
();
@Getter
private
final
RuleCommandHandler
pmr
=
new
RuleCommandHandler
();
@Getter
private
ProofScriptCommandBuilder
pmc
=
new
ProofScriptCommandBuilder
();
public
Interpreter
build
(
File
file
)
throws
IOException
{
return
build
(
Facade
.
getAST
(
file
));
@Getter
private
ProofScript
entryPoint
;
@Getter
private
Proof
proof
;
@Getter
private
KeYEnvironment
keyEnvironment
;
@Getter
private
HistoryListener
historyLogger
;
@Getter
private
ScopeLogger
logger
;
@Getter
private
DefaultLookup
lookup
=
new
DefaultLookup
(
psh
,
pmh
,
pmr
,
pmc
);
private
Interpreter
interpreter
=
new
Interpreter
(
lookup
);
public
InterpreterBuilder
addProofScripts
(
File
file
)
throws
IOException
{
return
addProofScripts
(
Facade
.
getAST
(
file
));
}
p
rivate
Interpreter
b
uild
(
List
<
ProofScript
>
ast
)
{
p
ublic
Interpreter
B
uild
er
addProofScripts
(
List
<
ProofScript
>
ast
)
{
psh
.
addScripts
(
ast
);
DefaultLookup
lookup
=
new
DefaultLookup
(
psh
,
pmh
,
pmr
,
pmc
);
return
new
Interpreter
(
lookup
);
return
this
;
}
public
InterpreterBuilder
scriptSearchPath
(
File
...
paths
)
{
public
InterpreterBuilder
startWith
(
ProofScript
entryPoint
)
{
this
.
entryPoint
=
entryPoint
;
return
this
;
}
public
Interpreter
build
()
{
return
interpreter
;
}
public
InterpreterBuilder
keyRules
(
Proof
proof
)
{
public
InterpreterBuilder
scriptSearchPath
(
File
...
paths
)
{
psh
.
getSearchPath
().
addAll
(
Arrays
.
asList
(
paths
));
return
this
;
}
//TODO
public
InterpreterBuilder
proof
(
KeYEnvironment
env
,
Proof
proof
)
{
this
.
proof
=
proof
;
this
.
keyEnvironment
=
env
;
return
this
;
}
public
InterpreterBuilder
defaultScriptCommands
(
List
<
ProofScriptCommand
>
commands
)
{
public
InterpreterBuilder
scriptCommands
()
{
return
scriptCommands
(
KeYApi
.
getScriptCommandApi
().
getScriptCommands
());
}
public
InterpreterBuilder
scriptCommands
(
Collection
<
ProofScriptCommand
>
commands
)
{
commands
.
forEach
(
m
->
pmc
.
getCommands
().
put
(
m
.
getName
(),
m
));
return
this
;
}
public
InterpreterBuilder
defaultKeyMacros
(
List
<
ProofMacro
>
macros
)
{
public
InterpreterBuilder
macros
()
{
return
macros
(
KeYApi
.
getMacroApi
().
getMacros
());
}
public
InterpreterBuilder
macros
(
Collection
<
ProofMacro
>
macros
)
{
macros
.
forEach
(
m
->
pmh
.
getMacros
().
put
(
m
.
getName
(),
m
));
return
this
;
}
public
InterpreterBuilder
register
(
ProofScript
...
script
)
{
...
...
@@ -56,21 +103,27 @@ public class InterpreterBuilder {
}
public
InterpreterBuilder
onEntry
(
Visitor
v
)
{
interpreter
.
getEntryListeners
().
add
(
v
);
return
this
;
}
public
InterpreterBuilder
onExit
(
Visitor
v
)
{
interpreter
.
getExitListeners
().
add
(
v
);
return
this
;
}
public
InterpreterBuilder
captureHistory
()
{
return
this
;
if
(
historyLogger
!=
null
)
historyLogger
=
new
HistoryListener
(
interpreter
);
return
onEntry
(
historyLogger
);
}
public
InterpreterBuilder
log
(
String
prefix
)
{
return
this
;
if
(
logger
==
null
)
logger
=
new
ScopeLogger
(
"interpreter"
);
return
onEntry
(
logger
);
}
}
src/main/java/edu/kit/formal/interpreter/funchdl/MacroCommandHandler.java
View file @
985b0a8b
...
...
@@ -9,6 +9,7 @@ import edu.kit.formal.proofscriptparser.ast.CallStatement;
import
edu.kit.formal.proofscriptparser.ast.Parameters
;
import
edu.kit.formal.proofscriptparser.ast.StringLiteral
;
import
edu.kit.formal.proofscriptparser.ast.Variable
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
java.lang.reflect.Parameter
;
...
...
@@ -21,7 +22,7 @@ import java.util.Map;
*/
@RequiredArgsConstructor
public
class
MacroCommandHandler
implements
CommandHandler
{
private
final
Map
<
String
,
ProofMacro
>
macros
;
@Getter
private
final
Map
<
String
,
ProofMacro
>
macros
;
public
MacroCommandHandler
()
{
macros
=
new
HashMap
<>();
...
...
src/main/java/edu/kit/formal/interpreter/funchdl/ProofScriptCommandBuilder.java
View file @
985b0a8b
package
edu.kit.formal.interpreter.funchdl
;
import
de.uka.ilkd.key.api.ProofScriptCommandCall
;
import
de.uka.ilkd.key.macros.scripts.EngineState
;
import
de.uka.ilkd.key.macros.scripts.ProofScriptCommand
;
import
edu.kit.formal.interpreter.Interpreter
;
import
edu.kit.formal.interpreter.VariableAssignment
;
import
edu.kit.formal.proofscriptparser.ast.CallStatement
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
java.util.HashMap
;
...
...
@@ -17,7 +17,8 @@ import java.util.Map;
*/
@RequiredArgsConstructor
public
class
ProofScriptCommandBuilder
implements
CommandHandler
{
private
final
Map
<
String
,
ProofScriptCommand
>
scripts
;
@Getter
private
final
Map
<
String
,
ProofScriptCommand
>
commands
;
public
ProofScriptCommandBuilder
()
{
this
(
new
HashMap
<>());
...
...
@@ -25,14 +26,14 @@ public class ProofScriptCommandBuilder implements CommandHandler {
@Override
public
boolean
handles
(
CallStatement
call
)
{
return
script
s
.
containsKey
(
call
.
getCommand
());
return
command
s
.
containsKey
(
call
.
getCommand
());
}
@Override
public
void
evaluate
(
Interpreter
interpreter
,
CallStatement
call
,
VariableAssignment
params
)
{
ProofScriptCommand
c
=
script
s
.
get
(
call
.
getCommand
());
ProofScriptCommand
c
=
command
s
.
get
(
call
.
getCommand
());
EngineState
state
=
null
;
Map
<
String
,
String
>
map
;
//ProofScriptCommandCall cc = c.evaluateArguments(state, map);
...
...
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