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:
parent
fff6cffa2d
commit
fba4d49389
4 changed files with 125 additions and 21 deletions
|
@ -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) {
|
||||
buffer.putInt(offset % Database.CHUNK_SIZE, value);
|
||||
}
|
||||
|
|
|
@ -236,6 +236,16 @@ public class Database {
|
|||
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 {
|
||||
Chunk chunk = getChunk(offset);
|
||||
chunk.putInt(offset, value);
|
||||
|
|
|
@ -147,17 +147,35 @@ public class PDOMBinding implements IBinding {
|
|||
}
|
||||
|
||||
public void addDeclaration(PDOMName name) throws CoreException {
|
||||
PDOMName firstDeclaration = getFirstDeclaration();
|
||||
if (firstDeclaration != null) {
|
||||
firstDeclaration.setPrevInBinding(name);
|
||||
name.setNextInBinding(firstDeclaration);
|
||||
PDOMName first = getFirstDeclaration();
|
||||
if (first != null) {
|
||||
first.setPrevInBinding(name);
|
||||
name.setNextInBinding(first);
|
||||
}
|
||||
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 {
|
||||
int firstDeclRec = pdom.getDB().getInt(record + FIRST_DECL_OFFSET);
|
||||
return firstDeclRec != 0 ? new PDOMName(pdom, firstDeclRec) : null;
|
||||
int namerec = pdom.getDB().getInt(record + FIRST_DECL_OFFSET);
|
||||
return namerec != 0 ? new PDOMName(pdom, namerec) : null;
|
||||
}
|
||||
|
||||
public void setFirstDeclaration(PDOMName name) throws CoreException {
|
||||
|
@ -165,6 +183,26 @@ public class PDOMBinding implements IBinding {
|
|||
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() {
|
||||
try {
|
||||
Database db = pdom.getDB();
|
||||
|
|
|
@ -33,27 +33,53 @@ public class PDOMName implements IASTName, IASTFileLocation {
|
|||
private final PDOMDatabase pdom;
|
||||
private final int record;
|
||||
|
||||
private static final int FILE_REC_OFFSET = 0 * Database.INT_SIZE;
|
||||
private static final int FILE_PREV_OFFSET = 1 * Database.INT_SIZE;
|
||||
private static final int FILE_NEXT_OFFSET = 2 * Database.INT_SIZE;
|
||||
private static final int BINDING_REC_OFFSET = 3 * Database.INT_SIZE;
|
||||
private static final int BINDING_PREV_OFFSET = 4 * Database.INT_SIZE;
|
||||
private static final int BINDING_NEXT_OFFSET = 5 * Database.INT_SIZE;
|
||||
private static final int NODE_OFFSET_OFFSET = 6 * Database.INT_SIZE;
|
||||
private static final int NODE_LENGTH_OFFSET = 7 * Database.INT_SIZE;
|
||||
private static final int FILE_REC_OFFSET = 0;
|
||||
private static final int FILE_PREV_OFFSET = 4;
|
||||
private static final int FILE_NEXT_OFFSET = 8;
|
||||
private static final int BINDING_REC_OFFSET = 12;
|
||||
private static final int BINDING_PREV_OFFSET = 16;
|
||||
private static final int BINDING_NEXT_OFFSET = 20;
|
||||
private static final int NODE_OFFSET_OFFSET = 24;
|
||||
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 {
|
||||
this.pdom = pdom;
|
||||
Database db = pdom.getDB();
|
||||
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
|
||||
if (binding != null) {
|
||||
db.putInt(record + BINDING_REC_OFFSET, binding.getRecord());
|
||||
if (name.isDeclaration())
|
||||
switch (flags) {
|
||||
case IS_DEFINITION:
|
||||
binding.addDefinition(this);
|
||||
break;
|
||||
case IS_DECLARATION:
|
||||
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
|
||||
|
@ -182,16 +208,38 @@ public class PDOMName implements IASTName, IASTFileLocation {
|
|||
}
|
||||
}
|
||||
|
||||
private byte getFlags() throws CoreException {
|
||||
return pdom.getDB().getByte(record + FLAGS);
|
||||
}
|
||||
|
||||
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() {
|
||||
throw new PDOMNotImplementedError();
|
||||
try {
|
||||
byte flags = getFlags();
|
||||
return flags == IS_REFERENCE;
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
|
|
Loading…
Add table
Reference in a new issue