2013-05-22 22:39:19 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2013 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
|
|
|
|
*******************************************************************************/
|
2007-06-01 03:31:35 +00:00
|
|
|
package com.ibm.wala.cast.ipa.callgraph;
|
|
|
|
|
2007-06-15 14:01:44 +00:00
|
|
|
import com.ibm.wala.cast.ipa.callgraph.AstSSAPropagationCallGraphBuilder.AstPointerAnalysisImpl.AstImplicitPointsToSetVisitor;
|
|
|
|
import com.ibm.wala.cast.util.TargetLanguageSelector;
|
2018-02-05 23:18:37 +00:00
|
|
|
import com.ibm.wala.classLoader.IMethod;
|
2007-06-15 14:01:44 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
|
|
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
|
|
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
2017-06-28 16:42:49 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
|
2007-06-15 14:01:44 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.impl.AbstractRootMethod;
|
|
|
|
import com.ibm.wala.ipa.callgraph.impl.ExplicitCallGraph;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKeyFactory;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PointerKeyFactory;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PointsToMap;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PropagationSystem;
|
2007-06-01 03:31:35 +00:00
|
|
|
import com.ibm.wala.util.intset.MutableMapping;
|
2008-01-24 22:05:51 +00:00
|
|
|
import com.ibm.wala.util.strings.Atom;
|
2007-06-01 03:31:35 +00:00
|
|
|
|
2007-07-06 22:09:29 +00:00
|
|
|
public abstract class CrossLanguageSSAPropagationCallGraphBuilder extends AstSSAPropagationCallGraphBuilder {
|
2007-06-01 03:31:35 +00:00
|
|
|
|
2015-04-06 01:19:56 +00:00
|
|
|
private final TargetLanguageSelector<ConstraintVisitor, CGNode> visitors;
|
2007-06-01 03:31:35 +00:00
|
|
|
|
2007-07-06 22:09:29 +00:00
|
|
|
private final TargetLanguageSelector<InterestingVisitor, Integer> interesting;
|
2007-06-01 03:31:35 +00:00
|
|
|
|
2015-04-06 01:19:56 +00:00
|
|
|
protected abstract TargetLanguageSelector<ConstraintVisitor, CGNode> makeMainVisitorSelector();
|
2007-06-01 03:31:35 +00:00
|
|
|
|
2007-07-06 22:09:29 +00:00
|
|
|
protected abstract TargetLanguageSelector<InterestingVisitor, Integer> makeInterestingVisitorSelector();
|
2007-06-01 03:31:35 +00:00
|
|
|
|
2007-07-06 22:09:29 +00:00
|
|
|
protected abstract TargetLanguageSelector<AstImplicitPointsToSetVisitor, LocalPointerKey> makeImplicitVisitorSelector(
|
|
|
|
CrossLanguagePointerAnalysisImpl analysis);
|
2007-06-01 03:31:35 +00:00
|
|
|
|
2007-07-06 22:09:29 +00:00
|
|
|
protected abstract TargetLanguageSelector<AbstractRootMethod, CrossLanguageCallGraph> makeRootNodeSelector();
|
2007-06-01 03:31:35 +00:00
|
|
|
|
2018-02-05 23:18:37 +00:00
|
|
|
protected CrossLanguageSSAPropagationCallGraphBuilder(IMethod fakeRootClass, AnalysisOptions options, IAnalysisCacheView cache,
|
2007-07-06 22:09:29 +00:00
|
|
|
PointerKeyFactory pointerKeyFactory) {
|
2018-02-05 23:18:37 +00:00
|
|
|
super(fakeRootClass, options, cache, pointerKeyFactory);
|
2007-06-01 03:31:35 +00:00
|
|
|
visitors = makeMainVisitorSelector();
|
|
|
|
interesting = makeInterestingVisitorSelector();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2018-02-05 23:18:37 +00:00
|
|
|
protected ExplicitCallGraph createEmptyCallGraph(IMethod fakeRootClass, AnalysisOptions options) {
|
|
|
|
return new CrossLanguageCallGraph(makeRootNodeSelector(), fakeRootClass, options, getAnalysisCache());
|
2007-06-01 03:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static Atom getLanguage(CGNode node) {
|
2007-07-06 22:09:29 +00:00
|
|
|
return node.getMethod().getReference().getDeclaringClass().getClassLoader().getLanguage();
|
2007-06-01 03:31:35 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-06-01 03:31:35 +00:00
|
|
|
protected InterestingVisitor makeInterestingVisitor(CGNode node, int vn) {
|
|
|
|
return interesting.get(getLanguage(node), new Integer(vn));
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2015-04-06 01:19:56 +00:00
|
|
|
public ConstraintVisitor makeVisitor(CGNode node) {
|
2007-06-01 03:31:35 +00:00
|
|
|
return visitors.get(getLanguage(node), node);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-06-01 03:31:35 +00:00
|
|
|
protected PropagationSystem makeSystem(AnalysisOptions options) {
|
2010-05-12 18:30:55 +00:00
|
|
|
return new PropagationSystem(callGraph, pointerKeyFactory, instanceKeyFactory) {
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2014-05-20 20:00:06 +00:00
|
|
|
public PointerAnalysis<InstanceKey> makePointerAnalysis(PropagationCallGraphBuilder builder) {
|
2007-07-06 22:09:29 +00:00
|
|
|
assert builder == CrossLanguageSSAPropagationCallGraphBuilder.this;
|
|
|
|
return new CrossLanguagePointerAnalysisImpl(CrossLanguageSSAPropagationCallGraphBuilder.this, cg, pointsToMap,
|
|
|
|
instanceKeys, pointerKeyFactory, instanceKeyFactory);
|
2007-06-01 03:31:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2007-07-06 22:09:29 +00:00
|
|
|
protected static class CrossLanguagePointerAnalysisImpl extends AstPointerAnalysisImpl {
|
|
|
|
private final TargetLanguageSelector<AstImplicitPointsToSetVisitor, LocalPointerKey> implicitVisitors;
|
|
|
|
|
|
|
|
protected CrossLanguagePointerAnalysisImpl(CrossLanguageSSAPropagationCallGraphBuilder builder, CallGraph cg,
|
|
|
|
PointsToMap pointsToMap, MutableMapping<InstanceKey> instanceKeys, PointerKeyFactory pointerKeys,
|
|
|
|
InstanceKeyFactory iKeyFactory) {
|
|
|
|
super(builder, cg, pointsToMap, instanceKeys, pointerKeys, iKeyFactory);
|
2007-06-01 03:31:35 +00:00
|
|
|
this.implicitVisitors = builder.makeImplicitVisitorSelector(this);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-06-01 03:31:35 +00:00
|
|
|
protected ImplicitPointsToSetVisitor makeImplicitPointsToVisitor(LocalPointerKey lpk) {
|
|
|
|
return implicitVisitors.get(getLanguage(lpk.getNode()), lpk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-06-01 03:31:35 +00:00
|
|
|
protected void customInit() {
|
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 (CGNode root : callGraph) {
|
|
|
|
markDiscovered(root);
|
2007-06-01 03:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|