Package daikon.inv
Class Equality
-
- All Implemented Interfaces:
Serializable
,Cloneable
public final class Equality extends Invariant
Keeps track of sets of variables that are equal. Other invariants are instantiated for only one member of the Equality set, the leader. If variablesx
,y
, andz
are members of the Equality set andx
is chosen as the leader, then the Equality will internally convert into binary comparison invariants that print asx == y
andx == z
.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class Invariant
Invariant.ClassVarnameComparator, Invariant.ClassVarnameFormulaComparator, Invariant.InvariantComparatorForPrinting, Invariant.Match
-
-
Field Summary
Fields Modifier and Type Field Description static Logger
debug
static Logger
debugPostProcess
-
Fields inherited from class Invariant
CONFIDENCE_JUSTIFIED, CONFIDENCE_NEVER, CONFIDENCE_UNJUSTIFIED, debugFlow, debugGuarding, debugIsObvious, debugIsWorthPrinting, debugPrint, debugPrintEquality, dkconfig_confidence_limit, dkconfig_fuzzy_ratio, dkconfig_simplify_define_predicates, falsified, invariantEnabledDefault, isGuardingPredicate, min_mod_non_missing_samples, ppt, PROBABILITY_JUSTIFIED, PROBABILITY_NEVER, PROBABILITY_UNJUSTIFIED
-
-
Constructor Summary
Constructors Constructor Description Equality(Collection<VarInfo> variables, PptSlice ppt)
Creates a new Equality invariant.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<VarInfo>
add(ValueTuple vt, int count)
Return a List of VarInfos that do not fit into this set anymore.double
computeConfidence()
Always return JUSTIFIED because we aggregate EqualityComparison invariants that are all justified to the confidence_limit threshold.boolean
enabled()
Returns whether or not this class of invariants is currently enabled.String
format_daikon()
String
format_esc()
String
format_java()
String
format_java_family(OutputFormat format)
String
format_simplify()
String
format_using(OutputFormat format)
Return a printed representation of this invariant, in the given format.Set<VarInfo>
getVars()
Returns the variables in their index order.boolean
hasNonCanonicalVariable()
protected Equality
instantiate_dyn(PptSlice slice)
Instantiates (creates) an invariant of the same class on the specified slice.boolean
isSameFormula(Invariant other)
Returns true iff the two invariants represent the same mathematical formula.VarInfo
leader()
Return the canonical VarInfo of this.int
numSamples()
void
pivot()
Switch the leader of this invariant, if possible, to a more canonical VarInfo: a VarInfo that is not isDerived() is better than one that is; one that is not isDerivedParamAndUninteresting() is better than one that is; and other things being equal, choose the least complex name.void
postProcess()
Convert Equality invariants into normal IntEqual type for filtering, printing, etc.void
repCheck()
Check the rep invariants of this.String
repr()
For printing invariants, there are two interfaces: repr gives a low-level representation (Invariant.repr_prob()
also prints the confidence), andInvariant.format()
gives a high-level representation for user output.protected Invariant
resurrect_done(int[] permutation)
Called on the new invariant just before resurrect() returns it to allow subclasses to fix any information they might have cached from the old Ppt and VarInfos.void
setSamples(int sample_cnt)
String
shortString()
int
size()
Returns the number of variables in the set.String
toString()
boolean
valid_types(VarInfo[] vis)
Returns whether or not the invariant is valid over the basic types in vis.-
Methods inherited from class Invariant
add_sample, asInvClass, checkRep, clear_falsified, clone, clone_and_permute, conf_is_ge, confidence_and, confidence_and, confidence_or, createGuardedInvariant, createGuardingPredicate, enoughSamples, falsify, find, format, format_classname, format_too_few_samples, format_unimplemented, formatFuzzy, get_comparability, get_ni_suppressions, getConfidence, getGuardingList, getGuardingList, hasUninterestingConstant, instantiate, instantiate_ok, is_false, is_ni_suppressed, isActive, isAllPrestate, isEqualityComparison, isExact, isExclusiveFormula, isObvious, isObviousDynamically, isObviousDynamically, isObviousDynamically_SomeInEquality, isObviousDynamically_SomeInEqualityHelper, isObviousStatically, isObviousStatically, isObviousStatically_AllInEquality, isObviousStatically_SomeInEquality, isObviousStatically_SomeInEqualityHelper, isReflexive, isSameInvariant, isValidEscExpression, isValidExpression, isWorthPrinting, justified, log, log, logDetail, logOn, match, merge, mergeFormulasOk, permute, prob_and, prob_and, prob_is_ge, prob_or, repr_prob, resurrect, simplify_format_double, simplify_format_long, simplify_format_string, state_match, toString, transfer, usesVar, usesVar, usesVarDerived, varNames
-
-
-
-
Field Detail
-
debugPostProcess
public static final Logger debugPostProcess
-
-
Constructor Detail
-
Equality
public Equality(Collection<VarInfo> variables, PptSlice ppt)
Creates a new Equality invariant.- Parameters:
variables
- variables that are equivalent, with the canonical one firstppt
- the program point
-
-
Method Detail
-
setSamples
public void setSamples(int sample_cnt)
-
numSamples
public int numSamples(@GuardSatisfied Equality this)
-
size
@Pure public int size(@GuardSatisfied Equality this)
Returns the number of variables in the set.
-
leader
@Pure public VarInfo leader(@GuardSatisfied @UnknownInitialization(Equality.class) Equality this)
Return the canonical VarInfo of this. Note that the leader never changes.- Returns:
- the canonical VarInfo of this
-
hasNonCanonicalVariable
public boolean hasNonCanonicalVariable()
-
computeConfidence
public double computeConfidence()
Always return JUSTIFIED because we aggregate EqualityComparison invariants that are all justified to the confidence_limit threshold.- Specified by:
computeConfidence
in classInvariant
- Returns:
- confidence of this invariant
- See Also:
Invariant.getConfidence()
-
repr
public String repr(@GuardSatisfied Equality this)
Description copied from class:Invariant
For printing invariants, there are two interfaces: repr gives a low-level representation (Invariant.repr_prob()
also prints the confidence), andInvariant.format()
gives a high-level representation for user output.
-
format_using
@SideEffectFree public String format_using(@GuardSatisfied Equality this, OutputFormat format)
Description copied from class:Invariant
Return a printed representation of this invariant, in the given format.- Specified by:
format_using
in classInvariant
-
format_daikon
public String format_daikon(@GuardSatisfied Equality this)
-
format_java
public String format_java()
-
format_esc
public String format_esc(@GuardSatisfied Equality this)
-
format_simplify
public String format_simplify(@GuardSatisfied Equality this)
-
shortString
public String shortString()
-
format_java_family
public String format_java_family(@GuardSatisfied Equality this, OutputFormat format)
-
add
public List<VarInfo> add(ValueTuple vt, int count)
Return a List of VarInfos that do not fit into this set anymore.Originally (8/14/2003), this did not check for the modified bits. It seems however, quite wrong to leave variables in the same equality set when one is missing and the other is not. It's possible we should go farther and break out of the equality set any variable that is missingOutOfBounds (JHP).
- Parameters:
vt
- the newly-observed samplecount
- the number of times the sample is seen- Returns:
- a List of VarInfos that do not fit into this set anymore
-
resurrect_done
protected Invariant resurrect_done(int[] permutation)
Description copied from class:Invariant
Called on the new invariant just before resurrect() returns it to allow subclasses to fix any information they might have cached from the old Ppt and VarInfos.- Specified by:
resurrect_done
in classInvariant
- Parameters:
permutation
- the permutation- Returns:
- the permuted invariant
-
isSameFormula
@Pure public boolean isSameFormula(Invariant other)
Description copied from class:Invariant
Returns true iff the two invariants represent the same mathematical formula. Does not consider the context such as variable names, confidences, sample counts, value counts, or related quantities. As a rule of thumb, if two invariants format the same, this method returns true. Furthermore, in many cases, if an invariant does not involve computed constants (as "x>c" and "y=ax+b" do for constants a, b, and c), then this method vacuously returns true.- Specified by:
isSameFormula
in classInvariant
- Parameters:
other
- the invariant to compare to this one- Returns:
- true iff the two invariants represent the same mathematical formula. Does not consider
-
postProcess
public void postProcess()
Convert Equality invariants into normal IntEqual type for filtering, printing, etc. Add these to parent.If the leader was changed to not be the first member of the group adds leader == leader invariant as well since that invariant is used in suppressions and obvious tests.
-
pivot
public void pivot()
Switch the leader of this invariant, if possible, to a more canonical VarInfo: a VarInfo that is not isDerived() is better than one that is; one that is not isDerivedParamAndUninteresting() is better than one that is; and other things being equal, choose the least complex name. Call this only after postProcess has been called. We do a pivot so that anything that's interesting to be printed gets printed and not filtered out. For example, if a == b and a is the leader, but not interesting, we still want to print f(b) as an invariant. Thus we pivot b to be the leader. Later on, each relevant PptSlice gets pivoted. But not here.
-
repCheck
public void repCheck()
Description copied from class:Invariant
Check the rep invariants of this.
-
enabled
public boolean enabled( Equality this)
Description copied from class:Invariant
Returns whether or not this class of invariants is currently enabled.Its implementation is almost always
return dkconfig_enabled;
.
-
valid_types
public boolean valid_types( Equality this, VarInfo[] vis)
Description copied from class:Invariant
Returns whether or not the invariant is valid over the basic types in vis. This only checks basic types (scalar, string, array, etc) and should match the basic superclasses of invariant (SingleFloat, SingleScalarSequence, ThreeScalar, etc). More complex checks that depend on variable details can be implemented in instantiate_ok().- Specified by:
valid_types
in classInvariant
- See Also:
Invariant.instantiate_ok(VarInfo[])
-
instantiate_dyn
protected Equality instantiate_dyn( Equality this, PptSlice slice)
Description copied from class:Invariant
Instantiates (creates) an invariant of the same class on the specified slice. Must be overridden in each class. Must be used rather thanInvariant.clone()
so that checks inInvariant.instantiate(daikon.PptSlice)
for reasonable invariants are done.The implementation of this method is almost always
return new <em>InvName</em>(slice);
- Specified by:
instantiate_dyn
in classInvariant
- Returns:
- the new invariant
-
-