Package daikon
Class VarInfoName.QuantHelper
- Object
-
- QuantHelper
-
- Enclosing class:
- VarInfoName
public static class VarInfoName.QuantHelper extends Object
Helper for writing parts of quantification expressions. Formatting methods in invariants call the formatting methods in this class to get commonly-used parts, like how universal quanitifiers look in the different formatting schemes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VarInfoName.QuantHelper.FreeVar
A FreeVar is very much like a Simple, except that it doesn't care if it's in prestate or poststate for simplify formatting.static class
VarInfoName.QuantHelper.QuantifyReturn
Record type for return value of the quantify method below.
-
Constructor Summary
Constructors Constructor Description QuantHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String[]
format_esc(VarInfoName[] roots)
Given a list of roots, return a String array where the first element is a ESC-style quantification over newly-introduced bound variables, the last element is a closer, and the other elements are esc-named strings for the provided roots (with sequences subscripted by one of the new bound variables).static String[]
format_esc(VarInfoName[] roots, boolean elementwise)
protected static String[]
format_java_style(VarInfoName.QuantHelper.QuantifyReturn qret, boolean elementwise, boolean forall, OutputFormat format)
protected static String[]
format_java_style(VarInfoName.QuantHelper.QuantifyReturn qret, boolean elementwise, OutputFormat format)
protected static String[]
format_java_style(VarInfoName.QuantHelper.QuantifyReturn qret, OutputFormat format)
protected static String[]
format_java_style(VarInfoName[] roots, boolean elementwise, boolean forall, OutputFormat format)
protected static String[]
format_java_style(VarInfoName[] roots, boolean elementwise, OutputFormat format)
protected static String[]
format_java_style(VarInfoName[] roots, OutputFormat format)
Given a list of roots, return a String array where the first element is a Java-style quantification over newly-introduced bound variables, the last element is a closer, and the other elements are java-named strings for the provided roots (with sequences subscripted by one of the new bound variables).static String[]
format_simplify(VarInfoName[] roots)
Given a list of roots, return a String array where the first element is a simplify-style quantification over newly-introduced bound variables, the last element is a closer, and the other elements are simplify-named strings for the provided roots (with sequences subscripted by one of the new bound variables).static String[]
format_simplify(VarInfoName[] roots, boolean eltwise)
static String[]
format_simplify(VarInfoName[] roots, boolean eltwise, boolean adjacent)
static String[]
format_simplify(VarInfoName[] roots, boolean eltwise, boolean adjacent, boolean distinct)
static String[]
format_simplify(VarInfoName[] roots, boolean elementwise, boolean adjacent, boolean distinct, boolean includeIndex)
static VarInfoName
getFreeIndex(VarInfoName... vins)
Return a fresh variable name that doesn't appear in the given variable names.protected static String
quant_element_conditions(VarInfoName _idx, VarInfoName _low, VarInfoName idx, VarInfoName low, OutputFormat format)
This function returns a string representing the extra conditions necessary if the quantification is element-wise.protected static String
quant_execution_condition(VarInfoName low, VarInfoName idx, VarInfoName high, OutputFormat format)
This function returns a string that represents the execution condition for the quantification.protected static String
quant_format_exists(OutputFormat format)
This function returns a string representing how to format an exists statement in a given output mode.protected static String
quant_format_forall(OutputFormat format)
This function returns a string representing how to format a forall statement in a given output mode.protected static String
quant_increment(VarInfoName idx, int i, OutputFormat format)
This function creates a string that represents how to increment the variables involved in quantification.protected static String
quant_separator1(OutputFormat format)
This function returns a string representing how to format the first seperation in the quantification, that is, the one between the intial condition and the execution condition.protected static String
quant_separator2(OutputFormat format)
This function returns a string representing how to format the second seperation in the quantification, that is, the one between the execution condition and the assertion.protected static String
quant_step_terminator(OutputFormat format)
This function returns a string representing how to format the final seperation in the quantification, that is, the one between the assertion and any closing symbols.protected static String
quant_var_initial_state(VarInfoName idx, VarInfoName low, OutputFormat format)
This function returns a string that represents the initial condition for the index variable.static VarInfoName.QuantHelper.QuantifyReturn
quantify(VarInfoName[] roots)
Given a list of roots, changes all Elements and Slice terms to Subscripts by inserting a new free variable; also return bounds for the new variables.static VarInfoName[]
replace(VarInfoName root, VarInfoName needy, VarInfoName index)
Replaces a needy (unquantified term) with its subscripted equivalent, using the given index variable.static VarInfoName
selectNth(VarInfoName root, @Nullable VarInfoName index_base, int index_off)
Assuming that root is a sequence, return a VarInfoName representing the (index_base+index_off)-th element of that sequence. index_base may be null, to represent 0.static VarInfoName
selectNth(VarInfoName root, String index_base, boolean free, int index_off)
Assuming that root is a sequence, return a VarInfoName representing the (index_base+index_off)-th element of that sequence. index_base may be null, to represent 0.static String[]
simplifyNameAndBounds(VarInfoName name)
Given a list of roots, return a String array where the first element is a JML-style quantification over newly-introduced bound variables, the last element is a closer, and the other elements are jml-named strings for the provided roots (with sequenced subscripted by one of the new bound variables).
-
-
-
Constructor Detail
-
QuantHelper
public QuantHelper()
-
-
Method Detail
-
replace
public static VarInfoName[] replace(VarInfoName root, VarInfoName needy, VarInfoName index)
Replaces a needy (unquantified term) with its subscripted equivalent, using the given index variable.- Parameters:
root
- the root of the expression to be modified. Substitution occurs only in the subtree reachable from root.needy
- the term to be subscripted (must be of type Elements or Slice)index
- the variable to place in the subscript- Returns:
- a 3-element array consisting of the new root, the lower bound for the index (inclusive), and the upper bound for the index (inclusive), in that order
-
selectNth
public static VarInfoName selectNth(VarInfoName root, @Nullable VarInfoName index_base, int index_off)
Assuming that root is a sequence, return a VarInfoName representing the (index_base+index_off)-th element of that sequence. index_base may be null, to represent 0.
-
selectNth
public static VarInfoName selectNth(VarInfoName root, String index_base, boolean free, int index_off)
Assuming that root is a sequence, return a VarInfoName representing the (index_base+index_off)-th element of that sequence. index_base may be null, to represent 0.
-
getFreeIndex
public static VarInfoName getFreeIndex(VarInfoName... vins)
Return a fresh variable name that doesn't appear in the given variable names.
-
quantify
public static VarInfoName.QuantHelper.QuantifyReturn quantify(VarInfoName[] roots)
Given a list of roots, changes all Elements and Slice terms to Subscripts by inserting a new free variable; also return bounds for the new variables.
-
format_esc
public static String[] format_esc(VarInfoName[] roots)
Given a list of roots, return a String array where the first element is a ESC-style quantification over newly-introduced bound variables, the last element is a closer, and the other elements are esc-named strings for the provided roots (with sequences subscripted by one of the new bound variables).
-
format_esc
public static String[] format_esc(VarInfoName[] roots, boolean elementwise)
-
simplifyNameAndBounds
public static String[] simplifyNameAndBounds(VarInfoName name)
Given a list of roots, return a String array where the first element is a JML-style quantification over newly-introduced bound variables, the last element is a closer, and the other elements are jml-named strings for the provided roots (with sequenced subscripted by one of the new bound variables).
-
format_simplify
public static String[] format_simplify(VarInfoName[] roots)
Given a list of roots, return a String array where the first element is a simplify-style quantification over newly-introduced bound variables, the last element is a closer, and the other elements are simplify-named strings for the provided roots (with sequences subscripted by one of the new bound variables).If elementwise is true, include the additional contraint that the indices (there must be exactly two in this case) refer to corresponding positions. If adjacent is true, include the additional constraint that the second index be one more than the first. If distinct is true, include the constraint that the two indices are different. If includeIndex is true, return additional strings, after the roots but before the closer, with the names of the index variables.
-
format_simplify
public static String[] format_simplify(VarInfoName[] roots, boolean eltwise)
-
format_simplify
public static String[] format_simplify(VarInfoName[] roots, boolean eltwise, boolean adjacent)
-
format_simplify
public static String[] format_simplify(VarInfoName[] roots, boolean eltwise, boolean adjacent, boolean distinct)
-
format_simplify
public static String[] format_simplify(VarInfoName[] roots, boolean elementwise, boolean adjacent, boolean distinct, boolean includeIndex)
-
format_java_style
protected static String[] format_java_style(VarInfoName[] roots, OutputFormat format)
Given a list of roots, return a String array where the first element is a Java-style quantification over newly-introduced bound variables, the last element is a closer, and the other elements are java-named strings for the provided roots (with sequences subscripted by one of the new bound variables).
-
format_java_style
protected static String[] format_java_style(VarInfoName[] roots, boolean elementwise, OutputFormat format)
-
format_java_style
protected static String[] format_java_style(VarInfoName[] roots, boolean elementwise, boolean forall, OutputFormat format)
-
format_java_style
protected static String[] format_java_style(VarInfoName.QuantHelper.QuantifyReturn qret, OutputFormat format)
-
format_java_style
protected static String[] format_java_style(VarInfoName.QuantHelper.QuantifyReturn qret, boolean elementwise, OutputFormat format)
-
format_java_style
protected static String[] format_java_style(VarInfoName.QuantHelper.QuantifyReturn qret, boolean elementwise, boolean forall, OutputFormat format)
-
quant_increment
protected static String quant_increment(VarInfoName idx, int i, OutputFormat format)
This function creates a string that represents how to increment the variables involved in quantification. Since the increment is not stated explicitly in the JML and ESC formats this function merely returns an empty string for those formats.
-
quant_var_initial_state
protected static String quant_var_initial_state(VarInfoName idx, VarInfoName low, OutputFormat format)
This function returns a string that represents the initial condition for the index variable.
-
quant_execution_condition
protected static String quant_execution_condition(VarInfoName low, VarInfoName idx, VarInfoName high, OutputFormat format)
This function returns a string that represents the execution condition for the quantification.
-
quant_element_conditions
protected static String quant_element_conditions(VarInfoName _idx, VarInfoName _low, VarInfoName idx, VarInfoName low, OutputFormat format)
This function returns a string representing the extra conditions necessary if the quantification is element-wise.
-
quant_format_forall
protected static String quant_format_forall(OutputFormat format)
This function returns a string representing how to format a forall statement in a given output mode.
-
quant_format_exists
protected static String quant_format_exists(OutputFormat format)
This function returns a string representing how to format an exists statement in a given output mode.
-
quant_separator1
protected static String quant_separator1(OutputFormat format)
This function returns a string representing how to format the first seperation in the quantification, that is, the one between the intial condition and the execution condition.
-
quant_separator2
protected static String quant_separator2(OutputFormat format)
This function returns a string representing how to format the second seperation in the quantification, that is, the one between the execution condition and the assertion.
-
quant_step_terminator
protected static String quant_step_terminator(OutputFormat format)
This function returns a string representing how to format the final seperation in the quantification, that is, the one between the assertion and any closing symbols.
-
-