mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 21:35:40 +02:00
Fix for 71964: Search parses too many times
This commit is contained in:
parent
88b543209b
commit
5e29d237f6
2 changed files with 150 additions and 63 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -101,10 +103,15 @@ import org.eclipse.core.runtime.Path;
|
||||||
*/
|
*/
|
||||||
public class MatchLocator implements IMatchLocator{
|
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;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -144,120 +151,149 @@ public class MatchLocator implements IMatchLocator{
|
||||||
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptParameterReference(org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterReference)
|
* @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptParameterReference(org.eclipse.cdt.internal.core.parser.ast.complete.ASTParameterReference)
|
||||||
*/
|
*/
|
||||||
public void acceptParameterReference(IASTParameterReference reference)
|
public void acceptParameterReference(IASTParameterReference reference)
|
||||||
{
|
{
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void acceptTemplateParameterReference(IASTTemplateParameterReference reference)
|
public void acceptTemplateParameterReference(IASTTemplateParameterReference reference)
|
||||||
{
|
{
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef){
|
public void acceptTypedefDeclaration(IASTTypedefDeclaration typedef){
|
||||||
lastDeclaration = typedef;
|
lastDeclaration = typedef;
|
||||||
check( DECLARATIONS, typedef );
|
|
||||||
|
if (checkForMatch)
|
||||||
|
check( DECLARATIONS, typedef );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptTypedefReference( IASTTypedefReference reference ){
|
public void acceptTypedefReference( IASTTypedefReference reference ){
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptEnumeratorReference(IASTEnumeratorReference reference){
|
public void acceptEnumeratorReference(IASTEnumeratorReference reference){
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptMacro(IASTMacro macro){
|
public void acceptMacro(IASTMacro macro){
|
||||||
check( DECLARATIONS, macro );
|
if (checkForMatch)
|
||||||
|
check( DECLARATIONS, macro );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptVariable(IASTVariable variable){
|
public void acceptVariable(IASTVariable variable){
|
||||||
lastDeclaration = variable;
|
lastDeclaration = variable;
|
||||||
|
|
||||||
check( DECLARATIONS, variable );
|
if (checkForMatch){
|
||||||
|
check( DECLARATIONS, variable );
|
||||||
//A declaration is a definition unless...:
|
|
||||||
//it contains the extern specifier or a linkage-spec and no initializer
|
//A declaration is a definition unless...:
|
||||||
if( variable.getInitializerClause() != null ||
|
//it contains the extern specifier or a linkage-spec and no initializer
|
||||||
( !variable.isExtern() && !(currentScope instanceof IASTLinkageSpecification) ) ){
|
if( variable.getInitializerClause() != null ||
|
||||||
check( DEFINITIONS, variable );
|
( !variable.isExtern() && !(currentScope instanceof IASTLinkageSpecification) ) ){
|
||||||
|
check( DEFINITIONS, variable );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptField(IASTField field){
|
public void acceptField(IASTField field){
|
||||||
lastDeclaration = field;
|
lastDeclaration = field;
|
||||||
if( currentScope instanceof IASTClassSpecifier ){
|
|
||||||
check( DECLARATIONS, field );
|
if (checkForMatch){
|
||||||
if( !field.isStatic() ){
|
if( currentScope instanceof IASTClassSpecifier ){
|
||||||
check( DEFINITIONS, field );
|
check( DECLARATIONS, field );
|
||||||
|
if( !field.isStatic() ){
|
||||||
|
check( DEFINITIONS, field );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
check( DEFINITIONS, field );
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
check( DEFINITIONS, field );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){
|
public void acceptEnumerationSpecifier(IASTEnumerationSpecifier enumeration){
|
||||||
lastDeclaration = enumeration;
|
lastDeclaration = enumeration;
|
||||||
check( DECLARATIONS, enumeration );
|
|
||||||
Iterator iter = enumeration.getEnumerators();
|
if (checkForMatch){
|
||||||
while( iter.hasNext() ){
|
check( DECLARATIONS, enumeration );
|
||||||
IASTEnumerator enumerator = (IASTEnumerator) iter.next();
|
Iterator iter = enumeration.getEnumerators();
|
||||||
lastDeclaration = enumerator;
|
while( iter.hasNext() ){
|
||||||
check ( DECLARATIONS, enumerator );
|
IASTEnumerator enumerator = (IASTEnumerator) iter.next();
|
||||||
}
|
lastDeclaration = enumerator;
|
||||||
|
check ( DECLARATIONS, enumerator );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptFunctionDeclaration(IASTFunction function){
|
public void acceptFunctionDeclaration(IASTFunction function){
|
||||||
lastDeclaration = function;
|
lastDeclaration = function;
|
||||||
check( DECLARATIONS, function );
|
|
||||||
|
if (checkForMatch)
|
||||||
|
check( DECLARATIONS, function );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptMethodDeclaration(IASTMethod method){
|
public void acceptMethodDeclaration(IASTMethod method){
|
||||||
lastDeclaration = method;
|
lastDeclaration = method;
|
||||||
check( DECLARATIONS, method );
|
|
||||||
|
if (checkForMatch)
|
||||||
|
check( DECLARATIONS, method );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptClassReference(IASTClassReference reference) {
|
public void acceptClassReference(IASTClassReference reference) {
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptNamespaceReference( IASTNamespaceReference reference ){
|
public void acceptNamespaceReference( IASTNamespaceReference reference ){
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptVariableReference( IASTVariableReference reference ){
|
public void acceptVariableReference( IASTVariableReference reference ){
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptFieldReference( IASTFieldReference reference ){
|
public void acceptFieldReference( IASTFieldReference reference ){
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptEnumerationReference( IASTEnumerationReference reference ){
|
public void acceptEnumerationReference( IASTEnumerationReference reference ){
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptFunctionReference( IASTFunctionReference reference ){
|
public void acceptFunctionReference( IASTFunctionReference reference ){
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptMethodReference( IASTMethodReference reference ){
|
public void acceptMethodReference( IASTMethodReference reference ){
|
||||||
check( REFERENCES, reference );
|
if (checkForMatch)
|
||||||
|
check( REFERENCES, reference );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enterFunctionBody(IASTFunction function){
|
public void enterFunctionBody(IASTFunction function){
|
||||||
lastDeclaration = function;
|
lastDeclaration = function;
|
||||||
|
|
||||||
if( !function.previouslyDeclared() )
|
if (checkForMatch)
|
||||||
check( DECLARATIONS, function );
|
{
|
||||||
|
if( !function.previouslyDeclared() )
|
||||||
|
check( DECLARATIONS, function );
|
||||||
|
|
||||||
|
check( DEFINITIONS, function );
|
||||||
|
|
||||||
check( DEFINITIONS, function );
|
Iterator parms =function.getParameters();
|
||||||
|
while (parms.hasNext()){
|
||||||
Iterator parms =function.getParameters();
|
Object tempParm = parms.next();
|
||||||
while (parms.hasNext()){
|
if (tempParm instanceof IASTParameterDeclaration){
|
||||||
Object tempParm = parms.next();
|
check( DECLARATIONS, ((IASTParameterDeclaration)tempParm));
|
||||||
if (tempParm instanceof IASTParameterDeclaration){
|
}
|
||||||
check( DECLARATIONS, ((IASTParameterDeclaration)tempParm));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,20 +302,22 @@ public class MatchLocator implements IMatchLocator{
|
||||||
|
|
||||||
public void enterMethodBody(IASTMethod method) {
|
public void enterMethodBody(IASTMethod method) {
|
||||||
lastDeclaration = method;
|
lastDeclaration = method;
|
||||||
if( !method.previouslyDeclared() )
|
|
||||||
check( DECLARATIONS, method );
|
if (checkForMatch){
|
||||||
|
if( !method.previouslyDeclared() )
|
||||||
|
check( DECLARATIONS, method );
|
||||||
|
|
||||||
|
check( DEFINITIONS, method );
|
||||||
|
|
||||||
check( DEFINITIONS, method );
|
|
||||||
|
Iterator parms =method.getParameters();
|
||||||
|
while (parms.hasNext()){
|
||||||
Iterator parms =method.getParameters();
|
Object tempParm = parms.next();
|
||||||
while (parms.hasNext()){
|
if (tempParm instanceof IASTParameterDeclaration){
|
||||||
Object tempParm = parms.next();
|
check( DECLARATIONS, ((IASTParameterDeclaration)tempParm));
|
||||||
if (tempParm instanceof IASTParameterDeclaration){
|
}
|
||||||
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;
|
||||||
check( DECLARATIONS, namespaceDefinition );
|
|
||||||
check( DEFINITIONS, namespaceDefinition );
|
if (checkForMatch){
|
||||||
|
check( DECLARATIONS, namespaceDefinition );
|
||||||
|
check( DEFINITIONS, namespaceDefinition );
|
||||||
|
}
|
||||||
|
|
||||||
pushScope( namespaceDefinition );
|
pushScope( namespaceDefinition );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enterClassSpecifier(IASTClassSpecifier classSpecification) {
|
public void enterClassSpecifier(IASTClassSpecifier classSpecification) {
|
||||||
lastDeclaration = classSpecification;
|
lastDeclaration = classSpecification;
|
||||||
check( DECLARATIONS, classSpecification );
|
|
||||||
|
if (checkForMatch){
|
||||||
|
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) {
|
||||||
check(DECLARATIONS, classSpecification);
|
if (checkForMatch){
|
||||||
|
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;
|
||||||
|
@ -645,6 +725,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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue