2007-02-02 17:25: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
|
|
|
|
*****************************************************************************/
|
|
|
|
package com.ibm.wala.cast.js.ipa.callgraph;
|
|
|
|
|
2014-05-28 17:35:11 +00:00
|
|
|
import com.ibm.wala.cast.js.ipa.summaries.JavaScriptConstructorFunctions;
|
2007-07-05 03:04:57 +00:00
|
|
|
import com.ibm.wala.cast.js.types.JavaScriptMethods;
|
|
|
|
import com.ibm.wala.classLoader.CallSiteReference;
|
|
|
|
import com.ibm.wala.classLoader.IClass;
|
|
|
|
import com.ibm.wala.classLoader.IMethod;
|
|
|
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
|
|
|
import com.ibm.wala.ipa.callgraph.MethodTargetSelector;
|
2007-06-01 03:32:56 +00:00
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
2007-07-05 03:04:57 +00:00
|
|
|
import com.ibm.wala.ssa.IR;
|
|
|
|
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
|
|
|
|
import com.ibm.wala.types.MethodReference;
|
2007-02-02 17:25:09 +00:00
|
|
|
|
2011-06-22 21:23:49 +00:00
|
|
|
/**
|
|
|
|
* generates instructions to simulate the semantics of JS constructor invocations
|
|
|
|
*
|
|
|
|
*/
|
2007-07-05 03:04:57 +00:00
|
|
|
public class JavaScriptConstructTargetSelector implements MethodTargetSelector {
|
2007-02-02 17:25:09 +00:00
|
|
|
private final MethodTargetSelector base;
|
2007-07-05 03:04:57 +00:00
|
|
|
|
2014-05-28 17:35:11 +00:00
|
|
|
private final JavaScriptConstructorFunctions constructors;
|
|
|
|
|
2007-07-06 22:09:08 +00:00
|
|
|
public JavaScriptConstructTargetSelector(IClassHierarchy cha, MethodTargetSelector base) {
|
2014-05-28 17:35:11 +00:00
|
|
|
this.constructors = new JavaScriptConstructorFunctions(cha);
|
2007-02-02 17:25:09 +00:00
|
|
|
this.base = base;
|
|
|
|
}
|
2007-07-05 03:04:57 +00:00
|
|
|
|
2014-05-28 17:35:11 +00:00
|
|
|
public JavaScriptConstructTargetSelector(JavaScriptConstructorFunctions constructors, MethodTargetSelector base) {
|
|
|
|
this.constructors = constructors;
|
|
|
|
this.base = base;
|
2007-02-02 17:25:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-07-05 03:04:57 +00:00
|
|
|
public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) {
|
2007-02-02 17:25:09 +00:00
|
|
|
if (site.getDeclaredTarget().equals(JavaScriptMethods.ctorReference)) {
|
2007-07-06 22:09:08 +00:00
|
|
|
IR callerIR = caller.getIR();
|
2007-07-05 03:04:57 +00:00
|
|
|
SSAAbstractInvokeInstruction callStmts[] = callerIR.getCalls(site);
|
2009-04-30 13:16:52 +00:00
|
|
|
assert callStmts.length == 1;
|
2011-05-05 03:51:54 +00:00
|
|
|
int nargs = callStmts[0].getNumberOfParameters();
|
2014-05-28 17:35:11 +00:00
|
|
|
return constructors.findOrCreateConstructorMethod(callerIR, callStmts[0], receiver, nargs - 1);
|
2007-02-02 17:25:09 +00:00
|
|
|
} else {
|
|
|
|
return base.getCalleeTarget(caller, site, receiver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-05 03:04:57 +00:00
|
|
|
public boolean mightReturnSyntheticMethod(CGNode caller, CallSiteReference site) {
|
2007-02-02 17:25:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean mightReturnSyntheticMethod(MethodReference declaredTarget) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|