mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 06:45:43 +02:00
Refactoring for the DOM Indexer to use new IIndexEntry encoding
This commit is contained in:
parent
86baacedc8
commit
3720c60ebd
6 changed files with 203 additions and 118 deletions
|
@ -13,8 +13,8 @@ package org.eclipse.cdt.internal.core.index;
|
|||
|
||||
public class FunctionEntry extends NamedEntry implements IFunctionEntry {
|
||||
|
||||
|
||||
char[][] signature;
|
||||
char[] returnString;
|
||||
|
||||
public FunctionEntry(int metakind, int entry_type, char[][] fullName, int modifiers,int fileNumber){
|
||||
super(metakind,entry_type,fullName, modifiers, fileNumber);
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
* Generic indexer query interface to allow for queries of any existing indexer storage mechanism
|
||||
* To be considered in development.
|
||||
* @author bgheorgh
|
||||
* @since 3.0
|
||||
*/
|
||||
public interface IIndexQuery {
|
||||
|
||||
/**
|
||||
* Metakind bit field constants
|
||||
*/
|
||||
final static int CLASS = 1;
|
||||
final static int STRUCT = 2;
|
||||
final static int UNION = 4;
|
||||
final static int ENUM = 8;
|
||||
final static int VAR = 16;
|
||||
final static int TYPEDEF = 32;
|
||||
final static int FUNCTION = 64;
|
||||
final static int METHOD = 128;
|
||||
final static int FIELD = 256;
|
||||
final static int MACRO = 512;
|
||||
final static int NAMESPACE = 1024;
|
||||
final static int ENUMTOR = 2048;
|
||||
final static int INCLUDE = 4096;
|
||||
|
||||
/**
|
||||
* Type bit field
|
||||
*/
|
||||
final static int DECLARATION = 1;
|
||||
final static int DEFINITION = 2;
|
||||
final static int REFERENCE= 4;
|
||||
|
||||
/**
|
||||
* Returns the entries in the index corresponding to the passed in:
|
||||
*
|
||||
* @param metakind - bit field that indicates the kinds to retrieve
|
||||
* @param type - bit field that indiciates what type of kinds to look for
|
||||
* @param pattern - String array that contains the elements of a pattern;
|
||||
* the interpretation of this array is left up to the implementor; can be left null
|
||||
* in which case a match is attempted based on the metakind and type fields
|
||||
* @param path - an IPath array that is used to limit the query; can be null to indicate
|
||||
* entire workspace
|
||||
*
|
||||
* @return IIndexEntry
|
||||
*/
|
||||
IIndexEntry[] getIndexEntries(int metakind, int type, String[] pattern, IPath[] paths);
|
||||
|
||||
/**
|
||||
* Returns the entries in the index corresponding to the passed in:
|
||||
*
|
||||
* @param metakind - bit field that indicates the kinds to retrieve
|
||||
* @param type - bit field that indiciates what type of kinds to look for
|
||||
* @param pattern - String array that contains the elements of a pattern;
|
||||
* the interpretation of this array is left up to the implementor; can be left null
|
||||
* in which case a match is attempted based on the metakind and type fields
|
||||
* @param projects - an IProject array that contains the projects that are to be queried
|
||||
*
|
||||
* @return IIndexEntry
|
||||
*/
|
||||
IIndexEntry[] getIndexEntries(int metakind, int type, String[] pattern, IProject[] projects);
|
||||
|
||||
/**
|
||||
* Returns the entries in the index corresponding to the passed in:
|
||||
*
|
||||
* @param metakind - bit field that indicates the kinds to retrieve
|
||||
* @param type - bit field that indiciates what type of kinds to look for
|
||||
* @param pattern - String array that contains the elements of a pattern;
|
||||
* the interpretation of this array is left up to the implementor; can be left null
|
||||
* in which case a match is attempted based on the metakind and type fields
|
||||
* @param projects - an IProject array that contains the projects that are to be queried
|
||||
* @param additionalPaths - an array for additional paths to query
|
||||
*
|
||||
* @return IIndexEntry
|
||||
*/
|
||||
IIndexEntry[] getIndexEntries(int metakind, int type, String[] pattern, IProject[] projects, IPath[] additionalPaths);
|
||||
|
||||
}
|
|
@ -156,26 +156,26 @@ public class CGenerateIndexVisitor extends CASTVisitor {
|
|||
entryType = IndexerOutputWrapper.FUNCTION;
|
||||
|
||||
if (entryType != null) {
|
||||
int entryKind=0;
|
||||
if (name.isDeclaration()) {
|
||||
IndexerOutputWrapper.addNameDecl(indexer.getOutput(),
|
||||
getFullyQualifiedName(name),
|
||||
entryType,
|
||||
fileNumber,
|
||||
loc.getNodeOffset(),
|
||||
loc.getNodeLength(),
|
||||
IIndex.OFFSET);
|
||||
}
|
||||
entryKind=IIndex.DECLARATION;
|
||||
}/* else if (name.isDefinition()){
|
||||
entryKind=IIndex.DEFINITION;
|
||||
}*/
|
||||
else if (name.isReference()) {
|
||||
IndexerOutputWrapper.addNameRef(indexer.getOutput(),
|
||||
entryKind=IIndex.REFERENCE;
|
||||
}
|
||||
|
||||
IndexerOutputWrapper.addIndexEntry(indexer.getOutput(),
|
||||
getFullyQualifiedName(name),
|
||||
entryType,
|
||||
entryKind,
|
||||
fileNumber,
|
||||
loc.getNodeOffset(),
|
||||
loc.getNodeLength(),
|
||||
IIndex.OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
|
|
|
@ -143,6 +143,9 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
if (name.isDeclaration()) {
|
||||
limitTo = ICSearchConstants.DECLARATIONS;
|
||||
}
|
||||
else if (name.isDefinition()){
|
||||
limitTo = ICSearchConstants.DEFINITIONS;
|
||||
}
|
||||
else if (name.isReference()) {
|
||||
limitTo = ICSearchConstants.REFERENCES;
|
||||
}
|
||||
|
@ -217,24 +220,26 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
}
|
||||
|
||||
if (entryType != null) {
|
||||
int entryKind =0;
|
||||
if (limitTo == ICSearchConstants.DECLARATIONS) {
|
||||
IndexerOutputWrapper.addNameDecl(indexer.getOutput(),
|
||||
getFullyQualifiedName(binding),
|
||||
entryType,
|
||||
fileNumber,
|
||||
loc.getNodeOffset(),
|
||||
loc.getNodeLength(),
|
||||
IIndex.OFFSET);
|
||||
entryKind = IIndex.DECLARATION;
|
||||
}
|
||||
/*else if (limitTo == ICSearchConstants.DEFINITIONS) {
|
||||
entryKind = IIndex.DEFINITION;
|
||||
}*/
|
||||
else if (limitTo == ICSearchConstants.REFERENCES) {
|
||||
IndexerOutputWrapper.addNameRef(indexer.getOutput(),
|
||||
entryKind = IIndex.REFERENCE;
|
||||
}
|
||||
|
||||
IndexerOutputWrapper.addIndexEntry(indexer.getOutput(),
|
||||
getFullyQualifiedName(binding),
|
||||
entryType,
|
||||
entryKind,
|
||||
fileNumber,
|
||||
loc.getNodeOffset(),
|
||||
loc.getNodeLength(),
|
||||
IIndex.OFFSET);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,8 +256,9 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
if (compositeKey == ICPPClassType.k_class || compositeKey == ICompositeType.k_struct) {
|
||||
if (prop == ICPPASTBaseSpecifier.NAME) {
|
||||
// base class
|
||||
IndexerOutputWrapper.addNameDecl(indexer.getOutput(), getFullyQualifiedName(compBinding),
|
||||
IndexerOutputWrapper.addIndexEntry(indexer.getOutput(), getFullyQualifiedName(compBinding),
|
||||
IndexerOutputWrapper.DERIVED,
|
||||
IIndex.DECLARATION,
|
||||
fileNumber,
|
||||
loc.getNodeOffset(),
|
||||
loc.getNodeLength(),
|
||||
|
|
|
@ -259,9 +259,10 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
|
|||
getOutput().addRelatives(fileNumber, include,
|
||||
(parent != null) ? parent.getIncludeDirective().getPath() : null);
|
||||
|
||||
IndexerOutputWrapper.addNameRef(getOutput(),
|
||||
IndexerOutputWrapper.addIndexEntry(getOutput(),
|
||||
new char[][] {include.toCharArray()},
|
||||
IndexerOutputWrapper.INCLUDE,
|
||||
IIndex.REFERENCE,
|
||||
fileNumber,
|
||||
1,
|
||||
1,
|
||||
|
@ -288,9 +289,10 @@ public class DOMSourceIndexerRunner extends AbstractIndexer {
|
|||
// Get the location
|
||||
IASTFileLocation loc = IndexEncoderUtil.getFileLocation(macro);
|
||||
int fileNumber = IndexEncoderUtil.calculateIndexFlags(this, loc);
|
||||
IndexerOutputWrapper.addNameDecl(getOutput(),
|
||||
IndexerOutputWrapper.addIndexEntry(getOutput(),
|
||||
new char[][] {macro.toCharArray()},
|
||||
IndexerOutputWrapper.MACRO,
|
||||
IIndex.DECLARATION,
|
||||
fileNumber,
|
||||
loc.getNodeOffset(),
|
||||
loc.getNodeLength(),
|
||||
|
|
|
@ -10,7 +10,11 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index.domsourceindexer;
|
||||
|
||||
import org.eclipse.cdt.internal.core.index.FunctionEntry;
|
||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexerOutput;
|
||||
import org.eclipse.cdt.internal.core.index.NamedEntry;
|
||||
import org.eclipse.cdt.internal.core.index.TypeEntry;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -74,9 +78,10 @@ class IndexerOutputWrapper {
|
|||
private IndexerOutputWrapper() {
|
||||
}
|
||||
|
||||
static void addNameDecl(IIndexerOutput indexerOutput,
|
||||
static void addIndexEntry (IIndexerOutput indexerOutput,
|
||||
char[][] name,
|
||||
EntryType entryType,
|
||||
int entryKind,
|
||||
int fileNumber,
|
||||
int offset,
|
||||
int length,
|
||||
|
@ -84,123 +89,103 @@ class IndexerOutputWrapper {
|
|||
//TODO temporary until all bindings are completed
|
||||
if (name == null)
|
||||
name = new char[][] {"NPE".toCharArray()}; //$NON-NLS-1$
|
||||
|
||||
TypeEntry typeEntry;
|
||||
NamedEntry namedEntry;
|
||||
FunctionEntry functionEntry;
|
||||
|
||||
switch (entryType.toInt()) {
|
||||
case CLASS_CONST:
|
||||
indexerOutput.addClassDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_CLASS,entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
//typeEntry.setBaseTypes(getInherits());
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case STRUCT_CONST:
|
||||
indexerOutput.addStructDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_STRUCT,entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
//typeEntry.setBaseTypes(getInherits());
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case UNION_CONST:
|
||||
indexerOutput.addUnionDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_UNION,entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
//typeEntry.setBaseTypes(getInherits());
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case ENUM_CONST:
|
||||
indexerOutput.addEnumDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_ENUM ,entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case VAR_CONST:
|
||||
indexerOutput.addVariableDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_VAR ,entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case TYPEDEF_CONST:
|
||||
indexerOutput.addTypedefDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_TYPEDEF, entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case DERIVED_CONST:
|
||||
indexerOutput.addDerivedDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_DERIVED ,entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case FRIEND_CONST:
|
||||
indexerOutput.addFriendDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_FRIEND ,entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case FWD_CLASS_CONST:
|
||||
indexerOutput.addFwd_ClassDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_FWD_CLASS ,entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case FWD_STRUCT_CONST:
|
||||
indexerOutput.addFwd_StructDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_FWD_STRUCT ,entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case FWD_UNION_CONST:
|
||||
indexerOutput.addFwd_UnionDecl(fileNumber, name, offset, length, offsetType);
|
||||
typeEntry = new TypeEntry(IIndex.TYPE_FWD_UNION ,entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
typeEntry.setNameOffset(offset, length, offsetType);
|
||||
typeEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case NAMESPACE_CONST:
|
||||
indexerOutput.addNamespaceDecl(fileNumber, name, offset, length, offsetType);
|
||||
namedEntry = new NamedEntry(IIndex.NAMESPACE, entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
namedEntry.setNameOffset(offset, length, offsetType);
|
||||
namedEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case ENUMERATOR_CONST:
|
||||
indexerOutput.addEnumtorDecl(fileNumber, name, offset, length, offsetType);
|
||||
namedEntry = new NamedEntry(IIndex.ENUMTOR, entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
namedEntry.setNameOffset(offset, length, offsetType);
|
||||
namedEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case FIELD_CONST:
|
||||
indexerOutput.addFieldDecl(fileNumber, name, offset, length, offsetType);
|
||||
namedEntry = new NamedEntry(IIndex.FIELD, entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
namedEntry.setNameOffset(offset, length, offsetType);
|
||||
namedEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case METHOD_CONST:
|
||||
indexerOutput.addMethodDecl(fileNumber, name, offset, length, offsetType);
|
||||
functionEntry = new FunctionEntry(IIndex.METHOD, entryKind,name,0 /*getModifiers()*/, fileNumber);
|
||||
//funEntry.setSignature(getFunctionSignature());
|
||||
functionEntry.setNameOffset(offset, length, offsetType);
|
||||
functionEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case FUNCTION_CONST:
|
||||
indexerOutput.addFunctionDecl(fileNumber, name, offset, length, offsetType);
|
||||
functionEntry = new FunctionEntry(IIndex.FUNCTION, entryKind,name,0 /*getModifiers()*/, fileNumber);
|
||||
//funEntry.setSignature(getFunctionSignature());
|
||||
functionEntry.setNameOffset(offset, length, offsetType);
|
||||
functionEntry.serialize(indexerOutput);
|
||||
break;
|
||||
case MACRO_CONST:
|
||||
indexerOutput.addMacroDecl(fileNumber, name, offset, length, offsetType);
|
||||
namedEntry = new NamedEntry(IIndex.MACRO, entryKind, name, 0 /*getModifiers()*/, fileNumber);
|
||||
namedEntry.setNameOffset(offset, length, offsetType);
|
||||
namedEntry.serialize(indexerOutput);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void addNameRef(IIndexerOutput indexerOutput,
|
||||
char[][] name,
|
||||
EntryType entryType,
|
||||
int fileNumber,
|
||||
int offset,
|
||||
int length,
|
||||
int offsetType) {
|
||||
//TODO temporary until all bindings are completed
|
||||
if (name == null)
|
||||
name = new char[][] {"NPE".toCharArray()}; //$NON-NLS-1$
|
||||
switch (entryType.toInt()) {
|
||||
case CLASS_CONST:
|
||||
indexerOutput.addClassRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case STRUCT_CONST:
|
||||
indexerOutput.addStructRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case UNION_CONST:
|
||||
indexerOutput.addUnionRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case ENUM_CONST:
|
||||
indexerOutput.addEnumRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case VAR_CONST:
|
||||
indexerOutput.addVariableRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case TYPEDEF_CONST:
|
||||
indexerOutput.addTypedefRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case DERIVED_CONST:
|
||||
indexerOutput.addDerivedRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case FRIEND_CONST:
|
||||
indexerOutput.addFriendRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case FWD_CLASS_CONST:
|
||||
indexerOutput.addFwd_ClassRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case FWD_STRUCT_CONST:
|
||||
indexerOutput.addFwd_StructRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case FWD_UNION_CONST:
|
||||
indexerOutput.addFwd_UnionRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case NAMESPACE_CONST:
|
||||
indexerOutput.addNamespaceRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case ENUMERATOR_CONST:
|
||||
indexerOutput.addEnumtorRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case FIELD_CONST:
|
||||
indexerOutput.addFieldRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case METHOD_CONST:
|
||||
indexerOutput.addMethodRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case FUNCTION_CONST:
|
||||
indexerOutput.addFunctionRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
case INCLUDE_CONST:
|
||||
indexerOutput.addIncludeRef(fileNumber, name, offset, length, offsetType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue