mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Revert "Bug 402498 - Apply declaredBefore() filtering to index bindings"
This reverts commit fbccef3ff1
.
Change-Id: I2b899750815200068dbe27b097f108b237d02447
This commit is contained in:
parent
b741fb552a
commit
35687baf43
7 changed files with 57 additions and 144 deletions
|
@ -8908,29 +8908,6 @@ public class AST2TemplateTests extends AST2TestBase {
|
|||
assertFalse(x.getType().isSameType(CommonCPPTypes.int_));
|
||||
}
|
||||
|
||||
// struct Cat { void meow(); };
|
||||
// struct Dog { void woof(); };
|
||||
//
|
||||
// template <typename T>
|
||||
// Dog bar(T);
|
||||
//
|
||||
// template <typename T>
|
||||
// auto foo(T t) -> decltype(bar(t));
|
||||
//
|
||||
// namespace N {
|
||||
// class A {};
|
||||
// }
|
||||
//
|
||||
// Cat bar(N::A);
|
||||
//
|
||||
// int main() {
|
||||
// auto x = foo(N::A());
|
||||
// x.woof();
|
||||
// }
|
||||
public void testUnqualifiedFunctionCallInTemplate_402498d() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// void bar();
|
||||
//
|
||||
// template <typename T>
|
||||
|
@ -8960,7 +8937,7 @@ public class AST2TemplateTests extends AST2TestBase {
|
|||
public void testUnqualifiedFunctionCallInTemplate_458316b() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
|
||||
// template <typename>
|
||||
// struct no_type {};
|
||||
//
|
||||
|
|
|
@ -2995,23 +2995,4 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
public void testBracedInitList_490475() throws Exception {
|
||||
checkBindings();
|
||||
}
|
||||
|
||||
// struct Cat { void meow(); };
|
||||
// struct Dog { void woof(); };
|
||||
|
||||
// template <typename T>
|
||||
// Dog bar(T);
|
||||
//
|
||||
// template <typename T>
|
||||
// auto foo(T t) -> decltype(bar(t));
|
||||
//
|
||||
// Cat bar(int);
|
||||
//
|
||||
// int main() {
|
||||
// auto x = foo(0);
|
||||
// x.woof();
|
||||
// }
|
||||
public void testUnqualifiedFunctionCallInTemplate_402498() throws Exception {
|
||||
checkBindings();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -279,17 +279,6 @@ public class CPPSemantics {
|
|||
// "a" => { null, "a", null }
|
||||
// ":: i" => { "::", "i", null }
|
||||
private static final Pattern QUALNAME_REGEX = Pattern.compile("^\\s*(::)?\\s*([^\\s:]+)\\s*(?:::(.*))?$"); //$NON-NLS-1$
|
||||
|
||||
// This flag controls whether name lookup is allowed to find bindings in headers
|
||||
// that are not reachable via includes from the file containing the name.
|
||||
// Generally this is not allowed, but certain consumers, such as IncludeOrganizer,
|
||||
// need it (since the whole point of IncludeOrganizer is to find missing headers).
|
||||
private static final ThreadLocal<Boolean> fAllowPromiscuousBindingResolution = new ThreadLocal<Boolean>() {
|
||||
@Override
|
||||
protected Boolean initialValue() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
static protected IBinding resolveBinding(IASTName name) {
|
||||
if (traceBindingResolution) {
|
||||
|
@ -1969,76 +1958,63 @@ public class CPPSemantics {
|
|||
}
|
||||
}
|
||||
|
||||
if (pointOfDecl < 0) {
|
||||
if (nd != null) {
|
||||
pointOfDecl = getPointOfDeclaration(nd);
|
||||
} else if (obj instanceof IIndexBinding && !fAllowPromiscuousBindingResolution.get()) {
|
||||
IIndexBinding indexBinding = ((IIndexBinding) obj);
|
||||
if (indexBinding instanceof ICPPMethod && ((ICPPMethod) indexBinding).isImplicit()) {
|
||||
return true;
|
||||
}
|
||||
IASTTranslationUnit tu = node.getTranslationUnit();
|
||||
IIndexFileSet indexFileSet = tu.getIndexFileSet();
|
||||
return (indexFileSet != null && indexFileSet.containsDeclaration(indexBinding));
|
||||
}
|
||||
if (pointOfDecl < 0 && nd != null) {
|
||||
ASTNodeProperty prop = nd.getPropertyInParent();
|
||||
if (prop == IASTDeclarator.DECLARATOR_NAME || nd instanceof IASTDeclarator) {
|
||||
// Point of declaration for a name is immediately after its complete declarator
|
||||
// and before its initializer.
|
||||
IASTDeclarator dtor = (IASTDeclarator)((nd instanceof IASTDeclarator) ? nd : nd.getParent());
|
||||
while (dtor.getParent() instanceof IASTDeclarator) {
|
||||
dtor = (IASTDeclarator) dtor.getParent();
|
||||
}
|
||||
IASTInitializer init = dtor.getInitializer();
|
||||
// [basic.scope.pdecl]/p9: The point of declaration for a template parameter
|
||||
// is immediately after its complete template-parameter.
|
||||
// Note: can't just check "dtor.getParent() instanceof ICPPASTTemplateParameter"
|
||||
// because function parameter declarations implement ICPPASTTemplateParameter too.
|
||||
boolean isTemplateParameter = dtor.getParent() instanceof ICPPASTTemplateParameter
|
||||
&& dtor.getParent().getPropertyInParent() == ICPPASTTemplateDeclaration.PARAMETER;
|
||||
if (init != null && !isTemplateParameter)
|
||||
pointOfDecl = ((ASTNode) init).getOffset() - 1;
|
||||
else
|
||||
pointOfDecl = ((ASTNode) dtor).getOffset() + ((ASTNode) dtor).getLength();
|
||||
} else if (prop == IASTEnumerator.ENUMERATOR_NAME) {
|
||||
// Point of declaration for an enumerator is immediately after it
|
||||
// enumerator-definition
|
||||
IASTEnumerator enumtor = (IASTEnumerator) nd.getParent();
|
||||
if (enumtor.getValue() != null) {
|
||||
ASTNode exp = (ASTNode) enumtor.getValue();
|
||||
pointOfDecl = exp.getOffset() + exp.getLength();
|
||||
} else {
|
||||
pointOfDecl = nd.getOffset() + nd.getLength();
|
||||
}
|
||||
} else if (prop == ICPPASTUsingDeclaration.NAME) {
|
||||
nd = (ASTNode) nd.getParent();
|
||||
pointOfDecl = nd.getOffset();
|
||||
} else if (prop == ICPPASTNamespaceAlias.ALIAS_NAME) {
|
||||
nd = (ASTNode) nd.getParent();
|
||||
pointOfDecl = nd.getOffset() + nd.getLength();
|
||||
} else if (prop == ICPPASTAliasDeclaration.ALIAS_NAME) {
|
||||
// [basic.scope.pdecl]/p3: The point of declaration of an alias or alias template
|
||||
// immediately follows the type-id to which the alias refers.
|
||||
ASTNode targetType = (ASTNode) ((ICPPASTAliasDeclaration) nd.getParent()).getMappingTypeId();
|
||||
pointOfDecl = targetType.getOffset() + targetType.getLength();
|
||||
} else if (prop == ICPPASTSimpleTypeTemplateParameter.PARAMETER_NAME
|
||||
|| prop == ICPPASTTemplatedTypeTemplateParameter.PARAMETER_NAME) {
|
||||
// [basic.scope.pdecl]/p9: The point of declaration for a template parameter
|
||||
// is immediately after its complete template-parameter.
|
||||
// Type and template template parameters are handled here;
|
||||
// non-type template parameters are handled in the DECLARATOR_NAME
|
||||
// case above.
|
||||
nd = (ASTNode) nd.getParent();
|
||||
pointOfDecl = nd.getOffset() + nd.getLength();
|
||||
} else {
|
||||
pointOfDecl = nd.getOffset() + nd.getLength();
|
||||
}
|
||||
}
|
||||
return (pointOfDecl < pointOfRef);
|
||||
}
|
||||
|
||||
private static int getPointOfDeclaration(ASTNode nd) {
|
||||
ASTNodeProperty prop = nd.getPropertyInParent();
|
||||
if (prop == IASTDeclarator.DECLARATOR_NAME || nd instanceof IASTDeclarator) {
|
||||
// Point of declaration for a name is immediately after its complete declarator
|
||||
// and before its initializer.
|
||||
IASTDeclarator dtor = (IASTDeclarator)((nd instanceof IASTDeclarator) ? nd : nd.getParent());
|
||||
while (dtor.getParent() instanceof IASTDeclarator)
|
||||
dtor = (IASTDeclarator) dtor.getParent();
|
||||
IASTInitializer init = dtor.getInitializer();
|
||||
// [basic.scope.pdecl]/p9: The point of declaration for a template parameter
|
||||
// is immediately after its complete template-parameter.
|
||||
// Note: can't just check "dtor.getParent() instanceof ICPPASTTemplateParameter"
|
||||
// because function parameter declarations implement ICPPASTTemplateParameter too.
|
||||
boolean isTemplateParameter = dtor.getParent() instanceof ICPPASTTemplateParameter
|
||||
&& dtor.getParent().getPropertyInParent() == ICPPASTTemplateDeclaration.PARAMETER;
|
||||
if (init != null && !isTemplateParameter)
|
||||
return ((ASTNode) init).getOffset() - 1;
|
||||
else
|
||||
return ((ASTNode) dtor).getOffset() + ((ASTNode) dtor).getLength();
|
||||
} else if (prop == IASTEnumerator.ENUMERATOR_NAME) {
|
||||
// Point of declaration for an enumerator is immediately after it
|
||||
// enumerator-definition
|
||||
IASTEnumerator enumtor = (IASTEnumerator) nd.getParent();
|
||||
if (enumtor.getValue() != null) {
|
||||
ASTNode exp = (ASTNode) enumtor.getValue();
|
||||
return exp.getOffset() + exp.getLength();
|
||||
} else {
|
||||
return nd.getOffset() + nd.getLength();
|
||||
}
|
||||
} else if (prop == ICPPASTUsingDeclaration.NAME) {
|
||||
nd = (ASTNode) nd.getParent();
|
||||
return nd.getOffset();
|
||||
} else if (prop == ICPPASTNamespaceAlias.ALIAS_NAME) {
|
||||
nd = (ASTNode) nd.getParent();
|
||||
return nd.getOffset() + nd.getLength();
|
||||
} else if (prop == ICPPASTAliasDeclaration.ALIAS_NAME) {
|
||||
// [basic.scope.pdecl]/p3: The point of declaration of an alias or alias template
|
||||
// immediately follows the type-id to which the alias refers.
|
||||
ASTNode targetType = (ASTNode) ((ICPPASTAliasDeclaration) nd.getParent()).getMappingTypeId();
|
||||
return targetType.getOffset() + targetType.getLength();
|
||||
} else if (prop == ICPPASTSimpleTypeTemplateParameter.PARAMETER_NAME
|
||||
|| prop == ICPPASTTemplatedTypeTemplateParameter.PARAMETER_NAME) {
|
||||
// [basic.scope.pdecl]/p9: The point of declaration for a template parameter
|
||||
// is immediately after its complete template-parameter.
|
||||
// Type and template template parameters are handled here;
|
||||
// non-type template parameters are handled in the DECLARATOR_NAME
|
||||
// case above.
|
||||
nd = (ASTNode) nd.getParent();
|
||||
return nd.getOffset() + nd.getLength();
|
||||
} else {
|
||||
return nd.getOffset() + nd.getLength();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean acceptDeclaredAfter(ICPPInternalBinding cpp) {
|
||||
try {
|
||||
if (cpp instanceof ICPPNamespace || cpp instanceof ICPPFunction || cpp instanceof ICPPVariable) {
|
||||
|
@ -4246,11 +4222,4 @@ public class CPPSemantics {
|
|||
|
||||
return binding;
|
||||
}
|
||||
|
||||
public static void enablePromiscuousBindingResolution() {
|
||||
fAllowPromiscuousBindingResolution.set(true);
|
||||
}
|
||||
public static void disablePromiscuousBindingResolution() {
|
||||
fAllowPromiscuousBindingResolution.set(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,7 +315,6 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
|
||||
// void foo() {}
|
||||
|
||||
// #include "header.h"
|
||||
// void bar() {
|
||||
// foo();
|
||||
// }
|
||||
|
@ -334,7 +333,6 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
|
||||
// void foo() {}
|
||||
|
||||
// #include "header.h"
|
||||
// void bar() {foo();foo();foo();}
|
||||
public void testNewResultsOnSearchAgainB() throws Exception {
|
||||
CSearchQuery query= makeProjectQuery("foo");
|
||||
|
@ -342,7 +340,7 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
assertOccurrences(query, 4);
|
||||
|
||||
// whitespace s.t. new match offset is same as older
|
||||
String newContent= "#include \"header.h\"\nvoid bar() { foo(); }";
|
||||
String newContent= "void bar() { foo(); }";
|
||||
IFile file = fCProject.getProject().getFile(new Path("references.cpp"));
|
||||
file.setContents(new ByteArrayInputStream(newContent.getBytes()), IResource.FORCE, npm());
|
||||
runEventQueue(1000);
|
||||
|
@ -352,7 +350,7 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
|
||||
assertOccurrences(query, 2);
|
||||
|
||||
String newContent2= "#include \"header.h\"\nvoid bar() {foo(); foo();}";
|
||||
String newContent2= "void bar() {foo(); foo();}";
|
||||
file.setContents(new ByteArrayInputStream(newContent2.getBytes()), IResource.FORCE, npm());
|
||||
waitForIndexer(fCProject);
|
||||
|
||||
|
@ -364,7 +362,6 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
// template<typename T> void f(T) {};
|
||||
// template<typename T> void f(T*) {};
|
||||
|
||||
// #include "header.h"
|
||||
// void a() {
|
||||
// CT<int>* r1;
|
||||
// CT<char>* r2;
|
||||
|
|
|
@ -184,7 +184,6 @@ public class CPPSelectionTestsIndexer extends BaseSelectionTestsIndexer {
|
|||
// public: void assign(const T* s) {}
|
||||
// };
|
||||
|
||||
// #include "testTemplateClassMethod.h"
|
||||
// void main() {
|
||||
// C<char> a;
|
||||
// a.assign("aaa");
|
||||
|
@ -1176,7 +1175,6 @@ public class CPPSelectionTestsIndexer extends BaseSelectionTestsIndexer {
|
|||
// T operator+(int);
|
||||
// };
|
||||
|
||||
// #include "test.h"
|
||||
// void main() {
|
||||
// C<char> a;
|
||||
// a + 2;
|
||||
|
|
|
@ -977,15 +977,7 @@ public class BindingClassifier {
|
|||
if (fAst == null) {
|
||||
fAst = node.getTranslationUnit();
|
||||
}
|
||||
try {
|
||||
// Enable promiscuous binding resolution for this AST traversal,
|
||||
// to allow names to be resolved even if the declarations of their
|
||||
// target bindings are in a header not reachable via includes.
|
||||
CPPSemantics.enablePromiscuousBindingResolution();
|
||||
node.accept(fBindingCollector);
|
||||
} finally {
|
||||
CPPSemantics.disablePromiscuousBindingResolution();
|
||||
}
|
||||
node.accept(fBindingCollector);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,7 +92,6 @@ public class QmlRegistrationTests extends BaseQtTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
// #include "junit-QObject.hh"
|
||||
// class T;
|
||||
//
|
||||
// static void func()
|
||||
|
|
Loading…
Add table
Reference in a new issue