mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 06:45:43 +02:00
Binding resolution with nested declarators, bug 294845.
This commit is contained in:
parent
4ca22ab897
commit
8370802243
2 changed files with 41 additions and 1 deletions
|
@ -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.ASTNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.CFunction;
|
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.CVisitor;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
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);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// /*
|
// /*
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
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.ASTNode;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
import org.eclipse.core.runtime.PlatformObject;
|
import org.eclipse.core.runtime.PlatformObject;
|
||||||
|
|
||||||
|
@ -165,7 +166,7 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (IASTDeclarator declarator : declarators) {
|
for (IASTDeclarator declarator : declarators) {
|
||||||
IASTName name = declarator.getName();
|
IASTName name = ASTQueries.findInnermostDeclarator(declarator).getName();
|
||||||
IBinding binding = name.resolveBinding();
|
IBinding binding = name.resolveBinding();
|
||||||
if (binding != null)
|
if (binding != null)
|
||||||
fields = (IField[]) ArrayUtil.append(IField.class, fields, binding);
|
fields = (IField[]) ArrayUtil.append(IField.class, fields, binding);
|
||||||
|
|
Loading…
Add table
Reference in a new issue