1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 20:05:35 +02:00

Bug 486688 - Syntax highlighting for dependent enumerator / enumeration

Change-Id: I3054a8e8d556f1473049e8b11c64c1e066e16004
This commit is contained in:
Nathan Ridge 2016-01-28 17:23:20 -05:00
parent f9375840ed
commit aca9b68b02
3 changed files with 66 additions and 2 deletions

View file

@ -23,11 +23,13 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownMember; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownMember;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownMemberClass;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType;
public class HeuristicResolver { public class HeuristicResolver {
@ -107,11 +109,17 @@ public class HeuristicResolver {
lookupType = null; lookupType = null;
} }
} }
IScope lookupScope = null;
if (lookupType instanceof ICPPClassType) { if (lookupType instanceof ICPPClassType) {
lookupScope = ((ICPPClassType) lookupType).getCompositeScope();
} else if (lookupType instanceof ICPPEnumeration) {
lookupScope = ((ICPPEnumeration) lookupType).asScope();
}
if (lookupScope != null) {
LookupData lookup = new LookupData(name, templateArgs, point); LookupData lookup = new LookupData(name, templateArgs, point);
lookup.fHeuristicBaseLookup = true; lookup.fHeuristicBaseLookup = true;
try { try {
CPPSemantics.lookup(lookup, ((ICPPClassType) lookupType).getCompositeScope()); CPPSemantics.lookup(lookup, lookupScope);
IBinding[] foundBindings = lookup.getFoundBindings(); IBinding[] foundBindings = lookup.getFoundBindings();
if (foundBindings.length > 0) { if (foundBindings.length > 0) {
return foundBindings; return foundBindings;
@ -179,6 +187,15 @@ public class HeuristicResolver {
} }
} }
// TODO(nathanridge): Handle more cases. // TODO(nathanridge): Handle more cases.
} else if (type instanceof ICPPUnknownMemberClass) {
ICPPUnknownMemberClass member = (ICPPUnknownMemberClass) type;
IBinding[] candidates = lookInside(member.getOwnerType(), false, member.getNameCharArray(),
null, point);
if (candidates.length == 1) {
if (candidates[0] instanceof IType) {
return (IType) candidates[0];
}
}
} }
return null; return null;
} }

View file

@ -491,4 +491,20 @@ public class SemanticHighlightingTest extends TestCase {
public void testLocalVariableInLambdaCapture_486679() throws Exception { public void testLocalVariableInLambdaCapture_486679() throws Exception {
makeAssertions(); makeAssertions();
} }
// template <typename T> //$templateParameter
// struct Base { //$class
// enum E { A }; //$enum,enumerator
// enum class F { B }; //$enum,enumerator
// };
// template <typename T> //$templateParameter
// struct Derived : Base<T> { //$class,class,templateParameter
// static typename Base<T>::E x //$class,templateParameter,enum,staticField
// = Base<T>::A; //$class,templateParameter,enumerator
// static typename Base<T>::F y //$class,templateParameter,enum,staticField
// = Base<T>::F::B; //$class,templateParameter,enum,enumerator
// };
public void testDependentEnum_486688() throws Exception {
makeAssertions();
}
} }

View file

@ -76,6 +76,7 @@ import org.eclipse.cdt.ui.text.ISemanticToken;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator; import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.HeuristicResolver;
/** /**
* Semantic highlightings. * Semantic highlightings.
@ -304,6 +305,11 @@ public class SemanticHighlightings {
} }
IBinding binding= token.getBinding(); IBinding binding= token.getBinding();
if (binding instanceof IField) { if (binding instanceof IField) {
if (binding instanceof ICPPUnknownBinding) {
if (heuristicallyResolvesToEnumerator((ICPPUnknownBinding) binding, node)) {
return false;
}
}
return true; return true;
} }
} }
@ -990,6 +996,11 @@ public class SemanticHighlightings {
if (node instanceof IASTName) { if (node instanceof IASTName) {
IBinding binding= token.getBinding(); IBinding binding= token.getBinding();
if (binding instanceof ICompositeType && !(binding instanceof ICPPTemplateParameter)) { if (binding instanceof ICompositeType && !(binding instanceof ICPPTemplateParameter)) {
if (binding instanceof ICPPUnknownBinding) {
if (heuristicallyResolvesToEnumeration((ICPPUnknownBinding) binding, node)) {
return false;
}
}
return true; return true;
} }
} }
@ -1042,6 +1053,11 @@ public class SemanticHighlightings {
if (binding instanceof IEnumeration) { if (binding instanceof IEnumeration) {
return true; return true;
} }
if (binding instanceof ICPPUnknownBinding) {
if (heuristicallyResolvesToEnumeration((ICPPUnknownBinding) binding, node)) {
return true;
}
}
} }
return false; return false;
} }
@ -1338,6 +1354,11 @@ public class SemanticHighlightings {
if (binding instanceof IEnumerator) { if (binding instanceof IEnumerator) {
return true; return true;
} }
if (binding instanceof ICPPUnknownBinding) {
if (heuristicallyResolvesToEnumerator((ICPPUnknownBinding) binding, node)) {
return true;
}
}
} }
return false; return false;
} }
@ -1596,6 +1617,16 @@ public class SemanticHighlightings {
} }
} }
private static boolean heuristicallyResolvesToEnumeration(ICPPUnknownBinding binding, IASTNode point) {
IBinding[] resolved = HeuristicResolver.resolveUnknownBinding(binding, point);
return resolved.length == 1 && resolved[0] instanceof IEnumeration;
}
private static boolean heuristicallyResolvesToEnumerator(ICPPUnknownBinding binding, IASTNode point) {
IBinding[] resolved = HeuristicResolver.resolveUnknownBinding(binding, point);
return resolved.length == 1 && resolved[0] instanceof IEnumerator;
}
// Note on the get___PreferenceKey() functions below: // Note on the get___PreferenceKey() functions below:
// - For semantic highlightings deriving from SemanticHighlightingWithOwnPreference, // - For semantic highlightings deriving from SemanticHighlightingWithOwnPreference,
// these functions return keys for accessing the highlighting's own preferences. // these functions return keys for accessing the highlighting's own preferences.