a little immature generics support
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@560 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
64fc9ca803
commit
b85c5fc3a5
|
@ -47,6 +47,7 @@ Export-Package: .,
|
|||
com.ibm.wala.ssa,
|
||||
com.ibm.wala.ssa.analysis,
|
||||
com.ibm.wala.types,
|
||||
com.ibm.wala.types.generics,
|
||||
com.ibm.wala.util,
|
||||
com.ibm.wala.util.bytecode,
|
||||
com.ibm.wala.util.collections,
|
||||
|
|
|
@ -129,8 +129,14 @@ public final class FieldImpl implements IField {
|
|||
public boolean isPublic() {
|
||||
return ((accessFlags & ClassConstants.ACC_PUBLIC) != 0);
|
||||
}
|
||||
|
||||
public boolean isVolatile() {
|
||||
return ((accessFlags & ClassConstants.ACC_VOLATILE) != 0);
|
||||
}
|
||||
|
||||
public ClassHierarchy getClassHierarchy() {
|
||||
return declaringClass.getClassHierarchy();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -37,9 +37,13 @@ public interface IMember extends IClassHierarchyDweller {
|
|||
Atom getName();
|
||||
|
||||
/**
|
||||
* Is this method static?
|
||||
* @return boolean
|
||||
* Is this member static?
|
||||
*/
|
||||
boolean isStatic();
|
||||
|
||||
/**
|
||||
* Is this member volatile?
|
||||
*/
|
||||
boolean isVolatile();
|
||||
|
||||
}
|
||||
|
|
|
@ -120,6 +120,11 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
|
|||
* Exception types this method might throw. Computed on demand.
|
||||
*/
|
||||
private TypeReference[] exceptionTypes;
|
||||
|
||||
/**
|
||||
* the "Signature" attribute; holds information on generics
|
||||
*/
|
||||
protected String genericsSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,7 +207,7 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
|
|||
}
|
||||
|
||||
/**
|
||||
* Method processBytecodes. Do a cheap pass over the bytecodes to collect some
|
||||
* Do a cheap pass over the bytecodes to collect some
|
||||
* mapping information. Some methods require this as a pre-req to accessing
|
||||
* ShrikeCT information.
|
||||
*
|
||||
|
@ -215,6 +220,7 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
|
|||
}
|
||||
bcInfo = new BytecodeInfo();
|
||||
bcInfo.exceptionTypes = computeDeclaredExceptions();
|
||||
bcInfo.genericsSignature = computeGenericsSignature();
|
||||
|
||||
if (isNative()) {
|
||||
return;
|
||||
|
@ -417,6 +423,10 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
|
|||
public boolean isFinal() {
|
||||
return ((getModifiers() & Constants.ACC_FINAL) != 0);
|
||||
}
|
||||
|
||||
public boolean isVolatile() {
|
||||
return ((getModifiers() & Constants.ACC_VOLATILE) != 0);
|
||||
}
|
||||
|
||||
public boolean isSynchronized() {
|
||||
return ((getModifiers() & Constants.ACC_SYNCHRONIZED) != 0);
|
||||
|
@ -838,6 +848,8 @@ public abstract class ShrikeBTMethod implements IMethod, BytecodeConstants {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String computeGenericsSignature() throws InvalidClassFileException;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
|
|
@ -19,8 +19,10 @@ import com.ibm.wala.shrikeCT.ExceptionsReader;
|
|||
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
||||
import com.ibm.wala.shrikeCT.LineNumberTableReader;
|
||||
import com.ibm.wala.shrikeCT.LocalVariableTableReader;
|
||||
import com.ibm.wala.shrikeCT.SignatureReader;
|
||||
import com.ibm.wala.shrikeCT.ClassReader.AttrIterator;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.types.generics.MethodTypeSignature;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +31,7 @@ import com.ibm.wala.util.debug.Assertions;
|
|||
*
|
||||
* @author sfink
|
||||
*/
|
||||
public final class ShrikeCTMethod extends ShrikeBTMethod {
|
||||
public final class ShrikeCTMethod extends ShrikeBTMethod implements IMethod {
|
||||
|
||||
/**
|
||||
* The index of this method in the declaring class's method list according to
|
||||
|
@ -41,7 +43,7 @@ public final class ShrikeCTMethod extends ShrikeBTMethod {
|
|||
* JVM-level modifiers for this method a value of -1 means "uninitialized"
|
||||
*/
|
||||
private int modifiers = -1;
|
||||
|
||||
|
||||
private final ClassHierarchy cha;
|
||||
|
||||
public ShrikeCTMethod(IClass klass, int index) {
|
||||
|
@ -131,7 +133,6 @@ public final class ShrikeCTMethod extends ShrikeBTMethod {
|
|||
bcInfo.localVariableMap = LocalVariableTableReader.makeVarMap(cr);
|
||||
}
|
||||
|
||||
|
||||
public String getLocalVariableName(int bcIndex, int localNumber) {
|
||||
if (bcInfo == null) {
|
||||
try {
|
||||
|
@ -198,7 +199,7 @@ public final class ShrikeCTMethod extends ShrikeBTMethod {
|
|||
}
|
||||
|
||||
private ClassReader getClassReader() {
|
||||
return ((ShrikeClass)getDeclaringClass()).getReader();
|
||||
return ((ShrikeClass) getDeclaringClass()).getReader();
|
||||
}
|
||||
|
||||
private CodeReader getCodeReader() {
|
||||
|
@ -239,6 +240,34 @@ public final class ShrikeCTMethod extends ShrikeBTMethod {
|
|||
return result;
|
||||
}
|
||||
|
||||
private SignatureReader getSignatureReader() {
|
||||
ClassReader.AttrIterator iter = new AttrIterator();
|
||||
getClassReader().initMethodAttributeIterator(shrikeMethodIndex, iter);
|
||||
|
||||
// search for the desired attribute
|
||||
SignatureReader result = null;
|
||||
try {
|
||||
for (; iter.isValid(); iter.advance()) {
|
||||
if (iter.getName().toString().equals("Signature")) {
|
||||
result = new SignatureReader(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (InvalidClassFileException e) {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String computeGenericsSignature() throws InvalidClassFileException {
|
||||
SignatureReader reader = getSignatureReader();
|
||||
if (reader == null) {
|
||||
return null;
|
||||
} else {
|
||||
return reader.getSignature();
|
||||
}
|
||||
}
|
||||
|
||||
public TypeReference getReturnType() {
|
||||
return getReference().getReturnType();
|
||||
}
|
||||
|
@ -246,4 +275,29 @@ public final class ShrikeCTMethod extends ShrikeBTMethod {
|
|||
public ClassHierarchy getClassHierarchy() {
|
||||
return cha;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return raw "Signature" attribute from the bytecode
|
||||
*/
|
||||
private String getGenericsSignature() {
|
||||
if (bcInfo == null) {
|
||||
try {
|
||||
processBytecodes();
|
||||
} catch (InvalidClassFileException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
}
|
||||
return bcInfo.genericsSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
* UNDER CONSTRUCTION
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public MethodTypeSignature getMethodTypeSignature() {
|
||||
String sig = getGenericsSignature();
|
||||
return sig == null ? null : MethodTypeSignature.make(sig);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -837,4 +837,35 @@ public final class ShrikeClass implements IClass {
|
|||
boolean result = ((modifiers & Constants.ACC_PUBLIC) != 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
// private SignatureReader getSignatureReader() throws InvalidClassFileException {
|
||||
// ClassReader r = reader.get();
|
||||
// ClassReader.AttrIterator attrs = new ClassReader.AttrIterator();
|
||||
// r.initClassAttributeIterator(attrs);
|
||||
//
|
||||
// // search for the desired attribute
|
||||
// SignatureReader result = null;
|
||||
// try {
|
||||
// for (; attrs.isValid(); attrs.advance()) {
|
||||
// if (attrs.getName().toString().equals("Signature")) {
|
||||
// result = new SignatureReader(attrs);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// } catch (InvalidClassFileException e) {
|
||||
// Assertions.UNREACHABLE();
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// public ParameterizedTypeReference getGenericType() throws InvalidClassFileException {
|
||||
// // TODO: cache this later?
|
||||
// SignatureReader r = getSignatureReader();
|
||||
// if (r == null) {
|
||||
// return ParameterizedTypeReference.makeRaw(getReference());
|
||||
// } else {
|
||||
// System.err.println("parse for " + getReference());
|
||||
// return StringStuff.parseForGenericType(r.getSignature());
|
||||
// }
|
||||
// }
|
||||
}
|
|
@ -119,6 +119,13 @@ public class SyntheticMethod implements IMethod {
|
|||
public boolean isFinal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.ibm.wala.classLoader.IMethod#isVolatile()
|
||||
*/
|
||||
public boolean isVolatile() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.ibm.wala.classLoader.IMethod#isAbstract()
|
||||
|
|
Loading…
Reference in New Issue