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:
parent
b82c58ee03
commit
1ff71b20b4
|
@ -61,9 +61,8 @@ public abstract class AbstractRootMethod extends SyntheticMethod {
|
|||
private Map<ConstantValue, Integer> 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);
|
||||
|
|
|
@ -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<Atom,IField> fakeRootStaticFields = null;
|
||||
private Map<Atom, IField> fakeRootStaticFields = null;
|
||||
|
||||
private Set<IMethod> 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<IMethod> getDeclaredMethods() throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
return Collections.unmodifiableCollection(methods);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue