Class PrintInvariants
- Object
-
- PrintInvariants
-
public final class PrintInvariants extends Object
PrintInvariants prints a set of invariants from a.inv
file. For documentation, see section "Printing Invariants" in the Daikon manual. Invoke the program as follows:java daikon.PrintInvariants [flags] inv-file
For a list of cammand-line options, pass the "-h" flag to this program.
-
-
Field Summary
Fields Modifier and Type Field Description static Logger
debug
Main debug tracer for PrintInvariants (for things unrelated to printing).static Logger
debugBound
Debug tracer for variable bound information.static Logger
debugFiltering
Debug tracer for filtering.static Logger
debugPrint
Debug tracer for printing.static Logger
debugPrintEquality
Debug tracer for printing equality.static Logger
debugPrintModified
Debug tracer for printing modified variables in ESC/JML/DBC output.static Logger
debugRepr
Debug tracer for printing.static boolean
dkconfig_old_array_names
In the new decl format, print array names as 'a[]' as opposed to 'a[..]'static boolean
dkconfig_print_all
If true, print all invariants without any filtering.static boolean
dkconfig_print_implementer_entry_ppts
If false, don't print entry method program points for methods that override or implement another method (i.e., entry program points that have a parent that is a method).static boolean
dkconfig_print_inv_class
Print invariant classname with invariants in output offormat()
method.static boolean
dkconfig_remove_post_vars
If true, remove as many variables as possible that need to be indicated as 'post'.static boolean
dkconfig_replace_prestate
This option must be given with "--format Java" option.static boolean
dkconfig_static_const_infer
This enables a different way of treating static constant variables.static boolean
dkconfig_true_inv_cnt
If true, print the total number of true invariants.static boolean
print_discarded_invariants
Switch for whether to print discarded Invariants or not, default is false.static boolean
wrap_xml
If true, then each invariant is printed using the current OutputFormat, but it's wrapped inside xml tags, along with other information about the invariant.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
addPrestateExpression(String expr)
See dkconfig_replace_prestate.static void
count_global_stats(PptTopLevel ppt)
Count statistics (via Global) on variables (canonical, missing, etc.)static void
discReasonSetup(String arg)
Method used to setup fields if the--disc_reason
command-line option is used if (arg==null) then show all discarded Invariants, otherwise just show the ones specified in arg, where arg = class-name<var1,var2,...>@ppt.name e.g.: OneOf<x>@foo():::ENTER would only show OneOf Invariants that involve x at the program point foo:::ENTER (any of the 3 params can be omitted, e.g.static String
get_csharp_inv_type(Invariant invariant)
Gets the invariant type string (i.e. daikon.inv.binary.inv) of a Daikon invariant.static void
get_csharp_invariant_variables(Invariant invariant, Set<String> variables, boolean group)
Parses the invariant variables of invariant and stores them in variables If group is true the invariant's grouping variables are parsed (the variables which the invariant is grouped by in the contract list view).static void
get_csharp_invariant_variables(VarInfo[] vars, Set<String> variables, boolean sort)
Parses the variables from vars.static void
main(String[] args)
See the documentation for this class.static void
mainHelper(String[] args)
This does the work ofmain(String[])
, but it never calls System.exit, so it is appropriate to be called progrmmatically.static String
parse_csharp_invariant_variable(VarInfo varInfo, boolean sort)
Parses the variables from varInfo.static void
print_all_invs(@Nullable PptSlice slice, String indent)
Prints all of the invariants in the specified slice.static void
print_all_invs(PptTopLevel ppt, VarInfo v1, VarInfo v2, String indent)
Prints all of the binary invariants over the specified variables.static void
print_all_invs(PptTopLevel ppt, VarInfo vi, String indent)
Prints all of the unary invariants over the specified variable.static void
print_all_ternary_invs(PptMap all_ppts)
Prints all invariants for ternary slices (organized by slice) and all of the unary and binary invariants over the same variables.static void
print_filter_stats(Logger log, PptTopLevel ppt, PptMap ppt_map)
Prints how many invariants are filtered by each filter.static void
print_invariant(Invariant inv, PrintWriter out, int invCounter, PptTopLevel ppt)
Prints the specified invariant to out.static void
print_invariants(PptMap all_ppts)
static void
print_invariants(PptTopLevel ppt, PrintWriter out, PptMap ppt_map)
Print invariants for a single program point, once we know that this ppt is worth printing.static void
print_invariants_maybe(PptTopLevel ppt, PrintWriter out, PptMap all_ppts)
Print invariants for a single program point and its conditionals.static void
print_modified_vars(PptTopLevel ppt, PrintWriter out)
Prints all variables that were modified if the format is ESCJAVA or DBCJAVA.static void
print_reasons(PptMap ppts)
Prints out all the discardCodes and discardStrings of the Invariants that will not be printed if the--disc_reason
command-line option is used.static void
print_sample_data(PptTopLevel ppt, PrintWriter out)
Prints the program point name.static void
print_true_inv_cnt(PptMap ppts)
static void
resetPrestateExpressions()
See dkconfig_replace_prestate.static List<Invariant>
sort_invariant_list(List<Invariant> invs)
Takes a list of Invariants and returns a list of Invariants that is sorted according to PptTopLevel.icfp.static void
validateGuardNulls()
Validate guardNulls config option.
-
-
-
Field Detail
-
dkconfig_replace_prestate
public static boolean dkconfig_replace_prestate
This option must be given with "--format Java" option.Instead of outputting prestate expressions as "\old(E)" within an invariant, output a variable name (e.g. `v1'). At the end of each program point, output the list of variable-to-expression mappings. For example: with this option set to false, a program point might print like this:
foo.bar.Bar(int):::EXIT \old(capacity) == sizeof(this.theArray)
With the option set to true, it would print like this:foo.bar.Bar(int):::EXIT v0 == sizeof(this.theArray) prestate assignment: v0=capacity
-
dkconfig_print_inv_class
public static boolean dkconfig_print_inv_class
Print invariant classname with invariants in output offormat()
method. Normally used only for debugging output rather than ordinary printing of invariants. This is especially useful when two different invariants have the same printed representation.
-
dkconfig_print_all
public static boolean dkconfig_print_all
If true, print all invariants without any filtering.
-
dkconfig_true_inv_cnt
public static boolean dkconfig_true_inv_cnt
If true, print the total number of true invariants. This includes invariants that are redundant and would normally not be printed or even created due to optimizations.
-
dkconfig_remove_post_vars
public static boolean dkconfig_remove_post_vars
If true, remove as many variables as possible that need to be indicated as 'post'. Post variables occur when the subscript for a derived variable with an orig sequence is not orig. For example: orig(a[post(i)]) An equivalent expression involving only orig variables is substitued for the post variable when one exists.
-
dkconfig_old_array_names
public static boolean dkconfig_old_array_names
In the new decl format, print array names as 'a[]' as opposed to 'a[..]' This creates names that are more compatible with the old output. This option has no effect in the old decl format.
-
dkconfig_static_const_infer
public static boolean dkconfig_static_const_infer
This enables a different way of treating static constant variables. They are not created into invariants into slices. Instead, they are examined during print time. If a unary invariant contains a value which matches the value of a static constant varible, the value will be replaced by the name of the variable, "if it makes sense". For example, if there is a static constant variable a = 1. And if there exists an invariant x ≤ 1, x ≤ a would be the result printed.
-
dkconfig_print_implementer_entry_ppts
public static boolean dkconfig_print_implementer_entry_ppts
If false, don't print entry method program points for methods that override or implement another method (i.e., entry program points that have a parent that is a method). Microsoft Code Contracts does not allow contracts on such methods.
-
debug
public static final Logger debug
Main debug tracer for PrintInvariants (for things unrelated to printing).
-
debugPrint
public static final Logger debugPrint
Debug tracer for printing.
-
debugPrintModified
public static final Logger debugPrintModified
Debug tracer for printing modified variables in ESC/JML/DBC output.
-
debugPrintEquality
public static final Logger debugPrintEquality
Debug tracer for printing equality.
-
debugFiltering
public static final Logger debugFiltering
Debug tracer for filtering.
-
debugBound
public static final Logger debugBound
Debug tracer for variable bound information.
-
print_discarded_invariants
public static boolean print_discarded_invariants
Switch for whether to print discarded Invariants or not, default is false. True iff--disc_reason
switch was supplied on the command line.
-
wrap_xml
public static boolean wrap_xml
If true, then each invariant is printed using the current OutputFormat, but it's wrapped inside xml tags, along with other information about the invariant. For example, if this switch is true and if the output format is JAVA, and the invariant prints as "x == null", the results of print_invariant would look something like:
The above output is actually all in one line, although in this comment it's broken up into multiple lines for clarity.<INVINFO> <INV> x == null </INV> <SAMPLES> 100 </SAMPLES> <DAIKON> x == null </DAIKON> <DAIKONCLASS> daikon.inv.unary.scalar.NonZero </DAIKONCLASS> <METHOD> foo() </METHOD> </INVINFO>
Note the extra information printed with the invariant: the number of samples from which the invariant was derived, the daikon representation (i.e. the Daikon output format), the Java class that the invariant corresponds to, and the method that the invariant belongs to ("null" for object invariants).
-
-
Method Detail
-
resetPrestateExpressions
public static void resetPrestateExpressions()
See dkconfig_replace_prestate.Resets the prestate expression mapping. This is done between printing of each different program point.
-
addPrestateExpression
public static String addPrestateExpression(String expr)
See dkconfig_replace_prestate.Return the variable name corresponding to expr. Create a new varname and an expr → varname mapping if there is not already one.
-
main
public static void main(String[] args) throws FileNotFoundException, StreamCorruptedException, OptionalDataException, IOException, ClassNotFoundException
See the documentation for this class.
-
mainHelper
public static void mainHelper(String[] args) throws FileNotFoundException, StreamCorruptedException, OptionalDataException, IOException, ClassNotFoundException
This does the work ofmain(String[])
, but it never calls System.exit, so it is appropriate to be called progrmmatically.
-
print_reasons
public static void print_reasons(PptMap ppts)
Prints out all the discardCodes and discardStrings of the Invariants that will not be printed if the--disc_reason
command-line option is used.
-
validateGuardNulls
public static void validateGuardNulls()
Validate guardNulls config option.
-
discReasonSetup
public static void discReasonSetup(String arg)
Method used to setup fields if the--disc_reason
command-line option is used if (arg==null) then show all discarded Invariants, otherwise just show the ones specified in arg, where arg = class-name<var1,var2,...>@ppt.name e.g.: OneOf<x>@foo():::ENTER would only show OneOf Invariants that involve x at the program point foo:::ENTER (any of the 3 params can be omitted, e.g. OneOf@foo:::ENTER)- Throws:
IllegalArgumentException
- if arg is not of the proper syntax
-
print_invariants
@RequiresNonNull("FileIO.new_decl_format") public static void print_invariants(PptMap all_ppts)
-
print_invariants_maybe
@RequiresNonNull("FileIO.new_decl_format") public static void print_invariants_maybe(PptTopLevel ppt, PrintWriter out, PptMap all_ppts)
Print invariants for a single program point and its conditionals. Does no output if no samples or no views.
-
print_sample_data
@RequiresNonNull("FileIO.new_decl_format") public static void print_sample_data(PptTopLevel ppt, PrintWriter out)
Prints the program point name. If Daikon.output_num_samples is enabled, prints the number of samples for the specified ppt. Also prints all of the variables for the ppt if Daikon.output_num_samples is enabled or the format is ESCJAVA, JML, or DBCJAVA.
-
print_modified_vars
public static void print_modified_vars(PptTopLevel ppt, PrintWriter out)
Prints all variables that were modified if the format is ESCJAVA or DBCJAVA.
-
count_global_stats
public static void count_global_stats(PptTopLevel ppt)
Count statistics (via Global) on variables (canonical, missing, etc.)
-
print_invariant
@RequiresNonNull("FileIO.new_decl_format") public static void print_invariant(Invariant inv, PrintWriter out, int invCounter, PptTopLevel ppt)
Prints the specified invariant to out.
-
parse_csharp_invariant_variable
public static String parse_csharp_invariant_variable(VarInfo varInfo, boolean sort)
Parses the variables from varInfo.- Parameters:
varInfo
- the Daikon variable representation to parsesort
- true to parse as a grouping variable, false to parse as a filtering variable- Returns:
- the parsed variable string
-
get_csharp_invariant_variables
public static void get_csharp_invariant_variables(VarInfo[] vars, Set<String> variables, boolean sort)
Parses the variables from vars.- Parameters:
vars
- an array of Daikon variable representationsvariables
- the set to store the parsed variablessort
- true to parse as group variables, false to parse as filtering variables
-
get_csharp_invariant_variables
public static void get_csharp_invariant_variables(Invariant invariant, Set<String> variables, boolean group)
Parses the invariant variables of invariant and stores them in variables If group is true the invariant's grouping variables are parsed (the variables which the invariant is grouped by in the contract list view). If group is false the invariant's filtering variables are parsed (the variables for which this invariant can be filtered by). In the case of implications, only variables on the right side of the implication are parsed.- Parameters:
invariant
- the invariant to parsevariables
- the set to store the parsed variablesgroup
- true to parse group variables, false to parse filtering variables
-
get_csharp_inv_type
public static String get_csharp_inv_type(Invariant invariant)
Gets the invariant type string (i.e. daikon.inv.binary.inv) of a Daikon invariant.- Parameters:
invariant
- the Daikon invariant- Returns:
- the invariant type string of the invariant
-
sort_invariant_list
public static List<Invariant> sort_invariant_list(List<Invariant> invs)
Takes a list of Invariants and returns a list of Invariants that is sorted according to PptTopLevel.icfp.- Parameters:
invs
- a list of Invariants- Returns:
- a sorted list of the Invariants
-
print_invariants
@RequiresNonNull("FileIO.new_decl_format") public static void print_invariants(PptTopLevel ppt, PrintWriter out, PptMap ppt_map)
Print invariants for a single program point, once we know that this ppt is worth printing.
-
print_all_ternary_invs
public static void print_all_ternary_invs(PptMap all_ppts)
Prints all invariants for ternary slices (organized by slice) and all of the unary and binary invariants over the same variables. The purpose of this is to look for possible ni-suppressions. It's not intended as a normal output mechanism.
-
print_all_invs
public static void print_all_invs(PptTopLevel ppt, VarInfo vi, String indent)
Prints all of the unary invariants over the specified variable.
-
print_all_invs
public static void print_all_invs(PptTopLevel ppt, VarInfo v1, VarInfo v2, String indent)
Prints all of the binary invariants over the specified variables.
-
print_all_invs
public static void print_all_invs(@Nullable PptSlice slice, String indent)
Prints all of the invariants in the specified slice.
-
print_filter_stats
public static void print_filter_stats(Logger log, PptTopLevel ppt, PptMap ppt_map)
Prints how many invariants are filtered by each filter.
-
print_true_inv_cnt
@RequiresNonNull({"daikon.suppress.NIS.all_suppressions","daikon.suppress.NIS.suppressor_map"}) public static void print_true_inv_cnt(PptMap ppts)
-
-