1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Using directives for fast indexer (including namespace composition), bug 200673+216527.

This commit is contained in:
Markus Schorn 2008-02-12 14:21:22 +00:00
parent b848ef7a4d
commit 5688a0ac9f
35 changed files with 841 additions and 188 deletions

View file

@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; 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.ICPPClassTemplate;
@ -35,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; 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.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; 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.ICPPTemplateInstance;
@ -752,4 +754,53 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas
assertTrue(outer instanceof ICPPClassScope); assertTrue(outer instanceof ICPPClassScope);
assertEquals("outer", outer.getScopeName().toString()); assertEquals("outer", outer.getScopeName().toString());
} }
// namespace ns {
// int v;
// };
// using namespace ns;
// #include "header.h"
// void test() {
// v=1;
// }
public void testUsingDirective_Bug216527() throws Exception {
IBinding b = getBindingFromASTName("v=", 1);
assertTrue(b instanceof IVariable);
IVariable v= (IVariable) b;
IScope scope= v.getScope();
assertTrue(scope instanceof ICPPNamespaceScope);
assertEquals("ns", scope.getScopeName().toString());
}
// namespace NSA {
// int a;
// }
// namespace NSB {
// int b;
// }
// namespace NSAB {
// using namespace NSA;
// using namespace NSB;
// }
// #include "header.h"
// void f() {
// NSAB::a= NSAB::b;
// }
public void testNamespaceComposition_Bug200673() throws Exception {
IBinding a = getBindingFromASTName("a=", 1);
assertTrue(a instanceof IVariable);
IVariable v= (IVariable) a;
IScope scope= v.getScope();
assertTrue(scope instanceof ICPPNamespaceScope);
assertEquals("NSA", scope.getScopeName().toString());
IBinding b = getBindingFromASTName("b;", 1);
assertTrue(b instanceof IVariable);
v= (IVariable) b;
scope= v.getScope();
assertTrue(scope instanceof ICPPNamespaceScope);
assertEquals("NSB", scope.getScopeName().toString());
}
} }

View file

@ -121,9 +121,10 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
// class B {}; // class B {};
// } // }
// #include "header.h"
// namespace n { class C{}; } // namespace n { class C{}; }
// m::C c; // m::C c;
public void _testUsingNamingDirective_177917_1b() { public void testUsingNamingDirective_177917_1b() {
IBinding b0= getBindingFromASTName("C c", 1); IBinding b0= getBindingFromASTName("C c", 1);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,23 +7,27 @@
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom; package org.eclipse.cdt.core.dom;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
* @author Doug Schaefer * Interface for all nodes that can be visited by a {@link IPDOMVisitor}.
*
*/ */
public interface IPDOMNode { public interface IPDOMNode {
/** /**
* Visit the children of this node. * Visits the children of this node.
*
* @param visitor
* @throws CoreException
*/ */
public void accept(IPDOMVisitor visitor) throws CoreException; 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;
} }

View file

@ -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; package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException; 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; 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 * @since 5.0
*/ */
public interface ICPPUsingDirective { public interface ICPPUsingDirective {
ICPPUsingDirective[] EMPTY_ARRAY = new ICPPUsingDirective[0];
/** /**
* Returns the scope of the namespace that is nominated by this * 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()}). * Returns the point of declaration as global offset ({@link ASTNode#getOffset()}).
*/ */
int getPointOfDeclaration(); int getPointOfDeclaration();
/**
* Returns the scope containing this directive.
*/
IScope getContainingScope();
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -9,9 +9,9 @@
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.index; package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -53,6 +53,13 @@ public interface IIndexFile {
*/ */
IIndexMacro[] getMacros() throws CoreException; 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. * Last modification of file before it was indexed.
* @return the last modification date of the file at the time it was parsed. * @return the last modification date of the file at the time it was parsed.

View file

@ -12,6 +12,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName; 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.CASTVisitor;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.index.IIndex; 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.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; 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.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; import org.eclipse.core.runtime.CoreException;
/** /**
* @author jcamelon * @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 IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[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) { public void setIsHeaderUnit(boolean headerUnit) {
fIsHeader= 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);
}
}
}
} }

View file

@ -11,7 +11,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; 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.CCorePlugin;
import org.eclipse.cdt.core.dom.IName; 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.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndex; 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.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil; 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.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter;
import org.eclipse.cdt.internal.core.index.IIndexScope; 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.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; import org.eclipse.core.runtime.CoreException;
/** /**
* @author jcamelon * @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 IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0]; private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
@ -88,7 +91,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
private IIndex index; private IIndex index;
private IIndexFileSet fIndexFileSet; private IIndexFileSet fIndexFileSet;
private boolean fIsHeader= true; private boolean fIsHeader= true;
private HashMap<IIndexScope, IScope> fMappedScopes= new HashMap<IIndexScope, IScope>(); private CPPScopeMapper fScopeMapper= new CPPScopeMapper(this);
public CPPASTTranslationUnit() { public CPPASTTranslationUnit() {
} }
@ -535,19 +538,32 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
fIsHeader= 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) {
final List<IIndexFile> files= fileContent.getFilesIncluded();
for (IIndexFile indexFile : files) {
fIndexFileSet.add(indexFile);
}
}
fScopeMapper.registerAdditionalDirectives(offset, fileContent.getUsingDirectives());
}
// bug 217102: namespace scopes from the index have to be mapped back to the AST. // bug 217102: namespace scopes from the index have to be mapped back to the AST.
IScope mapToASTScope(IIndexScope scope) { IScope mapToASTScope(IIndexScope scope) {
if (scope instanceof ICPPNamespaceScope) { return fScopeMapper.mapToASTScope(scope);
IScope result= fMappedScopes.get(scope);
if (result == null) {
result= getScope().findNamespaceScope(scope);
if (result == null) {
result= scope;
} }
fMappedScopes.put(scope, result);
/**
* Stores directives from the index into this scope.
*/
void handleAdditionalDirectives(ICPPNamespaceScope scope) {
fScopeMapper.handleAdditionalDirectives(scope);
} }
return result;
} IIndexFileSet getFileSet() {
return scope; return fIndexFileSet;
} }
} }

