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 variables x, y, and z are members of the Equality set and x is chosen as the leader, then the Equality will internally convert into binary comparison invariants that print as x == y and x == z.
    See Also:
    Serialized Form
    • 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 first
        ppt - 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.
      • getVars

        public Set<VarInfogetVars()
        Returns the variables in their index order. Unmodifiable.
      • 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
      • 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), and Invariant.format() gives a high-level representation for user output.
        Overrides:
        repr in class Invariant
        Returns:
        a string representation of this
      • add

        public List<VarInfoadd​(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 sample
        count - 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 class Invariant
        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 class Invariant
        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.
      • 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;.

        Specified by:
        enabled in class Invariant
      • 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 class Invariant
        See Also:
        Invariant.instantiate_ok(VarInfo[])