1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-02 05:45:58 +02:00

Fix for 71964: Search parses too many times

This commit is contained in:
Bogdan Gheorghe 2004-08-13 18:54:25 +00:00
parent 88b543209b
commit 5e29d237f6
2 changed files with 150 additions and 63 deletions

View file

@ -1,3 +1,8 @@
2004-08-11 Bogdan Gheorghe
Fix for 71964: Search parses too many times
* search/org/eclipse/cdt/internal/core/search/matching/MatchLocators.java
2004-08-11 Bogdan Gheorghe 2004-08-11 Bogdan Gheorghe
Fix for Bug 59493: need to refine index query for open-type Fix for Bug 59493: need to refine index query for open-type

View file

@ -18,6 +18,7 @@ import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
@ -80,6 +81,7 @@ import org.eclipse.cdt.core.search.ICSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchScope; import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.IMatch; import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IMatchLocator; import org.eclipse.cdt.core.search.IMatchLocator;
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectSet;
import org.eclipse.cdt.internal.core.search.AcceptMatchOperation; import org.eclipse.cdt.internal.core.search.AcceptMatchOperation;
import org.eclipse.cdt.internal.core.search.indexing.IndexProblemHandler; import org.eclipse.cdt.internal.core.search.indexing.IndexProblemHandler;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -104,7 +106,12 @@ public class MatchLocator implements IMatchLocator{
ArrayList matchStorage; ArrayList matchStorage;
protected ObjectSet encounteredHeaders;
protected ObjectSet tempHeaderSet;
public static boolean VERBOSE = false; public static boolean VERBOSE = false;
private boolean checkForMatch = true;
/** /**
* *
*/ */
@ -145,35 +152,43 @@ public class MatchLocator implements IMatchLocator{
*/ */
public void acceptParameterReference(IASTParameterReference reference) public void acceptParameterReference(IASTParameterReference reference)
{ {
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void acceptTemplateParameterReference(IASTTemplateParameterReference reference) public void acceptTemplateParameterReference(IASTTemplateParameterReference reference)
{ {
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef){ public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef){
lastDeclaration = typedef; lastDeclaration = typedef;
if (checkForMatch)
check( DECLARATIONS, typedef ); check( DECLARATIONS, typedef );
} }
public void acceptTypedefReference( IASTTypedefReference reference ){ public void acceptTypedefReference( IASTTypedefReference reference ){
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void acceptEnumeratorReference(IASTEnumeratorReference reference){ public void acceptEnumeratorReference(IASTEnumeratorReference reference){
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void acceptMacro(IASTMacro macro){ public void acceptMacro(IASTMacro macro){
if (checkForMatch)
check( DECLARATIONS, macro ); check( DECLARATIONS, macro );
} }
public void acceptVariable(IASTVariable variable){ public void acceptVariable(IASTVariable variable){
lastDeclaration = variable; lastDeclaration = variable;
if (checkForMatch){
check( DECLARATIONS, variable ); check( DECLARATIONS, variable );
//A declaration is a definition unless...: //A declaration is a definition unless...:
@ -183,9 +198,12 @@ public class MatchLocator implements IMatchLocator{
check( DEFINITIONS, variable ); check( DEFINITIONS, variable );
} }
} }
}
public void acceptField(IASTField field){ public void acceptField(IASTField field){
lastDeclaration = field; lastDeclaration = field;
if (checkForMatch){
if( currentScope instanceof IASTClassSpecifier ){ if( currentScope instanceof IASTClassSpecifier ){
check( DECLARATIONS, field ); check( DECLARATIONS, field );
if( !field.isStatic() ){ if( !field.isStatic() ){
@ -195,9 +213,12 @@ public class MatchLocator implements IMatchLocator{
check( DEFINITIONS, field ); check( DEFINITIONS, field );
} }
} }
}
public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){ public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){
lastDeclaration = enumeration; lastDeclaration = enumeration;
if (checkForMatch){
check( DECLARATIONS, enumeration ); check( DECLARATIONS, enumeration );
Iterator iter = enumeration.getEnumerators(); Iterator iter = enumeration.getEnumerators();
while( iter.hasNext() ){ while( iter.hasNext() ){
@ -206,48 +227,62 @@ public class MatchLocator implements IMatchLocator{
check ( DECLARATIONS, enumerator ); check ( DECLARATIONS, enumerator );
} }
} }
}
public void acceptFunctionDeclaration(IASTFunction function){ public void acceptFunctionDeclaration(IASTFunction function){
lastDeclaration = function; lastDeclaration = function;
if (checkForMatch)
check( DECLARATIONS, function ); check( DECLARATIONS, function );
} }
public void acceptMethodDeclaration(IASTMethod method){ public void acceptMethodDeclaration(IASTMethod method){
lastDeclaration = method; lastDeclaration = method;
if (checkForMatch)
check( DECLARATIONS, method ); check( DECLARATIONS, method );
} }
public void acceptClassReference(IASTClassReference reference) { public void acceptClassReference(IASTClassReference reference) {
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void acceptNamespaceReference( IASTNamespaceReference reference ){ public void acceptNamespaceReference( IASTNamespaceReference reference ){
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void acceptVariableReference( IASTVariableReference reference ){ public void acceptVariableReference( IASTVariableReference reference ){
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void acceptFieldReference( IASTFieldReference reference ){ public void acceptFieldReference( IASTFieldReference reference ){
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void acceptEnumerationReference( IASTEnumerationReference reference ){ public void acceptEnumerationReference( IASTEnumerationReference reference ){
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void acceptFunctionReference( IASTFunctionReference reference ){ public void acceptFunctionReference( IASTFunctionReference reference ){
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void acceptMethodReference( IASTMethodReference reference ){ public void acceptMethodReference( IASTMethodReference reference ){
if (checkForMatch)
check( REFERENCES, reference ); check( REFERENCES, reference );
} }
public void enterFunctionBody(IASTFunction function){ public void enterFunctionBody(IASTFunction function){
lastDeclaration = function; lastDeclaration = function;
if (checkForMatch)
{
if( !function.previouslyDeclared() ) if( !function.previouslyDeclared() )
check( DECLARATIONS, function ); check( DECLARATIONS, function );
@ -260,12 +295,15 @@ public class MatchLocator implements IMatchLocator{
check( DECLARATIONS, ((IASTParameterDeclaration)tempParm)); check( DECLARATIONS, ((IASTParameterDeclaration)tempParm));
} }
} }
}
pushScope( function ); pushScope( function );
} }
public void enterMethodBody(IASTMethod method) { public void enterMethodBody(IASTMethod method) {
lastDeclaration = method; lastDeclaration = method;
if (checkForMatch){
if( !method.previouslyDeclared() ) if( !method.previouslyDeclared() )
check( DECLARATIONS, method ); check( DECLARATIONS, method );
@ -279,7 +317,7 @@ public class MatchLocator implements IMatchLocator{
check( DECLARATIONS, ((IASTParameterDeclaration)tempParm)); check( DECLARATIONS, ((IASTParameterDeclaration)tempParm));
} }
} }
}
pushScope( method ); pushScope( method );
} }
@ -290,14 +328,22 @@ public class MatchLocator implements IMatchLocator{
public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) { public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
lastDeclaration = namespaceDefinition; lastDeclaration = namespaceDefinition;
if (checkForMatch){
check( DECLARATIONS, namespaceDefinition ); check( DECLARATIONS, namespaceDefinition );
check( DEFINITIONS, namespaceDefinition ); check( DEFINITIONS, namespaceDefinition );
}
pushScope( namespaceDefinition ); pushScope( namespaceDefinition );
} }
public void enterClassSpecifier(IASTClassSpecifier classSpecification) { public void enterClassSpecifier(IASTClassSpecifier classSpecification) {
lastDeclaration = classSpecification; lastDeclaration = classSpecification;
if (checkForMatch){
check( DECLARATIONS, classSpecification ); check( DECLARATIONS, classSpecification );
}
pushScope( classSpecification ); pushScope( classSpecification );
} }
@ -310,7 +356,10 @@ public class MatchLocator implements IMatchLocator{
} }
public void exitClassSpecifier(IASTClassSpecifier classSpecification) { public void exitClassSpecifier(IASTClassSpecifier classSpecification) {
if (checkForMatch){
check(DECLARATIONS, classSpecification); check(DECLARATIONS, classSpecification);
}
popScope(); popScope();
} }
@ -327,12 +376,26 @@ public class MatchLocator implements IMatchLocator{
IPath path = new Path( includePath ); IPath path = new Path( includePath );
IResource resource = null; IResource resource = null;
if (!encounteredHeaders.containsKey(includePath)){
//this header has not been seen before
searchStack.addFirst(new Boolean(checkForMatch));
checkForMatch = true;
if (!tempHeaderSet.containsKey(includePath)){
tempHeaderSet.put(includePath);
}
}
else{
//this header has been seen before; don't bother processing it
searchStack.addFirst(new Boolean(checkForMatch));
checkForMatch = false;
}
if( workspaceRoot != null ){ if( workspaceRoot != null ){
resource = workspaceRoot.getFileForLocation( path ); resource = workspaceRoot.getFileForLocation( path );
// if( resource == null ){ // if( resource == null ){
// //TODO:What to do if the file is not in the workspace? // //TODO:What to do if the file is not in the workspace?
// IFile file = currentResource.getProject().getFile( inclusion.getName() ); // IFile file = currentResource.getProject().getFile(
// inclusion.getName() );
// try{ // try{
// file.createLink( path, 0, null ); // file.createLink( path, 0, null );
// } catch ( CoreException e ){ // } catch ( CoreException e ){
@ -357,12 +420,19 @@ public class MatchLocator implements IMatchLocator{
currentPath = (IPath) obj; currentPath = (IPath) obj;
currentResource = null; currentResource = null;
} }
//set match for current level
Boolean check= (Boolean) searchStack.removeFirst();
checkForMatch = check.booleanValue();
} }
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies ) throws InterruptedException{ public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies ) throws InterruptedException{
matchStorage = new ArrayList(); matchStorage = new ArrayList();
encounteredHeaders= new ObjectSet(32);
tempHeaderSet = new ObjectSet(32);
workspaceRoot = (workspace != null) ? workspace.getRoot() : null; workspaceRoot = (workspace != null) ? workspace.getRoot() : null;
HashMap wcPaths = new HashMap(); HashMap wcPaths = new HashMap();
@ -407,6 +477,10 @@ public class MatchLocator implements IMatchLocator{
if (!searchScope.encloses(pathString)) continue; if (!searchScope.encloses(pathString)) continue;
IFile tempFile=workspaceRoot.getFile(new Path(pathString));
IPath tempLocation =tempFile.getLocation();
if ((tempLocation != null) && (encounteredHeaders.containsKey(tempLocation.toOSString()))) continue;
CodeReader reader = null; CodeReader reader = null;
realPath = null; realPath = null;
@ -466,6 +540,9 @@ public class MatchLocator implements IMatchLocator{
} }
} }
//Set checkForMatch to true
checkForMatch = true;
//Get the scanner info //Get the scanner info
IScannerInfo scanInfo = new ScannerInfo(); IScannerInfo scanInfo = new ScannerInfo();
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project); IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
@ -512,8 +589,11 @@ public class MatchLocator implements IMatchLocator{
vmErr.printStackTrace(); vmErr.printStackTrace();
} }
} finally { } finally {
encounteredHeaders.addAll(tempHeaderSet);
tempHeaderSet.clear();
scopeStack.clear(); scopeStack.clear();
resourceStack.clear(); resourceStack.clear();
searchStack.clear();
lastDeclaration = null; lastDeclaration = null;
currentScope = null; currentScope = null;
parser = null; parser = null;
@ -646,6 +726,8 @@ public class MatchLocator implements IMatchLocator{
private IASTScope currentScope = null; private IASTScope currentScope = null;
private LinkedList scopeStack = new LinkedList(); private LinkedList scopeStack = new LinkedList();
private LinkedList searchStack = new LinkedList();
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier) * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier)
*/ */