2007-02-02 17:20:09 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* Created on Aug 22, 2005
|
|
|
|
*/
|
|
|
|
package com.ibm.wala.cast.java.loader;
|
|
|
|
|
2007-02-08 19:07:47 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2009-04-10 18:33:07 +00:00
|
|
|
import com.ibm.wala.cast.ir.ssa.AssignInstruction;
|
|
|
|
import com.ibm.wala.cast.ir.ssa.AstAssertInstruction;
|
|
|
|
import com.ibm.wala.cast.ir.ssa.AstEchoInstruction;
|
|
|
|
import com.ibm.wala.cast.ir.ssa.AstGlobalRead;
|
|
|
|
import com.ibm.wala.cast.ir.ssa.AstGlobalWrite;
|
|
|
|
import com.ibm.wala.cast.ir.ssa.AstIsDefinedInstruction;
|
2011-04-03 04:08:05 +00:00
|
|
|
import com.ibm.wala.cast.ir.ssa.AstLexicalAccess.Access;
|
2009-04-10 18:33:07 +00:00
|
|
|
import com.ibm.wala.cast.ir.ssa.AstLexicalRead;
|
|
|
|
import com.ibm.wala.cast.ir.ssa.AstLexicalWrite;
|
2007-02-08 19:07:47 +00:00
|
|
|
import com.ibm.wala.cast.ir.translator.AstTranslator;
|
2008-12-02 14:08:57 +00:00
|
|
|
import com.ibm.wala.cast.ir.translator.AstTranslator.AstLexicalInformation;
|
2009-04-10 18:33:07 +00:00
|
|
|
import com.ibm.wala.cast.java.ssa.AstJavaInstructionFactory;
|
|
|
|
import com.ibm.wala.cast.java.ssa.AstJavaInvokeInstruction;
|
|
|
|
import com.ibm.wala.cast.java.ssa.AstJavaNewEnclosingInstruction;
|
|
|
|
import com.ibm.wala.cast.java.ssa.EnclosingObjectReference;
|
2007-02-08 19:07:47 +00:00
|
|
|
import com.ibm.wala.cast.java.translator.SourceModuleTranslator;
|
|
|
|
import com.ibm.wala.cast.loader.AstClass;
|
|
|
|
import com.ibm.wala.cast.loader.AstField;
|
|
|
|
import com.ibm.wala.cast.loader.AstMethod;
|
|
|
|
import com.ibm.wala.cast.loader.AstMethod.DebuggingInformation;
|
2014-04-09 15:15:08 +00:00
|
|
|
import com.ibm.wala.cast.tree.CAstAnnotation;
|
2007-02-08 19:07:47 +00:00
|
|
|
import com.ibm.wala.cast.tree.CAstEntity;
|
|
|
|
import com.ibm.wala.cast.tree.CAstQualifier;
|
|
|
|
import com.ibm.wala.cast.tree.CAstSourcePositionMap;
|
|
|
|
import com.ibm.wala.cast.tree.CAstType;
|
2007-02-02 17:20:09 +00:00
|
|
|
import com.ibm.wala.cast.tree.CAstType.Function;
|
|
|
|
import com.ibm.wala.cfg.AbstractCFG;
|
2013-04-11 01:09:10 +00:00
|
|
|
import com.ibm.wala.cfg.IBasicBlock;
|
2009-04-10 18:33:07 +00:00
|
|
|
import com.ibm.wala.classLoader.CallSiteReference;
|
2007-02-08 19:07:47 +00:00
|
|
|
import com.ibm.wala.classLoader.ClassLoaderImpl;
|
|
|
|
import com.ibm.wala.classLoader.IClass;
|
|
|
|
import com.ibm.wala.classLoader.IClassLoader;
|
2009-05-20 18:55:14 +00:00
|
|
|
import com.ibm.wala.classLoader.IField;
|
|
|
|
import com.ibm.wala.classLoader.IMethod;
|
2011-04-03 04:08:05 +00:00
|
|
|
import com.ibm.wala.classLoader.JavaLanguage.JavaInstructionFactory;
|
2009-03-26 15:11:45 +00:00
|
|
|
import com.ibm.wala.classLoader.Language;
|
2012-09-04 23:24:37 +00:00
|
|
|
import com.ibm.wala.classLoader.Module;
|
2008-12-23 15:22:37 +00:00
|
|
|
import com.ibm.wala.classLoader.ModuleEntry;
|
2009-04-10 18:33:07 +00:00
|
|
|
import com.ibm.wala.classLoader.NewSiteReference;
|
2007-06-01 03:37:03 +00:00
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
2014-04-09 15:15:08 +00:00
|
|
|
import com.ibm.wala.shrikeCT.AnnotationsReader.ConstantElementValue;
|
2013-06-24 18:28:11 +00:00
|
|
|
import com.ibm.wala.shrikeCT.AnnotationsReader.ElementValue;
|
2007-02-08 19:07:47 +00:00
|
|
|
import com.ibm.wala.shrikeCT.ClassConstants;
|
2017-02-23 15:10:39 +00:00
|
|
|
import com.ibm.wala.ssa.SSAInstruction;
|
2007-02-02 17:20:09 +00:00
|
|
|
import com.ibm.wala.ssa.SymbolTable;
|
2007-02-08 19:07:47 +00:00
|
|
|
import com.ibm.wala.types.ClassLoaderReference;
|
|
|
|
import com.ibm.wala.types.Descriptor;
|
|
|
|
import com.ibm.wala.types.FieldReference;
|
|
|
|
import com.ibm.wala.types.MethodReference;
|
|
|
|
import com.ibm.wala.types.Selector;
|
|
|
|
import com.ibm.wala.types.TypeName;
|
|
|
|
import com.ibm.wala.types.TypeReference;
|
2014-04-09 15:15:08 +00:00
|
|
|
import com.ibm.wala.types.annotations.Annotation;
|
2007-02-09 15:33:10 +00:00
|
|
|
import com.ibm.wala.util.collections.HashMapFactory;
|
2014-04-09 15:15:08 +00:00
|
|
|
import com.ibm.wala.util.collections.HashSetFactory;
|
2007-02-08 19:07:47 +00:00
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
2008-01-24 22:04:37 +00:00
|
|
|
import com.ibm.wala.util.strings.Atom;
|
2007-02-02 17:20:09 +00:00
|
|
|
|
|
|
|
/**
|
2009-04-13 13:50:45 +00:00
|
|
|
* A {@link ClassLoaderImpl} that processes source file entities in the
|
2007-02-09 15:33:10 +00:00
|
|
|
* compile-time classpath.
|
2007-02-02 17:20:09 +00:00
|
|
|
*/
|
|
|
|
public abstract class JavaSourceLoaderImpl extends ClassLoaderImpl {
|
2007-04-17 17:33:35 +00:00
|
|
|
public Map<CAstEntity, IClass> fTypeMap = HashMapFactory.make();
|
2013-03-08 14:52:51 +00:00
|
|
|
/** BEGIN Custom change: Common superclass is optional */
|
|
|
|
private final boolean existsCommonSuperclass; // extension to deal with X10 that has no common superclass
|
|
|
|
/** END Custom change: Common superclass is optional */
|
2007-02-09 15:33:10 +00:00
|
|
|
|
|
|
|
/**
|
2007-12-21 15:08:30 +00:00
|
|
|
* WALA representation of a Java class residing in a source file
|
2007-02-09 15:33:10 +00:00
|
|
|
*
|
|
|
|
* @author rfuhrer
|
|
|
|
*/
|
|
|
|
public class JavaClass extends AstClass {
|
2010-01-07 22:16:24 +00:00
|
|
|
protected final IClass enclosingClass;
|
2007-02-09 15:33:10 +00:00
|
|
|
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
protected final Collection<TypeName> superTypeNames;
|
2007-02-09 15:33:10 +00:00
|
|
|
|
2014-04-09 15:15:08 +00:00
|
|
|
private final Collection<Annotation> annotations;
|
|
|
|
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
public JavaClass(String typeName, Collection<TypeName> superTypeNames, CAstSourcePositionMap.Position position, Collection<CAstQualifier> qualifiers,
|
2014-04-09 15:15:08 +00:00
|
|
|
JavaSourceLoaderImpl loader, IClass enclosingClass, Collection<Annotation> annotations) {
|
2009-05-20 18:55:14 +00:00
|
|
|
super(position, TypeName.string2TypeName(typeName), loader, (short) mapToInt(qualifiers), new HashMap<Atom, IField>(), new HashMap<Selector, IMethod>());
|
2007-02-09 15:33:10 +00:00
|
|
|
this.superTypeNames = superTypeNames;
|
|
|
|
this.enclosingClass = enclosingClass;
|
2014-04-09 15:15:08 +00:00
|
|
|
this.annotations = annotations;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2014-04-09 15:15:08 +00:00
|
|
|
public Collection<Annotation> getAnnotations() {
|
|
|
|
return annotations;
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-06-01 03:37:03 +00:00
|
|
|
public IClassHierarchy getClassHierarchy() {
|
2007-02-09 15:33:10 +00:00
|
|
|
return cha;
|
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public IClass getSuperclass() {
|
2010-07-19 14:05:19 +00:00
|
|
|
boolean excludedSupertype=false;
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
for (Iterator<TypeName> iter = superTypeNames.iterator(); iter.hasNext();) {
|
|
|
|
TypeName name = iter.next();
|
2007-07-06 03:07:24 +00:00
|
|
|
IClass domoType = lookupClass(name);
|
2007-02-09 15:33:10 +00:00
|
|
|
if (domoType != null && !domoType.isInterface()) {
|
|
|
|
return domoType;
|
|
|
|
}
|
2010-07-19 14:05:19 +00:00
|
|
|
if (domoType == null && getClassHierarchy().getScope().getExclusions().contains(name.toString().substring(1))){
|
|
|
|
excludedSupertype = true;
|
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2009-05-05 17:22:57 +00:00
|
|
|
// The following test allows the root class to reside in source; without
|
|
|
|
// it, the assertion requires all classes represented by a JavaClass to
|
|
|
|
// have a superclass.
|
2013-03-08 14:52:51 +00:00
|
|
|
/** BEGIN Custom change: Common superclass is optional */
|
|
|
|
// Is no longer true in new X10 - no common object super class
|
|
|
|
if (existsCommonSuperclass && !getName().equals(JavaSourceLoaderImpl.this.getLanguage().getRootType().getName()) && !excludedSupertype) {
|
|
|
|
/** END Custom change: Common superclass is optional */
|
2009-05-05 17:22:57 +00:00
|
|
|
Assertions.UNREACHABLE("Cannot find super class for " + this + " in " + superTypeNames);
|
|
|
|
}
|
2010-07-19 14:05:19 +00:00
|
|
|
|
|
|
|
if (excludedSupertype){
|
|
|
|
System.err.println("Not tracking calls through excluded superclass of " + getName() + " extends " + superTypeNames);
|
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
return null;
|
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public Collection<IClass> getDirectInterfaces() {
|
2017-03-12 03:20:51 +00:00
|
|
|
List<IClass> result = new ArrayList<>();
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
for (TypeName name : superTypeNames) {
|
2007-07-06 03:07:24 +00:00
|
|
|
IClass domoType = lookupClass(name);
|
2007-02-09 15:33:10 +00:00
|
|
|
if (domoType != null && domoType.isInterface()) {
|
2010-07-19 14:05:19 +00:00
|
|
|
result.add(domoType);
|
|
|
|
}
|
|
|
|
if (domoType == null && !getClassHierarchy().getScope().getExclusions().contains(name.toString().substring(1))){
|
2012-10-01 17:11:10 +00:00
|
|
|
assert false : "Failed to find non-excluded interface: " + name;
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
2007-03-12 02:06:00 +00:00
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
return result;
|
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
private void addMethod(CAstEntity methodEntity, IClass owner, AbstractCFG<?, ?> cfg, SymbolTable symtab, boolean hasCatchBlock,
|
2017-02-23 15:10:39 +00:00
|
|
|
Map<IBasicBlock<SSAInstruction>, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) {
|
2007-02-09 15:33:10 +00:00
|
|
|
declaredMethods.put(Util.methodEntityToSelector(methodEntity), new ConcreteJavaMethod(methodEntity, owner, cfg, symtab,
|
2013-04-11 01:09:10 +00:00
|
|
|
hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo));
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
private void addMethod(CAstEntity methodEntity, IClass owner) {
|
|
|
|
declaredMethods.put(Util.methodEntityToSelector(methodEntity), new AbstractJavaMethod(methodEntity, owner));
|
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
private void addField(CAstEntity fieldEntity) {
|
2014-04-09 15:15:08 +00:00
|
|
|
declaredFields.put(Util.fieldEntityToAtom(fieldEntity), new JavaField(fieldEntity, JavaSourceLoaderImpl.this, this, JavaSourceLoaderImpl.this.getAnnotations(fieldEntity)));
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
public IClass getEnclosingClass() {
|
|
|
|
return enclosingClass;
|
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public String toString() {
|
2014-04-09 15:15:08 +00:00
|
|
|
StringBuffer sb = new StringBuffer("<src-class: " );
|
|
|
|
sb.append(getName().toString());
|
|
|
|
if (enclosingClass != null) {
|
|
|
|
sb.append(" (within " + enclosingClass.getName() + ")");
|
2007-02-07 18:51:19 +00:00
|
|
|
}
|
2014-04-09 15:15:08 +00:00
|
|
|
if (annotations != null && !annotations.isEmpty()) {
|
|
|
|
for(Annotation a : annotations) {
|
|
|
|
sb.append("[" + a.getType().getName().getClassName() + "]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb.toString();
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-09 15:15:08 +00:00
|
|
|
private Collection<Annotation> getAnnotations(CAstEntity e) {
|
|
|
|
Collection<CAstAnnotation> annotations = e.getAnnotations();
|
|
|
|
if (annotations == null || annotations.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
Collection<Annotation> result = HashSetFactory.make();
|
|
|
|
for(CAstAnnotation ca : annotations) {
|
|
|
|
TypeName walaTypeName = toWALATypeName(ca.getType());
|
|
|
|
TypeReference ref = TypeReference.findOrCreate(getReference(), walaTypeName);
|
|
|
|
if (ca.getArguments() == null || ca.getArguments().isEmpty()) {
|
|
|
|
result.add(Annotation.make(ref));
|
|
|
|
} else {
|
|
|
|
Map<String,ElementValue> args = HashMapFactory.make();
|
|
|
|
for(Map.Entry<String, Object> a : ca.getArguments().entrySet()) {
|
|
|
|
args.put(a.getKey(), new ConstantElementValue(a.getValue()));
|
|
|
|
}
|
|
|
|
result.add(Annotation.makeWithNamed(ref, args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
/**
|
2013-04-09 22:56:47 +00:00
|
|
|
* WALA representation of a field on a Java type that resides in a source file
|
2007-02-09 15:33:10 +00:00
|
|
|
*
|
|
|
|
* @author rfuhrer
|
|
|
|
*/
|
|
|
|
private class JavaField extends AstField {
|
2014-04-09 15:15:08 +00:00
|
|
|
private JavaField(CAstEntity fieldEntity, IClassLoader loader, IClass declaringClass, Collection<Annotation> annotations) {
|
2007-02-09 15:33:10 +00:00
|
|
|
super(FieldReference.findOrCreate(declaringClass.getReference(), Atom.findOrCreateUnicodeAtom(fieldEntity.getName()),
|
|
|
|
TypeReference.findOrCreate(loader.getReference(), TypeName.string2TypeName(fieldEntity.getType().getName()))),
|
2014-04-09 15:15:08 +00:00
|
|
|
fieldEntity.getQualifiers(), declaringClass, declaringClass.getClassHierarchy(), annotations);
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic DOMO representation of a method on a Java type that resides in a
|
|
|
|
* source file
|
|
|
|
*
|
|
|
|
* @author rfuhrer
|
|
|
|
*/
|
|
|
|
private abstract class JavaEntityMethod extends AstMethod {
|
|
|
|
private final TypeReference[] parameterTypes;
|
|
|
|
|
|
|
|
private final TypeReference[] exceptionTypes;
|
|
|
|
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
public JavaEntityMethod(CAstEntity methodEntity, IClass owner, AbstractCFG<?, ?> cfg, SymbolTable symtab, boolean hasCatchBlock,
|
2017-02-23 15:10:39 +00:00
|
|
|
Map<IBasicBlock<SSAInstruction>, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) {
|
2007-02-09 15:33:10 +00:00
|
|
|
super(owner, methodEntity.getQualifiers(), cfg, symtab, MethodReference.findOrCreate(owner.getReference(), Util
|
2013-04-11 01:09:10 +00:00
|
|
|
.methodEntityToSelector(methodEntity)), hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo, JavaSourceLoaderImpl.this.getAnnotations(methodEntity));
|
2007-02-09 15:33:10 +00:00
|
|
|
this.parameterTypes = computeParameterTypes(methodEntity);
|
|
|
|
this.exceptionTypes = computeExceptionTypes(methodEntity);
|
|
|
|
}
|
2007-02-07 18:51:19 +00:00
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
public JavaEntityMethod(CAstEntity methodEntity, IClass owner) {
|
|
|
|
super(owner, methodEntity.getQualifiers(), MethodReference.findOrCreate(owner.getReference(), Util
|
2014-04-09 15:15:08 +00:00
|
|
|
.methodEntityToSelector(methodEntity)), JavaSourceLoaderImpl.this.getAnnotations(methodEntity));
|
2007-02-09 15:33:10 +00:00
|
|
|
this.parameterTypes = computeParameterTypes(methodEntity);
|
|
|
|
this.exceptionTypes = computeExceptionTypes(methodEntity);
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
public int getMaxLocals() {
|
|
|
|
Assertions.UNREACHABLE("AbstractJavaMethod.getMaxLocals() called");
|
|
|
|
return 0;
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
public int getMaxStackHeight() {
|
|
|
|
Assertions.UNREACHABLE("AbstractJavaMethod.getMaxStackHeight() called");
|
|
|
|
return 0;
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public TypeReference getParameterType(int i) {
|
|
|
|
return parameterTypes[i];
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
private TypeReference[] computeParameterTypes(CAstEntity methodEntity) {
|
|
|
|
TypeReference[] types;
|
|
|
|
CAstType.Function type = (Function) methodEntity.getType();
|
|
|
|
int argCount = type.getArgumentTypes().size();
|
|
|
|
if (isStatic()) {
|
|
|
|
types = new TypeReference[argCount];
|
|
|
|
for (int i = 0; i < argCount; i++) {
|
2017-03-18 05:41:04 +00:00
|
|
|
types[i] = TypeReference.findOrCreate(JavaSourceLoaderImpl.this.getReference(), type.getArgumentTypes()
|
|
|
|
.get(i).getName());
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
types = new TypeReference[argCount + 1];
|
|
|
|
types[0] = cls.getReference();
|
|
|
|
for (int i = 0; i < argCount; i++) {
|
2017-03-18 05:41:04 +00:00
|
|
|
types[i + 1] = TypeReference.findOrCreate(JavaSourceLoaderImpl.this.getReference(), type.getArgumentTypes()
|
|
|
|
.get(i).getName());
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
return types;
|
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public TypeReference[] getDeclaredExceptions() {
|
|
|
|
return exceptionTypes;
|
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
private TypeReference[] computeExceptionTypes(CAstEntity methodEntity) {
|
|
|
|
CAstType.Function fType = (Function) methodEntity.getType();
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
Collection<CAstType> exceptionTypes = fType.getExceptionTypes();
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
TypeReference[] result = new TypeReference[exceptionTypes.size()];
|
|
|
|
int i = 0;
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
for (CAstType type : exceptionTypes) {
|
2007-02-09 15:33:10 +00:00
|
|
|
result[i] = TypeReference.findOrCreate(JavaSourceLoaderImpl.this.getReference(), type.getName());
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
++i;
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
2007-02-09 15:33:10 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public String toString() {
|
|
|
|
return "<src-method: " + this.getReference() + ">";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DOMO representation of an abstract (body-less) method on a Java type that
|
|
|
|
* resides in a source file
|
|
|
|
*
|
|
|
|
* @author rfuhrer
|
|
|
|
*/
|
|
|
|
private class AbstractJavaMethod extends JavaEntityMethod {
|
|
|
|
public AbstractJavaMethod(CAstEntity methodEntity, IClass owner) {
|
|
|
|
super(methodEntity, owner);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public String getLocalVariableName(int bcIndex, int localNumber) {
|
|
|
|
Assertions.UNREACHABLE("AbstractJavaMethod.getLocalVariableName() called");
|
|
|
|
return null;
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public boolean hasLocalVariableTable() {
|
|
|
|
Assertions.UNREACHABLE("AbstractJavaMethod.hasLocalVariableTable() called");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public LexicalParent[] getParents() {
|
|
|
|
return new LexicalParent[0];
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-06-01 03:37:03 +00:00
|
|
|
public IClassHierarchy getClassHierarchy() {
|
2007-02-02 17:20:09 +00:00
|
|
|
return cha;
|
|
|
|
}
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DOMO representation of a concrete method (which has a body) on a Java type
|
|
|
|
* that resides in a source file
|
|
|
|
*
|
|
|
|
* @author rfuhrer
|
|
|
|
*/
|
|
|
|
public class ConcreteJavaMethod extends JavaEntityMethod {
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
public ConcreteJavaMethod(CAstEntity methodEntity, IClass owner, AbstractCFG<?, ?> cfg, SymbolTable symtab, boolean hasCatchBlock,
|
2017-02-23 15:10:39 +00:00
|
|
|
Map<IBasicBlock<SSAInstruction>, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) {
|
2013-04-11 01:09:10 +00:00
|
|
|
super(methodEntity, owner, cfg, symtab, hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo);
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-06-01 03:37:03 +00:00
|
|
|
public IClassHierarchy getClassHierarchy() {
|
2007-02-09 15:33:10 +00:00
|
|
|
return cha;
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public String getLocalVariableName(int bcIndex, int localNumber) {
|
|
|
|
return null;
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public boolean hasLocalVariableTable() {
|
|
|
|
return false;
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public LexicalParent[] getParents() {
|
|
|
|
if (AstTranslator.DEBUG_LEXICAL) {
|
2009-04-09 20:31:14 +00:00
|
|
|
System.err.println(("resolving parents of " + this));
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
2008-12-02 14:08:57 +00:00
|
|
|
if (lexicalInfo() == null) {
|
2007-02-09 15:33:10 +00:00
|
|
|
if (AstTranslator.DEBUG_LEXICAL)
|
2009-04-09 20:31:14 +00:00
|
|
|
System.err.println("no info");
|
2007-02-09 15:33:10 +00:00
|
|
|
return new LexicalParent[0];
|
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2008-12-02 14:08:57 +00:00
|
|
|
final String[] parents = lexicalInfo().getScopingParents();
|
2007-02-09 15:33:10 +00:00
|
|
|
|
|
|
|
if (parents == null) {
|
|
|
|
if (AstTranslator.DEBUG_LEXICAL)
|
2009-04-09 20:31:14 +00:00
|
|
|
System.err.println("no parents");
|
2007-02-09 15:33:10 +00:00
|
|
|
return new LexicalParent[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
LexicalParent result[] = new LexicalParent[parents.length];
|
|
|
|
|
|
|
|
for (int i = 0; i < parents.length; i++) {
|
|
|
|
int lastLeftParen = parents[i].lastIndexOf('(');
|
|
|
|
int lastQ = parents[i].lastIndexOf('/', lastLeftParen);
|
|
|
|
String typeName = parents[i].substring(0, lastQ);
|
2007-07-06 03:07:24 +00:00
|
|
|
final IClass cls = lookupClass(TypeName.string2TypeName(typeName));
|
2007-02-09 15:33:10 +00:00
|
|
|
|
|
|
|
String sig = parents[i].substring(lastQ);
|
|
|
|
int nameEnd = sig.indexOf('(');
|
|
|
|
String nameStr = sig.substring(1, nameEnd);
|
|
|
|
Atom name = Atom.findOrCreateUnicodeAtom(nameStr);
|
|
|
|
|
|
|
|
String descStr = sig.substring(nameEnd);
|
2009-03-26 15:11:45 +00:00
|
|
|
Descriptor desc = Descriptor.findOrCreateUTF8(Language.JAVA, descStr);
|
2007-02-09 15:33:10 +00:00
|
|
|
|
|
|
|
final Selector sel = new Selector(name, desc);
|
|
|
|
|
|
|
|
if (AstTranslator.DEBUG_LEXICAL)
|
2009-04-09 20:31:14 +00:00
|
|
|
System.err.println(("get " + typeName + ", " + nameStr + ", " + descStr));
|
2007-02-09 15:33:10 +00:00
|
|
|
|
|
|
|
final int hack = i;
|
|
|
|
result[i] = new LexicalParent() {
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public String getName() {
|
|
|
|
return parents[hack];
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public AstMethod getMethod() {
|
|
|
|
return (AstMethod) cls.getMethod(sel);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (AstTranslator.DEBUG_LEXICAL)
|
2009-04-09 20:31:14 +00:00
|
|
|
System.err.println(("parent " + result[i].getName() + " is " + result[i].getMethod()));
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
public static int mapToInt(Collection<CAstQualifier> qualifiers) {
|
2007-02-09 15:33:10 +00:00
|
|
|
int result = 0;
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
for (CAstQualifier q : qualifiers) {
|
2007-02-09 15:33:10 +00:00
|
|
|
if (q == CAstQualifier.PUBLIC)
|
|
|
|
result |= ClassConstants.ACC_PUBLIC;
|
|
|
|
if (q == CAstQualifier.PROTECTED)
|
|
|
|
result |= ClassConstants.ACC_PROTECTED;
|
|
|
|
if (q == CAstQualifier.PRIVATE)
|
|
|
|
result |= ClassConstants.ACC_PRIVATE;
|
|
|
|
if (q == CAstQualifier.STATIC)
|
|
|
|
result |= ClassConstants.ACC_STATIC;
|
|
|
|
if (q == CAstQualifier.FINAL)
|
|
|
|
result |= ClassConstants.ACC_FINAL;
|
|
|
|
if (q == CAstQualifier.SYNCHRONIZED)
|
|
|
|
result |= ClassConstants.ACC_SYNCHRONIZED;
|
|
|
|
if (q == CAstQualifier.TRANSIENT)
|
|
|
|
result |= ClassConstants.ACC_TRANSIENT;
|
|
|
|
if (q == CAstQualifier.NATIVE)
|
|
|
|
result |= ClassConstants.ACC_NATIVE;
|
|
|
|
if (q == CAstQualifier.INTERFACE)
|
|
|
|
result |= ClassConstants.ACC_INTERFACE;
|
|
|
|
if (q == CAstQualifier.ABSTRACT)
|
|
|
|
result |= ClassConstants.ACC_ABSTRACT;
|
|
|
|
if (q == CAstQualifier.VOLATILE)
|
|
|
|
result |= ClassConstants.ACC_VOLATILE;
|
|
|
|
if (q == CAstQualifier.STRICTFP)
|
|
|
|
result |= ClassConstants.ACC_STRICT;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-08 14:52:51 +00:00
|
|
|
/** BEGIN Custom change: Common superclass is optional */
|
|
|
|
public JavaSourceLoaderImpl(boolean existsCommonSuperClass, ClassLoaderReference loaderRef, IClassLoader parent,
|
2017-07-28 20:33:41 +00:00
|
|
|
IClassHierarchy cha) {
|
2007-07-06 22:08:34 +00:00
|
|
|
super(loaderRef, cha.getScope().getArrayClassLoader(), parent, cha.getScope().getExclusions(), cha);
|
2013-03-08 14:52:51 +00:00
|
|
|
this.existsCommonSuperclass = existsCommonSuperClass;
|
|
|
|
}
|
|
|
|
|
2017-07-28 20:33:41 +00:00
|
|
|
public JavaSourceLoaderImpl(ClassLoaderReference loaderRef, IClassLoader parent, IClassHierarchy cha) {
|
2013-03-08 14:52:51 +00:00
|
|
|
// standard case: we have a common super class
|
2017-07-28 20:33:41 +00:00
|
|
|
this(true, loaderRef, parent, cha);
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
2013-03-08 14:52:51 +00:00
|
|
|
/** END Custom change: Common superclass is optional */
|
2007-02-09 15:33:10 +00:00
|
|
|
|
2007-06-01 03:37:03 +00:00
|
|
|
public IClassHierarchy getClassHierarchy() {
|
2007-02-09 15:33:10 +00:00
|
|
|
return cha;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2008-12-23 15:22:37 +00:00
|
|
|
protected void loadAllSources(Set<ModuleEntry> modules) {
|
2007-02-09 15:33:10 +00:00
|
|
|
getTranslator().loadAllSources(modules);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract SourceModuleTranslator getTranslator();
|
2013-03-06 16:09:45 +00:00
|
|
|
/** BEGIN Custom change: Optional deletion of fTypeMap */
|
|
|
|
public static volatile boolean deleteTypeMapAfterInit = true;
|
|
|
|
/** END Custom change: Optional deletion of fTypeMap */
|
|
|
|
|
2011-04-13 16:27:15 +00:00
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-13 16:27:15 +00:00
|
|
|
public void init(List<Module> modules) throws IOException {
|
|
|
|
super.init(modules);
|
2013-03-06 16:09:45 +00:00
|
|
|
/** BEGIN Custom change: Optional deletion of fTypeMap */
|
|
|
|
if (deleteTypeMapAfterInit) {
|
|
|
|
fTypeMap = null;
|
|
|
|
}
|
|
|
|
/** END Custom change: Optional deletion of fTypeMap */
|
2011-04-13 16:27:15 +00:00
|
|
|
}
|
|
|
|
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
public void defineFunction(CAstEntity n, IClass owner, AbstractCFG<?, ?> cfg, SymbolTable symtab, boolean hasCatchBlock,
|
2017-02-23 15:10:39 +00:00
|
|
|
Map<IBasicBlock<SSAInstruction>, TypeReference[]> caughtTypes, boolean hasMonitorOp, AstLexicalInformation lexicalInfo, DebuggingInformation debugInfo) {
|
2013-04-11 01:09:10 +00:00
|
|
|
((JavaClass) owner).addMethod(n, owner, cfg, symtab, hasCatchBlock, caughtTypes, hasMonitorOp, lexicalInfo, debugInfo);
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void defineAbstractFunction(CAstEntity n, IClass owner) {
|
|
|
|
((JavaClass) owner).addMethod(n, owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void defineField(CAstEntity n, IClass owner) {
|
|
|
|
((JavaClass) owner).addField(n);
|
|
|
|
}
|
|
|
|
|
2017-05-11 15:47:19 +00:00
|
|
|
private static TypeName toWALATypeName(CAstType type) {
|
2014-04-09 15:15:08 +00:00
|
|
|
return TypeName.string2TypeName(type.getName());
|
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
public IClass defineType(CAstEntity type, String typeName, CAstEntity owner) {
|
2017-03-12 03:20:51 +00:00
|
|
|
Collection<TypeName> superTypeNames = new ArrayList<>();
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
for (CAstType superType : type.getType().getSupertypes()) {
|
|
|
|
superTypeNames.add(toWALATypeName(superType));
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
2007-02-09 15:33:10 +00:00
|
|
|
|
|
|
|
JavaClass javaClass = new JavaClass(typeName, superTypeNames, type.getPosition(), type.getQualifiers(), this,
|
2014-04-09 15:15:08 +00:00
|
|
|
(owner != null) ? (JavaClass) fTypeMap.get(owner) : (JavaClass) null, getAnnotations(type));
|
2007-02-09 15:33:10 +00:00
|
|
|
|
2011-04-04 15:17:31 +00:00
|
|
|
if (getParent().lookupClass(javaClass.getName()) != null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:10 +00:00
|
|
|
fTypeMap.put(type, javaClass);
|
|
|
|
loadedClasses.put(javaClass.getName(), javaClass);
|
|
|
|
return javaClass;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-02-09 15:33:10 +00:00
|
|
|
public String toString() {
|
|
|
|
return "Java Source Loader (classes " + loadedClasses.values() + ")";
|
|
|
|
}
|
2009-04-10 18:33:07 +00:00
|
|
|
|
|
|
|
public static class InstructionFactory extends JavaInstructionFactory implements AstJavaInstructionFactory {
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public com.ibm.wala.cast.java.ssa.EnclosingObjectReference EnclosingObjectReference(int iindex, int lval, TypeReference type) {
|
|
|
|
return new EnclosingObjectReference(iindex, lval, type);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstJavaNewEnclosingInstruction JavaNewEnclosingInstruction(int iindex, int result, NewSiteReference site, int enclosing) {
|
|
|
|
return new AstJavaNewEnclosingInstruction(iindex, result, site, enclosing);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2014-07-29 17:45:24 +00:00
|
|
|
public AstJavaInvokeInstruction JavaInvokeInstruction(int iindex, int result[], int[] params, int exception, CallSiteReference site) {
|
2014-05-20 15:59:16 +00:00
|
|
|
return result == null ? new AstJavaInvokeInstruction(iindex, params, exception, site) : new AstJavaInvokeInstruction(iindex, result[0],
|
2013-07-10 16:44:17 +00:00
|
|
|
params, exception, site);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstAssertInstruction AssertInstruction(int iindex, int value, boolean fromSpecification) {
|
|
|
|
return new AstAssertInstruction(iindex, value, fromSpecification);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public com.ibm.wala.cast.ir.ssa.AssignInstruction AssignInstruction(int iindex, int result, int val) {
|
|
|
|
return new AssignInstruction(iindex, result, val);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2015-07-25 02:44:10 +00:00
|
|
|
public com.ibm.wala.cast.ir.ssa.EachElementGetInstruction EachElementGetInstruction(int iindex, int value, int objectRef, int propRef) {
|
2009-04-10 18:33:07 +00:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2015-07-25 02:44:10 +00:00
|
|
|
public com.ibm.wala.cast.ir.ssa.EachElementHasNextInstruction EachElementHasNextInstruction(int iindex, int value, int objectRef, int propRef) {
|
2009-04-10 18:33:07 +00:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstEchoInstruction EchoInstruction(int iindex, int[] rvals) {
|
2009-04-10 18:33:07 +00:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstGlobalRead GlobalRead(int iindex, int lhs, FieldReference global) {
|
2009-04-10 18:33:07 +00:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstGlobalWrite GlobalWrite(int iindex, FieldReference global, int rhs) {
|
2009-04-10 18:33:07 +00:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstIsDefinedInstruction IsDefinedInstruction(int iindex, int lval, int rval, int fieldVal, FieldReference fieldRef) {
|
2009-04-10 18:33:07 +00:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstIsDefinedInstruction IsDefinedInstruction(int iindex, int lval, int rval, FieldReference fieldRef) {
|
2009-04-10 18:33:07 +00:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstIsDefinedInstruction IsDefinedInstruction(int iindex, int lval, int rval, int fieldVal) {
|
2009-04-10 18:33:07 +00:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstIsDefinedInstruction IsDefinedInstruction(int iindex, int lval, int rval) {
|
2009-04-10 18:33:07 +00:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstLexicalRead LexicalRead(int iindex, Access[] accesses) {
|
|
|
|
return new AstLexicalRead(iindex, accesses);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstLexicalRead LexicalRead(int iindex, Access access) {
|
|
|
|
return new AstLexicalRead(iindex, access);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2014-05-20 15:59:16 +00:00
|
|
|
public AstLexicalRead LexicalRead(int iindex, int lhs, String definer, String globalName, TypeReference type) {
|
|
|
|
return new AstLexicalRead(iindex, lhs, definer, globalName, type);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstLexicalWrite LexicalWrite(int iindex, Access[] accesses) {
|
|
|
|
return new AstLexicalWrite(iindex, accesses);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-12 17:49:06 +00:00
|
|
|
public AstLexicalWrite LexicalWrite(int iindex, Access access) {
|
|
|
|
return new AstLexicalWrite(iindex, access);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2014-05-20 15:59:16 +00:00
|
|
|
public AstLexicalWrite LexicalWrite(int iindex, String definer, String globalName, TypeReference type, int rhs) {
|
|
|
|
return new AstLexicalWrite(iindex, definer, globalName, type, rhs);
|
2009-04-10 18:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final InstructionFactory insts = new InstructionFactory();
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2009-04-10 18:33:07 +00:00
|
|
|
public InstructionFactory getInstructionFactory() {
|
|
|
|
return insts;
|
|
|
|
}
|
|
|
|
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|