[Soot-list] From PrimType to RefType
Eric Bodden
eric.bodden at mail.mcgill.ca
Tue Feb 17 10:01:05 EST 2009
Hi Zifei.
Yes, to the best of my knowledge there is no easier way to do this
right now. In Soot, auto-boxing and auto-un-boxing is performed in the
AST nodes of the JastAdd frontend. Once the code was converted from
Java to Jimple, there's no built-in functionality for auto-boxing and
auto-un-boxing on the Jimple level unfortunately - at least not any
that I am aware of.
Eric
2009/2/16 Zifei Zhong <zfz at cs.utexas.edu>:
> 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
>
>
>
>
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
>
--
Eric Bodden
Sable Research Group, McGill University
Montréal, Québec, Canada
More information about the Soot-list
mailing list