2007-02-02 17:17:13 +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
|
|
|
|
*****************************************************************************/
|
|
|
|
package com.ibm.wala.cast.ipa.callgraph;
|
|
|
|
|
2007-05-14 21:31:03 +00:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import com.ibm.wala.cast.ipa.callgraph.AstCallGraph.ScriptFakeRoot;
|
|
|
|
import com.ibm.wala.classLoader.CallSiteReference;
|
|
|
|
import com.ibm.wala.classLoader.IClass;
|
|
|
|
import com.ibm.wala.classLoader.IMethod;
|
|
|
|
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
|
|
|
import com.ibm.wala.ipa.callgraph.impl.FakeRootMethod;
|
|
|
|
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
|
|
|
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
|
|
|
|
import com.ibm.wala.types.TypeReference;
|
2007-02-02 17:17:13 +00:00
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
|
|
|
import com.ibm.wala.util.warnings.WarningSet;
|
|
|
|
|
2007-05-15 17:44:59 +00:00
|
|
|
public abstract class ScriptEntryPoints implements Iterable<Entrypoint> {
|
2007-02-02 17:17:13 +00:00
|
|
|
|
|
|
|
private final ClassHierarchy cha;
|
2007-04-26 16:04:16 +00:00
|
|
|
|
2007-02-02 17:17:13 +00:00
|
|
|
private final IClass scriptType;
|
|
|
|
|
|
|
|
private class ScriptEntryPoint extends Entrypoint {
|
|
|
|
ScriptEntryPoint(IMethod scriptCodeBody) {
|
2007-04-26 16:04:16 +00:00
|
|
|
super(scriptCodeBody);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public TypeReference[] getParameterTypes(int i) {
|
2007-04-26 16:04:16 +00:00
|
|
|
Assertions._assert(i == 0);
|
|
|
|
return new TypeReference[] { getMethod().getDeclaringClass().getReference() };
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
2007-04-26 16:04:16 +00:00
|
|
|
|
2007-02-02 17:17:13 +00:00
|
|
|
public int getNumberOfParameters() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-04-26 16:04:16 +00:00
|
|
|
public SSAAbstractInvokeInstruction addCall(FakeRootMethod m, WarningSet warnings) {
|
2007-02-02 17:17:13 +00:00
|
|
|
CallSiteReference site = makeSite(0);
|
|
|
|
|
|
|
|
if (site == null) {
|
2007-04-26 16:04:16 +00:00
|
|
|
return null;
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int functionVn = makeArgument(m, 0, warnings);
|
|
|
|
int paramVns[] = new int[getNumberOfParameters() - 1];
|
|
|
|
for (int j = 0; j < paramVns.length; j++) {
|
2007-04-26 16:04:16 +00:00
|
|
|
paramVns[j] = makeArgument(m, j + 1, warnings);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 16:04:16 +00:00
|
|
|
return ((ScriptFakeRoot) m).addDirectCall(functionVn, paramVns, site);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ScriptEntryPoints(ClassHierarchy cha, IClass scriptType) {
|
|
|
|
this.cha = cha;
|
|
|
|
this.scriptType = scriptType;
|
|
|
|
}
|
|
|
|
|
2007-05-14 21:31:03 +00:00
|
|
|
public Iterator<Entrypoint> iterator() {
|
|
|
|
Set<Entrypoint> ES = new HashSet<Entrypoint>();
|
2007-02-14 16:16:23 +00:00
|
|
|
Iterator<IClass> classes = scriptType.getClassLoader().iterateAllClasses();
|
2007-04-26 16:04:16 +00:00
|
|
|
while (classes.hasNext()) {
|
2007-02-14 16:16:23 +00:00
|
|
|
IClass cls = classes.next();
|
2007-02-02 17:17:13 +00:00
|
|
|
if (cha.isSubclassOf(cls, scriptType)) {
|
2007-04-26 16:04:16 +00:00
|
|
|
for (Iterator<IMethod> methods = cls.getDeclaredMethods().iterator(); methods.hasNext();) {
|
|
|
|
ES.add(new ScriptEntryPoint(((IMethod) methods.next())));
|
|
|
|
}
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-26 16:04:16 +00:00
|
|
|
|
2007-02-02 17:17:13 +00:00
|
|
|
return ES.iterator();
|
|
|
|
}
|
2007-04-26 16:04:16 +00:00
|
|
|
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|