mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 22:35:43 +02:00
Bug 482421 - Ensure enumerations stored in the index return their
enumerators in the order of declaration Change-Id: I49eec356a1b241b1dbe3eb9b7744adce5816a7c5 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
5cd555717b
commit
927dd7502d
5 changed files with 86 additions and 16 deletions
|
@ -2193,6 +2193,68 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
||||||
assertNotNull(num);
|
assertNotNull(num);
|
||||||
assertEquals(1, num.longValue());
|
assertEquals(1, num.longValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// struct meta {
|
||||||
|
// enum {
|
||||||
|
// a = T::value,
|
||||||
|
// b = a
|
||||||
|
// };
|
||||||
|
// };
|
||||||
|
|
||||||
|
// struct S {
|
||||||
|
// static const int value = 42;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template <int> struct waldo;
|
||||||
|
//
|
||||||
|
// template <>
|
||||||
|
// struct waldo<42> {
|
||||||
|
// double operator()();
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template <typename>
|
||||||
|
// struct C : public waldo<meta<S>::b> {};
|
||||||
|
//
|
||||||
|
// void bar(double);
|
||||||
|
//
|
||||||
|
// void foo(C<S> x){
|
||||||
|
// bar(x());
|
||||||
|
// }
|
||||||
|
public void testDependentEnumerator_482421a() throws Exception {
|
||||||
|
checkBindings();
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// struct meta {
|
||||||
|
// enum {
|
||||||
|
// b = T::value,
|
||||||
|
// a = b
|
||||||
|
// };
|
||||||
|
// };
|
||||||
|
|
||||||
|
// struct S {
|
||||||
|
// static const int value = 42;
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template <int> struct waldo;
|
||||||
|
//
|
||||||
|
// template <>
|
||||||
|
// struct waldo<42> {
|
||||||
|
// double operator()();
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template <typename>
|
||||||
|
// struct C : public waldo<meta<S>::a> {};
|
||||||
|
//
|
||||||
|
// void bar(double);
|
||||||
|
//
|
||||||
|
// void foo(C<S> x){
|
||||||
|
// bar(x());
|
||||||
|
// }
|
||||||
|
public void testDependentEnumerator_482421b() throws Exception {
|
||||||
|
checkBindings();
|
||||||
|
}
|
||||||
|
|
||||||
// template<typename U>
|
// template<typename U>
|
||||||
// struct A {
|
// struct A {
|
||||||
|
|
|
@ -11,11 +11,12 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayMap;
|
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMBinding;
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ public interface IPDOMCPPEnumType extends ICPPEnumeration, IPDOMBinding, IIndexT
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the scope to access the enumerators.
|
* Called by the scope to access the enumerators.
|
||||||
|
* Returns the enumerators in the order of declaration.
|
||||||
*/
|
*/
|
||||||
void loadEnumerators(CharArrayMap<IPDOMCPPEnumerator> map);
|
void loadEnumerators(List<IPDOMCPPEnumerator> enumerators);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
import java.lang.ref.SoftReference;
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
@ -151,8 +150,12 @@ class PDOMCPPEnumScope implements ICPPEnumScope, IIndexScope {
|
||||||
|
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
// there is no cache, build it:
|
// there is no cache, build it:
|
||||||
map= new CharArrayMap<IPDOMCPPEnumerator>();
|
List<IPDOMCPPEnumerator> enumerators = new ArrayList<>();
|
||||||
enumeration.loadEnumerators(map);
|
enumeration.loadEnumerators(enumerators);
|
||||||
|
map = new CharArrayMap<IPDOMCPPEnumerator>();
|
||||||
|
for (IPDOMCPPEnumerator enumerator : enumerators) {
|
||||||
|
map.put(enumerator.getNameCharArray(), enumerator);
|
||||||
|
}
|
||||||
pdom.putCachedResult(key, new SoftReference<CharArrayMap<?>>(map));
|
pdom.putCachedResult(key, new SoftReference<CharArrayMap<?>>(map));
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
@ -171,14 +174,17 @@ class PDOMCPPEnumScope implements ICPPEnumScope, IIndexScope {
|
||||||
|
|
||||||
public static IEnumerator[] getEnumerators(IPDOMCPPEnumType enumType) {
|
public static IEnumerator[] getEnumerators(IPDOMCPPEnumType enumType) {
|
||||||
try {
|
try {
|
||||||
CharArrayMap<IPDOMCPPEnumerator> map = getBindingMap(enumType);
|
// We want to return the enumerators in order of declaration, so we don't
|
||||||
|
// use the cache (getBindingsMap()) which stores them in a hash map and thus
|
||||||
|
// loses the order.
|
||||||
|
List<IPDOMCPPEnumerator> enumerators = new ArrayList<>();
|
||||||
|
enumType.loadEnumerators(enumerators);
|
||||||
List<IEnumerator> result= new ArrayList<IEnumerator>();
|
List<IEnumerator> result= new ArrayList<IEnumerator>();
|
||||||
for (IEnumerator value : map.values()) {
|
for (IEnumerator value : enumerators) {
|
||||||
if (IndexFilter.ALL_DECLARED.acceptBinding(value)) {
|
if (IndexFilter.ALL_DECLARED.acceptBinding(value)) {
|
||||||
result.add(value);
|
result.add(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.reverse(result);
|
|
||||||
return result.toArray(new IEnumerator[result.size()]);
|
return result.toArray(new IEnumerator[result.size()]);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||||
|
@ -23,7 +25,6 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayMap;
|
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||||
|
@ -217,15 +218,14 @@ class PDOMCPPEnumeration extends PDOMCPPBinding implements IPDOMCPPEnumType, IPD
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadEnumerators(final CharArrayMap<IPDOMCPPEnumerator> map) {
|
public void loadEnumerators(final List<IPDOMCPPEnumerator> enumerators) {
|
||||||
try {
|
try {
|
||||||
PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + OFFSET_ENUMERATOR_LIST);
|
PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + OFFSET_ENUMERATOR_LIST);
|
||||||
list.accept(new IPDOMVisitor() {
|
list.accept(new IPDOMVisitor() {
|
||||||
@Override
|
@Override
|
||||||
public boolean visit(IPDOMNode node) throws CoreException {
|
public boolean visit(IPDOMNode node) throws CoreException {
|
||||||
if (node instanceof IPDOMCPPEnumerator) {
|
if (node instanceof IPDOMCPPEnumerator) {
|
||||||
final IPDOMCPPEnumerator item = (IPDOMCPPEnumerator) node;
|
enumerators.add((IPDOMCPPEnumerator) node);
|
||||||
map.put(item.getNameCharArray(), item);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||||
|
@ -24,7 +26,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumerationSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumerationSpecialization;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayMap;
|
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||||
|
@ -224,15 +225,14 @@ class PDOMCPPEnumerationSpecialization extends PDOMCPPSpecialization
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadEnumerators(final CharArrayMap<IPDOMCPPEnumerator> map) {
|
public void loadEnumerators(final List<IPDOMCPPEnumerator> enumerators) {
|
||||||
try {
|
try {
|
||||||
PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + OFFSET_ENUMERATOR_LIST);
|
PDOMNodeLinkedList list = new PDOMNodeLinkedList(getLinkage(), record + OFFSET_ENUMERATOR_LIST);
|
||||||
list.accept(new IPDOMVisitor() {
|
list.accept(new IPDOMVisitor() {
|
||||||
@Override
|
@Override
|
||||||
public boolean visit(IPDOMNode node) throws CoreException {
|
public boolean visit(IPDOMNode node) throws CoreException {
|
||||||
if (node instanceof IPDOMCPPEnumerator) {
|
if (node instanceof IPDOMCPPEnumerator) {
|
||||||
final IPDOMCPPEnumerator item = (IPDOMCPPEnumerator) node;
|
enumerators.add((IPDOMCPPEnumerator) node);
|
||||||
map.put(item.getNameCharArray(), item);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue