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

Modified DOM indexer to use IIndexEntry hierarchy to store index entries.

This enables more information to be stored during indexing (modifiers, function sigantures,...). Also should address definition/declaration issues raised by Devin.
This commit is contained in:
Vladimir Hirsl 2005-06-01 19:45:33 +00:00
parent b7745b5167
commit 8e99ab5565
11 changed files with 644 additions and 189 deletions

View file

@ -1,3 +1,19 @@
2005-06-01 Vladimir Hirsl
Modified DOM indexer to use IIndexEntry hierarchy to store index entries.
This enables more information to be stored during indexing (modifiers, function sigantures,...)
Also should address definition/declaration issues raised by Devin.
* index/org/eclipse/cdt/internal/core/index/FunctionEntry.java
* index/org/eclipse/cdt/internal/core/index/IFunctionEntry.java
* index/org/eclipse/cdt/internal/core/index/IIndex.java
* index/org/eclipse/cdt/internal/core/index/ITypeEntry.java
* index/org/eclipse/cdt/internal/core/index/TypeEntry.java
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/CGenerateIndexVisitor.java
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/CPPGenerateIndexVisitor.java
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/DOMSourceIndexerRunner.java
* index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexerOutputWrapper.java
+ index/org/eclipse/cdt/internal/core/index/domsourceindexer/IndexVisitorUtil.java
2005-05-25 David Inglis 2005-05-25 David Inglis
CModel performance improvement: only need to test project existance and nature for ICElement.exists() CModel performance improvement: only need to test project existance and nature for ICElement.exists()

View file

@ -26,12 +26,18 @@ public class FunctionEntry extends NamedEntry implements IFunctionEntry {
public char[][] getSignature() { public char[][] getSignature() {
return signature; return signature;
}
public void setReturnType(char[] returnType) {
this.returnString = returnType;
}
public char[] getReturnType() {
return returnString;
} }
public void serialize(IIndexerOutput output) { public void serialize(IIndexerOutput output) {
output.addIndexEntry(this); output.addIndexEntry(this);
} }
} }

View file

@ -16,4 +16,6 @@ public interface IFunctionEntry extends INamedEntry {
public char[][] getSignature(); public char[][] getSignature();
public char[] getReturnType();
} }

View file

@ -56,6 +56,7 @@ public interface IIndex {
final static int TYPE_FWD_UNION = 11; final static int TYPE_FWD_UNION = 11;
// type // type
final static int UNKNOWN = 0;
final static int DECLARATION = 1; final static int DECLARATION = 1;
final static int REFERENCE = 2; final static int REFERENCE = 2;
final static int DEFINITION = 3; final static int DEFINITION = 3;

View file

@ -39,8 +39,12 @@ public interface ITypeEntry extends INamedEntry {
public int getTypeKind(); public int getTypeKind();
/** /**
* Returns the types that are inherited * Returns the types that are inherited
* @return an array of char arrays - each representing a separate type that this entry inherits from * @return an array of index entries - each representing a separate type that this entry inherits from
*/ */
public IIndexEntry[] getBaseTypes(); public IIndexEntry[] getBaseTypes();
/**
* Return friend types
* @return an array of index entries - each representing a friend to this type
*/
public IIndexEntry[] getFriends();
} }

View file

@ -16,6 +16,7 @@ public class TypeEntry extends NamedEntry implements ITypeEntry {
int type_kind; int type_kind;
IIndexEntry[] baseTypes; IIndexEntry[] baseTypes;
IIndexEntry[] friends;
public TypeEntry(int type_kind, int entry_type, char[][] fullName, int modifiers, int fileNumber){ public TypeEntry(int type_kind, int entry_type, char[][] fullName, int modifiers, int fileNumber){
super(IIndex.TYPE, entry_type, fullName, modifiers, fileNumber); super(IIndex.TYPE, entry_type, fullName, modifiers, fileNumber);
@ -38,4 +39,12 @@ public class TypeEntry extends NamedEntry implements ITypeEntry {
return baseTypes; return baseTypes;
} }
public IIndexEntry[] getFriends() {
return friends;
}
public void setFriends(IIndexEntry[] friends) {
this.friends = friends;
}
} }

View file

