mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Fix for PR 93786: DOM Indexer adds local variables to the index
Other smaller fixes in DOM Indexer domain.
This commit is contained in:
parent
072e9d936e
commit
30084a7e84
4 changed files with 104 additions and 68 deletions
|
@ -1,3 +1,11 @@
|
|||
2005-06-03 Vladimir Hirsl
|
||||
Fix for PR 93786: DOM Indexer adds local variables to the index
|
||||
Other smaller fixes in DOM Indexer domain.
|
||||
|
||||
* 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/IndexVisitorUtil.java
|
||||
|
||||
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,...)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.index.domsourceindexer;
|
||||
|
||||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
|
@ -24,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IField;
|
|||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
||||
|
@ -31,6 +33,7 @@ import org.eclipse.cdt.internal.core.index.FunctionEntry;
|
|||
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||
import org.eclipse.cdt.internal.core.index.NamedEntry;
|
||||
import org.eclipse.cdt.internal.core.index.TypeEntry;
|
||||
import org.eclipse.cdt.internal.core.model.Util;
|
||||
|
||||
public class CGenerateIndexVisitor extends CASTVisitor {
|
||||
private DOMSourceIndexerRunner indexer;
|
||||
|
@ -70,7 +73,12 @@ public class CGenerateIndexVisitor extends CASTVisitor {
|
|||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
catch (Exception e) {
|
||||
// TODO remove
|
||||
e.printStackTrace();
|
||||
Util.log(e, e.toString(), ICLogConstants.CDT);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -95,6 +103,8 @@ public class CGenerateIndexVisitor extends CASTVisitor {
|
|||
return;
|
||||
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding == null) return;
|
||||
|
||||
// check for IProblemBinding
|
||||
if (binding instanceof IProblemBinding) {
|
||||
IProblemBinding problem = (IProblemBinding) binding;
|
||||
|
@ -126,8 +136,8 @@ public class CGenerateIndexVisitor extends CASTVisitor {
|
|||
*/
|
||||
private void processNameBinding(IASTName name, IBinding binding, IASTFileLocation loc, int fileNumber) throws DOMException {
|
||||
char[][] qualifiedName = getFullyQualifiedName(name);
|
||||
IASTFileLocation fileLoc = IndexEncoderUtil.getFileLocation(name);
|
||||
|
||||
if (qualifiedName == null)
|
||||
return;
|
||||
// determine entryKind
|
||||
int entryKind = IIndex.UNKNOWN;
|
||||
if (name.isDefinition()){
|
||||
|
@ -139,6 +149,9 @@ public class CGenerateIndexVisitor extends CASTVisitor {
|
|||
else if (name.isReference()) {
|
||||
entryKind = IIndex.REFERENCE;
|
||||
}
|
||||
else return;
|
||||
|
||||
IASTFileLocation fileLoc = IndexEncoderUtil.getFileLocation(name);
|
||||
|
||||
// determine type
|
||||
if (binding instanceof ICompositeType) {
|
||||
|
@ -198,16 +211,20 @@ public class CGenerateIndexVisitor extends CASTVisitor {
|
|||
|
||||
indexEntry.serialize(indexer.getOutput());
|
||||
}
|
||||
else if (binding instanceof IParameter ||
|
||||
binding instanceof IVariable) {
|
||||
int modifiers = 0;
|
||||
if (entryKind != IIndex.REFERENCE) {
|
||||
modifiers = IndexVisitorUtil.getModifiers(name, binding);
|
||||
else if (binding instanceof IVariable &&
|
||||
!(binding instanceof IParameter)) {
|
||||
// exclude local variables
|
||||
IScope definingScope = binding.getScope();
|
||||
if (definingScope == name.getTranslationUnit().getScope()) {
|
||||
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());
|
||||
}
|
||||
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 IFunction) {
|
||||
int modifiers = 0;
|
||||
|
@ -217,6 +234,7 @@ public class CGenerateIndexVisitor extends CASTVisitor {
|
|||
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.setReturnType(IndexVisitorUtil.getReturnType((IFunction) binding));
|
||||
|
||||
indexEntry.serialize(indexer.getOutput());
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.domsourceindexer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
|
@ -31,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IField;
|
|||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
|
@ -39,6 +41,7 @@ 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.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||
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.ICPPMethod;
|
||||
|
@ -50,6 +53,7 @@ import org.eclipse.cdt.internal.core.index.IIndex;
|
|||
import org.eclipse.cdt.internal.core.index.IIndexEntry;
|
||||
import org.eclipse.cdt.internal.core.index.NamedEntry;
|
||||
import org.eclipse.cdt.internal.core.index.TypeEntry;
|
||||
import org.eclipse.cdt.internal.core.model.Util;
|
||||
|
||||
public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
||||
private DOMSourceIndexerRunner indexer;
|
||||
|
@ -92,6 +96,11 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// TODO remove
|
||||
e.printStackTrace();
|
||||
Util.log(e, e.toString(), ICLogConstants.CDT);
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -117,6 +126,8 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
return;
|
||||
|
||||
IBinding binding = name.resolveBinding();
|
||||
if (binding == null) return;
|
||||
|
||||
// check for IProblemBinding
|
||||
if (binding instanceof IProblemBinding) {
|
||||
IProblemBinding problem = (IProblemBinding) binding;
|
||||
|
@ -149,8 +160,8 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
*/
|
||||
private void processNameBinding(IASTName name, IBinding binding, IASTFileLocation loc, int fileNumber, int entryKind) throws DOMException {
|
||||
char[][] qualifiedName = getFullyQualifiedName(binding);
|
||||
IASTFileLocation fileLoc = IndexEncoderUtil.getFileLocation(name);
|
||||
|
||||
if (qualifiedName == null)
|
||||
return;
|
||||
// determine entryKind
|
||||
if (entryKind == IIndex.UNKNOWN) {
|
||||
if (name.isDefinition()){
|
||||
|
@ -162,8 +173,11 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
else if (name.isReference()) {
|
||||
entryKind = IIndex.REFERENCE;
|
||||
}
|
||||
else return;
|
||||
}
|
||||
|
||||
IASTFileLocation fileLoc = IndexEncoderUtil.getFileLocation(name);
|
||||
|
||||
// determine type
|
||||
if (binding instanceof ICompositeType) {
|
||||
int iEntryType = 0;
|
||||
|
@ -241,16 +255,20 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
|
||||
indexEntry.serialize(indexer.getOutput());
|
||||
}
|
||||
else if (binding instanceof IParameter ||
|
||||
binding instanceof IVariable) {
|
||||
int modifiers = 0;
|
||||
if (entryKind != IIndex.REFERENCE) {
|
||||
modifiers = IndexVisitorUtil.getModifiers(name, binding);
|
||||
else if (binding instanceof IVariable &&
|
||||
!(binding instanceof IParameter)) {
|
||||
// exclude local variables
|
||||
IScope definingScope = binding.getScope();
|
||||
if (!(definingScope instanceof ICPPBlockScope)) {
|
||||
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());
|
||||
}
|
||||
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) {
|
||||
int modifiers = 0;
|
||||
|
@ -276,6 +294,7 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
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.setReturnType(IndexVisitorUtil.getReturnType((IFunction) binding));
|
||||
|
||||
indexEntry.serialize(indexer.getOutput());
|
||||
// TODO In case we want to add friend function declarations to index
|
||||
|
@ -318,6 +337,9 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
for (int i = 0; i < baseClasses.length; i++) {
|
||||
ICPPBase base = baseClasses[i];
|
||||
ICPPClassType baseClass = baseClasses[i].getBaseClass();
|
||||
// skip problem bindings
|
||||
if (baseClass instanceof IProblemBinding)
|
||||
continue;
|
||||
int modifiers = 0;
|
||||
int vis = base.getVisibility();
|
||||
if (vis == ICPPBase.v_public) {
|
||||
|
@ -366,49 +388,38 @@ public class CPPGenerateIndexVisitor extends CPPASTVisitor {
|
|||
* @param fileNumber
|
||||
*/
|
||||
private void addFriendDeclarations(IASTName name, ICPPClassType cppClassBinding, TypeEntry typeEntry, int fileNumber) {
|
||||
try {
|
||||
IBinding[] friends = cppClassBinding.getFriends();
|
||||
if (friends.length > 0) {
|
||||
IASTNode parent = name.getParent();
|
||||
if (parent instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
ICPPASTCompositeTypeSpecifier parentClass = (ICPPASTCompositeTypeSpecifier) parent;
|
||||
List friendEntries = new ArrayList();
|
||||
IASTDeclaration[] members = parentClass.getMembers();
|
||||
for (int j = 0; j < members.length; j++) {
|
||||
IASTDeclaration decl = members[j];
|
||||
if (decl instanceof IASTSimpleDeclaration) {
|
||||
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++) {
|
||||
IBinding friend = friends[i];
|
||||
if (friend.equals(friendName.resolveBinding())) {
|
||||
int modifiers = IndexVisitorUtil.getModifiers(friendName, friend);
|
||||
|
||||
NamedEntry namedEntry = new NamedEntry(IIndex.TYPE_FRIEND, IIndex.DECLARATION,
|
||||
getFullyQualifiedName(friend), modifiers, fileNumber);
|
||||
IASTFileLocation fileLoc = IndexEncoderUtil.getFileLocation(friendName);
|
||||
namedEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
|
||||
friendEntries.add(namedEntry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
IASTNode parent = name.getParent();
|
||||
if (parent instanceof ICPPASTCompositeTypeSpecifier) {
|
||||
ICPPASTCompositeTypeSpecifier parentClass = (ICPPASTCompositeTypeSpecifier) parent;
|
||||
List friendEntries = new ArrayList();
|
||||
IASTDeclaration[] members = parentClass.getMembers();
|
||||
for (int j = 0; j < members.length; j++) {
|
||||
IASTDeclaration decl = members[j];
|
||||
if (decl instanceof IASTSimpleDeclaration) {
|
||||
IASTSimpleDeclaration simplDecl = (IASTSimpleDeclaration) decl;
|
||||
IASTDeclSpecifier declSpec = simplDecl.getDeclSpecifier();
|
||||
if (declSpec instanceof ICPPASTElaboratedTypeSpecifier) {
|
||||
ICPPASTElaboratedTypeSpecifier elabTypeSpec = (ICPPASTElaboratedTypeSpecifier) declSpec;
|
||||
if (elabTypeSpec.isFriend()) {
|
||||
IASTName friendName = elabTypeSpec.getName();
|
||||
|
||||
IBinding friend = friendName.resolveBinding();
|
||||
if (friend != null && !(friend instanceof IProblemBinding)) {
|
||||
int modifiers = IndexVisitorUtil.getModifiers(friendName, friend);
|
||||
|
||||
NamedEntry namedEntry = new NamedEntry(IIndex.TYPE_FRIEND, IIndex.DECLARATION,
|
||||
getFullyQualifiedName(friend), modifiers, fileNumber);
|
||||
IASTFileLocation fileLoc = IndexEncoderUtil.getFileLocation(friendName);
|
||||
namedEntry.setNameOffset(fileLoc.getNodeOffset(), fileLoc.getNodeLength(), IIndex.OFFSET);
|
||||
friendEntries.add(namedEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (friendEntries.size() > 0) {
|
||||
typeEntry.setFriends((IIndexEntry[]) friendEntries.toArray(new IIndexEntry[friendEntries.size()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (DOMException e) {
|
||||
if (friendEntries.size() > 0) {
|
||||
typeEntry.setFriends((IIndexEntry[]) friendEntries.toArray(new IIndexEntry[friendEntries.size()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.index.domsourceindexer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -196,14 +197,12 @@ public class IndexVisitorUtil {
|
|||
}
|
||||
//For performance reasons, use internal interface if possible, since we know the
|
||||
//index is resolving bindings in order.
|
||||
else if ( (binding instanceof ICPPInternalFunction) ? ((ICPPInternalFunction)functionBinding).isStatic(false)
|
||||
: functionBinding.isStatic() )
|
||||
{
|
||||
else if ((binding instanceof ICPPInternalFunction) ? ((ICPPInternalFunction)functionBinding).isStatic(false)
|
||||
: functionBinding.isStatic()) {
|
||||
modifiers |= IIndex.staticSpecifier;
|
||||
}
|
||||
else if (functionBinding.isInline()) {
|
||||
|
||||
|
||||
modifiers |= IIndex.inlineSpecifier;
|
||||
}
|
||||
if (functionBinding instanceof ICPPFunction) {
|
||||
ICPPFunction cppFunction = (ICPPFunction) functionBinding;
|
||||
|
@ -255,7 +254,7 @@ public class IndexVisitorUtil {
|
|||
IType[] parameterTypes = functionType.getParameterTypes();
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
IType parameterType = parameterTypes[i];
|
||||
parameterList.add(parameterType.toString().toCharArray());
|
||||
parameterList.add(ASTTypeUtil.getType(parameterType).toCharArray());
|
||||
}
|
||||
if (parameterList.isEmpty()) {
|
||||
parameterList.add("void".toCharArray()); //$NON-NLS-1$
|
||||
|
@ -274,7 +273,7 @@ public class IndexVisitorUtil {
|
|||
try {
|
||||
IFunctionType functionType = function.getType();
|
||||
IType returnType = functionType.getReturnType();
|
||||
return returnType.toString().toCharArray();
|
||||
return ASTTypeUtil.getType(returnType).toCharArray();
|
||||
}
|
||||
catch (DOMException e) {
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue