mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +02:00
Testcase and fix for a parameter name resolution problem.
This commit is contained in:
parent
4fd6f1407b
commit
49b5fc416b
2 changed files with 29 additions and 3 deletions
|
@ -7302,4 +7302,23 @@ public class AST2Tests extends AST2BaseTest {
|
|||
td= bh.assertNonProblem("size_t", 0);
|
||||
assertEquals("unsigned long int", ASTTypeUtil.getType(td.getType()));
|
||||
}
|
||||
|
||||
// void f(int a) {
|
||||
// int tmp = a;
|
||||
// }
|
||||
// void f(int);
|
||||
public void testParameterResolution() throws Exception {
|
||||
final String code = getAboveComment();
|
||||
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
bh.assertNonProblem("f(int a)", 1);
|
||||
bh.assertNonProblem("f(int)", 1);
|
||||
bh.assertNonProblem("a;", 1);
|
||||
|
||||
bh= new BindingAssertionHelper(code, false);
|
||||
bh.assertNonProblem("f(int a)", 1);
|
||||
bh.assertNonProblem("f(int)", 1);
|
||||
bh.assertNonProblem("a;", 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -84,11 +84,10 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
|
|||
if (!(node instanceof IASTName))
|
||||
return;
|
||||
IASTName name = (IASTName) node;
|
||||
if (fDeclarations == null) {
|
||||
if (fDeclarations == null || fDeclarations.length == 0) {
|
||||
fDeclarations = new IASTName[] { name };
|
||||
} else {
|
||||
//keep the lowest offset declaration in[0]
|
||||
if (fDeclarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)fDeclarations[0]).getOffset()) {
|
||||
if (isDeclaredBefore((ASTNode)node, (ASTNode)fDeclarations[0])) {
|
||||
fDeclarations = (IASTName[]) ArrayUtil.prepend(IASTName.class, fDeclarations, name);
|
||||
} else {
|
||||
fDeclarations = (IASTName[]) ArrayUtil.append(IASTName.class, fDeclarations, name);
|
||||
|
@ -96,6 +95,14 @@ public class CPPParameter extends PlatformObject implements ICPPParameter, ICPPI
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isDeclaredBefore(ASTNode n1, ASTNode n2) {
|
||||
if (n1.getLength() == 0)
|
||||
return false;
|
||||
if (n2.getLength() == 0)
|
||||
return true;
|
||||
return n1.getOffset() < n2.getOffset();
|
||||
}
|
||||
|
||||
private IASTName getPrimaryDeclaration() {
|
||||
if (fDeclarations != null) {
|
||||
for (int i = 0; i < fDeclarations.length && fDeclarations[i] != null; i++) {
|
||||
|
|
Loading…
Add table
Reference in a new issue