@ -27,7 +27,7 @@
package parser.ast ;
import parser.EvaluateContext ;
import parser.visitor.* ;
import parser.visitor.ASTVisitor ;
import prism.PrismLangException ;
public class ExpressionTemporal extends Expression
@ -57,6 +57,8 @@ public class ExpressionTemporal extends Expression
/ / Strictness of ( time ) bounds
protected boolean lBoundStrict = false ; / / true : > , false : > =
protected boolean uBoundStrict = false ; / / true : < , false : < =
/ / Display as = T rather than [ T , T ] ?
protected boolean equals = false ;
/ / Constructors
@ -88,16 +90,8 @@ public class ExpressionTemporal extends Expression
operand2 = e2 ;
}
public int getNumOperands ( )
{
if ( operand1 = = null )
return 0 ;
else
return ( operand2 = = null ) ? 1 : 2 ;
}
/ * *
* Set lower timer bound to be of form > = e
* Set lower time bound to be of form > = e
* ( null denotes no lower bound , i . e . zero )
* /
public void setLowerBound ( Expression e )
@ -106,7 +100,7 @@ public class ExpressionTemporal extends Expression
}
/ * *
* Set lower timer bound to be of form > = e or > e
* Set lower time bound to be of form > = e or > e
* ( null denotes no lower bound , i . e . zero )
* /
public void setLowerBound ( Expression e , boolean strict )
@ -116,7 +110,7 @@ public class ExpressionTemporal extends Expression
}
/ * *
* Set upper timer bound to be of form < = e
* Set upper time bound to be of form < = e
* ( null denotes no upper bound , i . e . infinity )
* /
public void setUpperBound ( Expression e )
@ -125,7 +119,7 @@ public class ExpressionTemporal extends Expression
}
/ * *
* Set upper timer bound to be of form < = e or < e
* Set upper time bound to be of form < = e or < e
* ( null denotes no upper bound , i . e . infinity )
* /
public void setUpperBound ( Expression e , boolean strict )
@ -134,6 +128,18 @@ public class ExpressionTemporal extends Expression
uBoundStrict = strict ;
}
/ * *
* Set both lower / upper time bound to e , i . e . "=e" .
* /
public void setEqualBounds ( Expression e )
{
lBound = e ;
lBoundStrict = false ;
uBound = e ;
uBoundStrict = false ;
equals = true ;
}
/ / Get methods
public int getOperator ( )
@ -156,6 +162,14 @@ public class ExpressionTemporal extends Expression
return operand2 ;
}
public int getNumOperands ( )
{
if ( operand1 = = null )
return 0 ;
else
return ( operand2 = = null ) ? 1 : 2 ;
}
public boolean hasBounds ( )
{
return lBound ! = null | | uBound ! = null ;
@ -181,6 +195,14 @@ public class ExpressionTemporal extends Expression
return uBoundStrict ;
}
/ * *
* Returns true if lower / upper bound are equal and should be displayed as = T
* /
public boolean getEquals ( )
{
return equals ;
}
/ / Methods required for Expression :
/ * *
@ -236,7 +258,10 @@ public class ExpressionTemporal extends Expression
if ( uBound = = null ) {
s + = ">" + ( lBoundStrict ? "" : "=" ) + lBound ;
} else {
s + = "[" + lBound + "," + uBound + "]" ;
if ( equals )
s + = "=" + lBound ;
else
s + = "[" + lBound + "," + uBound + "]" ;
}
}
if ( operand2 ! = null )
@ -257,6 +282,7 @@ public class ExpressionTemporal extends Expression
expr . setOperand2 ( operand2 . deepCopy ( ) ) ;
expr . setLowerBound ( lBound = = null ? null : lBound . deepCopy ( ) , lBoundStrict ) ;
expr . setUpperBound ( uBound = = null ? null : uBound . deepCopy ( ) , uBoundStrict ) ;
expr . equals = equals ;
expr . setType ( type ) ;
expr . setPosition ( this ) ;
return expr ;
@ -280,6 +306,7 @@ public class ExpressionTemporal extends Expression
exprTemp = new ExpressionTemporal ( P_U , op1 , operand2 ) ;
exprTemp . setLowerBound ( lBound , lBoundStrict ) ;
exprTemp . setUpperBound ( uBound , uBoundStrict ) ;
exprTemp . equals = equals ;
return exprTemp ;
case P_G :
/ / G a = = ! ( true U ! a )
@ -288,6 +315,7 @@ public class ExpressionTemporal extends Expression
exprTemp = new ExpressionTemporal ( P_U , op1 , op2 ) ;
exprTemp . setLowerBound ( lBound , lBoundStrict ) ;
exprTemp . setUpperBound ( uBound , uBoundStrict ) ;
exprTemp . equals = equals ;
return Expression . Not ( exprTemp ) ;
case P_W :
/ / a W b = = ! ( a & ! b U ! a & ! b )
@ -296,6 +324,7 @@ public class ExpressionTemporal extends Expression
exprTemp = new ExpressionTemporal ( P_U , op1 , op2 ) ;
exprTemp . setLowerBound ( lBound , lBoundStrict ) ;
exprTemp . setUpperBound ( uBound , uBoundStrict ) ;
exprTemp . equals = equals ;
return Expression . Not ( exprTemp ) ;
case P_R :
/ / a R b = = ! ( ! a U ! b )
@ -304,6 +333,7 @@ public class ExpressionTemporal extends Expression
exprTemp = new ExpressionTemporal ( P_U , op1 , op2 ) ;
exprTemp . setLowerBound ( lBound , lBoundStrict ) ;
exprTemp . setUpperBound ( uBound , uBoundStrict ) ;
exprTemp . equals = equals ;
return Expression . Not ( exprTemp ) ;
}
throw new PrismLangException ( "Cannot convert " + getOperatorSymbol ( ) + " to until form" ) ;