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
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>key-project-psdbg</groupId>
<artifactId>key.util</artifactId>
<version>2.7-SNAPSHOT</version>
<description>POM was created from install:install-file</description>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
<groupId>key-project-psdbg</groupId>
<artifactId>key.util</artifactId>
<version>2.7-SNAPSHOT</version>
<versioning>
<snapshot>
<localCopy>true</localCopy>
</snapshot>
<lastUpdated>20170912105158</lastUpdated>
<snapshotVersions>
<snapshotVersion>
<extension>jar</extension>
<value>2.7-SNAPSHOT</value>
<updated>20170912105158</updated>
</snapshotVersion>
<snapshotVersion>
<extension>pom</extension>
<value>2.7-SNAPSHOT</value>
<updated>20170912103027</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>
</metadata>
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>key-project-psdbg</groupId>
<artifactId>key.util</artifactId>
<versioning>
<versions>
<version>2.7-SNAPSHOT</version>
</versions>
<lastUpdated>20170912105158</lastUpdated>
</versioning>
</metadata>
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>key-project-psdbg</groupId>
<artifactId>recoder</artifactId>
<version>2.7</version>
<description>POM was created from install:install-file</description>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>key-project-psdbg</groupId>
<artifactId>recoder</artifactId>
<versioning>
<release>2.7</release>
<versions>
<version>2.7</version>
</versions>
<lastUpdated>20170912105201</lastUpdated>
</versioning>
</metadata>
......@@ -116,12 +116,12 @@ casesStmt
casesList
: (TRY |
(CASE (expression
| (CLOSES INDENT closesScript=stmtList DEDENT) ) ) )
| (CLOSES INDENT closesGuard=stmtList DEDENT) ) ) )
COLON INDENT? body=stmtList DEDENT?
;
/*closesExpression
: CLOSES INDENT closesScript=stmtList DEDENT
: CLOSES INDENT closesGuard=stmtList DEDENT
;*/
forEachStmt
......
package edu.kit.iti.formal.psdbg;
import edu.kit.iti.formal.psdbg.parser.DefaultASTVisitor;
import edu.kit.iti.formal.psdbg.parser.Facade;
import edu.kit.iti.formal.psdbg.parser.ast.*;
/**
* Prints every command to a single line representation.
*
* @author Alexander Weigl
* @version 1
*/
public class ShortCommandPrinter extends DefaultASTVisitor<String> {
@Override
public String defaultVisit(ASTNode node) {
return (Facade.prettyPrint(node));
}
@Override
public String visit(Statements statements) {
return "{ ... " + statements.size() + " ... }";
}
@Override
public String visit(ProofScript proofScript) {
return String.format("script %s (%s) {%n",
proofScript.getName(),
Facade.prettyPrint(proofScript.getSignature()));
}
@Override
public String visit(CasesStatement casesStatement) {
return "cases {";
}
@Override
public String visit(GuardedCaseStatement caseStatement) {
return "case " + Facade.prettyPrint(caseStatement.getGuard());
}
@Override
public String visit(TryCase tryCase) {
return "try " + Facade.prettyPrint(tryCase.getBody());
}
@Override
public String visit(ClosesCase closesCase) {
return "closes with {" + Facade.prettyPrint(closesCase.getClosesGuard()) + "}";
}
@Override
public String visit(TheOnlyStatement theOnly) {
return "theonly {";
}
@Override
public String visit(ForeachStatement foreach) {
return "foreach {";
}
@Override
public String visit(RepeatStatement repeatStatement) {
return ("repeat {");
}
}
......@@ -118,15 +118,15 @@ public class ASTChanger extends DefaultASTVisitor<ASTNode> {
}
@Override
public SimpleCaseStatement visit(SimpleCaseStatement simpleCaseStatement) {
simpleCaseStatement.getGuard().accept(this);
simpleCaseStatement.getBody().accept(this);
return simpleCaseStatement;
public GuardedCaseStatement visit(GuardedCaseStatement guardedCaseStatement) {
guardedCaseStatement.getGuard().accept(this);
guardedCaseStatement.getBody().accept(this);
return guardedCaseStatement;
}
@Override
public ASTNode visit(ClosesCase closesCase) {
closesCase.getClosesScript().accept(this);
closesCase.getClosesGuard().accept(this);
closesCase.getBody().accept(this);
return closesCase;
}
......
package edu.kit.iti.formal.psdbg.parser;
import edu.kit.iti.formal.psdbg.parser.ast.*;
public class ASTDiff implements Visitor<ASTNode> {
private ASTNode other;
private ProofScript newScript;
@Override
public ProofScript visit(ProofScript proofScript) {
newScript = new ProofScript();
newScript.setName(proofScript.getName());
newScript.setSignature(proofScript.getSignature());
other = ((ProofScript) other).getBody();
newScript.setBody(visit(newScript.getBody()));
return newScript;
}
@Override
public ASTNode visit(AssignmentStatement assign) {
return null;
}
@Override
public ASTNode visit(BinaryExpression e) {
return null;
}
@Override
public ASTNode visit(MatchExpression match) {
return null;
}
@Override
public ASTNode visit(TermLiteral term) {
return null;
}
@Override
public ASTNode visit(StringLiteral string) {
return null;
}
@Override
public ASTNode visit(Variable variable) {
return null;
}
@Override
public ASTNode visit(BooleanLiteral bool) {
return null;
}
@Override
public Statements visit(Statements statements) {
Statements s = new Statements();
Statements other = (Statements) this.other;
assert statements.size() <= other.size();
int i = 0;
for (; i < statements.size(); i++) {
if (statements.get(i).eq(other.get(i))) {
break;
}
}
for (int j = i; j < other.size(); j++) {
s.add(other.get(i));
}
return s;
}
@Override
public ASTNode visit(IntegerLiteral integer) {
return null;
}
@Override
public ASTNode visit(CasesStatement cases) {
return null;
}
@Override
public ASTNode visit(DefaultCaseStatement defCase) {
return null;
}
@Override
public ASTNode visit(CallStatement call) {
return null;
}
@Override
public ASTNode visit(TheOnlyStatement theOnly) {
return null;
}
@Override
public ASTNode visit(ForeachStatement foreach) {
return null;
}
@Override
public ASTNode visit(RepeatStatement repeat) {
return null;
}
@Override
public ASTNode visit(Signature signature) {
return null;
}
@Override
public ASTNode visit(Parameters parameters) {
return null;
}
@Override
public ASTNode visit(UnaryExpression e) {
return null;
}
@Override
public ASTNode visit(TryCase TryCase) {
return null;
}
@Override
public ASTNode visit(GuardedCaseStatement guardedCaseStatement) {
return null;
}
@Override
public ASTNode visit(CaseStatement caseStatement) {
return null;
}
@Override
public ASTNode visit(SubstituteExpression subst) {
return null;
}
@Override
public ASTNode visit(ClosesCase closesCase) {
return null;
}
public ProofScript diff(ProofScript old, ProofScript rev) {
other = rev;
return (ProofScript) visit(old);
}
}
......@@ -167,9 +167,9 @@ public interface ASTTraversal<T> extends Visitor<T> {
}
@Override
default T visit(SimpleCaseStatement simpleCaseStatement) {
simpleCaseStatement.getGuard().accept(this);
simpleCaseStatement.getBody().accept(this);
default T visit(GuardedCaseStatement guardedCaseStatement) {
guardedCaseStatement.getGuard().accept(this);
guardedCaseStatement.getBody().accept(this);
return null;
}
......@@ -184,7 +184,7 @@ public interface ASTTraversal<T> extends Visitor<T> {
@Override
default T visit(ClosesCase closesCase) {
closesCase.getClosesScript().accept(this);
closesCase.getClosesGuard().accept(this);
closesCase.getBody().accept(this);
return null;
}
......
......@@ -143,8 +143,8 @@ public class DefaultASTVisitor<T> implements Visitor<T> {
}
@Override
public T visit(SimpleCaseStatement simpleCaseStatement) {
return defaultVisit(simpleCaseStatement);
public T visit(GuardedCaseStatement guardedCaseStatement) {
return defaultVisit(guardedCaseStatement);
}
@Override
......
......@@ -24,7 +24,9 @@ package edu.kit.iti.formal.psdbg.parser;
import edu.kit.iti.formal.psdbg.parser.ast.ASTNode;
import edu.kit.iti.formal.psdbg.parser.ast.Expression;
import edu.kit.iti.formal.psdbg.parser.ast.ProofScript;
import lombok.val;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
......@@ -33,7 +35,6 @@ import org.antlr.v4.runtime.ParserRuleContext;
import java.io.File;
import java.io.IOException;
import java.util.List;
import edu.kit.iti.formal.psdbg.parser.ast.*;
/**
* This class captures high-level functions of this package.
......@@ -104,4 +105,9 @@ public abstract class Facade {
node.accept(prettyPrinter);
return prettyPrinter.toString();
}
public static Expression parseExpression(String condition) {
val ctx = getParser(CharStreams.fromString(condition)).expression();
return (Expression) ctx.accept(new TransformAst());
}
}
......@@ -41,12 +41,15 @@ import java.util.Map;
public class PrettyPrinter extends DefaultASTVisitor<Void> {
private final StringBuilder s = new StringBuilder();
@Getter
@Setter
private int maxWidth = 80;
@Getter
@Setter
private boolean unicode = true;
private int indentation = 0;
@Override
......@@ -175,7 +178,7 @@ public class PrettyPrinter extends DefaultASTVisitor<Void> {
}
@Override
public Void visit(SimpleCaseStatement caseStatement) {
public Void visit(GuardedCaseStatement caseStatement) {
s.append("case ");
caseStatement.getGuard().accept(this);
s.append(" {");
......@@ -187,8 +190,11 @@ public class PrettyPrinter extends DefaultASTVisitor<Void> {
@Override
public Void visit(CallStatement call) {
s.append(call.getCommand()).append(' ');
call.getParameters().accept(this);
s.append(call.getCommand());
if (call.getParameters().size() != 0) {
s.append(' ');
call.getParameters().accept(this);
}
s.append(";");
return null;
}
......
......@@ -25,6 +25,7 @@ package edu.kit.iti.formal.psdbg.parser;
import edu.kit.iti.formal.psdbg.parser.ast.*;
import edu.kit.iti.formal.psdbg.parser.types.TypeFacade;
import lombok.Getter;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.ParseTree;
......@@ -38,19 +39,17 @@ import java.util.Map;
/**
* @author Alexander Weigl
* @version 1 (27.04.17)
* @version 2 (29.10.17), introduction of parent
* version 1 (27.04.17)
*/
public class TransformAst implements ScriptLanguageVisitor<Object> {
/**
* Start Index for positional arguments for command calls
* Start index for positional arguments for command calls
*/
public static final int KEY_START_INDEX_PARAMETER = 2;
private List<ProofScript> scripts = new ArrayList<>(10);
public List<ProofScript> getScripts() {
return scripts;
}
@Getter
private final List<ProofScript> scripts = new ArrayList<>(10);
@Override
public List<ProofScript> visitStart(ScriptLanguageParser.StartContext ctx) {
......@@ -64,8 +63,11 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
ProofScript s = new ProofScript();
s.setName(ctx.name.getText());
s.setRuleContext(ctx);
if (ctx.signature != null)
s.setSignature((Signature) ctx.signature.accept(this));
if (ctx.signature != null) {
final Signature sig = (Signature) ctx.signature.accept(this);
sig.setParent(s);
s.setSignature(sig);
}
s.setBody((Statements) ctx.body.accept(this));
return s;
}
......@@ -74,8 +76,9 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
public Signature visitArgList(ScriptLanguageParser.ArgListContext ctx) {
Signature signature = new Signature();
for (ScriptLanguageParser.VarDeclContext decl : ctx.varDecl()) {
signature.put(new Variable(decl.name),
TypeFacade.findType(decl.type.getText()));
Variable key = new Variable(decl.name);
key.setParent(signature);
signature.put(key, TypeFacade.findType(decl.type.getText()));
}
signature.setRuleContext(ctx);
return signature;
......@@ -100,7 +103,9 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
public Statements visitStmtList(ScriptLanguageParser.StmtListContext ctx) {
Statements statements = new Statements();
for (ScriptLanguageParser.StatementContext stmt : ctx.statement()) {
statements.add((Statement<ParserRuleContext>) stmt.accept(this));
Statement<ParserRuleContext> statement = (Statement<ParserRuleContext>) stmt.accept(this);
statement.setParent(statements);
statements.add(statement);
}
return statements;
}
......@@ -115,12 +120,16 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
public Object visitAssignment(ScriptLanguageParser.AssignmentContext ctx) {
AssignmentStatement assign = new AssignmentStatement();
assign.setRuleContext(ctx);
assign.setLhs(new Variable(ctx.variable));
Variable lhs = new Variable(ctx.variable);
lhs.setParent(assign);
assign.setLhs(lhs);
if (ctx.type != null) {
assign.setType(TypeFacade.findType(ctx.type.getText()));
}
if (ctx.expression() != null) {
assign.setRhs((Expression<ParserRuleContext>) ctx.expression().accept(this));
Expression<ParserRuleContext> rhs = (Expression<ParserRuleContext>) ctx.expression().accept(this);
rhs.setParent(assign);
assign.setRhs(rhs);
}
return assign;
}
......@@ -132,10 +141,11 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
private BinaryExpression createBinaryExpression(ParserRuleContext ctx,
List<ScriptLanguageParser.ExpressionContext> expression, Operator op) {
BinaryExpression be = new BinaryExpression();
be.setLeft((Expression<ParserRuleContext>) expression.get(0).accept(this));
be.setRight((Expression<ParserRuleContext>) expression.get(1).accept(this));
be.setOperator(op);
Expression<ParserRuleContext> left = (Expression<ParserRuleContext>) expression.get(0).accept(this);
Expression<ParserRuleContext> right = (Expression<ParserRuleContext>) expression.get(1).accept(this);
BinaryExpression be = new BinaryExpression(left, op, right);
left.setParent(be);
right.setParent(be);
return be;
}
......@@ -152,7 +162,9 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
private UnaryExpression createUnaryExpression(ParserRuleContext ctx, ScriptLanguageParser.ExpressionContext expression, Operator op) {
UnaryExpression ue = new UnaryExpression();
ue.setRuleContext(ctx);
ue.setExpression((Expression<ParserRuleContext>) expression.accept(this));
Expression<ParserRuleContext> expr = (Expression<ParserRuleContext>) expression.accept(this);
expr.setParent(ue);
ue.setExpression(expr);
ue.setOperator(op);
return ue;
}
......@@ -223,18 +235,18 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
@Override
public Object visitExprSubst(ScriptLanguageParser.ExprSubstContext ctx) {
SubstituteExpression se = new SubstituteExpression();
se.setSub((Expression) ctx.expression().accept(this));
se.setSubstitution(
(Map<String, Expression>) ctx.substExpressionList().accept(this));
Expression expr = (Expression) ctx.expression().accept(this);
Map<String, Expression> subs = (Map<String, Expression>) ctx.substExpressionList().accept(this);
subs.values().forEach(e -> e.setParent(se));
se.setSubstitution(subs);
se.setSub(expr);
expr.setParent(se);
return se;
}
//TODO implement
@Override
public Object visitExprDivision(ScriptLanguageParser.ExprDivisionContext ctx) {
return createBinaryExpression(ctx, ctx.expression(), Operator.DIVISION);
}
@Override
......@@ -284,13 +296,19 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
if (ctx.derivable != null) {
match.setDerivable(true);
match.setDerivableTerm((Expression<ParserRuleContext>) ctx.derivableExpression.accept(this));
Expression<ParserRuleContext> e = (Expression<ParserRuleContext>) ctx.derivableExpression.accept(this);
e.setParent(match);
match.setDerivableTerm(e);