use of edu.columbia.cs.psl.phosphor.struct.LazyCharArrayObjTags in project phosphor by gmu-swe.
the class MultiDTaintedArrayWithObjTag method boxIfNecessary.
public static final Object boxIfNecessary(final Object in) {
if (in != null && in.getClass().isArray()) {
if (in.getClass().getComponentType().isPrimitive()) {
// Is prim arraytype
Class tmp = in.getClass();
int dims = 0;
while (tmp.isArray()) {
tmp = tmp.getComponentType();
dims++;
}
if (dims > 1) {
// this should never be possible.
Type t = Type.getType(in.getClass());
initWithEmptyTaints((Object[]) in, t.getElementType().getSort(), t.getDimensions());
} else {
if (tmp == Boolean.TYPE)
return new LazyBooleanArrayObjTags((boolean[]) in);
if (tmp == Byte.TYPE)
return new LazyByteArrayObjTags(((byte[]) in));
if (tmp == Character.TYPE)
return new LazyCharArrayObjTags(((char[]) in));
if (tmp == Double.TYPE)
return new LazyDoubleArrayObjTags(((double[]) in));
if (tmp == Float.TYPE)
return new LazyFloatArrayObjTags(((float[]) in));
if (tmp == Integer.TYPE)
return new LazyIntArrayObjTags(((int[]) in));
if (tmp == Long.TYPE)
return new LazyLongArrayObjTags(((long[]) in));
if (tmp == Short.TYPE)
return new LazyShortArrayObjTags(((short[]) in));
throw new IllegalArgumentException();
}
} else if (in.getClass().getComponentType().isArray() && in.getClass().getComponentType().getComponentType().isPrimitive()) {
// THIS array is an prim[][] array
Object[] _in = (Object[]) in;
Class tmp = in.getClass();
while (tmp.isArray()) {
tmp = tmp.getComponentType();
}
if (tmp == Boolean.TYPE) {
LazyBooleanArrayObjTags[] ret = new LazyBooleanArrayObjTags[_in.length];
for (int i = 0; i < _in.length; i++) ret[i] = new LazyBooleanArrayObjTags((boolean[]) _in[i]);
return ret;
}
if (tmp == Byte.TYPE) {
LazyByteArrayObjTags[] ret = new LazyByteArrayObjTags[_in.length];
for (int i = 0; i < _in.length; i++) ret[i] = new LazyByteArrayObjTags((byte[]) _in[i]);
return ret;
}
if (tmp == Character.TYPE) {
LazyCharArrayObjTags[] ret = new LazyCharArrayObjTags[_in.length];
for (int i = 0; i < _in.length; i++) ret[i] = new LazyCharArrayObjTags((char[]) _in[i]);
return ret;
}
if (tmp == Double.TYPE) {
LazyDoubleArrayObjTags[] ret = new LazyDoubleArrayObjTags[_in.length];
for (int i = 0; i < _in.length; i++) ret[i] = new LazyDoubleArrayObjTags((double[]) _in[i]);
return ret;
}
if (tmp == Float.TYPE) {
LazyFloatArrayObjTags[] ret = new LazyFloatArrayObjTags[_in.length];
for (int i = 0; i < _in.length; i++) ret[i] = new LazyFloatArrayObjTags((float[]) _in[i]);
return ret;
}
if (tmp == Integer.TYPE) {
LazyIntArrayObjTags[] ret = new LazyIntArrayObjTags[_in.length];
for (int i = 0; i < _in.length; i++) ret[i] = new LazyIntArrayObjTags((int[]) _in[i]);
return ret;
}
if (tmp == Short.TYPE) {
LazyShortArrayObjTags[] ret = new LazyShortArrayObjTags[_in.length];
for (int i = 0; i < _in.length; i++) ret[i] = new LazyShortArrayObjTags((short[]) _in[i]);
return ret;
}
if (tmp == Long.TYPE) {
LazyLongArrayObjTags[] ret = new LazyLongArrayObjTags[_in.length];
for (int i = 0; i < _in.length; i++) ret[i] = new LazyLongArrayObjTags((long[]) _in[i]);
return ret;
}
throw new UnsupportedOperationException();
} else if (in.getClass().getComponentType().getName().equals("java.lang.Object")) {
Object[] _in = (Object[]) in;
for (int i = 0; i < _in.length; i++) {
_in[i] = boxIfNecessary(_in[i], new HashSet<Object>());
}
}
}
return in;
}
use of edu.columbia.cs.psl.phosphor.struct.LazyCharArrayObjTags in project phosphor by gmu-swe.
the class MultiDTaintedArrayWithObjTag method unboxVal.
public static final Object unboxVal(final Object _in, final int componentType, final int dims) {
if (dims == 0) {
switch(componentType) {
case Type.BOOLEAN:
case Type.BYTE:
case Type.CHAR:
case Type.DOUBLE:
case Type.FLOAT:
case Type.INT:
case Type.LONG:
case Type.SHORT:
return ((LazyArrayObjTags) _in).getVal();
default:
throw new IllegalArgumentException();
}
} else if (dims == 1) {
final Object[] in = (Object[]) _in;
switch(componentType) {
case Type.BOOLEAN:
boolean[][] retz = new boolean[in.length][];
for (int i = 0; i < in.length; i++) if (in[i] != null)
retz[i] = ((LazyBooleanArrayObjTags) in[i]).val;
return retz;
case Type.BYTE:
byte[][] retb = new byte[in.length][];
for (int i = 0; i < in.length; i++) if (in[i] != null)
retb[i] = ((LazyByteArrayObjTags) in[i]).val;
return retb;
case Type.CHAR:
char[][] retc = new char[in.length][];
for (int i = 0; i < in.length; i++) if (in[i] != null)
retc[i] = ((LazyCharArrayObjTags) in[i]).val;
return retc;
case Type.DOUBLE:
double[][] retd = new double[in.length][];
for (int i = 0; i < in.length; i++) if (in[i] != null)
retd[i] = ((LazyDoubleArrayObjTags) in[i]).val;
return retd;
case Type.FLOAT:
float[][] retf = new float[in.length][];
for (int i = 0; i < in.length; i++) if (in[i] != null)
retf[i] = ((LazyFloatArrayObjTags) in[i]).val;
return retf;
case Type.INT:
int[][] reti = new int[in.length][];
for (int i = 0; i < in.length; i++) if (in[i] != null)
reti[i] = ((LazyIntArrayObjTags) in[i]).val;
return reti;
case Type.LONG:
long[][] retl = new long[in.length][];
for (int i = 0; i < in.length; i++) if (in[i] != null)
retl[i] = ((LazyLongArrayObjTags) in[i]).val;
return retl;
case Type.SHORT:
short[][] rets = new short[in.length][];
for (int i = 0; i < in.length; i++) if (in[i] != null)
rets[i] = ((LazyShortArrayObjTags) in[i]).val;
return rets;
}
} else if (dims == 2) {
final Object[][] ina = (Object[][]) _in;
final Object[] in = (Object[]) _in;
switch(componentType) {
case Type.BOOLEAN:
boolean[][][] retz = new boolean[in.length][][];
for (int i = 0; i < in.length; i++) {
retz[i] = new boolean[ina[i].length][];
for (int j = 0; j < ina[i].length; j++) retz[i][j] = ((LazyBooleanArrayObjTags) ina[i][j]).val;
}
return retz;
case Type.BYTE:
byte[][][] retb = new byte[in.length][][];
for (int i = 0; i < in.length; i++) {
retb[i] = new byte[ina[i].length][];
for (int j = 0; j < ina[i].length; j++) retb[i][j] = ((LazyByteArrayObjTags) ina[i][j]).val;
}
return retb;
case Type.CHAR:
char[][][] retc = new char[in.length][][];
for (int i = 0; i < in.length; i++) {
retc[i] = new char[ina[i].length][];
for (int j = 0; j < ina[i].length; j++) retc[i][j] = ((LazyCharArrayObjTags) ina[i][j]).val;
}
return retc;
case Type.DOUBLE:
double[][][] retd = new double[in.length][][];
for (int i = 0; i < in.length; i++) {
retd[i] = new double[ina[i].length][];
for (int j = 0; j < ina[i].length; j++) retd[i][j] = ((LazyDoubleArrayObjTags) ina[i][j]).val;
}
return retd;
case Type.FLOAT:
float[][][] retf = new float[in.length][][];
for (int i = 0; i < in.length; i++) {
retf[i] = new float[ina[i].length][];
for (int j = 0; j < ina[i].length; j++) retf[i][j] = ((LazyFloatArrayObjTags) ina[i][j]).val;
}
return retf;
case Type.INT:
int[][][] reti = new int[in.length][][];
for (int i = 0; i < in.length; i++) {
reti[i] = new int[ina[i].length][];
for (int j = 0; j < ina[i].length; j++) reti[i][j] = ((LazyIntArrayObjTags) ina[i][j]).val;
}
return reti;
case Type.LONG:
long[][][] retl = new long[in.length][][];
for (int i = 0; i < in.length; i++) {
retl[i] = new long[ina[i].length][];
for (int j = 0; j < ina[i].length; j++) retl[i][j] = ((LazyLongArrayObjTags) ina[i][j]).val;
}
return retl;
case Type.SHORT:
short[][][] rets = new short[in.length][][];
for (int i = 0; i < in.length; i++) {
rets[i] = new short[ina[i].length][];
for (int j = 0; j < ina[i].length; j++) rets[i][j] = ((LazyShortArrayObjTags) ina[i][j]).val;
}
return rets;
}
}
throw new IllegalArgumentException();
}
Aggregations