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.ir.ssa;
|
|
|
|
|
2013-04-11 01:09:10 +00:00
|
|
|
import java.util.Map;
|
2017-02-23 15:10:39 +00:00
|
|
|
import java.util.Map.Entry;
|
2013-04-11 01:09:10 +00:00
|
|
|
|
2018-05-09 22:10:20 +00:00
|
|
|
import com.ibm.wala.cast.ir.ssa.SSAConversion.SSAInformation;
|
2007-06-06 20:15:48 +00:00
|
|
|
import com.ibm.wala.cast.loader.AstMethod;
|
2008-12-02 14:08:12 +00:00
|
|
|
import com.ibm.wala.cast.loader.AstMethod.LexicalInformation;
|
2007-02-02 17:17:13 +00:00
|
|
|
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
2007-06-06 20:15:48 +00:00
|
|
|
import com.ibm.wala.cfg.AbstractCFG;
|
|
|
|
import com.ibm.wala.cfg.ControlFlowGraph;
|
2013-04-11 01:09:10 +00:00
|
|
|
import com.ibm.wala.cfg.IBasicBlock;
|
2007-06-06 20:15:48 +00:00
|
|
|
import com.ibm.wala.classLoader.IMethod;
|
|
|
|
import com.ibm.wala.ipa.callgraph.Context;
|
|
|
|
import com.ibm.wala.ssa.DefaultIRFactory;
|
|
|
|
import com.ibm.wala.ssa.IR;
|
|
|
|
import com.ibm.wala.ssa.IRFactory;
|
|
|
|
import com.ibm.wala.ssa.SSACFG;
|
2011-04-03 04:08:05 +00:00
|
|
|
import com.ibm.wala.ssa.SSACFG.ExceptionHandlerBasicBlock;
|
2007-06-06 20:15:48 +00:00
|
|
|
import com.ibm.wala.ssa.SSAGetCaughtExceptionInstruction;
|
2009-05-20 18:59:53 +00:00
|
|
|
import com.ibm.wala.ssa.SSAIndirectionData;
|
2011-04-03 04:08:05 +00:00
|
|
|
import com.ibm.wala.ssa.SSAIndirectionData.Name;
|
2007-06-06 20:15:48 +00:00
|
|
|
import com.ibm.wala.ssa.SSAInstruction;
|
|
|
|
import com.ibm.wala.ssa.SSAOptions;
|
|
|
|
import com.ibm.wala.ssa.SymbolTable;
|
|
|
|
import com.ibm.wala.types.TypeReference;
|
2007-02-02 17:17:13 +00:00
|
|
|
|
2015-10-09 23:05:04 +00:00
|
|
|
public class AstIRFactory<T extends IMethod> implements IRFactory<T> {
|
2007-02-02 17:17:13 +00:00
|
|
|
|
2017-07-28 20:33:41 +00:00
|
|
|
public ControlFlowGraph<?, ?> makeCFG(final IMethod method) {
|
2007-02-08 20:45:07 +00:00
|
|
|
return ((AstMethod) method).getControlFlowGraph();
|
2007-02-02 17:17:13 +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 static class AstDefaultIRFactory<T extends IMethod> extends DefaultIRFactory {
|
|
|
|
private final AstIRFactory<T> astFactory;
|
2012-01-27 20:15:33 +00:00
|
|
|
|
|
|
|
public AstDefaultIRFactory() {
|
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
|
|
|
this(new AstIRFactory<T>());
|
2012-01-27 20:15:33 +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 AstDefaultIRFactory(AstIRFactory<T> astFactory) {
|
2012-01-27 20:15:33 +00:00
|
|
|
this.astFactory = astFactory;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-01-27 20:15:33 +00:00
|
|
|
public IR makeIR(IMethod method, Context context, SSAOptions options) {
|
|
|
|
if (method instanceof AstMethod) {
|
|
|
|
return astFactory.makeIR(method, context, options);
|
|
|
|
} else {
|
|
|
|
return super.makeIR(method, context, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-01-27 20:15:33 +00:00
|
|
|
public ControlFlowGraph makeCFG(IMethod method, Context context) {
|
|
|
|
if (method instanceof AstMethod) {
|
2017-07-28 20:33:41 +00:00
|
|
|
return astFactory.makeCFG(method);
|
2012-01-27 20:15:33 +00:00
|
|
|
} else {
|
|
|
|
return super.makeCFG(method, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 17:08:34 +00:00
|
|
|
public static class AstIR extends IR {
|
2008-12-02 14:08:12 +00:00
|
|
|
private final LexicalInformation lexicalInfo;
|
|
|
|
|
2018-05-09 22:10:20 +00:00
|
|
|
private final SSAConversion.SSAInformation localMap;
|
2007-02-02 17:17:13 +00:00
|
|
|
|
2008-12-02 14:08:12 +00:00
|
|
|
public LexicalInformation lexicalInfo() {
|
|
|
|
return lexicalInfo;
|
|
|
|
}
|
|
|
|
|
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 setCatchInstructions(SSACFG ssacfg, AbstractCFG<?, ?> oldcfg) {
|
2007-02-02 17:17:13 +00:00
|
|
|
for (int i = 0; i < oldcfg.getNumberOfNodes(); i++)
|
2007-02-08 20:45:07 +00:00
|
|
|
if (oldcfg.isCatchBlock(i)) {
|
|
|
|
ExceptionHandlerBasicBlock B = (ExceptionHandlerBasicBlock) ssacfg.getNode(i);
|
|
|
|
B.setCatchInstruction((SSAGetCaughtExceptionInstruction) getInstructions()[B.getFirstInstructionIndex()]);
|
2007-07-06 14:11:24 +00:00
|
|
|
getInstructions()[B.getFirstInstructionIndex()] = null;
|
2007-02-08 20:45:07 +00:00
|
|
|
}
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 17:08:34 +00:00
|
|
|
private static void setupCatchTypes(SSACFG cfg, Map<IBasicBlock<SSAInstruction>, TypeReference[]> map) {
|
2017-02-23 15:10:39 +00:00
|
|
|
for(Entry<IBasicBlock<SSAInstruction>, TypeReference[]> e : map.entrySet()) {
|
2013-04-11 01:09:10 +00:00
|
|
|
if (e.getKey().getNumber() != -1) {
|
|
|
|
ExceptionHandlerBasicBlock bb = (ExceptionHandlerBasicBlock) cfg.getNode(e.getKey().getNumber());
|
|
|
|
for (int j = 0; j < e.getValue().length; j++) {
|
|
|
|
bb.addCaughtExceptionType(e.getValue()[j]);
|
2007-02-08 20:45:07 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-08 20:45:07 +00:00
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2018-05-09 22:10:20 +00:00
|
|
|
public SSAInformation getLocalMap() {
|
2007-02-02 17:17:13 +00:00
|
|
|
return localMap;
|
|
|
|
}
|
2007-02-08 20:45:07 +00:00
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2007-02-02 17:17:13 +00:00
|
|
|
protected String instructionPosition(int instructionIndex) {
|
2013-06-25 15:53:58 +00:00
|
|
|
Position pos = getMethod().getSourcePosition(instructionIndex);
|
2007-02-02 17:17:13 +00:00
|
|
|
if (pos == null) {
|
|
|
|
return "";
|
|
|
|
} else {
|
2007-02-08 20:45:07 +00:00
|
|
|
return pos.toString();
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
|
|
|
public AstMethod getMethod() {
|
|
|
|
return (AstMethod)super.getMethod();
|
|
|
|
}
|
|
|
|
|
2007-02-08 20:45:07 +00:00
|
|
|
private AstIR(AstMethod method, SSAInstruction[] instructions, SymbolTable symbolTable, SSACFG cfg, SSAOptions options) {
|
2007-02-02 17:17:13 +00:00
|
|
|
super(method, instructions, symbolTable, cfg, options);
|
2007-02-08 20:45:07 +00:00
|
|
|
|
2008-12-02 14:08:12 +00:00
|
|
|
lexicalInfo = method.cloneLexicalInfo();
|
|
|
|
|
2007-02-02 17:17:13 +00:00
|
|
|
localMap = SSAConversion.convert(method, this, options);
|
2007-02-08 20:45:07 +00:00
|
|
|
|
2008-12-02 14:08:12 +00:00
|
|
|
setCatchInstructions(getControlFlowGraph(), method.cfg());
|
2007-03-14 03:38:59 +00:00
|
|
|
|
2008-12-02 14:08:12 +00:00
|
|
|
setupCatchTypes(getControlFlowGraph(), method.catchTypes());
|
2007-02-02 17:17:13 +00:00
|
|
|
|
|
|
|
setupLocationMap();
|
|
|
|
}
|
2009-05-20 18:59:53 +00:00
|
|
|
|
|
|
|
@Override
|
2009-05-29 15:26:35 +00:00
|
|
|
protected SSAIndirectionData<Name> getIndirectionData() {
|
2009-05-20 18:59:53 +00:00
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
}
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
2007-02-08 20:45:07 +00:00
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2007-07-06 22:09:29 +00:00
|
|
|
public IR makeIR(final IMethod method, final Context context, final SSAOptions options) {
|
2009-04-30 13:16:52 +00:00
|
|
|
assert method instanceof AstMethod : method.toString();
|
2010-09-09 14:03:22 +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
|
|
|
AbstractCFG<?, ?> oldCfg = ((AstMethod) method).cfg();
|
2008-12-02 14:08:12 +00:00
|
|
|
SSAInstruction[] oldInstrs = (SSAInstruction[]) oldCfg.getInstructions();
|
|
|
|
SSAInstruction[] instrs = new SSAInstruction[ oldInstrs.length ];
|
|
|
|
System.arraycopy(oldInstrs, 0, instrs, 0, instrs.length);
|
|
|
|
|
2010-09-09 14:03:22 +00:00
|
|
|
IR newIR = new AstIR((AstMethod) method, instrs, ((AstMethod) method).symbolTable().copy(), new SSACFG(method, oldCfg, instrs),
|
2007-02-08 20:45:07 +00:00
|
|
|
options);
|
2007-02-02 17:17:13 +00:00
|
|
|
|
|
|
|
return newIR;
|
|
|
|
}
|
2007-02-08 20:45:07 +00:00
|
|
|
|
2008-12-16 14:27:42 +00:00
|
|
|
public static IRFactory<IMethod> makeDefaultFactory() {
|
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 new AstDefaultIRFactory<>();
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
2008-05-12 13:34:25 +00:00
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2008-05-12 13:34:25 +00:00
|
|
|
public boolean contextIsIrrelevant(IMethod method) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|