1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-16 13:35:22 +02:00

Fix for Bug 59493: need to refine index query for open-type (2.0 Stream)

This commit is contained in:
Bogdan Gheorghe 2004-08-11 20:05:35 +00:00
parent 16258395c2
commit 4fd44238b9
12 changed files with 509 additions and 418 deletions

View file

@ -1,3 +1,6 @@
2004-08-11 Bogdan Gheorghe
Modified indexer test to work with new forward declaration encoding.
2004-08-03 Bogdan Gheorghe 2004-08-03 Bogdan Gheorghe
Updated indexer and dependency tests to work for indexing standalone headers Updated indexer and dependency tests to work for indexing standalone headers

View file

@ -425,7 +425,7 @@ public class IndexManagerTests extends TestCase {
IIndex ind = indexManager.getIndex(testProjectPath,true,true); IIndex ind = indexManager.getIndex(testProjectPath,true,true);
assertTrue("Index exists for project",ind != null); assertTrue("Index exists for project",ind != null);
String [] typeRefEntryResultModel ={"EntryResult: word=typeRef/C/C/B/A, refs={ 1 }", "EntryResult: word=typeRef/C/ForwardA/A, refs={ 1 }", "EntryResult: word=typeRef/E/e1/B/A, refs={ 1 }", "EntryResult: word=typeRef/V/x/B/A, refs={ 1 }"}; String [] typeRefEntryResultModel ={"EntryResult: word=typeRef/C/C/B/A, refs={ 1 }", "EntryResult: word=typeRef/E/e1/B/A, refs={ 1 }", "EntryResult: word=typeRef/G/ForwardA/A, refs={ 1 }", "EntryResult: word=typeRef/V/x/B/A, refs={ 1 }"};
IEntryResult[] typerefresults = ind.queryEntries(IIndexConstants.TYPE_REF); IEntryResult[] typerefresults = ind.queryEntries(IIndexConstants.TYPE_REF);
assertTrue("Entry exists",typerefresults != null); assertTrue("Entry exists",typerefresults != null);
@ -558,10 +558,10 @@ public class IndexManagerTests extends TestCase {
assertTrue("Index exists for project",ind != null); assertTrue("Index exists for project",ind != null);
//IEntryResult[] fwdDclResults = ind.queryEntries("typeDecl/C/ForwardA/A".toCharArray()); //IEntryResult[] fwdDclResults = ind.queryEntries("typeDecl/C/ForwardA/A".toCharArray());
IEntryResult[] fwdDclResults = ind.queryEntries("typeDecl/C/ForwardA/A".toCharArray()); IEntryResult[] fwdDclResults = ind.queryEntries("typeDecl/G/ForwardA/A".toCharArray());
assertTrue("Entry exists",fwdDclResults != null); assertTrue("Entry exists",fwdDclResults != null);
String [] fwdDclModel = {"EntryResult: word=typeDecl/C/ForwardA/A, refs={ 1 }"}; String [] fwdDclModel = {"EntryResult: word=typeDecl/G/ForwardA/A, refs={ 1 }"};
if (fwdDclResults.length != fwdDclModel.length) if (fwdDclResults.length != fwdDclModel.length)
fail("Entry Result length different from model for forward declarations"); fail("Entry Result length different from model for forward declarations");
@ -571,10 +571,10 @@ public class IndexManagerTests extends TestCase {
assertEquals(fwdDclModel[i],fwdDclResults[i].toString()); assertEquals(fwdDclModel[i],fwdDclResults[i].toString());
} }
IEntryResult[] fwdDclRefResults = ind.queryEntries("typeRef/C/ForwardA/A".toCharArray()); IEntryResult[] fwdDclRefResults = ind.queryEntries("typeRef/G/ForwardA/A".toCharArray());
assertTrue("Entry exists", fwdDclRefResults!= null); assertTrue("Entry exists", fwdDclRefResults!= null);
String [] fwdDclRefModel = {"EntryResult: word=typeRef/C/ForwardA/A, refs={ 1 }"}; String [] fwdDclRefModel = {"EntryResult: word=typeRef/G/ForwardA/A, refs={ 1 }"};
if (fwdDclRefResults.length != fwdDclRefModel.length) if (fwdDclRefResults.length != fwdDclRefModel.length)
fail("Entry Result length different from model for forward declarations refs"); fail("Entry Result length different from model for forward declarations refs");

View file

@ -1,3 +1,10 @@
2004-08-11 Bogdan Gheorghe
Fix for Bug 59493: need to refine index query for open-type
* index/org/eclipse/cdt/internal/core/search/indexing/AbstractIndexer.java
* index/org/eclipse/cdt/internal/core/search/indexing/IIndexConstants.java
* index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexerRequestor.java
2004-08-03 Bogdan Gheorghe 2004-08-03 Bogdan Gheorghe
Fix for Bug 60948: Indexer should pick up all headers in include path Fix for Bug 60948: Indexer should pick up all headers in include path

View file

@ -51,6 +51,9 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
final static int TYPEDEF = 6; final static int TYPEDEF = 6;
final static int DERIVED = 7; final static int DERIVED = 7;
final static int FRIEND = 8; final static int FRIEND = 8;
final static int FWD_CLASS = 9;
final static int FWD_STRUCT = 10;
final static int FWD_UNION = 11;
public static boolean VERBOSE = false; public static boolean VERBOSE = false;
@ -241,15 +244,15 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
public void addElaboratedForwardDeclaration(IASTElaboratedTypeSpecifier elaboratedType) { public void addElaboratedForwardDeclaration(IASTElaboratedTypeSpecifier elaboratedType) {
if (elaboratedType.getClassKind().equals(ASTClassKind.CLASS)) if (elaboratedType.getClassKind().equals(ASTClassKind.CLASS))
{ {
this.output.addRef(encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),CLASS, ICSearchConstants.DECLARATIONS)); this.output.addRef(encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_CLASS, ICSearchConstants.DECLARATIONS));
} }
else if (elaboratedType.getClassKind().equals(ASTClassKind.STRUCT)) else if (elaboratedType.getClassKind().equals(ASTClassKind.STRUCT))
{ {
this.output.addRef(encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),STRUCT, ICSearchConstants.DECLARATIONS)); this.output.addRef(encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_STRUCT, ICSearchConstants.DECLARATIONS));
} }
else if (elaboratedType.getClassKind().equals(ASTClassKind.UNION)) else if (elaboratedType.getClassKind().equals(ASTClassKind.UNION))
{ {
this.output.addRef(encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),UNION, ICSearchConstants.DECLARATIONS)); this.output.addRef(encodeTypeEntry(elaboratedType.getFullyQualifiedNameCharArrays(),FWD_UNION, ICSearchConstants.DECLARATIONS));
} }
} }
@ -336,6 +339,32 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
this.output.addRef(encodeTypeEntry(fullyQualifiedName,UNION,ICSearchConstants.REFERENCES)); this.output.addRef(encodeTypeEntry(fullyQualifiedName,UNION,ICSearchConstants.REFERENCES));
} }
} }
public void addForwardClassReference(IASTTypeSpecifier reference){
char[][] fullyQualifiedName = null;
ASTClassKind classKind = null;
if (reference instanceof IASTElaboratedTypeSpecifier){
IASTElaboratedTypeSpecifier typeRef = (IASTElaboratedTypeSpecifier) reference;
fullyQualifiedName = typeRef.getFullyQualifiedNameCharArrays();
classKind = typeRef.getClassKind();
}
if (classKind == null)
return;
if (classKind.equals(ASTClassKind.CLASS))
{
this.output.addRef(encodeTypeEntry(fullyQualifiedName,FWD_CLASS, ICSearchConstants.REFERENCES));
}
else if (classKind.equals(ASTClassKind.STRUCT))
{
this.output.addRef(encodeTypeEntry(fullyQualifiedName,FWD_STRUCT,ICSearchConstants.REFERENCES));
}
else if (classKind.equals(ASTClassKind.UNION))
{
this.output.addRef(encodeTypeEntry(fullyQualifiedName,FWD_UNION,ICSearchConstants.REFERENCES));
}
}
/** /**
* Type entries are encoded as follow: 'typeDecl/' ('C' | 'S' | 'U' | 'E' ) '/' TypeName ['/' Qualifier]* * Type entries are encoded as follow: 'typeDecl/' ('C' | 'S' | 'U' | 'E' ) '/' TypeName ['/' Qualifier]*
*/ */
@ -391,6 +420,18 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
case(FRIEND): case(FRIEND):
result[pos++]=FRIEND_SUFFIX; result[pos++]=FRIEND_SUFFIX;
break; break;
case(FWD_CLASS):
result[pos++]=FWD_CLASS_SUFFIX;
break;
case (FWD_STRUCT):
result[pos++]=FWD_STRUCT_SUFFIX;
break;
case (FWD_UNION):
result[pos++]=FWD_UNION_SUFFIX;
break;
} }
result[pos++] = SEPARATOR; result[pos++] = SEPARATOR;
//Encode in the following manner //Encode in the following manner
@ -509,6 +550,12 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
classType = DERIVED_SUFFIX; classType = DERIVED_SUFFIX;
} else if ( searchFor == ICSearchConstants.FRIEND){ } else if ( searchFor == ICSearchConstants.FRIEND){
classType = FRIEND_SUFFIX; classType = FRIEND_SUFFIX;
} else if ( searchFor == ICSearchConstants.FWD_CLASS) {
classType = FWD_CLASS_SUFFIX;
} else if ( searchFor == ICSearchConstants.FWD_STRUCT) {
classType = FWD_STRUCT_SUFFIX;
} else if ( searchFor == ICSearchConstants.FWD_UNION) {
classType = FWD_UNION_SUFFIX;
} else { } else {
//could be TYPE or CLASS_STRUCT, best we can do for these is the prefix //could be TYPE or CLASS_STRUCT, best we can do for these is the prefix
return prefix; return prefix;

View file

@ -105,6 +105,9 @@ public interface IIndexConstants {
char TYPEDEF_SUFFIX = 'T'; char TYPEDEF_SUFFIX = 'T';
char DERIVED_SUFFIX = 'D'; char DERIVED_SUFFIX = 'D';
char FRIEND_SUFFIX = 'F'; char FRIEND_SUFFIX = 'F';
char FWD_CLASS_SUFFIX = 'G';
char FWD_STRUCT_SUFFIX = 'H';
char FWD_UNION_SUFFIX = 'I';
char TYPE_SUFFIX = 0; char TYPE_SUFFIX = 0;
char SEPARATOR= '/'; char SEPARATOR= '/';

View file

@ -364,7 +364,7 @@ public class SourceIndexerRequestor implements ISourceElementRequestor, IIndexCo
indexer.addClassReference((IASTClassSpecifier)reference.getReferencedElement()); indexer.addClassReference((IASTClassSpecifier)reference.getReferencedElement());
else if (reference.getReferencedElement() instanceof IASTElaboratedTypeSpecifier) else if (reference.getReferencedElement() instanceof IASTElaboratedTypeSpecifier)
{ {
indexer.addClassReference((IASTTypeSpecifier) reference.getReferencedElement()); indexer.addForwardClassReference((IASTTypeSpecifier) reference.getReferencedElement());
} }
} }

