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.
220 lines
5.9 KiB
220 lines
5.9 KiB
//==============================================================================
|
|
//
|
|
// Copyright (c) 2002-
|
|
// Authors:
|
|
// * Dave Parker <david.parker@comlab.ox.ac.uk> (University of Oxford, formerly University of Birmingham)
|
|
//
|
|
//------------------------------------------------------------------------------
|
|
//
|
|
// This file is part of PRISM.
|
|
//
|
|
// PRISM is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// PRISM is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with PRISM; if not, write to the Free Software Foundation,
|
|
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
//
|
|
//==============================================================================
|
|
|
|
package parser.ast;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.stream.Collectors;
|
|
|
|
import param.BigRational;
|
|
import parser.EvaluateContext;
|
|
import parser.type.TypePathBool;
|
|
import parser.visitor.ASTVisitor;
|
|
import prism.PrismLangException;
|
|
|
|
public class ExpressionAccumulation extends Expression
|
|
{
|
|
AccumulationSymbol symbol;
|
|
AccumulationConstraint constraint;
|
|
ExpressionRegular regexp;
|
|
TemporalOperatorBound bound;
|
|
ArrayList<Expression> recordSet;
|
|
|
|
Expression operand1 = null;
|
|
Expression operand2 = null;
|
|
|
|
public ExpressionAccumulation(AccumulationSymbol symbol) {
|
|
this.symbol = symbol;
|
|
this.setType(TypePathBool.getInstance());
|
|
}
|
|
|
|
public boolean hasRegularExpression() {
|
|
return regexp != null;
|
|
}
|
|
|
|
public boolean hasBoundExpression() {
|
|
return bound != null;
|
|
}
|
|
|
|
public Expression getOperand1() {
|
|
return operand1;
|
|
}
|
|
|
|
public void setOperand1(Expression operand1) {
|
|
this.operand1 = operand1;
|
|
}
|
|
|
|
public Expression getOperand2() {
|
|
return operand2;
|
|
}
|
|
|
|
public void setOperand2(Expression operand2) {
|
|
this.operand2 = operand2;
|
|
}
|
|
|
|
public AccumulationSymbol getSymbol() {
|
|
return symbol;
|
|
}
|
|
public void setSymbol(AccumulationSymbol symbol) {
|
|
this.symbol = symbol;
|
|
}
|
|
public AccumulationConstraint getConstraint() {
|
|
return constraint;
|
|
}
|
|
public void setConstraint(AccumulationConstraint constraint) {
|
|
this.constraint = constraint;
|
|
}
|
|
public ExpressionRegular getRegularExpression() {
|
|
if ( hasRegularExpression() ) { return regexp; }
|
|
else throw new RuntimeException("getRegularExpression called without RegularExpression");
|
|
}
|
|
public void setRegularExpression(ExpressionRegular regexp) {
|
|
this.bound = null;
|
|
this.regexp = regexp;
|
|
}
|
|
|
|
public TemporalOperatorBound getBoundExpression() {
|
|
if ( hasBoundExpression() ) { return bound; }
|
|
else throw new RuntimeException("getBoundExpression called without BoundExpression");
|
|
}
|
|
|
|
public void setBoundExpression(TemporalOperatorBound bound) {
|
|
if ( bound.isDefaultBound() && bound.hasUpperBound() ) {
|
|
this.regexp= null;
|
|
this.bound = bound;
|
|
} else {
|
|
throw new RuntimeException("Bounds need to be upper and default.");
|
|
}
|
|
}
|
|
|
|
public ArrayList<Expression> getRecordSet() {
|
|
return recordSet;
|
|
}
|
|
|
|
public void setRecordSet(ArrayList<Expression> fireOn) {
|
|
this.recordSet = fireOn;
|
|
}
|
|
|
|
public boolean hasRecordSet() {
|
|
return recordSet != null;
|
|
}
|
|
|
|
public Expression recordSetExpression() {
|
|
if(!hasRecordSet()) { return Expression.True(); }
|
|
|
|
Expression ret = recordSet.get(0);
|
|
for(int i=1;i<recordSet.size();i++) {
|
|
ret = new ExpressionBinaryOp(ExpressionBinaryOp.OR, ret, recordSet.get(i));
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
public boolean isNullary() {
|
|
return (symbol.isDia() || symbol.isBox()) && operand2 == null;
|
|
}
|
|
|
|
// Add a toString
|
|
public String toString() {
|
|
String ret = "";
|
|
|
|
if(operand1 != null) { ret += operand1.toString() + " "; }
|
|
|
|
ret += symbol.toString();
|
|
|
|
if ( hasRegularExpression() ) { ret += "{ Reg:" + regexp.toString() + "}"; }
|
|
else if ( hasBoundExpression() ) { ret += "{" + bound.toString() + "}"; }
|
|
else throw new RuntimeException("Cannot stringify AccumulationExpression without fragment bounds.");
|
|
|
|
ret += "{" + constraint.toString() + "}";
|
|
|
|
if ( hasRecordSet() ) {
|
|
String fireOnString = recordSet.stream().map(f -> f.toString()).collect(Collectors.joining(","));
|
|
ret += "{" + fireOnString + "}";
|
|
}
|
|
|
|
if(operand2 != null) { ret += " " + operand2.toString(); }
|
|
|
|
return ret;
|
|
}
|
|
|
|
@Override
|
|
public boolean isConstant() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isProposition() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public Object evaluate(EvaluateContext ec) throws PrismLangException {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public BigRational evaluateExact(EvaluateContext ec) throws PrismLangException {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public boolean returnsSingleValue() {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public Expression deepCopy() {
|
|
ExpressionAccumulation ret = new ExpressionAccumulation(this.getSymbol());
|
|
|
|
ret.setConstraint(this.getConstraint().deepCopy());
|
|
if ( this.hasBoundExpression() ) {
|
|
ret.setBoundExpression(this.getBoundExpression().deepCopy());
|
|
}
|
|
if ( this.hasRegularExpression() ) {
|
|
ret.setRegularExpression((ExpressionRegular) this.getRegularExpression().deepCopy());
|
|
}
|
|
if ( this.hasRecordSet() ) {
|
|
ret.setRecordSet(new ArrayList<Expression>(this.getRecordSet().size()));
|
|
for(Expression e : this.getRecordSet()) {
|
|
ret.recordSet.add(e.deepCopy());
|
|
}
|
|
}
|
|
|
|
if ( operand1 != null ) { ret.setOperand1(this.getOperand1().deepCopy()); }
|
|
if ( operand2 != null ) { ret.setOperand2(this.getOperand2().deepCopy()); }
|
|
|
|
return ret;
|
|
}
|
|
|
|
@Override
|
|
public Object accept(ASTVisitor v) throws PrismLangException {
|
|
return v.visit(this);
|
|
}
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|