/** * Find or create an atom. * * @param str atom value, as string literal whose characters are unicode * @return atom */ public static Atom findOrCreateUnicodeAtom(String str) { byte[] utf8 = UTF8Convert.toUTF8(str); return findOrCreate(utf8); }
/** * Return printable representation of "this" atom. */ public final String toUnicodeString() throws java.io.UTFDataFormatException { return UTF8Convert.fromUTF8(val); }
throw new IllegalArgumentException("s is null"); byte[] result = new byte[utfLength(s)]; int result_index = 0; for (int i = 0, n = s.length(); i < n; ++i) {
/** * Find or create an atom. * * @param str atom value, as string literal whose characters are unicode * @return atom */ public static Atom findOrCreateUnicodeAtom(String str) { byte[] utf8 = UTF8Convert.toUTF8(str); return findOrCreate(utf8); }
/** * Return printable representation of "this" atom. */ public final String toUnicodeString() throws java.io.UTFDataFormatException { return UTF8Convert.fromUTF8(val); }
throw new IllegalArgumentException("s is null"); byte[] result = new byte[utfLength(s)]; int result_index = 0; for (int i = 0, n = s.length(); i < n; ++i) {
public static ImmutableByteArray make(String s) { return new ImmutableByteArray(UTF8Convert.toUTF8(s)); }
public static String fromUTF8(ImmutableByteArray s) { if (s == null) { throw new IllegalArgumentException("s is null"); } try { return fromUTF8(s.b); } catch (UTFDataFormatException e) { e.printStackTrace(); Assertions.UNREACHABLE(); return null; } } }
public static ImmutableByteArray make(String s) { return new ImmutableByteArray(UTF8Convert.toUTF8(s)); }
public static String fromUTF8(ImmutableByteArray s) { if (s == null) { throw new IllegalArgumentException("s is null"); } try { return fromUTF8(s.b); } catch (UTFDataFormatException e) { e.printStackTrace(); Assertions.UNREACHABLE(); return null; } } }
/** * @param s string representation of this descriptor * @return the canonical representative for this descriptor value */ public static Descriptor findOrCreateUTF8(Language l, String s) throws IllegalArgumentException { byte[] b = UTF8Convert.toUTF8(s); return findOrCreate(l, new ImmutableByteArray(b)); }
/** * @param s string representation of this descriptor * @return the canonical representative for this descriptor value */ public static Descriptor findOrCreateUTF8(Language l, String s) throws IllegalArgumentException { byte[] b = UTF8Convert.toUTF8(s); return findOrCreate(l, new ImmutableByteArray(b)); }
@Test public void testIR2() { // 'equals' is a nice medium-sized method doMethod(cha.getScope().findMethod(AnalysisScope.APPLICATION, "Ljava/lang/String", Atom.findOrCreateUnicodeAtom("equals"), new ImmutableByteArray(UTF8Convert.toUTF8("(Ljava/lang/Object;)Z")))); }
@Test public void testIR1() { // 'remove' is a nice short method doMethod(cha.getScope().findMethod(AnalysisScope.APPLICATION, "Ljava/util/HashMap", Atom.findOrCreateUnicodeAtom("remove"), new ImmutableByteArray(UTF8Convert.toUTF8("(Ljava/lang/Object;)Ljava/lang/Object;")))); }
@Test public void testIR4() { // test some corner cases with try-finally doMethod(cha.getScope().findMethod(AnalysisScope.APPLICATION, "LcornerCases/TryFinally", Atom.findOrCreateUnicodeAtom("test1"), new ImmutableByteArray(UTF8Convert.toUTF8("(Ljava/io/InputStream;Ljava/io/InputStream;)V")))); } }
@Test public void testIR3() { // 'resolveProxyClass' is a nice long method (at least in Sun libs) doMethod(cha.getScope().findMethod(AnalysisScope.APPLICATION, "Ljava/io/ObjectInputStream", Atom .findOrCreateUnicodeAtom("resolveProxyClass"), new ImmutableByteArray(UTF8Convert .toUTF8("([Ljava/lang/String;)Ljava/lang/Class;")))); }
@Test public void test3() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("inferInt"), new ImmutableByteArray(UTF8Convert.toUTF8("()V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, true); TypeAbstraction type = ti.getType(7); Assert.assertNotNull("null type abstraction", type); Assert.assertTrue("inferred wrong type", type.toString().equals("int")); }
@Test public void test4() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("useCast"), new ImmutableByteArray(UTF8Convert.toUTF8("(Ljava/lang/Object;)V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, false); TypeAbstraction type = ti.getType(4); Assert.assertNotNull("null type abstraction", type); Assert.assertTrue("inferred wrong type " + type, type instanceof ConeType && ((ConeType)type).getTypeReference().getName().toString().equals("Ljava/lang/String")); }
@Test public void test1() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("foo"), new ImmutableByteArray(UTF8Convert.toUTF8("()V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, false); for (int i = 1; i <= ir.getSymbolTable().getMaxValueNumber(); i++) { System.err.println(i + " " + ti.getType(i)); } }
@Test public void test2() { MethodReference method = scope.findMethod(AnalysisScope.APPLICATION, "LtypeInference/TI", Atom.findOrCreateUnicodeAtom("bar"), new ImmutableByteArray(UTF8Convert.toUTF8("(I)V"))); Assert.assertNotNull("method not found", method); IMethod imethod = cha.resolveMethod(method); Assert.assertNotNull("imethod not found", imethod); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); System.out.println(ir); TypeInference ti = TypeInference.make(ir, true); Assert.assertNotNull("null type abstraction for parameter", ti.getType(2)); }