Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java46
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java44
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/NamedNodeCollector.java22
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java48
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java3
7 files changed, 149 insertions, 23 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java
index ee67cc641ee..d25ce8255e8 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCBindingResolutionBugs.java
@@ -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());
+ }
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java
index f62bfe5388a..4729b0eee52 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java
@@ -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());
+ }
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java
index 4a6ad1b5722..b08d88dd113 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/GeneratePDOMApplicationTest.java
@@ -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);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/NamedNodeCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/NamedNodeCollector.java
index 654e1153e9f..4717bec5147 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/NamedNodeCollector.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/NamedNodeCollector.java
@@ -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
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
index 13533b7e0b3..394b60b08ba 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCLinkage.java
@@ -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,15 +85,14 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
}
}
else {
- 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
+
+ PDOMNode parent = getAdaptedParent(binding);
+ if (parent == null)
+ return null;
if (binding instanceof IField) { // must be before IVariable
if (parent instanceof IPDOMMemberOwner)
@@ -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));
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java
index b0fdb1b5db8..eaf8fd18ace 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCStructure.java
@@ -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 {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java
index dfaa3599cbf..62e90a3e7a2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassType.java
@@ -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);

Back to the top