1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Added decl/def/ref differentiation to PDOM Names, hooking them up correctly to the bindings. Added support for bytes in the database. Fixed up BindingsView to navigate to defs and added showing the first ref in action2.

This commit is contained in:
Doug Schaefer 2005-12-09 14:12:26 +00:00
parent fff6cffa2d
commit fba4d49389
4 changed files with 125 additions and 21 deletions

View file

@ -40,6 +40,14 @@ public class Chunk {
} }
} }
public void putByte(int offset, byte value) {
buffer.put(offset % Database.CHUNK_SIZE, value);
}
public byte getByte(int offset) {
return buffer.get(offset % Database.CHUNK_SIZE);
}
public void putInt(int offset, int value) { public void putInt(int offset, int value) {
buffer.putInt(offset % Database.CHUNK_SIZE, value); buffer.putInt(offset % Database.CHUNK_SIZE, value);
} }

View file

@ -236,6 +236,16 @@ public class Database {
addBlock(chunk, blocksize, block); addBlock(chunk, blocksize, block);
} }
public void putByte(int offset, byte value) throws CoreException {
Chunk chunk = getChunk(offset);
chunk.putByte(offset, value);
}
public byte getByte(int offset) throws CoreException {
Chunk chunk = getChunk(offset);
return chunk.getByte(offset);
}
public void putInt(int offset, int value) throws CoreException { public void putInt(int offset, int value) throws CoreException {
Chunk chunk = getChunk(offset); Chunk chunk = getChunk(offset);
chunk.putInt(offset, value); chunk.putInt(offset, value);

View file

@ -147,17 +147,35 @@ public class PDOMBinding implements IBinding {
} }
public void addDeclaration(PDOMName name) throws CoreException { public void addDeclaration(PDOMName name) throws CoreException {
PDOMName firstDeclaration = getFirstDeclaration(); PDOMName first = getFirstDeclaration();
if (firstDeclaration != null) { if (first != null) {
firstDeclaration.setPrevInBinding(name); first.setPrevInBinding(name);
name.setNextInBinding(firstDeclaration); name.setNextInBinding(first);
} }
setFirstDeclaration(name); setFirstDeclaration(name);
} }
public void addDefinition(PDOMName name) throws CoreException {
PDOMName first = getFirstDefinition();
if (first != null) {
first.setPrevInBinding(name);
name.setNextInBinding(first);
}
setFirstDefinition(name);
}
public void addReference(PDOMName name) throws CoreException {
PDOMName first = getFirstReference();
if (first != null) {
first.setPrevInBinding(name);
name.setNextInBinding(first);
}
setFirstReference(name);
}
public PDOMName getFirstDeclaration() throws CoreException { public PDOMName getFirstDeclaration() throws CoreException {
int firstDeclRec = pdom.getDB().getInt(record + FIRST_DECL_OFFSET); int namerec = pdom.getDB().getInt(record + FIRST_DECL_OFFSET);
return firstDeclRec != 0 ? new PDOMName(pdom, firstDeclRec) : null; return namerec != 0 ? new PDOMName(pdom, namerec) : null;
} }
public void setFirstDeclaration(PDOMName name) throws CoreException { public void setFirstDeclaration(PDOMName name) throws CoreException {
@ -165,6 +183,26 @@ public class PDOMBinding implements IBinding {
pdom.getDB().putInt(record + FIRST_DECL_OFFSET, namerec); pdom.getDB().putInt(record + FIRST_DECL_OFFSET, namerec);
} }
public PDOMName getFirstDefinition() throws CoreException {
int namerec = pdom.getDB().getInt(record + FIRST_DEF_OFFSET);
return namerec != 0 ? new PDOMName(pdom, namerec) : null;
}
public void setFirstDefinition(PDOMName name) throws CoreException {
int namerec = name != null ? name.getRecord() : 0;
pdom.getDB().putInt(record + FIRST_DEF_OFFSET, namerec);
}
public PDOMName getFirstReference() throws CoreException {
int namerec = pdom.getDB().getInt(record + FIRST_REF_OFFSET);
return namerec != 0 ? new PDOMName(pdom, namerec) : null;
}
public void setFirstReference(PDOMName name) throws CoreException {
int namerec = name != null ? name.getRecord() : 0;
pdom.getDB().putInt(record + FIRST_REF_OFFSET, namerec);
}
public String getName() { public String getName() {
try { try {
Database db = pdom.getDB(); Database db = pdom.getDB();

View file

@ -33,27 +33,53 @@ public class PDOMName implements IASTName, IASTFileLocation {
private final PDOMDatabase pdom; private final PDOMDatabase pdom;
private final int record; private final int record;
private static final int FILE_REC_OFFSET = 0 * Database.INT_SIZE; private static final int FILE_REC_OFFSET = 0;
private static final int FILE_PREV_OFFSET = 1 * Database.INT_SIZE; private static final int FILE_PREV_OFFSET = 4;
private static final int FILE_NEXT_OFFSET = 2 * Database.INT_SIZE; private static final int FILE_NEXT_OFFSET = 8;
private static final int BINDING_REC_OFFSET = 3 * Database.INT_SIZE; private static final int BINDING_REC_OFFSET = 12;
private static final int BINDING_PREV_OFFSET = 4 * Database.INT_SIZE; private static final int BINDING_PREV_OFFSET = 16;
private static final int BINDING_NEXT_OFFSET = 5 * Database.INT_SIZE; private static final int BINDING_NEXT_OFFSET = 20;
private static final int NODE_OFFSET_OFFSET = 6 * Database.INT_SIZE; private static final int NODE_OFFSET_OFFSET = 24;
private static final int NODE_LENGTH_OFFSET = 7 * Database.INT_SIZE; private static final int NODE_LENGTH_OFFSET = 28;
private static final int FLAGS = 32;
private static final int RECORD_SIZE = 33;
private static final int IS_DECLARATION = 1;
private static final int IS_DEFINITION = 2;
private static final int IS_REFERENCE = 3;
private static final int RECORD_SIZE = 8 * Database.INT_SIZE;
public PDOMName(PDOMDatabase pdom, IASTName name, PDOMBinding binding) throws CoreException { public PDOMName(PDOMDatabase pdom, IASTName name, PDOMBinding binding) throws CoreException {
this.pdom = pdom; this.pdom = pdom;
Database db = pdom.getDB(); Database db = pdom.getDB();
record = db.malloc(RECORD_SIZE); record = db.malloc(RECORD_SIZE);
// What kind of name are we
byte flags = 0;
if (name.isDefinition())
flags = IS_DEFINITION;
else if (name.isDeclaration())
flags = IS_DECLARATION;
else
flags = IS_REFERENCE;
db.putByte(record + FLAGS, flags);
// Hook us up to the binding // Hook us up to the binding
if (binding != null) { if (binding != null) {
db.putInt(record + BINDING_REC_OFFSET, binding.getRecord()); switch (flags) {
if (name.isDeclaration()) case IS_DEFINITION:
binding.addDefinition(this);
break;
case IS_DECLARATION:
binding.addDeclaration(this); binding.addDeclaration(this);
break;
case IS_REFERENCE:
binding.addReference(this);
break;
}
db.putInt(record + BINDING_REC_OFFSET, binding.getRecord());
} }
// Hook us up the the liked name list from file // Hook us up the the liked name list from file
@ -182,16 +208,38 @@ public class PDOMName implements IASTName, IASTFileLocation {
} }
} }
private byte getFlags() throws CoreException {
return pdom.getDB().getByte(record + FLAGS);
}
public boolean isDeclaration() { public boolean isDeclaration() {
throw new PDOMNotImplementedError(); try {
byte flags = getFlags();
return flags == IS_DECLARATION || flags == IS_DEFINITION;
} catch (CoreException e) {
CCorePlugin.log(e);
return false;
}
} }
public boolean isReference() { public boolean isReference() {
throw new PDOMNotImplementedError(); try {
byte flags = getFlags();
return flags == IS_REFERENCE;
} catch (CoreException e) {
CCorePlugin.log(e);
return false;
}
} }
public boolean isDefinition() { public boolean isDefinition() {
throw new PDOMNotImplementedError(); try {
byte flags = getFlags();
return flags == IS_DEFINITION;
} catch (CoreException e) {
CCorePlugin.log(e);
return false;
}
} }
public IASTTranslationUnit getTranslationUnit() { public IASTTranslationUnit getTranslationUnit() {