1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 09:55:29 +02:00

Binding resolution with nested declarators, bug 294845.

This commit is contained in:
Markus Schorn 2009-11-11 14:45:13 +00:00
parent 4ca22ab897
commit 8370802243
2 changed files with 41 additions and 1 deletions

View file

@ -109,6 +109,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.c.CFunction;
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding;
import org.eclipse.cdt.internal.core.parser.ParserException;
/**
@ -6963,6 +6964,44 @@ public class AST2Tests extends AST2BaseTest {
assertTrue(((IFunction)n.resolveBinding()).getType().getParameterTypes()[0] instanceof IPointerType);
}
}
//
// extern void goo();
// struct MyStruct {
// int a;
// void (*ptr)();
// };
// void foo() {
// struct MyStruct structure;
// structure.a = 1;
// structure.ptr = goo;
// }
//
public void testBindingsOnFields() throws Exception {
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.C, false);
IASTCompoundStatement bodyStmt = (IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[2]).getBody();
// Get the IFields bindings from the type used in the declaration of structure
IASTName n = ((IASTSimpleDeclaration)((IASTDeclarationStatement)bodyStmt.getStatements()[0]).getDeclaration()).getDeclarators()[0].getName();
ICompositeType t = (ICompositeType)((IVariable)n.resolveBinding()).getType();
IField[] fields = t.getFields();
assertTrue( fields.length ==2 );
// Get the IField for the first assignment
IASTFieldReference ref1 = (IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement)bodyStmt.getStatements()[1]).getExpression()).getOperand1();
IBinding field1 = ref1.getFieldName().resolveBinding();
// Get the IField for the second assignment
IASTFieldReference ref2 = (IASTFieldReference)((IASTBinaryExpression)((IASTExpressionStatement)bodyStmt.getStatements()[2]).getExpression()).getOperand1();
IBinding field2 = ref2.getFieldName().resolveBinding();
// Compare the IField from the type and the assignments
assertEquals( fields[0], field1);
assertEquals( fields[1], field2); // fails
assertEquals(1, ((ICInternalBinding) field1).getDeclarations().length);
assertEquals(1, ((ICInternalBinding) field2).getDeclarations().length);
}
// /*

View file

@ -37,6 +37,7 @@ import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.PlatformObject;
@ -165,7 +166,7 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
}
} else {
for (IASTDeclarator declarator : declarators) {
IASTName name = declarator.getName();
IASTName name = ASTQueries.findInnermostDeclarator(declarator).getName();
IBinding binding = name.resolveBinding();
if (binding != null)
fields = (IField[]) ArrayUtil.append(IField.class, fields, binding);