Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-02-12 14:21:22 +0000
committerMarkus Schorn2008-02-12 14:21:22 +0000
commit5688a0ac9f9482b9d70252275268ed6cd60b1ff5 (patch)
treed9a772748540fc51b65216bdef782a5a319bca6e /core/org.eclipse.cdt.core/parser/org/eclipse
parentb848ef7a4d0e479b4a864b885d6344fbe7f8ec5d (diff)
downloadorg.eclipse.cdt-5688a0ac9f9482b9d70252275268ed6cd60b1ff5.tar.gz
org.eclipse.cdt-5688a0ac9f9482b9d70252275268ed6cd60b1ff5.tar.xz
org.eclipse.cdt-5688a0ac9f9482b9d70252275268ed6cd60b1ff5.zip
Using directives for fast indexer (including namespace composition), bug 200673+216527.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMNode.java20
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPUsingDirective.java25
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexFile.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java19
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java48
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassScope.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPScopeMapper.java221
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPSemantics.java62
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPUsingDirective.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragmentBinding.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexScope.java17
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java31
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeScope.java16
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/ICompositesFactory.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java35
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPNamespaceScope.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ISkippedIndexedFilesListener.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IncludeFileContent.java15
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java19
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java49
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java17
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java37
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBase.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java63
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUsingDirective.java121
33 files changed, 788 insertions, 187 deletions
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 <code>null</code> 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;
/**
@@ -54,6 +54,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.
* @throws CoreException
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<IIndexFile> 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<IIndexScope, IScope> fMappedScopes= new HashMap<IIndexScope, IScope>();
-
+ private CPPScopeMapper fScopeMapper= new CPPScopeMapper(this);
+
public CPPASTTranslationUnit() {
}
@@ -535,19 +538,32 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
fIsHeader= headerUnit;
}
- // 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);
+ /* (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<IIndexFile> files= fileContent.getFilesIncluded();
+ for (IIndexFile indexFile : files) {
+ fIndexFileSet.add(indexFile);
}
- return result;
}
- return scope;
+ fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
+ }
+
+ // bug 217102: namespace scopes from the index have to be mapped back to the AST.
+ IScope mapToASTScope(IIndexScope 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<ICPPUsingDirective> 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<ICPPUsingDirective>(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<IIndexScope, IScope> fMappedScopes= new HashMap<IIndexScope, IScope>();
+ private final HashMap<String, NamespaceScopeWrapper> fNamespaceWrappers= new HashMap<String, NamespaceScopeWrapper>();
+ private final Map<String, List<UsingDirectiveWrapper>> fPerName= new HashMap<String, List<UsingDirectiveWrapper>>();
+ 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<ICPPUsingDirective> usingDirectives) {
+ if (!usingDirectives.isEmpty()) {
+ for (ICPPUsingDirective ud : usingDirectives) {
+ IScope container= ud.getContainingScope();
+ try {
+ final String name= getReverseQualifiedName(container);
+ List<UsingDirectiveWrapper> list= fPerName.get(name);
+ if (list == null) {
+ list= new LinkedList<UsingDirectiveWrapper>();
+ 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<UsingDirectiveWrapper> 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<ICPPNamespaceScope> handled= new HashSet<ICPPNamespaceScope>();
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<ICPPNamespaceScope> 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 <code>null</code> 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 <code>null</code> 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<IIndexFileLocation, IIndexMacro[]> macroMap= new LinkedHashMap<IIndexFileLocation, IIndexMacro[]>();
+ LinkedHashMap<IIndexFileLocation, FileContent> fileContentMap= new LinkedHashMap<IIndexFileLocation, FileContent>();
List<IIndexFile> files= new ArrayList<IIndexFile>();
- collectMacros(file, macroMap, files, false);
+ collectFileContent(file, fileContentMap, files, false);
ArrayList<IIndexMacro> allMacros= new ArrayList<IIndexMacro>();
- for (Map.Entry<IIndexFileLocation,IIndexMacro[]> entry : macroMap.entrySet()) {
- allMacros.addAll(Arrays.asList(entry.getValue()));
+ ArrayList<ICPPUsingDirective> allDirectives= new ArrayList<ICPPUsingDirective>();
+ for (Map.Entry<IIndexFileLocation,FileContent> 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<IIndexFileLocation, IIndexMacro[]> macroMap, List<IIndexFile> files, boolean checkIncluded) throws CoreException, NeedToParseException {
+ private void collectFileContent(IIndexFile file, Map<IIndexFileLocation, FileContent> macroMap, List<IIndexFile> 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<namespaces.length; i++) {
- if(namespaces[i] instanceof IScope) {
- IScope s= (IScope) namespaces[i];
- IName nm= s.getScopeName();
+ if(namespaces[i] instanceof IIndexScope) {
+ IIndexScope s= (IIndexScope) namespaces[i];
+ IIndexName nm= s.getScopeName();
if(nm!=null)
return nm;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
index 3254d427ca1..cd1ad383dc8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
@@ -25,8 +25,6 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
-import org.eclipse.cdt.core.index.IIndexFile;
-import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.EndOfFileException;
@@ -1014,7 +1012,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
path= fi.getFileLocation();
switch(fi.getKind()) {
case FOUND_IN_INDEX:
- processInclusionFromIndex(path, fi);
+ processInclusionFromIndex(poundOffset, path, fi);
break;
case USE_CODE_READER:
CodeReader reader= fi.getCodeReader();
@@ -1041,18 +1039,12 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
}
}
- private void processInclusionFromIndex(String path, IncludeFileContent fi) {
+ private void processInclusionFromIndex(int offset, String path, IncludeFileContent fi) {
List<IIndexMacro> mdefs= fi.getMacroDefinitions();
for (IIndexMacro macro : mdefs) {
addMacroDefinition(macro);
}
- IIndexFileSet fileSet= fLocationMap.getFileSet();
- if (fileSet != null) {
- List<IIndexFile> 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<IIndexMacro> fMacroDefinitions;
+ private final List<ICPPUsingDirective> fUsingDirectives;
private final String fFileLocation;
private List<IIndexFile> 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 <code>null</code>.
*/
- public IncludeFileContent(String fileLocation, List<IIndexMacro> macroDefinitions, List<IIndexFile> files) {
+ public IncludeFileContent(String fileLocation, List<IIndexMacro> macroDefinitions, List<ICPPUsingDirective> usingDirectives,
+ List<IIndexFile> 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 <code>null</code> if kind is different to {@link InclusionKind#FOUND_IN_INDEX}.
+ */
+ public List<ICPPUsingDirective> 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<IBinding, IASTPreprocessorMacroDefinition> fMacroDefinitionMap= null;
-
-
+ private List<ISkippedIndexedFilesListener> fSkippedFilesListeners= new ArrayList<ISkippedIndexedFilesListener>();
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<FileKey, FileInfo> fFileInfos= new HashMap<FileKey, FileInfo>();
+ private HashMap<FileKey, FileContent> fFileInfos= new HashMap<FileKey, FileContent>();
private Object[] fFilesToUpdate;
private List<Object> fFilesToRemove = new ArrayList<Object>();
@@ -308,7 +310,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
private void requestUpdate(int linkageID, IIndexFileLocation ifl, IIndexFragmentFile ifile) {
FileKey key= new FileKey(linkageID, ifl.getURI());
- FileInfo info= fFileInfos.get(key);
+ FileContent info= fFileInfos.get(key);
if (info == null) {
info= createFileInfo(key, null);
}
@@ -318,7 +320,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
private void setIndexed(int linkageID, IIndexFileLocation ifl) {
FileKey key= new FileKey(linkageID, ifl.getURI());
- FileInfo info= fFileInfos.get(key);
+ FileContent info= fFileInfos.get(key);
if (info == null) {
info= createFileInfo(key, null);
}
@@ -326,14 +328,14 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
info.fMacros= null;
}
- private FileInfo createFileInfo(FileKey key, IIndexFile ifile) {
- FileInfo info = new FileInfo();
+ private FileContent createFileInfo(FileKey key, IIndexFile ifile) {
+ FileContent info = new FileContent();
fFileInfos.put(key, info);
info.fIndexFile= ifile;
return info;
}
- private FileInfo getFileInfo(int linkageID, IIndexFileLocation ifl) {
+ private FileContent getFileInfo(int linkageID, IIndexFileLocation ifl) {
FileKey key= new FileKey(linkageID, ifl.getURI());
return fFileInfos.get(key);
}
@@ -467,7 +469,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return;
final Object tu= iter.next();
final IIndexFileLocation ifl = fResolver.resolveFile(tu);
- final FileInfo info= getFileInfo(linkageID, ifl);
+ final FileContent info= getFileInfo(linkageID, ifl);
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
info.fRequestIsCounted= false;
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, tu);
@@ -489,7 +491,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return;
final Object header= iter.next();
final IIndexFileLocation ifl = fResolver.resolveFile(header);
- final FileInfo info= getFileInfo(linkageID, ifl);
+ final FileContent info= getFileInfo(linkageID, ifl);
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
if (info.fIndexFile != null && fIndex.isWritableFile(info.fIndexFile)) {
Object tu= findContext((IIndexFragmentFile) info.fIndexFile, contextMap);
@@ -517,7 +519,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return;
final Object header= iter.next();
final IIndexFileLocation ifl = fResolver.resolveFile(header);
- final FileInfo info= getFileInfo(linkageID, ifl);
+ final FileContent info= getFileInfo(linkageID, ifl);
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
info.fRequestIsCounted= false;
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, header);
@@ -611,7 +613,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
}
IIndexFileLocation ifl= fResolver.resolveASTPath(astPath);
- FileInfo info= getFileInfo(linkageID, ifl);
+ FileContent info= getFileInfo(linkageID, ifl);
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
orderedIFLs.add(fResolver.resolveASTPath(astPath));
}
@@ -647,7 +649,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
}
public final boolean needToUpdateHeader(int linkageID, IIndexFileLocation ifl) throws CoreException {
- FileInfo info= getFileInfo(linkageID, ifl);
+ FileContent info= getFileInfo(linkageID, ifl);
if (info == null) {
IIndexFile ifile= null;
if (fResolver.canBePartOfSDK(ifl)) {
@@ -752,9 +754,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return result*31 + key.hashCode();
}
- public final IIndexMacro[] getConvertedMacros(int linkageID, IIndexFileLocation ifl) throws CoreException {
+ public final FileContent getFileContent(int linkageID, IIndexFileLocation ifl) throws CoreException {
if (!needToUpdateHeader(linkageID, ifl)) {
- FileInfo info= getFileInfo(linkageID, ifl);
+ FileContent info= getFileInfo(linkageID, ifl);
assert info != null;
if (info != null) {
if (info.fIndexFile == null) {
@@ -763,12 +765,13 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return null;
}
}
- IIndexMacro[] result= info.fMacros;
- if (result == null) {
- result= info.fIndexFile.getMacros();
- info.fMacros= result;
+ if (info.fMacros == null) {
+ info.fMacros= info.fIndexFile.getMacros();
}
- return result;
+ if (info.fDirectives == null) {
+ info.fDirectives= info.fIndexFile.getUsingDirectives();
+ }
+ return info;
}
}
return null;
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 db5347f10f3..79b9a39c3ed 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
@@ -91,7 +91,7 @@ public class PDOM extends PlatformObject implements IPDOM {
*/
public static final String FRAGMENT_PROPERTY_VALUE_FORMAT_ID= "org.eclipse.cdt.internal.core.pdom.PDOM"; //$NON-NLS-1$
- public static final int CURRENT_VERSION = 55;
+ public static final int CURRENT_VERSION = 56;
public static final int MIN_SUPPORTED_VERSION= CURRENT_VERSION;
/**
@@ -156,6 +156,7 @@ public class PDOM extends PlatformObject implements IPDOM {
* 53 - polymorphic method calls (bug 156691)
* 54 - optimization of database size (bug 210392)
* 55 - generalization of local bindings (bug 215783)
+ * 56 - using directives (bug 216527)
*/
public static final int LINKAGES = Database.DATA_AREA;
@@ -709,7 +710,7 @@ public class PDOM extends PlatformObject implements IPDOM {
public IIndexFragmentBinding findBinding(IIndexFragmentName indexName) throws CoreException {
if (indexName instanceof PDOMName) {
PDOMName pdomName= (PDOMName) indexName;
- return pdomName.getPDOMBinding();
+ return pdomName.getBinding();
}
return null;
}
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 89301da89ff..b9dcb7b7362 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
@@ -18,17 +18,16 @@ import java.util.ArrayList;
import java.util.List;
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.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator;
+import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.db.IString;
@@ -184,11 +183,11 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
return new char[0];
}
- public IScope getParent() throws DOMException {
+ public IIndexScope getParent() {
try {
IBinding parent = getParentBinding();
- if(parent instanceof IScope) {
- return (IScope) parent;
+ if(parent instanceof IIndexScope) {
+ return (IIndexScope) parent;
}
} catch(CoreException ce) {
CCorePlugin.log(ce);
@@ -196,11 +195,11 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
return null;
}
- public final IScope getScope() {
+ public final IIndexScope getScope() {
try {
IBinding parent = getParentBinding();
- if(parent instanceof IScope) {
- return (IScope) parent;
+ if(parent instanceof IIndexScope) {
+ return (IIndexScope) parent;
}
} catch(CoreException ce) {
CCorePlugin.log(ce);
@@ -267,7 +266,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
*/
protected final void fail() { throw new PDOMNotImplementedError(); }
- public IName getScopeName() throws DOMException {
+ public PDOMName getScopeName() {
try {
PDOMName name = getFirstDefinition();
if (name == null)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
index f9c0c2e9cf2..7e3f765d90c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
@@ -19,9 +19,12 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.ILinkage;
+import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexLocationConverter;
@@ -58,8 +61,9 @@ public class PDOMFile implements IIndexFragmentFile {
private static final int LINKAGE_ID= 20;
private static final int TIME_STAMP = 24;
private static final int SCANNER_CONFIG_HASH= 32;
+ private static final int FIRST_USING_DIRECTIVE= 36;
- private static final int RECORD_SIZE = 36;
+ private static final int RECORD_SIZE= 40;
public static class Comparator implements IBTreeComparator {
private Database db;
@@ -252,7 +256,7 @@ public class PDOMFile implements IIndexFragmentFile {
PDOMBinding binding = ((WritablePDOM) pdom).addBinding(name);
if (binding != null) {
result= new PDOMName(pdom, name, this, binding, caller);
- binding.getLinkageImpl().onCreateName(result, name);
+ binding.getLinkageImpl().onCreateName(this, name, result);
}
} catch (CoreException e) {
CCorePlugin.log(e);
@@ -261,6 +265,14 @@ public class PDOMFile implements IIndexFragmentFile {
}
public void clear(Collection<IIndexFileLocation> contextsRemoved) throws CoreException {
+ ICPPUsingDirective[] directives= getUsingDirectives();
+ for (ICPPUsingDirective ud : directives) {
+ if (ud instanceof IPDOMNode) {
+ ((IPDOMNode) ud).delete(null);
+ }
+ }
+ setFirstUsingDirectiveRec(0);
+
// Remove the includes
PDOMInclude include = getFirstInclude();
while (include != null) {
@@ -288,7 +300,7 @@ public class PDOMFile implements IIndexFragmentFile {
PDOMName name = getFirstName();
while (name != null) {
names.add(name);
- name.getPDOMBinding().getLinkageImpl().onDeleteName(name);
+ name.getBinding().getLinkageImpl().onDeleteName(name);
name= name.getNextInFile();
}
@@ -503,4 +515,23 @@ public class PDOMFile implements IIndexFragmentFile {
}
setFirstIncludedBy(null);
}
+
+ public int getFirstUsingDirectiveRec() throws CoreException {
+ return pdom.getDB().getInt(record + FIRST_USING_DIRECTIVE);
+ }
+
+ public void setFirstUsingDirectiveRec(int rec) throws CoreException {
+ pdom.getDB().putInt(record + FIRST_USING_DIRECTIVE, rec);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.index.IIndexFile#getUsingDirectives()
+ */
+ public ICPPUsingDirective[] getUsingDirectives() throws CoreException {
+ PDOMLinkage linkage= pdom.getLinkage(ILinkage.CPP_LINKAGE_NAME);
+ if (linkage != null) {
+ return linkage.getUsingDirectives(this);
+ }
+ return ICPPUsingDirective.EMPTY_ARRAY;
+ }
}
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 019f2d59302..5d56fe12063 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
@@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IQualifierType;
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.ICPPUsingDirective;
import org.eclipse.cdt.core.index.IIndexLinkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
@@ -270,14 +271,15 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
public abstract int getBindingType(IBinding binding);
/**
- * Callback informing the linkage that a name has been added. This is
+ * Call-back informing the linkage that a name has been added. This is
* used to do additional processing, like establishing inheritance relationships.
- * @param pdomName the name that was inserted into the linkage
+ * @param file the file that has triggered the creation of the name
* @param name the name that caused the insertion
+ * @param pdomName the name that was inserted into the linkage
* @throws CoreException
* @since 4.0
*/
- public void onCreateName(PDOMName pdomName, IASTName name) throws CoreException {
+ public void onCreateName(PDOMFile file, IASTName name, PDOMName pdomName) throws CoreException {
IASTNode parentNode= name.getParent();
if (parentNode instanceof IASTDeclSpecifier) {
IASTDeclSpecifier ds= (IASTDeclSpecifier) parentNode;
@@ -342,4 +344,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
public void delete(PDOMLinkage linkage) throws CoreException {
assert false; // no need to delete linkages.
}
+
+ public ICPPUsingDirective[] getUsingDirectives(PDOMFile file) throws CoreException {
+ return ICPPUsingDirective.EMPTY_ARRAY;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java
index a8610be992e..fc5b2a26394 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java
@@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
-import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
@@ -124,7 +123,7 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
pdom.getDB().putInt(record + offset, fieldrec);
}
- public PDOMBinding getPDOMBinding() throws CoreException {
+ public PDOMBinding getBinding() throws CoreException {
int bindingrec = getRecField(BINDING_REC_OFFSET);
return pdom.getBinding(bindingrec);
}
@@ -327,13 +326,13 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
else {
switch (getFlags(DECL_DEF_REF_MASK)) {
case IS_DECLARATION:
- getPDOMBinding().setFirstDeclaration(nextName);
+ getBinding().setFirstDeclaration(nextName);
break;
case IS_DEFINITION:
- getPDOMBinding().setFirstDefinition(nextName);
+ getBinding().setFirstDefinition(nextName);
break;
case IS_REFERENCE:
- getPDOMBinding().setFirstReference(nextName);
+ getBinding().setFirstReference(nextName);
break;
}
}
@@ -349,10 +348,6 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
return pdom;
}
- public IIndexFragmentBinding getBinding() throws CoreException {
- return getPDOMBinding();
- }
-
public IIndexName[] getEnclosedNames() throws CoreException {
ArrayList<PDOMName> result= new ArrayList<PDOMName>();
PDOMName name= getNextInFile();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java
index c54c89b81c5..30dde110768 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/c/PDOMCParameter.java
@@ -17,7 +17,6 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
-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.index.IIndexFile;
@@ -25,6 +24,7 @@ import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
+import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
@@ -126,7 +126,7 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment
return new String(getNameCharArray());
}
- public IScope getScope() throws DOMException {
+ public IIndexScope getScope() {
throw new PDOMNotImplementedError();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBase.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBase.java
index ed3406fb8c4..a143b2c36f8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBase.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBase.java
@@ -1,13 +1,13 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 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
- * Markus Schorn (Wind River Systems)
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@@ -93,7 +93,7 @@ class PDOMCPPBase implements ICPPBase, ICPPInternalBase {
try {
PDOMName name= getBaseClassSpecifierNameImpl();
if (name != null) {
- PDOMBinding b = name.getPDOMBinding();
+ PDOMBinding b = name.getBinding();
while( b instanceof PDOMCPPTypedef && ((PDOMCPPTypedef)b).getType() instanceof PDOMBinding ){
b = (PDOMBinding) ((PDOMCPPTypedef)b).getType();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java
index c76f8c16980..8bc912fb33b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPClassTemplate.java
@@ -17,14 +17,12 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
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.IProblemBinding;
-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.ICPPClassTemplate;
@@ -39,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
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.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
@@ -249,7 +248,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
- public IScope getParent() throws DOMException {
+ public IIndexScope getParent() {
return PDOMCPPClassTemplate.super.getParent();
}
@@ -258,7 +257,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return null;
}
- public IName getScopeName() throws DOMException {
+ public IIndexName getScopeName() {
return null;
}
@@ -269,7 +268,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
private PDOMCPPTemplateScope scope;
- public IScope getParent() throws DOMException {
+ public IIndexScope getParent() {
if (scope == null) {
scope = new PDOMCPPTemplateScope();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
index d8e8403d6d4..f94a2e997b3 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java
@@ -15,6 +15,7 @@
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
@@ -33,7 +34,9 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
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.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
@@ -60,6 +63,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
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.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.dom.ast.gnu.cpp.IGPPBasicType;
@@ -68,6 +72,7 @@ import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
@@ -857,8 +862,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
@Override
- public void onCreateName(PDOMName pdomName, IASTName name) throws CoreException {
- super.onCreateName(pdomName, name);
+ public void onCreateName(PDOMFile file, IASTName name, PDOMName pdomName) throws CoreException {
+ super.onCreateName(file, name, pdomName);
IASTNode parentNode= name.getParent();
if (parentNode instanceof ICPPASTQualifiedName) {
@@ -873,7 +878,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
PDOMName derivedClassName= (PDOMName) pdomName.getEnclosingDefinition();
if (derivedClassName != null) {
ICPPASTBaseSpecifier baseNode= (ICPPASTBaseSpecifier) parentNode;
- PDOMBinding derivedClassBinding= derivedClassName.getPDOMBinding();
+ PDOMBinding derivedClassBinding= derivedClassName.getBinding();
if (derivedClassBinding instanceof PDOMCPPClassType) {
PDOMCPPClassType ownerClass = (PDOMCPPClassType)derivedClassBinding;
PDOMCPPBase pdomBase = new PDOMCPPBase(pdom, pdomName, baseNode.isVirtual(), baseNode.getVisibility());
@@ -887,8 +892,58 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
}
}
+ else if (parentNode instanceof ICPPASTUsingDirective) {
+ IScope container= CPPVisitor.getContainingScope(name);
+ try {
+ boolean doit= false;
+ PDOMCPPNamespace containerNS= null;
+
+ IASTNode node= ASTInternal.getPhysicalNodeOfScope(container);
+ if (node instanceof IASTTranslationUnit) {
+ doit= true;
+ }
+ else if (node instanceof ICPPASTNamespaceDefinition) {
+ ICPPASTNamespaceDefinition nsDef= (ICPPASTNamespaceDefinition) node;
+ IASTName nsContainerName= nsDef.getName();
+ if (nsContainerName != null) {
+ PDOMBinding binding= adaptBinding(nsContainerName.resolveBinding());
+ if (binding instanceof PDOMCPPNamespace) {
+ containerNS= (PDOMCPPNamespace) binding;
+ doit= true;
+ }
+ }
+ }
+ if (doit) {
+ int rec= file.getFirstUsingDirectiveRec();
+ PDOMCPPUsingDirective ud= new PDOMCPPUsingDirective(this, rec, containerNS, pdomName.getBinding());
+ file.setFirstUsingDirectiveRec(ud.getRecord());
+ }
+ } catch (DOMException e) {
+ CCorePlugin.log(e);
+ }
+ }
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage#getUsingDirectives()
+ */
+ @Override
+ public ICPPUsingDirective[] getUsingDirectives(PDOMFile file) throws CoreException {
+ int rec= file.getFirstUsingDirectiveRec();
+ if (rec == 0) {
+ return ICPPUsingDirective.EMPTY_ARRAY;
+ }
+ LinkedList<ICPPUsingDirective> uds= new LinkedList<ICPPUsingDirective>();
+ do {
+ PDOMCPPUsingDirective ud= new PDOMCPPUsingDirective(this, rec);
+ uds.addFirst(ud);
+ rec= ud.getPreviousRec();
+ }
+ while (rec != 0);
+ return uds.toArray(new ICPPUsingDirective[uds.size()]);
+ }
+
@Override
public void onDeleteName(PDOMName pdomName) throws CoreException {
super.onDeleteName(pdomName);
@@ -896,7 +951,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
if (pdomName.isBaseSpecifier()) {
PDOMName derivedClassName= (PDOMName) pdomName.getEnclosingDefinition();
if (derivedClassName != null) {
- PDOMBinding derivedClassBinding= derivedClassName.getPDOMBinding();
+ PDOMBinding derivedClassBinding= derivedClassName.getBinding();
if (derivedClassBinding instanceof PDOMCPPClassType) {
PDOMCPPClassType ownerClass = (PDOMCPPClassType)derivedClassBinding;
ownerClass.removeBase(pdomName);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java
index 8cc7ec5187a..d36858deca3 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPParameter.java
@@ -16,7 +16,6 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
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.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
@@ -28,6 +27,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDelegateCreator;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
+import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
@@ -190,7 +190,7 @@ class PDOMCPPParameter extends PDOMNamedNode
return new String(getNameCharArray());
}
- public IScope getScope() throws DOMException {
+ public IIndexScope getScope() {
return null;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUsingDirective.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUsingDirective.java
new file mode 100644
index 00000000000..dd957b2264b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPUsingDirective.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * 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.pdom.dom.cpp;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.IPDOMNode;
+import org.eclipse.cdt.core.dom.IPDOMVisitor;
+import org.eclipse.cdt.core.dom.ast.DOMException;
+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.internal.core.pdom.db.Database;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Stores using directives for global or namespace scope. Directives for block-scopes
+ * are not persisted in the index.
+ * For performance reasons the directives are not stored with their container. Rather
+ * than that they are stored with the file, in which they are encountered.
+ * When parsing a file the directives from headers that are skipped are collected.
+ */
+public class PDOMCPPUsingDirective implements ICPPUsingDirective, IPDOMNode {
+ private static final int CONTAINER_NAMESPACE = 0;
+ private static final int NOMINATED_NAMESPACE = 4;
+ private static final int PREV_DIRECTIVE_OF_FILE = 8;
+ private static final int RECORD_SIZE = 12;
+
+ private final PDOMCPPLinkage fLinkage;
+ private final int fRecord;
+
+ PDOMCPPUsingDirective(PDOMCPPLinkage pdom, int record) {
+ fLinkage= pdom;
+ fRecord= record;
+ }
+
+ public PDOMCPPUsingDirective(PDOMCPPLinkage linkage, int prevRecInFile, PDOMCPPNamespace containerNS, PDOMBinding nominated) throws CoreException {
+ final Database db= linkage.getPDOM().getDB();
+ final int containerRec= containerNS == null ? 0 : containerNS.getRecord();
+ final int nominatedRec= nominated.getRecord();
+
+ fLinkage= linkage;
+ fRecord= db.malloc(RECORD_SIZE);
+ db.putInt(fRecord + CONTAINER_NAMESPACE, containerRec);
+ db.putInt(fRecord + NOMINATED_NAMESPACE, nominatedRec);
+ db.putInt(fRecord + PREV_DIRECTIVE_OF_FILE, prevRecInFile);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getNamespace()
+ */
+ public ICPPNamespaceScope getNominatedScope() {
+ try {
+ int rec = fLinkage.getPDOM().getDB().getInt(fRecord + NOMINATED_NAMESPACE);
+ PDOMNode node= fLinkage.getNode(rec);
+ if (node instanceof ICPPNamespace) {
+ return ((ICPPNamespace) node).getNamespaceScope();
+ }
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ } catch (DOMException e) {
+ }
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getContainingScope()
+ */
+ public IScope getContainingScope() {
+ try {
+ int rec = fLinkage.getPDOM().getDB().getInt(fRecord + CONTAINER_NAMESPACE);
+ if (rec != 0) {
+ PDOMNode node= fLinkage.getNode(rec);
+ if (node instanceof PDOMCPPNamespace) {
+ return (PDOMCPPNamespace) node;
+ }
+ }
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getPointOfDeclaration()
+ */
+ public int getPointOfDeclaration() {
+ return 0;
+ }
+
+ public int getRecord() {
+ return fRecord;
+ }
+
+ public int getPreviousRec() throws CoreException {
+ final Database db= fLinkage.getPDOM().getDB();
+ return db.getInt(fRecord + PREV_DIRECTIVE_OF_FILE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.dom.IPDOMNode#accept(org.eclipse.cdt.core.dom.IPDOMVisitor)
+ */
+ public void accept(IPDOMVisitor visitor) throws CoreException {
+ }
+
+ public void delete(PDOMLinkage linkage) throws CoreException {
+ fLinkage.getPDOM().getDB().free(fRecord);
+ }
+}

Back to the top