FEAT: - type inference is now language-agnostic.
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3600 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
4595806dc9
commit
093cc5a927
|
@ -17,6 +17,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IMethod;
|
||||
import com.ibm.wala.classLoader.Language;
|
||||
import com.ibm.wala.dataflow.ssa.SSAInference;
|
||||
import com.ibm.wala.eclipse.util.CancelException;
|
||||
import com.ibm.wala.eclipse.util.CancelRuntimeException;
|
||||
|
@ -69,6 +70,8 @@ public class TypeInference extends SSAInference<TypeVariable> implements FixedPo
|
|||
* The governing class hierarchy
|
||||
*/
|
||||
final protected IClassHierarchy cha;
|
||||
|
||||
final protected Language language;
|
||||
|
||||
/**
|
||||
* A singleton instance of the phi operator.
|
||||
|
@ -98,6 +101,7 @@ public class TypeInference extends SSAInference<TypeVariable> implements FixedPo
|
|||
if (ir == null) {
|
||||
throw new IllegalArgumentException("ir is null");
|
||||
}
|
||||
this.language = ir.getMethod().getDeclaringClass().getClassLoader().getLanguage();
|
||||
this.cha = ir.getMethod().getDeclaringClass().getClassHierarchy();
|
||||
this.ir = ir;
|
||||
this.doPrimitives = doPrimitives;
|
||||
|
@ -180,7 +184,7 @@ public class TypeInference extends SSAInference<TypeVariable> implements FixedPo
|
|||
if (defaultExceptions.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
assert defaultExceptions.size() == 1;
|
||||
assert (defaultExceptions.size() == 1);
|
||||
// t should be NullPointerException
|
||||
TypeReference t = defaultExceptions.iterator().next();
|
||||
IClass klass = cha.lookupClass(t);
|
||||
|
@ -510,7 +514,7 @@ public class TypeInference extends SSAInference<TypeVariable> implements FixedPo
|
|||
|
||||
@Override
|
||||
public void visitLoadMetadata(SSALoadMetadataInstruction instruction) {
|
||||
IClass jlClassKlass = cha.lookupClass(TypeReference.JavaLangClass);
|
||||
IClass jlClassKlass = cha.lookupClass(language.getMetadataType());
|
||||
assert jlClassKlass != null;
|
||||
result = new DeclaredTypeOperator(new ConeType(jlClassKlass));
|
||||
}
|
||||
|
@ -689,7 +693,7 @@ public class TypeInference extends SSAInference<TypeVariable> implements FixedPo
|
|||
|
||||
public TypeAbstraction getConstantType(int valueNumber) {
|
||||
if (ir.getSymbolTable().isStringConstant(valueNumber)) {
|
||||
return new PointType(cha.lookupClass(TypeReference.JavaLangString));
|
||||
return new PointType(cha.lookupClass(language.getStringType()));
|
||||
} else {
|
||||
return getConstantPrimitiveType(valueNumber);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,80 +1,84 @@
|
|||
package com.ibm.wala.classLoader;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
||||
import com.ibm.wala.ssa.SSAInstructionFactory;
|
||||
import com.ibm.wala.types.MethodReference;
|
||||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.strings.Atom;
|
||||
|
||||
/**
|
||||
* Main interface for language-specific information. This interface helps build analyses which can operate over multiple languages.
|
||||
*
|
||||
* TODO: document the rest of this interface.
|
||||
*/
|
||||
public interface Language {
|
||||
|
||||
/**
|
||||
* The canonical {@link Language} implementation for Java
|
||||
*/
|
||||
public static JavaLanguage JAVA = new JavaLanguage();
|
||||
|
||||
/**
|
||||
* What is the name of the language?
|
||||
*/
|
||||
Atom getName();
|
||||
|
||||
/**
|
||||
* If this language is "derived" from some other langauge, which one?
|
||||
*/
|
||||
Language getBaseLanguage();
|
||||
|
||||
/**
|
||||
* Yuck? Languages are mutable?
|
||||
*/
|
||||
void registerDerivedLanguage(Language l);
|
||||
|
||||
Set<Language> getDerivedLanguages();
|
||||
|
||||
/**
|
||||
* What is the root type in a type hierarchy for this language? e.g. java.lang.Object in Java.
|
||||
*/
|
||||
TypeReference getRootType();
|
||||
|
||||
/**
|
||||
* What is the root type of exceptions in this language? e.g. java.lang.Throwable in Java
|
||||
*/
|
||||
TypeReference getThrowableType();
|
||||
|
||||
TypeReference getConstantType(Object o);
|
||||
|
||||
boolean isNullType(TypeReference type);
|
||||
|
||||
boolean isIntType(TypeReference type);
|
||||
|
||||
boolean isLongType(TypeReference type);
|
||||
|
||||
boolean isVoidType(TypeReference type);
|
||||
|
||||
boolean isFloatType(TypeReference type);
|
||||
|
||||
boolean isDoubleType(TypeReference type);
|
||||
|
||||
boolean isStringType(TypeReference type);
|
||||
|
||||
boolean isMetadataType(TypeReference type);
|
||||
|
||||
Object getMetadataToken(Object value);
|
||||
|
||||
TypeReference[] getArrayInterfaces();
|
||||
|
||||
TypeName lookupPrimitiveType(String name);
|
||||
|
||||
SSAInstructionFactory instructionFactory();
|
||||
|
||||
Collection<TypeReference> inferInvokeExceptions(MethodReference target, IClassHierarchy cha) throws InvalidClassFileException;
|
||||
}
|
||||
package com.ibm.wala.classLoader;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
||||
import com.ibm.wala.ssa.SSAInstructionFactory;
|
||||
import com.ibm.wala.types.MethodReference;
|
||||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.strings.Atom;
|
||||
|
||||
/**
|
||||
* Main interface for language-specific information. This interface helps build analyses which can operate over multiple languages.
|
||||
*
|
||||
* TODO: document the rest of this interface.
|
||||
*/
|
||||
public interface Language {
|
||||
|
||||
/**
|
||||
* The canonical {@link Language} implementation for Java
|
||||
*/
|
||||
public static JavaLanguage JAVA = new JavaLanguage();
|
||||
|
||||
/**
|
||||
* What is the name of the language?
|
||||
*/
|
||||
Atom getName();
|
||||
|
||||
/**
|
||||
* If this language is "derived" from some other langauge, which one?
|
||||
*/
|
||||
Language getBaseLanguage();
|
||||
|
||||
/**
|
||||
* Yuck? Languages are mutable?
|
||||
*/
|
||||
void registerDerivedLanguage(Language l);
|
||||
|
||||
Set<Language> getDerivedLanguages();
|
||||
|
||||
/**
|
||||
* What is the root type in a type hierarchy for this language? e.g. java.lang.Object in Java.
|
||||
*/
|
||||
TypeReference getRootType();
|
||||
|
||||
/**
|
||||
* What is the root type of exceptions in this language? e.g. java.lang.Throwable in Java
|
||||
*/
|
||||
TypeReference getThrowableType();
|
||||
|
||||
TypeReference getConstantType(Object o);
|
||||
|
||||
boolean isNullType(TypeReference type);
|
||||
|
||||
boolean isIntType(TypeReference type);
|
||||
|
||||
boolean isLongType(TypeReference type);
|
||||
|
||||
boolean isVoidType(TypeReference type);
|
||||
|
||||
boolean isFloatType(TypeReference type);
|
||||
|
||||
boolean isDoubleType(TypeReference type);
|
||||
|
||||
boolean isStringType(TypeReference type);
|
||||
|
||||
boolean isMetadataType(TypeReference type);
|
||||
|
||||
Object getMetadataToken(Object value);
|
||||
|
||||
TypeReference[] getArrayInterfaces();
|
||||
|
||||
TypeName lookupPrimitiveType(String name);
|
||||
|
||||
SSAInstructionFactory instructionFactory();
|
||||
|
||||
Collection<TypeReference> inferInvokeExceptions(MethodReference target, IClassHierarchy cha) throws InvalidClassFileException;
|
||||
|
||||
TypeReference getStringType();
|
||||
|
||||
TypeReference getMetadataType();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue