From 61e387d69ca915705c8e7022b2fc3d4773cee289 Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Tue, 17 Mar 2020 13:18:29 +0000 Subject: [PATCH] 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. --- prism/src/param/ParamResult.java | 2 +- prism/src/parser/ast/ASTElement.java | 29 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/prism/src/param/ParamResult.java b/prism/src/param/ParamResult.java index 5e738f86..027d06a9 100644 --- a/prism/src/param/ParamResult.java +++ b/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()); diff --git a/prism/src/parser/ast/ASTElement.java b/prism/src/parser/ast/ASTElement.java index 39a5a4e4..17eeb3ff 100644 --- a/prism/src/parser/ast/ASTElement.java +++ b/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,