mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Bug 417143 - Organize Includes removes include of the header declaring a
variable.
This commit is contained in:
parent
b46b4962a1
commit
79cd2757f5
4 changed files with 36 additions and 11 deletions
|
@ -349,7 +349,8 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
||||||
assertDeclared("B");
|
assertDeclared("B");
|
||||||
}
|
}
|
||||||
|
|
||||||
// int a;
|
// typedef unsigned int size_t;
|
||||||
|
// size_t a;
|
||||||
|
|
||||||
// void test() {
|
// void test() {
|
||||||
// void* x = &a;
|
// void* x = &a;
|
||||||
|
@ -362,7 +363,7 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
||||||
// struct A {
|
// struct A {
|
||||||
// void operator()(int p);
|
// void operator()(int p);
|
||||||
// };
|
// };
|
||||||
// const A& a;
|
// A a;
|
||||||
|
|
||||||
// void test() {
|
// void test() {
|
||||||
// a(1);
|
// a(1);
|
||||||
|
|
|
@ -456,6 +456,23 @@ public class IncludeOrganizerTest extends IncludesTestBase {
|
||||||
assertExpectedResults();
|
assertExpectedResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//h1.h
|
||||||
|
//typedef int int32;
|
||||||
|
|
||||||
|
//h2.h
|
||||||
|
//#include "h1.h"
|
||||||
|
//extern int32 var;
|
||||||
|
|
||||||
|
//source.cpp
|
||||||
|
//int a = var;
|
||||||
|
//====================
|
||||||
|
//#include "h2.h"
|
||||||
|
//
|
||||||
|
//int a = var;
|
||||||
|
public void testVariableReference() throws Exception {
|
||||||
|
assertExpectedResults();
|
||||||
|
}
|
||||||
|
|
||||||
//h1.h
|
//h1.h
|
||||||
//namespace ns3 {
|
//namespace ns3 {
|
||||||
//class C {};
|
//class C {};
|
||||||
|
|
|
@ -314,8 +314,6 @@ public class BindingClassifier {
|
||||||
} else {
|
} else {
|
||||||
bindings.add(binding);
|
bindings.add(binding);
|
||||||
}
|
}
|
||||||
// Resolve the type of the variable.
|
|
||||||
binding = getTypeBinding(((IVariable) binding).getType());
|
|
||||||
} else if (binding instanceof IType) {
|
} else if (binding instanceof IType) {
|
||||||
// Resolve the type.
|
// Resolve the type.
|
||||||
binding = getTypeBinding((IType) binding);
|
binding = getTypeBinding((IType) binding);
|
||||||
|
@ -392,12 +390,14 @@ public class BindingClassifier {
|
||||||
if (fAst.getDeclarationsInAST(binding).length != 0)
|
if (fAst.getDeclarationsInAST(binding).length != 0)
|
||||||
return; // Declared locally.
|
return; // Declared locally.
|
||||||
|
|
||||||
if (!canForwardDeclare(binding))
|
|
||||||
defineBinding(binding);
|
|
||||||
|
|
||||||
if (!fProcessedDeclaredBindings.add(binding))
|
if (!fProcessedDeclaredBindings.add(binding))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!canForwardDeclare(binding)) {
|
||||||
|
defineBinding(binding);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<IBinding> requiredBindings = getRequiredBindings(binding);
|
List<IBinding> requiredBindings = getRequiredBindings(binding);
|
||||||
|
|
||||||
for (IBinding requiredBinding : requiredBindings) {
|
for (IBinding requiredBinding : requiredBindings) {
|
||||||
|
@ -1050,8 +1050,10 @@ public class BindingClassifier {
|
||||||
IBinding binding = ((IASTIdExpression) functionNameExpression).getName().resolveBinding();
|
IBinding binding = ((IASTIdExpression) functionNameExpression).getName().resolveBinding();
|
||||||
if (binding instanceof IFunction) {
|
if (binding instanceof IFunction) {
|
||||||
declareFunction((IFunction) binding, functionCallExpression);
|
declareFunction((IFunction) binding, functionCallExpression);
|
||||||
} else if (binding instanceof IType) {
|
} else {
|
||||||
defineBinding(binding);
|
if (binding instanceof IType)
|
||||||
|
defineBinding(binding);
|
||||||
|
|
||||||
if (functionCallExpression instanceof IASTImplicitNameOwner) {
|
if (functionCallExpression instanceof IASTImplicitNameOwner) {
|
||||||
IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) functionCallExpression).getImplicitNames();
|
IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) functionCallExpression).getImplicitNames();
|
||||||
for (IASTName name : implicitNames) {
|
for (IASTName name : implicitNames) {
|
||||||
|
|
|
@ -1008,12 +1008,17 @@ public class IncludeOrganizer {
|
||||||
indexNames[indexNames.length - 1] = indexName;
|
indexNames[indexNames.length - 1] = indexName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (allowDeclarations || binding instanceof IFunction) {
|
} else if (allowDeclarations || binding instanceof IFunction || binding instanceof IVariable) {
|
||||||
// For functions we need to include the declaration.
|
// For functions and variables we need to include a declaration.
|
||||||
indexNames = index.findDeclarations(binding);
|
indexNames = index.findDeclarations(binding);
|
||||||
} else {
|
} else {
|
||||||
// For all other bindings we need to include the definition.
|
// For all other bindings we need to include the definition.
|
||||||
indexNames = index.findDefinitions(binding);
|
indexNames = index.findDefinitions(binding);
|
||||||
|
if (indexNames.length == 0) {
|
||||||
|
// If we could not find any definitions, there is still a chance that
|
||||||
|
// a declaration would be sufficient.
|
||||||
|
indexNames = index.findDeclarations(binding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexNames.length != 0) {
|
if (indexNames.length != 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue