Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-02-06 15:30:47 +0000
committerMarkus Schorn2008-02-06 15:30:47 +0000
commit9cd75c484ed1858995358b0b6f269fdd18e7678f (patch)
treeaa3da6536444e759efda5f229bf3d03e5b617732 /core/org.eclipse.cdt.core/parser
parenta39c03d796ec92a75b336653b6604bfdc0e028a7 (diff)
downloadorg.eclipse.cdt-9cd75c484ed1858995358b0b6f269fdd18e7678f.tar.gz
org.eclipse.cdt-9cd75c484ed1858995358b0b6f269fdd18e7678f.tar.xz
org.eclipse.cdt-9cd75c484ed1858995358b0b6f269fdd18e7678f.zip
Anonymous unions and structs, bug 216791.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser')
-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
4 files changed, 58 insertions, 21 deletions
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