001// ***** This file is automatically generated from SequencesIntersectionFactory.java.jpp
002
003package daikon.derive.binary;
004
005import org.checkerframework.checker.nullness.qual.Nullable;
006import daikon.*;
007import daikon.derive.Derivation;
008import java.util.logging.Level;
009import java.util.logging.Logger;
010import org.checkerframework.checker.nullness.qual.Nullable;
011
012// This controls derivations which use the scalar as an index into the
013// sequence, such as getting the element at that index or a subsequence up
014// to that index.
015
016public final class SequenceScalarIntersectionFactory extends BinaryDerivationFactory {
017
018  /** Debug tracer. */
019  private static final Logger debug =
020    Logger.getLogger("daikon.derive.binary.SequenceScalarIntersectionFactory");
021
022  @Override
023  public BinaryDerivation @Nullable [] instantiate(VarInfo seq1, VarInfo seq2) {
024
025    if (!SequenceScalarIntersection.dkconfig_enabled) {
026      return null;
027    }
028
029    if ((seq1.rep_type != ProglangType.INT_ARRAY) || (seq2.rep_type != ProglangType.INT_ARRAY)) {
030      return null;
031    }
032
033    // Intersect only sets with the same declared element type
034    if (!seq1.type.base().equals(seq2.type.base())) {
035      return null;
036    }
037
038    // For now, do nothing if the sequences are derived.
039    //    if ((seq1.derived != null) || (seq2.derived != null))
040    //  return null;
041
042    // We allow double derivations of predicate slices because it may be interesting
043    if ((seq1.derived != null)) {
044      Derivation derivation = seq1.derived;
045      if (!(derivation instanceof SequencesPredicate)) {
046        return null;
047      }
048    }
049
050    if ((seq2.derived != null)) {
051      Derivation derivation = seq2.derived;
052      if (!(derivation instanceof SequencesPredicate)) {
053        return null;
054      }
055    }
056
057    if (debug.isLoggable(Level.FINE)) {
058      debug.fine("Instantiatiating " + seq1.name() + " and " + seq2.name());
059      debug.fine("  in " + seq1.ppt.name());
060    }
061
062    return new BinaryDerivation[] {new SequenceScalarIntersection(seq1, seq2)};
063  }
064}