@ -30,6 +30,7 @@ import java.util.HashMap;
import java.util.Map ;
import java.util.Vector ;
import param.BigRational ;
import parser.* ;
import parser.visitor.* ;
import prism.PrismLangException ;
@ -232,37 +233,66 @@ public class ConstantList extends ASTElement
return false ;
return ( getConstant ( i ) ! = null ) ;
}
/ * *
* Set values for * all * undefined constants , evaluate values for * all * constants
* and return a Values object with values for * all * constants .
* Argument ' someValues ' contains values for undefined ones , can be null if all already defined
* Argument ' otherValues ' contains any other values which may be needed , null if none
* < br >
* Uses standard ( integer , floating - point ) arithmetic for evaluating constants .
* /
public Values evaluateConstants ( Values someValues , Values otherValues ) throws PrismLangException
{
return evaluateSomeOrAll Constants ( someValues , otherValues , tru e) ;
return evaluateConstants ( someValues , otherValues , fals e) ;
}
/ * *
* Set values for * all * undefined constants , evaluate values for * all * constants
* and return a Values object with values for * all * constants .
* Argument ' someValues ' contains values for undefined ones , can be null if all already defined
* Argument ' otherValues ' contains any other values which may be needed , null if none
* If argument ' exact ' is true , constants are evaluated using exact arithmetic ( BigRational )
* /
public Values evaluateConstants ( Values someValues , Values otherValues , boolean exact ) throws PrismLangException
{
return evaluateSomeOrAllConstants ( someValues , otherValues , true , exact ) ;
}
/ * *
* Set values for * some * undefined constants , evaluate values for constants where possible
* and return a Values object with values for all constants that could be evaluated .
* Argument ' someValues ' contains values for undefined ones , can be null if all already defined
* Argument ' otherValues ' contains any other values which may be needed , null if none
* < br >
* Uses standard ( integer , floating - point ) arithmetic for evaluating constants .
* /
public Values evaluateSomeConstants ( Values someValues , Values otherValues ) throws PrismLangException
{
return evaluateSomeOrAllConstants ( someValues , otherValues , false ) ;
return evaluateSomeConstants ( someValues , otherValues , false ) ;
}
/ * *
* Set values for * some * undefined constants , evaluate values for constants where possible
* and return a Values object with values for all constants that could be evaluated .
* Argument ' someValues ' contains values for undefined ones , can be null if all already defined
* Argument ' otherValues ' contains any other values which may be needed , null if none
* If argument ' exact ' is true , constants are evaluated using exact arithmetic ( BigRational )
* /
public Values evaluateSomeConstants ( Values someValues , Values otherValues , boolean exact ) throws PrismLangException
{
return evaluateSomeOrAllConstants ( someValues , otherValues , false , exact ) ;
}
/ * *
* Set values for * some * or * all * undefined constants , evaluate values for constants where possible
* and return a Values object with values for all constants that could be evaluated .
* Argument ' someValues ' contains values for undefined ones , can be null if all already defined .
* Argument ' otherValues ' contains any other values which may be needed , null if none .
* If argument ' all ' is true , an exception is thrown if any undefined constant is not defined .
* If argument ' exact ' is true , constants are evaluated using exact arithmetic ( BigRational )
* /
private Values evaluateSomeOrAllConstants ( Values someValues , Values otherValues , boolean all ) throws PrismLangException
private Values evaluateSomeOrAllConstants ( Values someValues , Values otherValues , boolean all , boolean exact ) throws PrismLangException
{
ConstantList cl ;
Expression e ;
@ -322,8 +352,23 @@ public class ConstantList extends ASTElement
/ / Evaluate constants and store in new Values object ( again , ignoring ' otherValues ' ones )
allValues = new Values ( ) ;
for ( i = 0 ; i < numToEvaluate ; i + + ) {
if ( cl . getConstant ( i ) ! = null ) {
val = cl . getConstant ( i ) . evaluate ( null , otherValues ) ;
Expression constant = cl . getConstant ( i ) ;
if ( constant ! = null ) {
if ( exact ) {
BigRational r = constant . evaluateExact ( null , otherValues ) ;
/ / handle differently , depending on constant type
if ( constant . getType ( ) instanceof TypeDouble ) {
/ / we keep as BigRational for TypeDouble
val = r ;
} else {
/ / we convert to Java int / boolean for TypeInt and TypeBool
/ / Note : throws exception if value can ' t be precisely represented
/ / using the corresponding Java data type
val = constant . getType ( ) . castFromBigRational ( r ) ;
}
} else {
val = constant . evaluate ( null , otherValues ) ;
}
allValues . addValue ( cl . getConstantName ( i ) , val ) ;
}
}