001// ***** This file is automatically generated from SequencesUnion.java.jpp 002 003package daikon.derive.binary; 004 005import org.checkerframework.checker.interning.qual.Interned; 006import org.checkerframework.dataflow.qual.Pure; 007import org.checkerframework.dataflow.qual.SideEffectFree; 008import daikon.*; 009import daikon.derive.*; 010import org.plumelib.util.ArraysPlume; 011import org.plumelib.util.Intern; 012 013/** 014 * Represents the setwise union of two base variables, each of which is a collection. This variable 015 * contains every element that is in either of the base variables, but this variable contains no 016 * duplicate elements. Elements are in order of first appearance in the base variables (base1 017 * first). 018 */ 019public final class SequenceStringUnion extends BinaryDerivation { 020 static final long serialVersionUID = 20020122L; 021 022 // Variables starting with dkconfig_ should only be set via the 023 // daikon.config.Configuration interface. 024 /** Boolean. True iff SequenceStringUnion derived variables should be generated. */ 025 public static boolean dkconfig_enabled = false; 026 027 SequenceStringUnion(VarInfo vi1, VarInfo vi2) { 028 super(vi1, vi2); 029 } 030 031 @Override 032 public ValueAndModified computeValueAndModifiedImpl(ValueTuple full_vt) { 033 int mod1 = base1.getModified(full_vt); 034 if (mod1 == ValueTuple.MISSING_NONSENSICAL) { 035 return ValueAndModified.MISSING_NONSENSICAL; 036 } 037 int mod2 = base2.getModified(full_vt); 038 if (mod2 == ValueTuple.MISSING_NONSENSICAL) { 039 return ValueAndModified.MISSING_NONSENSICAL; 040 } 041 Object val1 = base1.getValue(full_vt); 042 if (val1 == null) { 043 return ValueAndModified.MISSING_NONSENSICAL; 044 } 045 @Interned String[] val1_array = (@Interned String[]) val1; 046 Object val2 = base2.getValue(full_vt); 047 if (val2 == null) { 048 return ValueAndModified.MISSING_NONSENSICAL; 049 } 050 @Interned String[] val2_array = (@Interned String[]) val2; 051 052 @Interned String[] tmp = new @Interned String[val1_array.length + val2_array.length]; 053 int size = 0; 054 for (int i = 0; i < val1_array.length; i++) { 055 @Interned String v = val1_array[i]; 056 if ((size == 0) || (ArraysPlume.indexOf(ArraysPlume.subarray(tmp, 0, size), v) == -1)) { 057 tmp[size++] = v; 058 } 059 } 060 for (int i = 0; i < val2_array.length; i++) { 061 @Interned String v = val2_array[i]; 062 if ((size == 0) || (ArraysPlume.indexOf(ArraysPlume.subarray(tmp, 0, size), v) == -1)) { 063 tmp[size++] = v; 064 } 065 } 066 067 @Interned String[] union = ArraysPlume.subarray(tmp, 0, size); 068 union = Intern.intern(union); 069 070 int mod = 071 (((mod1 == ValueTuple.UNMODIFIED) && (mod2 == ValueTuple.UNMODIFIED)) 072 ? ValueTuple.UNMODIFIED 073 : ValueTuple.MODIFIED); 074 return new ValueAndModified(union, mod); 075 } 076 077 @Override 078 protected VarInfo makeVarInfo() { 079 return VarInfo.make_function("union", base1, base2); 080 } 081 082 @Pure 083 @Override 084 public boolean isSameFormula(Derivation other) { 085 return (other instanceof SequenceStringUnion); 086 } 087 088 @SideEffectFree 089 @Override 090 public String esc_name(String index) { 091 return String.format("union(%s,%s)", var1().esc_name(), var2().esc_name()); 092 } 093}