From 00f9822770be11d0d11d2d40c3b73c4e45151067 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 7 May 2008 18:57:45 -0700 Subject: [PATCH] fix selection for "a++" and "++a" --- Svelte/src/edu/berkeley/cs/bodik/svelte/CGNodeUtils.java | 7 +++++-- .../edu/berkeley/cs/bodik/svelte/slicers/JavaLanguage.java | 12 ++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Svelte/src/edu/berkeley/cs/bodik/svelte/CGNodeUtils.java b/Svelte/src/edu/berkeley/cs/bodik/svelte/CGNodeUtils.java index 42a2c15..98c13c4 100644 --- a/Svelte/src/edu/berkeley/cs/bodik/svelte/CGNodeUtils.java +++ b/Svelte/src/edu/berkeley/cs/bodik/svelte/CGNodeUtils.java @@ -59,7 +59,6 @@ import com.ibm.wala.ipa.slicer.PhiStatement; import com.ibm.wala.ipa.slicer.Statement; import com.ibm.wala.shrikeCT.InvalidClassFileException; import com.ibm.wala.ssa.IR; -import com.ibm.wala.ssa.SSAArrayStoreInstruction; import com.ibm.wala.ssa.SSAInstruction; import com.ibm.wala.ssa.SSAInvokeInstruction; import com.ibm.wala.ssa.SSAPhiInstruction; @@ -363,10 +362,14 @@ public class CGNodeUtils { /** * Could return a NormalStatement that has a null instruction. In that case, the * instruction has probably been optimized away. + * + * Tries to get a non-null instruction, if possible. + * * @param cgn * @param offsetStart * @param offsetEnd * @param parentInstructionClass + * @param klass * @return */ public static Collection getInnermostStatementFromOffset(CGNode cgn, @@ -378,7 +381,7 @@ public class CGNodeUtils { if (si != null) { if (si.offsetStart <= offsetStart && si.offsetEnd >= offsetEnd ) { if (si.offsetEnd - si.offsetStart < minCoveringLength - || minCoveringLength == -1) { + || minCoveringLength == -1 || cgn.getIR().getInstructions()[minCoveringInst] == null) { minCoveringLength = si.offsetEnd - si.offsetStart; minCoveringInst = i; } diff --git a/Svelte/src/edu/berkeley/cs/bodik/svelte/slicers/JavaLanguage.java b/Svelte/src/edu/berkeley/cs/bodik/svelte/slicers/JavaLanguage.java index 5dfff6f..065f5c0 100644 --- a/Svelte/src/edu/berkeley/cs/bodik/svelte/slicers/JavaLanguage.java +++ b/Svelte/src/edu/berkeley/cs/bodik/svelte/slicers/JavaLanguage.java @@ -54,7 +54,6 @@ import com.ibm.wala.ipa.slicer.Statement; import com.ibm.wala.ssa.SSAAbstractInvokeInstruction; import com.ibm.wala.ssa.SSAArrayStoreInstruction; import com.ibm.wala.ssa.SSAInstruction; -import com.ibm.wala.ssa.SSAInvokeInstruction; import com.ibm.wala.types.TypeReference; import edu.berkeley.cs.bodik.svelte.CGNodeUtils; @@ -359,10 +358,8 @@ public class JavaLanguage implements ILanguage { if (parent.getNodeType() == ASTNode.ARRAY_INITIALIZER) { ArrayInitializer ai = (ArrayInitializer) covering.getParent(); substatementIndex = 0; - boolean found = false; for ( Object o: ai.expressions() ) { if ( o.equals(covering) ) { - found = true; break; } substatementIndex++; @@ -405,19 +402,18 @@ public class JavaLanguage implements ILanguage { // if varargs, args are boxed first, so we have to deal with that. IMethodBinding binding = mi.resolveMethodBinding().getMethodDeclaration(); if ( binding.isVarargs() && mi.getExpression() != covering ) { - List arguments = mi.arguments(); - int nActuals = arguments.size(); + int nActuals = mi.arguments().size(); int nFormals = binding.getParameterTypes().length; // if the nActuals != nFormals, it's definitely a varargs invocation. If // nActuals == nFormals, however, we have to check the type of the last argument. // if the last argument is an array type of the correct type, it will be passed in and not boxed. ITypeBinding lastArgType = null; - if ( nActuals > 0 && arguments.get(nActuals-1) instanceof Expression ) // if nActuals=0 then it's definitely varargs and nFormals != 0 - lastArgType = ((Expression)arguments.get(nActuals-1)).resolveTypeBinding(); + if ( nActuals > 0 && mi.arguments().get(nActuals-1) instanceof Expression ) // if nActuals=0 then it's definitely varargs and nFormals != 0 + lastArgType = ((Expression)mi.arguments().get(nActuals-1)).resolveTypeBinding(); if ( nActuals != nFormals || lastArgType.isSubTypeCompatible(binding.getParameterTypes()[nFormals-1]) ) { - int argIndex = arguments.indexOf(covering); + int argIndex = mi.arguments().indexOf(covering); if ( argIndex >= (nFormals-1) ) { int indexWithinVarargsArray = argIndex - (nFormals-1); -- 2.11.4.GIT