@ -27,8 +27,10 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor; import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.internal.core.index.FunctionEntry;
import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.domsourceindexer.IndexerOutputWrapper.EntryType; import org.eclipse.cdt.internal.core.index.NamedEntry;
import org.eclipse.cdt.internal.core.index.TypeEntry;
public class CGenerateIndexVisitor extends CASTVisitor { public class CGenerateIndexVisitor extends CASTVisitor {
private DOMSourceIndexerRunner indexer; private DOMSourceIndexerRunner indexer;
@ -123,57 +125,100 @@ public class CGenerateIndexVisitor extends CASTVisitor {
* @throws DOMException * @throws DOMException
*/ */
private void processNameBinding(IASTName name, IBinding binding, IASTFileLocation loc, int fileNumber) throws DOMException { private void processNameBinding(IASTName name, IBinding binding, IASTFileLocation loc, int fileNumber) throws DOMException {
char[][] qualifiedName = getFullyQualifiedName(name);
IASTFileLocation fileLoc = IndexEncoderUtil.getFileLocation(name);
// determine entryKind
int entryKind = IIndex.UNKNOWN;
if (name.isDefinition()){
entryKind = IIndex.DEFINITION;
}
else if (name.isDeclaration()) {
entryKind = IIndex.DECLARATION;
}
else if (name.isReference()) {
entryKind = IIndex.REFERENCE;
}
// determine type // determine type
EntryType entryType = null;
if (binding instanceof ICompositeType) { if (binding instanceof ICompositeType) {
int iEntryType = 0;
int compositeKey = ((ICompositeType) binding).getKey(); int compositeKey = ((ICompositeType) binding).getKey();
ASTNodeProperty prop = name.getPropertyInParent(); ASTNodeProperty prop = name.getPropertyInParent();
switch (compositeKey) { switch (compositeKey) {
case ICompositeType.k_struct: case ICompositeType.k_struct:
entryType = IndexerOutputWrapper.STRUCT; iEntryType = IIndex.TYPE_STRUCT;
if (name.isDeclaration() && prop == IASTElaboratedTypeSpecifier.TYPE_NAME) if (name.isDeclaration() && prop == IASTElaboratedTypeSpecifier.TYPE_NAME)
entryType = IndexerOutputWrapper.FWD_STRUCT; iEntryType = IIndex.TYPE_FWD_STRUCT;
break; break;
case ICompositeType.k_union: case ICompositeType.k_union:
entryType = IndexerOutputWrapper.UNION; iEntryType = IIndex.TYPE_UNION;
if (name.isDeclaration() && prop == IASTElaboratedTypeSpecifier.TYPE_NAME) if (name.isDeclaration() && prop == IASTElaboratedTypeSpecifier.TYPE_NAME)
entryType = IndexerOutputWrapper.FWD_UNION; iEntryType = IIndex.TYPE_FWD_UNION;
break; break;
} }
int modifiers = 0;
if (entryKind != IIndex.REFERENCE) {
modifiers = IndexVisitorUtil.getModifiers(name, binding);
}
TypeEntry indexEntry = new TypeEntry(iEntryType, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
}
else if (binding instanceof IEnumeration){
int modifiers = 0;
if (entryKind != IIndex.REFERENCE) {
modifiers = IndexVisitorUtil.getModifiers(name, binding);
}
TypeEntry indexEntry = new TypeEntry(IIndex.TYPE_ENUM, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
}
else if (binding instanceof ITypedef) {
TypeEntry indexEntry = new TypeEntry(IIndex.TYPE_TYPEDEF, entryKind, qualifiedName, 0, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
}
else if (binding instanceof IEnumerator) {
NamedEntry indexEntry = new NamedEntry(IIndex.ENUMTOR, entryKind, qualifiedName, 0, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
}
else if (binding instanceof IField) {
int modifiers = 0;
if (entryKind != IIndex.REFERENCE) {
modifiers = IndexVisitorUtil.getModifiers(name, binding);
}
NamedEntry indexEntry = new NamedEntry(IIndex.FIELD, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
} }
else if (binding instanceof IEnumeration)
entryType = IndexerOutputWrapper.ENUM;
else if (binding instanceof ITypedef)
entryType = IndexerOutputWrapper.TYPEDEF;
else if (binding instanceof IEnumerator)
entryType = IndexerOutputWrapper.ENUMERATOR;
else if (binding instanceof IField)
entryType = IndexerOutputWrapper.FIELD;
else if (binding instanceof IParameter || else if (binding instanceof IParameter ||
binding instanceof IVariable) binding instanceof IVariable) {
entryType = IndexerOutputWrapper.VAR; int modifiers = 0;
else if (binding instanceof IFunction) if (entryKind != IIndex.REFERENCE) {
entryType = IndexerOutputWrapper.FUNCTION; modifiers = IndexVisitorUtil.getModifiers(name, binding);
if (entryType != null) {
int entryKind=0;
if (name.isDeclaration()) {
entryKind=IIndex.DECLARATION;
}/* else if (name.isDefinition()){
entryKind=IIndex.DEFINITION;
}*/
else if (name.isReference()) {
entryKind=IIndex.REFERENCE;
} }
TypeEntry indexEntry = new TypeEntry(IIndex.TYPE_VAR, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
IndexerOutputWrapper.addIndexEntry(indexer.getOutput(), indexEntry.serialize(indexer.getOutput());
getFullyQualifiedName(name), }
entryType, else if (binding instanceof IFunction) {
entryKind, int modifiers = 0;
fileNumber, if (entryKind != IIndex.REFERENCE) {
loc.getNodeOffset(), modifiers = IndexVisitorUtil.getModifiers(name, binding);
loc.getNodeLength(), }
IIndex.OFFSET); FunctionEntry indexEntry = new FunctionEntry(IIndex.FUNCTION, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.setSignature(IndexVisitorUtil.getParameters((IFunction) binding));
indexEntry.serialize(indexer.getOutput());
} }
} }

View file

@ -10,12 +10,19 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.index.domsourceindexer; package org.eclipse.cdt.internal.core.index.domsourceindexer;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
@ -27,8 +34,10 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
@ -36,10 +45,11 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.search.ICSearchConstants; import org.eclipse.cdt.internal.core.index.FunctionEntry;
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.domsourceindexer.IndexerOutputWrapper.EntryType; import org.eclipse.cdt.internal.core.index.IIndexEntry;
import org.eclipse.cdt.internal.core.index.NamedEntry;
import org.eclipse.cdt.internal.core.index.TypeEntry;
public class CPPGenerateIndexVisitor extends CPPASTVisitor { public class CPPGenerateIndexVisitor extends CPPASTVisitor {
private DOMSourceIndexerRunner indexer; private DOMSourceIndexerRunner indexer;
@ -125,7 +135,7 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
//or if it occurs in another file //or if it occurs in another file
int indexFlag = IndexEncoderUtil.calculateIndexFlags(indexer, loc); int indexFlag = IndexEncoderUtil.calculateIndexFlags(indexer, loc);
processNameBinding(name, binding, loc, indexFlag, null); // function will determine limitTo processNameBinding(name, binding, loc, indexFlag, IIndex.UNKNOWN); // function will determine limitTo
} }
} }
@ -137,73 +147,137 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
* @param limitTo * @param limitTo
* @throws DOMException * @throws DOMException
*/ */
private void processNameBinding(IASTName name, IBinding binding, IASTFileLocation loc, int fileNumber, LimitTo limitTo) throws DOMException { private void processNameBinding(IASTName name, IBinding binding, IASTFileLocation loc, int fileNumber, int entryKind) throws DOMException {
// determine LimitTo char[][] qualifiedName = getFullyQualifiedName(binding);
if (limitTo == null) { IASTFileLocation fileLoc = IndexEncoderUtil.getFileLocation(name);
if (name.isDeclaration()) {
limitTo = ICSearchConstants.DECLARATIONS; // determine entryKind
if (entryKind == IIndex.UNKNOWN) {
if (name.isDefinition()){
entryKind = IIndex.DEFINITION;
} }
else if (name.isDefinition()){ else if (name.isDeclaration()) {
limitTo = ICSearchConstants.DEFINITIONS; entryKind = IIndex.DECLARATION;
} }
else if (name.isReference()) { else if (name.isReference()) {
limitTo = ICSearchConstants.REFERENCES; entryKind = IIndex.REFERENCE;
}
else {
limitTo = ICSearchConstants.UNKNOWN_LIMIT_TO;
} }
} }
// determine type // determine type
EntryType entryType = null;
if (binding instanceof ICompositeType) { if (binding instanceof ICompositeType) {
int iEntryType = 0;
ICompositeType compBinding = (ICompositeType) binding; ICompositeType compBinding = (ICompositeType) binding;
int compositeKey = compBinding.getKey(); int compositeKey = compBinding.getKey();
ASTNodeProperty prop = name.getPropertyInParent(); ASTNodeProperty prop = name.getPropertyInParent();
switch (compositeKey) { switch (compositeKey) {
case ICPPClassType.k_class: case ICPPClassType.k_class:
entryType = IndexerOutputWrapper.CLASS; iEntryType = IIndex.TYPE_CLASS;
if (name.isDeclaration() && prop == IASTElaboratedTypeSpecifier.TYPE_NAME) if (name.isDeclaration() && prop == IASTElaboratedTypeSpecifier.TYPE_NAME) {
entryType = IndexerOutputWrapper.FWD_CLASS; iEntryType = IIndex.TYPE_FWD_CLASS;
}
break; break;
case ICompositeType.k_struct: case ICompositeType.k_struct:
entryType = IndexerOutputWrapper.STRUCT; iEntryType = IIndex.TYPE_STRUCT;
if (name.isDeclaration() && prop == IASTElaboratedTypeSpecifier.TYPE_NAME) if (name.isDeclaration() && prop == IASTElaboratedTypeSpecifier.TYPE_NAME) {
entryType = IndexerOutputWrapper.FWD_STRUCT; iEntryType = IIndex.TYPE_FWD_STRUCT;
}
break; break;
case ICompositeType.k_union: case ICompositeType.k_union:
entryType = IndexerOutputWrapper.UNION; iEntryType = IIndex.TYPE_UNION;
if (name.isDeclaration() && prop == IASTElaboratedTypeSpecifier.TYPE_NAME) if (name.isDeclaration() && prop == IASTElaboratedTypeSpecifier.TYPE_NAME) {
entryType = IndexerOutputWrapper.FWD_UNION; iEntryType = IIndex.TYPE_FWD_UNION;
}
break; break;
} }
addDerivedDeclaratiion(name, compBinding, loc, fileNumber); int modifiers = 0;
if (isFriendDeclaration(name, binding)) { if (entryKind != IIndex.REFERENCE) {
entryType = IndexerOutputWrapper.FRIEND; modifiers = IndexVisitorUtil.getModifiers(name, binding);
} }
TypeEntry indexEntry = new TypeEntry(iEntryType, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
if (entryKind == IIndex.DEFINITION && binding instanceof ICPPClassType) {
addDerivedDeclarations(name, (ICPPClassType)binding, indexEntry, fileNumber);
addFriendDeclarations(name, (ICPPClassType)binding, indexEntry, fileNumber);
}
indexEntry.serialize(indexer.getOutput());
}
else if (binding instanceof IEnumeration) {
int modifiers = 0;
if (entryKind != IIndex.REFERENCE) {
modifiers = IndexVisitorUtil.getModifiers(name, binding);
}
TypeEntry indexEntry = new TypeEntry(IIndex.TYPE_ENUM, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
}
else if (binding instanceof ITypedef) {
TypeEntry indexEntry = new TypeEntry(IIndex.TYPE_TYPEDEF, entryKind, qualifiedName, 0, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
}
else if (binding instanceof ICPPNamespace) {
NamedEntry indexEntry = new NamedEntry(IIndex.NAMESPACE, entryKind, qualifiedName, 0, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
}
else if (binding instanceof IEnumerator) {
NamedEntry indexEntry = new NamedEntry(IIndex.ENUMTOR, entryKind, qualifiedName, 0, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
}
else if (binding instanceof IField) {
int modifiers = 0;
if (entryKind != IIndex.REFERENCE) {
modifiers = IndexVisitorUtil.getModifiers(name, binding);
}
NamedEntry indexEntry = new NamedEntry(IIndex.FIELD, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
} }
else if (binding instanceof IEnumeration)
entryType = IndexerOutputWrapper.ENUM;
else if (binding instanceof ITypedef)
entryType = IndexerOutputWrapper.TYPEDEF;
else if (binding instanceof ICPPNamespace)
entryType = IndexerOutputWrapper.NAMESPACE;
else if (binding instanceof IEnumerator)
entryType = IndexerOutputWrapper.ENUMERATOR;
else if (binding instanceof IField)
entryType = IndexerOutputWrapper.FIELD;
else if (binding instanceof IParameter || else if (binding instanceof IParameter ||
binding instanceof IVariable) binding instanceof IVariable) {
entryType = IndexerOutputWrapper.VAR; int modifiers = 0;
if (entryKind != IIndex.REFERENCE) {
modifiers = IndexVisitorUtil.getModifiers(name, binding);
}
TypeEntry indexEntry = new TypeEntry(IIndex.TYPE_VAR, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.serialize(indexer.getOutput());
}
else if (binding instanceof ICPPMethod) { else if (binding instanceof ICPPMethod) {
entryType = IndexerOutputWrapper.METHOD; int modifiers = 0;
if (entryKind != IIndex.REFERENCE) {
modifiers = IndexVisitorUtil.getModifiers(name, binding);
}
FunctionEntry indexEntry = new FunctionEntry(IIndex.METHOD, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.setSignature(IndexVisitorUtil.getParameters((IFunction) binding));
indexEntry.setReturnType(IndexVisitorUtil.getReturnType((IFunction) binding));
indexEntry.serialize(indexer.getOutput());
// TODO In case we want to add friend method declarations to index // TODO In case we want to add friend method declarations to index
// if (isFriendDeclaration(name, binding)) { // if (isFriendDeclaration(name, binding)) {
// entryType = IndexerOutputWrapper.FRIEND; // entryType = IndexerOutputWrapper.FRIEND;
// } // }
} }
else if (binding instanceof IFunction) { else if (binding instanceof IFunction) {
entryType = IndexerOutputWrapper.FUNCTION; int modifiers = 0;
if (entryKind != IIndex.REFERENCE) {
modifiers = IndexVisitorUtil.getModifiers(name, binding);
}
FunctionEntry indexEntry = new FunctionEntry(IIndex.FUNCTION, entryKind, qualifiedName, modifiers, fileNumber);
indexEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
indexEntry.setSignature(IndexVisitorUtil.getParameters((IFunction) binding));
indexEntry.serialize(indexer.getOutput());
// TODO In case we want to add friend function declarations to index // TODO In case we want to add friend function declarations to index
// if (isFriendDeclaration(name, binding)) { // if (isFriendDeclaration(name, binding)) {
// entryType = IndexerOutputWrapper.FRIEND; // entryType = IndexerOutputWrapper.FRIEND;
@ -213,102 +287,129 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
ICPPDelegate[] delegates = ((ICPPUsingDeclaration)binding).getDelegates(); ICPPDelegate[] delegates = ((ICPPUsingDeclaration)binding).getDelegates();
for (int i = 0; i < delegates.length; i++) { for (int i = 0; i < delegates.length; i++) {
IBinding orig = delegates[i].getBinding(); IBinding orig = delegates[i].getBinding();
processNameBinding(name, orig, loc, fileNumber, ICSearchConstants.REFERENCES); // reference to the original binding processNameBinding(name, orig, loc, fileNumber, IIndex.REFERENCE); // reference to the original binding
processNameBinding(name, delegates[i], loc, fileNumber, ICSearchConstants.DECLARATIONS); // declaration of the new name processNameBinding(name, delegates[i], loc, fileNumber, IIndex.DECLARATION); // declaration of the new name
} }
return; return;
} }
if (entryType != null) { // if (entryType != null) {
int entryKind =0; // IndexerOutputWrapper.addIndexEntry(indexer.getOutput(),
if (limitTo == ICSearchConstants.DECLARATIONS) { // getFullyQualifiedName(binding),
entryKind = IIndex.DECLARATION; // entryType,
} // entryKind,
/*else if (limitTo == ICSearchConstants.DEFINITIONS) { // fileNumber,
entryKind = IIndex.DEFINITION; // loc.getNodeOffset(),
}*/ // loc.getNodeLength(),
else if (limitTo == ICSearchConstants.REFERENCES) { // IIndex.OFFSET);
entryKind = IIndex.REFERENCE; // }
} }
IndexerOutputWrapper.addIndexEntry(indexer.getOutput(), /**
getFullyQualifiedName(binding), * @param name
entryType, * @param cppClassBinding
entryKind, * @param typeEntry
fileNumber, * @param fileNumber
loc.getNodeOffset(), * @throws DOMException
loc.getNodeLength(), */
IIndex.OFFSET); private void addDerivedDeclarations(IASTName name, ICPPClassType cppClassBinding, TypeEntry typeEntry, int fileNumber) throws DOMException {
List baseEntries = new ArrayList();
ICPPBase[] baseClasses = cppClassBinding.getBases();
for (int i = 0; i < baseClasses.length; i++) {
ICPPBase base = baseClasses[i];
ICPPClassType baseClass = baseClasses[i].getBaseClass();
int modifiers = 0;
int vis = base.getVisibility();
if (vis == ICPPBase.v_public) {
modifiers |= IIndex.publicAccessSpecifier;
}
else if (vis == ICPPBase.v_protected) {
modifiers |= IIndex.protectedAccessSpecifier;
}
else if (vis == ICPPBase.v_private) {
modifiers |= IIndex.privateAccessSpecifier;
}
if (base.isVirtual()) {
modifiers |= IIndex.virtualSpecifier;
}
NamedEntry namedEntry = new NamedEntry(IIndex.TYPE_DERIVED, IIndex.DECLARATION,
baseClass.getQualifiedNameCharArray(), modifiers, fileNumber);
// tricky part - get the location of base specifier name
IASTNode parent = name.getParent();
if (parent instanceof ICPPASTCompositeTypeSpecifier) {
ICPPASTCompositeTypeSpecifier typeParent = (ICPPASTCompositeTypeSpecifier) parent;
ICPPASTBaseSpecifier[] baseSpecs = typeParent.getBaseSpecifiers();
IASTFileLocation baseLoc = null;
for (int j = 0; j < baseSpecs.length; j++) {
ICPPASTBaseSpecifier baseSpec = baseSpecs[j];
IASTName baseName = baseSpec.getName();
if (baseName.resolveBinding().equals(baseClass)) {
baseLoc = IndexEncoderUtil.getFileLocation(baseName);
break;
}
}
if (baseLoc != null) {
namedEntry.setNameOffset(baseLoc.getNodeOffset(), baseLoc.getNodeLength(), IIndex.OFFSET);
baseEntries.add(namedEntry);
}
}
}
if (baseEntries.size() > 0) {
typeEntry.setBaseTypes((IIndexEntry[]) baseEntries.toArray(new IIndexEntry[baseEntries.size()]));
} }
} }
/** /**
* @param name * @param name
* @param compBinding * @param cppClassBinding
* @param loc * @param typeEntry
* @param fileNumber * @param fileNumber
* @throws DOMException
*/ */
private void addDerivedDeclaratiion(IASTName name, ICompositeType compBinding, IASTFileLocation loc, int fileNumber) throws DOMException { private void addFriendDeclarations(IASTName name, ICPPClassType cppClassBinding, TypeEntry typeEntry, int fileNumber) {
ASTNodeProperty prop = name.getPropertyInParent(); try {
int compositeKey = compBinding.getKey(); IBinding[] friends = cppClassBinding.getFriends();
if (compositeKey == ICPPClassType.k_class || compositeKey == ICompositeType.k_struct) { if (friends.length > 0) {
if (prop == ICPPASTBaseSpecifier.NAME) { IASTNode parent = name.getParent();
// base class if (parent instanceof ICPPASTCompositeTypeSpecifier) {
IndexerOutputWrapper.addIndexEntry(indexer.getOutput(), getFullyQualifiedName(compBinding), ICPPASTCompositeTypeSpecifier parentClass = (ICPPASTCompositeTypeSpecifier) parent;
IndexerOutputWrapper.DERIVED, List friendEntries = new ArrayList();
IIndex.DECLARATION, IASTDeclaration[] members = parentClass.getMembers();
fileNumber, for (int j = 0; j < members.length; j++) {
loc.getNodeOffset(), IASTDeclaration decl = members[j];
loc.getNodeLength(), if (decl instanceof IASTSimpleDeclaration) {
IIndex.OFFSET); IASTSimpleDeclaration simplDecl = (IASTSimpleDeclaration) decl;
} IASTDeclSpecifier declSpec = simplDecl.getDeclSpecifier();
} if (declSpec instanceof ICPPASTElaboratedTypeSpecifier) {
} ICPPASTElaboratedTypeSpecifier elabTypeSpec = (ICPPASTElaboratedTypeSpecifier) declSpec;
// sanity check
if (elabTypeSpec.isFriend()) {
IASTName friendName = elabTypeSpec.getName();
/** for (int i = 0; i < friends.length; i++) {
* @param name IBinding friend = friends[i];
* @param fileNumber if (friend.equals(friendName.resolveBinding())) {
* @param loc int modifiers = IndexVisitorUtil.getModifiers(friendName, friend);
* @param binding
* @throws DOMException NamedEntry namedEntry = new NamedEntry(IIndex.TYPE_FRIEND, IIndex.DECLARATION,
*/ getFullyQualifiedName(friend), modifiers, fileNumber);
private boolean isFriendDeclaration(IASTName name, IBinding binding) throws DOMException { IASTFileLocation fileLoc = IndexEncoderUtil.getFileLocation(friendName);
boolean rc = false; namedEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
if (!name.isDeclaration()) friendEntries.add(namedEntry);
return rc; break;
ASTNodeProperty prop = name.getPropertyInParent();
if (binding instanceof ICompositeType) {
ICompositeType compBinding = (ICompositeType) binding;
int compositeKey = compBinding.getKey();
if (compositeKey == ICPPClassType.k_class || compositeKey == ICompositeType.k_struct) {
if (prop == IASTElaboratedTypeSpecifier.TYPE_NAME) {
IASTElaboratedTypeSpecifier elaboratedTypeSpec = (IASTElaboratedTypeSpecifier) name.getParent();
if (elaboratedTypeSpec instanceof ICPPASTDeclSpecifier) {
ICPPASTDeclSpecifier cppDeclSpec = (ICPPASTDeclSpecifier) elaboratedTypeSpec;
rc = cppDeclSpec.isFriend();
} }
} }
} }
} }
// TODO In case we want to add friend function declarations to index }
// else if (binding instanceof IFunction) { }
// IFunction funBinding = (IFunction) binding; if (friendEntries.size() > 0) {
// if (prop == IASTFunctionDeclarator.DECLARATOR_NAME) { typeEntry.setFriends((IIndexEntry[]) friendEntries.toArray(new IIndexEntry[friendEntries.size()]));
// IASTFunctionDeclarator fDecl = (IASTFunctionDeclarator) name.getParent(); }
// IASTNode fDeclParent = fDecl.getParent(); }
// if (fDeclParent instanceof IASTSimpleDeclaration) { }
// IASTSimpleDeclaration sDecl = (IASTSimpleDeclaration) fDeclParent; }
// IASTDeclSpecifier declSpec = sDecl.getDeclSpecifier(); catch (DOMException e) {
// if (declSpec instanceof ICPPASTSimpleDeclSpecifier) { }
// ICPPASTSimpleDeclSpecifier fDeclSpec = (ICPPASTSimpleDeclSpecifier) declSpec;
// rc = fDeclSpec.isFriend();
// }
// }
// }
// }
return rc;
} }
/** /**

View file

@ -40,6 +40,7 @@ import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.index.IIndex; import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.NamedEntry;
import org.eclipse.cdt.internal.core.index.impl.IndexDelta; import org.eclipse.cdt.internal.core.index.impl.IndexDelta;
import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer; import org.eclipse.cdt.internal.core.index.sourceindexer.AbstractIndexer;
import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer; import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
@ -259,14 +260,9 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
getOutput().addRelatives(fileNumber, include, getOutput().addRelatives(fileNumber, include,
(parent != null) ? parent.getIncludeDirective().getPath() : null); (parent != null) ? parent.getIncludeDirective().getPath() : null);
IndexerOutputWrapper.addIndexEntry(getOutput(), NamedEntry namedEntry = new NamedEntry(IIndex.INCLUDE, IIndex.REFERENCE, new char[][] {include.toCharArray()}, 0, fileNumber);
new char[][] {include.toCharArray()}, namedEntry.setNameOffset(1, 1, IIndex.OFFSET);
IndexerOutputWrapper.INCLUDE, namedEntry.serialize(getOutput());
IIndex.REFERENCE,
fileNumber,
1,
1,
IIndex.OFFSET);
/* See if this file has been encountered before */ /* See if this file has been encountered before */
indexer.haveEncounteredHeader(resourceFile.getProject().getFullPath(), new Path(include), true); indexer.haveEncounteredHeader(resourceFile.getProject().getFullPath(), new Path(include), true);
@ -289,16 +285,11 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
// Get the location // Get the location
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(macro); IASTFileLocation loc = IndexEncoderUtil.getFileLocation(macro);
int fileNumber = IndexEncoderUtil.calculateIndexFlags(this, loc); int fileNumber = IndexEncoderUtil.calculateIndexFlags(this, loc);
IndexerOutputWrapper.addIndexEntry(getOutput(),
new char[][] {macro.toCharArray()},
IndexerOutputWrapper.MACRO,
IIndex.DECLARATION,
fileNumber,
loc.getNodeOffset(),
loc.getNodeLength(),
IIndex.OFFSET);
}
NamedEntry namedEntry = new NamedEntry(IIndex.MACRO, IIndex.DECLARATION, new char[][] {macro.toCharArray()}, 0, fileNumber);
namedEntry.setNameOffset(loc.getNodeOffset(), loc.getNodeLength(), IIndex.OFFSET);
namedEntry.serialize(getOutput());
}
} }
/** /**

View file

@ -0,0 +1,279 @@
/***********************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.index.domsourceindexer;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.internal.core.index.IIndex;
/**
* Utility methods used by both C and C++ visitors
*
* @author vhirsl
*/
public class IndexVisitorUtil {
private IndexVisitorUtil() {}
/**
* @param declSpec
* @return
*/
// static int getModifiers(IASTDeclSpecifier declSpec) {
// int modifiers = 0;
// if (declSpec.isConst()) {
// modifiers |= IIndex.constQualifier;
// }
// else if (declSpec.isVolatile()) {
// modifiers |= IIndex.volatileQualifier;
// }
// if (declSpec.isInline()) {
// modifiers |= IIndex.inlineSpecifier;
// }
// if (declSpec instanceof ICPPASTDeclSpecifier) {
// ICPPASTDeclSpecifier cppDeclSpec = (ICPPASTDeclSpecifier) declSpec;
// if (cppDeclSpec.isExplicit()) {
// modifiers |= IIndex.explicitSpecifier;
// }
// if (cppDeclSpec.isVirtual()) {
// modifiers |= IIndex.virtualSpecifier;
// }
// }
// return modifiers;
// }
/**
* @param variableBinding
* @return
*/
// static int getModifiers(IVariable variableBinding) {
// int modifiers = 0;
// try {
// if (variableBinding.isAuto()) {
// modifiers |= IIndex.autoSpecifier;
// }
// else if (variableBinding.isExtern()) {
// modifiers |= IIndex.externSpecifier;
// }
// else if (variableBinding.isRegister()) {
// modifiers |= IIndex.registerSpecifier;
// }
// else if (variableBinding.isStatic()) {
// modifiers |= IIndex.staticSpecifier;
// }
// if (variableBinding instanceof ICPPVariable) {
// ICPPVariable cppVariable = (ICPPVariable) variableBinding;
// if (cppVariable.isMutable()) {
// modifiers |= IIndex.mutableSpecifier;
// }
// }
// if (variableBinding instanceof ICPPMember) {
// ICPPMember member = (ICPPMember) variableBinding;
// int vis = member.getVisibility();
// if (vis == ICPPMember.v_public) {
// modifiers |= IIndex.publicAccessSpecifier;
// }
// else if (vis == ICPPMember.v_private) {
// modifiers |= IIndex.privateAccessSpecifier;
// }
// else if (vis == ICPPMember.v_protected) {
// modifiers |= IIndex.protectedAccessSpecifier;
// }
// }
// }
// catch (DOMException e) {
// }
// return modifiers;
// }
/**
* @param name
* @param functionBinding
* @return
*/
static int getModifiers(IASTName name, IBinding binding) {
int modifiers = 0;
try {
if (binding instanceof ICPPMember) {
ICPPMember member = (ICPPMember) binding;
int vis = member.getVisibility();
if (vis == ICPPMember.v_public) {
modifiers |= IIndex.publicAccessSpecifier;
}
else if (vis == ICPPMember.v_private) {
modifiers |= IIndex.privateAccessSpecifier;
}
else if (vis == ICPPMember.v_protected) {
modifiers |= IIndex.protectedAccessSpecifier;
}
}
if (binding instanceof ICompositeType ||
binding instanceof IEnumeration) {
IASTNode parent = name.getParent();
if (parent instanceof IASTDeclSpecifier) {
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) parent;
if (declSpec.isConst()) {
modifiers |= IIndex.constQualifier;
}
else if (declSpec.isVolatile()) {
modifiers |= IIndex.volatileQualifier;
}
if (declSpec.isInline()) {
modifiers |= IIndex.inlineSpecifier;
}
if (declSpec instanceof ICPPASTDeclSpecifier) {
ICPPASTDeclSpecifier cppDeclSpec = (ICPPASTDeclSpecifier) declSpec;
if (cppDeclSpec.isExplicit()) {
modifiers |= IIndex.explicitSpecifier;
}
if (cppDeclSpec.isVirtual()) {
modifiers |= IIndex.virtualSpecifier;
}
}
}
}
else if (binding instanceof IVariable) {
IVariable variableBinding = (IVariable) binding;
if (variableBinding.isAuto()) {
modifiers |= IIndex.autoSpecifier;
}
else if (variableBinding.isExtern()) {
modifiers |= IIndex.externSpecifier;
}
else if (variableBinding.isRegister()) {
modifiers |= IIndex.registerSpecifier;
}
else if (variableBinding.isStatic()) {
modifiers |= IIndex.staticSpecifier;
}
if (variableBinding instanceof ICPPVariable) {
ICPPVariable cppVariable = (ICPPVariable) variableBinding;
if (cppVariable.isMutable()) {
modifiers |= IIndex.mutableSpecifier;
}
}
}
else if (binding instanceof IFunction) {
IFunction functionBinding = (IFunction) binding;
if (functionBinding.isAuto()) {
modifiers |= IIndex.autoSpecifier;
}
else if (functionBinding.isExtern()) {
modifiers |= IIndex.externSpecifier;
}
else if (functionBinding.isRegister()) {
modifiers |= IIndex.registerSpecifier;
}
else if (functionBinding.isStatic()) {
modifiers |= IIndex.staticSpecifier;
}
else if (functionBinding.isInline()) {
}
if (functionBinding instanceof ICPPFunction) {
ICPPFunction cppFunction = (ICPPFunction) functionBinding;
if (cppFunction.isMutable()) {
modifiers |= IIndex.mutableSpecifier;
}
if (cppFunction instanceof ICPPMethod) {
ICPPMethod cppMethod = (ICPPMethod) cppFunction;
if (cppMethod.isVirtual()) {
modifiers |= IIndex.virtualSpecifier;
}
if (cppMethod instanceof ICPPConstructor) {
ICPPConstructor constructor = (ICPPConstructor) cppMethod;
if (constructor.isExplicit()) {
modifiers |= IIndex.explicitSpecifier;
}
}
}
}
// check parent node for const, pure virtual and volatile
IASTNode parent = name.getParent();
if (parent instanceof ICPPASTFunctionDeclarator) {
ICPPASTFunctionDeclarator cppFunDecl = (ICPPASTFunctionDeclarator) parent;
if (cppFunDecl.isConst()) {
modifiers |= IIndex.constQualifier;
}
else if (cppFunDecl.isVolatile()) {
modifiers |= IIndex.volatileQualifier;
}
if (cppFunDecl.isPureVirtual()) {
modifiers |= IIndex.pureVirtualSpecifier;
}
}
} // IFunction
}
catch (DOMException e) {
}
return modifiers;
}
/**
* @param function
* @return
*/
static char[][] getParameters(IFunction function) {
List parameterList = new ArrayList();
try {
IFunctionType functionType = function.getType();
IType[] parameterTypes = functionType.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
IType parameterType = parameterTypes[i];
parameterList.add(parameterType.toString().toCharArray());
}
if (parameterList.isEmpty()) {
parameterList.add("void".toCharArray()); //$NON-NLS-1$
}
}
catch (DOMException e) {
}
return (char[][]) parameterList.toArray(new char[parameterList.size()][]);
}
/**
* @param function
* @return
*/
static char[] getReturnType(IFunction function) {
try {
IFunctionType functionType = function.getType();
IType returnType = functionType.getReturnType();
return returnType.toString().toCharArray();
}
catch (DOMException e) {
}
return new char[0];
}
}

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.internal.core.index.TypeEntry;
* (in anticipation that the interface is going to change) * (in anticipation that the interface is going to change)
* *
* @author vhirsl * @author vhirsl
* @deprecated Obsolete with introduction of IIndexEntry hierarchy
*/ */
class IndexerOutputWrapper { class IndexerOutputWrapper {
static class EntryType { static class EntryType {