package fr.lifl.stc.stan.execution.stack; /* * Created on 23 nov. 04 * */ import org.apache.bcel.generic.Type; /** * @author ryl * @author dorina * * Abstract representation of an object/reference */ public class Reference extends JvmType { static public final int ARGUMENT_TYPE = 0, NEW_TYPE = 1, RETURNED_TYPE= 2, CONSTANT_TYPE= 3, NULL_TYPE = 4, THROWN_TYPE = 5, FLUX_TYPE = 6, ARETURN_TYPE = 7; static String types [] = {"A", "N", "R", "C", "N", "E", "F", "r"}; static String parts [] ={"w", "p", "", "s"}; private int internalType; private int id; //line private Type t; // private String typename; private boolean exactType; private boolean hasMultipleParts; Reference secretReference; Reference publicReference; Reference wholeReference; //FIXME to eliminate public Reference (int internalType, int line, Type t, boolean exact){ this(internalType, line, t, exact, JvmType.WHOLE_PART, true); } public Reference (int internalType, int line, Type t, boolean exact, boolean multParts){ this(internalType, line, t, exact, JvmType.WHOLE_PART, multParts, null); } public Reference (int internalType, int line, Type t, boolean exact, int part, boolean multParts){ this(internalType, line, t, exact, part, multParts, null); } public Reference (int internalType, int line, Type t, boolean exact, int part, boolean multParts, Reference wholePart){ super(part); this.internalType = internalType; this.id = line; this.exactType = exact; //this.typename = typename; this.t = t; this.part = part; this.wholeReference = wholePart; this.hasMultipleParts = multParts && (part == JvmType.WHOLE_PART); if(hasMultipleParts()){ secretReference = new Reference(internalType, line, t, exact, SECRET_PART, false, this); publicReference = new Reference(internalType, line, t, exact, PUBLIC_PART, false, this); } } public int getInternalType() { return internalType; } /* (non-Javadoc) * @see fr.lifl.rd2p.jits.tools.ea.execution.stack.Stackable#getType() */ public Type getType() { return Type.OBJECT; } public String getTypeName() { if(t == null) return ""; return t.toString(); } public boolean hasMultipleParts() { return hasMultipleParts; } public Reference getSecret(){ return secretReference; } public Reference getPublic(){ return publicReference; } public Reference getAll() { if(wholeReference!=null) return wholeReference; return this; } public boolean hasSecret() { return secretReference!=null; } public boolean hasPublic() { return publicReference!=null; } public Object clone (){ Reference r = new Reference (internalType,id,t,exactType, part, hasMultipleParts, wholeReference); return r; } public String toHTML() { return "REFERENCE: (" + t + "," + id + ")"; } public boolean equals(Object r) { if (!(r instanceof Reference)) return false; Reference rr = (Reference)r; return (internalType == rr.internalType) && (id == rr.id) && (t == rr.t) && (exactType == rr.exactType) && (part == rr.part); } public int getId() { return id; } public boolean isArgument() { return internalType == ARGUMENT_TYPE; } public boolean isConstant() { return internalType == CONSTANT_TYPE; } public boolean isNull() { return internalType == NULL_TYPE; } public boolean isNew() { return internalType == NEW_TYPE; } public boolean isReturned() { return internalType == RETURNED_TYPE; } public boolean isThrown() { return internalType == THROWN_TYPE; } public boolean isFlux() { return internalType == FLUX_TYPE; } public int typeSize() { return 1; } public boolean isExactType() { return exactType; } public boolean isSecretPart() { return part == SECRET_PART; } public boolean isPublicPart() { return part == PUBLIC_PART; } public boolean isWholePart() { return part == WHOLE_PART; } /* public boolean isPrimitiveArray() { if(t == null) return false; boolean res1 = (t instanceof ArrayType); boolean res2 = false; if(res1) { res2 = ((ArrayType)t).getBasicType() instanceof BasicType; } return res2; } */ public String toString() { //System.out.println("R(" + types[internalType] + "," + id + ","); //System.out.println(""+parts[part]+")"); return "R(" + types[internalType] + "," + id + ","+parts[part]+")"; } }