View file

@ -1,3 +1,12 @@
2004-08-11 Bogdan Gheorghe
Fix for Bug 59493: need to refine index query for open-type
* search/org/eclipse/cdt/internal/core/search/ICSearchConstants.java
* search/org/eclipse/cdt/internal/core/search/matching/ClassDeclarationPattern.java
* search/org/eclipse/cdt/internal/core/search/matching/CSearchPattern.java
* search/org/eclipse/cdt/internal/core/search/matching/DerivedTypesPattern.java
* search/org/eclipse/cdt/internal/core/search/matching/FriendPattern.java
2004-06-25 Bogdan Gheorghe 2004-06-25 Bogdan Gheorghe
Indirect fix for Bug 65551: [Search] Search for Variable references should not include parameters Indirect fix for Bug 65551: [Search] Search for Variable references should not include parameters
Instead of excluding parameter references from searches, added parm declarations to the index (for Instead of excluding parameter references from searches, added parm declarations to the index (for

View file

@ -107,6 +107,12 @@ public interface ICSearchConstants {
public static final SearchFor FRIEND = new SearchFor( 16 ); public static final SearchFor FRIEND = new SearchFor( 16 );
public static final SearchFor FWD_CLASS = new SearchFor ( 17 );
public static final SearchFor FWD_STRUCT = new SearchFor ( 18 );
public static final SearchFor FWD_UNION = new SearchFor ( 19 );
/* Nature of match */ /* Nature of match */
/** /**

View file

@ -110,6 +110,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
CSearchPattern pattern = null; CSearchPattern pattern = null;
if( searchFor == TYPE || searchFor == CLASS || searchFor == STRUCT || if( searchFor == TYPE || searchFor == CLASS || searchFor == STRUCT ||
searchFor == FWD_CLASS || searchFor == FWD_STRUCT || searchFor == FWD_UNION ||
searchFor == ENUM || searchFor == UNION || searchFor == CLASS_STRUCT || searchFor == ENUM || searchFor == UNION || searchFor == CLASS_STRUCT ||
searchFor == TYPEDEF ) searchFor == TYPEDEF )
{ {
@ -344,6 +345,11 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
return orPattern; return orPattern;
} }
boolean isForward = false;
if (searchFor == FWD_CLASS || searchFor == FWD_STRUCT || searchFor == FWD_UNION){
isForward = true;
}
char [] patternArray = patternString.toCharArray(); char [] patternArray = patternString.toCharArray();
IScanner scanner =null; IScanner scanner =null;
@ -393,7 +399,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
char[] name = (char [])list.removeLast(); char[] name = (char [])list.removeLast();
char [][] qualifications = new char[0][]; char [][] qualifications = new char[0][];
return new ClassDeclarationPattern( name, (char[][])list.toArray( qualifications ), searchFor, limitTo, matchMode, caseSensitive ); return new ClassDeclarationPattern( name, (char[][])list.toArray( qualifications ), searchFor, limitTo, matchMode, caseSensitive, isForward );
} }

View file

@ -42,9 +42,10 @@ public class ClassDeclarationPattern extends CSearchPattern {
// super( matchMode, caseSensitive, DECLARATIONS ); // super( matchMode, caseSensitive, DECLARATIONS );
// } // }
public ClassDeclarationPattern( char[] name, char[][] containers, SearchFor searchFor, LimitTo limit, int mode, boolean caseSensitive ){ public ClassDeclarationPattern( char[] name, char[][] containers, SearchFor searchFor, LimitTo limit, int mode, boolean caseSensitive, boolean isForward ){
super( mode, caseSensitive, limit ); super( mode, caseSensitive, limit );
this.isForward = isForward;
simpleName = caseSensitive ? name : CharOperation.toLowerCase( name ); simpleName = caseSensitive ? name : CharOperation.toLowerCase( name );
if( caseSensitive || containers == null ){ if( caseSensitive || containers == null ){
qualifications = containers; qualifications = containers;
@ -58,13 +59,13 @@ public class ClassDeclarationPattern extends CSearchPattern {
this.searchFor = searchFor; this.searchFor = searchFor;
if( searchFor == CLASS ){ if( searchFor == CLASS || searchFor == FWD_CLASS ){
classKind = ASTClassKind.CLASS; classKind = ASTClassKind.CLASS;
} else if( searchFor == STRUCT ) { } else if( searchFor == STRUCT || searchFor == FWD_STRUCT) {
classKind = ASTClassKind.STRUCT; classKind = ASTClassKind.STRUCT;
} else if ( searchFor == ENUM ) { } else if ( searchFor == ENUM ) {
classKind = ASTClassKind.ENUM; classKind = ASTClassKind.ENUM;
} else if ( searchFor == UNION ) { } else if ( searchFor == UNION || searchFor == FWD_UNION ) {
classKind = ASTClassKind.UNION; classKind = ASTClassKind.UNION;
} else { } else {
classKind = null; classKind = null;
@ -86,6 +87,11 @@ public class ClassDeclarationPattern extends CSearchPattern {
if( ! canAccept( limit ) ) if( ! canAccept( limit ) )
return IMPOSSIBLE_MATCH; return IMPOSSIBLE_MATCH;
if ((node instanceof IASTElaboratedTypeSpecifier &&!isForward)||
(node instanceof IASTClassSpecifier && isForward)){
return IMPOSSIBLE_MATCH;
}
char[] nodeName = null; char[] nodeName = null;
if (node instanceof IASTElaboratedTypeSpecifier) if (node instanceof IASTElaboratedTypeSpecifier)
{ {
@ -145,6 +151,7 @@ public class ClassDeclarationPattern extends CSearchPattern {
protected char[] decodedSimpleName; protected char[] decodedSimpleName;
private char[][] decodedContainingTypes; private char[][] decodedContainingTypes;
protected char decodedType; protected char decodedType;
protected boolean isForward;
public void feedIndexRequestor(IIndexSearchRequestor requestor, int detailLevel, int[] references, IndexInput input, ICSearchScope scope) throws IOException { public void feedIndexRequestor(IIndexSearchRequestor requestor, int detailLevel, int[] references, IndexInput input, ICSearchScope scope) throws IOException {
@ -213,15 +220,18 @@ public class ClassDeclarationPattern extends CSearchPattern {
return false; return false;
} }
} else if( classKind == ASTClassKind.CLASS ) { } else if( classKind == ASTClassKind.CLASS ) {
if( decodedType != CLASS_SUFFIX ){ if( decodedType != CLASS_SUFFIX &&
decodedType != FWD_CLASS_SUFFIX){
return false; return false;
} }
} else if ( classKind == ASTClassKind.STRUCT ) { } else if ( classKind == ASTClassKind.STRUCT ) {
if( decodedType != STRUCT_SUFFIX ){ if( decodedType != STRUCT_SUFFIX &&
decodedType != FWD_STRUCT_SUFFIX){
return false; return false;
} }
} else if ( classKind == ASTClassKind.UNION ) { } else if ( classKind == ASTClassKind.UNION ) {
if( decodedType != UNION_SUFFIX ){ if( decodedType != UNION_SUFFIX &&
decodedType != FWD_UNION_SUFFIX){
return false; return false;
} }
} else if ( classKind == ASTClassKind.ENUM ) { } else if ( classKind == ASTClassKind.ENUM ) {

View file

@ -42,7 +42,7 @@ public class DerivedTypesPattern extends ClassDeclarationPattern {
* @param caseSensitive * @param caseSensitive
*/ */
public DerivedTypesPattern(char[] name, char[][] containers, SearchFor searchFor, LimitTo limit, int mode, boolean caseSensitive) { public DerivedTypesPattern(char[] name, char[][] containers, SearchFor searchFor, LimitTo limit, int mode, boolean caseSensitive) {
super(name, containers, searchFor, limit, mode, caseSensitive); super(name, containers, searchFor, limit, mode, caseSensitive, false);
} }
public char[] indexEntryPrefix() { public char[] indexEntryPrefix() {

View file

@ -41,7 +41,7 @@ public class FriendPattern extends ClassDeclarationPattern {
* @param caseSensitive * @param caseSensitive
*/ */
public FriendPattern(char[] name, char[][] containers, SearchFor searchFor, LimitTo limit, int mode, boolean caseSensitive) { public FriendPattern(char[] name, char[][] containers, SearchFor searchFor, LimitTo limit, int mode, boolean caseSensitive) {
super(name, containers, searchFor, limit, mode, caseSensitive); super(name, containers, searchFor, limit, mode, caseSensitive, false);
} }
public char[] indexEntryPrefix() { public char[] indexEntryPrefix() {