Browse Source

Add new ASTElement.evaluatePartially() methods.

In particular for a whole State, not just a substate.
Also for just some constants, with no variable values.
Can be used to get an expression symbolically in terms of constants.
accumulation-v4.7
Dave Parker 6 years ago
parent
commit
61e387d69c
  1. 2
      prism/src/param/ParamResult.java
  2. 29
      prism/src/parser/ast/ASTElement.java

2
prism/src/param/ParamResult.java

@ -153,7 +153,7 @@ public class ParamResult
// replace constants in the expression that have a value
// with the value
exprExpected = (Expression) exprExpected.evaluatePartially(constValues, null);
exprExpected = (Expression) exprExpected.evaluatePartially(constValues);
}
} catch (PrismLangException e) {
throw new PrismException("Invalid RESULT specification \"" + strExpected + "\" for property: " + e.getMessage());

29
prism/src/parser/ast/ASTElement.java

@ -456,6 +456,16 @@ public abstract class ASTElement
return (ASTElement) accept(visitor);
}
/**
* Evaluate partially: replace some constants with actual values.
* Constants are specified as a Values object.
* Warning: Unlike evaluate(), evaluatePartially() methods modify (and return) the expression.
*/
public ASTElement evaluatePartially(Values constantValues) throws PrismLangException
{
return evaluatePartially(new EvaluateContextValues(constantValues, null));
}
/**
* Evaluate partially: replace some constants and variables with actual values.
* Constants/variables are specified as Values objects; either can be left null.
@ -466,6 +476,25 @@ public abstract class ASTElement
return evaluatePartially(new EvaluateContextValues(constantValues, varValues));
}
/**
* Evaluate partially: replace variables with actual values, specified as a State object.
* Warning: Unlike evaluate(), evaluatePartially() methods modify (and return) the expression.
*/
public ASTElement evaluatePartially(State state) throws PrismLangException
{
return evaluatePartially(new EvaluateContextState(state));
}
/**
* Evaluate partially: replace variables with actual values, specified as a State object.
* Constant values are supplied as a Values object.
* Warning: Unlike evaluate(), evaluatePartially() methods modify (and return) the expression.
*/
public ASTElement evaluatePartially(Values constantValues, State state) throws PrismLangException
{
return evaluatePartially(new EvaluateContextState(constantValues, state));
}
/**
* Evaluate partially: replace some variables with actual values.
* Variables are specified as a State object, indexed over a subset of all variables,

Loading…
Cancel
Save