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

Fix for Bug 59493: need to refine index query for open-type

This commit is contained in:
Bogdan Gheorghe 2004-08-11 19:50:26 +00:00
parent 7944065574
commit 9df1ac81b8
12 changed files with 112 additions and 20 deletions

View file

@ -1,3 +1,6 @@
2004-08-11 Bogdan Gheorghe
Modified indexer test to work with new forward declartion encoding.
2004-08-06 Vladimir Hirsl
Parser correctness tests in FailedCompleteParseASTTest.java

View file

@ -425,7 +425,7 @@ public class IndexManagerTests extends TestCase {
IIndex ind = indexManager.getIndex(testProjectPath,true,true);
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);
assertTrue("Entry exists",typerefresults != null);
@ -558,10 +558,10 @@ public class IndexManagerTests extends TestCase {
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/G/ForwardA/A".toCharArray());
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)
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());
}
IEntryResult[] fwdDclRefResults = ind.queryEntries("typeRef/C/ForwardA/A".toCharArray());
IEntryResult[] fwdDclRefResults = ind.queryEntries("typeRef/G/ForwardA/A".toCharArray());
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)
fail("Entry Result length different from model for forward declarations refs");

View file

@ -1,3 +1,11 @@
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-07-12 Bogdan Gheorghe
Fix for Bug 69166: NPE in IndexerModelListener.processDelta

View file

@ -51,6 +51,9 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
final static int TYPEDEF = 6;
final static int DERIVED = 7;
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;
@ -241,15 +244,15 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
public void addElaboratedForwardDeclaration(IASTElaboratedTypeSpecifier elaboratedType) {
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))
{
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))
{
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));
}
}
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]*
*/
@ -391,6 +420,18 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
case(FRIEND):
result[pos++]=FRIEND_SUFFIX;
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;
//Encode in the following manner
@ -509,6 +550,12 @@ public abstract class AbstractIndexer implements IIndexer, IIndexConstants, ICSe
classType = DERIVED_SUFFIX;
} else if ( searchFor == ICSearchConstants.FRIEND){
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 {
//could be TYPE or CLASS_STRUCT, best we can do for these is the prefix
return prefix;

View file

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

View file

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

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
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

View file

@ -107,6 +107,12 @@ public interface ICSearchConstants {
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 */
/**

View file

@ -110,6 +110,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
CSearchPattern pattern = null;
if( searchFor == TYPE || searchFor == CLASS || searchFor == STRUCT ||
searchFor == FWD_CLASS || searchFor == FWD_STRUCT || searchFor == FWD_UNION ||
searchFor == ENUM || searchFor == UNION || searchFor == CLASS_STRUCT ||
searchFor == TYPEDEF )
{
@ -344,6 +345,11 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
return orPattern;
}
boolean isForward = false;
if (searchFor == FWD_CLASS || searchFor == FWD_STRUCT || searchFor == FWD_UNION){
isForward = true;
}
char [] patternArray = patternString.toCharArray();
IScanner scanner =null;
@ -393,7 +399,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
char[] name = (char [])list.removeLast();
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 );
// }
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 );
this.isForward = isForward;
simpleName = caseSensitive ? name : CharOperation.toLowerCase( name );
if( caseSensitive || containers == null ){
qualifications = containers;
@ -58,13 +59,13 @@ public class ClassDeclarationPattern extends CSearchPattern {
this.searchFor = searchFor;
if( searchFor == CLASS ){
if( searchFor == CLASS || searchFor == FWD_CLASS ){
classKind = ASTClassKind.CLASS;
} else if( searchFor == STRUCT ) {
} else if( searchFor == STRUCT || searchFor == FWD_STRUCT) {
classKind = ASTClassKind.STRUCT;
} else if ( searchFor == ENUM ) {
classKind = ASTClassKind.ENUM;
} else if ( searchFor == UNION ) {
} else if ( searchFor == UNION || searchFor == FWD_UNION ) {
classKind = ASTClassKind.UNION;
} else {
classKind = null;
@ -86,6 +87,11 @@ public class ClassDeclarationPattern extends CSearchPattern {
if( ! canAccept( limit ) )
return IMPOSSIBLE_MATCH;
if ((node instanceof IASTElaboratedTypeSpecifier &&!isForward)||
(node instanceof IASTClassSpecifier && isForward)){
return IMPOSSIBLE_MATCH;
}
char[] nodeName = null;
if (node instanceof IASTElaboratedTypeSpecifier)
{
@ -145,6 +151,7 @@ public class ClassDeclarationPattern extends CSearchPattern {
protected char[] decodedSimpleName;
private char[][] decodedContainingTypes;
protected char decodedType;
protected boolean isForward;
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;
}
} else if( classKind == ASTClassKind.CLASS ) {
if( decodedType != CLASS_SUFFIX ){
if( decodedType != CLASS_SUFFIX &&
decodedType != FWD_CLASS_SUFFIX){
return false;
}
} else if ( classKind == ASTClassKind.STRUCT ) {
if( decodedType != STRUCT_SUFFIX ){
if( decodedType != STRUCT_SUFFIX &&
decodedType != FWD_STRUCT_SUFFIX){
return false;
}
} else if ( classKind == ASTClassKind.UNION ) {
if( decodedType != UNION_SUFFIX ){
if( decodedType != UNION_SUFFIX &&
decodedType != FWD_UNION_SUFFIX){
return false;
}
} else if ( classKind == ASTClassKind.ENUM ) {

View file

@ -42,7 +42,7 @@ public class DerivedTypesPattern extends ClassDeclarationPattern {
* @param 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() {

View file

@ -41,7 +41,7 @@ public class FriendPattern extends ClassDeclarationPattern {
* @param 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() {