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 4729b0eee52..6e807f5adf8 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
@@ -26,6 +26,7 @@ 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.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
@@ -35,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
@@ -752,4 +754,53 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
assertTrue(outer instanceof ICPPClassScope);
assertEquals("outer", outer.getScopeName().toString());
}
+
+ // namespace ns {
+ // int v;
+ // };
+ // using namespace ns;
+
+ // #include "header.h"
+ // void test() {
+ // v=1;
+ // }
+ public void testUsingDirective_Bug216527() throws Exception {
+ IBinding b = getBindingFromASTName("v=", 1);
+ assertTrue(b instanceof IVariable);
+ IVariable v= (IVariable) b;
+ IScope scope= v.getScope();
+ assertTrue(scope instanceof ICPPNamespaceScope);
+ assertEquals("ns", scope.getScopeName().toString());
+ }
+
+ // namespace NSA {
+ // int a;
+ // }
+ // namespace NSB {
+ // int b;
+ // }
+ // namespace NSAB {
+ // using namespace NSA;
+ // using namespace NSB;
+ // }
+
+ // #include "header.h"
+ // void f() {
+ // NSAB::a= NSAB::b;
+ // }
+ public void testNamespaceComposition_Bug200673() throws Exception {
+ IBinding a = getBindingFromASTName("a=", 1);
+ assertTrue(a instanceof IVariable);
+ IVariable v= (IVariable) a;
+ IScope scope= v.getScope();
+ assertTrue(scope instanceof ICPPNamespaceScope);
+ assertEquals("NSA", scope.getScopeName().toString());
+
+ IBinding b = getBindingFromASTName("b;", 1);
+ assertTrue(b instanceof IVariable);
+ v= (IVariable) b;
+ scope= v.getScope();
+ assertTrue(scope instanceof ICPPNamespaceScope);
+ assertEquals("NSB", scope.getScopeName().toString());
+ }
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java
index 34e0af0e0a0..6c5d5c89bcc 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java
@@ -121,9 +121,10 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
// class B {};
// }
+ // #include "header.h"
// namespace n { class C{}; }
// m::C c;
- public void _testUsingNamingDirective_177917_1b() {
+ public void testUsingNamingDirective_177917_1b() {
IBinding b0= getBindingFromASTName("C c", 1);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMNode.java
index 194db2e6326..4b83d27d7e4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMNode.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMNode.java
@@ -1,29 +1,33 @@
/*******************************************************************************
- * Copyright (c) 2006 QNX Software Systems and others.
+ * Copyright (c) 2006, 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
/**
- * @author Doug Schaefer
- *
+ * Interface for all nodes that can be visited by a {@link IPDOMVisitor}.
*/
public interface IPDOMNode {
/**
- * Visit the children of this node.
- *
- * @param visitor
- * @throws CoreException
+ * Visits the children of this node.
*/
public void accept(IPDOMVisitor visitor) throws CoreException;
+
+ /**
+ * Frees memory allocated by this node, the node may no longer be used.
+ * @param linkage the linkage the node belongs to.
+ */
+ public void delete(PDOMLinkage linkage) throws CoreException;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPUsingDirective.java
index febcbbfe7fb..35c702e566c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPUsingDirective.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPUsingDirective.java
@@ -1,22 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/**
- * Interface to model using directives
+ * Interface to model using directives. Needed to bridge between directives found in the
+ * AST and the ones found in the index.
* @since 5.0
*/
public interface ICPPUsingDirective {
+ ICPPUsingDirective[] EMPTY_ARRAY = new ICPPUsingDirective[0];
+
/**
* Returns the scope of the namespace that is nominated by this
- * directive.
+ * directive, or null
if it cannot be determined.
*/
- ICPPNamespace getNamespace() throws DOMException;
+ ICPPNamespaceScope getNominatedScope() throws DOMException;
/**
* Returns the point of declaration as global offset ({@link ASTNode#getOffset()}).
*/
int getPointOfDeclaration();
+
+ /**
+ * Returns the scope containing this directive.
+ */
+ IScope getContainingScope();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexFile.java
index be6ace5dd32..2649320a973 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexFile.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexFile.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
@@ -9,9 +9,9 @@
* Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian)
*******************************************************************************/
-
package org.eclipse.cdt.core.index;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.core.runtime.CoreException;
/**
@@ -53,6 +53,13 @@ public interface IIndexFile {
*/
IIndexMacro[] getMacros() throws CoreException;
+ /**
+ * Returns all using directives for namespaces and global scope, found in this file.
+ * @throws CoreException
+ * @since 5.0
+ */
+ ICPPUsingDirective[] getUsingDirectives() throws CoreException;
+
/**
* Last modification of file before it was indexed.
* @return the last modification date of the file at the time it was parsed.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
index c9c584a757c..b4237588b52 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
@@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
+import java.util.List;
+
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName;
@@ -44,18 +46,21 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
+import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
+import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
import org.eclipse.core.runtime.CoreException;
/**
* @author jcamelon
*/
-public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit {
+public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit, ISkippedIndexedFilesListener {
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
@@ -560,4 +565,16 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
public void setIsHeaderUnit(boolean headerUnit) {
fIsHeader= headerUnit;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
+ */
+ public void skippedFile(int offset, IncludeFileContent fileContent) {
+ if (fIndexFileSet != null) {
+ List files= fileContent.getFilesIncluded();
+ for (IIndexFile indexFile : files) {
+ fIndexFileSet.add(indexFile);
+ }
+ }
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
index de7ad22c899..65bd878155b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
@@ -11,7 +11,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
-import java.util.HashMap;
+import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName;
@@ -58,6 +58,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
@@ -67,12 +68,14 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
+import org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener;
+import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
import org.eclipse.core.runtime.CoreException;
/**
* @author jcamelon
*/
-public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslationUnit, IASTAmbiguityParent {
+public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslationUnit, IASTAmbiguityParent, ISkippedIndexedFilesListener {
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
@@ -88,8 +91,8 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
private IIndex index;
private IIndexFileSet fIndexFileSet;
private boolean fIsHeader= true;
- private HashMap fMappedScopes= new HashMap();
-
+ private CPPScopeMapper fScopeMapper= new CPPScopeMapper(this);
+
public CPPASTTranslationUnit() {
}
@@ -535,19 +538,32 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
fIsHeader= headerUnit;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.parser.scanner.ISkippedIndexedFilesListener#skippedFile(org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent)
+ */
+ public void skippedFile(int offset, IncludeFileContent fileContent) {
+ if (fIndexFileSet != null) {
+ final List files= fileContent.getFilesIncluded();
+ for (IIndexFile indexFile : files) {
+ fIndexFileSet.add(indexFile);
+ }
+ }
+ fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
+ }
+
// bug 217102: namespace scopes from the index have to be mapped back to the AST.
IScope mapToASTScope(IIndexScope scope) {
- if (scope instanceof ICPPNamespaceScope) {
- IScope result= fMappedScopes.get(scope);
- if (result == null) {
- result= getScope().findNamespaceScope(scope);
- if (result == null) {
- result= scope;
- }
- fMappedScopes.put(scope, result);
- }
- return result;
- }
- return scope;
+ return fScopeMapper.mapToASTScope(scope);
+ }
+
+ /**
+ * Stores directives from the index into this scope.
+ */
+ void handleAdditionalDirectives(ICPPNamespaceScope scope) {
+ fScopeMapper.handleAdditionalDirectives(scope);
+ }
+
+ IIndexFileSet getFileSet() {
+ return fIndexFileSet;
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java
index 14e7a295f96..04c938fc7a8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java
@@ -11,9 +11,6 @@
* Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian)
*******************************************************************************/
-/*
- * Created on Nov 29, 2004
- */
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import java.util.ArrayList;
@@ -247,7 +244,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
return false;
if(forName == null)
return true;
- if(!forName.isReference() && !CPPSemantics.declaredBefore(candidate, forName))
+ if(!forName.isReference() && !CPPSemantics.declaredBefore(candidate, forName, false))
return false;
return true;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java
new file mode 100644
index 00000000000..1a7f5ea049d
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java
@@ -0,0 +1,221 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.parser.cpp;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.cdt.core.dom.IName;
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
+import org.eclipse.cdt.core.index.IIndexFileSet;
+import org.eclipse.cdt.internal.core.index.IIndexScope;
+
+/**
+ * Utility to map index-scopes to scopes from the AST. This is important for
+ * scopes that can be reopened, i.e. namespaces.
+ */
+public class CPPScopeMapper {
+ /**
+ * Wrapper for namespace-scopes from the index.
+ */
+ private class NamespaceScopeWrapper implements ICPPNamespaceScope {
+ private final ICPPNamespaceScope fScope;
+ private ArrayList fUsingDirectives;
+
+ public NamespaceScopeWrapper(ICPPNamespaceScope scope) {
+ fScope= scope;
+ }
+
+ public IBinding[] find(String name) throws DOMException {
+ return fScope.find(name);
+ }
+ public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
+ return fScope.getBinding(name, resolve);
+ }
+ public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) throws DOMException {
+ return fScope.getBinding(name, resolve, acceptLocalBindings);
+ }
+ public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
+ return fScope.getBindings(name, resolve, prefixLookup);
+ }
+ public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings) throws DOMException {
+ return fScope.getBindings(name, resolve, prefixLookup, acceptLocalBindings);
+ }
+ public IScope getParent() throws DOMException {
+ IScope parent= fScope.getParent();
+ if (parent instanceof IIndexScope) {
+ return mapToASTScope((IIndexScope) parent);
+ }
+ return fTuScope;
+ }
+
+ public IName getScopeName() throws DOMException {
+ return fScope.getScopeName();
+ }
+
+ public void addUsingDirective(ICPPUsingDirective usingDirective) throws DOMException {
+ if (fUsingDirectives == null) {
+ fUsingDirectives= new ArrayList(1);
+ }
+ fUsingDirectives.add(usingDirective);
+ }
+
+ public ICPPUsingDirective[] getUsingDirectives() throws DOMException {
+ if (fUsingDirectives == null) {
+ return ICPPUsingDirective.EMPTY_ARRAY;
+ }
+ return fUsingDirectives.toArray(new ICPPUsingDirective[fUsingDirectives.size()]);
+ }
+ }
+
+ /**
+ * Wrapper for using directives from the index.
+ */
+ private class UsingDirectiveWrapper implements ICPPUsingDirective {
+ private final int fOffset;
+ private final ICPPUsingDirective fDirective;
+
+ public UsingDirectiveWrapper(int offset, ICPPUsingDirective ud) {
+ fOffset= offset;
+ fDirective= ud;
+ }
+
+ public IScope getContainingScope() {
+ final IScope scope= fDirective.getContainingScope();
+ if (scope == null) {
+ return fTuScope;
+ }
+ return scope;
+ }
+
+ public ICPPNamespaceScope getNominatedScope() throws DOMException {
+ return fDirective.getNominatedScope();
+ }
+
+ public int getPointOfDeclaration() {
+ return fOffset;
+ }
+ }
+
+
+
+ private final HashMap fMappedScopes= new HashMap();
+ private final HashMap fNamespaceWrappers= new HashMap();
+ private final Map> fPerName= new HashMap>();
+ private final CPPNamespaceScope fTuScope;
+
+
+ public CPPScopeMapper(CPPASTTranslationUnit tu) {
+ fTuScope= tu.getScope();
+ }
+
+ /**
+ * Register an additional list of using directives to be considered.
+ * @param offset the global offset at which the using directives are provided
+ * @param usingDirectives the list of additional directives.
+ */
+ public void registerAdditionalDirectives(int offset, List usingDirectives) {
+ if (!usingDirectives.isEmpty()) {
+ for (ICPPUsingDirective ud : usingDirectives) {
+ IScope container= ud.getContainingScope();
+ try {
+ final String name= getReverseQualifiedName(container);
+ List list= fPerName.get(name);
+ if (list == null) {
+ list= new LinkedList();
+ fPerName.put(name, list);
+ }
+ list.add(new UsingDirectiveWrapper(offset, ud));
+ } catch (DOMException e) {
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds additional directives previously registered to the given scope.
+ */
+ public void handleAdditionalDirectives(ICPPNamespaceScope scope) {
+ assert !(scope instanceof IIndexScope);
+ if (fPerName.isEmpty()) {
+ return;
+ }
+ try {
+ String qname = getReverseQualifiedName(scope);
+ List candidates= fPerName.remove(qname);
+ if (candidates != null) {
+ for (UsingDirectiveWrapper ud : candidates) {
+ scope.addUsingDirective(ud);
+ }
+ }
+ } catch (DOMException e) {
+ }
+ }
+
+ private String getReverseQualifiedName(IScope scope) throws DOMException {
+ if (scope == fTuScope || scope == null) {
+ return ""; //$NON-NLS-1$
+ }
+ StringBuilder buf= new StringBuilder();
+ buf.append(scope.getScopeName().toCharArray());
+ scope= scope.getParent();
+ while (scope != null && scope != fTuScope) {
+ buf.append(':');
+ buf.append(scope.getScopeName().toCharArray());
+ scope= scope.getParent();
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Maps namespace scopes from the index back into the AST.
+ */
+ public IScope mapToASTScope(IIndexScope scope) {
+ if (scope == null) {
+ return fTuScope;
+ }
+ if (scope instanceof ICPPNamespaceScope) {
+ IScope result= fMappedScopes.get(scope);
+ if (result == null) {
+ result= fTuScope.findNamespaceScope(scope);
+ if (result == null) {
+ result= wrapNamespaceScope(scope);
+ }
+ fMappedScopes.put(scope, result);
+ }
+ return result;
+ }
+ return scope;
+ }
+
+ private IScope wrapNamespaceScope(IIndexScope scope) {
+ try {
+ String rqname= getReverseQualifiedName(scope);
+ NamespaceScopeWrapper result= fNamespaceWrappers.get(rqname);
+ if (result == null) {
+ result= new NamespaceScopeWrapper((ICPPNamespaceScope) scope);
+ fNamespaceWrappers.put(rqname, result);
+ }
+ return result;
+ } catch (DOMException e) {
+ assert false; // index scopes don't throw dom-exceptions
+ return null;
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java
index 8f8fedeb4d3..70886dfe887 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java
@@ -125,6 +125,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
@@ -1021,12 +1022,12 @@ public class CPPSemantics {
IASTNode node = data.astName;
IIndexFileSet fileSet= IIndexFileSet.EMPTY;
- if (node != null) {
- if (data.tu != null) {
- final IIndexFileSet fs= (IIndexFileSet) data.tu.getAdapter(IIndexFileSet.class);
- if (fs != null) {
- fileSet= fs;
- }
+ boolean isIndexBased= false;
+ if (data.tu != null) {
+ final IIndexFileSet fs= data.tu.getFileSet();
+ if (fs != null) {
+ fileSet= fs;
+ isIndexBased= true;
}
}
@@ -1048,6 +1049,9 @@ public class CPPSemantics {
}
while( scope != null ){
+ if (scope instanceof IIndexScope && data.tu != null) {
+ scope= (ICPPScope) data.tu.mapToASTScope(((IIndexScope) scope));
+ }
IASTNode blockItem = CPPVisitor.getContainingBlockItem( node );
if( !data.usingDirectivesOnly ){
@@ -1055,7 +1059,7 @@ public class CPPSemantics {
if (!data.contentAssist && data.astName != null) {
IBinding binding = scope.getBinding( data.astName, true, fileSet );
if( binding != null &&
- ( CPPSemantics.declaredBefore( binding, data.astName ) ||
+ ( CPPSemantics.declaredBefore( binding, data.astName, isIndexBased ) ||
(scope instanceof ICPPClassScope && data.checkWholeClassScope) ) )
{
mergeResults( data, binding, true );
@@ -1103,13 +1107,16 @@ public class CPPSemantics {
final ICPPNamespaceScope blockScope= (ICPPNamespaceScope) scope;
if (! (blockScope instanceof ICPPBlockScope)) {
data.visited.put(blockScope); // namespace has been searched.
+ if (data.tu != null) {
+ data.tu.handleAdditionalDirectives(blockScope);
+ }
}
ICPPUsingDirective[] uds= blockScope.getUsingDirectives();
if( uds != null && uds.length > 0) {
HashSet handled= new HashSet();
for( int i = 0; i < uds.length; i++ ){
final ICPPUsingDirective ud = uds[i];
- if( CPPSemantics.declaredBefore( ud, data.astName ) ){
+ if( CPPSemantics.declaredBefore( ud, data.astName, false ) ){
storeUsingDirective(data, blockScope, ud, handled);
}
}
@@ -1390,11 +1397,10 @@ public class CPPSemantics {
*/
static private void storeUsingDirective(CPPSemantics.LookupData data, ICPPNamespaceScope container,
ICPPUsingDirective directive, Set handled) throws DOMException {
- final ICPPNamespace nsBinding = directive.getNamespace();
- if (nsBinding == null) {
- return;
+ ICPPNamespaceScope nominated= directive.getNominatedScope();
+ if (nominated instanceof IIndexScope && data.tu != null) {
+ nominated= (ICPPNamespaceScope) data.tu.mapToASTScope((IIndexScope) nominated);
}
- final ICPPNamespaceScope nominated= nsBinding.getNamespaceScope();
if (nominated == null || data.visited.containsKey(nominated) || (handled != null && !handled.add(nominated))) {
return;
}
@@ -1417,6 +1423,9 @@ public class CPPSemantics {
// container.
if (!data.qualified() || data.contentAssist) {
assert handled != null;
+ if (data.tu != null) {
+ data.tu.handleAdditionalDirectives(nominated);
+ }
ICPPUsingDirective[] transitive= nominated.getUsingDirectives();
for (int i = 0; i < transitive.length; i++) {
storeUsingDirective(data, container, transitive[i], handled);
@@ -1448,6 +1457,7 @@ public class CPPSemantics {
* @throws DOMException
*/
static protected IASTName[] lookupInScope( CPPSemantics.LookupData data, ICPPScope scope, IASTNode blockItem ) throws DOMException {
+ final boolean isIndexBased= data.tu == null ? false : data.tu.getIndex() != null;
Object possible = null;
IASTNode [] nodes = null;
IASTNode parent = ASTInternal.getPhysicalNodeOfScope(scope);
@@ -1549,7 +1559,7 @@ public class CPPSemantics {
temp = ((IASTName[])possible)[++jdx];
while( temp != null ) {
- if( (checkWholeClassScope || declaredBefore( temp, data.astName )) &&
+ if( (checkWholeClassScope || declaredBefore( temp, data.astName, isIndexBased )) &&
(item != blockItem || data.includeBlockItem( item )) )
{
@@ -1656,6 +1666,9 @@ public class CPPSemantics {
// the lookup did not succeed. In the qualified case this is done earlier, when the directive
// is encountered.
if (!found && data.qualified() && !data.contentAssist) {
+ if (data.tu != null) {
+ data.tu.handleAdditionalDirectives(nominated);
+ }
ICPPUsingDirective[] usings= nominated.getUsingDirectives();
for (int i = 0; i < usings.length; i++) {
ICPPUsingDirective using = usings[i];
@@ -1918,7 +1931,7 @@ public class CPPSemantics {
return new CPPCompositeBinding( result );
}
- static public boolean declaredBefore( Object obj, IASTNode node ){
+ static public boolean declaredBefore( Object obj, IASTNode node, boolean indexBased ){
if( node == null ) return true;
if( node.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return true;
final int pointOfRef= ((ASTNode) node).getOffset();
@@ -1931,6 +1944,21 @@ public class CPPSemantics {
int pointOfDecl= -1;
if( obj instanceof ICPPInternalBinding ){
ICPPInternalBinding cpp = (ICPPInternalBinding) obj;
+ // for bindings in global or namespace scope we don't know whether there is a
+ // previous declaration in one of the skipped header files. For bindings that
+ // are likely to be redeclared we need to assume that there is a declaration
+ // in one of the headers.
+ if (indexBased) {
+ if (cpp instanceof ICPPNamespace || cpp instanceof ICPPFunction || cpp instanceof ICPPVariable) {
+ try {
+ IScope scope= cpp.getScope();
+ if (!(scope instanceof ICPPBlockScope) && scope instanceof ICPPNamespaceScope) {
+ return true;
+ }
+ } catch (DOMException e) {
+ }
+ }
+ }
IASTNode[] n = cpp.getDeclarations();
if( n != null && n.length > 0 ) {
nd = (ASTNode) n[0];
@@ -1986,6 +2014,7 @@ public class CPPSemantics {
if( !data.hasResults() || data.contentAssist )
return null;
+ final boolean indexBased= data.tu == null ? false : data.tu.getIndex() != null;
IBinding type = null;
IBinding obj = null;
IBinding temp = null;
@@ -1996,7 +2025,7 @@ public class CPPSemantics {
Object [] items = (Object[]) data.foundItems;
for( int i = 0; i < items.length && items[i] != null; i++ ){
Object o = items[i];
- boolean declaredBefore = declaredBefore( o, name );
+ boolean declaredBefore = declaredBefore( o, name, indexBased );
boolean checkResolvedNamesOnly= false;
if( !data.checkWholeClassScope && !declaredBefore) {
if (!name.isReference()) {
@@ -2724,6 +2753,7 @@ public class CPPSemantics {
} catch ( DOMException e1 ) {
return null;
}
+ final boolean isIndexBased= data.tu == null ? false : data.tu.getIndex() != null;
if( data.hasResults() ){
Object [] items = (Object[]) data.foundItems;
IBinding temp = null;
@@ -2734,7 +2764,7 @@ public class CPPSemantics {
temp = ((IASTName) o).resolveBinding();
else if( o instanceof IBinding ){
temp = (IBinding) o;
- if( !declaredBefore( temp, name ) )
+ if( !declaredBefore( temp, name, isIndexBased ) )
continue;
} else
continue;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDirective.java
index 7c41abe9df9..c096c8ae4e8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDirective.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDirective.java
@@ -13,9 +13,11 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@@ -43,10 +45,10 @@ public class CPPUsingDirective implements ICPPUsingDirective {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getNamespaceScope()
*/
- public ICPPNamespace getNamespace() throws DOMException {
+ public ICPPNamespaceScope getNominatedScope() throws DOMException {
IBinding binding= fNamespaceName.resolveBinding();
if (binding instanceof ICPPNamespace) {
- return (ICPPNamespace) binding;
+ return ((ICPPNamespace) binding).getNamespaceScope();
}
return null;
}
@@ -58,4 +60,11 @@ public class CPPUsingDirective implements ICPPUsingDirective {
final ASTNode astNode = (ASTNode) fNamespaceName;
return astNode.getOffset() + astNode.getLength();
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getContainingScope()
+ */
+ public IScope getContainingScope() {
+ return CPPVisitor.getContainingScope(fNamespaceName);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java
index 89a6c5477f3..0732497f95d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.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
@@ -45,4 +45,9 @@ public interface IIndexFragmentBinding extends IIndexBinding {
* Returns the constant identifying the type of binding stored in the index
*/
int getBindingConstant();
+
+ /**
+ * Returns the scope that contains this binding, or null
for bindings in global scope.
+ */
+ IIndexScope getScope();
}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexScope.java
index 3fcc88166db..1dcc8fbfe2d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexScope.java
@@ -1,17 +1,19 @@
/*******************************************************************************
- * 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.index.IIndexBinding;
+import org.eclipse.cdt.core.index.IIndexName;
/**
@@ -21,7 +23,16 @@ import org.eclipse.cdt.core.index.IIndexBinding;
public interface IIndexScope extends IScope {
/**
* Get the binding associated with scope
- * @return
*/
IIndexBinding getScopeBinding();
+
+ /**
+ * Returns the parent scope or null
if the scope is nested in the global scope.
+ */
+ IIndexScope getParent();
+
+ /**
+ * Returns the name of this scope.
+ */
+ IIndexName getScopeName();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java
index 4e4b7648c4d..19564b3b40f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java
@@ -24,6 +24,7 @@ import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
@@ -37,6 +38,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent.InclusionKind;
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask;
+import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.FileContent;
import org.eclipse.core.runtime.CoreException;
/**
@@ -102,15 +104,18 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
IIndexFile file= fIndex.getFile(fLinkage, ifl);
if (file != null) {
try {
- LinkedHashMap macroMap= new LinkedHashMap();
+ LinkedHashMap fileContentMap= new LinkedHashMap();
List files= new ArrayList();
- collectMacros(file, macroMap, files, false);
+ collectFileContent(file, fileContentMap, files, false);
ArrayList allMacros= new ArrayList();
- for (Map.Entry entry : macroMap.entrySet()) {
- allMacros.addAll(Arrays.asList(entry.getValue()));
+ ArrayList allDirectives= new ArrayList();
+ for (Map.Entry entry : fileContentMap.entrySet()) {
+ final FileContent content= entry.getValue();
+ allMacros.addAll(Arrays.asList(content.fMacros));
+ allDirectives.addAll(Arrays.asList(content.fDirectives));
fIncludedFiles.add(entry.getKey());
}
- return new IncludeFileContent(path, allMacros, files);
+ return new IncludeFileContent(path, allMacros, allDirectives, files);
}
catch (NeedToParseException e) {
}
@@ -132,22 +137,24 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
return fIncludedFiles.contains(ifl);
}
- private void collectMacros(IIndexFile file, Map macroMap, List files, boolean checkIncluded) throws CoreException, NeedToParseException {
+ private void collectFileContent(IIndexFile file, Map macroMap, List files, boolean checkIncluded) throws CoreException, NeedToParseException {
IIndexFileLocation ifl= file.getLocation();
if (macroMap.containsKey(ifl) || (checkIncluded && fIncludedFiles.contains(ifl))) {
return;
}
- IIndexMacro[] converted;
+ FileContent content;
if (fRelatedIndexerTask != null) {
- converted= fRelatedIndexerTask.getConvertedMacros(fLinkage, ifl);
- if (converted == null) {
+ content= fRelatedIndexerTask.getFileContent(fLinkage, ifl);
+ if (content == null) {
throw new NeedToParseException();
}
}
else {
- converted= file.getMacros();
+ content= new FileContent();
+ content.fMacros= file.getMacros();
+ content.fDirectives= file.getUsingDirectives();
}
- macroMap.put(ifl, converted); // prevent recursion
+ macroMap.put(ifl, content); // prevent recursion
files.add(file);
// follow the includes
@@ -156,7 +163,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
final IIndexInclude indexInclude = includeDirectives[i];
IIndexFile includedFile= fIndex.resolveInclude(indexInclude);
if (includedFile != null) {
- collectMacros(includedFile, macroMap, files, true);
+ collectFileContent(includedFile, macroMap, files, true);
}
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java
index 87efb08503c..c30f8dcf586 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java
@@ -6,18 +6,18 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.index.IIndexFileSet;
+import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCompositeBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclaration;
@@ -44,17 +44,17 @@ public abstract class CompositeScope implements IIndexScope {
this.rbinding = rbinding;
}
- final public IScope getParent() throws DOMException {
- IIndexScope rscope = (IIndexScope) rbinding.getScope();
+ final public IIndexScope getParent() {
+ IIndexScope rscope = rbinding.getScope();
if(rscope!=null) {
return cf.getCompositeScope(rscope);
}
return null;
}
- public IName getScopeName() throws DOMException {
- if(rbinding instanceof IScope)
- return ((IScope) rbinding).getScopeName();
+ public IIndexName getScopeName() {
+ if(rbinding instanceof IIndexScope)
+ return ((IIndexScope) rbinding).getScopeName();
return null;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/ICompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/ICompositesFactory.java
index 962283104cb..a471ab3db24 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/ICompositesFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/ICompositesFactory.java
@@ -1,17 +1,16 @@
/*******************************************************************************
- * 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite;
import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
@@ -20,7 +19,7 @@ import org.eclipse.cdt.internal.core.index.IIndexType;
public interface ICompositesFactory {
- public IScope getCompositeScope(IIndexScope rscope) throws DOMException;
+ public IIndexScope getCompositeScope(IIndexScope rscope);
/**
* Returns a composite (in the sense of potentially spanning multiple index fragments - i.e. not to be confused
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java
index 03f871af1ec..f5c40d5aa3c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java
@@ -1,12 +1,12 @@
/*******************************************************************************
- * 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.c;
@@ -23,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
-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;
@@ -50,14 +49,14 @@ public class CCompositesFactory extends AbstractCompositeFactory implements ICom
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getCompositeScope(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.dom.ast.IScope)
*/
- public IScope getCompositeScope(IIndexScope rscope) {
+ public IIndexScope getCompositeScope(IIndexScope rscope) {
if(rscope==null)
return null;
if(rscope instanceof ICCompositeTypeScope) {
try {
ICCompositeTypeScope cscope = (ICCompositeTypeScope) rscope;
IIndexFragmentBinding rbinding = (IIndexFragmentBinding) cscope.getCompositeType();
- return ((ICompositeType)getCompositeBinding(rbinding)).getCompositeScope();
+ return (IIndexScope) ((ICompositeType)getCompositeBinding(rbinding)).getCompositeScope();
} catch(DOMException de) {
CCorePlugin.log(de);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java
index 4be98f03061..861c4fb1c8e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java
@@ -1,12 +1,12 @@
/*******************************************************************************
- * 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
@@ -19,10 +19,33 @@ import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
-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.*;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
+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.ICPPClassTemplatePartialSpecialization;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.CIndex;
@@ -46,8 +69,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory implements IC
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getCompositeScope(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.core.dom.ast.IScope)
*/
- public IScope getCompositeScope(IIndexScope rscope) throws DOMException {
- IScope result;
+ public IIndexScope getCompositeScope(IIndexScope rscope) {
+ IIndexScope result;
try {
if(rscope == null) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java
index 702e8455a64..ecb9fcab41c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java
@@ -11,18 +11,18 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
-import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
+import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
+import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@@ -75,11 +75,11 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace
return cf.getCompositeBinding(rbinding);
}
- public IName getScopeName() throws DOMException {
+ public IIndexName getScopeName() {
for(int i=0; i mdefs= fi.getMacroDefinitions();
for (IIndexMacro macro : mdefs) {
addMacroDefinition(macro);
}
- IIndexFileSet fileSet= fLocationMap.getFileSet();
- if (fileSet != null) {
- List files= fi.getFilesIncluded();
- for (IIndexFile indexFile : files) {
- fileSet.add(indexFile);
- }
- }
+ fLocationMap.skippedFile(fLocationMap.getSequenceNumberForOffset(offset), fi);
}
private char[] extractHeaderName(final char[] image, final char startDelim, final char endDelim, int[] offsets) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ISkippedIndexedFilesListener.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ISkippedIndexedFilesListener.java
new file mode 100644
index 00000000000..7821db6c68b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ISkippedIndexedFilesListener.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.parser.scanner;
+
+import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
+
+/**
+ * Interface to listen for information about files skipped by the preprocessor,
+ * because they are found in the index
+ */
+public interface ISkippedIndexedFilesListener {
+
+ /**
+ * Notifies the listeners that an include file has been skipped.
+ * @param offset offset at which the file is included (see {@link ASTNode#getOffset()}
+ * @param fileContent information about the skipped file.
+ */
+ void skippedFile(int offset, IncludeFileContent fileContent);
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeFileContent.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeFileContent.java
index 9c79179bd70..5d57781cdec 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeFileContent.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeFileContent.java
@@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.List;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.parser.CodeReader;
@@ -40,6 +41,7 @@ public class IncludeFileContent {
private final InclusionKind fKind;
private final CodeReader fCodeReader;
private final List fMacroDefinitions;
+ private final List fUsingDirectives;
private final String fFileLocation;
private List fFiles;
@@ -57,6 +59,7 @@ public class IncludeFileContent {
fKind= kind;
fFileLocation= fileLocation;
fMacroDefinitions= null;
+ fUsingDirectives= null;
fCodeReader= null;
}
@@ -73,6 +76,7 @@ public class IncludeFileContent {
fFileLocation= codeReader.getPath();
fCodeReader= codeReader;
fMacroDefinitions= null;
+ fUsingDirectives= null;
if (fFileLocation == null) {
throw new IllegalArgumentException();
}
@@ -85,10 +89,12 @@ public class IncludeFileContent {
* @param files
* @throws IllegalArgumentException in case the fileLocation or the macroDefinitions are null
.
*/
- public IncludeFileContent(String fileLocation, List macroDefinitions, List files) {
+ public IncludeFileContent(String fileLocation, List macroDefinitions, List usingDirectives,
+ List files) {
fKind= InclusionKind.FOUND_IN_INDEX;
fFileLocation= fileLocation;
fCodeReader= null;
+ fUsingDirectives= usingDirectives;
fMacroDefinitions= macroDefinitions;
fFiles= files;
}
@@ -123,6 +129,13 @@ public class IncludeFileContent {
return fMacroDefinitions;
}
+ /**
+ * Valid with {@link InclusionKind#FOUND_IN_INDEX}.
+ * @return the usingDirectives or null
if kind is different to {@link InclusionKind#FOUND_IN_INDEX}.
+ */
+ public List getUsingDirectives() {
+ return fUsingDirectives;
+ }
/**
* Valid with {@link InclusionKind#FOUND_IN_INDEX}.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
index 8200d3a8e98..9defd56ff9c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
@@ -31,9 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
-import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
-import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
/**
* Converts the offsets relative to various contexts to the global sequence number. Also creates and stores
@@ -58,8 +56,7 @@ public class LocationMap implements ILocationResolver {
// stuff computed on demand
private IdentityHashMap fMacroDefinitionMap= null;
-
-
+ private List fSkippedFilesListeners= new ArrayList();
public void registerPredefinedMacro(IMacroBinding macro) {
registerPredefinedMacro(macro, null, -1);
@@ -312,6 +309,9 @@ public class LocationMap implements ILocationResolver {
public void setRootNode(IASTTranslationUnit root) {
fTranslationUnit= root;
+ if (fTranslationUnit instanceof ISkippedIndexedFilesListener) {
+ fSkippedFilesListeners.add((ISkippedIndexedFilesListener) root);
+ }
}
public String getTranslationUnitPath() {
@@ -600,14 +600,9 @@ public class LocationMap implements ILocationResolver {
public void cleanup() {
}
- public ASTPreprocessorSelectionResult getPreprocessorNode(String path, int offset, int length) {
- throw new UnsupportedOperationException();
- }
-
- public IIndexFileSet getFileSet() {
- if (fTranslationUnit != null) {
- return (IIndexFileSet) fTranslationUnit.getAdapter(IIndexFileSet.class);
+ public void skippedFile(int sequenceNumber, IncludeFileContent fi) {
+ for (ISkippedIndexedFilesListener l : fSkippedFilesListeners) {
+ l.skippedFile(sequenceNumber, fi);
}
- return null;
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java
index af9683f0682..14b8106eae9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java
@@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude;
@@ -76,18 +77,19 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
}
}
- private static class FileInfo {
- IIndexFile fIndexFile= null;
- boolean fRequestUpdate= false;
- boolean fRequestIsCounted= true;
- boolean fIsUpdated= false;
+ public static class FileContent {
+ private IIndexFile fIndexFile= null;
+ private boolean fRequestUpdate= false;
+ private boolean fRequestIsCounted= true;
+ private boolean fIsUpdated= false;
public IIndexMacro[] fMacros;
+ public ICPPUsingDirective[] fDirectives;
}
private int fUpdateFlags= IIndexManager.UPDATE_ALL;
private boolean fIndexHeadersWithoutContext= true;
private boolean fIndexFilesWithoutConfiguration= true;
- private HashMap fFileInfos= new HashMap();
+ private HashMap fFileInfos= new HashMap();
private Object[] fFilesToUpdate;
private List