diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java
index 81cb0ee03b5..02b34f23845 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/DefDeclTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 QNX Software Systems and others.
+ * Copyright (c) 2006, 2007 QNX 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
@@ -23,10 +23,16 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.index.IIndexFile;
+import org.eclipse.cdt.core.index.IIndexFileLocation;
+import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter;
+import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.CCoreInternals;
+import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@@ -204,25 +210,35 @@ public class DefDeclTests extends PDOMTestBase {
assertDefDeclRef("foo", "06", 1, 1, 1);
}
- public void testWrongMatchedStaticDefinition_unexpected() throws Exception {
- assertDefDeclRef("foo", "07", 1, 1, 1);
+ public void testWrongMatchedStaticDefinition() throws Exception {
+ assertDefDeclRef("foo", "07", 0, 1, 1);
}
- public void testStaticBindings_f08_unexpected() throws Exception {
- // should be 2 bindings, otherwise how to distinguish proper def/decl
- // pairs?
- // static elements cannot be found on global scope, see bug 161216
+ public void testStaticBindings_f08() throws Exception {
String elName = "foo" + "08";
- IBinding[] binds = pdom.findBindings(Pattern.compile(elName), true,
- IndexFilter.ALL, new NullProgressMonitor());
- assertEquals(0, binds.length);
-// assertEquals(elName, binds[0].getName());
-// IBinding element = binds[0];
-// IBinding binding = element;
-// checkDefinition(binding, "def" + "08", 2);
-// checkReference(binding, "ref" + "08", 2);
-// checkDefinition(binding, "defS" + "08", 2);
-// checkReference(binding, "refS" + "08", 2);
+
+ IIndexFileLocation ifl= IndexLocationFactory.getIFL((ITranslationUnit) cproject.findElement(new Path("func.c")));
+ IIndexFile file= pdom.getFile(ifl);
+ int offset= TestSourceReader.indexOfInFile("foo08();", new Path(ifl.getFullPath()));
+ IIndexName[] names= file.findNames(offset, 5);
+ assertEquals(1, names.length);
+
+ IBinding element = pdom.findBinding((IIndexFragmentName)names[0]);
+ assertEquals(elName, element.getName());
+ checkDefinition(element, "def" + "08", 1);
+ checkReference(element, "ref" + "08", 1);
+
+ // check the other file
+ ifl= IndexLocationFactory.getIFL((ITranslationUnit) cproject.findElement(new Path("second.c")));
+ file= pdom.getFile(ifl);
+ offset= TestSourceReader.indexOfInFile("foo08();", new Path(ifl.getFullPath()));
+ names= file.findNames(offset, 5);
+ assertEquals(1, names.length);
+
+ element = pdom.findBinding((IIndexFragmentName)names[0]);
+ assertEquals(elName, element.getName());
+ checkDefinition(element, "defS" + "08", 1);
+ checkReference(element, "refS" + "08", 1);
}
public void testSimpleGlobalWrite_v09() throws Exception {
@@ -263,7 +279,7 @@ public class DefDeclTests extends PDOMTestBase {
assertDefDeclRef("type", "_t03", 1, 1, 1);
}
- public void _testStructAndTypedef_t04_unexpected() throws Exception {
+ public void testStructAndTypedef_t04() throws Exception {
String num = "_t04";
String elName = "type" + num;
@@ -274,7 +290,7 @@ public class DefDeclTests extends PDOMTestBase {
IBinding struct = bindings[0] instanceof ICompositeType ? bindings[0] : bindings[1];
checkReference(typedef, "ref" + num, 1);
- checkDeclaration(typedef, "def" + num, 1);
+ checkDefinition(typedef, "def" + num, 1);
checkReference(struct, "refS" + num, 1);
checkDefinition(struct, "defS" + num, 1);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java
index a8c23d0e42c..89da0dc5ad4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2007 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
@@ -12,6 +12,7 @@
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.core.runtime.CoreException;
/**
* Represents the semantics of a name in the index.
@@ -35,4 +36,11 @@ public interface IIndexBinding extends IBinding {
* Returns the qualified name of this binding as array of strings.
*/
String[] getQualifiedName();
+
+ /**
+ * Returns whether the scope of the binding is file-local. A file local
+ * binding is private to an index and should not be adapted to a binding
+ * in another index.
+ */
+ boolean isFileLocal() throws CoreException;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java
index df20edcec4a..4acb933a600 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPField.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2007 IBM Corporation 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
@@ -165,7 +165,6 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBind
}
public ICompositeType getCompositeTypeOwner() throws DOMException {
- // mstodo Auto-generated method stub
- return null;
+ return getClassOwner();
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
index b00b664f682..4c194928296 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
@@ -72,7 +72,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
private Database db;
- public static final int VERSION = 22;
+ public static final int VERSION = 24;
// 0 - the beginning of it all
// 1 - first change to kick off upgrades
// 2 - added file inclusions
@@ -97,6 +97,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
// 21 - change representation of paths in the pdom (167549)
// 22 - fix inheritance relations (167396)
// 23 - types on c-variables, return types on c-functions
+ // 24 - file local scopes (161216)
public static final int LINKAGES = Database.DATA_AREA;
public static final int FILE_INDEX = Database.DATA_AREA + 4;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java
index 5a9620612f4..8a2cd38f865 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java
@@ -11,27 +11,17 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
-import java.util.ArrayList;
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.IBinding;
import org.eclipse.cdt.core.index.IndexFilter;
-import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
-import org.eclipse.core.runtime.CoreException;
/**
* Visitor to find bindings in a BTree or below a PDOMNode. Nested bindings are not visited.
* @since 4.0
*/
-public final class BindingCollector implements IBTreeVisitor, IPDOMVisitor {
- private final PDOMLinkage linkage;
- private final char[] name;
- private final boolean prefixLookup;
+public final class BindingCollector extends NamedNodeCollector {
private IndexFilter filter;
-
- private List bindings = new ArrayList();
/**
* Collects all bindings with given name.
@@ -45,55 +35,21 @@ public final class BindingCollector implements IBTreeVisitor, IPDOMVisitor {
* true
a binding is considered if its name starts with the given prefix.
*/
public BindingCollector(PDOMLinkage linkage, char[] name, IndexFilter filter, boolean prefixLookup) {
- this.name = name;
- this.linkage= linkage;
+ super(linkage, name, prefixLookup);
this.filter= filter;
- this.prefixLookup = prefixLookup;
}
-
- public int compare(int record) throws CoreException {
- PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record));
- return compare(node);
- }
-
- private int compare(PDOMNamedNode node) throws CoreException {
- if (prefixLookup) {
- return node.getDBName().comparePrefix(name);
- }
- return node.getDBName().compare(name);
- }
-
- public boolean visit(int record) throws CoreException {
- if (record == 0)
- return true;
- PDOMBinding tBinding = linkage.getPDOM().getBinding(record);
- if (tBinding != null) {
- visit(tBinding);
+ public boolean addNode(PDOMNamedNode tBinding) {
+ if (tBinding instanceof IBinding) {
+ if (filter == null || filter.acceptBinding((IBinding) tBinding)) {
+ return super.addNode(tBinding);
+ }
}
return true; // look for more
}
-
- private void visit(PDOMBinding tBinding) {
- if (filter == null || filter.acceptBinding(tBinding)) {
- bindings.add(tBinding);
- }
- }
public IBinding[] getBindings() {
+ List bindings= getNodeList();
return (IBinding[])bindings.toArray(new IBinding[bindings.size()]);
}
-
- public boolean visit(IPDOMNode node) throws CoreException {
- if (node instanceof PDOMBinding) {
- PDOMBinding pb= (PDOMBinding) node;
- if (compare(pb) == 0) {
- visit(pb);
- }
- }
- return false; // don't visit children
- }
-
- public void leave(IPDOMNode node) throws CoreException {
- }
}
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
new file mode 100644
index 00000000000..d9cd0e8cdfb
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/NamedNodeCollector.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.pdom.dom;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.cdt.core.dom.IPDOMNode;
+import org.eclipse.cdt.core.dom.IPDOMVisitor;
+import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Visitor to find named nodes in a BTree or below a PDOMNode. Nested nodes are not visited.
+ * @since 4.0
+ */
+public class NamedNodeCollector implements IBTreeVisitor, IPDOMVisitor {
+ private final PDOMLinkage linkage;
+ private final char[] name;
+ private final boolean prefixLookup;
+
+ private List nodes = new ArrayList();
+
+ /**
+ * Collects all nodes with given name.
+ */
+ public NamedNodeCollector(PDOMLinkage linkage, char[] name) {
+ this(linkage, name, false);
+ }
+
+ /**
+ * Collects all nodes with given name, passing the filter. If prefixLookup is set to
+ * true
a binding is considered if its name starts with the given prefix.
+ */
+ public NamedNodeCollector(PDOMLinkage linkage, char[] name, boolean prefixLookup) {
+ this.name = name;
+ this.linkage= linkage;
+ this.prefixLookup = prefixLookup;
+ }
+
+ final public int compare(int record) throws CoreException {
+ PDOMNamedNode node = ((PDOMNamedNode)linkage.getNode(record));
+ return compare(node);
+ }
+
+ private int compare(PDOMNamedNode node) throws CoreException {
+ if (prefixLookup) {
+ return node.getDBName().comparePrefix(name);
+ }
+ return node.getDBName().compare(name);
+ }
+
+ final public boolean visit(int record) throws CoreException {
+ if (record == 0)
+ return true;
+
+ PDOMNode node= linkage.getNode(record);
+ if (node instanceof PDOMNamedNode) {
+ return addNode((PDOMNamedNode) node);
+ }
+ return true; // look for more
+ }
+
+ /**
+ * Return true to continue the visit.
+ */
+ protected boolean addNode(PDOMNamedNode node) {
+ nodes.add(node);
+ return true; // look for more
+ }
+
+ final protected List getNodeList() {
+ return nodes;
+ }
+
+ final public PDOMNamedNode[] getNodes() {
+ return (PDOMNamedNode[])nodes.toArray(new PDOMNamedNode[nodes.size()]);
+ }
+
+ final public boolean visit(IPDOMNode node) throws CoreException {
+ if (node instanceof PDOMNamedNode) {
+ PDOMNamedNode pb= (PDOMNamedNode) node;
+ if (compare(pb) == 0) {
+ addNode(pb);
+ }
+ }
+ return false; // don't visit children
+ }
+
+ final public void leave(IPDOMNode node) throws CoreException {
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
index fbbda752cd2..e9fbab19f85 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 QNX Software Systems and others.
+ * Copyright (c) 2005, 2007 QNX 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
@@ -234,4 +234,8 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
return null;
}
}
+
+ final public boolean isFileLocal() throws CoreException {
+ return getParentNode() instanceof PDOMFileLocalScope;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFileLocalScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFileLocalScope.java
new file mode 100644
index 00000000000..b428e929a0a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFileLocalScope.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.internal.core.pdom.dom;
+
+import org.eclipse.cdt.core.dom.IPDOMVisitor;
+import org.eclipse.cdt.internal.core.pdom.PDOM;
+import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
+import org.eclipse.core.runtime.CoreException;
+
+public class PDOMFileLocalScope extends PDOMNamedNode implements IPDOMMemberOwner {
+ private static final int MEMBERLIST = PDOMNamedNode.RECORD_SIZE;
+ private static final int RECORD_SIZE = MEMBERLIST+4;
+
+
+ public PDOMFileLocalScope(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
+ super(pdom, parent, name);
+ }
+
+ public PDOMFileLocalScope(PDOM pdom, int record) {
+ super(pdom, record);
+ }
+
+ protected int getRecordSize() {
+ return RECORD_SIZE;
+ }
+
+ public int getNodeType() {
+ return PDOMLinkage.FILE_LOCAL_SCOPE_TYPE;
+ }
+
+ public void accept(IPDOMVisitor visitor) throws CoreException {
+ super.accept(visitor);
+ PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
+ list.accept(visitor);
+ }
+
+ public void addMember(PDOMNode member) throws CoreException {
+ PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
+ list.addMember(member);
+ }
+
+ public void addChild(PDOMNode child) throws CoreException {
+ addMember(child);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
index ef2c3713112..c00116c448d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
@@ -59,12 +59,13 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 12;
// node types
- protected static final int LINKAGE = 0; // special one for myself
- static final int POINTER_TYPE = 1;
- static final int ARRAY_TYPE = 2;
- static final int QUALIFIER_TYPE = 3;
+ protected static final int LINKAGE= 0; // special one for myself
+ static final int POINTER_TYPE= 1;
+ static final int ARRAY_TYPE= 2;
+ static final int QUALIFIER_TYPE= 3;
+ static final int FILE_LOCAL_SCOPE_TYPE= 4;
- protected static final int LAST_NODE_TYPE = QUALIFIER_TYPE;
+ protected static final int LAST_NODE_TYPE = FILE_LOCAL_SCOPE_TYPE;
public PDOMLinkage(PDOM pdom, int record) {
super(pdom, record);
@@ -144,6 +145,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return new PDOMArrayType(pdom, record);
case QUALIFIER_TYPE:
return new PDOMQualifierType(pdom, record);
+ case FILE_LOCAL_SCOPE_TYPE:
+ return new PDOMFileLocalScope(pdom, record);
}
return null;
}
@@ -178,17 +181,28 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
/**
*
* @param binding
+ * @param createFileLocalScope if true
the creation of a file local
+ * scope object is allowed.
* @return