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

Avoid computation of implicit references, bug 291024.

This commit is contained in:
Markus Schorn 2009-10-02 09:25:24 +00:00
parent b30ac38a2a
commit 7c343c6050
4 changed files with 64 additions and 18 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others. * Copyright (c) 2000, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems) - Adapted for CDT * Anton Leherbauer (Wind River Systems) - Adapted for CDT
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.editor; package org.eclipse.cdt.internal.ui.editor;
@ -72,6 +73,14 @@ public abstract class SemanticHighlighting {
* @return the display name * @return the display name
*/ */
public abstract String getDisplayName(); public abstract String getDisplayName();
/**
* Indicates that the highlighting needs to visit implicit names
* (e.g. overloaded operators)
*/
public boolean requiresImplicitNames() {
return false;
}
/** /**
* Returns <code>true</code> iff the semantic highlighting consumes the semantic token. * Returns <code>true</code> iff the semantic highlighting consumes the semantic token.

View file

@ -64,7 +64,13 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
* Collects positions from the AST. * Collects positions from the AST.
*/ */
private class PositionCollector extends CPPASTVisitor { private class PositionCollector extends CPPASTVisitor {
{
/** The semantic token */
private SemanticToken fToken= new SemanticToken();
private int fMinLocation;
public PositionCollector(boolean visitImplicitNames) {
fMinLocation= -1;
shouldVisitTranslationUnit= true; shouldVisitTranslationUnit= true;
shouldVisitNames= true; shouldVisitNames= true;
shouldVisitDeclarations= true; shouldVisitDeclarations= true;
@ -72,16 +78,8 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
shouldVisitStatements= true; shouldVisitStatements= true;
shouldVisitDeclarators= true; shouldVisitDeclarators= true;
shouldVisitNamespaces= true; shouldVisitNamespaces= true;
shouldVisitImplicitNames = true; shouldVisitImplicitNames = visitImplicitNames;
shouldVisitImplicitNameAlternates = true; shouldVisitImplicitNameAlternates = visitImplicitNames;
}
/** The semantic token */
private SemanticToken fToken= new SemanticToken();
private int fMinLocation;
public PositionCollector() {
fMinLocation= -1;
} }
/* /*
@ -351,7 +349,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
if (ast == null || fJobPresenter.isCanceled()) if (ast == null || fJobPresenter.isCanceled())
return; return;
PositionCollector collector= new PositionCollector(); PositionCollector collector= new PositionCollector(requiresImplicitNames());
startReconcilingPositions(); startReconcilingPositions();
@ -376,6 +374,16 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
} }
} }
private boolean requiresImplicitNames() {
for (int i = 0; i < fSemanticHighlightings.length; i++) {
SemanticHighlighting sh = fSemanticHighlightings[i];
if (sh.requiresImplicitNames() && fHighlightings[i].isEnabled()) {
return true;
}
}
return false;
}
/** /**
* Start reconciling positions. * Start reconciling positions.
*/ */

View file

@ -1935,6 +1935,13 @@ public class SemanticHighlightings {
return OVERLOADED_OPERATOR; return OVERLOADED_OPERATOR;
} }
@Override
public boolean requiresImplicitNames() {
return true;
}
/* /*
* @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#getDefaultTextColor() * @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#getDefaultTextColor()
*/ */
@ -1964,7 +1971,7 @@ public class SemanticHighlightings {
*/ */
@Override @Override
public boolean isEnabledByDefault() { public boolean isEnabledByDefault() {
return true; return false;
} }
/* /*

View file

@ -20,6 +20,9 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
@ -68,15 +71,34 @@ public class OccurrencesFinder implements IOccurrencesFinder {
addUsage(candidate, candidate.resolveBinding()); addUsage(candidate, candidate.resolveBinding());
} }
} }
names= CPPVisitor.getImplicitReferences(fRoot, fTarget); if (canHaveImplicitReference(fTarget)) {
for (IASTName candidate : names) { names= CPPVisitor.getImplicitReferences(fRoot, fTarget);
if (candidate.isPartOfTranslationUnitFile()) { for (IASTName candidate : names) {
addUsage(candidate, candidate.resolveBinding()); if (candidate.isPartOfTranslationUnitFile()) {
addUsage(candidate, candidate.resolveBinding());
}
} }
} }
} }
} }
private boolean canHaveImplicitReference(IBinding binding) {
final char[] op = Keywords.cOPERATOR;
final char[] nameCharArray = binding.getNameCharArray();
if (nameCharArray.length > 0) {
if (nameCharArray[0] == '~') {
return true;
}
if (CharArrayUtils.equals(nameCharArray, 0, op.length, op)) {
return true;
}
}
if (binding instanceof ICPPConstructor)
return true;
return false;
}
public OccurrenceLocation[] getOccurrences() { public OccurrenceLocation[] getOccurrences() {
performSearch(); performSearch();
if (fResult.isEmpty()) if (fResult.isEmpty())