private static String getSourceLevelName(IR ir, int index, int vn) { String indexName = null; String[] sourceNamesForValues = ir.getLocalNames(index, vn); if(sourceNamesForValues == null) return null; for(String candidateName : sourceNamesForValues) { if(indexName != null) { indexName = null; break; } if(!candidateName.contains(" ")) // ignore internal names indexName = candidateName; } return indexName; }
private static String getSourceLevelName(IR ir, int index, int vn) { String indexName = null; String[] sourceNamesForValues = ir.getLocalNames(index, vn); if(sourceNamesForValues == null) return null; for(String candidateName : sourceNamesForValues) { if(indexName != null) { indexName = null; break; } if(!candidateName.contains(" ")) // ignore internal names indexName = candidateName; } return indexName; }
private void addNames(int j, Map<Integer, Set<String>> valNames, int valNum) { if (getLocalNames(j, valNum) != null && getLocalNames(j, valNum).length > 0) { if (! valNames.containsKey(valNum)) { valNames.put(valNum, HashSetFactory.<String>make()); } for(String s : getLocalNames(j, valNum)) { valNames.get(valNum).add(s); } } }
private void addNames(int j, Map<Integer, Set<String>> valNames, int valNum) { if (getLocalNames(j, valNum) != null && getLocalNames(j, valNum).length > 0) { if (! valNames.containsKey(valNum)) { valNames.put(valNum, HashSetFactory.<String>make()); } for(String s : getLocalNames(j, valNum)) { valNames.get(valNum).add(s); } } }
public static int getArgumentsArrayVn(IR ir) { for(int i = 0; i < ir.getInstructions().length; i++) { SSAInstruction inst = ir.getInstructions()[i]; if (inst != null) { for(int v = 0; v < inst.getNumberOfUses(); v++) { String[] names = ir.getLocalNames(i, inst.getUse(v)); if (names != null && names.length == 1 && "arguments".equals(names[0])) { return inst.getUse(v); } } } } return -1; }
public static int getArgumentsArrayVn(IR ir) { for(int i = 0; i < ir.getInstructions().length; i++) { SSAInstruction inst = ir.getInstructions()[i]; if (inst != null) { for(int v = 0; v < inst.getNumberOfUses(); v++) { String[] names = ir.getLocalNames(i, inst.getUse(v)); if (names != null && names.length == 1 && "arguments".equals(names[0])) { return inst.getUse(v); } } } } return -1; }
@Override public String toString() { StringBuilder name = new StringBuilder(); if (getInstruction().hasDef()) { String[] names = getNode().getIR().getLocalNames(getInstructionIndex(), getInstruction().getDef()); if (names != null && names.length > 0) { name = new StringBuilder("[").append(names[0]); for (int i = 1; i < names.length; i++) { name.append(", ").append(names[i]); } name.append("]: "); } } return "NORMAL " + getNode().getMethod().getName() + ':' + name + getInstruction().toString() + ' ' + getNode(); }
@Override public String toString() { StringBuilder name = new StringBuilder(); if (getInstruction().hasDef()) { String[] names = getNode().getIR().getLocalNames(getInstructionIndex(), getInstruction().getDef()); if (names != null && names.length > 0) { name = new StringBuilder("[").append(names[0]); for (int i = 1; i < names.length; i++) { name.append(", ").append(names[i]); } name.append("]: "); } } return "NORMAL " + getNode().getMethod().getName() + ':' + name + getInstruction().toString() + ' ' + getNode(); }
private void handleLexicalDef(int def) { assert def != -1; if(instructionIndex != -1 && exposedVars.contains(def)) { VarVertex v = factory.makeVarVertex(func, def); for(String localName : ir.getLocalNames(instructionIndex, def)) flowgraph.addEdge(v, factory.makeLexicalAccessVertex(lexicalInfo.getScopingName(), localName)); } }
private void handleLexicalDef(int def) { assert def != -1; if(instructionIndex != -1 && exposedVars.contains(def)) { VarVertex v = factory.makeVarVertex(func, def); for(String localName : ir.getLocalNames(instructionIndex, def)) flowgraph.addEdge(v, factory.makeLexicalAccessVertex(lexicalInfo.getScopingName(), localName)); } }
protected void verifyNameAssertions(CallGraph CG, Object[][] assertionData) { for (Object[] element : assertionData) { Iterator<CGNode> NS = getNodes(CG, (String) element[0]).iterator(); while (NS.hasNext()) { CGNode N = NS.next(); IR ir = N.getIR(); Name[] names = (Name[]) element[1]; for (Name name : names) { System.err.println("looking for " + name.name + ", " + name.vn + " in " + N); String[] localNames = ir.getLocalNames(name.instructionIndex, name.vn); boolean found = false; for (String localName : localNames) { if (localName.equals(name.name)) { found = true; } } Assert.assertTrue("no name " + name.name + " for " + N + "\n" + ir, found); } } } }
boolean check(IMethod m, IR ir) { System.err.println(("check for " + variableName + " defined at " + definingLineNumber)); SSAInstruction[] insts = ir.getInstructions(); for (int i = 0; i < insts.length; i++) { if (insts[i] != null) { int ln = m.getLineNumber(i); if (ln == definingLineNumber) { System.err.println((" found " + insts[i] + " at " + ln)); for (int j = 0; j < insts[i].getNumberOfDefs(); j++) { int def = insts[i].getDef(j); System.err.println((" looking at def " + j + ": " + def)); String[] names = ir.getLocalNames(i, def); if (names != null) { for (String name : names) { System.err.println((" looking at name " + name)); if (name.equals(variableName)) { return true; } } } } } } } return false; } }
@Test public void testLocalNamesWithoutPiNodes() { SSAPiNodePolicy save = options.getSSAOptions().getPiNodePolicy(); options.getSSAOptions().setPiNodePolicy(null); MethodReference mref = scope.findMethod(AnalysisScope.APPLICATION, "LcornerCases/Locals", Atom.findOrCreateUnicodeAtom("foo"), new ImmutableByteArray(UTF8Convert.toUTF8("([Ljava/lang/String;)V"))); Assert.assertNotNull("method not found", mref); IMethod imethod = cha.resolveMethod(mref); Assert.assertNotNull("imethod not found", imethod); IAnalysisCacheView cache = new AnalysisCacheImpl(options.getSSAOptions()); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); options.getSSAOptions().setPiNodePolicy(save); // v1 should be the parameter "a" at pc 0 String[] names = ir.getLocalNames(0, 1); Assert.assertTrue("failed local name resolution for v1@0", names != null); Assert.assertTrue("incorrect number of local names for v1@0: " + names.length, names.length == 1); Assert.assertTrue("incorrect local name resolution for v1@0: " + names[0], names[0].equals("a")); // v2 is a compiler-induced temporary Assert.assertTrue("didn't expect name for v2 at pc 2", ir.getLocalNames(2, 2) == null); // at pc 5, v1 should represent the locals "a" and "b" names = ir.getLocalNames(5, 1); Assert.assertTrue("failed local name resolution for v1@5", names != null); Assert.assertTrue("incorrect number of local names for v1@5: " + names.length, names.length == 2); Assert.assertTrue("incorrect local name resolution #0 for v1@5: " + names[0], names[0].equals("a")); Assert.assertTrue("incorrect local name resolution #1 for v1@5: " + names[1], names[1].equals("b")); }
@Test public void testLocalNamesWithPiNodes() { SSAPiNodePolicy save = options.getSSAOptions().getPiNodePolicy(); options.getSSAOptions().setPiNodePolicy(SSAOptions.getAllBuiltInPiNodes()); MethodReference mref = scope.findMethod(AnalysisScope.APPLICATION, "LcornerCases/Locals", Atom.findOrCreateUnicodeAtom("foo"), new ImmutableByteArray(UTF8Convert.toUTF8("([Ljava/lang/String;)V"))); Assert.assertNotNull("method not found", mref); IMethod imethod = cha.resolveMethod(mref); Assert.assertNotNull("imethod not found", imethod); IAnalysisCacheView cache = new AnalysisCacheImpl(options.getSSAOptions()); IR ir = cache.getIRFactory().makeIR(imethod, Everywhere.EVERYWHERE, options.getSSAOptions()); options.getSSAOptions().setPiNodePolicy(save); // v1 should be the parameter "a" at pc 0 String[] names = ir.getLocalNames(0, 1); Assert.assertTrue("failed local name resolution for v1@0", names != null); Assert.assertTrue("incorrect number of local names for v1@0: " + names.length, names.length == 1); Assert.assertTrue("incorrect local name resolution for v1@0: " + names[0], names[0].equals("a")); // v2 is a compiler-induced temporary Assert.assertTrue("didn't expect name for v2 at pc 2", ir.getLocalNames(2, 2) == null); // at pc 5, v1 should represent the locals "a" and "b" names = ir.getLocalNames(5, 1); Assert.assertTrue("failed local name resolution for v1@5", names != null); Assert.assertTrue("incorrect number of local names for v1@5: " + names.length, names.length == 2); Assert.assertTrue("incorrect local name resolution #0 for v1@5: " + names[0], names[0].equals("a")); Assert.assertTrue("incorrect local name resolution #1 for v1@5: " + names[1], names[1].equals("b")); } }
Assert.assertEquals("Expected an array store to 'y'.", node.getIR().getLocalNames(i, as.getArrayRef())[0], "y");
SSAInstruction instr = ir.getInstructions()[offsetIndex]; if (instr != null) { String[] localNames = ir.getLocalNames(offsetIndex, instr.getDef()); if (localNames != null && localNames.length > 0 && localNames[0] == null) { System.err.println(ir);