mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +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);
|
td= bh.assertNonProblem("size_t", 0);
|
||||||
assertEquals("unsigned long int", ASTTypeUtil.getType(td.getType()));
|
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))
|
if (!(node instanceof IASTName))
|
||||||
return;
|
return;
|
||||||
IASTName name = (IASTName) node;
|
IASTName name = (IASTName) node;
|
||||||
if (fDeclarations == null) {
|
if (fDeclarations == null || fDeclarations.length == 0) {
|
||||||
fDeclarations = new IASTName[] { name };
|
fDeclarations = new IASTName[] { name };
|
||||||
} else {
|
} else {
|
||||||
//keep the lowest offset declaration in[0]
|
if (isDeclaredBefore((ASTNode)node, (ASTNode)fDeclarations[0])) {
|
||||||
if (fDeclarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)fDeclarations[0]).getOffset()) {
|
|
||||||
fDeclarations = (IASTName[]) ArrayUtil.prepend(IASTName.class, fDeclarations, name);
|
fDeclarations = (IASTName[]) ArrayUtil.prepend(IASTName.class, fDeclarations, name);
|
||||||
} else {
|
} else {
|
||||||
fDeclarations = (IASTName[]) ArrayUtil.append(IASTName.class, fDeclarations, name);
|
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() {
|
private IASTName getPrimaryDeclaration() {
|
||||||
if (fDeclarations != null) {
|
if (fDeclarations != null) {
|
||||||
for (int i = 0; i < fDeclarations.length && fDeclarations[i] != null; i++) {
|
for (int i = 0; i < fDeclarations.length && fDeclarations[i] != null; i++) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue