2007-06-12 13:43:16 +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
|
|
|
|
*****************************************************************************/
|
2007-06-01 03:31:35 +00:00
|
|
|
package com.ibm.wala.cast.ipa.callgraph;
|
|
|
|
|
2007-07-06 22:09:29 +00:00
|
|
|
import java.util.Map;
|
2007-06-01 03:31:35 +00:00
|
|
|
|
2007-07-06 22:09:29 +00:00
|
|
|
import com.ibm.wala.classLoader.CallSiteReference;
|
|
|
|
import com.ibm.wala.classLoader.IMethod;
|
|
|
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
|
|
|
import com.ibm.wala.ipa.callgraph.Context;
|
|
|
|
import com.ibm.wala.ipa.callgraph.ContextSelector;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
2011-04-27 13:58:56 +00:00
|
|
|
import com.ibm.wala.util.intset.IntSet;
|
2008-01-24 22:05:51 +00:00
|
|
|
import com.ibm.wala.util.strings.Atom;
|
2007-06-01 03:31:35 +00:00
|
|
|
|
2007-06-12 13:43:16 +00:00
|
|
|
/**
|
2015-04-06 01:19:56 +00:00
|
|
|
* A ContextSelector implementation adapted to work for analysis across
|
2007-06-12 13:43:16 +00:00
|
|
|
* multiple languages. This context selector delegates to one of several
|
|
|
|
* child selectors based on the language of the code body for which a
|
|
|
|
* context is being selected.
|
|
|
|
*
|
2015-04-06 01:19:56 +00:00
|
|
|
* This provides a convenient way to integrate multiple, language-specific
|
2007-06-12 13:43:16 +00:00
|
|
|
* specialized context policies---such as the ones used for clone() in
|
|
|
|
* Java and runtime primitives in JavaScript.
|
|
|
|
*
|
|
|
|
* @author Julian Dolby (dolby@us.ibm.com)
|
|
|
|
*/
|
2007-06-01 03:31:35 +00:00
|
|
|
public class CrossLanguageContextSelector implements ContextSelector {
|
|
|
|
|
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 final Map<Atom, ContextSelector> languageSelectors;
|
2007-06-01 03:31:35 +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 CrossLanguageContextSelector(Map<Atom, ContextSelector> languageSelectors) {
|
2007-06-01 03:31:35 +00:00
|
|
|
this.languageSelectors = languageSelectors;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Atom getLanguage(CallSiteReference site) {
|
|
|
|
return site
|
|
|
|
.getDeclaredTarget()
|
|
|
|
.getDeclaringClass()
|
|
|
|
.getClassLoader()
|
|
|
|
.getLanguage();
|
|
|
|
}
|
|
|
|
|
|
|
|
private ContextSelector getSelector(CallSiteReference site) {
|
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
|
|
|
return languageSelectors.get(getLanguage(site));
|
2007-06-01 03:31:35 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-27 13:58:56 +00:00
|
|
|
public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] receiver) {
|
2007-06-01 03:31:35 +00:00
|
|
|
return getSelector(site).getCalleeTarget(caller, site, callee, receiver);
|
|
|
|
}
|
2011-04-27 13:58:56 +00:00
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2011-04-27 13:58:56 +00:00
|
|
|
public IntSet getRelevantParameters(CGNode caller, CallSiteReference site) {
|
|
|
|
return getSelector(site).getRelevantParameters(caller, site);
|
|
|
|
}
|
2007-06-01 03:31:35 +00:00
|
|
|
}
|