package fr.lifl.stc.stan.dsl; import org.apache.bcel.generic.ObjectType; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.generic.Type; import org.apache.bcel.classfile.Method; class FlowSpecialType extends Type { public static final FlowSpecialType IO = new FlowSpecialType((byte)1337, "IO"); public static final FlowSpecialType STATIC = new FlowSpecialType((byte)123, "STATIC"); public static final FlowSpecialType EXCEPTION = new FlowSpecialType((byte)542, "EXCEPTION"); protected FlowSpecialType(byte x, String name) { super(x, name); } } public class Flow { public int src, dst, link; public Type srcType, dstType; private Method m; private JavaClass c; /* Flow endpoints */ public final static int FLOW_R = 0; public final static int FLOW_E = 1; public final static int FLOW_S = 2; public final static int FLOW_F = 3; public final static int FLOW_THIS = 4; /* * bit 7 6 5 4 3 2 1 0 * entity a (from) S S p p S S p p * entity b (to) S p S p S p S p * type of link V V V V R R R R */ public final static int RPP = 1; public final static int RPS = 2; public final static int RSP = 4; public final static int RSS = 8; public final static int VPP = 16; public final static int VPS = 32; public final static int VSP = 64; public final static int VSS = 128; public Flow(JavaClass c, Method m, int src, int dst, int link) { this.src = src; this.dst = dst; this.m = m; this.c = c; this.link = link; this.srcType = codeToType(src); this.dstType = codeToType(dst); //System.out.println(srcType + "<->" + dstType); } private Type codeToType(int code) { switch (code) { case FLOW_E: return FlowSpecialType.EXCEPTION; case FLOW_S: return FlowSpecialType.STATIC; case FLOW_F: return FlowSpecialType.IO; case FLOW_R: return m.getReturnType(); case FLOW_THIS: return new ObjectType(this.c.getClassName()); default: if ( (code-5) <= m.getArgumentTypes().length ) return this.m.getArgumentTypes()[code-5]; else { System.out.println("IMPLEMENTTTTTT"); return new ObjectType("null"); } } } private String pos2Str(int pos) { switch (pos) { case FLOW_E: return "Exception"; case FLOW_S: return "Static"; case FLOW_F: return "I/O"; case FLOW_R: return "Return"; case FLOW_THIS: return "This"; default: return "Argument #" + (pos-5); } } public String toString() { return srcType + "(" + pos2Str(src) + ") -> " + dstType + "(" + pos2Str(dst) + ")"; } }