mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Bug 484894: Update generification of DisassemblyDocument
This fix follows on fromaf49d7701a
and redoes the generification changes brought on by the AbstractDocument changes for Neon M4. The earlier fix (af49d77
) made a copy of the list to work around the casting problem, however many of the methods that work on the positions expected access to the real list, not a copy. For example, consider addModelPositionFirst(), it gets the CATEGORY_MODEL list and then adds to it. If getAddressRangePositions returned a copy, then the wrong list would be updated. Change-Id: I36ca589ba748b66541c632182aceaf0b0b64aea4 Signed-off-by: Jonah Graham <jonah@kichwacoders.com>
This commit is contained in:
parent
afa0449e30
commit
59d0f15afe
1 changed files with 45 additions and 52 deletions
|
@ -178,7 +178,7 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
return (int)(fMeanSizeOfInstructions+.9);
|
return (int)(fMeanSizeOfInstructions+.9);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<AddressRangePosition> getModelPositionIterator(BigInteger address) {
|
public Iterator<Position> getModelPositionIterator(BigInteger address) {
|
||||||
try {
|
try {
|
||||||
return getPositionIterator(CATEGORY_MODEL, address);
|
return getPositionIterator(CATEGORY_MODEL, address);
|
||||||
} catch (BadPositionCategoryException e) {
|
} catch (BadPositionCategoryException e) {
|
||||||
|
@ -196,39 +196,21 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
return positions.listIterator(idx);
|
return positions.listIterator(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<AddressRangePosition> getPositionIterator(String category, BigInteger address) throws BadPositionCategoryException {
|
public Iterator<Position> getPositionIterator(String category, BigInteger address) throws BadPositionCategoryException {
|
||||||
List<AddressRangePosition> positions = getAddressRangePositions(category);
|
List<Position> positions = getDocumentManagedPositions().get(category);
|
||||||
|
if (positions == null) {
|
||||||
|
throw new BadPositionCategoryException();
|
||||||
|
}
|
||||||
int idx = computeIndexInPositionListFirst(positions, address);
|
int idx = computeIndexInPositionListFirst(positions, address);
|
||||||
return positions.listIterator(idx);
|
return positions.listIterator(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<AddressRangePosition> getAddressRangePositions(String category) throws BadPositionCategoryException {
|
public int computeIndexInCategory(String category, BigInteger address) throws BadPositionCategoryException {
|
||||||
List<Position> tmpPositions = getDocumentManagedPositions().get(category);
|
List<Position> c = getDocumentManagedPositions().get(category);
|
||||||
if (tmpPositions == null) {
|
if (c == null) {
|
||||||
throw new BadPositionCategoryException();
|
throw new BadPositionCategoryException();
|
||||||
}
|
}
|
||||||
List<AddressRangePosition> positions = new ArrayList<>();
|
return computeIndexInPositionListFirst(c, address);
|
||||||
for(Position position: tmpPositions) {
|
|
||||||
positions.add((AddressRangePosition) position);
|
|
||||||
}
|
|
||||||
return positions;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<AddressRangePosition> getAddressRangePositionsRaw(String category) {
|
|
||||||
List<Position> tmpPositions = getDocumentManagedPositions().get(category);
|
|
||||||
if (tmpPositions == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
List<AddressRangePosition> positions = new ArrayList<>();
|
|
||||||
for(Position position: tmpPositions) {
|
|
||||||
positions.add((AddressRangePosition) position);
|
|
||||||
}
|
|
||||||
return positions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int computeIndexInCategory(String category, BigInteger address) throws BadPositionCategoryException {
|
|
||||||
List<AddressRangePosition> positions = getAddressRangePositions(category);
|
|
||||||
return computeIndexInPositionListFirst(positions, address);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,7 +223,7 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
* @return the computed index
|
* @return the computed index
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected int computeIndexInPositionListFirst(List<AddressRangePosition> positions, BigInteger address) {
|
protected int computeIndexInPositionListFirst(List<Position> positions, BigInteger address) {
|
||||||
int size = positions.size();
|
int size = positions.size();
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -251,7 +233,7 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
int mid = 0;
|
int mid = 0;
|
||||||
while (low < high) {
|
while (low < high) {
|
||||||
mid = (low + high) >>> 1;
|
mid = (low + high) >>> 1;
|
||||||
AddressRangePosition range = positions.get(mid);
|
AddressRangePosition range = (AddressRangePosition)positions.get(mid);
|
||||||
int compareSign = address.compareTo(range.fAddressOffset);
|
int compareSign = address.compareTo(range.fAddressOffset);
|
||||||
if (compareSign < 0) {
|
if (compareSign < 0) {
|
||||||
high = mid;
|
high = mid;
|
||||||
|
@ -265,14 +247,14 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = mid;
|
int idx = mid;
|
||||||
AddressRangePosition p = positions.get(idx);
|
AddressRangePosition p = (AddressRangePosition)positions.get(idx);
|
||||||
if (address.compareTo(p.fAddressOffset) == 0) {
|
if (address.compareTo(p.fAddressOffset) == 0) {
|
||||||
do {
|
do {
|
||||||
--idx;
|
--idx;
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
p = positions.get(idx);
|
p = (AddressRangePosition)positions.get(idx);
|
||||||
} while (address.compareTo(p.fAddressOffset) == 0);
|
} while (address.compareTo(p.fAddressOffset) == 0);
|
||||||
++idx;
|
++idx;
|
||||||
} else if (address.compareTo(p.fAddressOffset.add(p.fAddressLength)) >= 0) {
|
} else if (address.compareTo(p.fAddressOffset.add(p.fAddressLength)) >= 0) {
|
||||||
|
@ -291,7 +273,7 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
* @return the computed index
|
* @return the computed index
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected int computeIndexInPositionListLast(List<AddressRangePosition> positions, BigInteger address) {
|
protected int computeIndexInPositionListLast(List<Position> positions, BigInteger address) {
|
||||||
int size = positions.size();
|
int size = positions.size();
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -301,7 +283,7 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
int mid = 0;
|
int mid = 0;
|
||||||
while (low < high) {
|
while (low < high) {
|
||||||
mid = (low + high) >>> 1;
|
mid = (low + high) >>> 1;
|
||||||
AddressRangePosition range = positions.get(mid);
|
AddressRangePosition range = (AddressRangePosition) positions.get(mid);
|
||||||
if (address.compareTo(range.fAddressOffset) < 0) {
|
if (address.compareTo(range.fAddressOffset) < 0) {
|
||||||
high = mid;
|
high = mid;
|
||||||
} else if (address.compareTo(range.fAddressOffset) == 0) {
|
} else if (address.compareTo(range.fAddressOffset) == 0) {
|
||||||
|
@ -314,7 +296,7 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = mid;
|
int idx = mid;
|
||||||
AddressRangePosition p = positions.get(idx);
|
AddressRangePosition p = (AddressRangePosition) positions.get(idx);
|
||||||
if (address.compareTo(p.fAddressOffset) > 0) {
|
if (address.compareTo(p.fAddressOffset) > 0) {
|
||||||
++idx;
|
++idx;
|
||||||
} else if (address.compareTo(p.fAddressOffset) == 0 && p.fAddressLength.compareTo(BigInteger.ZERO) == 0) {
|
} else if (address.compareTo(p.fAddressOffset) == 0 && p.fAddressLength.compareTo(BigInteger.ZERO) == 0) {
|
||||||
|
@ -323,7 +305,7 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
if (idx == size) {
|
if (idx == size) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
p = positions.get(idx);
|
p = (AddressRangePosition) positions.get(idx);
|
||||||
} while (address.compareTo(p.fAddressOffset) == 0 && p.fAddressLength.compareTo(BigInteger.ZERO) == 0);
|
} while (address.compareTo(p.fAddressOffset) == 0 && p.fAddressLength.compareTo(BigInteger.ZERO) == 0);
|
||||||
// --idx;
|
// --idx;
|
||||||
}
|
}
|
||||||
|
@ -340,7 +322,10 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
* @return the computed index
|
* @return the computed index
|
||||||
*
|
*
|
||||||
* @see IDocument#computeIndexInCategory(String, int)
|
* @see IDocument#computeIndexInCategory(String, int)
|
||||||
|
* @deprecated Use {@link #computeIndexInPositionListLast(List, BigInteger)}
|
||||||
|
* as it is for managing lists of AddressRangePositions
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
protected int computeIndexInPositionListLast(List<Position> positions, int offset) {
|
protected int computeIndexInPositionListLast(List<Position> positions, int offset) {
|
||||||
if (positions.size() == 0)
|
if (positions.size() == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -412,13 +397,13 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddressRangePosition getPositionOfAddress(String category, BigInteger address) {
|
public AddressRangePosition getPositionOfAddress(String category, BigInteger address) {
|
||||||
List<AddressRangePosition> positions = getAddressRangePositionsRaw(category);
|
List<Position> positions = getDocumentManagedPositions().get(category);
|
||||||
if (positions == null) {
|
if (positions == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int index = computeIndexInPositionListFirst(positions, address);
|
int index = computeIndexInPositionListFirst(positions, address);
|
||||||
if (index < positions.size()) {
|
if (index < positions.size()) {
|
||||||
AddressRangePosition p = positions.get(index);
|
AddressRangePosition p = (AddressRangePosition) positions.get(index);
|
||||||
if (address.compareTo(p.fAddressOffset) == 0 || p.containsAddress(address)) {
|
if (address.compareTo(p.fAddressOffset) == 0 || p.containsAddress(address)) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -432,7 +417,7 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public AddressRangePosition getPositionInAddressRange(String category, AddressRangePosition range) {
|
public AddressRangePosition getPositionInAddressRange(String category, AddressRangePosition range) {
|
||||||
List<AddressRangePosition> positions = getAddressRangePositionsRaw(category);
|
List<Position> positions = getDocumentManagedPositions().get(category);
|
||||||
if (positions == null) {
|
if (positions == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -440,7 +425,7 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
int index = computeIndexInPositionListFirst(positions, range.fAddressOffset);
|
int index = computeIndexInPositionListFirst(positions, range.fAddressOffset);
|
||||||
if (index < positions.size()) {
|
if (index < positions.size()) {
|
||||||
do {
|
do {
|
||||||
AddressRangePosition p = positions.get(index);
|
AddressRangePosition p = (AddressRangePosition) positions.get(index);
|
||||||
if (p.fAddressOffset.compareTo(endAddress) >= 0) {
|
if (p.fAddressOffset.compareTo(endAddress) >= 0) {
|
||||||
--index;
|
--index;
|
||||||
} else {
|
} else {
|
||||||
|
@ -692,11 +677,11 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
* @param pos
|
* @param pos
|
||||||
*/
|
*/
|
||||||
public void addModelPositionFirst(AddressRangePosition pos) {
|
public void addModelPositionFirst(AddressRangePosition pos) {
|
||||||
List<AddressRangePosition> list = getAddressRangePositionsRaw(CATEGORY_MODEL);
|
List<Position> list = getDocumentManagedPositions().get(CATEGORY_MODEL);
|
||||||
int idx;
|
int idx;
|
||||||
idx = computeIndexInPositionListFirst(list, pos.fAddressOffset.add(pos.fAddressLength));
|
idx = computeIndexInPositionListFirst(list, pos.fAddressOffset.add(pos.fAddressLength));
|
||||||
if (idx < list.size()) {
|
if (idx < list.size()) {
|
||||||
AddressRangePosition nextPos = list.get(idx);
|
AddressRangePosition nextPos = (AddressRangePosition) list.get(idx);
|
||||||
assert nextPos.fAddressOffset.compareTo(pos.fAddressOffset.add(pos.fAddressLength)) == 0;
|
assert nextPos.fAddressOffset.compareTo(pos.fAddressOffset.add(pos.fAddressLength)) == 0;
|
||||||
}
|
}
|
||||||
list.add(idx, pos);
|
list.add(idx, pos);
|
||||||
|
@ -734,7 +719,10 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
* @throws BadPositionCategoryException
|
* @throws BadPositionCategoryException
|
||||||
*/
|
*/
|
||||||
public void addPositionLast(String category, AddressRangePosition pos) throws BadPositionCategoryException {
|
public void addPositionLast(String category, AddressRangePosition pos) throws BadPositionCategoryException {
|
||||||
List<AddressRangePosition> list = getAddressRangePositions(category);
|
List<Position> list = getDocumentManagedPositions().get(category);
|
||||||
|
if (list == null) {
|
||||||
|
throw new BadPositionCategoryException();
|
||||||
|
}
|
||||||
if (DEBUG) System.out.println("Adding position to category <" + category + "> : " + pos); //$NON-NLS-1$ //$NON-NLS-2$
|
if (DEBUG) System.out.println("Adding position to category <" + category + "> : " + pos); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
list.add(computeIndexInPositionListLast(list, pos.fAddressOffset), pos);
|
list.add(computeIndexInPositionListLast(list, pos.fAddressOffset), pos);
|
||||||
}
|
}
|
||||||
|
@ -848,6 +836,11 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #addPositionLast(String, AddressRangePosition)}
|
||||||
|
* instead as DissemblyDocument's lists are AddressRangePositions
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public void addPositionLast(String category, Position position) throws BadLocationException,
|
public void addPositionLast(String category, Position position) throws BadLocationException,
|
||||||
BadPositionCategoryException {
|
BadPositionCategoryException {
|
||||||
|
|
||||||
|
@ -892,9 +885,9 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
int delta = (text != null ? text.length() : 0) - replaceLength;
|
int delta = (text != null ? text.length() : 0) - replaceLength;
|
||||||
if (delta != 0) {
|
if (delta != 0) {
|
||||||
BigInteger address = insertPos.fAddressOffset;
|
BigInteger address = insertPos.fAddressOffset;
|
||||||
Iterator<AddressRangePosition> it = getModelPositionIterator(address);
|
Iterator<Position> it = getModelPositionIterator(address);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
AddressRangePosition pos = it.next();
|
AddressRangePosition pos = (AddressRangePosition) it.next();
|
||||||
assert pos.fAddressOffset.compareTo(address) >= 0;
|
assert pos.fAddressOffset.compareTo(address) >= 0;
|
||||||
if (pos.fAddressOffset.compareTo(address) > 0) {
|
if (pos.fAddressOffset.compareTo(address) > 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -907,7 +900,7 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
AddressRangePosition pos = it.next();
|
AddressRangePosition pos = (AddressRangePosition) it.next();
|
||||||
pos.offset += delta;
|
pos.offset += delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -944,10 +937,10 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
int replaceLength = 0;
|
int replaceLength = 0;
|
||||||
if (length.compareTo(BigInteger.ONE) > 0 && !pos.containsAddress(address.add(length.subtract(BigInteger.ONE)))) {
|
if (length.compareTo(BigInteger.ONE) > 0 && !pos.containsAddress(address.add(length.subtract(BigInteger.ONE)))) {
|
||||||
// merge with successor positions
|
// merge with successor positions
|
||||||
Iterator<AddressRangePosition> it = getModelPositionIterator(pos.fAddressOffset.add(pos.fAddressLength));
|
Iterator<Position> it = getModelPositionIterator(pos.fAddressOffset.add(pos.fAddressLength));
|
||||||
assert it.hasNext();
|
assert it.hasNext();
|
||||||
do {
|
do {
|
||||||
AddressRangePosition overlap = it.next();
|
AddressRangePosition overlap = (AddressRangePosition) it.next();
|
||||||
BigInteger posEndAddress= pos.fAddressOffset.add(pos.fAddressLength);
|
BigInteger posEndAddress= pos.fAddressOffset.add(pos.fAddressLength);
|
||||||
assert pos.offset <= overlap.offset && overlap.fAddressOffset.compareTo(posEndAddress) == 0;
|
assert pos.offset <= overlap.offset && overlap.fAddressOffset.compareTo(posEndAddress) == 0;
|
||||||
if (overlap instanceof LabelPosition || overlap instanceof SourcePosition) {
|
if (overlap instanceof LabelPosition || overlap instanceof SourcePosition) {
|
||||||
|
@ -1312,9 +1305,9 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
int replaceLen = replacement != null ? replacement.length() : 0;
|
int replaceLen = replacement != null ? replacement.length() : 0;
|
||||||
AddressRangePosition lastPos = null;
|
AddressRangePosition lastPos = null;
|
||||||
ArrayList<AddressRangePosition> toRemove = new ArrayList<AddressRangePosition>();
|
ArrayList<AddressRangePosition> toRemove = new ArrayList<AddressRangePosition>();
|
||||||
Iterator<AddressRangePosition> it = getModelPositionIterator(startAddress);
|
Iterator<Position> it = getModelPositionIterator(startAddress);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
AddressRangePosition pos = it.next();
|
AddressRangePosition pos = (AddressRangePosition) it.next();
|
||||||
BigInteger posEndAddress = pos.fAddressOffset.add(pos.fAddressLength);
|
BigInteger posEndAddress = pos.fAddressOffset.add(pos.fAddressLength);
|
||||||
if (pos instanceof LabelPosition) {
|
if (pos instanceof LabelPosition) {
|
||||||
if (!invalidate && pos.length > 0 && posEndAddress.compareTo(endAddress) > 0) {
|
if (!invalidate && pos.length > 0 && posEndAddress.compareTo(endAddress) > 0) {
|
||||||
|
@ -1455,9 +1448,9 @@ public class DisassemblyDocument extends REDDocument implements IDisassemblyDocu
|
||||||
BigInteger addressLength = BigInteger.ZERO;
|
BigInteger addressLength = BigInteger.ZERO;
|
||||||
ArrayList<AddressRangePosition> toRemove = new ArrayList<AddressRangePosition>();
|
ArrayList<AddressRangePosition> toRemove = new ArrayList<AddressRangePosition>();
|
||||||
try {
|
try {
|
||||||
Iterator<AddressRangePosition> it = getPositionIterator(DisassemblyDocument.CATEGORY_MODEL, startAddress);
|
Iterator<Position> it = getPositionIterator(DisassemblyDocument.CATEGORY_MODEL, startAddress);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
AddressRangePosition p = it.next();
|
AddressRangePosition p = (AddressRangePosition) it.next();
|
||||||
addressLength = addressLength.add(p.fAddressLength);
|
addressLength = addressLength.add(p.fAddressLength);
|
||||||
replaceLength += p.length;
|
replaceLength += p.length;
|
||||||
toRemove.add(p);
|
toRemove.add(p);
|
||||||
|
|
Loading…
Add table
Reference in a new issue