Skip to content

Commit 0075289

Browse files
author
Steffen Märcker
committed
[DAG-copy] Implement DAG-aware vistitors
After certain replacements, e.g., formula substitution, the AST becomes a directed acyclic graph. Most often it is not required to visit a node of this DAG multiply times. The new class DAGVisitor keeps track of the nodes already seen and visits each node only once.
1 parent 753d5b3 commit 0075289

25 files changed

Lines changed: 627 additions & 147 deletions

prism/src/automata/LTL2RabinLibrary.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static DA<BitSet, AcceptanceRabin> getDRAforLTL(Expression ltl, Values co
132132
labels = new ArrayList<String>();
133133
ltl.accept(new ASTTraverse()
134134
{
135-
public Object visit(ExpressionLabel e) throws PrismLangException
135+
public Object visitNow(ExpressionLabel e) throws PrismLangException
136136
{
137137
labels.add(e.getName());
138138
return null;
@@ -144,7 +144,7 @@ public Object visit(ExpressionLabel e) throws PrismLangException
144144
Expression ltl2 = ltl.deepCopy();
145145
ltl2.accept(new ASTTraverseModify()
146146
{
147-
public Object visit(ExpressionLabel e) throws PrismLangException
147+
public Object visitNow(ExpressionLabel e) throws PrismLangException
148148
{
149149
int i = labels.indexOf(e.getName());
150150
//char letter = (char) ('a' + i);

prism/src/parser/BooleanUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,18 @@ private static Expression removeImpliesIffAndParentheses(Expression expr)
118118
try {
119119
exprMod = (Expression) expr.accept(new ASTTraverseModify()
120120
{
121-
public Object visit(ExpressionUnaryOp e) throws PrismLangException
121+
public Object visitNow(ExpressionUnaryOp e) throws PrismLangException
122122
{
123123
// Remove parentheses: (a)
124124
if (Expression.isParenth(e)) {
125125
Expression a = (Expression) (e.getOperand().accept(this));
126126
// (a) == a
127127
return a;
128128
}
129-
return super.visit(e);
129+
return super.visitNow(e);
130130
}
131131

132-
public Object visit(ExpressionBinaryOp e) throws PrismLangException
132+
public Object visitNow(ExpressionBinaryOp e) throws PrismLangException
133133
{
134134
// Remove implication: a => b
135135
if (Expression.isImplies(e)) {
@@ -145,7 +145,7 @@ public Object visit(ExpressionBinaryOp e) throws PrismLangException
145145
// a <=> b == (a | !b) & (!a | b)
146146
return Expression.And(Expression.Or(a, Expression.Not(b)), Expression.Or(Expression.Not(a.deepCopy()), b.deepCopy()));
147147
}
148-
return super.visit(e);
148+
return super.visitNow(e);
149149
}
150150
});
151151
} catch (PrismLangException e) {

prism/src/parser/PrismParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ else if (args[0].equals("-expression") || args[0].equals("-e")) {
8080
else if (args[0].equals("-ltl") || args[0].equals("-l")) {
8181
Expression expr = p.parseSingleLTLFormula(str);
8282
expr = (Expression) expr.accept(new ASTTraverseModify() {
83-
public Object visit(ExpressionIdent e) throws PrismLangException
83+
public Object visitNow(ExpressionIdent e) throws PrismLangException
8484
{
8585
return new parser.ast.ExpressionVar(e.getName(), TypeBool.getInstance());
8686
}
@@ -99,7 +99,7 @@ public Object visit(ExpressionIdent e) throws PrismLangException
9999
System.out.println("Syntactically co-safe: " + Expression.isCoSafeLTLSyntactic(exprPnf));
100100
}
101101
Expression expr2 = (Expression) expr.deepCopy().accept(new ASTTraverseModify() {
102-
public Object visit(ExpressionVar e) throws PrismLangException
102+
public Object visitNow(ExpressionVar e) throws PrismLangException
103103
{
104104
return new parser.ast.ExpressionLabel(e.getName());
105105
}

prism/src/parser/ast/ASTElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
// Abstract class for PRISM language AST elements
3737

38-
public abstract class ASTElement
38+
public abstract class ASTElement implements Cloneable
3939
{
4040
// Type - default to null (unknown)
4141
protected Type type = null;

prism/src/parser/ast/Updates.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public Command getParent()
148148
/**
149149
* Visitor method.
150150
*/
151+
@Override
151152
public Object accept(ASTVisitor v) throws PrismLangException
152153
{
153154
return v.visit(this);

prism/src/parser/visitor/ASTTraverse.java

Lines changed: 50 additions & 50 deletions
Large diffs are not rendered by default.

prism/src/parser/visitor/ASTTraverseModify.java

Lines changed: 50 additions & 51 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)