mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Bug 45203. Added more tests and fixed issues uncovered by them.
This commit is contained in:
parent
4726136341
commit
2cb5f8a29a
2 changed files with 21 additions and 9 deletions
|
@ -243,8 +243,18 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
||||||
// #define MACRO(t1, v1, t2, v3, t4, v4) t1 v1; t2 b; C v3; prefix##t4 v4
|
// #define MACRO(t1, v1, t2, v3, t4, v4) t1 v1; t2 b; C v3; prefix##t4 v4
|
||||||
|
|
||||||
// MACRO(A, a, B, c, D, d);
|
// MACRO(A, a, B, c, D, d);
|
||||||
public void testMacro() throws Exception {
|
public void testMacro_1() throws Exception {
|
||||||
assertDefined("A", "B", "MACRO");
|
assertDefined("A", "B", "MACRO");
|
||||||
assertDeclared();
|
assertDeclared();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typedef int INT;
|
||||||
|
// #define MACRO(x) extern INT x
|
||||||
|
|
||||||
|
// MACRO(a);
|
||||||
|
// INT b;
|
||||||
|
public void testMacro_2() throws Exception {
|
||||||
|
assertDefined("MACRO", "INT"); // INT has to be defined because it is used outside of MACRO.
|
||||||
|
assertDeclared();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,6 +271,9 @@ public class BindingClassifier {
|
||||||
if (fProcessedDefinedBindings.contains(binding))
|
if (fProcessedDefinedBindings.contains(binding))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (fAst.getDeclarationsInAST(binding).length != 0)
|
||||||
|
return; // Declared locally
|
||||||
|
|
||||||
if (!canForwardDeclare(binding))
|
if (!canForwardDeclare(binding))
|
||||||
defineBinding(binding);
|
defineBinding(binding);
|
||||||
|
|
||||||
|
@ -318,7 +321,8 @@ public class BindingClassifier {
|
||||||
} else if (binding instanceof IFunction && !(binding instanceof ICPPMethod)) {
|
} else if (binding instanceof IFunction && !(binding instanceof ICPPMethod)) {
|
||||||
canDeclare = fPreferences.forwardDeclareFunctions;
|
canDeclare = fPreferences.forwardDeclareFunctions;
|
||||||
} else if (binding instanceof IVariable) {
|
} else if (binding instanceof IVariable) {
|
||||||
canDeclare = fPreferences.forwardDeclareExternalVariables;
|
if (((IVariable) binding).isExtern())
|
||||||
|
canDeclare = fPreferences.forwardDeclareExternalVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canDeclare && !fPreferences.forwardDeclareTemplates
|
if (canDeclare && !fPreferences.forwardDeclareTemplates
|
||||||
|
@ -364,9 +368,8 @@ public class BindingClassifier {
|
||||||
if (!markAsDefined(binding))
|
if (!markAsDefined(binding))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fAst.getDefinitionsInAST(binding).length != 0) {
|
if (fAst.getDefinitionsInAST(binding).length != 0)
|
||||||
return; // Defined locally
|
return; // Defined locally
|
||||||
}
|
|
||||||
|
|
||||||
List<IBinding> requiredBindings = getRequiredBindings(binding);
|
List<IBinding> requiredBindings = getRequiredBindings(binding);
|
||||||
for (IBinding requiredBinding : requiredBindings) {
|
for (IBinding requiredBinding : requiredBindings) {
|
||||||
|
@ -381,11 +384,8 @@ public class BindingClassifier {
|
||||||
|
|
||||||
private void defineBindingForName(IASTName name) {
|
private void defineBindingForName(IASTName name) {
|
||||||
IBinding binding = name.resolveBinding();
|
IBinding binding = name.resolveBinding();
|
||||||
if (isPartOfExternalMacroDefinition(name)) {
|
if (!isPartOfExternalMacroDefinition(name))
|
||||||
markAsDefined(binding);
|
|
||||||
} else {
|
|
||||||
defineBinding(binding);
|
defineBinding(binding);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -432,7 +432,6 @@ public class BindingClassifier {
|
||||||
private class BindingCollector extends ASTVisitor {
|
private class BindingCollector extends ASTVisitor {
|
||||||
BindingCollector() {
|
BindingCollector() {
|
||||||
super(true);
|
super(true);
|
||||||
shouldVisitImplicitNames = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -996,6 +995,9 @@ public class BindingClassifier {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTName name) {
|
public int visit(IASTName name) {
|
||||||
|
if (isPartOfExternalMacroDefinition(name))
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
|
||||||
// Add the binding associated with the name to the bindings that can be declared
|
// Add the binding associated with the name to the bindings that can be declared
|
||||||
// (we assume that all bindings which have to be defined are already explicitly handled
|
// (we assume that all bindings which have to be defined are already explicitly handled
|
||||||
// elsewhere).
|
// elsewhere).
|
||||||
|
|
Loading…
Add table
Reference in a new issue