From 1ff71b20b47cd4e74cbb381e067f6b54253ea7e7 Mon Sep 17 00:00:00 2001 From: sjfink Date: Mon, 25 Aug 2008 14:21:14 +0000 Subject: [PATCH] support method lookup in FakeRootClass git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3010 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../callgraph/impl/AbstractRootMethod.java | 14 ++++++++----- .../ipa/callgraph/impl/FakeRootClass.java | 21 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/AbstractRootMethod.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/AbstractRootMethod.java index 84540886c..ef696b4e5 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/AbstractRootMethod.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/AbstractRootMethod.java @@ -61,9 +61,8 @@ public abstract class AbstractRootMethod extends SyntheticMethod { private Map constant2ValueNumber = HashMapFactory.make(); /** - * The number of the next local value number available for the fake root - * method. Note that we reserve value number 1 to represent the value "any - * exception caught by the root method" + * The number of the next local value number available for the fake root method. Note that we reserve value number 1 to represent + * the value "any exception caught by the root method" */ protected int nextLocal = 2; @@ -79,6 +78,11 @@ public abstract class AbstractRootMethod extends SyntheticMethod { this.cha = cha; this.options = options; this.cache = cache; + // I'd like to enforce that declaringClass is a FakeRootClass ... but CASt would currently break. + // so checking dynamically instead. + if (declaringClass instanceof FakeRootClass) { + ((FakeRootClass)declaringClass).addMethod(this); + } assert cache != null; } @@ -260,7 +264,7 @@ public abstract class AbstractRootMethod extends SyntheticMethod { } return result; } - + protected int getValueNumberForByteConstant(byte c) { // treat it like an int constant for now. ConstantValue v = new ConstantValue(c); @@ -271,7 +275,7 @@ public abstract class AbstractRootMethod extends SyntheticMethod { } return result; } - + protected int getValueNumberForCharConstant(char c) { // treat it like an int constant for now. ConstantValue v = new ConstantValue(c); diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/FakeRootClass.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/FakeRootClass.java index 5f8118dce..5dcbb7574 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/FakeRootClass.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/FakeRootClass.java @@ -13,6 +13,7 @@ package com.ibm.wala.ipa.callgraph.impl; import java.util.Collection; import java.util.Collections; import java.util.Map; +import java.util.Set; import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IField; @@ -26,25 +27,30 @@ import com.ibm.wala.types.Selector; import com.ibm.wala.types.TypeName; import com.ibm.wala.types.TypeReference; import com.ibm.wala.util.collections.HashMapFactory; +import com.ibm.wala.util.collections.HashSetFactory; import com.ibm.wala.util.debug.Assertions; import com.ibm.wala.util.debug.UnimplementedError; import com.ibm.wala.util.strings.Atom; /** * A synthetic class for the fake root method - * - * @author sfink */ public class FakeRootClass extends SyntheticClass { public static final TypeReference FAKE_ROOT_CLASS = TypeReference.findOrCreate(ClassLoaderReference.Primordial, TypeName .string2TypeName("Lcom/ibm/wala/FakeRootClass")); - private Map fakeRootStaticFields = null; + private Map fakeRootStaticFields = null; + + private Set methods = HashSetFactory.make(); FakeRootClass(IClassHierarchy cha) { super(FAKE_ROOT_CLASS, cha); } + public void addMethod(IMethod m) { + methods.add(m); + } + public void addStaticField(final Atom name, final TypeReference fieldType) { if (fakeRootStaticFields == null) { fakeRootStaticFields = HashMapFactory.make(2); @@ -129,7 +135,12 @@ public class FakeRootClass extends SyntheticClass { * @see com.ibm.wala.classLoader.IClass#getMethod(com.ibm.wala.classLoader.Selector) */ public IMethod getMethod(Selector selector) throws UnsupportedOperationException { - throw new UnsupportedOperationException(); + for (IMethod m : methods) { + if (m.getSelector().equals(selector)) { + return m; + } + } + return null; } /* @@ -155,7 +166,7 @@ public class FakeRootClass extends SyntheticClass { * @see com.ibm.wala.classLoader.IClass#getDeclaredMethods() */ public Collection getDeclaredMethods() throws UnsupportedOperationException { - throw new UnsupportedOperationException(); + return Collections.unmodifiableCollection(methods); } /*