mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Anonymous unions and structs, bug 216791.
This commit is contained in:
parent
a39c03d796
commit
9cd75c484e
7 changed files with 150 additions and 24 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -22,9 +22,11 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
|||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
|
||||
/**
|
||||
|
@ -327,4 +329,46 @@ public class IndexCBindingResolutionBugs extends IndexBindingResolutionTestBase
|
|||
assertTrue(tAST.isSameType(tIndex));
|
||||
assertTrue(tIndex.isSameType(tAST));
|
||||
}
|
||||
|
||||
// struct outer {
|
||||
// union {
|
||||
// int var1;
|
||||
// };
|
||||
// };
|
||||
|
||||
// #include "header.h"
|
||||
// void test() {
|
||||
// struct outer x;
|
||||
// x.var1=1;
|
||||
// }
|
||||
public void testAnonymousUnion_Bug216791() throws DOMException {
|
||||
// struct
|
||||
IBinding b = getBindingFromASTName("var1=", 4);
|
||||
assertTrue(b instanceof IField);
|
||||
IField f= (IField) b;
|
||||
IScope outer= f.getCompositeTypeOwner().getScope();
|
||||
assertTrue(outer instanceof ICCompositeTypeScope);
|
||||
assertEquals("outer", outer.getScopeName().toString());
|
||||
}
|
||||
|
||||
// union outer {
|
||||
// struct {
|
||||
// int var1;
|
||||
// };
|
||||
// };
|
||||
|
||||
// #include "header.h"
|
||||
// void test() {
|
||||
// union outer x;
|
||||
// x.var1=1;
|
||||
// }
|
||||
public void testAnonymousStruct_Bug216791() throws DOMException {
|
||||
// struct
|
||||
IBinding b = getBindingFromASTName("var1=", 4);
|
||||
assertTrue(b instanceof IField);
|
||||
IField f= (IField) b;
|
||||
IScope outer= f.getCompositeTypeOwner().getScope();
|
||||
assertTrue(outer instanceof ICCompositeTypeScope);
|
||||
assertEquals("outer", outer.getScopeName().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,14 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
|
||||
|
@ -708,4 +710,46 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
|
|||
assertTrue(cl instanceof ICPPClassType);
|
||||
assertEquals("BAR", cl.getScope().getScopeName().toString());
|
||||
}
|
||||
|
||||
// struct outer {
|
||||
// union {
|
||||
// int var1;
|
||||
// };
|
||||
// };
|
||||
|
||||
// #include "header.h"
|
||||
// void test() {
|
||||
// struct outer x;
|
||||
// x.var1=1;
|
||||
// }
|
||||
public void testAnonymousUnion_Bug216791() throws DOMException {
|
||||
// struct
|
||||
IBinding b = getBindingFromASTName("var1=", 4);
|
||||
assertTrue(b instanceof IField);
|
||||
IField f= (IField) b;
|
||||
IScope outer= f.getCompositeTypeOwner().getScope();
|
||||
assertTrue(outer instanceof ICPPClassScope);
|
||||
assertEquals("outer", outer.getScopeName().toString());
|
||||
}
|
||||
|
||||
// union outer {
|
||||
// struct {
|
||||
// int var1;
|
||||
// };
|
||||
// };
|
||||
|
||||
// #include "header.h"
|
||||
// void test() {
|
||||
// union outer x;
|
||||
// x.var1=1;
|
||||
// }
|
||||
public void testAnonymousStruct_Bug216791() throws DOMException {
|
||||
// struct
|
||||
IBinding b = getBindingFromASTName("var1=", 4);
|
||||
assertTrue(b instanceof IField);
|
||||
IField f= (IField) b;
|
||||
IScope outer= f.getCompositeTypeOwner().getScope();
|
||||
assertTrue(outer instanceof ICPPClassScope);
|
||||
assertEquals("outer", outer.getScopeName().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Symbian Software Systems and others.
|
||||
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -189,6 +189,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
stateCount[0]++;
|
||||
}
|
||||
};
|
||||
CCorePlugin.getIndexManager().joinIndexer(8000, new NullProgressMonitor());
|
||||
CCorePlugin.getIndexManager().addIndexerStateListener(listener);
|
||||
|
||||
URL url= FileLocator.find(CTestPlugin.getDefault().getBundle(), new Path(locProject1), null);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||
import org.eclipse.cdt.core.dom.IPDOMVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IString;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -32,8 +33,9 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
|
|||
private final boolean caseSensitive;
|
||||
private IProgressMonitor monitor= null;
|
||||
private int monitorCheckCounter= 0;
|
||||
private boolean visitAnonymousClassTypes= false;
|
||||
|
||||
private List nodes = new ArrayList();
|
||||
private List<PDOMNamedNode> nodes = new ArrayList<PDOMNamedNode>();
|
||||
|
||||
/**
|
||||
* Collects all nodes with given name.
|
||||
|
@ -61,6 +63,10 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
|
|||
monitor= pm;
|
||||
}
|
||||
|
||||
public void setVisitAnonymousClassTypes(boolean val) {
|
||||
visitAnonymousClassTypes= val;
|
||||
}
|
||||
|
||||
final public int compare(int record) throws CoreException {
|
||||
if (monitor != null)
|
||||
checkCancelled();
|
||||
|
@ -110,12 +116,12 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
|
|||
return true; // look for more
|
||||
}
|
||||
|
||||
final protected List getNodeList() {
|
||||
final protected List<PDOMNamedNode> getNodeList() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
final public PDOMNamedNode[] getNodes() {
|
||||
return (PDOMNamedNode[])nodes.toArray(new PDOMNamedNode[nodes.size()]);
|
||||
return nodes.toArray(new PDOMNamedNode[nodes.size()]);
|
||||
}
|
||||
|
||||
final public boolean visit(IPDOMNode node) throws CoreException {
|
||||
|
@ -127,6 +133,14 @@ public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
|
|||
if (compare(pb.getDBName()) == 0) {
|
||||
addNode(pb);
|
||||
}
|
||||
else if (visitAnonymousClassTypes) {
|
||||
if (pb instanceof ICompositeType) {
|
||||
char[] nchars= pb.getNameCharArray();
|
||||
if (nchars.length > 0 && nchars[0] == '{') {
|
||||
return true; // visit children
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false; // don't visit children
|
||||
}
|
||||
|
|
|
@ -34,9 +34,11 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.internal.core.Util;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
|
||||
|
@ -83,16 +85,15 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
|
|||
}
|
||||
}
|
||||
else {
|
||||
// assign names to anonymous types.
|
||||
binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(binding);
|
||||
if (binding == null || binding instanceof IParameter)
|
||||
return null; // skip parameters
|
||||
|
||||
PDOMNode parent = getAdaptedParent(binding);
|
||||
if (parent == null)
|
||||
return null;
|
||||
|
||||
// assign names to anonymous types.
|
||||
binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(binding);
|
||||
|
||||
if (binding == null || binding instanceof IParameter)
|
||||
return null; // skip parameters
|
||||
|
||||
if (binding instanceof IField) { // must be before IVariable
|
||||
if (parent instanceof IPDOMMemberOwner)
|
||||
pdomBinding = new PDOMCField(pdom, (IPDOMMemberOwner)parent, (IField) binding);
|
||||
|
@ -224,18 +225,33 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
|
|||
IBinding scopeBinding = null;
|
||||
if (scopeNode instanceof IASTCompoundStatement) {
|
||||
return null;
|
||||
} else if (scopeNode instanceof IASTTranslationUnit) {
|
||||
return this;
|
||||
} else {
|
||||
IName scopeName = scope.getScopeName();
|
||||
if (scopeName instanceof IASTName) {
|
||||
scopeBinding = ((IASTName) scopeName).resolveBinding();
|
||||
}
|
||||
if (scopeNode instanceof IASTTranslationUnit) {
|
||||
boolean isGlobal= true;
|
||||
if (binding instanceof ICompositeType) {
|
||||
ICompositeType ct= (ICompositeType) binding;
|
||||
final IScope ctscope = ct.getCompositeScope();
|
||||
if (ctscope != null) {
|
||||
final IName myOrigScopeName = ctscope.getScopeName();
|
||||
if (myOrigScopeName instanceof IASTName && myOrigScopeName.toCharArray().length == 0) {
|
||||
scope= CVisitor.getContainingScope((IASTName) myOrigScopeName);
|
||||
if (scope instanceof ICCompositeTypeScope) {
|
||||
isGlobal= false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isGlobal) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
IName scopeName = scope.getScopeName();
|
||||
if (scopeName instanceof IASTName) {
|
||||
scopeBinding = ((IASTName) scopeName).resolveBinding();
|
||||
if (scopeBinding != null && scopeBinding != binding) {
|
||||
return adaptBinding(scopeBinding);
|
||||
}
|
||||
}
|
||||
if (scopeBinding != null && scopeBinding != binding) {
|
||||
PDOMBinding scopePDOMBinding= adaptBinding(scopeBinding);
|
||||
if (scopePDOMBinding != null)
|
||||
return scopePDOMBinding;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
throw new CoreException(Util.createStatus(e));
|
||||
|
|
|
@ -152,6 +152,12 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (node instanceof ICompositeType) {
|
||||
char[] nchars= ((ICompositeType) node).getNameCharArray();
|
||||
if (nchars.length > 0 && nchars[0] == '{') {
|
||||
return true; // visit children
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void leave(IPDOMNode node) throws CoreException {
|
||||
|
|
|
@ -367,7 +367,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
|
|||
// the class itself
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
visitor.setVisitAnonymousClassTypes(true);
|
||||
accept(visitor);
|
||||
result= visitor.getBindings();
|
||||
} catch (CoreException e) {
|
||||
|
@ -386,6 +386,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
|
|||
if (getDBName().compare(name, true) == 0) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
visitor.setVisitAnonymousClassTypes(true);
|
||||
accept(visitor);
|
||||
result = visitor.getBindings();
|
||||
pdom.putCachedResult(key, result);
|
||||
|
|
Loading…
Add table
Reference in a new issue