mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Bug 402878. Code streamlining.
This commit is contained in:
parent
0243165590
commit
95073b1f13
1 changed files with 36 additions and 25 deletions
|
@ -48,18 +48,18 @@ public class PDOMCPPMemberBlock {
|
||||||
|
|
||||||
private final PDOMLinkage linkage;
|
private final PDOMLinkage linkage;
|
||||||
private final long record;
|
private final long record;
|
||||||
private int nextMemberPosition = -1;
|
private int nextMemberPosition;
|
||||||
|
|
||||||
public PDOMCPPMemberBlock(PDOMLinkage linkage, long record) throws CoreException {
|
public PDOMCPPMemberBlock(PDOMLinkage linkage, long record) throws CoreException {
|
||||||
this.linkage = linkage;
|
this.linkage = linkage;
|
||||||
this.record = record;
|
this.record = record;
|
||||||
|
this.nextMemberPosition = -1; // nextMemberPosition is unknown.
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMCPPMemberBlock(PDOMLinkage linkage) throws CoreException {
|
public PDOMCPPMemberBlock(PDOMLinkage linkage) throws CoreException {
|
||||||
Database db = linkage.getDB();
|
Database db = linkage.getDB();
|
||||||
this.linkage = linkage;
|
this.linkage = linkage;
|
||||||
this.record = db.malloc(RECORD_SIZE);
|
this.record = db.malloc(RECORD_SIZE);
|
||||||
db.clearBytes(record, RECORD_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNextPosition() throws CoreException {
|
private int getNextPosition() throws CoreException {
|
||||||
|
@ -91,19 +91,26 @@ public class PDOMCPPMemberBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMember(PDOMNode member, int visibility) throws CoreException {
|
public void addMember(PDOMNode member, int visibility) throws CoreException {
|
||||||
if (getNextPosition() == MAX_MEMBER_COUNT) {
|
addMember(this, member, visibility);
|
||||||
PDOMCPPMemberBlock nextBlock = getNextBlock();
|
}
|
||||||
if (nextBlock == null) {
|
|
||||||
nextBlock = new PDOMCPPMemberBlock(linkage);
|
private static void addMember(PDOMCPPMemberBlock block, PDOMNode member, int visibility)
|
||||||
setNextBlock(nextBlock);
|
throws CoreException {
|
||||||
|
while (true) {
|
||||||
|
int pos = block.getNextPosition();
|
||||||
|
if (pos < MAX_MEMBER_COUNT) {
|
||||||
|
long memberLocationOffset = block.getMemberOffset(pos);
|
||||||
|
block.getDB().putRecPtr(memberLocationOffset, member.getRecord());
|
||||||
|
block.setVisibility(pos, visibility);
|
||||||
|
block.nextMemberPosition++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PDOMCPPMemberBlock previousBlock = block;
|
||||||
|
block = block.getNextBlock();
|
||||||
|
if (block == null) {
|
||||||
|
block = new PDOMCPPMemberBlock(previousBlock.linkage);
|
||||||
|
previousBlock.setNextBlock(block);
|
||||||
}
|
}
|
||||||
nextBlock.addMember(member, visibility);
|
|
||||||
} else {
|
|
||||||
long memberLocationOffset = getMemberOffset(getNextPosition());
|
|
||||||
long rec = member.getRecord();
|
|
||||||
getDB().putRecPtr(memberLocationOffset, rec);
|
|
||||||
setVisibility(getNextPosition(), visibility);
|
|
||||||
nextMemberPosition++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,10 +130,11 @@ public class PDOMCPPMemberBlock {
|
||||||
long memberRecord;
|
long memberRecord;
|
||||||
while (item < MAX_MEMBER_COUNT && (memberRecord = getMemberRecord(item++)) != 0) {
|
while (item < MAX_MEMBER_COUNT && (memberRecord = getMemberRecord(item++)) != 0) {
|
||||||
PDOMNode node = linkage.getNode(memberRecord);
|
PDOMNode node = linkage.getNode(memberRecord);
|
||||||
if (visitor.visit(node) && node != null) {
|
if (node != null) {
|
||||||
node.accept(visitor);
|
if (visitor.visit(node))
|
||||||
|
node.accept(visitor);
|
||||||
|
visitor.leave(node);
|
||||||
}
|
}
|
||||||
visitor.leave(node);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,8 +154,7 @@ public class PDOMCPPMemberBlock {
|
||||||
if (memberIndex < getNextPosition() && memberIndex < MAX_MEMBER_COUNT) {
|
if (memberIndex < getNextPosition() && memberIndex < MAX_MEMBER_COUNT) {
|
||||||
long memberRecord = getMemberRecord(memberIndex);
|
long memberRecord = getMemberRecord(memberIndex);
|
||||||
if (memberRecord != 0) {
|
if (memberRecord != 0) {
|
||||||
PDOMNode node = linkage.getNode(memberRecord);
|
return linkage.getNode(memberRecord);
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -159,9 +166,9 @@ public class PDOMCPPMemberBlock {
|
||||||
int visibilityBitOffset = memberIndex % VISIBILITY_VALUES_PER_BYTE;
|
int visibilityBitOffset = memberIndex % VISIBILITY_VALUES_PER_BYTE;
|
||||||
long visibilityOffset = record + MEMBER_VISIBILITIES + memberIndex / VISIBILITY_VALUES_PER_BYTE;
|
long visibilityOffset = record + MEMBER_VISIBILITIES + memberIndex / VISIBILITY_VALUES_PER_BYTE;
|
||||||
int visibility = getDB().getByte(visibilityOffset);
|
int visibility = getDB().getByte(visibilityOffset);
|
||||||
// Resetting the previous visibility bits of the target member
|
// Resetting the previous visibility bits of the target member.
|
||||||
visibility &= ~(VISIBILITY_MASK << visibilityBitOffset * VISIBILITY_BITS);
|
visibility &= ~(VISIBILITY_MASK << visibilityBitOffset * VISIBILITY_BITS);
|
||||||
// Setting the new visibility bits of the target member
|
// Setting the new visibility bits of the target member.
|
||||||
visibility |= newVisibility << visibilityBitOffset * VISIBILITY_BITS;
|
visibility |= newVisibility << visibilityBitOffset * VISIBILITY_BITS;
|
||||||
|
|
||||||
getDB().putByte(visibilityOffset, (byte) visibility);
|
getDB().putByte(visibilityOffset, (byte) visibility);
|
||||||
|
@ -171,7 +178,11 @@ public class PDOMCPPMemberBlock {
|
||||||
* Returns visibility of the member, or -1 if the given binding is not a member.
|
* Returns visibility of the member, or -1 if the given binding is not a member.
|
||||||
*/
|
*/
|
||||||
public int getVisibility(IBinding member) throws CoreException {
|
public int getVisibility(IBinding member) throws CoreException {
|
||||||
for (PDOMCPPMemberBlock block = this; block != null; block = block.getNextBlock()) {
|
return getVisibility(this, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getVisibility(PDOMCPPMemberBlock block, IBinding member) throws CoreException {
|
||||||
|
do {
|
||||||
for (int memberIndex = 0; memberIndex < block.getNextPosition(); memberIndex++) {
|
for (int memberIndex = 0; memberIndex < block.getNextPosition(); memberIndex++) {
|
||||||
PDOMNode candidate = block.getMember(memberIndex);
|
PDOMNode candidate = block.getMember(memberIndex);
|
||||||
if (candidate == null)
|
if (candidate == null)
|
||||||
|
@ -179,7 +190,8 @@ public class PDOMCPPMemberBlock {
|
||||||
if (candidate.equals(member))
|
if (candidate.equals(member))
|
||||||
return block.getVisibility(memberIndex);
|
return block.getVisibility(memberIndex);
|
||||||
}
|
}
|
||||||
}
|
} while ((block = block.getNextBlock()) != null);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,9 +201,8 @@ public class PDOMCPPMemberBlock {
|
||||||
int visibility = getDB().getByte(visibilityOffset);
|
int visibility = getDB().getByte(visibilityOffset);
|
||||||
|
|
||||||
visibility >>>= visibilityBitOffset * VISIBILITY_BITS;
|
visibility >>>= visibilityBitOffset * VISIBILITY_BITS;
|
||||||
// Filtering the visibility bits of the target member
|
// Filtering the visibility bits of the target member.
|
||||||
visibility &= VISIBILITY_MASK;
|
visibility &= VISIBILITY_MASK;
|
||||||
|
|
||||||
return visibility;
|
return visibility;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue