mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Plain C: nested declarators for fields, bug 257540.
This commit is contained in:
parent
4ad132f821
commit
d5d62baf17
3 changed files with 77 additions and 79 deletions
|
@ -5581,4 +5581,17 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertEquals(0, children[0].getChildren().length);
|
assertEquals(0, children[0].getChildren().length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct s {
|
||||||
|
// int (mem);
|
||||||
|
// };
|
||||||
|
// void foo() {
|
||||||
|
// struct s v;
|
||||||
|
// v.mem = 1;
|
||||||
|
// }
|
||||||
|
public void testNestedDeclarator_Bug257540() throws Exception {
|
||||||
|
final String code= getAboveComment();
|
||||||
|
parseAndCheckBindings(code, ParserLanguage.C);
|
||||||
|
parseAndCheckBindings(code, ParserLanguage.CPP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTElaboratedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
|
||||||
|
@ -156,9 +157,6 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
|
||||||
return (IField[]) ArrayUtil.trim( IField.class, fields );
|
return (IField[]) ArrayUtil.trim( IField.class, fields );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.core.dom.ast.ICompositeType#findField(org.eclipse.cdt.core.dom.ast.IASTName)
|
|
||||||
*/
|
|
||||||
public IField findField(String name) throws DOMException {
|
public IField findField(String name) throws DOMException {
|
||||||
if (definition == null) {
|
if (definition == null) {
|
||||||
ICASTCompositeTypeSpecifier temp = checkForDefinition((IASTElaboratedTypeSpecifier) declarations[0].getParent());
|
ICASTCompositeTypeSpecifier temp = checkForDefinition((IASTElaboratedTypeSpecifier) declarations[0].getParent());
|
||||||
|
@ -167,9 +165,10 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
|
||||||
definition = temp.getName();
|
definition = temp.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final char[] nchars= name.toCharArray();
|
||||||
ICCompositeTypeScope scope = (ICCompositeTypeScope) getCompositeScope();
|
ICCompositeTypeScope scope = (ICCompositeTypeScope) getCompositeScope();
|
||||||
if (scope != null && ASTInternal.isFullyCached(scope)) {
|
if (scope != null && ASTInternal.isFullyCached(scope)) {
|
||||||
IBinding binding = scope.getBinding( name.toCharArray() );
|
IBinding binding = scope.getBinding(nchars);
|
||||||
if (binding instanceof IField)
|
if (binding instanceof IField)
|
||||||
return (IField) binding;
|
return (IField) binding;
|
||||||
} else {
|
} else {
|
||||||
|
@ -186,16 +185,16 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
|
||||||
IASTDeclarator[] declarators = ((IASTSimpleDeclaration) node).getDeclarators();
|
IASTDeclarator[] declarators = ((IASTSimpleDeclaration) node).getDeclarators();
|
||||||
for (int j = 0; j < declarators.length; j++) {
|
for (int j = 0; j < declarators.length; j++) {
|
||||||
IASTDeclarator declarator = declarators[j];
|
IASTDeclarator declarator = declarators[j];
|
||||||
IASTName dtorName = declarator.getName();
|
IASTName dtorName = CVisitor.findInnermostDeclarator(declarator).getName();
|
||||||
if (scope != null)
|
if (scope != null)
|
||||||
ASTInternal.addName(scope, dtorName);
|
ASTInternal.addName(scope, dtorName);
|
||||||
if( name.equals( dtorName.toString() ) ){
|
if (CharArrayUtils.equals(nchars, dtorName.toCharArray())) {
|
||||||
IBinding binding = dtorName.resolveBinding();
|
IBinding binding = dtorName.resolveBinding();
|
||||||
if (binding instanceof IField)
|
if (binding instanceof IField)
|
||||||
found = (IField) binding;
|
found = (IField) binding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//anonymous structurs and unions
|
// anonymous structures and unions
|
||||||
if (declarators.length == 0 && ((IASTSimpleDeclaration) node).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) {
|
if (declarators.length == 0 && ((IASTSimpleDeclaration) node).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) {
|
||||||
IASTCompositeTypeSpecifier declSpec = (IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) node).getDeclSpecifier();
|
IASTCompositeTypeSpecifier declSpec = (IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) node).getDeclSpecifier();
|
||||||
IASTName n = declSpec.getName();
|
IASTName n = declSpec.getName();
|
||||||
|
|
|
@ -886,32 +886,18 @@ public class CVisitor {
|
||||||
|
|
||||||
private static IBinding createBinding(IASTDeclarator declarator) {
|
private static IBinding createBinding(IASTDeclarator declarator) {
|
||||||
IASTNode parent = declarator.getParent();
|
IASTNode parent = declarator.getParent();
|
||||||
|
|
||||||
while (parent instanceof IASTDeclarator) {
|
while (parent instanceof IASTDeclarator) {
|
||||||
parent = parent.getParent();
|
parent = parent.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (declarator.getNestedDeclarator() != null)
|
declarator= CVisitor.findInnermostDeclarator(declarator);
|
||||||
declarator = declarator.getNestedDeclarator();
|
IASTDeclarator typeRelevant= CVisitor.findTypeRelevantDeclarator(declarator);
|
||||||
|
|
||||||
IASTFunctionDeclarator funcDeclarator= null;
|
IASTFunctionDeclarator funcDeclarator= null;
|
||||||
IASTNode node= declarator;
|
if (typeRelevant instanceof IASTFunctionDeclarator) {
|
||||||
do {
|
funcDeclarator= (IASTFunctionDeclarator) typeRelevant;
|
||||||
if (node instanceof IASTFunctionDeclarator) {
|
|
||||||
funcDeclarator= (IASTFunctionDeclarator) node;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (((IASTDeclarator) node).getPointerOperators().length > 0 ||
|
|
||||||
node.getPropertyInParent() != IASTDeclarator.NESTED_DECLARATOR) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
node= node.getParent();
|
|
||||||
}
|
|
||||||
while (node instanceof IASTDeclarator)
|
|
||||||
;
|
|
||||||
|
|
||||||
IScope scope= getContainingScope(parent);
|
IScope scope= getContainingScope(parent);
|
||||||
|
|
||||||
ASTNodeProperty prop = parent.getPropertyInParent();
|
ASTNodeProperty prop = parent.getPropertyInParent();
|
||||||
if (prop == IASTDeclarationStatement.DECLARATION) {
|
if (prop == IASTDeclarationStatement.DECLARATION) {
|
||||||
//implicit scope, see 6.8.4-3
|
//implicit scope, see 6.8.4-3
|
||||||
|
|
Loading…
Add table
Reference in a new issue