From fba4d493898b83d5d75b64fab713a84ff08c24a5 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Fri, 9 Dec 2005 14:12:26 +0000 Subject: [PATCH] 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. --- .../cdt/internal/core/pdom/db/Chunk.java | 8 ++ .../cdt/internal/core/pdom/db/Database.java | 10 +++ .../internal/core/pdom/dom/PDOMBinding.java | 50 ++++++++++-- .../cdt/internal/core/pdom/dom/PDOMName.java | 78 +++++++++++++++---- 4 files changed, 125 insertions(+), 21 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java index 4833eefb5b5..ebbb00e094a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Chunk.java @@ -39,6 +39,14 @@ public class Chunk { throw new CoreException(new DBStatus(e)); } } + + 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); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java index 386c34c047a..f819e5ac492 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java @@ -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); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java index 8a2b30b2af1..4b08f3f8a8b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java @@ -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(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java index 8274b9abc37..9e3a7bb0ec1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java @@ -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() {