You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.0 KiB
67 lines
2.0 KiB
package parser.visitor;
|
|
|
|
import parser.ast.AccumulationSymbol;
|
|
import parser.ast.ExpressionAccumulation;
|
|
import parser.ast.ExpressionLabel;
|
|
import parser.ast.ExpressionTemporal;
|
|
import parser.ast.ExpressionUnaryOp;
|
|
import parser.ast.TemporalOperatorBound;
|
|
import parser.ast.TemporalOperatorBounds;
|
|
import prism.IntegerBound;
|
|
import prism.PrismLangException;
|
|
|
|
|
|
public class ReplaceAccumulationExpression extends ASTTraverseModify {
|
|
|
|
private ExpressionAccumulation accexp;
|
|
private String replacementLabel;
|
|
private int replacementPosition;
|
|
|
|
|
|
|
|
public ReplaceAccumulationExpression(ExpressionAccumulation accexp, String replacementLabel) {
|
|
super();
|
|
this.accexp = accexp;
|
|
this.replacementLabel = replacementLabel;
|
|
this.replacementPosition = 0;
|
|
}
|
|
|
|
public ReplaceAccumulationExpression(ExpressionAccumulation accexp, String replacementLabel, int replacementPosition)
|
|
{
|
|
this(accexp, replacementLabel);
|
|
this.replacementPosition = replacementPosition;
|
|
}
|
|
|
|
public Object visit(ExpressionAccumulation expr) throws PrismLangException
|
|
{
|
|
ExpressionLabel label = new ExpressionLabel(replacementLabel);
|
|
//System.out.println("Replacing "+expr.toString()+" with "+label.toString());
|
|
if (expr == accexp) {
|
|
AccumulationSymbol sym = expr.getSymbol();
|
|
|
|
if (sym.isPlus()) {
|
|
// We are looking into a bright future, wrap it in F=position
|
|
ExpressionTemporal fLabel = new ExpressionTemporal(ExpressionTemporal.P_F, null, label);
|
|
TemporalOperatorBounds fBounds = new TemporalOperatorBounds();
|
|
TemporalOperatorBound fBound = IntegerBound.fromEqualBounds(replacementPosition).toTemporalOperatorBound();
|
|
fBounds.setDefaultBound(fBound);
|
|
fLabel.setBounds(fBounds);
|
|
// If its a BOX, negate it
|
|
if (sym.isBox()) {
|
|
return new ExpressionUnaryOp(ExpressionUnaryOp.NOT, fLabel);
|
|
} else {
|
|
return fLabel;
|
|
}
|
|
} else {
|
|
// This is a MINUS, just check for negation
|
|
if (sym.isBox()) {
|
|
return new ExpressionUnaryOp(ExpressionUnaryOp.NOT, label);
|
|
} else {
|
|
return label;
|
|
}
|
|
}
|
|
} else {
|
|
return expr;
|
|
}
|
|
}
|
|
}
|