support method lookup in FakeRootClass

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3010 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2008-08-25 14:21:14 +00:00
parent b82c58ee03
commit 1ff71b20b4
2 changed files with 25 additions and 10 deletions

View File

@ -61,9 +61,8 @@ public abstract class AbstractRootMethod extends SyntheticMethod {
private Map<ConstantValue, Integer> constant2ValueNumber = HashMapFactory.make(); private Map<ConstantValue, Integer> constant2ValueNumber = HashMapFactory.make();
/** /**
* The number of the next local value number available for the fake root * The number of the next local value number available for the fake root method. Note that we reserve value number 1 to represent
* method. Note that we reserve value number 1 to represent the value "any * the value "any exception caught by the root method"
* exception caught by the root method"
*/ */
protected int nextLocal = 2; protected int nextLocal = 2;
@ -79,6 +78,11 @@ public abstract class AbstractRootMethod extends SyntheticMethod {
this.cha = cha; this.cha = cha;
this.options = options; this.options = options;
this.cache = cache; 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; assert cache != null;
} }

View File

@ -13,6 +13,7 @@ package com.ibm.wala.ipa.callgraph.impl;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set;
import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.IField; import com.ibm.wala.classLoader.IField;
@ -26,14 +27,13 @@ import com.ibm.wala.types.Selector;
import com.ibm.wala.types.TypeName; import com.ibm.wala.types.TypeName;
import com.ibm.wala.types.TypeReference; import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.collections.HashMapFactory; 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.Assertions;
import com.ibm.wala.util.debug.UnimplementedError; import com.ibm.wala.util.debug.UnimplementedError;
import com.ibm.wala.util.strings.Atom; import com.ibm.wala.util.strings.Atom;
/** /**
* A synthetic class for the fake root method * A synthetic class for the fake root method
*
* @author sfink
*/ */
public class FakeRootClass extends SyntheticClass { public class FakeRootClass extends SyntheticClass {
public static final TypeReference FAKE_ROOT_CLASS = TypeReference.findOrCreate(ClassLoaderReference.Primordial, TypeName public static final TypeReference FAKE_ROOT_CLASS = TypeReference.findOrCreate(ClassLoaderReference.Primordial, TypeName
@ -41,10 +41,16 @@ public class FakeRootClass extends SyntheticClass {
private Map<Atom, IField> fakeRootStaticFields = null; private Map<Atom, IField> fakeRootStaticFields = null;
private Set<IMethod> methods = HashSetFactory.make();
FakeRootClass(IClassHierarchy cha) { FakeRootClass(IClassHierarchy cha) {
super(FAKE_ROOT_CLASS, cha); super(FAKE_ROOT_CLASS, cha);
} }
public void addMethod(IMethod m) {
methods.add(m);
}
public void addStaticField(final Atom name, final TypeReference fieldType) { public void addStaticField(final Atom name, final TypeReference fieldType) {
if (fakeRootStaticFields == null) { if (fakeRootStaticFields == null) {
fakeRootStaticFields = HashMapFactory.make(2); 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) * @see com.ibm.wala.classLoader.IClass#getMethod(com.ibm.wala.classLoader.Selector)
*/ */
public IMethod getMethod(Selector selector) throws UnsupportedOperationException { 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() * @see com.ibm.wala.classLoader.IClass#getDeclaredMethods()
*/ */
public Collection<IMethod> getDeclaredMethods() throws UnsupportedOperationException { public Collection<IMethod> getDeclaredMethods() throws UnsupportedOperationException {
throw new UnsupportedOperationException(); return Collections.unmodifiableCollection(methods);
} }
/* /*