Search in sources :

Example 1 with UnopStmt

use of com.googlecode.dex2jar.ir.stmt.UnopStmt in project dex2jar by pxb1988.

the class ConstTransformerTest method test04.

@Test
public void test04() {
    IrMethod jm = new IrMethod();
    Local a = nLocal("a");
    Local b = nLocal("b");
    Local p = nLocal("p");
    jm.locals.add(a);
    jm.locals.add(b);
    jm.locals.add(p);
    jm.stmts.add(nAssign(a, nString(new String("a String"))));
    jm.stmts.add(nAssign(b, nString(new String("a String"))));
    jm.stmts.add(nAssign(p, Exprs.nPhi(a, b)));
    UnopStmt retStmt = nReturn(p);
    jm.stmts.add(retStmt);
    new ConstTransformer().transform(jm);
    Assert.assertTrue(jm.locals.size() == 3);
    Assert.assertTrue(jm.stmts.getSize() == 4);
    Assert.assertEquals(VT.CONSTANT, retStmt.op.vt);
}
Also used : ConstTransformer(com.googlecode.dex2jar.ir.ts.ConstTransformer) Exprs.nLocal(com.googlecode.dex2jar.ir.expr.Exprs.nLocal) Local(com.googlecode.dex2jar.ir.expr.Local) Exprs.nString(com.googlecode.dex2jar.ir.expr.Exprs.nString) IrMethod(com.googlecode.dex2jar.ir.IrMethod) UnopStmt(com.googlecode.dex2jar.ir.stmt.UnopStmt) Test(org.junit.Test)

Example 2 with UnopStmt

use of com.googlecode.dex2jar.ir.stmt.UnopStmt in project dex2jar by pxb1988.

the class ConstTransformerTest method test00.

@Test
public void test00() {
    IrMethod jm = new IrMethod();
    Local a = nLocal("a");
    jm.locals.add(a);
    jm.stmts.add(nAssign(a, nString("a String")));
    UnopStmt retStmt = nReturn(a);
    jm.stmts.add(retStmt);
    new ConstTransformer().transform(jm);
    Assert.assertTrue(jm.locals.size() == 1);
    Assert.assertTrue(jm.stmts.getSize() == 2);
    Assert.assertEquals("a String", ((Constant) retStmt.op.trim()).value);
}
Also used : ConstTransformer(com.googlecode.dex2jar.ir.ts.ConstTransformer) Exprs.nLocal(com.googlecode.dex2jar.ir.expr.Exprs.nLocal) Local(com.googlecode.dex2jar.ir.expr.Local) IrMethod(com.googlecode.dex2jar.ir.IrMethod) UnopStmt(com.googlecode.dex2jar.ir.stmt.UnopStmt) Test(org.junit.Test)

Example 3 with UnopStmt

use of com.googlecode.dex2jar.ir.stmt.UnopStmt in project dex2jar by pxb1988.

the class ConstTransformerTest method test01.

@Test
public void test01() {
    // local in phi
    IrMethod jm = new IrMethod();
    Local a = nLocal("a");
    Local p = nLocal("p");
    jm.locals.add(a);
    jm.locals.add(p);
    jm.stmts.add(nAssign(a, nString("a String")));
    jm.stmts.add(nAssign(p, Exprs.nPhi(a)));
    UnopStmt retStmt = nReturn(p);
    jm.stmts.add(retStmt);
    new ConstTransformer().transform(jm);
    Assert.assertTrue(jm.locals.size() == 2);
    Assert.assertTrue(jm.stmts.getSize() == 3);
    Assert.assertEquals("a String", ((Constant) retStmt.op.trim()).value);
}
Also used : ConstTransformer(com.googlecode.dex2jar.ir.ts.ConstTransformer) Exprs.nLocal(com.googlecode.dex2jar.ir.expr.Exprs.nLocal) Local(com.googlecode.dex2jar.ir.expr.Local) IrMethod(com.googlecode.dex2jar.ir.IrMethod) UnopStmt(com.googlecode.dex2jar.ir.stmt.UnopStmt) Test(org.junit.Test)

Example 4 with UnopStmt

use of com.googlecode.dex2jar.ir.stmt.UnopStmt in project dex2jar by pxb1988.

the class ConstTransformerTest method test02.

@Test
public void test02() {
    // test local loop
    IrMethod jm = new IrMethod();
    Local a = nLocal("a");
    Local p = nLocal("p");
    Local q = nLocal("q");
    jm.locals.add(a);
    jm.locals.add(p);
    jm.locals.add(q);
    jm.stmts.add(nAssign(a, nString("a String")));
    jm.stmts.add(nAssign(p, Exprs.nPhi(a, q)));
    jm.stmts.add(nAssign(q, Exprs.nPhi(p)));
    UnopStmt retStmt = nReturn(q);
    jm.stmts.add(retStmt);
    new ConstTransformer().transform(jm);
    Assert.assertTrue(jm.locals.size() == 3);
    Assert.assertTrue(jm.stmts.getSize() == 4);
    Assert.assertEquals("a String", ((Constant) retStmt.op.trim()).value);
}
Also used : ConstTransformer(com.googlecode.dex2jar.ir.ts.ConstTransformer) Exprs.nLocal(com.googlecode.dex2jar.ir.expr.Exprs.nLocal) Local(com.googlecode.dex2jar.ir.expr.Local) IrMethod(com.googlecode.dex2jar.ir.IrMethod) UnopStmt(com.googlecode.dex2jar.ir.stmt.UnopStmt) Test(org.junit.Test)

Example 5 with UnopStmt

use of com.googlecode.dex2jar.ir.stmt.UnopStmt in project dex2jar by pxb1988.

the class TypeTransformerTest method test1Const.

@Test
public void test1Const() {
    initMethod(true, "F");
    Local b = addLocal("b");
    AssignStmt st1 = addStmt(nAssign(b, nInt(0)));
    UnopStmt st3 = addStmt(nReturn(b));
    transform();
    Assert.assertEquals("", b.valueType, "F");
}
Also used : AssignStmt(com.googlecode.dex2jar.ir.stmt.AssignStmt) Local(com.googlecode.dex2jar.ir.expr.Local) UnopStmt(com.googlecode.dex2jar.ir.stmt.UnopStmt) Test(org.junit.Test)

Aggregations

Local (com.googlecode.dex2jar.ir.expr.Local)6 UnopStmt (com.googlecode.dex2jar.ir.stmt.UnopStmt)6 Test (org.junit.Test)6 IrMethod (com.googlecode.dex2jar.ir.IrMethod)5 Exprs.nLocal (com.googlecode.dex2jar.ir.expr.Exprs.nLocal)5 ConstTransformer (com.googlecode.dex2jar.ir.ts.ConstTransformer)5 Exprs.nString (com.googlecode.dex2jar.ir.expr.Exprs.nString)1 AssignStmt (com.googlecode.dex2jar.ir.stmt.AssignStmt)1