Commit 6ddf4f97 authored by Alexander Weigl's avatar Alexander Weigl 🐼
Browse files

Merge branch 'weigl-sync' into 'master'

Everything new! Everything Better Now!!

See merge request !4
parents e6361f70 4ed3bd10
Pipeline #15115 passed with stages
in 6 minutes and 42 seconds
......@@ -34,7 +34,8 @@ import lombok.*;
* @author Alexander Weigl
* @version 1 (28.04.17)
*/
@Data
@Getter
@Setter
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
......@@ -63,6 +64,20 @@ public class CallStatement extends Statement<ScriptLanguageParser.ScriptCommandC
*/
@Override
public CallStatement copy() {
return new CallStatement(command, parameters.copy());
CallStatement s = new CallStatement(command, parameters.copy());
s.setRuleContext(this.getRuleContext());
return s;
}
@Override
public boolean eq(ASTNode o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
CallStatement that = (CallStatement) o;
if (!getCommand().equals(that.getCommand())) return false;
return getParameters().equals(that.getParameters());
}
}
......@@ -23,22 +23,22 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
/**
* @author Alexander Weigl
* @version 1 (28.04.17)
*/
@Data
@NoArgsConstructor
@Getter
@Setter
@RequiredArgsConstructor
@AllArgsConstructor
public class CaseStatement extends Statement<ScriptLanguageParser.CasesListContext> {
public boolean isClosedStmt;
public abstract class CaseStatement extends Statement<ScriptLanguageParser.CasesListContext> {
protected Statements body;
/**
......@@ -51,7 +51,17 @@ public class CaseStatement extends Statement<ScriptLanguageParser.CasesListConte
/**
* {@inheritDoc}
*/
@Override public CaseStatement copy() {
return new CaseStatement(isClosedStmt, body.copy());
@Override public abstract CaseStatement copy();
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
CaseStatement that = (CaseStatement) o;
return getBody().eq(that.getBody());
}
}
......@@ -23,11 +23,12 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.Data;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
......@@ -36,7 +37,9 @@ import java.util.List;
* @author Alexander Weigl
* @version 1 (28.04.17)
*/
@Data
@Setter
@Getter
@RequiredArgsConstructor
public class CasesStatement extends Statement<ScriptLanguageParser.CasesStmtContext> {
@NonNull private final List<CaseStatement> cases = new ArrayList<>();
// @NonNull private Statements defaultCase = new Statements();
......@@ -60,6 +63,24 @@ public class CasesStatement extends Statement<ScriptLanguageParser.CasesStmtCont
// c.defaultCase = defaultCase.copy();
if (defCaseStmt != null)
c.defCaseStmt = defCaseStmt.copy();
c.setRuleContext(this.ruleContext);
return c;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
CasesStatement that = (CasesStatement) o;
for (int i = 0; i < cases.size(); i++) {
if(!cases.get(i).eq(that.cases.get(i)))
return false;
}
return getDefCaseStmt() != null ? getDefCaseStmt().eq(that.getDefCaseStmt()) : that.getDefCaseStmt() == null;
}
}
......@@ -10,23 +10,20 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class ClosesCase extends CaseStatement {
private boolean isClosedStmt = true;
/**
* Script that should be executed and shown whether case can be closed
*/
private Statements closesScript;
private Statements closesGuard;
/**
* A close subscript() {bodyscript} expression
*
* @param closesScript the script that is exectued in order to determine whether goal would clos. This proof is pruned afterwards
* @param closesGuard the script that is exectued in order to determine whether goal would clos. This proof is pruned afterwards
* @param body the actual script that is then executed when closesscript was successful and pruned
*/
public ClosesCase(Statements closesScript, Statements body) {
public ClosesCase(Statements closesGuard, Statements body) {
this.body = body;
this.closesScript = closesScript;
this.closesGuard = closesGuard;
}
/**
......@@ -42,7 +39,20 @@ public class ClosesCase extends CaseStatement {
*/
@Override
public ClosesCase copy() {
return new ClosesCase(closesScript.copy(), body.copy());
ClosesCase cs = new ClosesCase(closesGuard.copy(), body.copy());
cs.setRuleContext(this.ruleContext);
return cs;
}
@Override
public boolean eq(ASTNode o) {
if (this == o) return true;
if (!(o instanceof ClosesCase)) return false;
if (!super.equals(o)) return false;
ClosesCase that = (ClosesCase) o;
return getClosesGuard() != null ? getClosesGuard().eq(that.getClosesGuard()) : that.getClosesGuard() == null;
}
}
......@@ -2,9 +2,11 @@ package edu.kit.iti.formal.psdbg.parser.ast;
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data
@Getter
@Setter
public class DefaultCaseStatement extends Statement<ScriptLanguageParser.StmtListContext> {
protected Statements body;
......@@ -31,7 +33,27 @@ public class DefaultCaseStatement extends Statement<ScriptLanguageParser.StmtLis
*/
@Override
public DefaultCaseStatement copy() {
return new DefaultCaseStatement(body.copy());
DefaultCaseStatement dcs = new DefaultCaseStatement(body.copy());
dcs.setRuleContext(this.ruleContext);
return dcs;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
DefaultCaseStatement that = (DefaultCaseStatement) o;
return getBody().eq(that.getBody());
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + getBody().hashCode();
return result;
}
}
......
......@@ -23,16 +23,17 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
/**
* @author Alexander Weigl
* @version 1 (29.04.17)
*/
@Data
@Getter
@Setter
public class ForeachStatement extends GoalSelector<ScriptLanguageParser.ForEachStmtContext> {
public ForeachStatement() {
}
......@@ -52,6 +53,8 @@ public class ForeachStatement extends GoalSelector<ScriptLanguageParser.ForEachS
* {@inheritDoc}
*/
@Override public ForeachStatement copy() {
return new ForeachStatement(getBody().copy());
ForeachStatement fs = new ForeachStatement(getBody().copy());
fs.setRuleContext(this.ruleContext);
return fs;
}
}
......@@ -31,7 +31,25 @@ import org.antlr.v4.runtime.ParserRuleContext;
* @author Alexander Weigl
* @version 1 (29.04.17)
*/
@Data @AllArgsConstructor @NoArgsConstructor public abstract class GoalSelector<T extends ParserRuleContext>
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public abstract class GoalSelector<T extends ParserRuleContext>
extends Statement<T> {
@Getter
@Setter
@NonNull private Statements body = new Statements();
@Override
public boolean eq(ASTNode o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
GoalSelector<?> that = (GoalSelector<?>) o;
return getBody() != null ? getBody().eq(that.getBody()) : that.getBody() == null;
}
}
......@@ -11,11 +11,10 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SimpleCaseStatement extends CaseStatement {
public class GuardedCaseStatement extends CaseStatement {
private Expression guard;
private boolean isClosedStmt = false;
public SimpleCaseStatement(Expression guard, Statements body) {
public GuardedCaseStatement(Expression guard, Statements body) {
this.guard = guard;
this.body = body;
}
......@@ -32,9 +31,21 @@ public class SimpleCaseStatement extends CaseStatement {
* {@inheritDoc}
*/
@Override
public SimpleCaseStatement copy() {
return new SimpleCaseStatement(guard.copy(), body.copy());
public GuardedCaseStatement copy() {
GuardedCaseStatement scs = new GuardedCaseStatement(guard.copy(), body.copy());
scs.setRuleContext(this.ruleContext);
return scs;
}
@Override
public boolean eq(ASTNode o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
GuardedCaseStatement that = (GuardedCaseStatement) o;
return getGuard().eq(that.getGuard());
}
}
......@@ -67,6 +67,7 @@ public class MatchExpression extends Expression<ScriptLanguageParser.MatchPatter
if (signature != null)
me.signature = signature.copy();
me.pattern = pattern.copy();
me.setRuleContext(this.ruleContext);
return me;
}
......
......@@ -23,7 +23,6 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.EqualsAndHashCode;
......@@ -46,13 +45,16 @@ import java.util.function.Function;
public class Parameters extends ASTNode<ScriptLanguageParser.ParametersContext> {
private final Map<Variable, Expression> parameters = new LinkedHashMap<>();
@Override public <T> T accept(Visitor<T> visitor) {
@Override
public <T> T accept(Visitor<T> visitor) {
return visitor.visit(this);
}
@Override public Parameters copy() {
@Override
public Parameters copy() {
Parameters p = new Parameters();
forEach((k, v) -> p.put(k.copy(), v.copy()));
p.setRuleContext(this.getRuleContext());
return p;
}
......@@ -137,18 +139,38 @@ public class Parameters extends ASTNode<ScriptLanguageParser.ParametersContext>
}
public Expression computeIfPresent(Variable key,
BiFunction<? super Variable, ? super Expression, ? extends Expression> remappingFunction) {
BiFunction<? super Variable, ? super Expression, ? extends Expression> remappingFunction) {
return parameters.computeIfPresent(key, remappingFunction);
}
public Expression compute(Variable key,
BiFunction<? super Variable, ? super Expression, ? extends Expression> remappingFunction) {
BiFunction<? super Variable, ? super Expression, ? extends Expression> remappingFunction) {
return parameters.compute(key, remappingFunction);
}
public Expression merge(Variable key, Expression value,
BiFunction<? super Expression, ? super Expression, ? extends Expression> remappingFunction) {
BiFunction<? super Expression, ? super Expression, ? extends Expression> remappingFunction) {
return parameters.merge(key, value, remappingFunction);
}
@Override
public boolean eq(ASTNode o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
Parameters that = (Parameters) o;
for (Map.Entry<Variable, Expression> e : that.parameters.entrySet()) {
if (!e.getValue().eq(get(e.getKey())))
return false;
}
for (Map.Entry<Variable, Expression> e : parameters.entrySet()) {
if (!e.getValue().eq(that.get(e.getKey())))
return false;
}
return true;
}
}
......@@ -54,8 +54,23 @@ public class ProofScript extends ASTNode<ScriptLanguageParser.ScriptContext> {
ps.setName(getName());
ps.setBody(body.copy());
ps.setSignature(signature.copy());
ps.setRuleContext(this.ruleContext);
return ps;
}
@Override
public boolean eq(ASTNode o) {
if (this == o) return true;
if (!(o instanceof ProofScript)) return false;
if (!super.equals(o)) return false;
ProofScript that = (ProofScript) o;
if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false;
if (getSignature() != null ? !getSignature().eq(that.getSignature()) : that.getSignature() != null)
return false;
return getBody() != null ? getBody().eq(that.getBody()) : that.getBody() == null;
}
}
......@@ -23,16 +23,17 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
/**
* @author Alexander Weigl
* @version 1 (29.04.17)
*/
@Data
@Getter
@Setter
public class RepeatStatement extends GoalSelector<ScriptLanguageParser.RepeatStmtContext> {
public RepeatStatement() {
}
......@@ -54,6 +55,10 @@ public class RepeatStatement extends GoalSelector<ScriptLanguageParser.RepeatStm
*/
@Override
public RepeatStatement copy() {
return new RepeatStatement(getBody().copy());
RepeatStatement rs = new RepeatStatement(getBody().copy());
rs.setRuleContext(this.ruleContext);
return rs;
}
}
......@@ -23,7 +23,6 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitor;
import edu.kit.iti.formal.psdbg.parser.types.Type;
......@@ -42,18 +41,21 @@ import java.util.function.Function;
* @author Alexander Weigl
* @version 1 (29.04.17)
*/
@EqualsAndHashCode(callSuper = false, of="sig")
@EqualsAndHashCode(callSuper = false, of = "sig")
@ToString
public class Signature extends ASTNode<ScriptLanguageParser.ArgListContext> implements Map<Variable, Type> {
private final Map<Variable, Type> sig = new LinkedHashMap<>();
@Override public <T> T accept(Visitor<T> visitor) {
@Override
public <T> T accept(Visitor<T> visitor) {
return visitor.visit(this);
}
@Override public Signature copy() {
@Override
public Signature copy() {
Signature signature = new Signature();
forEach((k, v) -> signature.put(k.copy(), v));
signature.setRuleContext(this.ruleContext);
return signature;
}
......@@ -143,17 +145,17 @@ public class Signature extends ASTNode<ScriptLanguageParser.ArgListContext> impl
}
public Type computeIfPresent(Variable key,
BiFunction<? super Variable, ? super Type, ? extends Type> remappingFunction) {
BiFunction<? super Variable, ? super Type, ? extends Type> remappingFunction) {
return sig.computeIfPresent(key, remappingFunction);
}
public Type compute(Variable key,
BiFunction<? super Variable, ? super Type, ? extends Type> remappingFunction) {
BiFunction<? super Variable, ? super Type, ? extends Type> remappingFunction) {
return sig.compute(key, remappingFunction);
}
public Type merge(Variable key, Type value,
BiFunction<? super Type, ? super Type, ? extends Type> remappingFunction) {
BiFunction<? super Type, ? super Type, ? extends Type> remappingFunction) {
return sig.merge(key, value, remappingFunction);
}
}
......@@ -23,11 +23,9 @@ package edu.kit.iti.formal.psdbg.parser.ast;
*/
import edu.kit.iti.formal.psdbg.parser.ScriptLanguageParser;
import edu.kit.iti.formal.psdbg.parser.Visitable;
import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.*;
......@@ -40,7 +38,6 @@ import java.util.stream.Stream;
* @author Alexander Weigl
* @version 1 (27.04.17)
*/
@EqualsAndHashCode
@ToString
public class Statements extends ASTNode<ScriptLanguageParser.StmtListContext>
implements Visitable, Iterable<Statement> {
......@@ -164,17 +161,39 @@ public class Statements extends ASTNode<ScriptLanguageParser.StmtListContext>
statements.forEach(action);
}
@Override public String toString() {
@Override
public String toString() {
return "Statements{" + "statements=" + statements + '}';
}
@Override public <T> T accept(Visitor<T> visitor) {
@Override
public <T> T accept(Visitor<T> visitor) {
return visitor.visit(this);
}
@Override public Statements copy() {
@Override
public Statements copy() {
Statements s = new Statements();
forEach(e -> s.add(e.copy()));
forEach(e -> {
Statement ecopy = e.copy();
ecopy.setRuleContext(e.getRuleContext());
s.add(ecopy);
});
s.setRuleContext(this.getRuleContext());
return s;
}
@Override
public boolean eq(ASTNode o) {
if (this == o) return true;
if (!(o instanceof Statements)) return false;
if (!super.equals(o)) return false;
Statements that = (Statements) o;
for (int i = 0; i < statements.size(); i++) {
if (!statements.get(i).eq(that.statements.get(i))) {
return false;
}
}
return true;
}
}
......@@ -39,6 +39,7 @@ public class SubstituteExpression extends Expression<ScriptLanguageParser.ExprSu
SubstituteExpression se<