View file

@ -11,9 +11,6 @@
* Bryan Wilkinson (QNX) * Bryan Wilkinson (QNX)
* Andrew Ferguson (Symbian) * Andrew Ferguson (Symbian)
*******************************************************************************/ *******************************************************************************/
/*
* Created on Nov 29, 2004
*/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import java.util.ArrayList; import java.util.ArrayList;
@ -247,7 +244,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
return false; return false;
if(forName == null) if(forName == null)
return true; return true;
if(!forName.isReference() && !CPPSemantics.declaredBefore(candidate, forName)) if(!forName.isReference() && !CPPSemantics.declaredBefore(candidate, forName, false))
return false; return false;
return true; return true;
} }

View file

@ -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;
}
}
}

View file

@ -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.ICPPTemplateTypeParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration; 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.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.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexFileSet;
@ -1021,12 +1022,12 @@ public class CPPSemantics {
IASTNode node = data.astName; IASTNode node = data.astName;
IIndexFileSet fileSet= IIndexFileSet.EMPTY; IIndexFileSet fileSet= IIndexFileSet.EMPTY;
if (node != null) { boolean isIndexBased= false;
if (data.tu != null) { if (data.tu != null) {
final IIndexFileSet fs= (IIndexFileSet) data.tu.getAdapter(IIndexFileSet.class); final IIndexFileSet fs= data.tu.getFileSet();
if (fs != null) { if (fs != null) {
fileSet= fs; fileSet= fs;
} isIndexBased= true;
} }
} }
@ -1048,6 +1049,9 @@ public class CPPSemantics {
} }
while( scope != null ){ while( scope != null ){
if (scope instanceof IIndexScope && data.tu != null) {
scope= (ICPPScope) data.tu.mapToASTScope(((IIndexScope) scope));
}
IASTNode blockItem = CPPVisitor.getContainingBlockItem( node ); IASTNode blockItem = CPPVisitor.getContainingBlockItem( node );
if( !data.usingDirectivesOnly ){ if( !data.usingDirectivesOnly ){
@ -1055,7 +1059,7 @@ public class CPPSemantics {
if (!data.contentAssist && data.astName != null) { if (!data.contentAssist && data.astName != null) {
IBinding binding = scope.getBinding( data.astName, true, fileSet ); IBinding binding = scope.getBinding( data.astName, true, fileSet );
if( binding != null && if( binding != null &&
( CPPSemantics.declaredBefore( binding, data.astName ) || ( CPPSemantics.declaredBefore( binding, data.astName, isIndexBased ) ||
(scope instanceof ICPPClassScope && data.checkWholeClassScope) ) ) (scope instanceof ICPPClassScope && data.checkWholeClassScope) ) )
{ {
mergeResults( data, binding, true ); mergeResults( data, binding, true );
@ -1103,13 +1107,16 @@ public class CPPSemantics {
final ICPPNamespaceScope blockScope= (ICPPNamespaceScope) scope; final ICPPNamespaceScope blockScope= (ICPPNamespaceScope) scope;
if (! (blockScope instanceof ICPPBlockScope)) { if (! (blockScope instanceof ICPPBlockScope)) {
data.visited.put(blockScope); // namespace has been searched. data.visited.put(blockScope); // namespace has been searched.
if (data.tu != null) {
data.tu.handleAdditionalDirectives(blockScope);
}
} }
ICPPUsingDirective[] uds= blockScope.getUsingDirectives(); ICPPUsingDirective[] uds= blockScope.getUsingDirectives();
if( uds != null && uds.length > 0) { if( uds != null && uds.length > 0) {
HashSet<ICPPNamespaceScope> handled= new HashSet<ICPPNamespaceScope>(); HashSet<ICPPNamespaceScope> handled= new HashSet<ICPPNamespaceScope>();
for( int i = 0; i < uds.length; i++ ){ for( int i = 0; i < uds.length; i++ ){
final ICPPUsingDirective ud = uds[i]; final ICPPUsingDirective ud = uds[i];
if( CPPSemantics.declaredBefore( ud, data.astName ) ){ if( CPPSemantics.declaredBefore( ud, data.astName, false ) ){
storeUsingDirective(data, blockScope, ud, handled); storeUsingDirective(data, blockScope, ud, handled);
} }
} }
@ -1390,11 +1397,10 @@ public class CPPSemantics {
*/ */
static private void storeUsingDirective(CPPSemantics.LookupData data, ICPPNamespaceScope container, static private void storeUsingDirective(CPPSemantics.LookupData data, ICPPNamespaceScope container,
ICPPUsingDirective directive, Set<ICPPNamespaceScope> handled) throws DOMException { ICPPUsingDirective directive, Set<ICPPNamespaceScope> handled) throws DOMException {
final ICPPNamespace nsBinding = directive.getNamespace(); ICPPNamespaceScope nominated= directive.getNominatedScope();
if (nsBinding == null) { if (nominated instanceof IIndexScope && data.tu != null) {
return; nominated= (ICPPNamespaceScope) data.tu.mapToASTScope((IIndexScope) nominated);
} }
final ICPPNamespaceScope nominated= nsBinding.getNamespaceScope();
if (nominated == null || data.visited.containsKey(nominated) || (handled != null && !handled.add(nominated))) { if (nominated == null || data.visited.containsKey(nominated) || (handled != null && !handled.add(nominated))) {
return; return;
} }
@ -1417,6 +1423,9 @@ public class CPPSemantics {
// container. // container.
if (!data.qualified() || data.contentAssist) { if (!data.qualified() || data.contentAssist) {
assert handled != null; assert handled != null;
if (data.tu != null) {
data.tu.handleAdditionalDirectives(nominated);
}
ICPPUsingDirective[] transitive= nominated.getUsingDirectives(); ICPPUsingDirective[] transitive= nominated.getUsingDirectives();
for (int i = 0; i < transitive.length; i++) { for (int i = 0; i < transitive.length; i++) {
storeUsingDirective(data, container, transitive[i], handled); storeUsingDirective(data, container, transitive[i], handled);
@ -1448,6 +1457,7 @@ public class CPPSemantics {
* @throws DOMException * @throws DOMException
*/ */
static protected IASTName[] lookupInScope( CPPSemantics.LookupData data, ICPPScope scope, IASTNode blockItem ) 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; Object possible = null;
IASTNode [] nodes = null; IASTNode [] nodes = null;
IASTNode parent = ASTInternal.getPhysicalNodeOfScope(scope); IASTNode parent = ASTInternal.getPhysicalNodeOfScope(scope);
@ -1549,7 +1559,7 @@ public class CPPSemantics {
temp = ((IASTName[])possible)[++jdx]; temp = ((IASTName[])possible)[++jdx];
while( temp != null ) { while( temp != null ) {
if( (checkWholeClassScope || declaredBefore( temp, data.astName )) && if( (checkWholeClassScope || declaredBefore( temp, data.astName, isIndexBased )) &&
(item != blockItem || data.includeBlockItem( item )) ) (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 // the lookup did not succeed. In the qualified case this is done earlier, when the directive
// is encountered. // is encountered.
if (!found && data.qualified() && !data.contentAssist) { if (!found && data.qualified() && !data.contentAssist) {
if (data.tu != null) {
data.tu.handleAdditionalDirectives(nominated);
}
ICPPUsingDirective[] usings= nominated.getUsingDirectives(); ICPPUsingDirective[] usings= nominated.getUsingDirectives();
for (int i = 0; i < usings.length; i++) { for (int i = 0; i < usings.length; i++) {
ICPPUsingDirective using = usings[i]; ICPPUsingDirective using = usings[i];
@ -1918,7 +1931,7 @@ public class CPPSemantics {
return new CPPCompositeBinding( result ); 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 == null ) return true;
if( node.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return true; if( node.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return true;
final int pointOfRef= ((ASTNode) node).getOffset(); final int pointOfRef= ((ASTNode) node).getOffset();
@ -1931,6 +1944,21 @@ public class CPPSemantics {
int pointOfDecl= -1; int pointOfDecl= -1;
if( obj instanceof ICPPInternalBinding ){ if( obj instanceof ICPPInternalBinding ){
ICPPInternalBinding cpp = (ICPPInternalBinding) obj; 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(); IASTNode[] n = cpp.getDeclarations();
if( n != null && n.length > 0 ) { if( n != null && n.length > 0 ) {
nd = (ASTNode) n[0]; nd = (ASTNode) n[0];
@ -1986,6 +2014,7 @@ public class CPPSemantics {
if( !data.hasResults() || data.contentAssist ) if( !data.hasResults() || data.contentAssist )
return null; return null;
final boolean indexBased= data.tu == null ? false : data.tu.getIndex() != null;
IBinding type = null; IBinding type = null;
IBinding obj = null; IBinding obj = null;
IBinding temp = null; IBinding temp = null;
@ -1996,7 +2025,7 @@ public class CPPSemantics {
Object [] items = (Object[]) data.foundItems; Object [] items = (Object[]) data.foundItems;
for( int i = 0; i < items.length && items[i] != null; i++ ){ for( int i = 0; i < items.length && items[i] != null; i++ ){
Object o = items[i]; Object o = items[i];
boolean declaredBefore = declaredBefore( o, name ); boolean declaredBefore = declaredBefore( o, name, indexBased );
boolean checkResolvedNamesOnly= false; boolean checkResolvedNamesOnly= false;
if( !data.checkWholeClassScope && !declaredBefore) { if( !data.checkWholeClassScope && !declaredBefore) {
if (!name.isReference()) { if (!name.isReference()) {
@ -2724,6 +2753,7 @@ public class CPPSemantics {
} catch ( DOMException e1 ) { } catch ( DOMException e1 ) {
return null; return null;
} }
final boolean isIndexBased= data.tu == null ? false : data.tu.getIndex() != null;
if( data.hasResults() ){ if( data.hasResults() ){
Object [] items = (Object[]) data.foundItems; Object [] items = (Object[]) data.foundItems;
IBinding temp = null; IBinding temp = null;
@ -2734,7 +2764,7 @@ public class CPPSemantics {
temp = ((IASTName) o).resolveBinding(); temp = ((IASTName) o).resolveBinding();
else if( o instanceof IBinding ){ else if( o instanceof IBinding ){
temp = (IBinding) o; temp = (IBinding) o;
if( !declaredBefore( temp, name ) ) if( !declaredBefore( temp, name, isIndexBased ) )
continue; continue;
} else } else
continue; continue;

View file

@ -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.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; 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.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
@ -43,10 +45,10 @@ public class CPPUsingDirective implements ICPPUsingDirective {
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getNamespaceScope() * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getNamespaceScope()
*/ */
public ICPPNamespace getNamespace() throws DOMException { public ICPPNamespaceScope getNominatedScope() throws DOMException {
IBinding binding= fNamespaceName.resolveBinding(); IBinding binding= fNamespaceName.resolveBinding();
if (binding instanceof ICPPNamespace) { if (binding instanceof ICPPNamespace) {
return (ICPPNamespace) binding; return ((ICPPNamespace) binding).getNamespaceScope();
} }
return null; return null;
} }
@ -58,4 +60,11 @@ public class CPPUsingDirective implements ICPPUsingDirective {
final ASTNode astNode = (ASTNode) fNamespaceName; final ASTNode astNode = (ASTNode) fNamespaceName;
return astNode.getOffset() + astNode.getLength(); return astNode.getOffset() + astNode.getLength();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective#getContainingScope()
*/
public IScope getContainingScope() {
return CPPVisitor.getContainingScope(fNamespaceName);
}
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * 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 * Returns the constant identifying the type of binding stored in the index
*/ */
int getBindingConstant(); int getBindingConstant();
/**
* Returns the scope that contains this binding, or <code>null</code> for bindings in global scope.
*/
IIndexScope getScope();
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others. * Copyright (c) 2007, 2008 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,11 +7,13 @@
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.index; package org.eclipse.cdt.internal.core.index;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.index.IIndexBinding; 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 { public interface IIndexScope extends IScope {
/** /**
* Get the binding associated with scope * Get the binding associated with scope
* @return
*/ */
IIndexBinding getScopeBinding(); 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();
} }

View file

@ -24,6 +24,7 @@ import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ICodeReaderFactory; 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.IIndex;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation; 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.parser.scanner.IncludeFileContent.InclusionKind;
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver; import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask; import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask;
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.FileContent;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -102,15 +104,18 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
IIndexFile file= fIndex.getFile(fLinkage, ifl); IIndexFile file= fIndex.getFile(fLinkage, ifl);
if (file != null) { if (file != null) {
try { try {
LinkedHashMap<IIndexFileLocation, IIndexMacro[]> macroMap= new LinkedHashMap<IIndexFileLocation, IIndexMacro[]>(); LinkedHashMap<IIndexFileLocation, FileContent> fileContentMap= new LinkedHashMap<IIndexFileLocation, FileContent>();
List<IIndexFile> files= new ArrayList<IIndexFile>(); List<IIndexFile> files= new ArrayList<IIndexFile>();
collectMacros(file, macroMap, files, false); collectFileContent(file, fileContentMap, files, false);
ArrayList<IIndexMacro> allMacros= new ArrayList<IIndexMacro>(); ArrayList<IIndexMacro> allMacros= new ArrayList<IIndexMacro>();
for (Map.Entry<IIndexFileLocation,IIndexMacro[]> entry : macroMap.entrySet()) { ArrayList<ICPPUsingDirective> allDirectives= new ArrayList<ICPPUsingDirective>();
allMacros.addAll(Arrays.asList(entry.getValue())); 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()); fIncludedFiles.add(entry.getKey());
} }
return new IncludeFileContent(path, allMacros, files); return new IncludeFileContent(path, allMacros, allDirectives, files);
} }
catch (NeedToParseException e) { catch (NeedToParseException e) {
} }
@ -132,22 +137,24 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
return fIncludedFiles.contains(ifl); 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(); IIndexFileLocation ifl= file.getLocation();
if (macroMap.containsKey(ifl) || (checkIncluded && fIncludedFiles.contains(ifl))) { if (macroMap.containsKey(ifl) || (checkIncluded && fIncludedFiles.contains(ifl))) {
return; return;
} }
IIndexMacro[] converted; FileContent content;
if (fRelatedIndexerTask != null) { if (fRelatedIndexerTask != null) {
converted= fRelatedIndexerTask.getConvertedMacros(fLinkage, ifl); content= fRelatedIndexerTask.getFileContent(fLinkage, ifl);
if (converted == null) { if (content == null) {
throw new NeedToParseException(); throw new NeedToParseException();
} }
} }
else { 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); files.add(file);
// follow the includes // follow the includes
@ -156,7 +163,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
final IIndexInclude indexInclude = includeDirectives[i]; final IIndexInclude indexInclude = includeDirectives[i];
IIndexFile includedFile= fIndex.resolveInclude(indexInclude); IIndexFile includedFile= fIndex.resolveInclude(indexInclude);
if (includedFile != null) { if (includedFile != null) {
collectMacros(includedFile, macroMap, files, true); collectFileContent(includedFile, macroMap, files, true);
} }
} }
} }

View file

@ -7,17 +7,17 @@
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite; package org.eclipse.cdt.internal.core.index.composite;
import org.eclipse.cdt.core.CCorePlugin; 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.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.index.IIndexFileSet; 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.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCompositeBinding; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCompositeBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPUsingDeclaration;
@ -44,17 +44,17 @@ public abstract class CompositeScope implements IIndexScope {
this.rbinding = rbinding; this.rbinding = rbinding;
} }
final public IScope getParent() throws DOMException { final public IIndexScope getParent() {
IIndexScope rscope = (IIndexScope) rbinding.getScope(); IIndexScope rscope = rbinding.getScope();
if(rscope!=null) { if(rscope!=null) {
return cf.getCompositeScope(rscope); return cf.getCompositeScope(rscope);
} }
return null; return null;
} }
public IName getScopeName() throws DOMException { public IIndexName getScopeName() {
if(rbinding instanceof IScope) if(rbinding instanceof IIndexScope)
return ((IScope) rbinding).getScopeName(); return ((IIndexScope) rbinding).getScopeName();
return null; return null;
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others. * Copyright (c) 2007, 2008 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.core.index.composite; package org.eclipse.cdt.internal.core.index.composite;
import org.eclipse.cdt.core.dom.ast.DOMException; 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.dom.ast.IType;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
@ -20,7 +19,7 @@ import org.eclipse.cdt.internal.core.index.IIndexType;
public interface ICompositesFactory { 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 * Returns a composite (in the sense of potentially spanning multiple index fragments - i.e. not to be confused

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others. * Copyright (c) 2007, 2008 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -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.IParameter;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType; 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
@ -50,14 +49,14 @@ public class CCompositesFactory extends AbstractCompositeFactory implements ICom
/* (non-Javadoc) /* (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) * @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) if(rscope==null)
return null; return null;
if(rscope instanceof ICCompositeTypeScope) { if(rscope instanceof ICCompositeTypeScope) {
try { try {
ICCompositeTypeScope cscope = (ICCompositeTypeScope) rscope; ICCompositeTypeScope cscope = (ICCompositeTypeScope) rscope;
IIndexFragmentBinding rbinding = (IIndexFragmentBinding) cscope.getCompositeType(); IIndexFragmentBinding rbinding = (IIndexFragmentBinding) cscope.getCompositeType();
return ((ICompositeType)getCompositeBinding(rbinding)).getCompositeScope(); return (IIndexScope) ((ICompositeType)getCompositeBinding(rbinding)).getCompositeScope();
} catch(DOMException de) { } catch(DOMException de) {
CCorePlugin.log(de); CCorePlugin.log(de);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Symbian Software Systems and others. * Copyright (c) 2007, 2008 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -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.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IPointerType; import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IQualifierType; 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; 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.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.index.CIndex; import org.eclipse.cdt.internal.core.index.CIndex;
@ -46,8 +69,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory implements IC
/* (non-Javadoc) /* (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) * @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 { public IIndexScope getCompositeScope(IIndexScope rscope) {
IScope result; IIndexScope result;
try { try {
if(rscope == null) { if(rscope == null) {

View file

@ -11,18 +11,18 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp; 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.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet; 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.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; 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.CompositeScope;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory; import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@ -75,11 +75,11 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace
return cf.getCompositeBinding(rbinding); return cf.getCompositeBinding(rbinding);
} }
public IName getScopeName() throws DOMException { public IIndexName getScopeName() {
for(int i=0; i<namespaces.length; i++) { for(int i=0; i<namespaces.length; i++) {
if(namespaces[i] instanceof IScope) { if(namespaces[i] instanceof IIndexScope) {
IScope s= (IScope) namespaces[i]; IIndexScope s= (IIndexScope) namespaces[i];
IName nm= s.getScopeName(); IIndexName nm= s.getScopeName();
if(nm!=null) if(nm!=null)
return nm; return nm;
} }

View file

@ -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.IASTName;
import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; 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.index.IIndexMacro;
import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
@ -1014,7 +1012,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
path= fi.getFileLocation(); path= fi.getFileLocation();
switch(fi.getKind()) { switch(fi.getKind()) {
case FOUND_IN_INDEX: case FOUND_IN_INDEX:
processInclusionFromIndex(path, fi); processInclusionFromIndex(poundOffset, path, fi);
break; break;
case USE_CODE_READER: case USE_CODE_READER:
CodeReader reader= fi.getCodeReader(); 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(); List<IIndexMacro> mdefs= fi.getMacroDefinitions();
for (IIndexMacro macro : mdefs) { for (IIndexMacro macro : mdefs) {
addMacroDefinition(macro); addMacroDefinition(macro);
} }
IIndexFileSet fileSet= fLocationMap.getFileSet(); fLocationMap.skippedFile(fLocationMap.getSequenceNumberForOffset(offset), fi);
if (fileSet != null) {
List<IIndexFile> files= fi.getFilesIncluded();
for (IIndexFile indexFile : files) {
fileSet.add(indexFile);
}
}
} }
private char[] extractHeaderName(final char[] image, final char startDelim, final char endDelim, int[] offsets) { private char[] extractHeaderName(final char[] image, final char startDelim, final char endDelim, int[] offsets) {

View file

@ -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);
}

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.List; 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.IIndexFile;
import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.CodeReader;
@ -40,6 +41,7 @@ public class IncludeFileContent {
private final InclusionKind fKind; private final InclusionKind fKind;
private final CodeReader fCodeReader; private final CodeReader fCodeReader;
private final List<IIndexMacro> fMacroDefinitions; private final List<IIndexMacro> fMacroDefinitions;
private final List<ICPPUsingDirective> fUsingDirectives;
private final String fFileLocation; private final String fFileLocation;
private List<IIndexFile> fFiles; private List<IIndexFile> fFiles;
@ -57,6 +59,7 @@ public class IncludeFileContent {
fKind= kind; fKind= kind;
fFileLocation= fileLocation; fFileLocation= fileLocation;
fMacroDefinitions= null; fMacroDefinitions= null;
fUsingDirectives= null;
fCodeReader= null; fCodeReader= null;
} }
@ -73,6 +76,7 @@ public class IncludeFileContent {
fFileLocation= codeReader.getPath(); fFileLocation= codeReader.getPath();
fCodeReader= codeReader; fCodeReader= codeReader;
fMacroDefinitions= null; fMacroDefinitions= null;
fUsingDirectives= null;
if (fFileLocation == null) { if (fFileLocation == null) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@ -85,10 +89,12 @@ public class IncludeFileContent {
* @param files * @param files
* @throws IllegalArgumentException in case the fileLocation or the macroDefinitions are <code>null</code>. * @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; fKind= InclusionKind.FOUND_IN_INDEX;
fFileLocation= fileLocation; fFileLocation= fileLocation;
fCodeReader= null; fCodeReader= null;
fUsingDirectives= usingDirectives;
fMacroDefinitions= macroDefinitions; fMacroDefinitions= macroDefinitions;
fFiles= files; fFiles= files;
} }
@ -123,6 +129,13 @@ public class IncludeFileContent {
return fMacroDefinitions; 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}. * Valid with {@link InclusionKind#FOUND_IN_INDEX}.

View file

@ -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.IBinding;
import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree; 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.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 * 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 // stuff computed on demand
private IdentityHashMap<IBinding, IASTPreprocessorMacroDefinition> fMacroDefinitionMap= null; private IdentityHashMap<IBinding, IASTPreprocessorMacroDefinition> fMacroDefinitionMap= null;
private List<ISkippedIndexedFilesListener> fSkippedFilesListeners= new ArrayList<ISkippedIndexedFilesListener>();
public void registerPredefinedMacro(IMacroBinding macro) { public void registerPredefinedMacro(IMacroBinding macro) {
registerPredefinedMacro(macro, null, -1); registerPredefinedMacro(macro, null, -1);
@ -312,6 +309,9 @@ public class LocationMap implements ILocationResolver {
public void setRootNode(IASTTranslationUnit root) { public void setRootNode(IASTTranslationUnit root) {
fTranslationUnit= root; fTranslationUnit= root;
if (fTranslationUnit instanceof ISkippedIndexedFilesListener) {
fSkippedFilesListeners.add((ISkippedIndexedFilesListener) root);
}
} }
public String getTranslationUnitPath() { public String getTranslationUnitPath() {
@ -600,14 +600,9 @@ public class LocationMap implements ILocationResolver {
public void cleanup() { public void cleanup() {
} }
public ASTPreprocessorSelectionResult getPreprocessorNode(String path, int offset, int length) { public void skippedFile(int sequenceNumber, IncludeFileContent fi) {
throw new UnsupportedOperationException(); for (ISkippedIndexedFilesListener l : fSkippedFilesListeners) {
} l.skippedFile(sequenceNumber, fi);
}
public IIndexFileSet getFileSet() {
if (fTranslationUnit != null) {
return (IIndexFileSet) fTranslationUnit.getAdapter(IIndexFileSet.class);
}
return null;
} }
} }

View file

@ -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;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree; 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.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.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation; import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IIndexInclude;
@ -76,18 +77,19 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
} }
private static class FileInfo { public static class FileContent {
IIndexFile fIndexFile= null; private IIndexFile fIndexFile= null;
boolean fRequestUpdate= false; private boolean fRequestUpdate= false;
boolean fRequestIsCounted= true; private boolean fRequestIsCounted= true;
boolean fIsUpdated= false; private boolean fIsUpdated= false;
public IIndexMacro[] fMacros; public IIndexMacro[] fMacros;
public ICPPUsingDirective[] fDirectives;
} }
private int fUpdateFlags= IIndexManager.UPDATE_ALL; private int fUpdateFlags= IIndexManager.UPDATE_ALL;
private boolean fIndexHeadersWithoutContext= true; private boolean fIndexHeadersWithoutContext= true;
private boolean fIndexFilesWithoutConfiguration= 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 Object[] fFilesToUpdate;
private List<Object> fFilesToRemove = new ArrayList<Object>(); 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) { private void requestUpdate(int linkageID, IIndexFileLocation ifl, IIndexFragmentFile ifile) {
FileKey key= new FileKey(linkageID, ifl.getURI()); FileKey key= new FileKey(linkageID, ifl.getURI());
FileInfo info= fFileInfos.get(key); FileContent info= fFileInfos.get(key);
if (info == null) { if (info == null) {
info= createFileInfo(key, null); info= createFileInfo(key, null);
} }
@ -318,7 +320,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
private void setIndexed(int linkageID, IIndexFileLocation ifl) { private void setIndexed(int linkageID, IIndexFileLocation ifl) {
FileKey key= new FileKey(linkageID, ifl.getURI()); FileKey key= new FileKey(linkageID, ifl.getURI());
FileInfo info= fFileInfos.get(key); FileContent info= fFileInfos.get(key);
if (info == null) { if (info == null) {
info= createFileInfo(key, null); info= createFileInfo(key, null);
} }
@ -326,14 +328,14 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
info.fMacros= null; info.fMacros= null;
} }
private FileInfo createFileInfo(FileKey key, IIndexFile ifile) { private FileContent createFileInfo(FileKey key, IIndexFile ifile) {
FileInfo info = new FileInfo(); FileContent info = new FileContent();
fFileInfos.put(key, info); fFileInfos.put(key, info);
info.fIndexFile= ifile; info.fIndexFile= ifile;
return info; return info;
} }
private FileInfo getFileInfo(int linkageID, IIndexFileLocation ifl) { private FileContent getFileInfo(int linkageID, IIndexFileLocation ifl) {
FileKey key= new FileKey(linkageID, ifl.getURI()); FileKey key= new FileKey(linkageID, ifl.getURI());
return fFileInfos.get(key); return fFileInfos.get(key);
} }
@ -467,7 +469,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return; return;
final Object tu= iter.next(); final Object tu= iter.next();
final IIndexFileLocation ifl = fResolver.resolveFile(tu); 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) { if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
info.fRequestIsCounted= false; info.fRequestIsCounted= false;
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, tu); final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, tu);
@ -489,7 +491,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return; return;
final Object header= iter.next(); final Object header= iter.next();
final IIndexFileLocation ifl = fResolver.resolveFile(header); 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 != null && info.fRequestUpdate && !info.fIsUpdated) {
if (info.fIndexFile != null && fIndex.isWritableFile(info.fIndexFile)) { if (info.fIndexFile != null && fIndex.isWritableFile(info.fIndexFile)) {
Object tu= findContext((IIndexFragmentFile) info.fIndexFile, contextMap); Object tu= findContext((IIndexFragmentFile) info.fIndexFile, contextMap);
@ -517,7 +519,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return; return;
final Object header= iter.next(); final Object header= iter.next();
final IIndexFileLocation ifl = fResolver.resolveFile(header); 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 != null && info.fRequestUpdate && !info.fIsUpdated) {
info.fRequestIsCounted= false; info.fRequestIsCounted= false;
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, header); final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, header);
@ -611,7 +613,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
IIndexFileLocation ifl= fResolver.resolveASTPath(astPath); IIndexFileLocation ifl= fResolver.resolveASTPath(astPath);
FileInfo info= getFileInfo(linkageID, ifl); FileContent info= getFileInfo(linkageID, ifl);
if (info != null && info.fRequestUpdate && !info.fIsUpdated) { if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
orderedIFLs.add(fResolver.resolveASTPath(astPath)); 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 { public final boolean needToUpdateHeader(int linkageID, IIndexFileLocation ifl) throws CoreException {
FileInfo info= getFileInfo(linkageID, ifl); FileContent info= getFileInfo(linkageID, ifl);
if (info == null) { if (info == null) {
IIndexFile ifile= null; IIndexFile ifile= null;
if (fResolver.canBePartOfSDK(ifl)) { if (fResolver.canBePartOfSDK(ifl)) {
@ -752,9 +754,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return result*31 + key.hashCode(); 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)) { if (!needToUpdateHeader(linkageID, ifl)) {
FileInfo info= getFileInfo(linkageID, ifl); FileContent info= getFileInfo(linkageID, ifl);
assert info != null; assert info != null;
if (info != null) { if (info != null) {
if (info.fIndexFile == null) { if (info.fIndexFile == null) {
@ -763,12 +765,13 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return null; return null;
} }
} }
IIndexMacro[] result= info.fMacros; if (info.fMacros == null) {
if (result == null) { info.fMacros= info.fIndexFile.getMacros();
result= info.fIndexFile.getMacros();
info.fMacros= result;
} }
return result; if (info.fDirectives == null) {
info.fDirectives= info.fIndexFile.getUsingDirectives();
}
return info;
} }
} }
return null; return null;

View file

@ -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 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; 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) * 53 - polymorphic method calls (bug 156691)
* 54 - optimization of database size (bug 210392) * 54 - optimization of database size (bug 210392)
* 55 - generalization of local bindings (bug 215783) * 55 - generalization of local bindings (bug 215783)
* 56 - using directives (bug 216527)
*/ */
public static final int LINKAGES = Database.DATA_AREA; 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 { public IIndexFragmentBinding findBinding(IIndexFragmentName indexName) throws CoreException {
if (indexName instanceof PDOMName) { if (indexName instanceof PDOMName) {
PDOMName pdomName= (PDOMName) indexName; PDOMName pdomName= (PDOMName) indexName;
return pdomName.getPDOMBinding(); return pdomName.getBinding();
} }
return null; return null;
} }

View file

@ -18,17 +18,16 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; 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.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.db.IString; 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]; return new char[0];
} }
public IScope getParent() throws DOMException { public IIndexScope getParent() {
try { try {
IBinding parent = getParentBinding(); IBinding parent = getParentBinding();
if(parent instanceof IScope) { if(parent instanceof IIndexScope) {
return (IScope) parent; return (IIndexScope) parent;
} }
} catch(CoreException ce) { } catch(CoreException ce) {
CCorePlugin.log(ce); CCorePlugin.log(ce);
@ -196,11 +195,11 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
return null; return null;
} }
public final IScope getScope() { public final IIndexScope getScope() {
try { try {
IBinding parent = getParentBinding(); IBinding parent = getParentBinding();
if(parent instanceof IScope) { if(parent instanceof IIndexScope) {
return (IScope) parent; return (IIndexScope) parent;
} }
} catch(CoreException ce) { } catch(CoreException ce) {
CCorePlugin.log(ce); CCorePlugin.log(ce);
@ -267,7 +266,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
*/ */
protected final void fail() { throw new PDOMNotImplementedError(); } protected final void fail() { throw new PDOMNotImplementedError(); }
public IName getScopeName() throws DOMException { public PDOMName getScopeName() {
try { try {
PDOMName name = getFirstDefinition(); PDOMName name = getFirstDefinition();
if (name == null) if (name == null)

View file

@ -19,9 +19,12 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; 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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IParameter; 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.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexLocationConverter; 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 LINKAGE_ID= 20;
private static final int TIME_STAMP = 24; private static final int TIME_STAMP = 24;
private static final int SCANNER_CONFIG_HASH= 32; 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 { public static class Comparator implements IBTreeComparator {
private Database db; private Database db;
@ -252,7 +256,7 @@ public class PDOMFile implements IIndexFragmentFile {
PDOMBinding binding = ((WritablePDOM) pdom).addBinding(name); PDOMBinding binding = ((WritablePDOM) pdom).addBinding(name);
if (binding != null) { if (binding != null) {
result= new PDOMName(pdom, name, this, binding, caller); result= new PDOMName(pdom, name, this, binding, caller);
binding.getLinkageImpl().onCreateName(result, name); binding.getLinkageImpl().onCreateName(this, name, result);
} }
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
@ -261,6 +265,14 @@ public class PDOMFile implements IIndexFragmentFile {
} }
public void clear(Collection<IIndexFileLocation> contextsRemoved) throws CoreException { 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 // Remove the includes
PDOMInclude include = getFirstInclude(); PDOMInclude include = getFirstInclude();
while (include != null) { while (include != null) {
@ -288,7 +300,7 @@ public class PDOMFile implements IIndexFragmentFile {
PDOMName name = getFirstName(); PDOMName name = getFirstName();
while (name != null) { while (name != null) {
names.add(name); names.add(name);
name.getPDOMBinding().getLinkageImpl().onDeleteName(name); name.getBinding().getLinkageImpl().onDeleteName(name);
name= name.getNextInFile(); name= name.getNextInFile();
} }
@ -503,4 +515,23 @@ public class PDOMFile implements IIndexFragmentFile {
} }
setFirstIncludedBy(null); 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;
}
} }

View file

@ -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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable; 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.core.index.IIndexLinkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants; 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); 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. * 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 name the name that caused the insertion
* @param pdomName the name that was inserted into the linkage
* @throws CoreException * @throws CoreException
* @since 4.0 * @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(); IASTNode parentNode= name.getParent();
if (parentNode instanceof IASTDeclSpecifier) { if (parentNode instanceof IASTDeclSpecifier) {
IASTDeclSpecifier ds= (IASTDeclSpecifier) parentNode; IASTDeclSpecifier ds= (IASTDeclSpecifier) parentNode;
@ -342,4 +344,8 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
public void delete(PDOMLinkage linkage) throws CoreException { public void delete(PDOMLinkage linkage) throws CoreException {
assert false; // no need to delete linkages. assert false; // no need to delete linkages.
} }
public ICPPUsingDirective[] getUsingDirectives(PDOMFile file) throws CoreException {
return ICPPUsingDirective.EMPTY_ARRAY;
}
} }

View file

@ -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.IIndexFile;
import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.internal.core.index.IIndexFragment; 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.index.IIndexFragmentName;
import org.eclipse.cdt.internal.core.pdom.PDOM; 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.Database;
@ -124,7 +123,7 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
pdom.getDB().putInt(record + offset, fieldrec); pdom.getDB().putInt(record + offset, fieldrec);
} }
public PDOMBinding getPDOMBinding() throws CoreException { public PDOMBinding getBinding() throws CoreException {
int bindingrec = getRecField(BINDING_REC_OFFSET); int bindingrec = getRecField(BINDING_REC_OFFSET);
return pdom.getBinding(bindingrec); return pdom.getBinding(bindingrec);
} }
@ -327,13 +326,13 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
else { else {
switch (getFlags(DECL_DEF_REF_MASK)) { switch (getFlags(DECL_DEF_REF_MASK)) {
case IS_DECLARATION: case IS_DECLARATION:
getPDOMBinding().setFirstDeclaration(nextName); getBinding().setFirstDeclaration(nextName);
break; break;
case IS_DEFINITION: case IS_DEFINITION:
getPDOMBinding().setFirstDefinition(nextName); getBinding().setFirstDefinition(nextName);
break; break;
case IS_REFERENCE: case IS_REFERENCE:
getPDOMBinding().setFirstReference(nextName); getBinding().setFirstReference(nextName);
break; break;
} }
} }
@ -349,10 +348,6 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation {
return pdom; return pdom;
} }
public IIndexFragmentBinding getBinding() throws CoreException {
return getPDOMBinding();
}
public IIndexName[] getEnclosedNames() throws CoreException { public IIndexName[] getEnclosedNames() throws CoreException {
ArrayList<PDOMName> result= new ArrayList<PDOMName>(); ArrayList<PDOMName> result= new ArrayList<PDOMName>();
PDOMName name= getNextInFile(); PDOMName name= getNextInFile();

View file

@ -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.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.index.IIndexFile; 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.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
@ -126,7 +126,7 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment
return new String(getNameCharArray()); return new String(getNameCharArray());
} }
public IScope getScope() throws DOMException { public IIndexScope getScope() {
throw new PDOMNotImplementedError(); throw new PDOMNotImplementedError();
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -93,7 +93,7 @@ class PDOMCPPBase implements ICPPBase, ICPPInternalBase {
try { try {
PDOMName name= getBaseClassSpecifierNameImpl(); PDOMName name= getBaseClassSpecifierNameImpl();
if (name != null) { if (name != null) {
PDOMBinding b = name.getPDOMBinding(); PDOMBinding b = name.getBinding();
while( b instanceof PDOMCPPTypedef && ((PDOMCPPTypedef)b).getType() instanceof PDOMBinding ){ while( b instanceof PDOMCPPTypedef && ((PDOMCPPTypedef)b).getType() instanceof PDOMBinding ){
b = (PDOMBinding) ((PDOMCPPTypedef)b).getType(); b = (PDOMBinding) ((PDOMCPPTypedef)b).getType();
} }

View file

@ -17,14 +17,12 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage; 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.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; 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.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet; 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.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
@ -249,7 +248,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return (IBinding[]) ArrayUtil.trim(IBinding.class, result); return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
} }
public IScope getParent() throws DOMException { public IIndexScope getParent() {
return PDOMCPPClassTemplate.super.getParent(); return PDOMCPPClassTemplate.super.getParent();
} }
@ -258,7 +257,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return null; return null;
} }
public IName getScopeName() throws DOMException { public IIndexName getScopeName() {
return null; return null;
} }
@ -269,7 +268,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
private PDOMCPPTemplateScope scope; private PDOMCPPTemplateScope scope;
public IScope getParent() throws DOMException { public IIndexScope getParent() {
if (scope == null) { if (scope == null) {
scope = new PDOMCPPTemplateScope(); scope = new PDOMCPPTemplateScope();
} }

View file

@ -15,6 +15,7 @@
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; 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.IScope;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; 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.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.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; 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.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.ICPPTemplateScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; 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.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.ICPPVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType; 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.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; 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.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.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexScope; 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.CompositeScope;
@ -857,8 +862,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
} }
@Override @Override
public void onCreateName(PDOMName pdomName, IASTName name) throws CoreException { public void onCreateName(PDOMFile file, IASTName name, PDOMName pdomName) throws CoreException {
super.onCreateName(pdomName, name); super.onCreateName(file, name, pdomName);
IASTNode parentNode= name.getParent(); IASTNode parentNode= name.getParent();
if (parentNode instanceof ICPPASTQualifiedName) { if (parentNode instanceof ICPPASTQualifiedName) {
@ -873,7 +878,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
PDOMName derivedClassName= (PDOMName) pdomName.getEnclosingDefinition(); PDOMName derivedClassName= (PDOMName) pdomName.getEnclosingDefinition();
if (derivedClassName != null) { if (derivedClassName != null) {
ICPPASTBaseSpecifier baseNode= (ICPPASTBaseSpecifier) parentNode; ICPPASTBaseSpecifier baseNode= (ICPPASTBaseSpecifier) parentNode;
PDOMBinding derivedClassBinding= derivedClassName.getPDOMBinding(); PDOMBinding derivedClassBinding= derivedClassName.getBinding();
if (derivedClassBinding instanceof PDOMCPPClassType) { if (derivedClassBinding instanceof PDOMCPPClassType) {
PDOMCPPClassType ownerClass = (PDOMCPPClassType)derivedClassBinding; PDOMCPPClassType ownerClass = (PDOMCPPClassType)derivedClassBinding;
PDOMCPPBase pdomBase = new PDOMCPPBase(pdom, pdomName, baseNode.isVirtual(), baseNode.getVisibility()); PDOMCPPBase pdomBase = new PDOMCPPBase(pdom, pdomName, baseNode.isVirtual(), baseNode.getVisibility());
@ -887,6 +892,56 @@ 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 @Override
@ -896,7 +951,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
if (pdomName.isBaseSpecifier()) { if (pdomName.isBaseSpecifier()) {
PDOMName derivedClassName= (PDOMName) pdomName.getEnclosingDefinition(); PDOMName derivedClassName= (PDOMName) pdomName.getEnclosingDefinition();
if (derivedClassName != null) { if (derivedClassName != null) {
PDOMBinding derivedClassBinding= derivedClassName.getPDOMBinding(); PDOMBinding derivedClassBinding= derivedClassName.getBinding();
if (derivedClassBinding instanceof PDOMCPPClassType) { if (derivedClassBinding instanceof PDOMCPPClassType) {
PDOMCPPClassType ownerClass = (PDOMCPPClassType)derivedClassBinding; PDOMCPPClassType ownerClass = (PDOMCPPClassType)derivedClassBinding;
ownerClass.removeBase(pdomName); ownerClass.removeBase(pdomName);

View file

@ -16,7 +16,6 @@ package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IParameter; 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.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; 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.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; 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.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database; import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
@ -190,7 +190,7 @@ class PDOMCPPParameter extends PDOMNamedNode
return new String(getNameCharArray()); return new String(getNameCharArray());
} }
public IScope getScope() throws DOMException { public IIndexScope getScope() {
return null; return null;
} }

View file

@ -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);
}
}