[Soot-list] From PrimType to RefType

Zifei Zhong zfz at cs.utexas.edu
Mon Feb 16 22:07:26 EST 2009


Hi,

I got a problem concerning PrimType.

For example, I have the following piece of code:
int i  = 0;
Object [] obj = new Object[1];
obj[0] = i; // i is IntType

The corresponding jimple code for 'obj[0] = i' would be:
r1 = staticinvoke <java.lang.Integer: java.lang.Integer valueOf(int)>(i2);
obj[0] = r1;

I found it's a little bit tedious to write soot code to do such transforms.
For example, given an arbitrary PrimType 'inputType', what I did is:
    TypeSwitch primTypeSwitch = new TypeSwitch() {
      public void caseBooleanType(BooleanType t) {
          SootClass sootClass = SootUtil.getClass("java.lang.Boolean");
          setResult(sootClass.getMethod("valueOf", Arrays.asList(t)));
      }
      public void caseByteType(ByteType t) {
          SootClass sootClass = SootUtil.getClass("java.lang.Byte");
          setResult(sootClass.getMethod("valueOf", Arrays.asList(t)));
      }
      public void caseCharType(CharType t) {
          SootClass sootClass = SootUtil.getClass("java.lang.Character");
          setResult(sootClass.getMethod("valueOf", Arrays.asList(t)));
      }
      public void caseDoubleType(DoubleType t) {
          SootClass sootClass = SootUtil.getClass("java.lang.Double");
          setResult(sootClass.getMethod("valueOf", Arrays.asList(t)));
      }
     public void caseFloatType(FloatType t) {
          SootClass sootClass = SootUtil.getClass("java.lang.Float");
          setResult(sootClass.getMethod("valueOf", Arrays.asList(t)));
      }
      public void caseIntType(IntType t) {
          SootClass sootClass = SootUtil.getClass("java.lang.Integer");
          setResult(sootClass.getMethod("valueOf", Arrays.asList(t)));
      }
      public void caseLongType(LongType t) {
          SootClass sootClass = SootUtil.getClass("java.lang.Long");
          setResult(sootClass.getMethod("valueOf", Arrays.asList(t)));
      }
      public void caseShortType(ShortType t) {
          SootClass sootClass = SootUtil.getClass("java.lang.Short");
          setResult(sootClass.getMethod("valueOf", Arrays.asList(t)));
      }
      public void defaultCase(Type t) {
          throw new RuntimeException("not a soot primType we are
expecting.");
      }
    };
    inputType.apply(primTypeSwitch); // inputType is an arbitrary PrimType.
    SootMethod sootMethod = (SootMethod) primTypeSwitch.getResult();
    InvokeExpr expr = Jimple.v().newStaticInvokeExpr(sootMethod.makeRef(),
Arrays.asList(value));
    ...

Basically, if it's a IntType, I want to match it to the class
'java.lang.Integer'.

I wonder what is the simplest way of doing this.

Thanks,
Zifei
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20090216/fda4e5b1/attachment.html 


More information about the Soot-list mailing list