further work on analysis for JavaScript in Eclipse
This commit is contained in:
parent
cb17b24875
commit
56236dec53
|
@ -55,7 +55,7 @@ public class JSMethodInstructionVisitor extends JSAbstractInstructionVisitor {
|
|||
if(fndef instanceof AstGlobalRead) {
|
||||
AstGlobalRead agr = (AstGlobalRead)fndef;
|
||||
if(agr.getGlobalName().equals("global Function")) {
|
||||
if(invk.getNumberOfParameters() == 0)
|
||||
if(invk.getNumberOfParameters() < 2)
|
||||
return false;
|
||||
// this may be a genuine use of "new Function()", not a declaration/expression
|
||||
if(!symtab.isStringConstant(invk.getUse(1)))
|
||||
|
|
|
@ -52,11 +52,15 @@ public class PessimisticCallGraphBuilder extends FieldBasedCallGraphBuilder {
|
|||
return flowgraph;
|
||||
}
|
||||
|
||||
protected boolean filterFunction(IMethod function) {
|
||||
return function.getDescriptor().equals(AstMethodReference.fnDesc);
|
||||
}
|
||||
|
||||
// add inter-procedural flow for local calls
|
||||
private void resolveLocalCalls(FlowGraph flowgraph) {
|
||||
for(IClass klass : cha) {
|
||||
for(IMethod method : klass.getDeclaredMethods()) {
|
||||
if(method.getDescriptor().equals(AstMethodReference.fnDesc)) {
|
||||
if (filterFunction(method)) {
|
||||
IR ir = cache.getIR(method);
|
||||
ir.visitAllInstructions(new LocalCallSSAVisitor(method, ir.getSymbolTable(), cache.getDefUse(ir), flowgraph));
|
||||
}
|
||||
|
|
|
@ -79,6 +79,12 @@ public class JSAstTranslator extends AstTranslator {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean ignoreName(String name) {
|
||||
return super.ignoreName(name) || name.endsWith(" temp");
|
||||
}
|
||||
|
||||
/**
|
||||
* generate an instruction that checks if readVn is undefined and throws an exception if it isn't
|
||||
*/
|
||||
|
|
|
@ -423,7 +423,7 @@ public abstract class AstSSAPropagationCallGraphBuilder extends SSAPropagationCa
|
|||
system.newSideEffect(new UnaryOperator<PointsToSetVariable>() {
|
||||
@Override
|
||||
public byte evaluate(PointsToSetVariable lhs, PointsToSetVariable rhs) {
|
||||
final IntSetVariable objects = (IntSetVariable) rhs;
|
||||
final IntSetVariable objects = rhs;
|
||||
if (objects.getValue() != null) {
|
||||
objects.getValue().foreach(new IntSetAction() {
|
||||
@Override
|
||||
|
@ -489,7 +489,7 @@ public abstract class AstSSAPropagationCallGraphBuilder extends SSAPropagationCa
|
|||
system.newSideEffect(new UnaryOperator<PointsToSetVariable>() {
|
||||
@Override
|
||||
public byte evaluate(PointsToSetVariable lhs, PointsToSetVariable rhs) {
|
||||
final IntSetVariable objects = (IntSetVariable) rhs;
|
||||
final IntSetVariable objects = rhs;
|
||||
if (objects.getValue() != null) {
|
||||
objects.getValue().foreach(new IntSetAction() {
|
||||
@Override
|
||||
|
@ -971,7 +971,7 @@ public abstract class AstSSAPropagationCallGraphBuilder extends SSAPropagationCa
|
|||
system.newSideEffect(new UnaryOperator<PointsToSetVariable>() {
|
||||
@Override
|
||||
public byte evaluate(PointsToSetVariable lhs, PointsToSetVariable rhs) {
|
||||
final IntSetVariable objects = (IntSetVariable) rhs;
|
||||
final IntSetVariable objects = rhs;
|
||||
if (objects.getValue() != null) {
|
||||
objects.getValue().foreach(new IntSetAction() {
|
||||
@Override
|
||||
|
@ -1035,7 +1035,7 @@ public abstract class AstSSAPropagationCallGraphBuilder extends SSAPropagationCa
|
|||
system.newSideEffect(new UnaryOperator<PointsToSetVariable>() {
|
||||
@Override
|
||||
public byte evaluate(PointsToSetVariable lhs, PointsToSetVariable rhs) {
|
||||
final IntSetVariable fields = (IntSetVariable) rhs;
|
||||
final IntSetVariable fields = rhs;
|
||||
if (fields.getValue() != null) {
|
||||
fields.getValue().foreach(new IntSetAction() {
|
||||
@Override
|
||||
|
|
|
@ -11,7 +11,6 @@ package com.ibm.wala.cast.ipa.callgraph;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
|
@ -19,7 +18,6 @@ import com.ibm.wala.cast.loader.SingleClassLoaderFactory;
|
|||
import com.ibm.wala.classLoader.ArrayClassLoader;
|
||||
import com.ibm.wala.classLoader.Language;
|
||||
import com.ibm.wala.classLoader.SourceModule;
|
||||
import com.ibm.wala.classLoader.SourceURLModule;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
|
|
@ -71,7 +71,7 @@ public class CrossLanguageClassHierarchy implements IClassHierarchy {
|
|||
}
|
||||
|
||||
private IClassHierarchy getHierarchy(Atom language) {
|
||||
return (IClassHierarchy) hierarchies.get(language);
|
||||
return hierarchies.get(language);
|
||||
}
|
||||
|
||||
private IClassHierarchy getHierarchy(IClassLoader loader) {
|
||||
|
@ -105,7 +105,7 @@ public class CrossLanguageClassHierarchy implements IClassHierarchy {
|
|||
loaders.add(getLoader((ClassLoaderReference) ldrs.next()));
|
||||
}
|
||||
|
||||
return (IClassLoader[]) loaders.toArray(new IClassLoader[loaders.size()]);
|
||||
return loaders.toArray(new IClassLoader[loaders.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -261,7 +261,7 @@ public abstract class AbstractSSAConversion {
|
|||
|
||||
initializeVariables();
|
||||
|
||||
SEARCH((SSACFG.BasicBlock) CFG.entry());
|
||||
SEARCH(CFG.entry());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ package com.ibm.wala.cast.ir.ssa;
|
|||
|
||||
import com.ibm.wala.classLoader.CallSiteReference;
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.ssa.SSAInstruction.IVisitor;
|
||||
import com.ibm.wala.ssa.SSAInstructionFactory;
|
||||
|
||||
/**
|
||||
|
|
|
@ -206,7 +206,7 @@ public class SSAConversion extends AbstractSSAConversion {
|
|||
PhiUseRecord use = (PhiUseRecord) x;
|
||||
int bb = use.BBnumber;
|
||||
int phi = use.phiNumber;
|
||||
SSACFG.BasicBlock BB = (SSACFG.BasicBlock) CFG.getNode(bb);
|
||||
SSACFG.BasicBlock BB = CFG.getNode(bb);
|
||||
BB.addPhiForLocal(phi, (SSAPhiInstruction) undo(BB.getPhiForLocal(phi), use.useNumber, lhs));
|
||||
copyPropagationMap.remove(use);
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ public class SSAConversion extends AbstractSSAConversion {
|
|||
|
||||
private CopyPropagationRecord topR(int v) {
|
||||
if (R[v] != null && !R[v].isEmpty()) {
|
||||
CopyPropagationRecord rec = (CopyPropagationRecord) R[v].peek();
|
||||
CopyPropagationRecord rec = R[v].peek();
|
||||
if (top(v) == rec.rhs) {
|
||||
return rec;
|
||||
}
|
||||
|
@ -474,7 +474,7 @@ public class SSAConversion extends AbstractSSAConversion {
|
|||
this.R = new Stack[ir.getSymbolTable().getMaxValueNumber() + 1];
|
||||
|
||||
for (int i = 0; i < CFG.getNumberOfNodes(); i++) {
|
||||
SSACFG.BasicBlock bb = (SSACFG.BasicBlock) CFG.getNode(i);
|
||||
SSACFG.BasicBlock bb = CFG.getNode(i);
|
||||
if (bb.hasPhi()) {
|
||||
int n = 0;
|
||||
for (Iterator X = bb.iteratePhis(); X.hasNext(); n++)
|
||||
|
|
|
@ -80,7 +80,7 @@ public class LiveAnalysis {
|
|||
*/
|
||||
public static Result perform(final ControlFlowGraph<SSAInstruction, ISSABasicBlock> cfg, final SymbolTable symtab, final BitVector considerLiveAtExit) {
|
||||
final BitVectorIntSet liveAtExit = new BitVectorIntSet(considerLiveAtExit);
|
||||
final SSAInstruction[] instructions = (SSAInstruction[]) cfg.getInstructions();
|
||||
final SSAInstruction[] instructions = cfg.getInstructions();
|
||||
|
||||
/**
|
||||
* Gen/kill operator specific to exit basic blocks
|
||||
|
|
|
@ -314,6 +314,14 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
return doLexReadHelper(context, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name A variable name
|
||||
* @return is this name safe to overwrite, i.e. it's synthetic from the translator?
|
||||
*/
|
||||
protected boolean ignoreName(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* we only have this method to avoid having to pass a node parameter at other
|
||||
* call sites, as would be required for
|
||||
|
@ -2987,7 +2995,12 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
Scope scope = S.next();
|
||||
for (Iterator<String> I = scope.getAllNames(); I.hasNext();) {
|
||||
String nm = I.next();
|
||||
Symbol v = (Symbol) scope.lookup(nm);
|
||||
|
||||
if (ignoreName(nm)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Symbol v = scope.lookup(nm);
|
||||
|
||||
if (v.isInternalName()) {
|
||||
continue;
|
||||
|
@ -2997,7 +3010,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
if (scope.isConstant(v.valueNumber()))
|
||||
continue;
|
||||
|
||||
assert map[v.valueNumber()] == null || map[v.valueNumber()].equals(nm) : "value number " + v.valueNumber()
|
||||
assert map[v.valueNumber()] == null || map[v.valueNumber()].equals(nm) || ignoreName(map[v.valueNumber()]) : "value number " + v.valueNumber()
|
||||
+ " mapped to multiple names in " + n.getName() + ": " + nm + " and " + map[v.valueNumber()];
|
||||
|
||||
map[v.valueNumber()] = nm;
|
||||
|
@ -3036,17 +3049,16 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected WalkContext makeFileContext(WalkContext c, CAstEntity n) {
|
||||
return new FileContext((WalkContext) c, n.getName());
|
||||
return new FileContext(c, n.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WalkContext makeTypeContext(WalkContext c, CAstEntity n) {
|
||||
return new TypeContext((WalkContext) c, n);
|
||||
return new TypeContext(c, n);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WalkContext makeCodeContext(WalkContext c, CAstEntity n) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
protected WalkContext makeCodeContext(WalkContext context, CAstEntity n) {
|
||||
AbstractScope scope;
|
||||
if (n.getKind() == CAstEntity.SCRIPT_ENTITY)
|
||||
scope = makeScriptScope(n, context.currentScope());
|
||||
|
@ -3082,7 +3094,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
// processing allows such.
|
||||
CAstEntity topEntity = context.top(); // better be a type
|
||||
assert topEntity.getKind() == CAstEntity.TYPE_ENTITY : "Parent of field entity is not a type???";
|
||||
defineField(topEntity, (WalkContext) context, n);
|
||||
defineField(topEntity, context, n);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3099,7 +3111,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitTypeEntity(CAstEntity n, WalkContext context, WalkContext typeContext, CAstVisitor<WalkContext> visitor) {
|
||||
return !defineType(n, (WalkContext) context);
|
||||
return !defineType(n, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3109,16 +3121,16 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
@Override
|
||||
protected boolean visitFunctionEntity(CAstEntity n, WalkContext context, WalkContext codeContext, CAstVisitor<WalkContext> visitor) {
|
||||
if (n.getAST() == null) // presumably abstract
|
||||
declareFunction(n, (WalkContext) context);
|
||||
declareFunction(n, context);
|
||||
else
|
||||
initFunctionEntity(n, (WalkContext) context, (WalkContext) codeContext);
|
||||
initFunctionEntity(n, context, codeContext);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void leaveFunctionEntity(CAstEntity n, WalkContext context, WalkContext codeContext, CAstVisitor<WalkContext> visitor) {
|
||||
if (n.getAST() != null) // non-abstract
|
||||
closeFunctionEntity(n, (WalkContext) context, (WalkContext) codeContext);
|
||||
closeFunctionEntity(n, context, codeContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3128,14 +3140,14 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitScriptEntity(CAstEntity n, WalkContext context, WalkContext codeContext, CAstVisitor<WalkContext> visitor) {
|
||||
declareFunction(n, (WalkContext) codeContext);
|
||||
initFunctionEntity(n, (WalkContext) context, (WalkContext) codeContext);
|
||||
declareFunction(n, codeContext);
|
||||
initFunctionEntity(n, context, codeContext);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void leaveScriptEntity(CAstEntity n, WalkContext context, WalkContext codeContext, CAstVisitor<WalkContext> visitor) {
|
||||
closeFunctionEntity(n, (WalkContext) context, (WalkContext) codeContext);
|
||||
closeFunctionEntity(n, context, codeContext);
|
||||
}
|
||||
|
||||
public void initFunctionEntity(final CAstEntity n, WalkContext parentContext, WalkContext functionContext) {
|
||||
|
@ -3169,7 +3181,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
// (put here to allow subclasses to handle stuff in scoped entities)
|
||||
// assemble lexical information
|
||||
AstLexicalInformation LI = new AstLexicalInformation(functionContext.getEntityName(n), (AbstractScope) functionContext.currentScope(), cfg.getInstructions(),
|
||||
AstLexicalInformation LI = new AstLexicalInformation(functionContext.getEntityName(n), functionContext.currentScope(), cfg.getInstructions(),
|
||||
functionContext.exposeNameSet(n, false),
|
||||
functionContext.exposeNameSet(n, true),
|
||||
functionContext.getAccesses(n));
|
||||
|
@ -3182,13 +3194,13 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected WalkContext makeLocalContext(WalkContext context, CAstNode n) {
|
||||
return new LocalContext((WalkContext) context, makeLocalScope(n, ((WalkContext) context).currentScope()));
|
||||
return new LocalContext(context, makeLocalScope(n, context.currentScope()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WalkContext makeUnwindContext(WalkContext context, CAstNode n, CAstVisitor<WalkContext> visitor) {
|
||||
// here, n represents the "finally" block of the unwind
|
||||
return new UnwindContext(n, (WalkContext) context, visitor);
|
||||
return new UnwindContext(n, context, visitor);
|
||||
}
|
||||
|
||||
private Map<CAstEntity, Set<String>> entity2ExposedNames;
|
||||
|
@ -3266,7 +3278,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitLoop(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
// loop test block
|
||||
context.cfg().newBlock(true);
|
||||
PreBasicBlock headerB = context.cfg().getCurrentBlock();
|
||||
|
@ -3314,7 +3326,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveGetCaughtException(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
String nm = (String) n.getChild(0).getValue();
|
||||
context.currentScope().declare(new FinalCAstSymbol(nm));
|
||||
context.cfg().addInstruction(
|
||||
|
@ -3344,7 +3356,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitCall(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = context.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
return false;
|
||||
|
@ -3352,7 +3364,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveCall(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = c.getValue(n);
|
||||
int exp = context.currentScope().allocateTempValue();
|
||||
int fun = c.getValue(n.getChild(0));
|
||||
|
@ -3371,7 +3383,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveVar(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
String nm = (String) n.getChild(0).getValue();
|
||||
assert nm != null : "cannot find var for " + CAstPrinter.print(n, context.getSourceMap());
|
||||
Symbol s = context.currentScope().lookup(nm);
|
||||
|
@ -3392,13 +3404,13 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveConstant(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
c.setValue(n, context.currentScope().getConstantValue(n.getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean visitBinaryExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = context.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
return false;
|
||||
|
@ -3428,7 +3440,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveBinaryExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = c.getValue(n);
|
||||
CAstNode l = n.getChild(1);
|
||||
CAstNode r = n.getChild(2);
|
||||
|
@ -3448,7 +3460,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitUnaryExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = context.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
return false;
|
||||
|
@ -3456,7 +3468,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveUnaryExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = c.getValue(n);
|
||||
CAstNode v = n.getChild(1);
|
||||
context.cfg().addInstruction(insts.UnaryOpInstruction(translateUnaryOpcode(n.getChild(0)), result, c.getValue(v)));
|
||||
|
@ -3464,7 +3476,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitArrayLength(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = context.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
return false;
|
||||
|
@ -3472,7 +3484,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveArrayLength(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = c.getValue(n);
|
||||
int arrayValue = c.getValue(n.getChild(0));
|
||||
context.cfg().addInstruction(insts.ArrayLengthInstruction(result, arrayValue));
|
||||
|
@ -3485,7 +3497,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveArrayRef(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int arrayValue = c.getValue(n.getChild(0));
|
||||
int result = context.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
|
@ -3526,7 +3538,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveReturn(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
if (n.getChildCount() > 0) {
|
||||
context.cfg().addInstruction(insts.ReturnInstruction(c.getValue(n.getChild(0)), false));
|
||||
} else {
|
||||
|
@ -3545,7 +3557,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveIfgoto(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
if (n.getChildCount() == 1) {
|
||||
context.cfg().addInstruction(
|
||||
insts.ConditionalBranchInstruction(translateConditionOpcode(CAstOperator.OP_NE), null, c.getValue(n.getChild(0)), context
|
||||
|
@ -3570,7 +3582,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveGoto(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
if (!context.cfg().isDeadBlock(context.cfg().getCurrentBlock())) {
|
||||
context.cfg().addPreNode(n, context.getUnwindState());
|
||||
context.cfg().addPreEdge(n, context.getControlFlow().getTarget(n, null), false);
|
||||
|
@ -3585,7 +3597,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitLabelStmt(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
if (!context.getControlFlow().getSourceNodes(n).isEmpty()) {
|
||||
context.cfg().newBlock(true);
|
||||
context.cfg().addPreNode(n, context.getUnwindState());
|
||||
|
@ -3598,7 +3610,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
}
|
||||
|
||||
protected void processIf(CAstNode n, boolean isExpr, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
PreBasicBlock trueB = null, falseB = null;
|
||||
// conditional
|
||||
CAstNode l = n.getChild(0);
|
||||
|
@ -3673,7 +3685,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitIfExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = context.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
processIf(n, true, c, visitor);
|
||||
|
@ -3687,7 +3699,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveNew(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
|
||||
int result = context.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
|
@ -3711,7 +3723,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveObjectLiteralFieldInit(CAstNode n, int i, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
if (n.getChild(i).getKind() == CAstNode.EMPTY) {
|
||||
handleUnspecifiedLiteralKey(context, n, i, visitor);
|
||||
}
|
||||
|
@ -3735,7 +3747,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveArrayLiteralInitElement(CAstNode n, int i, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
arrayOpHandler.doArrayWrite(context, c.getValue(n.getChild(0)), n,
|
||||
new int[] { context.currentScope().getConstantValue(new Integer(i - 1)) }, c.getValue(n.getChild(i)));
|
||||
}
|
||||
|
@ -3746,7 +3758,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitObjectRef(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = context.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
return false;
|
||||
|
@ -3754,7 +3766,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveObjectRef(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = c.getValue(n);
|
||||
CAstNode elt = n.getChild(1);
|
||||
doFieldRead(context, result, c.getValue(n.getChild(0)), elt, n);
|
||||
|
@ -3784,7 +3796,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
/* Prereq: a.getKind() == ASSIGN_PRE_OP || a.getKind() == ASSIGN_POST_OP */
|
||||
protected int processAssignOp(CAstNode n, CAstNode v, CAstNode a, int temp, boolean post, WalkContext c) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int rval = c.getValue(v);
|
||||
CAstNode op = a.getChild(2);
|
||||
int temp2 = context.currentScope().allocateTempValue();
|
||||
|
@ -3808,7 +3820,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveArrayRefAssign(CAstNode n, CAstNode v, CAstNode a, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int rval = c.getValue(v);
|
||||
c.setValue(n, rval);
|
||||
arrayOpHandler.doArrayWrite(context, c.getValue(n.getChild(0)), n, gatherArrayDims(c, n), rval);
|
||||
|
@ -3821,7 +3833,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveArrayRefAssignOp(CAstNode n, CAstNode v, CAstNode a, boolean pre, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int temp = context.currentScope().allocateTempValue();
|
||||
int[] dims = gatherArrayDims(c, n);
|
||||
arrayOpHandler.doArrayRead(context, temp, c.getValue(n.getChild(0)), n, dims);
|
||||
|
@ -3837,7 +3849,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveObjectRefAssign(CAstNode n, CAstNode v, CAstNode a, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int rval = c.getValue(v);
|
||||
c.setValue(n, rval);
|
||||
doFieldWrite(context, c.getValue(n.getChild(0)), n.getChild(1), n, rval);
|
||||
|
@ -3853,7 +3865,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveObjectRefAssignOp(CAstNode n, CAstNode v, CAstNode a, boolean pre, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int temp = context.currentScope().allocateTempValue();
|
||||
doFieldRead(context, temp, c.getValue(n.getChild(0)), n.getChild(1), n);
|
||||
int rval = processAssignOp(n, v, a, temp, !pre, c);
|
||||
|
@ -3902,7 +3914,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveVarAssign(CAstNode n, CAstNode v, CAstNode a, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int rval = c.getValue(v);
|
||||
String nm = (String) n.getChild(0).getValue();
|
||||
Symbol ls = context.currentScope().lookup(nm);
|
||||
|
@ -3917,7 +3929,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveVarAssignOp(CAstNode n, CAstNode v, CAstNode a, boolean pre, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
String nm = (String) n.getChild(0).getValue();
|
||||
Symbol ls = context.currentScope().lookup(nm);
|
||||
int temp;
|
||||
|
@ -3968,7 +3980,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
Object val = context.currentScope().getConstantObject(context.getValue(xn));
|
||||
if (val instanceof Number) {
|
||||
Number num = (Number) val;
|
||||
if ((double) num.intValue() == num.doubleValue()) {
|
||||
if (num.intValue() == num.doubleValue()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -4081,7 +4093,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitSwitch(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
if (isSimpleSwitch(n, context, visitor)) {
|
||||
doSimpleSwitch(n, context, visitor);
|
||||
} else {
|
||||
|
@ -4106,7 +4118,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveThrow(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
doThrow(context, c.getValue(n.getChild(0)));
|
||||
|
||||
context.cfg().addPreNode(n, context.getUnwindState());
|
||||
|
@ -4125,7 +4137,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitCatch(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
|
||||
// unreachable catch block
|
||||
if (context.getControlFlow().getSourceNodes(n).isEmpty()) {
|
||||
|
@ -4183,7 +4195,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected boolean visitTry(final CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
final WalkContext context = (WalkContext) c;
|
||||
final WalkContext context = c;
|
||||
boolean addSkipCatchGoto = false;
|
||||
visitor.visit(n.getChild(0), context, visitor);
|
||||
PreBasicBlock endOfTry = context.cfg().getCurrentBlock();
|
||||
|
@ -4236,7 +4248,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveEmpty(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
c.setValue(n, context.currentScope().getConstantValue(null));
|
||||
}
|
||||
|
||||
|
@ -4247,7 +4259,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leavePrimitive(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
int result = context.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
|
||||
|
@ -4271,7 +4283,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveAssert(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext context = (WalkContext) c;
|
||||
WalkContext context = c;
|
||||
boolean fromSpec = true;
|
||||
int result = c.getValue(n.getChild(0));
|
||||
if (n.getChildCount() == 2) {
|
||||
|
@ -4289,9 +4301,9 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveEachElementGet(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
int result = ((WalkContext) c).currentScope().allocateTempValue();
|
||||
int result = c.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
((WalkContext) c).cfg().addInstruction(new EachElementGetInstruction(result, c.getValue(n.getChild(0))));
|
||||
c.cfg().addInstruction(new EachElementGetInstruction(result, c.getValue(n.getChild(0))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4301,9 +4313,9 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveEachElementHasNext(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
int result = ((WalkContext) c).currentScope().allocateTempValue();
|
||||
int result = c.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
((WalkContext) c).cfg().addInstruction(new EachElementHasNextInstruction(result, c.getValue(n.getChild(0))));
|
||||
c.cfg().addInstruction(new EachElementHasNextInstruction(result, c.getValue(n.getChild(0))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4313,7 +4325,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveTypeLiteralExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext wc = (WalkContext) c;
|
||||
WalkContext wc = c;
|
||||
assert n.getChild(0).getKind() == CAstNode.CONSTANT;
|
||||
String typeNameStr = (String) n.getChild(0).getValue();
|
||||
TypeName typeName = TypeName.string2TypeName(typeNameStr);
|
||||
|
@ -4332,7 +4344,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveIsDefinedExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext wc = (WalkContext) c;
|
||||
WalkContext wc = c;
|
||||
int ref = c.getValue(n.getChild(0));
|
||||
int result = wc.currentScope().allocateTempValue();
|
||||
c.setValue(n, result);
|
||||
|
@ -4350,7 +4362,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveEcho(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext wc = (WalkContext) c;
|
||||
WalkContext wc = c;
|
||||
|
||||
int rvals[] = new int[n.getChildCount()];
|
||||
for (int i = 0; i < n.getChildCount(); i++) {
|
||||
|
@ -4371,7 +4383,7 @@ public abstract class AstTranslator extends CAstVisitor<AstTranslator.WalkContex
|
|||
|
||||
@Override
|
||||
protected void leaveInclude(final CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) {
|
||||
WalkContext wc = (WalkContext) c;
|
||||
WalkContext wc = c;
|
||||
|
||||
CAstEntity included = getIncludedEntity(n);
|
||||
|
||||
|
|
|
@ -111,12 +111,12 @@ public abstract class CAstAbstractLoader implements IClassLoader {
|
|||
|
||||
public IClass lookupClass(String className, IClassHierarchy cha) {
|
||||
assert this.cha == cha;
|
||||
return (IClass) types.get(TypeName.string2TypeName(className));
|
||||
return types.get(TypeName.string2TypeName(className));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClass lookupClass(TypeName className) {
|
||||
return (IClass) types.get(className);
|
||||
return types.get(className);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -116,7 +116,7 @@ public abstract class CAstAbstractModuleLoader extends CAstAbstractLoader {
|
|||
for (Iterator ts = types.keySet().iterator(); ts.hasNext();) {
|
||||
TypeName tn = (TypeName) ts.next();
|
||||
try {
|
||||
System.err.println(("found type " + tn + " : " + types.get(tn) + " < " + ((IClass) types.get(tn)).getSuperclass()));
|
||||
System.err.println(("found type " + tn + " : " + types.get(tn) + " < " + types.get(tn).getSuperclass()));
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ public class CAstControlFlowRecorder implements CAstControlFlowMap {
|
|||
if (table.containsKey(key)) {
|
||||
Object target = table.get(key);
|
||||
assert nodeToCAst.containsKey(target);
|
||||
return (CAstNode) nodeToCAst.get(target);
|
||||
return nodeToCAst.get(target);
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public class CAstControlFlowRecorder implements CAstControlFlowMap {
|
|||
@Override
|
||||
public Collection getSourceNodes(CAstNode to) {
|
||||
if (sourceMap.containsKey(CAstToNode.get(to))) {
|
||||
return (Set) sourceMap.get(CAstToNode.get(to));
|
||||
return sourceMap.get(CAstToNode.get(to));
|
||||
} else {
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
|
@ -129,8 +129,8 @@ public class CAstControlFlowRecorder implements CAstControlFlowMap {
|
|||
nodes = new LinkedHashSet<CAstNode>();
|
||||
for (Iterator<Key> keys = table.keySet().iterator(); keys.hasNext();) {
|
||||
Key key = keys.next();
|
||||
nodes.add((CAstNode) nodeToCAst.get(key.from));
|
||||
nodes.add((CAstNode) nodeToCAst.get(table.get(key)));
|
||||
nodes.add(nodeToCAst.get(key.from));
|
||||
nodes.add(nodeToCAst.get(table.get(key)));
|
||||
}
|
||||
cachedMappedNodes = nodes;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class CAstNodeTypeMapRecorder
|
|||
|
||||
@Override
|
||||
public CAstType getNodeType(CAstNode node) {
|
||||
return (CAstType) get(node);
|
||||
return get(node);
|
||||
}
|
||||
|
||||
public void add(CAstNode node, CAstType type) {
|
||||
|
|
|
@ -164,7 +164,7 @@ public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>, K e
|
|||
CAstNode oldSource = N.fst;
|
||||
K key = N.snd;
|
||||
|
||||
CAstNode newSource = (CAstNode) entry.getValue();
|
||||
CAstNode newSource = entry.getValue();
|
||||
assert newSource != null;
|
||||
|
||||
newMap.map(newSource, newSource);
|
||||
|
@ -213,7 +213,7 @@ public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>, K e
|
|||
|
||||
CAstNode newTarget;
|
||||
if (nodeMap.containsKey(targetKey)) {
|
||||
newTarget = (CAstNode) nodeMap.get(targetKey);
|
||||
newTarget = nodeMap.get(targetKey);
|
||||
newMap.add(newSource, newTarget, newLabel);
|
||||
allNewTargetNodes.add(newTarget);
|
||||
|
||||
|
|
|
@ -58,12 +58,12 @@ public class CAstFunctions {
|
|||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return i < ((CAstNode) n).getChildCount();
|
||||
return i < n.getChildCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CAstNode next() {
|
||||
return ((CAstNode) n).getChild(i++);
|
||||
return n.getChild(i++);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,6 +15,8 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
||||
import com.ibm.wala.cast.tree.impl.AbstractSourcePosition;
|
||||
|
@ -26,45 +28,69 @@ public class SourceBuffer {
|
|||
public SourceBuffer(Position p) throws IOException {
|
||||
this.p = p;
|
||||
|
||||
InputStreamReader reader = new InputStreamReader(p.getInputStream());
|
||||
if (p.getFirstOffset() >= 0 && p.getLastOffset() >= 0) {
|
||||
int skip = 0;
|
||||
while((skip += reader.skip(p.getFirstOffset())) < p.getFirstOffset());
|
||||
|
||||
int size = p.getLastOffset() - p.getFirstOffset();
|
||||
char[] buf = new char[size];
|
||||
int read = 0;
|
||||
while ((read += reader.read(buf, read, size)) < size);
|
||||
|
||||
this.lines = new String(buf).split("\\n");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
|
||||
String currentLine = null;
|
||||
List<String> lines = new ArrayList<String>();
|
||||
int offset = 0, line = 0;
|
||||
do {
|
||||
currentLine = reader.readLine();
|
||||
if (currentLine == null) {
|
||||
this.lines = new String[0];
|
||||
return;
|
||||
}
|
||||
offset += (currentLine.length() + 1);
|
||||
line++;
|
||||
} while (p.getLastOffset()>=0? p.getFirstOffset() > offset: p.getFirstLine() > line);
|
||||
|
||||
// partial first line
|
||||
if (p.getLastOffset() >= 0) {
|
||||
if (p.getFirstOffset() == offset) {
|
||||
lines.add("\n");
|
||||
} else {
|
||||
lines.add(currentLine.substring(p.getFirstOffset() - (offset-currentLine.length()-1)));
|
||||
}
|
||||
} else {
|
||||
this.lines = new String[ p.getLastLine() - p.getFirstLine() + 1];
|
||||
BufferedReader r =
|
||||
new BufferedReader(reader);
|
||||
int line = 1;
|
||||
while (line <= p.getLastLine()) {
|
||||
String theLine = r.readLine();
|
||||
if (line >= p.getFirstLine()) {
|
||||
lines[line-p.getFirstLine()] =
|
||||
line == p.getLastLine()?
|
||||
theLine.substring(0, Math.min(theLine.length(), p.getLastCol()+1)):
|
||||
theLine;
|
||||
lines.add(currentLine.substring(p.getFirstCol()));
|
||||
}
|
||||
|
||||
while (p.getLastOffset()>=0? p.getLastOffset() >= offset: p.getLastLine() >= line) {
|
||||
currentLine = reader.readLine();
|
||||
|
||||
if (currentLine == null) {
|
||||
offset = p.getLastOffset();
|
||||
break;
|
||||
} else {
|
||||
offset += currentLine.length() + 1;
|
||||
}
|
||||
line++;
|
||||
if (p.getLastOffset() >= 0) {
|
||||
if (offset > p.getLastOffset()) {
|
||||
lines.add(currentLine.substring(0, currentLine.length() - (offset - p.getLastOffset()) + 1));
|
||||
} else {
|
||||
lines.add(currentLine);
|
||||
}
|
||||
} else {
|
||||
if (p.getLastLine() == line) {
|
||||
lines.add(currentLine.substring(0, p.getLastCol()));
|
||||
} else {
|
||||
lines.add(currentLine);
|
||||
}
|
||||
line++;
|
||||
}
|
||||
}
|
||||
|
||||
this.lines = lines.toArray(new String[ lines.size() ]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer result = new StringBuffer();
|
||||
for(int i = 0; i < lines.length; i++) {
|
||||
if (i == 0 && p.getFirstOffset() == -1) {
|
||||
result.append(lines[i].substring(p.getFirstCol())).append("\n");
|
||||
} else if (i == lines.length - 1) {
|
||||
result.append(lines[i]);
|
||||
if (i == lines.length - 1) {
|
||||
result.append(lines[i]);
|
||||
} else {
|
||||
result.append(lines[i]).append("\n");
|
||||
result.append(lines[i]).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.junit.Test;
|
|||
|
||||
import com.ibm.wala.cast.ipa.callgraph.CAstAnalysisScope;
|
||||
import com.ibm.wala.cast.js.client.EclipseJavaScriptAnalysisEngine;
|
||||
import com.ibm.wala.cast.js.client.EclipseJavaScriptAnalysisEngine.BuilderType;
|
||||
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
|
||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader;
|
||||
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
|
||||
|
@ -90,7 +91,7 @@ public abstract class AbstractJSProjectScopeTest {
|
|||
}
|
||||
|
||||
protected EclipseJavaScriptAnalysisEngine makeAnalysisEngine(IJavaScriptProject p) throws IOException, CoreException {
|
||||
return new EclipseJavaScriptAnalysisEngine(p);
|
||||
return new EclipseJavaScriptAnalysisEngine(p, BuilderType.REFLECTIVE);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.wst.jsdt.core.IJavaScriptProject;
|
||||
|
||||
import com.ibm.wala.cast.js.client.EclipseJavaScriptAnalysisEngine;
|
||||
import com.ibm.wala.cast.js.client.EclipseJavaScriptAnalysisEngine.BuilderType;
|
||||
import com.ibm.wala.cast.js.client.EclipseWebAnalysisEngine;
|
||||
import com.ibm.wala.ide.util.EclipseWebProjectPath;
|
||||
|
||||
|
@ -19,7 +20,7 @@ public class WLProjectWebScopeTest extends WLProjectScopeTest {
|
|||
|
||||
@Override
|
||||
protected EclipseJavaScriptAnalysisEngine makeAnalysisEngine(IJavaScriptProject p) throws IOException, CoreException {
|
||||
return new EclipseWebAnalysisEngine(p, Collections.EMPTY_SET);
|
||||
return new EclipseWebAnalysisEngine(p, Collections.EMPTY_SET, BuilderType.REFLECTIVE);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.Collections;
|
|||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.eclipse.wst.jsdt.core.IJavaScriptProject;
|
||||
|
||||
import com.ibm.wala.cast.ipa.callgraph.CAstAnalysisScope;
|
||||
|
@ -51,12 +52,18 @@ import com.ibm.wala.types.ClassLoaderReference;
|
|||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.NullProgressMonitor;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
import com.ibm.wala.util.functions.Function;
|
||||
|
||||
public class EclipseJavaScriptAnalysisEngine extends EclipseProjectSourceAnalysisEngine<IJavaScriptProject> {
|
||||
|
||||
public EclipseJavaScriptAnalysisEngine(IJavaScriptProject project) throws IOException, CoreException {
|
||||
public enum BuilderType { PESSIMISTIC, OPTIMISTIC, REFLECTIVE };
|
||||
|
||||
private final BuilderType builderType;
|
||||
|
||||
public EclipseJavaScriptAnalysisEngine(IJavaScriptProject project, BuilderType builderType) throws IOException, CoreException {
|
||||
super(project, "js");
|
||||
this.builderType = builderType;
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,7 +95,7 @@ public class EclipseJavaScriptAnalysisEngine extends EclipseProjectSourceAnalysi
|
|||
|
||||
@Override
|
||||
protected JavaScriptEclipseProjectPath createProjectPath(IJavaScriptProject project) throws IOException, CoreException {
|
||||
return JavaScriptEclipseProjectPath.make(project, Collections.EMPTY_SET);
|
||||
return JavaScriptEclipseProjectPath.make(project, Collections.<Pair<String,Plugin>>emptySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -136,23 +143,43 @@ public class EclipseJavaScriptAnalysisEngine extends EclipseProjectSourceAnalysi
|
|||
String scriptName = getScriptName(((AstMethod)e.getMethod()));
|
||||
scripts.add(scriptName);
|
||||
}
|
||||
|
||||
FieldBasedCallGraphBuilder builder = new OptimisticCallgraphBuilder(getClassHierarchy(), getDefaultOptions(roots), makeDefaultCache()) {
|
||||
|
||||
final Function<IMethod, Boolean> filter = new Function<IMethod, Boolean>() {
|
||||
@Override
|
||||
protected FlowGraph flowGraphFactory() {
|
||||
FlowGraphBuilder b = new FilteredFlowGraphBuilder(cha, cache, new Function<IMethod, Boolean>() {
|
||||
@Override
|
||||
public Boolean apply(IMethod object) {
|
||||
if (object instanceof AstMethod) {
|
||||
return scripts.contains(getScriptName((AstMethod)object));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return b.buildFlowGraph();
|
||||
}
|
||||
public Boolean apply(IMethod object) {
|
||||
if (object instanceof AstMethod) {
|
||||
return scripts.contains(getScriptName((AstMethod)object));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AnalysisOptions options = getDefaultOptions(roots);
|
||||
if (builderType.equals(BuilderType.OPTIMISTIC)) {
|
||||
((JSAnalysisOptions)options).setHandleCallApply(false);
|
||||
}
|
||||
|
||||
FieldBasedCallGraphBuilder builder =
|
||||
builderType.equals(BuilderType.PESSIMISTIC)?
|
||||
new PessimisticCallGraphBuilder(getClassHierarchy(), options, makeDefaultCache()) {
|
||||
@Override
|
||||
protected FlowGraph flowGraphFactory() {
|
||||
FlowGraphBuilder b = new FilteredFlowGraphBuilder(cha, cache, filter);
|
||||
return b.buildFlowGraph();
|
||||
}
|
||||
@Override
|
||||
protected boolean filterFunction(IMethod function) {
|
||||
return super.filterFunction(function) && filter.apply(function);
|
||||
}
|
||||
}
|
||||
: new OptimisticCallgraphBuilder(getClassHierarchy(), options, makeDefaultCache()) {
|
||||
@Override
|
||||
protected FlowGraph flowGraphFactory() {
|
||||
FlowGraphBuilder b = new FilteredFlowGraphBuilder(cha, cache, filter);
|
||||
return b.buildFlowGraph();
|
||||
}
|
||||
};
|
||||
|
||||
return builder.buildCallGraph(roots, new NullProgressMonitor());
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ public class EclipseWebAnalysisEngine extends EclipseJavaScriptAnalysisEngine {
|
|||
|
||||
private final Set<Pair<String, Plugin>> models = HashSetFactory.make();
|
||||
|
||||
public EclipseWebAnalysisEngine(IJavaScriptProject project, Collection<Pair<String, Plugin>> models) throws IOException, CoreException {
|
||||
super(project);
|
||||
public EclipseWebAnalysisEngine(IJavaScriptProject project, Collection<Pair<String, Plugin>> models, BuilderType builderType) throws IOException, CoreException {
|
||||
super(project, builderType);
|
||||
// core DOM model
|
||||
this.models.add(Pair.make("preamble.js", (Plugin)JavaScriptPlugin.getDefault()));
|
||||
this.models.addAll(models);
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||
<listEntry value="/com.ibm.wala.ide.tests/src/com/ibm/wala/examples/drivers/SWTCallGraph.java"/>
|
||||
</listAttribute>
|
||||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||
<listEntry value="1"/>
|
||||
</listAttribute>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.ibm.wala.examples.drivers.SWTCallGraph"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-appJar /Users/dolby/Analysis/examples/ocaml-examples-3.12/pascal/ipascal.jar"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.ide.tests"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx2048M"/>
|
||||
</launchConfiguration>
|
|
@ -102,7 +102,7 @@ public class SWTCallGraph {
|
|||
if (jar.getManifest() != null) {
|
||||
String mainClass = jar.getManifest().getMainAttributes().getValue("Main-Class");
|
||||
if (mainClass != null) {
|
||||
entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "L" + mainClass);
|
||||
entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "L" + mainClass.replace('.', '/'));
|
||||
}
|
||||
}
|
||||
if (entrypoints == null) {
|
||||
|
|
|
@ -28,6 +28,8 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
|||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.eclipse.ui.dialogs.IOverwriteQuery;
|
||||
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
|
||||
import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
|
||||
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
|
||||
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
@ -57,9 +59,8 @@ public class EclipseTestUtil {
|
|||
|
||||
public static void importZippedProject(Plugin plugin, String projectName, String zipFileName, IProgressMonitor monitor) {
|
||||
ZipFile zipFile = getZipFile(plugin, zipFileName);
|
||||
ZipFileStructureProvider zp = new ZipFileStructureProvider(zipFile);
|
||||
createOpenProject(projectName);
|
||||
importZipfile(projectName, zipFile, zp, monitor);
|
||||
importZipfile(projectName, zipFile, monitor);
|
||||
}
|
||||
|
||||
public static void createOpenProject(String projectName) {
|
||||
|
@ -83,17 +84,34 @@ public class EclipseTestUtil {
|
|||
}
|
||||
}
|
||||
|
||||
protected static void importZipfile(String projectName, ZipFile sourceZip, ZipFileStructureProvider provider, IProgressMonitor monitor) {
|
||||
public static void importProjectFromFilesystem(String projectName, File root, IProgressMonitor monitor) {
|
||||
FileSystemStructureProvider fs = FileSystemStructureProvider.INSTANCE;
|
||||
importProject(fs, monitor, projectName, root);
|
||||
}
|
||||
|
||||
public static void importZipfile(String projectName, ZipFile zipFile, IProgressMonitor monitor) {
|
||||
ZipFileStructureProvider provider = new ZipFileStructureProvider(zipFile);
|
||||
|
||||
importProject(provider, monitor, projectName, provider.getRoot());
|
||||
|
||||
try {
|
||||
zipFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static <T> void importProject(IImportStructureProvider provider, IProgressMonitor monitor, String projectName, T root) {
|
||||
IPath containerPath = getWorkspacePath().append(projectName).addTrailingSeparator();
|
||||
|
||||
ImportOperation importOp = new ImportOperation(containerPath, provider.getRoot(), provider, new IOverwriteQuery() {
|
||||
ImportOperation importOp = new ImportOperation(containerPath, root, provider, new IOverwriteQuery() {
|
||||
@Override
|
||||
public String queryOverwrite(String pathString) {
|
||||
return IOverwriteQuery.ALL;
|
||||
}
|
||||
});
|
||||
|
||||
importOp.setCreateContainerStructure(true);
|
||||
importOp.setCreateContainerStructure(false);
|
||||
importOp.setOverwriteResources(true);
|
||||
try {
|
||||
importOp.run(monitor);
|
||||
|
@ -102,12 +120,6 @@ public class EclipseTestUtil {
|
|||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
sourceZip.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static File getTestDataFile(Plugin plugin, String filename) {
|
||||
|
|
|
@ -67,7 +67,7 @@ public final class ClassReader implements ClassConstants {
|
|||
if (majorVersion < 45 || majorVersion > 51) {
|
||||
throw new InvalidClassFileException(offset, "unknown class file version: " + majorVersion + "." + minorVersion);
|
||||
}
|
||||
|
||||
|
||||
cpParser = new ConstantPoolParser(bytes, offset, constantPoolCount);
|
||||
offset += cpParser.getRawSize();
|
||||
|
||||
|
|
Loading…
Reference in New Issue