001// ***** This file is automatically generated from ThreeScalar.java.jpp
002package daikon.inv.ternary.threeScalar;
003
004import daikon.*;
005import daikon.inv.*;
006import daikon.inv.ternary.TernaryInvariant;
007import org.checkerframework.checker.interning.qual.Interned;
008import org.checkerframework.checker.lock.qual.GuardSatisfied;
009import org.plumelib.util.Intern;
010import typequals.prototype.qual.NonPrototype;
011import typequals.prototype.qual.Prototype;
012
013/**
014 * Abstract base class for invariants over three numeric variables. An example is {@code z = ax + by
015 * + c}.
016 */
017public abstract class ThreeScalar extends TernaryInvariant {
018  // We are Serializable, so we specify a version to allow changes to
019  // method signatures without breaking serialization.  If you add or
020  // remove fields, you should change this number to the current date.
021  static final long serialVersionUID = 20020122L;
022
023  protected ThreeScalar(PptSlice ppt) {
024    super(ppt);
025  }
026
027  protected @Prototype ThreeScalar() {
028    super();
029  }
030
031  /** Returns whether or not the specified types are valid. */
032  @Override
033  public final boolean valid_types(VarInfo[] vis) {
034
035    return ((vis.length == 3)
036            && vis[0].file_rep_type.isScalar()
037            && vis[1].file_rep_type.isScalar()
038            && vis[2].file_rep_type.isScalar());
039  }
040
041  public VarInfo var1(@GuardSatisfied ThreeScalar this) {
042    return ppt.var_infos[0];
043  }
044
045  public VarInfo var2(@GuardSatisfied ThreeScalar this) {
046    return ppt.var_infos[1];
047  }
048
049  public VarInfo var3(@GuardSatisfied ThreeScalar this) {
050    return ppt.var_infos[2];
051  }
052
053  @Override
054  public InvariantStatus check(@Interned Object val1, @Interned Object val2, @Interned Object val3, int mod_index, int count) {
055    // Tests for whether a value is missing should be performed before
056    // making this call, so as to reduce overall work.
057    assert ! falsified;
058    if ((mod_index < 0) || (mod_index > 8)) {
059      assert (mod_index >= 0) && (mod_index < 8)
060        : "var 1 " + ppt.var_infos[0].name() + " value = "
061         + val1 + "mod_index = " +  mod_index;
062    }
063    long v1 = ((Long) val1).longValue();
064    long v2 = ((Long) val2).longValue();
065    if (!(val3 instanceof Long)) {
066      System.out.println("val3 should be PRIMITIVE, but is " + val3.getClass());
067    }
068    long v3 = ((Long) val3).longValue();
069    if (mod_index == 0) {
070      return check_unmodified(v1, v2, v3, count);
071    } else {
072      return check_modified(v1, v2, v3, count);
073    }
074  }
075
076  @Override
077  public InvariantStatus add(@Interned Object val1, @Interned Object val2, @Interned Object val3, int mod_index, int count) {
078    // Tests for whether a value is missing should be performed before
079    // making this call, so as to reduce overall work.
080    assert ! falsified;
081    if ((mod_index < 0) || (mod_index > 8)) {
082      assert (mod_index >= 0) && (mod_index < 8)
083        : "var 1 " + ppt.var_infos[0].name() + " value = "
084         + val1 + "mod_index = " +  mod_index + " line "
085         + FileIO.get_linenum();
086    }
087    long v1 = ((Long) val1).longValue();
088    long v2 = ((Long) val2).longValue();
089    if (!(val3 instanceof Long)) {
090      System.out.printf("val3 should be PRIMITIVE, but is %s=%s, v2 is %s=%s%n",
091              val3.getClass().getName(), Debug.toString(val3),
092              val2.getClass().getName(), Debug.toString(val2));
093      System.out.println("our class = " + this.getClass().getName());
094      System.out.println("our slice = " + this.ppt);
095      PptSlice slice = this.ppt;
096      System.out.printf("var3 reptype = %s%n", slice.var_infos[2].rep_type);
097      assert (slice.var_infos[0].rep_type == ProglangType.INT)
098                  && (slice.var_infos[1].rep_type == ProglangType.INT)
099                  && (slice.var_infos[2].rep_type == ProglangType.INT);
100    }
101    long v3 = ((Long) val3).longValue();
102    if (mod_index == 0) {
103      return add_unmodified(v1, v2, v3, count);
104    } else {
105      return add_modified(v1, v2, v3, count);
106    }
107  }
108
109  /**
110   * Presents a sample to the invariant. Returns whether the sample is consistent with the
111   * invariant. Does not change the state of the invariant.
112   *
113   * @param count how many identical samples were observed in a row. For example, three calls to
114   * check_modified with a count parameter of 1 is equivalent to one call to check_modified with a
115   * count parameter of 3.
116   * @return whether or not the sample is consistent with the invariant
117   */
118  public abstract InvariantStatus check_modified(long v1, long v2, long v3, int count);
119
120  public InvariantStatus check_unmodified(long v1, long v2, long v3, int count) {
121    return InvariantStatus.NO_CHANGE;
122  }
123
124  /**
125   * Similar to {@link #check_modified} except that it can change the state of the invariant if
126   * necessary. If the invariant doesn't have any state, then the implementation should simply call
127   * {@link #check_modified}. This method need not check for falsification; that is done by the
128   * caller.
129   */
130  public abstract InvariantStatus add_modified(long v1, long v2, long v3, int count);
131
132  /** By default, do nothing if the value hasn't been seen yet. Subclasses can override this. */
133  public InvariantStatus add_unmodified(long v1, long v2, long v3, int count) {
134    return InvariantStatus.NO_CHANGE;
135  }
136}