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:
parent
b30ac38a2a
commit
7c343c6050
4 changed files with 64 additions and 18 deletions
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems) - Adapted for CDT
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
@ -72,6 +73,14 @@ public abstract class SemanticHighlighting {
|
|||
* @return the display name
|
||||
*/
|
||||
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.
|
||||
|
|
|
@ -64,7 +64,13 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
|||
* Collects positions from the AST.
|
||||
*/
|
||||
private class PositionCollector extends CPPASTVisitor {
|
||||
{
|
||||
|
||||
/** The semantic token */
|
||||
private SemanticToken fToken= new SemanticToken();
|
||||
private int fMinLocation;
|
||||
|
||||
public PositionCollector(boolean visitImplicitNames) {
|
||||
fMinLocation= -1;
|
||||
shouldVisitTranslationUnit= true;
|
||||
shouldVisitNames= true;
|
||||
shouldVisitDeclarations= true;
|
||||
|
@ -72,16 +78,8 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
|||
shouldVisitStatements= true;
|
||||
shouldVisitDeclarators= true;
|
||||
shouldVisitNamespaces= true;
|
||||
shouldVisitImplicitNames = true;
|
||||
shouldVisitImplicitNameAlternates = true;
|
||||
}
|
||||
|
||||
/** The semantic token */
|
||||
private SemanticToken fToken= new SemanticToken();
|
||||
private int fMinLocation;
|
||||
|
||||
public PositionCollector() {
|
||||
fMinLocation= -1;
|
||||
shouldVisitImplicitNames = visitImplicitNames;
|
||||
shouldVisitImplicitNameAlternates = visitImplicitNames;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -351,7 +349,7 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
|
|||
if (ast == null || fJobPresenter.isCanceled())
|
||||
return;
|
||||
|
||||
PositionCollector collector= new PositionCollector();
|
||||
PositionCollector collector= new PositionCollector(requiresImplicitNames());
|
||||
|
||||
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.
|
||||
*/
|
||||
|
|
|
@ -1935,6 +1935,13 @@ public class SemanticHighlightings {
|
|||
return OVERLOADED_OPERATOR;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean requiresImplicitNames() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#getDefaultTextColor()
|
||||
*/
|
||||
|
@ -1964,7 +1971,7 @@ public class SemanticHighlightings {
|
|||
*/
|
||||
@Override
|
||||
public boolean isEnabledByDefault() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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.IBinding;
|
||||
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;
|
||||
|
||||
|
@ -68,15 +71,34 @@ public class OccurrencesFinder implements IOccurrencesFinder {
|
|||
addUsage(candidate, candidate.resolveBinding());
|
||||
}
|
||||
}
|
||||
names= CPPVisitor.getImplicitReferences(fRoot, fTarget);
|
||||
for (IASTName candidate : names) {
|
||||
if (candidate.isPartOfTranslationUnitFile()) {
|
||||
addUsage(candidate, candidate.resolveBinding());
|
||||
if (canHaveImplicitReference(fTarget)) {
|
||||
names= CPPVisitor.getImplicitReferences(fRoot, fTarget);
|
||||
for (IASTName candidate : names) {
|
||||
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() {
|
||||
performSearch();
|
||||
if (fResult.isEmpty())
|
||||
|
|
Loading…
Add table
Reference in a new issue