1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 417143 - Organize Includes removes include of the header declaring a

variable.
This commit is contained in:
Sergey Prigogin 2013-09-12 16:04:05 -07:00
parent b46b4962a1
commit 79cd2757f5
4 changed files with 36 additions and 11 deletions

View file

@ -349,7 +349,8 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
assertDeclared("B");
}
// int a;
// typedef unsigned int size_t;
// size_t a;
// void test() {
// void* x = &a;
@ -362,7 +363,7 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
// struct A {
// void operator()(int p);
// };
// const A& a;
// A a;
// void test() {
// a(1);

View file

@ -456,6 +456,23 @@ public class IncludeOrganizerTest extends IncludesTestBase {
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
//namespace ns3 {
//class C {};

View file

@ -314,8 +314,6 @@ public class BindingClassifier {
} else {
bindings.add(binding);
}
// Resolve the type of the variable.
binding = getTypeBinding(((IVariable) binding).getType());
} else if (binding instanceof IType) {
// Resolve the type.
binding = getTypeBinding((IType) binding);
@ -392,12 +390,14 @@ public class BindingClassifier {
if (fAst.getDeclarationsInAST(binding).length != 0)
return; // Declared locally.
if (!canForwardDeclare(binding))
defineBinding(binding);
if (!fProcessedDeclaredBindings.add(binding))
return;
if (!canForwardDeclare(binding)) {
defineBinding(binding);
return;
}
List<IBinding> requiredBindings = getRequiredBindings(binding);
for (IBinding requiredBinding : requiredBindings) {
@ -1050,8 +1050,10 @@ public class BindingClassifier {
IBinding binding = ((IASTIdExpression) functionNameExpression).getName().resolveBinding();
if (binding instanceof IFunction) {
declareFunction((IFunction) binding, functionCallExpression);
} else if (binding instanceof IType) {
defineBinding(binding);
} else {
if (binding instanceof IType)
defineBinding(binding);
if (functionCallExpression instanceof IASTImplicitNameOwner) {
IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) functionCallExpression).getImplicitNames();
for (IASTName name : implicitNames) {

View file

@ -1008,12 +1008,17 @@ public class IncludeOrganizer {
indexNames[indexNames.length - 1] = indexName;
}
}
} else if (allowDeclarations || binding instanceof IFunction) {
// For functions we need to include the declaration.
} else if (allowDeclarations || binding instanceof IFunction || binding instanceof IVariable) {
// For functions and variables we need to include a declaration.
indexNames = index.findDeclarations(binding);
} else {
// For all other bindings we need to include the definition.
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) {