/** * Extracts and returns the source position information out of an instruction list. * * @param insns {@code non-null;} instructions to convert * @param howMuch how much information should be included; one of the static constants defined by * this class * @return {@code non-null;} the positions list */ public static PositionList make(DalvInsnList insns, int howMuch) { switch (howMuch) { case NONE: { return EMPTY; } case LINES: case IMPORTANT: { // Valid. break; } default: { throw new IllegalArgumentException("bogus howMuch"); } } SourcePosition noInfo = SourcePosition.NO_INFO; SourcePosition cur = noInfo; int sz = insns.size(); PositionList.Entry[] arr = new PositionList.Entry[sz]; boolean lastWasTarget = false; int at = 0; for (int i = 0; i < sz; i++) { DalvInsn insn = insns.get(i); if (insn instanceof CodeAddress) { lastWasTarget = true; ; continue; } SourcePosition pos = insn.getPosition(); if (pos.equals(noInfo) || pos.sameLine(cur)) { continue; } if ((howMuch == IMPORTANT) && !lastWasTarget) { continue; } cur = pos; arr[at] = new PositionList.Entry(insn.getAddress(), pos); at++; lastWasTarget = false; } PositionList result = new PositionList(at); for (int i = 0; i < at; i++) { result.set(i, arr[i]); } result.setImmutable(); return result; }