Commit 8feff6db authored by Sarah Grebing's avatar Sarah Grebing

adderd flag for matchexpreesion

parent 985b0a8b
Pipeline #10677 passed with stage
in 2 minutes and 15 seconds
...@@ -97,41 +97,6 @@ ...@@ -97,41 +97,6 @@
<visitor>true</visitor> <visitor>true</visitor>
</configuration> </configuration>
</plugin> </plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>keyinstall</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.key-project</groupId>
<artifactId>key.core</artifactId>
<version>2.7</version>
<packaging>jar</packaging>
<file>${basedir}/lib/key.core.jar</file>
</configuration>
</execution>
<execution>
<id>recoderinstall</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.key-project</groupId>
<artifactId>recoderKey</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<file>${basedir}/lib/recoderKey.jar</file>
</configuration>
</execution>
</executions>
</plugin>-->
</plugins> </plugins>
</build> </build>
......
...@@ -4,11 +4,17 @@ import edu.kit.formal.interpreter.*; ...@@ -4,11 +4,17 @@ import edu.kit.formal.interpreter.*;
import edu.kit.formal.interpreter.funchdl.BuiltinCommands; import edu.kit.formal.interpreter.funchdl.BuiltinCommands;
import edu.kit.formal.interpreter.funchdl.CommandHandler; import edu.kit.formal.interpreter.funchdl.CommandHandler;
import edu.kit.formal.interpreter.funchdl.DefaultLookup; import edu.kit.formal.interpreter.funchdl.DefaultLookup;
import edu.kit.formal.proofscriptparser.*; import edu.kit.formal.proofscriptparser.DefaultASTVisitor;
import edu.kit.formal.proofscriptparser.Facade;
import edu.kit.formal.proofscriptparser.ScriptLanguageParser;
import edu.kit.formal.proofscriptparser.TransformAst;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CharStreams;
import java.io.*; import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.List; import java.util.List;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
...@@ -36,7 +42,6 @@ public class Debugger { ...@@ -36,7 +42,6 @@ public class Debugger {
interpreter.getEntryListeners().add(history); interpreter.getEntryListeners().add(history);
interpreter.getEntryListeners().add(blocker); interpreter.getEntryListeners().add(blocker);
interpreter.getEntryListeners().add(new CommandLogger()); interpreter.getEntryListeners().add(new CommandLogger());
//TODO install debugger functions
registerDebuggerFunction("step", this::step); registerDebuggerFunction("step", this::step);
registerDebuggerFunction("b", this::setBreakpoint); registerDebuggerFunction("b", this::setBreakpoint);
...@@ -47,6 +52,11 @@ public class Debugger { ...@@ -47,6 +52,11 @@ public class Debugger {
registerDebuggerFunction("status", this::status); registerDebuggerFunction("status", this::status);
} }
public static void main(String[] args) throws IOException {
Debugger d = new Debugger("src/test/resources/edu/kit/formal/interpreter/dbg.kps");
d.run();
}
private void registerDebuggerFunction(final String step, private void registerDebuggerFunction(final String step,
BiConsumer<CallStatement, VariableAssignment> func) { BiConsumer<CallStatement, VariableAssignment> func) {
debuggerFunctions.getBuilders().add(new CommandHandler() { debuggerFunctions.getBuilders().add(new CommandHandler() {
...@@ -62,11 +72,6 @@ public class Debugger { ...@@ -62,11 +72,6 @@ public class Debugger {
}); });
} }
public static void main(String[] args) throws IOException {
Debugger d = new Debugger("src/test/resources/edu/kit/formal/interpreter/dbg.kps");
d.run();
}
private void run() throws IOException { private void run() throws IOException {
blocker.stepUntilBlock.set(2); blocker.stepUntilBlock.set(2);
interpreterThread = new Thread(() -> { interpreterThread = new Thread(() -> {
......
...@@ -7,7 +7,6 @@ import lombok.Getter; ...@@ -7,7 +7,6 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
...@@ -17,19 +16,16 @@ import java.util.List; ...@@ -17,19 +16,16 @@ import java.util.List;
* @author A. Weigl * @author A. Weigl
*/ */
public class Evaluator extends DefaultASTVisitor<Value> implements ScopeObservable { public class Evaluator extends DefaultASTVisitor<Value> implements ScopeObservable {
private final GoalNode goal;
private final VariableAssignment state;
private List<VariableAssignment> matchedVariables = new ArrayList<>(); private List<VariableAssignment> matchedVariables = new ArrayList<>();
@Getter @Getter
@Setter @Setter
private MatcherApi matcher; private MatcherApi matcher;
@Getter @Getter
private List<Visitor> entryListeners = new ArrayList<>(), private List<Visitor> entryListeners = new ArrayList<>(),
exitListeners = new ArrayList<>(); exitListeners = new ArrayList<>();
private final GoalNode goal;
private final VariableAssignment state;
public Evaluator(VariableAssignment assignment, GoalNode node) { public Evaluator(VariableAssignment assignment, GoalNode node) {
state = new VariableAssignment(assignment); // unmodifiable version of assignment state = new VariableAssignment(assignment); // unmodifiable version of assignment
goal = node; goal = node;
...@@ -122,4 +118,7 @@ public class Evaluator extends DefaultASTVisitor<Value> implements ScopeObservab ...@@ -122,4 +118,7 @@ public class Evaluator extends DefaultASTVisitor<Value> implements ScopeObservab
} }
public List<VariableAssignment> getMatchedVariables() {
return null;
}
} }
package edu.kit.formal.interpreter; package edu.kit.formal.interpreter;
import de.uka.ilkd.key.api.ProjectedNode;
import edu.kit.formal.proofscriptparser.ast.Type; import edu.kit.formal.proofscriptparser.ast.Type;
import lombok.Getter; import lombok.Getter;
...@@ -7,24 +8,40 @@ import lombok.Getter; ...@@ -7,24 +8,40 @@ import lombok.Getter;
* Objects of this class represent a GoalNode in a script state * Objects of this class represent a GoalNode in a script state
* If parent is null, this is the root * If parent is null, this is the root
* *
* This object wraps a ProjectedNode
* @author S.Grebing * @author S.Grebing
*/ */
public class GoalNode { public class GoalNode {
//TODO this is only for testing, later Sequent object or similar
@Getter @Getter
private String sequent; private String sequent; //TODO this is only for testing, when connected with key using projectednode
private VariableAssignment assignments; private VariableAssignment assignments;
private GoalNode parent; private GoalNode parent;
@Getter
private ProjectedNode actualKeYGoalNode;
/**
* This conctructur will be replaced with concrete one that uses projectedNode
*
* @param parent
* @param seq
*/
public GoalNode(GoalNode parent, String seq) { public GoalNode(GoalNode parent, String seq) {
//BUG: Hier muesste deepcopy der assignments passieren //BUG: Hier muesste deepcopy der assignments passieren
this.assignments = new VariableAssignment(parent == null ? null : parent.deepCopyAssignments()); this.assignments = new VariableAssignment(parent == null ? null : parent.deepCopyAssignments());
this.parent = parent; this.parent = parent;
this.sequent = seq; this.sequent = seq;
actualKeYGoalNode = null;
} }
public GoalNode(GoalNode parent, String seq, ProjectedNode pNode) {
this.actualKeYGoalNode = pNode;
this.assignments = new VariableAssignment(parent == null ? null : parent.deepCopyAssignments());
this.parent = parent;
this.sequent = seq;
}
private VariableAssignment deepCopyAssignments() { private VariableAssignment deepCopyAssignments() {
return assignments.deepCopy(); return assignments.deepCopy();
} }
...@@ -119,4 +136,6 @@ public class GoalNode { ...@@ -119,4 +136,6 @@ public class GoalNode {
//TODO method does nothing helpful atm //TODO method does nothing helpful atm
return new GoalNode(this.getParent(), sequent); return new GoalNode(this.getParent(), sequent);
} }
} }
...@@ -4,7 +4,6 @@ import edu.kit.formal.proofscriptparser.DefaultASTVisitor; ...@@ -4,7 +4,6 @@ import edu.kit.formal.proofscriptparser.DefaultASTVisitor;
import edu.kit.formal.proofscriptparser.ast.ASTNode; import edu.kit.formal.proofscriptparser.ast.ASTNode;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Setter;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
...@@ -28,4 +27,6 @@ public class HistoryListener extends DefaultASTVisitor<Void> { ...@@ -28,4 +27,6 @@ public class HistoryListener extends DefaultASTVisitor<Void> {
queueNode.add(node); queueNode.add(node);
return null; return null;
} }
} }
...@@ -3,7 +3,10 @@ package edu.kit.formal.interpreter; ...@@ -3,7 +3,10 @@ package edu.kit.formal.interpreter;
import edu.kit.formal.proofscriptparser.ast.Type; import edu.kit.formal.proofscriptparser.ast.Type;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/** /**
* Variable Assignments for each goal node * Variable Assignments for each goal node
...@@ -142,4 +145,44 @@ public class VariableAssignment { ...@@ -142,4 +145,44 @@ public class VariableAssignment {
public Map<String, Value> asMap() { public Map<String, Value> asMap() {
return asMap(new HashMap<>()); return asMap(new HashMap<>());
} }
/**
* Method joins two variable assignments without checking their compatibility
*
* @param assignment
* @return
*/
public VariableAssignment joinWithoutCheck(VariableAssignment assignment) {
this.getValues().putAll(assignment.getValues());
this.getTypes().putAll(assignment.getTypes());
return this;
}
/**
* @param assignment
* @return empty variable assignment if not possible to join conflictfree (i.e., if a variable name is present in both assignments with different types or dfferent values)
* @throws RuntimeException
*/
public VariableAssignment joinWithCheck(VariableAssignment assignment) throws RuntimeException {
Set<String> namesV2 = assignment.getValues().keySet();
Set<String> nonConflicting = new HashSet<>();
Set<String> conflictingCand = new HashSet<>();
//subtract V2 from V1 and add the nonconflicting varNames into the nonconflicting set
nonConflicting = this.getValues().keySet().stream().filter(item -> !namesV2.contains(item)).collect(Collectors.toSet());
//subtract V1 from V2 and add the nonconflicting varNames into the nonconflicting set
nonConflicting.addAll(namesV2.stream().filter(item -> !this.getValues().keySet().contains(item)).collect(Collectors.toSet()));
//create intersection
conflictingCand = this.getValues().keySet().stream().filter(item -> namesV2.contains(item)).collect(Collectors.toSet());
if (!conflictingCand.isEmpty()) {
for (String s : conflictingCand) {
if (!this.lookupVarValue(s).equals(assignment.lookupVarValue(s))) {
return new VariableAssignment(null);
}
}
}
return this.joinWithoutCheck(assignment);
}
} }
...@@ -75,6 +75,11 @@ public class BinaryExpression extends Expression<ParserRuleContext> { ...@@ -75,6 +75,11 @@ public class BinaryExpression extends Expression<ParserRuleContext> {
return operator.returnType(); return operator.returnType();
} }
@Override
public boolean hasMatchExpression() {
return left.hasMatchExpression() || right.hasMatchExpression();
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -65,6 +65,11 @@ public class BooleanLiteral extends Literal { ...@@ -65,6 +65,11 @@ public class BooleanLiteral extends Literal {
return visitor.visit(this); return visitor.visit(this);
} }
@Override
public boolean hasMatchExpression() {
return false;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -34,6 +34,24 @@ import org.antlr.v4.runtime.ParserRuleContext; ...@@ -34,6 +34,24 @@ import org.antlr.v4.runtime.ParserRuleContext;
* @version 1 (28.04.17) * @version 1 (28.04.17)
*/ */
public abstract class Expression<T extends ParserRuleContext> extends ASTNode<T> { public abstract class Expression<T extends ParserRuleContext> extends ASTNode<T> {
/**
* @param type
* @param e
* @param signature
* @throws NotWelldefinedException
*/
public static final void checkType(Type type, Expression e, Signature signature) throws NotWelldefinedException {
Type got = e.getType(signature);
if (!type.equals(got)) {
throw new NotWelldefinedException("Typemismatch in expected " + type + ", got" + got, e);
}
}
/**
* @return returns true if a child expression contains a match expression
*/
public abstract boolean hasMatchExpression();
/** /**
* Returns the precedence of the operator expression. * Returns the precedence of the operator expression.
* <p> * <p>
...@@ -54,17 +72,4 @@ public abstract class Expression<T extends ParserRuleContext> extends ASTNode<T> ...@@ -54,17 +72,4 @@ public abstract class Expression<T extends ParserRuleContext> extends ASTNode<T>
*/ */
public abstract Type getType(Signature signature) public abstract Type getType(Signature signature)
throws NotWelldefinedException; throws NotWelldefinedException;
/**
* @param type
* @param e
* @param signature
* @throws NotWelldefinedException
*/
public static final void checkType(Type type, Expression e, Signature signature) throws NotWelldefinedException {
Type got = e.getType(signature);
if (!type.equals(got)) {
throw new NotWelldefinedException("Typemismatch in expected " + type + ", got" + got, e);
}
}
} }
...@@ -59,6 +59,11 @@ public class IntegerLiteral extends Literal { ...@@ -59,6 +59,11 @@ public class IntegerLiteral extends Literal {
return visitor.visit(this); return visitor.visit(this);
} }
@Override
public boolean hasMatchExpression() {
return false;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -76,6 +76,11 @@ public class MatchExpression extends Expression<ScriptLanguageParser.MatchPatter ...@@ -76,6 +76,11 @@ public class MatchExpression extends Expression<ScriptLanguageParser.MatchPatter
return Type.BOOL; return Type.BOOL;
} }
@Override
public boolean hasMatchExpression() {
return true;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -51,6 +51,11 @@ public class StringLiteral extends Literal { ...@@ -51,6 +51,11 @@ public class StringLiteral extends Literal {
return visitor.visit(this); return visitor.visit(this);
} }
@Override
public boolean hasMatchExpression() {
return false;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -52,6 +52,11 @@ public class TermLiteral extends Literal { ...@@ -52,6 +52,11 @@ public class TermLiteral extends Literal {
return visitor.visit(this); return visitor.visit(this);
} }
@Override
public boolean hasMatchExpression() {
return false;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -74,6 +74,11 @@ public class UnaryExpression extends Expression<ParserRuleContext> { ...@@ -74,6 +74,11 @@ public class UnaryExpression extends Expression<ParserRuleContext> {
return operator.returnType(); return operator.returnType();
} }
@Override
public boolean hasMatchExpression() {
return expression.hasMatchExpression();
}
/** /**
* {@inheritDoc * {@inheritDoc
*/ */
......
...@@ -52,6 +52,11 @@ public class Variable extends Literal { ...@@ -52,6 +52,11 @@ public class Variable extends Literal {
return visitor.visit(this); return visitor.visit(this);
} }
@Override
public boolean hasMatchExpression() {
return false;
}
@Override @Override
public Variable copy() { public Variable copy() {
Variable v = new Variable(identifier); Variable v = new Variable(identifier);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment