1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +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
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.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
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.IMatch;
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.indexing.IndexProblemHandler;
import org.eclipse.core.resources.IFile;
@ -104,7 +106,12 @@ public class MatchLocator implements IMatchLocator{
ArrayList matchStorage;
protected ObjectSet encounteredHeaders;
protected ObjectSet tempHeaderSet;
public static boolean VERBOSE = false;
private boolean checkForMatch = true;
/**
*
*/
@ -145,35 +152,43 @@ public class MatchLocator implements IMatchLocator{
*/
public void acceptParameterReference(IASTParameterReference reference)
{
if (checkForMatch)
check( REFERENCES, reference );
}
public void acceptTemplateParameterReference(IASTTemplateParameterReference reference)
{
if (checkForMatch)
check( REFERENCES, reference );
}
public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef){
lastDeclaration = typedef;
if (checkForMatch)
check( DECLARATIONS, typedef );
}
public void acceptTypedefReference( IASTTypedefReference reference ){
if (checkForMatch)
check( REFERENCES, reference );
}
public void acceptEnumeratorReference(IASTEnumeratorReference reference){
if (checkForMatch)
check( REFERENCES, reference );
}
public void acceptMacro(IASTMacro macro){
if (checkForMatch)
check( DECLARATIONS, macro );
}
public void acceptVariable(IASTVariable variable){
lastDeclaration = variable;
if (checkForMatch){
check( DECLARATIONS, variable );
//A declaration is a definition unless...:
@ -183,9 +198,12 @@ public class MatchLocator implements IMatchLocator{
check( DEFINITIONS, variable );
}
}
}
public void acceptField(IASTField field){
lastDeclaration = field;
if (checkForMatch){
if( currentScope instanceof IASTClassSpecifier ){
check( DECLARATIONS, field );
if( !field.isStatic() ){
@ -195,9 +213,12 @@ public class MatchLocator implements IMatchLocator{
check( DEFINITIONS, field );
}
}
}
public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){
lastDeclaration = enumeration;
if (checkForMatch){
check( DECLARATIONS, enumeration );
Iterator iter = enumeration.getEnumerators();
while( iter.hasNext() ){
@ -206,48 +227,62 @@ public class MatchLocator implements IMatchLocator{
check ( DECLARATIONS, enumerator );
}
}
}
public void acceptFunctionDeclaration(IASTFunction function){
lastDeclaration = function;
if (checkForMatch)
check( DECLARATIONS, function );
}
public void acceptMethodDeclaration(IASTMethod method){
lastDeclaration = method;
if (checkForMatch)
check( DECLARATIONS, method );
}
public void acceptClassReference(IASTClassReference reference) {
if (checkForMatch)
check( REFERENCES, reference );
}
public void acceptNamespaceReference( IASTNamespaceReference reference ){
if (checkForMatch)
check( REFERENCES, reference );
}
public void acceptVariableReference( IASTVariableReference reference ){
if (checkForMatch)
check( REFERENCES, reference );
}
public void acceptFieldReference( IASTFieldReference reference ){
if (checkForMatch)
check( REFERENCES, reference );
}
public void acceptEnumerationReference( IASTEnumerationReference reference ){
if (checkForMatch)
check( REFERENCES, reference );
}
public void acceptFunctionReference( IASTFunctionReference reference ){
if (checkForMatch)
check( REFERENCES, reference );
}
public void acceptMethodReference( IASTMethodReference reference ){
if (checkForMatch)
check( REFERENCES, reference );
}
public void enterFunctionBody(IASTFunction function){
lastDeclaration = function;
if (checkForMatch)
{
if( !function.previouslyDeclared() )
check( DECLARATIONS, function );
@ -260,12 +295,15 @@ public class MatchLocator implements IMatchLocator{
check( DECLARATIONS, ((IASTParameterDeclaration)tempParm));
}
}
}
pushScope( function );
}
public void enterMethodBody(IASTMethod method) {
lastDeclaration = method;
if (checkForMatch){
if( !method.previouslyDeclared() )
check( DECLARATIONS, method );
@ -279,7 +317,7 @@ public class MatchLocator implements IMatchLocator{
check( DECLARATIONS, ((IASTParameterDeclaration)tempParm));
}
}
}
pushScope( method );
}
@ -290,14 +328,22 @@ public class MatchLocator implements IMatchLocator{
public void enterNamespaceDefinition(IASTNamespaceDefinition namespaceDefinition) {
lastDeclaration = namespaceDefinition;
if (checkForMatch){
check( DECLARATIONS, namespaceDefinition );
check( DEFINITIONS, namespaceDefinition );
}
pushScope( namespaceDefinition );
}
public void enterClassSpecifier(IASTClassSpecifier classSpecification) {
lastDeclaration = classSpecification;
if (checkForMatch){
check( DECLARATIONS, classSpecification );
}
pushScope( classSpecification );
}
@ -310,7 +356,10 @@ public class MatchLocator implements IMatchLocator{
}
public void exitClassSpecifier(IASTClassSpecifier classSpecification) {
if (checkForMatch){
check(DECLARATIONS, classSpecification);
}
popScope();
}
@ -327,12 +376,26 @@ public class MatchLocator implements IMatchLocator{
IPath path = new Path( includePath );
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 ){
resource = workspaceRoot.getFileForLocation( path );
// if( resource == null ){
// //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{
// file.createLink( path, 0, null );
// } catch ( CoreException e ){
@ -357,12 +420,19 @@ public class MatchLocator implements IMatchLocator{
currentPath = (IPath) obj;
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{
matchStorage = new ArrayList();
encounteredHeaders= new ObjectSet(32);
tempHeaderSet = new ObjectSet(32);
workspaceRoot = (workspace != null) ? workspace.getRoot() : null;
HashMap wcPaths = new HashMap();
@ -407,6 +477,10 @@ public class MatchLocator implements IMatchLocator{
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;
realPath = null;
@ -466,6 +540,9 @@ public class MatchLocator implements IMatchLocator{
}
}
//Set checkForMatch to true
checkForMatch = true;
//Get the scanner info
IScannerInfo scanInfo = new ScannerInfo();
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project);
@ -512,8 +589,11 @@ public class MatchLocator implements IMatchLocator{
vmErr.printStackTrace();
}
} finally {
encounteredHeaders.addAll(tempHeaderSet);
tempHeaderSet.clear();
scopeStack.clear();
resourceStack.clear();
searchStack.clear();
lastDeclaration = null;
currentScope = null;
parser = null;
@ -646,6 +726,8 @@ public class MatchLocator implements IMatchLocator{
private IASTScope currentScope = null;
private LinkedList scopeStack = new LinkedList();
private LinkedList searchStack = new LinkedList();
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptElaboratedForewardDeclaration(org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier)
*/