1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 10:15:39 +02:00

Access to local bindings, bug 215783.

This commit is contained in:
Markus Schorn 2008-01-25 17:00:38 +00:00
parent ac692546b6
commit c0b97bbe1c
80 changed files with 1457 additions and 960 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Symbian Software Ltd. and others.
* Copyright (c) 2007, 2008 Symbian Software Ltd. 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
@ -22,6 +22,7 @@ import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFileSet;
import org.eclipse.cdt.internal.core.index.IIndexFragmentInclude;
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
import org.eclipse.core.runtime.CoreException;
@ -113,4 +114,8 @@ public class EmptyIndexFragment implements IIndexFragment {
public void releaseReadLock() {}
public void resetCacheCounters() {}
public IIndexFragmentFileSet createFileSet() {
return null;
}
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexName;
@ -212,7 +213,24 @@ public class DefDeclTests extends PDOMTestBase {
}
public void testWrongMatchedStaticDefinition() throws Exception {
assertDefDeclRef("foo", "07", 0, 1, 1);
String elName = "foo" + "07";
IIndexBinding[] binds = pdom.findBindings(Pattern.compile(elName), true, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(2, binds.length);
assertTrue(binds[0].isFileLocal() != binds[1].isFileLocal());
if (binds[0].isFileLocal()) {
IIndexBinding b= binds[0]; binds[0]= binds[1]; binds[1]= b;
}
assertEquals(elName, binds[0].getName());
checkDefinition(binds[0], "def" + "07", 0);
checkDeclaration(binds[0], "decl" + "07", 1);
checkReference(binds[0], "ref" + "07", 1);
assertEquals(elName, binds[1].getName());
assertTrue(binds[1].getLocalToFile().getLocation().getFullPath().endsWith("second.c"));
checkDefinition(binds[1], "def" + "07", 1);
checkDeclaration(binds[1], "decl" + "07", 0);
checkReference(binds[1], "ref" + "07", 0);
}
public void testStaticBindings_f08() throws Exception {

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -66,7 +66,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
}
private final String[] fqn;
private final String fileLocal;
private final IIndexFileLocation fileLocal;
private final int elementType;
private final IIndex index;
private final String[] params;
@ -82,7 +82,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
public static IndexTypeInfo create(IIndex index, IIndexBinding binding) {
String[] fqn;
int elementType;
String flsq= null;
IIndexFileLocation flsq= null;
try {
elementType = IndexModelUtil.getElementType(binding);
if (binding instanceof ICPPBinding) {
@ -97,7 +97,10 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
fqn= new String[] {binding.getName()};
}
try {
flsq = binding.getFileLocalScopeQualifier();
IIndexFile file= binding.getLocalToFile();
if (file != null) {
flsq= file.getLocation();
}
} catch (CoreException e) {
}
if (binding instanceof IFunction) {
@ -125,7 +128,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
return new IndexTypeInfo(new String[] {new String(name)}, ICElement.C_MACRO, index);
}
private IndexTypeInfo(String[] fqn, String fileLocal, int elementType, IIndex index, String[] params, String returnType, ITypeReference reference) {
private IndexTypeInfo(String[] fqn, IIndexFileLocation fileLocal, int elementType, IIndex index, String[] params, String returnType, ITypeReference reference) {
Assert.isTrue(index != null);
this.fqn= fqn;
this.fileLocal= fileLocal;
@ -229,24 +232,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
try {
index.acquireReadLock();
char[][] cfqn = new char[fqn.length][];
for(int i=0; i<fqn.length; i++)
cfqn[i] = fqn[i].toCharArray();
IIndexBinding[] ibs = index.findBindings(cfqn, new IndexFilter() {
public boolean acceptBinding(IBinding binding) {
boolean sameType= IndexModelUtil.bindingHasCElementType(binding, new int[]{elementType});
if (sameType && binding instanceof IFunction && params != null) {
try {
String[]otherParams= IndexModelUtil.extractParameterTypes((IFunction)binding);
return Arrays.equals(params, otherParams);
} catch (DOMException exc) {
CCorePlugin.log(exc);
}
}
return sameType;
}
}, new NullProgressMonitor());
IIndexBinding[] ibs = findBindings();
if(ibs.length>0) {
IIndexName[] names;
names= index.findNames(ibs[0], IIndex.FIND_DEFINITIONS);
@ -271,6 +257,46 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
return reference;
}
private IIndexBinding[] findBindings() throws CoreException {
char[][] cfqn = new char[fqn.length][];
for(int i=0; i<fqn.length; i++)
cfqn[i] = fqn[i].toCharArray();
IIndexBinding[] ibs = index.findBindings(cfqn, new IndexFilter() {
@Override
public boolean acceptBinding(IBinding binding) {
if (!IndexModelUtil.bindingHasCElementType(binding, new int[]{elementType})) {
return false;
}
try {
if (fileLocal == null) {
if (((IIndexBinding) binding).isFileLocal()) {
return false;
}
}
else {
IIndexFile localToFile= ((IIndexBinding) binding).getLocalToFile();
if (localToFile == null || !fileLocal.equals(localToFile.getLocation())) {
return false;
}
}
if (binding instanceof IFunction && params != null) {
String[]otherParams= IndexModelUtil.extractParameterTypes((IFunction)binding);
if (!Arrays.equals(params, otherParams)) {
return false;
}
}
} catch (CoreException e) {
CCorePlugin.log(e);
} catch (DOMException e) {
CCorePlugin.log(e);
}
return true;
}
}, new NullProgressMonitor());
return ibs;
}
private ITypeReference createMacroReference() {
try {
index.acquireReadLock();
@ -341,39 +367,11 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
return getMacroReferences();
}
List references= new ArrayList();
List<IndexTypeReference> references= new ArrayList<IndexTypeReference>();
try {
index.acquireReadLock();
int j= 0;
char[][] cfqn;
if (fileLocal != null) {
cfqn = new char[fqn.length+1][];
cfqn[j++]= fileLocal.toCharArray();
}
else {
cfqn = new char[fqn.length][];
}
for(int i=0; i<fqn.length; i++) {
cfqn[j++] = fqn[i].toCharArray();
}
IIndexBinding[] ibs = index.findBindings(cfqn, new IndexFilter() {
public boolean acceptBinding(IBinding binding) {
boolean sameType= IndexModelUtil.bindingHasCElementType(binding, new int[]{elementType});
if (sameType && binding instanceof IFunction && params != null) {
try {
String[]otherParams= IndexModelUtil.extractParameterTypes((IFunction)binding);
return Arrays.equals(params, otherParams);
} catch (DOMException exc) {
CCorePlugin.log(exc);
}
}
return sameType;
}
}, new NullProgressMonitor());
// in case a file is represented multiple times in the index then we take references from
// one of those, only.
HashMap iflMap= new HashMap();
IIndexBinding[] ibs= findBindings();
HashMap<IIndexFileLocation, IIndexFile> iflMap= new HashMap<IIndexFileLocation, IIndexFile>();
for (int i = 0; i < ibs.length; i++) {
IIndexBinding binding = ibs[i];
IIndexName[] names;
@ -381,7 +379,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
if (names.length == 0) {
names= index.findNames(binding, IIndex.FIND_DECLARATIONS);
}
for (j = 0; j < names.length; j++) {
for (int j= 0; j < names.length; j++) {
IIndexName indexName = names[j];
if (checkFile(iflMap, indexName.getFile())) {
IndexTypeReference ref= createReference(binding, indexName);
@ -398,12 +396,12 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
} finally {
index.releaseReadLock();
}
return (IndexTypeReference[]) references.toArray(new IndexTypeReference[references.size()]);
return references.toArray(new IndexTypeReference[references.size()]);
}
private ITypeReference[] getMacroReferences() {
List references= new ArrayList();
List<IndexTypeReference> references= new ArrayList<IndexTypeReference>();
try {
index.acquireReadLock();
@ -411,7 +409,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
IIndexMacro[] ibs = index.findMacros(cfn, IndexFilter.ALL_DECLARED, new NullProgressMonitor());
// in case a file is represented multiple times in the index then we take references from
// one of those, only.
HashMap iflMap= new HashMap();
HashMap<IIndexFileLocation, IIndexFile> iflMap= new HashMap<IIndexFileLocation, IIndexFile>();
for (int i = 0; i < ibs.length; i++) {
IIndexMacro macro= ibs[i];
if (checkFile(iflMap, macro.getFile())) {
@ -428,15 +426,15 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
} finally {
index.releaseReadLock();
}
return (IndexTypeReference[]) references.toArray(new IndexTypeReference[references.size()]);
return references.toArray(new IndexTypeReference[references.size()]);
}
/**
* Makes sure that per file only refs from one IIndexFile object are taken.
*/
private boolean checkFile(HashMap iflMap, IIndexFile file) throws CoreException {
private boolean checkFile(HashMap<IIndexFileLocation, IIndexFile> iflMap, IIndexFile file) throws CoreException {
IIndexFileLocation ifl= file.getLocation();
IIndexFile otherFile= (IIndexFile) iflMap.get(ifl);
IIndexFile otherFile= iflMap.get(ifl);
if (otherFile == null) {
iflMap.put(ifl, file);
return true;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -13,6 +13,7 @@
package org.eclipse.cdt.core.dom.ast;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.index.IIndexFileSet;
/**
@ -62,6 +63,23 @@ public interface IScope {
*/
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException;
/**
* Get the binding in this scope that the given name would resolve to. Could
* return null if there is no matching binding in this scope, if the binding has not
* yet been cached in this scope, or if resolve == false and the appropriate binding
* has not yet been resolved. Accepts file local bindings from the index for the files
* int the given set, only.
*
* @param name
* @param resolve :
* whether or not to resolve the matching binding if it has not
* been so already.
* @param acceptLocalBindings a set of files for which to accept local bindings.
* @return : the binding in this scope that matches the name, or null
* @throws DOMException
*/
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) throws DOMException;
/**
* Get the bindings in this scope that the given name or prefix could resolve to. Could
* return null if there is no matching bindings in this scope, if the bindings have not
@ -77,4 +95,22 @@ public interface IScope {
* @throws DOMException
*/
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException;
/**
* Get the bindings in this scope that the given name or prefix could resolve to. Could
* return null if there is no matching bindings in this scope, if the bindings have not
* yet been cached in this scope, or if resolve == false and the appropriate bindings
* have not yet been resolved.
*
* @param name
* @param resolve :
* whether or not to resolve the matching bindings if they have not
* been so already.
* @param prefixLookup whether the lookup is for a full name or a prefix
* @param acceptLocalBindings a set of files for which to accept local bindings.
* @return : the bindings in this scope that match the name or prefix, or null
* @throws DOMException
*/
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings) throws DOMException;
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -265,8 +265,6 @@ public interface IIndex {
* Searches for all bindings in global scope with a given name. In case a binding exists in multiple projects, no duplicate bindings are returned.
* This method makes use of the BTree and is faster than the methods using patterns.
* <p>
* To find bindings for file-local (static) variables or functions you need to provide an additional qualifier.
* It can be obtained by calling {@link IIndexBinding#getFileLocalScopeQualifier()}.
* @param names an array of names, which has to be matched by the qualified name of the bindings.
* @param filter a filter that allows for skipping parts of the index
* @param monitor a monitor to report progress, may be <code>null</code>.
@ -295,13 +293,13 @@ public interface IIndex {
/**
* Searches for all bindings with names that start with the given prefix.
* @param prefix the prefix with which all returned bindings must start
* @param filescope if true, only bindings at file scope are returned
* @param fileScopeOnly if true, only bindings at file scope are returned
* @param filter a filter that allows for skipping parts of the index
* @param monitor a monitor for progress reporting and cancellation, may be <code>null</code>
* @return an array of bindings with the prefix
* @throws CoreException
*/
public IIndexBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
public IIndexBinding[] findBindingsForPrefix(char[] prefix, boolean fileScopeOnly, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
/**
* Searches for all names that resolve to the given binding. You can limit the result to references, declarations
@ -360,4 +358,9 @@ public interface IIndex {
* @throws CoreException
*/
public IIndexBinding adaptBinding(IBinding binding);
/**
* Creates a file-set that can be used with this index as long as you hold a read-lock.
*/
public IIndexFileSet createFileSet();
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -43,11 +43,12 @@ public interface IIndexBinding extends IBinding {
* in another index.
*/
boolean isFileLocal() throws CoreException;
/**
* Returns the qualifier that can be used to search for file local bindings using
* {@link IIndex#findBindings(char[][], IndexFilter, org.eclipse.core.runtime.IProgressMonitor)}.
* In case the binding is not file-local, <code>null</code> is returned.
* Returns the file this binding is local to, or <code>null</code> for global
* bindings.
* A binding is local if a file has a separate instances of the binding. This
* is used to model static files, static variables.
*/
String getFileLocalScopeQualifier() throws CoreException;
IIndexFile getLocalToFile() throws CoreException;
}

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* 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.index;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.index.IndexFileSet;
/**
* File set for index files. Can be used to filter file-local bindings.
* @since 5.0
*/
public interface IIndexFileSet {
IIndexFileSet EMPTY = new IndexFileSet();
/**
* Returns an array of bindings where all local bindings that are not part of this file-set
* have been removed.
*/
IBinding[] filterFileLocalBindings(IBinding[] bindings);
/**
* Adds a file to this set.
* @param indexFile
*/
void add(IIndexFile indexFile);
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -14,10 +14,12 @@ package org.eclipse.cdt.internal.core.dom.parser;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalFunction;
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalVariable;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
@ -82,22 +84,22 @@ public class ASTInternal {
}
}
public static boolean isStatic(IFunction func, boolean resolveAll, boolean checkHeaders) throws DOMException {
public static boolean isStatic(IFunction func, boolean resolveAll) throws DOMException {
if (func instanceof ICPPInternalFunction) {
return ((ICPPInternalFunction)func).isStatic(resolveAll, checkHeaders);
return ((ICPPInternalFunction)func).isStatic(resolveAll);
}
if (func instanceof ICInternalFunction) {
return ((ICInternalFunction) func).isStatic(resolveAll, checkHeaders);
return ((ICInternalFunction) func).isStatic(resolveAll);
}
return func.isStatic();
}
public static boolean isStatic(IVariable var, boolean checkHeaders) throws DOMException {
public static boolean isStatic(IVariable var) throws DOMException {
if (var instanceof ICPPInternalVariable) {
return ((ICPPInternalVariable)var).isStatic(checkHeaders);
return ((ICPPInternalVariable)var).isStatic();
}
if (var instanceof ICInternalVariable) {
return ((ICInternalVariable)var).isStatic(checkHeaders);
return ((ICInternalVariable)var).isStatic();
}
return var.isStatic();
}
@ -107,4 +109,54 @@ public class ASTInternal {
((ICInternalFunction) binding).setFullyResolved(true);
}
}
public static String getDeclaredInSourceFileOnly(IBinding binding) {
IASTNode[] decls;
IASTNode def;
if (binding instanceof ICPPInternalBinding) {
ICPPInternalBinding ib= (ICPPInternalBinding) binding;
decls= ib.getDeclarations();
def= ib.getDefinition();
}
else if (binding instanceof ICInternalBinding) {
ICInternalBinding ib= (ICInternalBinding) binding;
decls= ib.getDeclarations();
def= ib.getDefinition();
}
else {
return null;
}
String filePath= null;
if (def != null) {
if ( (filePath= isPartOfSource(filePath, def)) == null) {
return null;
}
}
if (decls != null) {
for (int i = 0; i < decls.length; i++) {
final IASTNode node= decls[i];
if (node != null) {
if ( (filePath= isPartOfSource(filePath, node)) == null) {
return null;
}
}
}
}
return filePath;
}
private static String isPartOfSource(String filePath, IASTNode decl) {
IASTTranslationUnit tu;
if (filePath == null) {
tu= decl.getTranslationUnit();
if (tu.isHeaderUnit()) {
return null;
}
filePath= tu.getFilePath();
}
if (!filePath.equals(decl.getContainingFilename())) {
return null;
}
return filePath;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -28,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.parser.ParserMessages;
@ -169,11 +170,22 @@ public class ProblemBinding extends PlatformObject implements IProblemBinding, I
public IBinding getBinding( IASTName name, boolean resolve ) throws DOMException {
throw new DOMException( this );
}
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
throw new DOMException( this );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
*/
public IBinding[] getBindings( IASTName name, boolean resolve, boolean prefixLookup ) throws DOMException {
public IBinding getBinding( IASTName name, boolean resolve, IIndexFileSet fileSet ) throws DOMException {
throw new DOMException( this );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
*/
public IBinding[] getBindings( IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet ) throws DOMException {
throw new DOMException( this );
}

View file

@ -44,6 +44,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
@ -70,6 +71,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
private ILocationResolver resolver;
private IIndex index;
private boolean fIsHeader;
private IIndexFileSet fIndexFileSet;
public IASTTranslationUnit getTranslationUnit() {
return this;
@ -524,6 +526,9 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
public void setIndex(IIndex index) {
this.index = index;
if (index != null) {
fIndexFileSet= index.createFileSet();
}
}
public IASTComment[] getComments() {
@ -538,6 +543,9 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit
if (adapter.isAssignableFrom(resolver.getClass())) {
return resolver;
}
if (adapter.isAssignableFrom(IIndexFileSet.class)) {
return fIndexFileSet;
}
return null;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -164,4 +164,12 @@ public class CEnumeration extends PlatformObject implements IEnumeration, ICInte
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
public IASTNode[] getDeclarations() {
return declarations;
}
public IASTNode getDefinition() {
return definition;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -334,31 +334,23 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/
public boolean isStatic() {
return isStatic(true, true);
return isStatic(true);
}
public boolean isStatic(boolean resolveAll, boolean checkHeaders) {
public boolean isStatic(boolean resolveAll) {
if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
return hasStorageClass( IASTDeclSpecifier.sc_static, checkHeaders );
return hasStorageClass( IASTDeclSpecifier.sc_static );
}
public boolean hasStorageClass( int storage, boolean checkHeaders){
public boolean hasStorageClass( int storage){
IASTDeclarator dtor = definition;
IASTDeclarator[] ds = declarators;
boolean useDeclsInRoot= checkHeaders;
int i = -1;
do{
if( dtor != null ){
if (!useDeclsInRoot) {
if (dtor.getTranslationUnit().isHeaderUnit()) {
return false;
}
useDeclsInRoot= true;
}
IASTNode parent = dtor.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
@ -370,9 +362,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage ) {
if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
return true;
}
return true;
}
}
@ -395,7 +385,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
return hasStorageClass( IASTDeclSpecifier.sc_extern);
}
/* (non-Javadoc)
@ -405,7 +395,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
if( (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
return hasStorageClass( IASTDeclSpecifier.sc_auto, true);
return hasStorageClass( IASTDeclSpecifier.sc_auto);
}
/* (non-Javadoc)
@ -415,7 +405,7 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
if( (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
return hasStorageClass( IASTDeclSpecifier.sc_register, true);
return hasStorageClass( IASTDeclSpecifier.sc_register);
}
/* (non-Javadoc)
@ -482,4 +472,12 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
public ILinkage getLinkage() throws CoreException {
return Linkage.C_LINKAGE;
}
public IASTNode[] getDeclarations() {
return declarators;
}
public IASTNode getDefinition() {
return definition;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -103,5 +103,12 @@ public class CImplicitTypedef extends CTypedef implements ITypedef, ICInternalBi
public IASTNode getPhysicalNode() {
return null;
}
public IASTNode[] getDeclarations() {
return IASTNode.EMPTY_NODE_ARRAY;
}
public IASTNode getDefinition() {
return null;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -23,13 +23,10 @@ import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -38,11 +35,11 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
import org.eclipse.cdt.core.dom.ast.c.ICScope;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
@ -193,7 +190,15 @@ public class CScope implements ICScope, IASTInternalScope {
return NAMESPACE_TYPE_OTHER;
}
public IBinding getBinding( IASTName name, boolean resolve ) {
public final IBinding getBinding( IASTName name, boolean resolve ) {
return getBinding(name, resolve, IIndexFileSet.EMPTY);
}
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
}
public IBinding getBinding( IASTName name, boolean resolve, IIndexFileSet fileSet ) {
char [] c = name.toCharArray();
if( c.length == 0 ){
return null;
@ -205,10 +210,14 @@ public class CScope implements ICScope, IASTInternalScope {
if( o == null || name == o) {
IBinding result= null;
if(physicalNode instanceof IASTTranslationUnit) {
IIndex index= ((IASTTranslationUnit)physicalNode).getIndex();
final IASTTranslationUnit tu = (IASTTranslationUnit)physicalNode;
IIndex index= tu.getIndex();
if(index!=null) {
try {
IBinding[] bindings= index.findBindings(name.toCharArray(), INDEX_FILTERS[type], new NullProgressMonitor());
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
}
result= processIndexResults(name, bindings);
} catch(CoreException ce) {
CCorePlugin.log(ce);
@ -239,7 +248,7 @@ public class CScope implements ICScope, IASTInternalScope {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
*/
public IBinding[] getBindings( IASTName name, boolean resolve, boolean prefixLookup ) {
public IBinding[] getBindings( IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet ) {
char [] c = name.toCharArray();
Object[] obj = null;
@ -259,12 +268,17 @@ public class CScope implements ICScope, IASTInternalScope {
}
if(physicalNode instanceof IASTTranslationUnit) {
IIndex index= ((IASTTranslationUnit)physicalNode).getIndex();
final IASTTranslationUnit tu = (IASTTranslationUnit)physicalNode;
IIndex index= tu.getIndex();
if(index!=null) {
try {
IBinding[] bindings = prefixLookup ?
index.findBindingsForPrefix(name.toCharArray(), true, INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null) :
index.findBindings(name.toCharArray(), INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null);
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
}
obj = ArrayUtil.addAll(Object.class, obj, bindings);
} catch(CoreException ce) {
CCorePlugin.log(ce);
@ -295,28 +309,29 @@ public class CScope implements ICScope, IASTInternalScope {
private IBinding processIndexResults(IASTName name, IBinding[] bindings) {
if(bindings.length!=1)
return null;
IBinding candidate= bindings[0];
if(candidate instanceof IFunction) {
IASTNode parent= name.getParent();
if(parent instanceof IASTFunctionDeclarator) {
IASTNode parent2= parent.getParent();
if(parent2 instanceof IASTFunctionDefinition) {
IASTFunctionDefinition def= (IASTFunctionDefinition) parent2;
if(def.getDeclSpecifier().getStorageClass()==IASTDeclSpecifier.sc_static) {
try {
if(!((IFunction)candidate).isStatic()) {
return null;
}
} catch(DOMException de) {
CCorePlugin.log(de);
}
}
}
}
}
return candidate;
return bindings[0];
// IBinding candidate= bindings[0];
// if(candidate instanceof IFunction) {
// IASTNode parent= name.getParent();
// if(parent instanceof IASTFunctionDeclarator) {
// IASTNode parent2= parent.getParent();
// if(parent2 instanceof IASTFunctionDefinition) {
// IASTFunctionDefinition def= (IASTFunctionDefinition) parent2;
// if(def.getDeclSpecifier().getStorageClass()==IASTDeclSpecifier.sc_static) {
// try {
// if(!((IFunction)candidate).isStatic()) {
// return null;
// }
// } catch(DOMException de) {
// CCorePlugin.log(de);
// }
// }
// }
// }
// }
//
// return candidate;
}
/* (non-Javadoc)

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2006 IBM Corporation and others.
* Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -266,4 +266,12 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
public IASTNode[] getDeclarations() {
return declarations;
}
public IASTNode getDefinition() {
return definition;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -94,27 +94,16 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalVa
return CVisitor.getContainingScope( declarator.getParent() );
}
public boolean isStatic(boolean checkHeaders) {
return hasStorageClass(IASTDeclSpecifier.sc_static, checkHeaders);
public boolean isStatic() {
return hasStorageClass(IASTDeclSpecifier.sc_static);
}
public boolean isStatic() {
return isStatic(true);
}
public boolean hasStorageClass( int storage, boolean checkHeaders){
public boolean hasStorageClass( int storage){
if( declarations == null )
return false;
boolean useDeclsInRoot= checkHeaders;
for( int i = 0; i < declarations.length && declarations[i] != null; i++ ){
final IASTName name = declarations[i];
if (!useDeclsInRoot) {
if (name.getTranslationUnit().isHeaderUnit()) {
return false;
}
useDeclsInRoot= true;
}
IASTNode parent = name.getParent();
while( !(parent instanceof IASTDeclaration) )
@ -123,9 +112,7 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalVa
if( parent instanceof IASTSimpleDeclaration ){
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage ) {
if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
return true;
}
return true;
}
}
}
@ -135,22 +122,28 @@ public class CVariable extends PlatformObject implements IVariable, ICInternalVa
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
return hasStorageClass( IASTDeclSpecifier.sc_extern);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto, true);
return hasStorageClass( IASTDeclSpecifier.sc_auto);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register, true);
return hasStorageClass( IASTDeclSpecifier.sc_register);
}
public ILinkage getLinkage() {
return Linkage.C_LINKAGE;
}
public IASTNode[] getDeclarations() {
return declarations;
}
public IASTNode getDefinition() {
return getPhysicalNode();
}
}

View file

@ -96,6 +96,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
@ -1212,6 +1213,17 @@ public class CVisitor {
* otherwise returns IBinding
*/
protected static Object findBinding( IASTNode blockItem, IASTName name, int bits ) throws DOMException{
IIndexFileSet fileSet= IIndexFileSet.EMPTY;
if (blockItem != null) {
final IASTTranslationUnit tu= blockItem.getTranslationUnit();
if (tu != null) {
final IIndexFileSet fs= (IIndexFileSet) tu.getAdapter(IIndexFileSet.class);
if (fs != null) {
fileSet= fs;
}
}
}
boolean prefix = ( bits & PREFIX_LOOKUP ) != 0;
Object binding = prefix ? new ObjectSet( 2 ) : null;
IIndexBinding foundIndexBinding= null;
@ -1264,7 +1276,7 @@ public class CVisitor {
if( scope != null && ASTInternal.isFullyCached(scope) ){
try {
binding = scope.getBinding( name, true );
binding = scope.getBinding( name, true, fileSet );
} catch ( DOMException e ) {
binding = null;
}
@ -1272,7 +1284,7 @@ public class CVisitor {
return binding;
} else {
if (!prefix && scope != null && scope.getParent() == null) {
binding= scope.getBinding(name, false);
binding= scope.getBinding(name, false, fileSet);
if (binding != null) {
if (binding instanceof IIndexBinding) {
foundIndexBinding= (IIndexBinding) binding;
@ -1379,7 +1391,7 @@ public class CVisitor {
IBinding[] bindings= prefix
? index.findBindingsForPrefix(name.toCharArray(), true, filter, null)
: index.findBindings(name.toCharArray(), filter, null);
bindings= fileSet.filterFileLocalBindings(bindings);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings);
} catch (CoreException e) {
CCorePlugin.log(e);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -22,4 +22,16 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
public interface ICInternalBinding {
//methods needed by CVisitor but not meant for public interface
public IASTNode getPhysicalNode();
/**
* Returns the declarations for this binding.
* @since 5.0
*/
public IASTNode[] getDeclarations();
/**
* Returns the definitions for this binding.
* @since 5.0
*/
public IASTNode getDefinition();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -25,8 +25,6 @@ public interface ICInternalFunction extends ICInternalBinding {
/**
* Returns whether there is a static declaration for this function.
* @param resolveAll checks for names that are not yet resolved to this binding.
* @param checkHeaders if <code>false</code> declarations within header files are not
* considered.
*/
public boolean isStatic(boolean resolveAll, boolean checkHeaders);
public boolean isStatic(boolean resolveAll);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -21,8 +21,6 @@ public interface ICInternalVariable extends ICInternalBinding {
/**
* Returns whether there is a static declaration for this variable.
* @param checkHeaders if <code>false</code> declarations within header files are not
* considered.
*/
public boolean isStatic(boolean checkHeaders) throws DOMException;
public boolean isStatic() throws DOMException;
}

View file

@ -56,6 +56,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.ICPPScope;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
@ -82,6 +83,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
private ICPPScope scope = null;
private ILocationResolver resolver;
private IIndex index;
private IIndexFileSet fIndexFileSet;
private boolean fIsHeader;
public IASTTranslationUnit getTranslationUnit() {
@ -495,6 +497,9 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
public void setIndex(IIndex pdom) {
this.index = pdom;
if (index != null) {
fIndexFileSet= index.createFileSet();
}
}
public IASTComment[] getComments() {
@ -509,6 +514,9 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat
if (adapter.isAssignableFrom(resolver.getClass())) {
return resolver;
}
if (adapter.isAssignableFrom(IIndexFileSet.class)) {
return fIndexFileSet;
}
return null;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -50,6 +50,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
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.ICPPMethod;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@ -197,7 +198,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getBinding(int, char[])
*/
public IBinding getBinding( IASTName name, boolean resolve ) throws DOMException {
public IBinding getBinding( IASTName name, boolean resolve, IIndexFileSet fileSet ) throws DOMException {
char [] c = name.toCharArray();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
@ -213,10 +214,10 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
//9.2 ... The class-name is also inserted into the scope of the class itself
return compName.resolveBinding();
}
return super.getBinding( name, resolve );
return super.getBinding( name, resolve, fileSet);
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
char [] c = name.toCharArray();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
@ -237,7 +238,7 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result,
super.getBindings( name, resolve, prefixLookup ));
super.getBindings( name, resolve, prefixLookup, fileSet ));
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectMap;
@ -62,7 +63,15 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
return null;
}
public IBinding getBinding( IASTName name, boolean forceResolve ) throws DOMException {
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
return getBinding(name, resolve, IIndexFileSet.EMPTY);
}
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
}
public IBinding getBinding( IASTName name, boolean forceResolve, IIndexFileSet fileSet) throws DOMException {
char [] c = name.toCharArray();
if( CharArrayUtils.equals( c, specialization.getNameCharArray() ) )
@ -83,7 +92,7 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
return CPPSemantics.resolveAmbiguities( name, specs );
}
public IBinding[] getBindings( IASTName name, boolean forceResolve, boolean prefixLookup ) throws DOMException {
public IBinding[] getBindings( IASTName name, boolean forceResolve, boolean prefixLookup, IIndexFileSet fileSet ) throws DOMException {
char [] c = name.toCharArray();
IBinding[] result = null;
@ -93,7 +102,7 @@ public class CPPClassSpecializationScope implements ICPPClassScope, IASTInternal
ICPPClassType specialized = (ICPPClassType) specialization.getSpecializedBinding();
IScope classScope = specialized.getCompositeScope();
IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, prefixLookup) : null;
IBinding[] bindings = classScope != null ? classScope.getBindings(name, forceResolve, prefixLookup, fileSet) : null;
if (bindings != null) {
for (int i = 0; i < bindings.length; i++) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -179,9 +179,9 @@ public class CPPDeferredFunctionInstance extends CPPInstance implements ICPPFunc
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/
public boolean isStatic( boolean resolveAll, boolean checkHeaders) {
public boolean isStatic( boolean resolveAll) {
try {
return ASTInternal.isStatic((IFunction) getTemplateDefinition(), resolveAll, checkHeaders);
return ASTInternal.isStatic((IFunction) getTemplateDefinition(), resolveAll);
} catch (DOMException e) {
return false;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -63,6 +63,7 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBind
public ICPPClassType getClassOwner() throws DOMException {
throw new DOMException( this );
}
@Override
public boolean isStatic() throws DOMException {
throw new DOMException( this );
}
@ -143,6 +144,7 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBind
return scope.getClassType();
}
@Override
public boolean isStatic() {
// definition of a static field doesn't necessarily say static
if (getDeclarations() == null) {
@ -158,7 +160,7 @@ public class CPPField extends CPPVariable implements ICPPField, ICPPInternalBind
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable#isMutable()
*/
public boolean isMutable() {
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable, true);
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable);
}
public boolean isExtern() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -86,9 +86,9 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
public boolean takesVarArgs() throws DOMException {
return ((ICPPFunction)getBinding()).takesVarArgs();
}
public boolean isStatic( boolean resolveAll, boolean checkHeaders) {
public boolean isStatic( boolean resolveAll) {
try {
return ASTInternal.isStatic((IFunction) getBinding(), resolveAll, checkHeaders);
return ASTInternal.isStatic((IFunction) getBinding(), resolveAll);
} catch (DOMException e) {
return false;
}
@ -432,16 +432,16 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/
public boolean isStatic( ) {
return isStatic( true, true );
return isStatic( true );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/
public boolean isStatic( boolean resolveAll, boolean checkHeaders ) {
public boolean isStatic( boolean resolveAll ) {
if( resolveAll && (bits & FULLY_RESOLVED) == 0 ){
resolveAllDeclarations();
}
return hasStorageClass( this, IASTDeclSpecifier.sc_static, checkHeaders );
return hasStorageClass( this, IASTDeclSpecifier.sc_static );
}
// }
// static public boolean isStatic
@ -509,24 +509,13 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
return new CPPFunctionDelegate( name, this );
}
static public boolean hasStorageClass( ICPPInternalFunction function, int storage ){
return hasStorageClass(function, storage, true);
}
static public boolean hasStorageClass( ICPPInternalFunction function, int storage, boolean checkHeaders){
static public boolean hasStorageClass( ICPPInternalFunction function, int storage){
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) function.getDefinition();
IASTNode[] ds = function.getDeclarations();
boolean useDeclsInRoot= checkHeaders;
int i = -1;
do{
if( dtor != null ){
if (!useDeclsInRoot) {
if (dtor.getTranslationUnit().isHeaderUnit()) {
return false;
}
useDeclsInRoot= true;
}
IASTNode parent = dtor.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
@ -537,9 +526,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage ) {
if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
return true;
}
return true;
}
}
if( ds != null && ++i < ds.length ) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -144,10 +144,10 @@ public class CPPFunctionInstance extends CPPInstance implements ICPPFunction, IC
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/
public boolean isStatic( boolean resolveAll, boolean checkHeaders ) {
public boolean isStatic( boolean resolveAll ) {
ICPPFunction func = (ICPPFunction) getTemplateDefinition();
try {
return ASTInternal.isStatic(func, resolveAll, checkHeaders);
return ASTInternal.isStatic(func, resolveAll);
} catch (DOMException e) {
return false;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -104,19 +104,19 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
}
public boolean isStatic() {
return isStatic(true, true);
return isStatic(true);
}
public boolean isStatic(boolean resolveAll, boolean checkHeaders) {
public boolean isStatic(boolean resolveAll) {
//TODO resolveAll
IBinding f = getSpecializedBinding();
if( f instanceof ICPPInternalFunction)
return ((ICPPInternalFunction)f).isStatic( resolveAll, checkHeaders);
return ((ICPPInternalFunction)f).isStatic( resolveAll);
if( f instanceof IIndexBinding && f instanceof ICPPFunction ) {
try {
return ((ICPPFunction) f).isStatic();
} catch(DOMException de) { /* cannot occur as we query the index */}
}
return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_static, checkHeaders);
return CPPFunction.hasStorageClass( this, IASTDeclSpecifier.sc_static);
}
public boolean isExtern() throws DOMException {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -221,20 +221,12 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
return type;
}
public boolean hasStorageClass( int storage, boolean checkHeaders){
public boolean hasStorageClass( int storage){
IASTName name = (IASTName) getDefinition();
IASTNode[] ns = getDeclarations();
int i = -1;
boolean useDeclsInRoot= checkHeaders;
do{
if( name != null ){
if (!useDeclsInRoot) {
if (name.getTranslationUnit().isHeaderUnit()) {
return false;
}
useDeclsInRoot= true;
}
IASTNode parent = name.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
@ -245,9 +237,7 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
else if( parent instanceof IASTFunctionDefinition )
declSpec = ((IASTFunctionDefinition)parent).getDeclSpecifier();
if( declSpec.getStorageClass() == storage ) {
if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
return true;
}
return true;
}
}
if( ns != null && ++i < ns.length )
@ -321,13 +311,13 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
* @see org.eclipse.cdt.core.dom.ast.IFunction#isStatic()
*/
public boolean isStatic() {
return hasStorageClass( IASTDeclSpecifier.sc_static, true);
return hasStorageClass( IASTDeclSpecifier.sc_static);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction#isMutable()
*/
public boolean isMutable() {
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable, true);
return hasStorageClass( ICPPASTDeclSpecifier.sc_mutable);
}
/* (non-Javadoc)
@ -379,21 +369,21 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
* @see org.eclipse.cdt.core.dom.ast.IFunction#isExtern()
*/
public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
return hasStorageClass( IASTDeclSpecifier.sc_extern);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isAuto()
*/
public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto, true );
return hasStorageClass( IASTDeclSpecifier.sc_auto );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IFunction#isRegister()
*/
public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register, true);
return hasStorageClass( IASTDeclSpecifier.sc_register);
}
/* (non-Javadoc)
@ -430,8 +420,8 @@ public class CPPFunctionTemplate extends CPPTemplateDefinition implements ICPPFu
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalFunction#isStatic(boolean)
*/
public boolean isStatic( boolean resolveAll, boolean checkHeaders ) {
return hasStorageClass( IASTDeclSpecifier.sc_static, checkHeaders);
public boolean isStatic( boolean resolveAll ) {
return hasStorageClass( IASTDeclSpecifier.sc_static );
}
/* (non-Javadoc)

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -84,6 +84,7 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
public ICPPClassType getClassOwner() throws DOMException {
throw new DOMException( this );
}
@Override
public boolean isStatic() throws DOMException {
throw new DOMException( this );
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
@ -95,15 +96,19 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
}
}
public IBinding getBinding(IASTName name, boolean forceResolve) throws DOMException {
public IBinding getBinding(IASTName name, boolean forceResolve, IIndexFileSet fileSet) throws DOMException {
IBinding binding= getBindingInAST(name, forceResolve);
if (binding == null) {
IIndex index = name.getTranslationUnit().getIndex();
final IASTTranslationUnit tu = name.getTranslationUnit();
IIndex index = tu.getIndex();
if (index != null) {
// Try looking this up in the PDOM
if (physicalNode instanceof IASTTranslationUnit) {
try {
IBinding[] bindings= index.findBindings(name.toCharArray(), IndexFilter.CPP_DECLARED_OR_IMPLICIT, NPM);
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
}
binding= CPPSemantics.resolveAmbiguities(name, bindings);
} catch (CoreException e) {
CCorePlugin.log(e);
@ -117,6 +122,9 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
ICPPNamespace nsbindingAdapted = (ICPPNamespace) index.adaptBinding(nsbinding);
if(nsbindingAdapted!=null) {
IBinding[] bindings = nsbindingAdapted.getNamespaceScope().find(name.toString());
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
}
binding= CPPSemantics.resolveAmbiguities(name, bindings);
}
}
@ -174,10 +182,11 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
return null;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
IBinding[] result = getBindingsInAST(name, resolve, prefixLookup);
IIndex index = name.getTranslationUnit().getIndex();
final IASTTranslationUnit tu = name.getTranslationUnit();
IIndex index = tu.getIndex();
if (index != null) {
if (physicalNode instanceof IASTTranslationUnit) {
try {
@ -185,6 +194,9 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
IBinding[] bindings = prefixLookup ?
index.findBindingsForPrefix(name.toCharArray(), true, filter, null) :
index.findBindings(name.toCharArray(), filter, null);
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
}
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings);
} catch (CoreException e) {
CCorePlugin.log(e);
@ -196,6 +208,9 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
if (binding instanceof ICPPNamespace) {
ICPPNamespaceScope indexNs = ((ICPPNamespace)binding).getNamespaceScope();
IBinding[] bindings = indexNs.getBindings(name, resolve, prefixLookup);
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
}
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings);
}
} catch (CoreException e) {
@ -337,4 +352,12 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
bindings.put( c, binding );
}
}
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
return getBinding(name, resolve, IIndexFileSet.EMPTY);
}
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -117,6 +117,7 @@ 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.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@ -1008,6 +1009,17 @@ public class CPPSemantics {
static protected void lookup( CPPSemantics.LookupData data, Object start ) throws DOMException{
IASTNode node = data.astName;
IIndexFileSet fileSet= IIndexFileSet.EMPTY;
if (node != null) {
final IASTTranslationUnit tu= node.getTranslationUnit();
if (tu != null) {
final IIndexFileSet fs= (IIndexFileSet) tu.getAdapter(IIndexFileSet.class);
if (fs != null) {
fileSet= fs;
}
}
}
ICPPScope scope = null;
if( start instanceof ICPPScope )
scope = (ICPPScope) start;
@ -1032,7 +1044,7 @@ public class CPPSemantics {
if( !data.usingDirectivesOnly ){
if( ASTInternal.isFullyCached(scope) ){
if (!data.contentAssist && data.astName != null) {
IBinding binding = scope.getBinding( data.astName, true );
IBinding binding = scope.getBinding( data.astName, true, fileSet );
if( binding != null &&
( CPPSemantics.declaredBefore( binding, data.astName ) ||
(scope instanceof ICPPClassScope && data.checkWholeClassScope) ) )
@ -1040,19 +1052,19 @@ public class CPPSemantics {
mergeResults( data, binding, true );
}
} else if (data.astName != null) {
IBinding[] bindings = scope.getBindings( data.astName, true, data.prefixLookup );
IBinding[] bindings = scope.getBindings( data.astName, true, data.prefixLookup, fileSet );
mergeResults(data, bindings, true);
}
} else if (data.astName != null) {
IBinding[] b = null;
if (!data.contentAssist) {
IBinding binding = scope.getBinding( data.astName, false );
IBinding binding = scope.getBinding( data.astName, false, fileSet );
if (binding instanceof CPPImplicitFunction || binding instanceof CPPImplicitTypedef)
mergeResults( data, binding, true );
else
b = new IBinding[] { binding };
} else {
b = scope.getBindings( data.astName, false, data.prefixLookup );
b = scope.getBindings( data.astName, false, data.prefixLookup, fileSet );
}
IASTName[] inScope = lookupInScope( data, scope, blockItem );
@ -1352,7 +1364,7 @@ public class CPPSemantics {
}
//it is not ambiguous if they are the same thing and it is static or an enumerator
if( binding instanceof IEnumerator ||
(binding instanceof IFunction && ASTInternal.isStatic((IFunction) binding, false, true)) ||
(binding instanceof IFunction && ASTInternal.isStatic((IFunction) binding, false)) ||
(binding instanceof IVariable && ((IVariable)binding).isStatic()) )
{
ok = true;
@ -2394,7 +2406,7 @@ public class CPPSemantics {
} else
varArgs = true;
if( useImplicitObj && j == 0 && ASTInternal.isStatic(currFn, false, true)) {
if( useImplicitObj && j == 0 && ASTInternal.isStatic(currFn, false)) {
//13.3.1-4 for static member functions, the implicit object parameter is considered to match any object
cost = new Cost( source, target );
cost.rank = Cost.IDENTITY_RANK; //exact match, no cost

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@ -86,10 +87,18 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
}
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
return getBinding(name, resolve, IIndexFileSet.EMPTY);
}
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IScope#getBinding(org.eclipse.cdt.core.dom.ast.IASTName, boolean)
*/
public IBinding getBinding( IASTName name, boolean resolve ) {
public IBinding getBinding( IASTName name, boolean resolve, IIndexFileSet fileSet ) {
if( map == null )
map = new CharArrayObjectMap(2);
@ -105,7 +114,7 @@ public class CPPUnknownScope implements ICPPScope, IASTInternalScope {
return b;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) {
if( map == null )
map = new CharArrayObjectMap(2);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -298,21 +298,13 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
addDeclaration( node );
}
public boolean hasStorageClass(int storage, boolean checkHeaders) {
public boolean hasStorageClass(int storage) {
IASTName name = (IASTName) getDefinition();
IASTNode[] ns = getDeclarations();
boolean useDeclsInRoot= checkHeaders;
int i = -1;
do{
if( name != null ){
if (!useDeclsInRoot) {
if (name.getTranslationUnit().isHeaderUnit()) {
return false;
}
useDeclsInRoot= true;
}
IASTNode parent = name.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
@ -320,9 +312,7 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
if( parent instanceof IASTSimpleDeclaration ){
IASTDeclSpecifier declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
if (declSpec.getStorageClass() == storage) {
if (checkHeaders || declSpec.isPartOfTranslationUnitFile()) {
return true;
}
return true;
}
}
}
@ -343,19 +333,15 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
}
public boolean isStatic(boolean checkHeaders) {
return hasStorageClass(IASTDeclSpecifier.sc_static, checkHeaders);
}
public boolean isStatic() {
return isStatic(true);
public boolean isStatic() {
return hasStorageClass(IASTDeclSpecifier.sc_static);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isExtern()
*/
public boolean isExtern() {
return hasStorageClass( IASTDeclSpecifier.sc_extern, true);
return hasStorageClass( IASTDeclSpecifier.sc_extern);
}
/* (non-Javadoc)
@ -380,14 +366,14 @@ public class CPPVariable extends PlatformObject implements ICPPVariable, ICPPInt
* @see org.eclipse.cdt.core.dom.ast.IVariable#isAuto()
*/
public boolean isAuto() {
return hasStorageClass( IASTDeclSpecifier.sc_auto, true);
return hasStorageClass( IASTDeclSpecifier.sc_auto);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IVariable#isRegister()
*/
public boolean isRegister() {
return hasStorageClass( IASTDeclSpecifier.sc_register, true);
return hasStorageClass( IASTDeclSpecifier.sc_register);
}
public ILinkage getLinkage() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -25,8 +25,6 @@ public interface ICPPInternalFunction extends ICPPInternalBinding {
/**
* Returns whether there is a static declaration for this function.
* @param resolveAll checks for names that are not yet resolved to this binding.
* @param checkHeaders if <code>false</code> declarations within header files are not
* considered.
*/
public boolean isStatic(boolean resolveAll, boolean checkHeaders);
public boolean isStatic(boolean resolveAll);
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -22,8 +22,6 @@ public interface ICPPInternalVariable extends ICPPInternalBinding {
/**
* Returns whether there is a static declaration for this variable.
* @param checkHeaders if <code>false</code> declarations within header files are not
* considered.
*/
public boolean isStatic(boolean checkHeaders) throws DOMException;
public boolean isStatic() throws DOMException;
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -34,6 +34,7 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.index.IIndexName;
@ -95,7 +96,7 @@ public class CIndex implements IIndex {
if(SPECIALCASE_SINGLES && fFragments.length==1) {
return fFragments[0].findBindings(patterns, isFullyQualified, filter, monitor);
} else {
List result = new ArrayList();
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
ILinkage[] linkages = Linkage.getAllLinkages();
for(int j=0; j < linkages.length; j++) {
if(filter.acceptLinkage(linkages[j])) {
@ -119,7 +120,7 @@ public class CIndex implements IIndex {
}
public IIndexName[] findNames(IBinding binding, int flags) throws CoreException {
LinkedList result= new LinkedList();
LinkedList<IIndexFragmentName> result= new LinkedList<IIndexFragmentName>();
int fragCount= 0;
for (int i = 0; i < fPrimaryFragmentCount; i++) {
final IIndexFragmentName[] names = fFragments[i].findNames(binding, flags);
@ -130,12 +131,12 @@ public class CIndex implements IIndex {
}
// bug 192352, files can reside in multiple fragments, remove duplicates
if (fragCount > 1) {
HashMap fileMap= new HashMap();
for (Iterator iterator = result.iterator(); iterator.hasNext();) {
final IIndexFragmentName name = (IIndexFragmentName) iterator.next();
HashMap<String, IIndexFile> fileMap= new HashMap<String, IIndexFile>();
for (Iterator<IIndexFragmentName> iterator = result.iterator(); iterator.hasNext();) {
final IIndexFragmentName name = iterator.next();
final IIndexFile file= name.getFile();
final String fileKey= name.getFile().getLocation().getURI().toString();
final IIndexFile otherFile= (IIndexFile) fileMap.get(fileKey);
final IIndexFile otherFile= fileMap.get(fileKey);
if (otherFile == null) {
fileMap.put(fileKey, file);
}
@ -144,7 +145,7 @@ public class CIndex implements IIndex {
}
}
}
return (IIndexName[]) result.toArray(new IIndexName[result.size()]);
return result.toArray(new IIndexName[result.size()]);
}
public IIndexName[] findDeclarations(IBinding binding) throws CoreException {
@ -170,7 +171,7 @@ public class CIndex implements IIndex {
}
public IIndexFile[] getFiles(IIndexFileLocation location) throws CoreException {
ArrayList result= new ArrayList();
ArrayList<IIndexFragmentFile> result= new ArrayList<IIndexFragmentFile>();
BitSet linkages= new BitSet();
for (int i = 0; i < fPrimaryFragmentCount; i++) {
IIndexFragmentFile[] candidates= fFragments[i].getFiles(location);
@ -186,7 +187,7 @@ public class CIndex implements IIndex {
if (result.isEmpty()) {
return IIndexFile.EMPTY_FILE_ARRAY;
}
return (IIndexFile[]) result.toArray(new IIndexFile[result.size()]);
return result.toArray(new IIndexFile[result.size()]);
}
public IIndexFile resolveInclude(IIndexInclude include) throws CoreException {
@ -207,14 +208,14 @@ public class CIndex implements IIndex {
}
public IIndexInclude[] findIncludedBy(IIndexFile file, int depth) throws CoreException {
List result= new ArrayList();
findIncludedBy(Collections.singletonList(file), result, depth, new HashSet());
return (IIndexInclude[]) result.toArray(new IIndexInclude[result.size()]);
List<IIndexInclude> result= new ArrayList<IIndexInclude>();
findIncludedBy(Collections.singletonList(file), result, depth, new HashSet<IIndexFileLocation>());
return result.toArray(new IIndexInclude[result.size()]);
}
public void findIncludedBy(List in, List out, int depth, HashSet handled) throws CoreException {
List nextLevel= depth != 0 ? new LinkedList() : null;
for (Iterator it= in.iterator(); it.hasNext(); ) {
public void findIncludedBy(List<IIndexFile> in, List<IIndexInclude> out, int depth, HashSet<IIndexFileLocation> handled) throws CoreException {
List<IIndexFile> nextLevel= depth != 0 ? new LinkedList<IIndexFile>() : null;
for (Iterator<IIndexFile> it= in.iterator(); it.hasNext(); ) {
IIndexFragmentFile file = (IIndexFragmentFile) it.next();
for (int j= 0; j < fPrimaryFragmentCount; j++) {
IIndexInclude[] includedBy= fFragments[j].findIncludedBy(file);
@ -244,14 +245,14 @@ public class CIndex implements IIndex {
}
public IIndexInclude[] findIncludes(IIndexFile file, int depth) throws CoreException {
List result= new ArrayList();
findIncludes(Collections.singletonList(file), result, depth, new HashSet());
return (IIndexInclude[]) result.toArray(new IIndexInclude[result.size()]);
List<IIndexInclude> result= new ArrayList<IIndexInclude>();
findIncludes(Collections.singletonList(file), result, depth, new HashSet<Object>());
return result.toArray(new IIndexInclude[result.size()]);
}
private void findIncludes(List in, List out, int depth, HashSet handled) throws CoreException {
List nextLevel= depth != 0 ? new LinkedList() : null;
for (Iterator it= in.iterator(); it.hasNext(); ) {
private void findIncludes(List<IIndexFile> in, List<IIndexInclude> out, int depth, HashSet<Object> handled) throws CoreException {
List<IIndexFile> nextLevel= depth != 0 ? new LinkedList<IIndexFile>() : null;
for (Iterator<IIndexFile> it= in.iterator(); it.hasNext(); ) {
IIndexFragmentFile file = (IIndexFragmentFile) it.next();
IIndexInclude[] includes= file.getIncludes();
for (int k= 0; k < includes.length; k++) {
@ -330,7 +331,7 @@ public class CIndex implements IIndex {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
List result = new ArrayList();
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
ILinkage[] linkages = Linkage.getAllLinkages();
monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length * linkages.length);
for(int j=0; j < linkages.length; j++) {
@ -382,15 +383,15 @@ public class CIndex implements IIndex {
* Non-API
*/
private IIndexBinding[] flatten(List bindingArrays) {
private IIndexBinding[] flatten(List<IIndexBinding[]> bindingArrays) {
int size = 0;
for(int i=0; i<bindingArrays.size(); i++) {
size += ((IBinding[])bindingArrays.get(i)).length;
size += bindingArrays.get(i).length;
}
IIndexBinding[] result = new IIndexBinding[size];
int offset = 0;
for(int i=0; i<bindingArrays.size(); i++) {
IBinding[] src = (IBinding[]) bindingArrays.get(i);
IBinding[] src = bindingArrays.get(i);
System.arraycopy(src, 0, result, offset, src.length);
offset += src.length;
}
@ -404,14 +405,14 @@ public class CIndex implements IIndex {
}
public IIndexFragmentBinding[] findEquivalentBindings(IBinding binding) throws CoreException {
List result = new ArrayList();
List<IIndexFragmentBinding> result = new ArrayList<IIndexFragmentBinding>();
for (int i = 0; i < fFragments.length; i++) {
IIndexFragmentBinding adapted = fFragments[i].adaptBinding(binding);
if (adapted != null) {
result.add(adapted);
}
}
return (IIndexFragmentBinding[]) result.toArray(new IIndexFragmentBinding[result.size()]);
return result.toArray(new IIndexFragmentBinding[result.size()]);
}
private ICompositesFactory getCompositesFactory(int linkageID) {
@ -454,7 +455,7 @@ public class CIndex implements IIndex {
if(SPECIALCASE_SINGLES && fFragments.length==1) {
return fFragments[0].findBindingsForPrefix(prefix, filescope, filter, monitor);
} else {
List result = new ArrayList();
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
ILinkage[] linkages = Linkage.getAllLinkages();
for(int j=0; j < linkages.length; j++) {
if(filter.acceptLinkage(linkages[j])) {
@ -497,11 +498,11 @@ public class CIndex implements IIndex {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
List result = new ArrayList();
HashSet handledIFLs= new HashSet();
List<IIndexMacro> result = new ArrayList<IIndexMacro>();
HashSet<IIndexFileLocation> handledIFLs= new HashSet<IIndexFileLocation>();
monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length);
for (int i = 0; i < fPrimaryFragmentCount; i++) {
HashSet allowedFiles= new HashSet();
HashSet<IIndexFile> allowedFiles= new HashSet<IIndexFile>();
try {
IIndexMacro[] macros= fFragments[i].findMacros(name, isPrefix, caseSensitive, filter, new SubProgressMonitor(monitor, 1));
for (int k = 0; k < macros.length; k++) {
@ -522,7 +523,7 @@ public class CIndex implements IIndex {
}
}
monitor.done();
return (IIndexMacro[]) result.toArray(new IIndexMacro[result.size()]);
return result.toArray(new IIndexMacro[result.size()]);
}
}
@ -575,4 +576,8 @@ public class CIndex implements IIndex {
}
return 0;
}
public IIndexFileSet createFileSet() {
return new IndexFileSet();
}
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.index.IIndexName;
@ -125,4 +126,8 @@ final public class EmptyCIndex implements IIndex {
public IIndexMacro[] findMacrosForPrefix(char[] prefix, IndexFilter filter, IProgressMonitor monitor) {
return IIndexMacro.EMPTY_INDEX_MACRO_ARRAY;
}
public IIndexFileSet createFileSet() {
return new IndexFileSet();
}
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -17,6 +17,5 @@ public interface IIndexBindingConstants {
int POINTER_TYPE= 1;
int ARRAY_TYPE= 2;
int QUALIFIER_TYPE= 3;
int FILE_LOCAL_SCOPE_TYPE= 4;
int LAST_CONSTANT= FILE_LOCAL_SCOPE_TYPE;
int LAST_CONSTANT= QUALIFIER_TYPE;
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -226,4 +226,10 @@ public interface IIndexFragment {
* Returns cache misses since last reset of counters.
*/
long getCacheMisses();
/**
* Creates an empty file set for this fragment
* @since 5.0
*/
IIndexFragmentFileSet createFileSet();
}

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.index;
import org.eclipse.core.runtime.CoreException;
public interface IIndexFragmentFileSet {
/**
* Returns whether the file-set contains the file of the local binding.
* @throws CoreException
*/
boolean containsFileOfLocalBinding(IIndexFragmentBinding fb) throws CoreException;
/**
* Adds the fragment file to the file-set.
*/
void add(IIndexFragmentFile fragFile);
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
import org.eclipse.core.runtime.CoreException;
/**
@ -59,7 +60,7 @@ public interface IWritableIndex extends IIndex {
* @param a collection that receives IndexFileLocation objects for files that
* had the cleared file as a context. May be <code>null</code>.
*/
void clearFile(IIndexFragmentFile file, Collection clearedContexts) throws CoreException;
void clearFile(IIndexFragmentFile file, Collection<IIndexFileLocation> clearedContexts) throws CoreException;
/**
* Creates a file object for the given location or returns an existing one.
@ -71,7 +72,8 @@ public interface IWritableIndex extends IIndex {
*/
void setFileContent(IIndexFragmentFile sourceFile,
int linkageID, IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException;
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names,
ASTFilePathResolver resolver) throws CoreException;
/**
* Clears the entire index.

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
import org.eclipse.core.runtime.CoreException;
/**
@ -36,7 +37,7 @@ public interface IWritableIndexFragment extends IIndexFragment {
* @param a collection that receives IndexFileLocation objects for files that
* had the cleared file as a context.
*/
void clearFile(IIndexFragmentFile file, Collection contextsRemoved) throws CoreException;
void clearFile(IIndexFragmentFile file, Collection<IIndexFileLocation> contextsRemoved) throws CoreException;
/**
* Creates a file object for the given location and linkage or returns an existing one.
@ -51,7 +52,7 @@ public interface IWritableIndexFragment extends IIndexFragment {
*/
void addFileContent(IIndexFragmentFile sourceFile,
IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException;
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names, ASTFilePathResolver resolver) throws CoreException;
/**
* Acquires a write lock, while giving up a certain amount of read locks.

View file

@ -18,6 +18,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -31,8 +32,8 @@ import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.ICodeReaderCache;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
import org.eclipse.cdt.internal.core.parser.scanner.IIndexBasedCodeReaderFactory;
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent;
import org.eclipse.cdt.internal.core.parser.scanner.IncludeFileContent.InclusionKind;
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask;
@ -102,13 +103,14 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
if (file != null) {
try {
LinkedHashMap<IIndexFileLocation, IIndexMacro[]> macroMap= new LinkedHashMap<IIndexFileLocation, IIndexMacro[]>();
collectMacros(file, macroMap, false);
List<IIndexFile> files= new ArrayList<IIndexFile>();
collectMacros(file, macroMap, files, false);
ArrayList<IIndexMacro> allMacros= new ArrayList<IIndexMacro>();
for (Map.Entry<IIndexFileLocation,IIndexMacro[]> entry : macroMap.entrySet()) {
allMacros.addAll(Arrays.asList(entry.getValue()));
fIncludedFiles.add(entry.getKey());
}
return new IncludeFileContent(path, allMacros);
return new IncludeFileContent(path, allMacros, files);
}
catch (NeedToParseException e) {
}
@ -130,7 +132,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
return fIncludedFiles.contains(ifl);
}
private void collectMacros(IIndexFile file, LinkedHashMap<IIndexFileLocation, IIndexMacro[]> macroMap, boolean checkIncluded) throws CoreException, NeedToParseException {
private void collectMacros(IIndexFile file, Map<IIndexFileLocation, IIndexMacro[]> macroMap, List<IIndexFile> files, boolean checkIncluded) throws CoreException, NeedToParseException {
IIndexFileLocation ifl= file.getLocation();
if (macroMap.containsKey(ifl) || (checkIncluded && fIncludedFiles.contains(ifl))) {
return;
@ -146,6 +148,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
converted= file.getMacros();
}
macroMap.put(ifl, converted); // prevent recursion
files.add(file);
// follow the includes
IIndexInclude[] includeDirectives= file.getIncludes();
@ -153,7 +156,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
final IIndexInclude indexInclude = includeDirectives[i];
IIndexFile includedFile= fIndex.resolveInclude(indexInclude);
if (includedFile != null) {
collectMacros(includedFile, macroMap, true);
collectMacros(includedFile, macroMap, files, true);
}
}
}

View file

@ -0,0 +1,82 @@
/*******************************************************************************
* 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.index;
import java.util.BitSet;
import java.util.HashMap;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.core.runtime.CoreException;
public class IndexFileSet implements IIndexFileSet {
private HashMap<IIndexFragment, IIndexFragmentFileSet> fSubSets= new HashMap<IIndexFragment, IIndexFragmentFileSet>();
public IndexFileSet() {
}
public void add(IIndexFile indexFile) {
final IIndexFragmentFile fragFile = (IIndexFragmentFile) indexFile;
final IIndexFragment frag= fragFile.getIndexFragment();
IIndexFragmentFileSet subSet= fSubSets.get(frag);
if (subSet == null) {
subSet= frag.createFileSet();
fSubSets.put(frag, subSet);
}
subSet.add(fragFile);
}
public IBinding[] filterFileLocalBindings(IBinding[] bindings) {
if (bindings == null || bindings.length == 0) {
return bindings;
}
BitSet ok= new BitSet(bindings.length);
for (int i = 0; i < bindings.length; i++) {
IBinding binding = bindings[i];
if (binding != null) {
IIndexFragmentBinding fb;
if (binding instanceof IIndexFragmentBinding) {
fb= (IIndexFragmentBinding) binding;
}
else {
fb= (IIndexFragmentBinding) binding.getAdapter(IIndexFragmentBinding.class);
}
try {
if (fb != null && fb.isFileLocal()) {
IIndexFragmentFileSet subSet= fSubSets.get(fb.getFragment());
if (subSet != null && subSet.containsFileOfLocalBinding(fb)) {
ok.set(i);
}
}
else {
ok.set(i);
}
} catch (CoreException e) {
CCorePlugin.log(e);
}
}
}
if (ok.cardinality() == bindings.length) {
return bindings;
}
IBinding[] result= new IBinding[ok.cardinality()];
int j= ok.nextSetBit(0);
for (int i = 0; i < result.length; i++) {
result[i]= bindings[j];
j= ok.nextSetBit(j+1);
}
return result;
}
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
import org.eclipse.core.runtime.CoreException;
public class WritableCIndex extends CIndex implements IWritableIndex {
@ -59,7 +60,7 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
public void setFileContent(IIndexFragmentFile file, int linkageID,
IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException {
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names, ASTFilePathResolver resolver) throws CoreException {
IIndexFragment indexFragment = file.getIndexFragment();
if (!isWritableFragment(indexFragment)) {
@ -72,7 +73,7 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
ii.fTargetFile= addFile(linkageID, ii.fLocation);
}
}
((IWritableIndexFragment) indexFragment).addFileContent(file, includes, macros, names);
((IWritableIndexFragment) indexFragment).addFileContent(file, includes, macros, names, resolver);
}
}
@ -85,7 +86,7 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
isWritableFragment(((IIndexFragmentFile)file).getIndexFragment());
}
public void clearFile(IIndexFragmentFile file, Collection clearedContexts) throws CoreException {
public void clearFile(IIndexFragmentFile file, Collection<IIndexFileLocation> clearedContexts) throws CoreException {
IIndexFragment indexFragment = file.getIndexFragment();
if (!isWritableFragment(indexFragment)) {
assert false : "Attempt to clear file of read-only fragment"; //$NON-NLS-1$

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.core.runtime.CoreException;
@ -59,6 +60,7 @@ public abstract class CompositeIndexBinding implements IIndexBinding {
return rbinding.getNameCharArray();
}
@SuppressWarnings("unchecked")
public Object getAdapter(Class adapter) {
if (adapter.isInstance(rbinding)) {
return rbinding;
@ -90,8 +92,8 @@ public abstract class CompositeIndexBinding implements IIndexBinding {
return rbinding != null ? rbinding.isFileLocal() : false;
}
public String getFileLocalScopeQualifier() throws CoreException {
return rbinding != null ? rbinding.getFileLocalScopeQualifier() : null;
public IIndexFile getLocalToFile() throws CoreException {
return rbinding != null ? rbinding.getLocalToFile() : null;
}
public boolean equals(Object obj) {

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -13,9 +13,11 @@ package org.eclipse.cdt.internal.core.index.composite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPCompositeBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
@ -101,4 +103,12 @@ public abstract class CompositeScope implements IIndexScope {
}
return result;
}
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
return getBinding(name, resolve, IIndexFileSet.EMPTY);
}
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
}
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@ -34,13 +35,13 @@ class CompositeCCompositeScope extends CompositeScope implements ICCompositeType
return (ICompositeType) cf.getCompositeBinding(rbinding);
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
IBinding binding = ((ICompositeType)rbinding).getCompositeScope().getBinding(name, resolve);
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
IBinding binding = ((ICompositeType)rbinding).getCompositeScope().getBinding(name, resolve, fileSet);
return processUncertainBinding(binding);
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
IBinding[] bindings = ((ICompositeType)rbinding).getCompositeScope().getBindings(name, resolve, prefixLookup);
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
IBinding[] bindings = ((ICompositeType)rbinding).getCompositeScope().getBindings(name, resolve, prefixLookup, fileSet);
return processUncertainBindings(bindings);
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@ -45,13 +46,13 @@ class CompositeCPPClassScope extends CompositeScope implements ICPPClassScope {
return ICPPMethod.EMPTY_CPPMETHOD_ARRAY;
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
IBinding binding = ((ICPPClassType)rbinding).getCompositeScope().getBinding(name, resolve);
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
IBinding binding = ((ICPPClassType)rbinding).getCompositeScope().getBinding(name, resolve, fileSet);
return processUncertainBinding(binding);
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
IBinding[] bindings = ((ICPPClassType)rbinding).getCompositeScope().getBindings(name, resolve, prefixLookup);
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
IBinding[] bindings = ((ICPPClassType)rbinding).getCompositeScope().getBindings(name, resolve, prefixLookup, fileSet);
return processUncertainBindings(bindings);
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -19,6 +19,7 @@ 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.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
@ -40,21 +41,21 @@ class CompositeCPPNamespaceScope extends CompositeScope implements ICPPNamespace
return new IASTNode[0]; // same behaviour as PDOMCPPNamespace
}
public IBinding getBinding(IASTName name, boolean resolve)
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet)
throws DOMException {
IBinding preresult = null;
for(int i=0; preresult==null && i<namespaces.length; i++) {
preresult = namespaces[i].getNamespaceScope().getBinding(name, resolve);
preresult = namespaces[i].getNamespaceScope().getBinding(name, resolve, fileSet);
}
return processUncertainBinding(preresult);
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup)
throws DOMException {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet)
throws DOMException {
IBinding[] preresult = null;
for(int i=0; i<namespaces.length; i++) {
preresult = (IBinding[]) ArrayUtil.addAll(IBinding.class, preresult,
namespaces[i].getNamespaceScope().getBindings(name, resolve, prefixLookup));
namespaces[i].getNamespaceScope().getBindings(name, resolve, prefixLookup, fileSet));
}
return processUncertainBindings(preresult);
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
import org.eclipse.cdt.internal.core.index.composite.ICompositesFactory;
@ -36,13 +37,13 @@ public class CompositeCPPTemplateScope extends CompositeScope implements ICPPTem
return processUncertainBindings(preresult);
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
IBinding binding = ((ICPPTemplateScope)rbinding).getBinding(name, resolve);
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
IBinding binding = ((ICPPTemplateScope)rbinding).getBinding(name, resolve, fileSet);
return processUncertainBinding(binding);
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
IBinding[] bindings = ((ICPPTemplateScope)rbinding).getBindings(name, resolve, prefixLookup);
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
IBinding[] bindings = ((ICPPTemplateScope)rbinding).getBindings(name, resolve, prefixLookup, fileSet);
return processUncertainBindings(bindings);
}

View file

@ -25,6 +25,8 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.EndOfFileException;
@ -1042,6 +1044,13 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
for (IIndexMacro macro : mdefs) {
addMacroDefinition(macro);
}
IIndexFileSet fileSet= fLocationMap.getFileSet();
if (fileSet != null) {
List<IIndexFile> files= fi.getFilesIncluded();
for (IIndexFile indexFile : files) {
fileSet.add(indexFile);
}
}
}
private char[] extractHeaderName(final char[] image, final char startDelim, final char endDelim, int[] offsets) {

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.parser.scanner;
import java.util.List;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.parser.CodeReader;
@ -40,6 +41,7 @@ public class IncludeFileContent {
private final CodeReader fCodeReader;
private final List<IIndexMacro> fMacroDefinitions;
private final String fFileLocation;
private List<IIndexFile> fFiles;
/**
* For skipping include files.
@ -80,13 +82,15 @@ public class IncludeFileContent {
* For using information about an include file from the index.
* @param fileLocation the location of the file
* @param macroDefinitions a list of macro definitions
* @param files
* @throws IllegalArgumentException in case the fileLocation or the macroDefinitions are <code>null</code>.
*/
public IncludeFileContent(String fileLocation, List<IIndexMacro> macroDefinitions) {
public IncludeFileContent(String fileLocation, List<IIndexMacro> macroDefinitions, List<IIndexFile> files) {
fKind= InclusionKind.FOUND_IN_INDEX;
fFileLocation= fileLocation;
fCodeReader= null;
fMacroDefinitions= macroDefinitions;
fFiles= files;
}
/**
@ -118,4 +122,13 @@ public class IncludeFileContent {
public List<IIndexMacro> getMacroDefinitions() {
return fMacroDefinitions;
}
/**
* Valid with {@link InclusionKind#FOUND_IN_INDEX}.
* @return the files included or <code>null</code> if kind is different to {@link InclusionKind#FOUND_IN_INDEX}.
*/
public List<IIndexFile> getFilesIncluded() {
return fFiles;
}
}

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
@ -602,4 +603,11 @@ public class LocationMap implements ILocationResolver {
public ASTPreprocessorSelectionResult getPreprocessorNode(String path, int offset, int length) {
throw new UnsupportedOperationException();
}
public IIndexFileSet getFileSet() {
if (fTranslationUnit != null) {
return (IIndexFileSet) fTranslationUnit.getAdapter(IIndexFileSet.class);
}
return null;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 QNX Software Systems and others.
* Copyright (c) 2005, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -51,6 +51,7 @@ import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFileSet;
import org.eclipse.cdt.internal.core.index.IIndexFragmentInclude;
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
@ -90,7 +91,7 @@ public class PDOM extends PlatformObject implements IPDOM {
*/
public static final String FRAGMENT_PROPERTY_VALUE_FORMAT_ID= "org.eclipse.cdt.internal.core.pdom.PDOM"; //$NON-NLS-1$
public static final int CURRENT_VERSION = 53;
public static final int CURRENT_VERSION = 55;
public static final int MIN_SUPPORTED_VERSION= CURRENT_VERSION;
/**
@ -136,9 +137,9 @@ public class PDOM extends PlatformObject implements IPDOM {
* 25 - change ordering of bindings (175275)
* 26 - add properties storage
* 27 - templates: classes, functions, limited nesting support, only template type parameters
* 28 - templates: class instance/specialisation base classes
* 29 - includes: fixed modelling of unresolved includes (180159)
* 30 - templates: method/constructor templates, typedef specialisations
* 28 - templates: class instance/specialization base classes
* 29 - includes: fixed modeling of unresolved includes (180159)
* 30 - templates: method/constructor templates, typedef specializations
* 31 - macros: added file locations
* 32 - support stand-alone function types (181936)
* 33 - templates: constructor instances
@ -154,6 +155,7 @@ public class PDOM extends PlatformObject implements IPDOM {
* 52 - files per linkage (bug 191989)
* 53 - polymorphic method calls (bug 156691)
* 54 - optimization of database size (bug 210392)
* 55 - generalization of local bindings (bug 215783)
*/
public static final int LINKAGES = Database.DATA_AREA;
@ -169,18 +171,18 @@ public class PDOM extends PlatformObject implements IPDOM {
protected Database db;
private BTree fileIndex;
private BTree fMacroIndex= null;
private Map fLinkageIDCache = new HashMap();
private Map<String, PDOMLinkage> fLinkageIDCache = new HashMap<String, PDOMLinkage>();
private File fPath;
private IIndexLocationConverter locationConverter;
private Map fPDOMLinkageFactoryCache;
private HashMap fResultCache= new HashMap();
private Map<String, IPDOMLinkageFactory> fPDOMLinkageFactoryCache;
private HashMap<Object, Object> fResultCache= new HashMap<Object, Object>();
public PDOM(File dbPath, IIndexLocationConverter locationConverter, Map linkageFactoryMappings) throws CoreException {
public PDOM(File dbPath, IIndexLocationConverter locationConverter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException {
this(dbPath, locationConverter, ChunkCache.getSharedInstance(), linkageFactoryMappings);
}
public PDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache, Map linkageFactoryMappings) throws CoreException {
public PDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache, Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException {
fPDOMLinkageFactoryCache = linkageFactoryMappings;
loadDatabase(dbPath, cache);
this.locationConverter = locationConverter;
@ -222,8 +224,8 @@ public class PDOM extends PlatformObject implements IPDOM {
}
public void accept(IPDOMVisitor visitor) throws CoreException {
for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage = (PDOMLinkage) iter.next();
for (Iterator<PDOMLinkage> iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage = iter.next();
linkage.accept(visitor);
}
}
@ -232,11 +234,11 @@ public class PDOM extends PlatformObject implements IPDOM {
public void handleChange(PDOM pdom);
}
private List listeners;
private List<IListener> listeners;
public void addListener(IListener listener) {
if (listeners == null)
listeners = new LinkedList();
listeners = new LinkedList<IListener>();
listeners.add(listener);
}
@ -249,9 +251,9 @@ public class PDOM extends PlatformObject implements IPDOM {
private void fireChange() {
if (listeners == null)
return;
Iterator i = listeners.iterator();
Iterator<IListener> i = listeners.iterator();
while (i.hasNext())
((IListener)i.next()).handleChange(this);
i.next().handleChange(this);
}
public Database getDB() {
@ -264,7 +266,7 @@ public class PDOM extends PlatformObject implements IPDOM {
return fileIndex;
}
public IIndexFragmentFile getFile(int linkageID, IIndexFileLocation location) throws CoreException {
public PDOMFile getFile(int linkageID, IIndexFileLocation location) throws CoreException {
return PDOMFile.findFile(this, getFileIndex(), location, linkageID, locationConverter);
}
@ -273,7 +275,7 @@ public class PDOM extends PlatformObject implements IPDOM {
}
public IIndexFragmentFile[] getAllFiles() throws CoreException {
final List locations = new ArrayList();
final List<PDOMFile> locations = new ArrayList<PDOMFile>();
getFileIndex().accept(new IBTreeVisitor(){
public int compare(int record) throws CoreException {
return 0;
@ -284,7 +286,7 @@ public class PDOM extends PlatformObject implements IPDOM {
return true;
}
});
return (IIndexFragmentFile[]) locations.toArray(new IIndexFragmentFile[locations.size()]);
return locations.toArray(new IIndexFragmentFile[locations.size()]);
}
protected IIndexFragmentFile addFile(int linkageID, IIndexFileLocation location) throws CoreException {
@ -333,12 +335,12 @@ public class PDOM extends PlatformObject implements IPDOM {
*/
public IName[] getDefinitions(IBinding binding) throws CoreException {
if (binding instanceof PDOMBinding) {
List names = new ArrayList();
List<PDOMName> names = new ArrayList<PDOMName>();
for (PDOMName name = ((PDOMBinding)binding).getFirstDefinition();
name != null;
name = name.getNextInBinding())
names.add(name);
return (IName[]) names.toArray(new IIndexName[names.size()]);
return names.toArray(new IIndexName[names.size()]);
}
return IIndexFragmentName.EMPTY_NAME_ARRAY;
}
@ -348,12 +350,12 @@ public class PDOM extends PlatformObject implements IPDOM {
*/
public IName[] getReferences(IBinding binding) throws CoreException {
if (binding instanceof PDOMBinding) {
List names = new ArrayList();
List<PDOMName> names = new ArrayList<PDOMName>();
for (PDOMName name = ((PDOMBinding)binding).getFirstReference();
name != null;
name = name.getNextInBinding())
names.add(name);
return (IName[]) names.toArray(new IIndexName[names.size()]);
return names.toArray(new IIndexName[names.size()]);
}
return IIndexFragmentName.EMPTY_NAME_ARRAY;
}
@ -370,9 +372,9 @@ public class PDOM extends PlatformObject implements IPDOM {
private final Pattern[] pattern;
private final IProgressMonitor monitor;
private final ArrayList currentPath= new ArrayList();
private final ArrayList matchStack= new ArrayList();
private List bindings = new ArrayList();
private final ArrayList<PDOMNamedNode> currentPath= new ArrayList<PDOMNamedNode>();
private final ArrayList<BitSet> matchStack= new ArrayList<BitSet>();
private List<PDOMNamedNode> bindings = new ArrayList<PDOMNamedNode>();
private boolean isFullyQualified;
private BitSet matchesUpToLevel;
private IndexFilter filter;
@ -433,12 +435,12 @@ public class PDOM extends PlatformObject implements IPDOM {
final int idx= currentPath.size()-1;
if (idx >= 0 && currentPath.get(idx) == node) {
currentPath.remove(idx);
matchesUpToLevel= (BitSet) matchStack.remove(matchStack.size()-1);
matchesUpToLevel= matchStack.remove(matchStack.size()-1);
}
}
public IIndexFragmentBinding[] getBindings() {
return (IIndexFragmentBinding[])bindings.toArray(new IIndexFragmentBinding[bindings.size()]);
return bindings.toArray(new IIndexFragmentBinding[bindings.size()]);
}
}
@ -451,8 +453,8 @@ public class PDOM extends PlatformObject implements IPDOM {
monitor= new NullProgressMonitor();
}
BindingFinder finder = new BindingFinder(pattern, isFullyQualified, filter, monitor);
for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage = (PDOMLinkage) iter.next();
for (Iterator<PDOMLinkage> iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage = iter.next();
if (filter.acceptLinkage(linkage)) {
try {
linkage.accept(finder);
@ -471,17 +473,17 @@ public class PDOM extends PlatformObject implements IPDOM {
if (names.length == 0) {
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
}
ArrayList result= new ArrayList();
ArrayList nodes= new ArrayList();
for (Iterator iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage = (PDOMLinkage) iter.next();
ArrayList<PDOMBinding> result= new ArrayList<PDOMBinding>();
ArrayList<PDOMNamedNode> nodes= new ArrayList<PDOMNamedNode>();
for (Iterator<PDOMLinkage> iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage = iter.next();
if (filter.acceptLinkage(linkage)) {
nodes.add(linkage);
for (int i=0; i < names.length-1; i++) {
char[] name= names[i];
NamedNodeCollector collector= new NamedNodeCollector(linkage, name, false, true);
for (Iterator in = nodes.iterator(); in.hasNext();) {
PDOMNode node= (PDOMNode) in.next();
for (Iterator<PDOMNamedNode> in = nodes.iterator(); in.hasNext();) {
PDOMNode node= in.next();
node.accept(collector);
}
nodes.clear();
@ -489,15 +491,15 @@ public class PDOM extends PlatformObject implements IPDOM {
}
char[] name= names[names.length-1];
BindingCollector collector= new BindingCollector(linkage, name, filter, false, true);
for (Iterator in = nodes.iterator(); in.hasNext();) {
PDOMNode node= (PDOMNode) in.next();
for (Iterator<PDOMNamedNode> in = nodes.iterator(); in.hasNext();) {
PDOMNode node= in.next();
node.accept(collector);
}
nodes.clear();
result.addAll(Arrays.asList(collector.getBindings()));
}
}
return (IIndexFragmentBinding[]) result.toArray(new IIndexFragmentBinding[result.size()]);
return result.toArray(new IIndexFragmentBinding[result.size()]);
}
private void readLinkages() throws CoreException {
@ -505,7 +507,7 @@ public class PDOM extends PlatformObject implements IPDOM {
int record= getFirstLinkageRecord();
while (record != 0) {
String linkageID= PDOMLinkage.getId(this, record).getString();
IPDOMLinkageFactory factory= (IPDOMLinkageFactory) fPDOMLinkageFactoryCache.get(linkageID);
IPDOMLinkageFactory factory= fPDOMLinkageFactoryCache.get(linkageID);
if (factory != null) {
PDOMLinkage linkage= factory.getLinkage(this, record);
fLinkageIDCache.put(linkageID, linkage);
@ -515,14 +517,14 @@ public class PDOM extends PlatformObject implements IPDOM {
}
public PDOMLinkage getLinkage(String linkageID) {
return (PDOMLinkage) fLinkageIDCache.get(linkageID);
return fLinkageIDCache.get(linkageID);
}
public PDOMLinkage createLinkage(String linkageID) throws CoreException {
PDOMLinkage pdomLinkage= (PDOMLinkage) fLinkageIDCache.get(linkageID);
PDOMLinkage pdomLinkage= fLinkageIDCache.get(linkageID);
if (pdomLinkage == null) {
// Need to create it
IPDOMLinkageFactory factory= (IPDOMLinkageFactory) fPDOMLinkageFactoryCache.get(linkageID);
IPDOMLinkageFactory factory= fPDOMLinkageFactoryCache.get(linkageID);
if (factory != null) {
return factory.createLinkage(this);
}
@ -536,9 +538,9 @@ public class PDOM extends PlatformObject implements IPDOM {
// First check the cache. We do a linear search since there will be very few linkages
// in a given database.
Iterator i = fLinkageIDCache.values().iterator();
Iterator<PDOMLinkage> i = fLinkageIDCache.values().iterator();
while (i.hasNext()) {
PDOMLinkage linkage = (PDOMLinkage)i.next();
PDOMLinkage linkage = i.next();
if (linkage.getRecord() == record)
return linkage;
}
@ -552,13 +554,13 @@ public class PDOM extends PlatformObject implements IPDOM {
}
public IIndexLinkage[] getLinkages() {
Collection values = fLinkageIDCache.values();
return (IIndexLinkage[]) values.toArray(new IIndexLinkage[values.size()]);
Collection<PDOMLinkage> values = fLinkageIDCache.values();
return values.toArray(new IIndexLinkage[values.size()]);
}
public PDOMLinkage[] getLinkageImpls() {
Collection values = fLinkageIDCache.values();
return (PDOMLinkage[]) values.toArray(new PDOMLinkage[values.size()]);
Collection<PDOMLinkage> values = fLinkageIDCache.values();
return values.toArray(new PDOMLinkage[values.size()]);
}
public void insertLinkage(PDOMLinkage linkage) throws CoreException {
@ -685,7 +687,7 @@ public class PDOM extends PlatformObject implements IPDOM {
}
protected PDOMLinkage adaptLinkage(ILinkage linkage) throws CoreException {
return (PDOMLinkage) fLinkageIDCache.get(linkage.getLinkageName());
return fLinkageIDCache.get(linkage.getLinkageName());
}
public IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException {
@ -713,10 +715,10 @@ public class PDOM extends PlatformObject implements IPDOM {
}
public IIndexFragmentName[] findNames(IBinding binding, int options) throws CoreException {
ArrayList names= new ArrayList();
ArrayList<PDOMName> names= new ArrayList<PDOMName>();
PDOMBinding pdomBinding = (PDOMBinding) adaptBinding(binding);
if (pdomBinding != null) {
names= new ArrayList();
names= new ArrayList<PDOMName>();
findNamesForMyBinding(pdomBinding, options, names);
}
if ((options & SEARCH_ACCROSS_LANGUAGE_BOUNDARIES) != 0) {
@ -725,10 +727,10 @@ public class PDOM extends PlatformObject implements IPDOM {
findNamesForMyBinding(xlangBindings[j], options, names);
}
}
return (IIndexFragmentName[]) names.toArray(new IIndexFragmentName[names.size()]);
return names.toArray(new IIndexFragmentName[names.size()]);
}
private void findNamesForMyBinding(PDOMBinding pdomBinding, int options, ArrayList names)
private void findNamesForMyBinding(PDOMBinding pdomBinding, int options, ArrayList<PDOMName> names)
throws CoreException {
PDOMName name;
if ((options & FIND_DECLARATIONS) != 0) {
@ -751,11 +753,11 @@ public class PDOM extends PlatformObject implements IPDOM {
public IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException {
PDOMFile pdomFile= adaptFile(file);
if (pdomFile != null) {
List result = new ArrayList();
List<PDOMInclude> result = new ArrayList<PDOMInclude>();
for (PDOMInclude i= pdomFile.getFirstIncludedBy(); i != null; i= i.getNextInIncludedBy()) {
result.add(i);
}
return (IIndexFragmentInclude[]) result.toArray(new PDOMInclude[result.size()]);
return result.toArray(new PDOMInclude[result.size()]);
}
return new PDOMInclude[0];
}
@ -765,7 +767,7 @@ public class PDOM extends PlatformObject implements IPDOM {
return (PDOMFile) file;
}
return (PDOMFile) getFile(file.getLinkageID(), file.getLocation());
return getFile(file.getLinkageID(), file.getLocation());
}
public File getPath() {
@ -773,11 +775,11 @@ public class PDOM extends PlatformObject implements IPDOM {
}
public IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, boolean filescope, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
ArrayList result= new ArrayList();
for (Iterator iter= fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage= (PDOMLinkage) iter.next();
ArrayList<IIndexFragmentBinding> result= new ArrayList<IIndexFragmentBinding>();
for (Iterator<PDOMLinkage> iter= fLinkageIDCache.values().iterator(); iter.hasNext();) {
PDOMLinkage linkage= iter.next();
if (filter.acceptLinkage(linkage)) {
IBinding[] bindings;
PDOMBinding[] bindings;
BindingCollector visitor = new BindingCollector(linkage, prefix, filter, true, false);
visitor.setMonitor(monitor);
try {
@ -795,11 +797,11 @@ public class PDOM extends PlatformObject implements IPDOM {
}
}
}
return (IIndexFragmentBinding[]) result.toArray(new IIndexFragmentBinding[result.size()]);
return result.toArray(new IIndexFragmentBinding[result.size()]);
}
public IIndexMacro[] findMacros(char[] prefix, boolean isPrefix, boolean isCaseSensitive, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
ArrayList result= new ArrayList();
ArrayList<IIndexMacro> result= new ArrayList<IIndexMacro>();
MacroCollector visitor = new MacroCollector(this, prefix, isPrefix, isCaseSensitive);
visitor.setMonitor(monitor);
try {
@ -808,7 +810,7 @@ public class PDOM extends PlatformObject implements IPDOM {
}
catch (OperationCanceledException e) {
}
return (IIndexMacro[]) result.toArray(new IIndexMacro[result.size()]);
return result.toArray(new IIndexMacro[result.size()]);
}
private BTree getMacroIndex() {
@ -907,13 +909,13 @@ public class PDOM extends PlatformObject implements IPDOM {
ICPPFunction func = (ICPPFunction) binding;
if (func.isExternC()) {
result = FindBinding.findBinding(c.getIndex(), this, func.getNameCharArray(),
new int[] { IIndexCBindingConstants.CFUNCTION });
new int[] { IIndexCBindingConstants.CFUNCTION }, 0);
}
} else if (binding instanceof ICPPVariable) {
ICPPVariable var = (ICPPVariable) binding;
if (var.isExternC()) {
result = FindBinding.findBinding(c.getIndex(), this, var.getNameCharArray(),
new int[] { IIndexCBindingConstants.CVARIABLE });
new int[] { IIndexCBindingConstants.CVARIABLE }, 0);
}
}
} catch (DOMException e) {
@ -962,5 +964,7 @@ public class PDOM extends PlatformObject implements IPDOM {
return PDOMBinding.EMPTY_PDOMBINDING_ARRAY;
}
public IIndexFragmentFileSet createFileSet() {
return new PDOMFileSet();
}
}

View file

@ -0,0 +1,35 @@
/*******************************************************************************
* 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;
import java.util.HashSet;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFileSet;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.core.runtime.CoreException;
public class PDOMFileSet implements IIndexFragmentFileSet {
private HashSet<Integer> fFileIDs= new HashSet<Integer>();
public void add(IIndexFragmentFile fragFile) {
PDOMFile pdomFile= (PDOMFile) fragFile;
fFileIDs.add(pdomFile.getRecord());
}
public boolean containsFileOfLocalBinding(IIndexFragmentBinding fb) throws CoreException {
PDOMBinding pdomBinding= (PDOMBinding) fb;
return fFileIDs.contains(pdomBinding.getLocalToFileRec());
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -23,6 +23,7 @@ import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFileSet;
import org.eclipse.cdt.internal.core.index.IIndexFragmentInclude;
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
import org.eclipse.cdt.internal.core.pdom.PDOM.IListener;
@ -38,7 +39,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class PDOMProxy implements IPDOM {
private PDOM fDelegate;
private int fReadLockCount;
private Set fListeners= new HashSet();
private Set<IListener> fListeners= new HashSet<IListener>();
public synchronized void acquireReadLock() throws InterruptedException {
if (fDelegate != null)
@ -168,6 +169,7 @@ public class PDOMProxy implements IPDOM {
fDelegate.resetCacheCounters();
}
@SuppressWarnings("unchecked")
public synchronized Object getAdapter(Class adapter) {
if (adapter.isAssignableFrom(PDOMProxy.class)) {
return this;
@ -204,17 +206,21 @@ public class PDOMProxy implements IPDOM {
while (fReadLockCount-- > 0) {
pdom.acquireReadLock();
}
for (Iterator iterator = fListeners.iterator(); iterator.hasNext();) {
IListener listener = (IListener) iterator.next();
for (Iterator<IListener> iterator = fListeners.iterator(); iterator.hasNext();) {
IListener listener = iterator.next();
pdom.addListener(listener);
}
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
for (Iterator iterator = fListeners.iterator(); iterator.hasNext();) {
IListener listener = (IListener) iterator.next();
for (Iterator<IListener> iterator = fListeners.iterator(); iterator.hasNext();) {
IListener listener = iterator.next();
listener.handleChange(fDelegate);
}
}
public IIndexFragmentFileSet createFileSet() {
return new PDOMFileSet();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -17,7 +17,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -63,6 +62,11 @@ abstract public class PDOMWriter {
public static int SKIP_TYPE_REFERENCES= 1;
public static int SKIP_NO_REFERENCES= 0;
private static class Symbols {
ArrayList<IASTName[]> fNames= new ArrayList<IASTName[]>();
ArrayList<IASTPreprocessorMacroDefinition> fMacros= new ArrayList<IASTPreprocessorMacroDefinition>();
ArrayList<IASTPreprocessorIncludeStatement> fIncludes= new ArrayList<IASTPreprocessorIncludeStatement>();
}
protected boolean fShowActivity;
protected boolean fShowProblems;
protected final IndexerStatistics fStatistics;
@ -111,13 +115,13 @@ abstract public class PDOMWriter {
public void addSymbols(IASTTranslationUnit ast, IIndexFileLocation[] ifls, IWritableIndex index,
int readlockCount, boolean flushIndex, int configHash, ITodoTaskUpdater taskUpdater, IProgressMonitor pm)
throws InterruptedException, CoreException {
final Map symbolMap= new HashMap();
final Map<IIndexFileLocation, Symbols> symbolMap= new HashMap<IIndexFileLocation, Symbols>();
for (int i = 0; i < ifls.length; i++) {
prepareInMap(symbolMap, ifls[i]);
}
ArrayList stati= new ArrayList();
ArrayList<IStatus> stati= new ArrayList<IStatus>();
HashSet contextIncludes= new HashSet();
HashSet<IASTPreprocessorIncludeStatement> contextIncludes= new HashSet<IASTPreprocessorIncludeStatement>();
extractSymbols(ast, symbolMap, contextIncludes);
// name resolution
@ -139,7 +143,7 @@ abstract public class PDOMWriter {
}
String msg= NLS.bind(Messages.PDOMWriter_errorWhileParsing, path);
if (stati.size() == 1) {
IStatus status= (IStatus) stati.get(0);
IStatus status= stati.get(0);
if (msg.equals(status.getMessage())) {
throw new CoreException(status);
}
@ -147,13 +151,13 @@ abstract public class PDOMWriter {
msg + ':' + status.getMessage(), status.getException()));
}
throw new CoreException(new MultiStatus(CCorePlugin.PLUGIN_ID, 0,
(IStatus[]) stati.toArray(new IStatus[stati.size()]), msg, null));
stati.toArray(new IStatus[stati.size()]), msg, null));
}
}
private void storeSymbolsInIndex(final Map symbolMap, IIndexFileLocation[] ifls, int linkageID, int configHash,
HashSet contextIncludes, IWritableIndex index, int readlockCount, boolean flushIndex,
ArrayList stati, IProgressMonitor pm) throws InterruptedException, CoreException {
private void storeSymbolsInIndex(final Map<IIndexFileLocation, Symbols> symbolMap, IIndexFileLocation[] ifls, int linkageID, int configHash,
HashSet<IASTPreprocessorIncludeStatement> contextIncludes, IWritableIndex index, int readlockCount, boolean flushIndex,
ArrayList<IStatus> stati, IProgressMonitor pm) throws InterruptedException, CoreException {
index.acquireWriteLock(readlockCount);
long start= System.currentTimeMillis();
try {
@ -188,19 +192,19 @@ abstract public class PDOMWriter {
fStatistics.fAddToIndexTime+= System.currentTimeMillis()-start;
}
private void resolveNames(final Map symbolMap, IIndexFileLocation[] ifls, ArrayList stati, IProgressMonitor pm) {
private void resolveNames(final Map<IIndexFileLocation, Symbols> symbolMap, IIndexFileLocation[] ifls, ArrayList<IStatus> stati, IProgressMonitor pm) {
long start= System.currentTimeMillis();
for (int i=0; i<ifls.length; i++) {
if (pm.isCanceled()) {
return;
}
IIndexFileLocation path= ifls[i];
ArrayList[] arrayLists = ((ArrayList[]) symbolMap.get(path));
Symbols symbols= symbolMap.get(path);
ArrayList names= arrayLists[2];
ArrayList<IASTName[]> names= symbols.fNames;
boolean reported= false;
for (Iterator j = names.iterator(); j.hasNext();) {
final IASTName[] na= (IASTName[]) j.next();
for (Iterator<IASTName[]> j = names.iterator(); j.hasNext();) {
final IASTName[] na= j.next();
final IASTName name = na[0];
try {
final IBinding binding = name.resolveBinding();
@ -238,9 +242,9 @@ abstract public class PDOMWriter {
fStatistics.fResolutionTime += System.currentTimeMillis()-start;
}
private void extractSymbols(IASTTranslationUnit ast, final Map symbolMap, Collection contextIncludes) throws CoreException {
private void extractSymbols(IASTTranslationUnit ast, final Map<IIndexFileLocation, Symbols> symbolMap, Collection<IASTPreprocessorIncludeStatement> contextIncludes) throws CoreException {
final HashSet contextIFLs= new HashSet();
final HashSet<IIndexFileLocation> contextIFLs= new HashSet<IIndexFileLocation>();
final IIndexFileLocation astIFL = fResolver.resolveASTPath(ast.getFilePath());
// includes
@ -251,7 +255,7 @@ abstract public class PDOMWriter {
final IIndexFileLocation sourceIFL= astLoc != null ? fResolver.resolveASTPath(astLoc.getFileName()) : astIFL; // command-line includes
final boolean updateSource= symbolMap.containsKey(sourceIFL);
if (updateSource) {
addToMap(symbolMap, 0, sourceIFL, include);
addToMap(symbolMap, sourceIFL, include);
}
if (include.isActive()) {
if (!include.isResolved()) {
@ -274,7 +278,7 @@ abstract public class PDOMWriter {
IASTFileLocation sourceLoc = macro.getFileLocation();
if (sourceLoc != null) { // skip built-ins and command line macros
IIndexFileLocation path2 = fResolver.resolveASTPath(sourceLoc.getFileName());
addToMap(symbolMap, 1, path2, macro);
addToMap(symbolMap, path2, macro);
}
}
@ -295,7 +299,7 @@ abstract public class PDOMWriter {
IASTFileLocation nameLoc = name.getFileLocation();
if (nameLoc != null) {
IIndexFileLocation location = fResolver.resolveASTPath(nameLoc.getFileName());
addToMap(symbolMap, 2, location, new IASTName[]{name, caller});
addToMap(symbolMap, location, new IASTName[]{name, caller});
}
}
}
@ -350,38 +354,47 @@ abstract public class PDOMWriter {
}
}
private void addToMap(Map map, int idx, IIndexFileLocation location, Object thing) {
List[] lists= (List[]) map.get(location);
private void addToMap(Map<IIndexFileLocation, Symbols> map, IIndexFileLocation location, IASTName[] thing) {
Symbols lists= map.get(location);
if (lists != null)
lists[idx].add(thing);
lists.fNames.add(thing);
}
private boolean prepareInMap(Map map, IIndexFileLocation location) {
private void addToMap(Map<IIndexFileLocation, Symbols> map, IIndexFileLocation location, IASTPreprocessorIncludeStatement thing) {
Symbols lists= map.get(location);
if (lists != null)
lists.fIncludes.add(thing);
}
private void addToMap(Map<IIndexFileLocation, Symbols> map, IIndexFileLocation location, IASTPreprocessorMacroDefinition thing) {
Symbols lists= map.get(location);
if (lists != null)
lists.fMacros.add(thing);
}
private boolean prepareInMap(Map<IIndexFileLocation, Symbols> map, IIndexFileLocation location) {
if (map.get(location) == null) {
Object lists= new ArrayList[]{new ArrayList(), new ArrayList(), new ArrayList()};
map.put(location, lists);
map.put(location, new Symbols());
}
return false;
}
private IIndexFragmentFile storeFileInIndex(IWritableIndex index, IIndexFileLocation location, Map symbolMap,
int linkageID, int configHash, Set contextIncludes) throws CoreException {
Set clearedContexts= Collections.EMPTY_SET;
private IIndexFragmentFile storeFileInIndex(IWritableIndex index, IIndexFileLocation location, Map<IIndexFileLocation, Symbols> symbolMap,
int linkageID, int configHash, Set<IASTPreprocessorIncludeStatement> contextIncludes) throws CoreException {
Set<IIndexFileLocation> clearedContexts= Collections.emptySet();
IIndexFragmentFile file= index.getWritableFile(linkageID, location);
if (file != null) {
clearedContexts= new HashSet();
clearedContexts= new HashSet<IIndexFileLocation>();
index.clearFile(file, clearedContexts);
} else {
file= index.addFile(linkageID, location);
}
file.setTimestamp(fResolver.getLastModified(location));
file.setScannerConfigurationHashcode(configHash);
ArrayList[] lists= (ArrayList[]) symbolMap.get(location);
Symbols lists= symbolMap.get(location);
if (lists != null) {
ArrayList list= lists[1];
IASTPreprocessorMacroDefinition[] macros= (IASTPreprocessorMacroDefinition[]) list.toArray(new IASTPreprocessorMacroDefinition[list.size()]);
list= lists[2];
IASTName[][] names= (IASTName[][]) list.toArray(new IASTName[list.size()][]);
IASTPreprocessorMacroDefinition[] macros= lists.fMacros.toArray(new IASTPreprocessorMacroDefinition[lists.fMacros.size()]);
IASTName[][] names= lists.fNames.toArray(new IASTName[lists.fNames.size()][]);
for (int j= 0; j<names.length; j++) {
final IASTName name= names[j][0];
if (name != null) {
@ -389,10 +402,9 @@ abstract public class PDOMWriter {
}
}
list= lists[0];
IncludeInformation[] includeInfos= new IncludeInformation[list.size()];
for (int i=0; i<list.size(); i++) {
final IASTPreprocessorIncludeStatement include = (IASTPreprocessorIncludeStatement) list.get(i);
IncludeInformation[] includeInfos= new IncludeInformation[lists.fIncludes.size()];
for (int i=0; i<lists.fIncludes.size(); i++) {
final IASTPreprocessorIncludeStatement include = lists.fIncludes.get(i);
final IncludeInformation info= includeInfos[i]= new IncludeInformation();
info.fStatement= include;
if (include.isResolved()) {
@ -401,7 +413,7 @@ abstract public class PDOMWriter {
(contextIncludes.contains(include) || clearedContexts.contains(info.fLocation));
}
}
index.setFileContent(file, linkageID, includeInfos, macros, names);
index.setFileContent(file, linkageID, includeInfos, macros, names, fResolver);
}
return file;
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -32,6 +32,7 @@ import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
import org.eclipse.cdt.internal.core.pdom.db.ChunkCache;
import org.eclipse.cdt.internal.core.pdom.db.DBProperties;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
@ -40,12 +41,13 @@ import org.eclipse.core.runtime.CoreException;
public class WritablePDOM extends PDOM implements IWritableIndexFragment {
private boolean fClearedBecauseOfVersionMismatch= false;
private boolean fCreatedFromScratch= false;
private ASTFilePathResolver fPathResolver;
public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter, Map linkageFactoryMappings) throws CoreException {
public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter, Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException {
this(dbPath, locationConverter, ChunkCache.getSharedInstance(), linkageFactoryMappings);
}
public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache, Map linkageFactoryMappings) throws CoreException {
public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache, Map<String, IPDOMLinkageFactory> linkageFactoryMappings) throws CoreException {
super(dbPath, locationConverter, cache, linkageFactoryMappings);
}
@ -53,18 +55,23 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
return super.addFile(linkageID, location);
}
public void addFileContent(IIndexFragmentFile sourceFile,
IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names) throws CoreException {
public void addFileContent(IIndexFragmentFile sourceFile, IncludeInformation[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[][] names, ASTFilePathResolver pathResolver) throws CoreException {
assert sourceFile.getIndexFragment() == this;
PDOMFile pdomFile = (PDOMFile) sourceFile;
pdomFile.addIncludesTo(includes);
pdomFile.addMacros(macros);
pdomFile.addNames(names);
fPathResolver= pathResolver;
try {
pdomFile.addNames(names);
}
finally {
fPathResolver= null;
}
}
public void clearFile(IIndexFragmentFile file, Collection contextsRemoved) throws CoreException {
public void clearFile(IIndexFragmentFile file, Collection<IIndexFileLocation> contextsRemoved) throws CoreException {
assert file.getIndexFragment() == this;
((PDOMFile) file).clear(contextsRemoved);
}
@ -113,7 +120,7 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
* @throws CoreException
*/
public void rewriteLocations(final IIndexLocationConverter newConverter) throws CoreException {
final List pdomfiles = new ArrayList();
final List<PDOMFile> pdomfiles = new ArrayList<PDOMFile>();
getFileIndex().accept(new IBTreeVisitor(){
public int compare(int record) throws CoreException {
return 0;
@ -126,9 +133,9 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
});
clearFileIndex();
final List notConverted = new ArrayList();
for(Iterator i= pdomfiles.iterator(); i.hasNext(); ) {
PDOMFile file= (PDOMFile) i.next();
final List<PDOMFile> notConverted = new ArrayList<PDOMFile>();
for(Iterator<PDOMFile> i= pdomfiles.iterator(); i.hasNext(); ) {
PDOMFile file= i.next();
String internalFormat = newConverter.toInternalFormat(file.getLocation());
if(internalFormat!=null) {
file.setInternalLocation(internalFormat);
@ -140,8 +147,8 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
// remove content where converter returns null
for(Iterator i = notConverted.iterator(); i.hasNext(); ) {
PDOMFile file = (PDOMFile) i.next();
for(Iterator<PDOMFile> i = notConverted.iterator(); i.hasNext(); ) {
PDOMFile file = i.next();
file.convertIncludersToUnresolved();
file.clear(null);
}
@ -166,4 +173,15 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
protected final boolean isPermanentlyReadOnly() {
return false;
}
public PDOMFile getFileForASTPath(int linkageID, String astPath) throws CoreException {
if (fPathResolver != null) {
if (astPath != null) {
return getFile(linkageID, fPathResolver.resolveASTPath(astPath));
}
}
return null;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Symbian Software Systems and others.
* Copyright (c) 2006, 2008 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -20,8 +19,7 @@ import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.db.IString;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.OperationCanceledException;
/**
* Look up bindings in BTree objects and IPDOMNode objects
@ -37,14 +35,87 @@ public class FindBinding {
IString nm2 = PDOMNamedNode.getDBName(pdom, record2);
int cmp= nm1.compareCompatibleWithIgnoreCase(nm2);
if(cmp == 0) {
int t1 = PDOMNode.getNodeType(pdom, record1);
int t2 = PDOMNode.getNodeType(pdom, record2);
return t1 < t2 ? -1 : (t1 > t2 ? 1 : 0);
int t1= PDOMBinding.getLocalToFileRec(pdom, record1);
int t2= PDOMBinding.getLocalToFileRec(pdom, record2);
if (t1 == t2) {
t1 = PDOMNode.getNodeType(pdom, record1);
t2 = PDOMNode.getNodeType(pdom, record2);
}
cmp= t1 < t2 ? -1 : (t1 > t2 ? 1 : 0);
}
return cmp;
}
}
public static class DefaultFindBindingVisitor implements IBTreeVisitor, IPDOMVisitor {
protected final PDOM fPdom;
private final char[] fName;
private final int[] fConstants;
private final int fLocalToFile;
protected PDOMBinding fResult;
protected DefaultFindBindingVisitor(PDOM pdom, char[] name, int[] constants, int localToFile) {
fPdom = pdom;
fName = name;
fConstants = constants;
fLocalToFile= localToFile;
}
// IBTreeVisitor
public int compare(int record) throws CoreException {
IString nm1 = PDOMNamedNode.getDBName(fPdom, record);
int cmp= nm1.compareCompatibleWithIgnoreCase(fName);
if(cmp == 0) {
int t1= PDOMBinding.getLocalToFileRec(fPdom, record);
int t2= fLocalToFile;
cmp= t1 < t2 ? -1 : (t1 > t2 ? 1 : 0);
}
return cmp;
}
// IBTreeVisitor
public boolean visit(int record) throws CoreException {
final PDOMNamedNode nnode = (PDOMNamedNode) PDOMNode.getLinkage(fPdom, record).getNode(record);
if (nnode instanceof PDOMBinding) {
final PDOMBinding binding = (PDOMBinding) nnode;
if (matches(binding)) {
fResult= binding;
return false;
}
}
return true;
}
protected boolean matches(PDOMBinding nnode) throws CoreException {
if (nnode.hasName(fName)) {
int constant = nnode.getNodeType();
for(int i=0; i<fConstants.length; i++) {
if(constant==fConstants[i]) {
return true;
}
}
}
return false;
}
public PDOMBinding getResult() {
return fResult;
}
// IPDOMVisitor
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof PDOMBinding) {
final PDOMBinding nnode = (PDOMBinding) node;
if (matches(nnode)) {
fResult= nnode;
throw new OperationCanceledException();
}
}
return false; /* do not visit children of node */
}
// IPDOMVisitor
public void leave(IPDOMNode node) throws CoreException {
}
}
public static class NestedBindingsBTreeComparator extends DefaultBindingBTreeComparator implements IBTreeComparator {
protected PDOMLinkage linkage;
@ -89,60 +160,22 @@ public class FindBinding {
}
}
public static PDOMBinding findBinding(BTree btree, final PDOM pdom, final char[]name, final int[] constants) throws CoreException {
final PDOMBinding[] result = new PDOMBinding[1];
btree.accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
IString nm1 = PDOMNamedNode.getDBName(pdom, record);
return nm1.compareCompatibleWithIgnoreCase(name);
}
public boolean visit(int record) throws CoreException {
PDOMNamedNode nnode = (PDOMNamedNode) PDOMNode.getLinkage(pdom, record).getNode(record);
if(nnode.hasName(name)) {
int constant = nnode.getNodeType();
for(int i=0; i<constants.length; i++) {
if(constant==constants[i]) {
result[0] = (PDOMBinding) nnode;
return false;
}
}
return true;
}
return false;
}
});
return result[0];
public static PDOMBinding findBinding(BTree btree, final PDOM pdom, final char[]name, final int[] constants,
final int localToFileRec) throws CoreException {
final DefaultFindBindingVisitor visitor = new DefaultFindBindingVisitor(pdom, name, constants, localToFileRec);
btree.accept(visitor);
return visitor.getResult();
}
public static PDOMBinding findBinding(IPDOMNode node, final PDOM pdom, final char[]name, final int[] constants) {
final PDOMBinding[] result = new PDOMBinding[1];
public static PDOMBinding findBinding(IPDOMNode node, final PDOM pdom, final char[]name, final int[] constants,
int localToFileRec) throws CoreException {
final DefaultFindBindingVisitor visitor = new DefaultFindBindingVisitor(pdom, name, constants, localToFileRec);
try {
node.accept(new IPDOMVisitor() {
public boolean visit(IPDOMNode node) throws CoreException {
if(node instanceof PDOMNamedNode) {
PDOMNamedNode nnode = (PDOMNamedNode) node;
if(nnode.hasName(name)) {
int constant = nnode.getNodeType();
for(int i=0; i<constants.length; i++) {
if(constant==constants[i]) {
result[0] = (PDOMBinding) node;
throw new CoreException(Status.OK_STATUS);
}
}
}
}
return false; /* do not visit children of node */
}
public void leave(IPDOMNode node) throws CoreException {}
});
} catch(CoreException ce) {
if(ce.getStatus().getCode()==IStatus.OK) {
return result[0];
} else {
CCorePlugin.log(ce);
}
node.accept(visitor);
} catch (OperationCanceledException e) {
}
return null;
return visitor.getResult();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -32,7 +32,7 @@ public final class MacroCollector implements IBTreeVisitor {
private IProgressMonitor monitor= null;
private int monitorCheckCounter= 0;
private List macros = new ArrayList();
private List<PDOMMacro> macros = new ArrayList<PDOMMacro>();
/**
@ -91,7 +91,7 @@ public final class MacroCollector implements IBTreeVisitor {
return true; // look for more
}
final public List getMacroList() {
final public List<PDOMMacro> getMacroList() {
return macros;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 QNX Software Systems and others.
* Copyright (c) 2005, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator;
@ -43,8 +44,10 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
private static final int FIRST_DECL_OFFSET = PDOMNamedNode.RECORD_SIZE + 0; // size 4
private static final int FIRST_DEF_OFFSET = PDOMNamedNode.RECORD_SIZE + 4; // size 4
private static final int FIRST_REF_OFFSET = PDOMNamedNode.RECORD_SIZE + 8; // size 4
private static final int LOCAL_TO_FILE = PDOMNamedNode.RECORD_SIZE + 12; // size 4
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 12;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 16;
protected PDOMBinding(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
super(pdom, parent, name);
@ -54,6 +57,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
super(pdom, record);
}
@SuppressWarnings("unchecked")
public Object getAdapter(Class adapter) {
if (adapter.isAssignableFrom(PDOMBinding.class))
return this;
@ -64,6 +68,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
/**
* Is the binding as the record orphaned, i.e., has no declarations
* or references.
* Watch out, a binding may also be used in a type (e.g. pointer to class)
*
* @param pdom
* @param record
@ -144,6 +149,24 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
pdom.getDB().putInt(record + FIRST_REF_OFFSET, namerec);
}
public final PDOMFile getLocalToFile() throws CoreException {
final int filerec = getLocalToFileRec(pdom, record);
return filerec == 0 ? null : new PDOMFile(pdom, filerec);
}
public final int getLocalToFileRec() throws CoreException {
return pdom.getDB().getInt(record + LOCAL_TO_FILE);
}
public static int getLocalToFileRec(PDOM pdom, int record) throws CoreException {
return pdom.getDB().getInt(record + LOCAL_TO_FILE);
}
public final void setLocalToFile(PDOMFile file) throws CoreException {
final int filerec= file == null ? 0 : file.getRecord();
pdom.getDB().putInt(record + LOCAL_TO_FILE, filerec);
}
public String getName() {
try {
return super.getDBName().getString();
@ -219,7 +242,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
* @return
*/
protected static String getConstantNameForValue(PDOMLinkage linkage, int value) {
Class c= linkage.getClass();
Class<? extends PDOMLinkage> c= linkage.getClass();
Field[] fields= c.getFields();
for(int i=0; i<fields.length; i++) {
try {
@ -258,7 +281,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
}
final public String[] getQualifiedName() {
List result = new ArrayList();
List<String> result = new ArrayList<String>();
try {
PDOMNode node = this;
while (node != null) {
@ -267,7 +290,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
}
node = node.getParentNode();
}
return (String[]) result.toArray(new String[result.size()]);
return result.toArray(new String[result.size()]);
} catch(CoreException ce) {
CCorePlugin.log(ce);
return null;
@ -275,18 +298,9 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
}
final public boolean isFileLocal() throws CoreException {
return getParentNode() instanceof PDOMFileLocalScope;
return pdom.getDB().getInt(record + LOCAL_TO_FILE) != 0;
}
final public String getFileLocalScopeQualifier() throws CoreException {
final PDOMNode parentNode = getParentNode();
if (parentNode instanceof PDOMFileLocalScope) {
return ((PDOMFileLocalScope) parentNode).getDBName().getString();
}
return null;
}
public boolean hasDefinition() throws CoreException {
return getFirstDefinition()!=null;
}
@ -373,4 +387,20 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
public int getAdditionalNameFlags(int standardFlags, IASTName name) {
return 0;
}
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
return getBinding(name, resolve, null);
}
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
return null;
}
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
return getBindings(name, resolve, prefix, null);
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix, IIndexFileSet fileSet) throws DOMException {
return null;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 QNX Software Systems and others.
* Copyright (c) 2005, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -221,12 +221,12 @@ public class PDOMFile implements IIndexFragmentFile {
public void addNames(IASTName[][] names) throws CoreException {
assert getFirstName() == null;
HashMap nameCache= new HashMap();
HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>();
PDOMName lastName= null;
for (int i = 0; i < names.length; i++) {
IASTName[] name = names[i];
if (name[0] != null) {
PDOMName caller= (PDOMName) nameCache.get(name[1]);
PDOMName caller= nameCache.get(name[1]);
PDOMName pdomName = createPDOMName(name[0], caller);
if (pdomName != null) {
nameCache.put(name[0], pdomName);
@ -256,7 +256,7 @@ public class PDOMFile implements IIndexFragmentFile {
return result;
}
public void clear(Collection contextsRemoved) throws CoreException {
public void clear(Collection<IIndexFileLocation> contextsRemoved) throws CoreException {
// Remove the includes
PDOMInclude include = getFirstInclude();
while (include != null) {
@ -280,7 +280,7 @@ public class PDOMFile implements IIndexFragmentFile {
setFirstMacro(null);
// Delete all the names in this file
ArrayList names= new ArrayList();
ArrayList<PDOMName> names= new ArrayList<PDOMName>();
PDOMName name = getFirstName();
while (name != null) {
names.add(name);
@ -288,8 +288,8 @@ public class PDOMFile implements IIndexFragmentFile {
name= name.getNextInFile();
}
for (Iterator iterator = names.iterator(); iterator.hasNext();) {
name = (PDOMName) iterator.next();
for (Iterator<PDOMName> iterator = names.iterator(); iterator.hasNext();) {
name = iterator.next();
name.delete();
}
setFirstName(null);
@ -343,23 +343,23 @@ public class PDOMFile implements IIndexFragmentFile {
}
public IIndexInclude[] getIncludes() throws CoreException {
List result= new ArrayList();
List<PDOMInclude> result= new ArrayList<PDOMInclude>();
PDOMInclude include = getFirstInclude();
while (include != null) {
result.add(include);
include = include.getNextInIncludes();
}
return (IIndexInclude[]) result.toArray(new IIndexInclude[result.size()]);
return result.toArray(new IIndexInclude[result.size()]);
}
public IIndexMacro[] getMacros() throws CoreException {
List result= new ArrayList();
List<PDOMMacro> result= new ArrayList<PDOMMacro>();
PDOMMacro macro = getFirstMacro();
while (macro != null) {
result.add(macro);
macro = macro.getNextMacro();
}
return (IIndexMacro[]) result.toArray(new IIndexMacro[result.size()]);
return result.toArray(new IIndexMacro[result.size()]);
}
public IIndexFragment getIndexFragment() {
@ -367,7 +367,7 @@ public class PDOMFile implements IIndexFragmentFile {
}
public IIndexName[] findNames(int offset, int length) throws CoreException {
ArrayList result= new ArrayList();
ArrayList<PDOMName> result= new ArrayList<PDOMName>();
for (PDOMName name= getFirstName(); name != null; name= name.getNextInFile()) {
int nameOffset= name.getNodeOffset();
if (nameOffset >= offset) {
@ -382,10 +382,10 @@ public class PDOMFile implements IIndexFragmentFile {
}
}
return (IIndexName[]) result.toArray(new IIndexName[result.size()]);
return result.toArray(new IIndexName[result.size()]);
}
public static IIndexFragmentFile findFile(PDOM pdom, BTree btree, IIndexFileLocation location, int linkageID, IIndexLocationConverter strategy)
public static PDOMFile findFile(PDOM pdom, BTree btree, IIndexFileLocation location, int linkageID, IIndexLocationConverter strategy)
throws CoreException {
String internalRepresentation= strategy.toInternalFormat(location);
int record= 0;

View file

@ -1,63 +0,0 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
import org.eclipse.core.runtime.CoreException;
public class PDOMFileLocalScope extends PDOMNamedNode implements IPDOMMemberOwner {
private static final int MEMBERLIST = PDOMNamedNode.RECORD_SIZE;
private static final int RECORD_SIZE = MEMBERLIST+4;
public PDOMFileLocalScope(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
super(pdom, parent, name);
}
public PDOMFileLocalScope(PDOM pdom, int record) {
super(pdom, record);
}
protected int getRecordSize() {
return RECORD_SIZE;
}
public int getNodeType() {
return PDOMLinkage.FILE_LOCAL_SCOPE_TYPE;
}
public void accept(IPDOMVisitor visitor) throws CoreException {
super.accept(visitor);
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
list.accept(visitor);
}
public void addMember(PDOMNode member) throws CoreException {
PDOMNodeLinkedList list = new PDOMNodeLinkedList(pdom, record + MEMBERLIST, getLinkageImpl());
list.addMember(member);
}
public void addChild(PDOMNode child) throws CoreException {
addMember(child);
}
public void delete(PDOMLinkage linkage) throws CoreException {
// no support for deleting bindings and their scopes.
assert false;
}
public boolean mayHaveChildren() {
return true;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 QNX Software Systems and others.
* Copyright (c) 2005, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -25,10 +25,14 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IArrayType;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
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.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
@ -41,11 +45,11 @@ import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexLinkage;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.index.CIndex;
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.composite.CompositeScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
@ -67,6 +71,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
private static final int INDEX_OFFSET = PDOMNamedNode.RECORD_SIZE + 8;
private static final int NESTED_BINDINGS_INDEX = PDOMNamedNode.RECORD_SIZE + 12;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 16;
// node types
@ -159,8 +164,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return new PDOMArrayType(pdom, record);
case QUALIFIER_TYPE:
return new PDOMQualifierType(pdom, record);
case FILE_LOCAL_SCOPE_TYPE:
return new PDOMFileLocalScope(pdom, record);
}
return null;
}
@ -186,7 +189,51 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
public abstract PDOMBinding addBinding(IBinding binding, IASTName fromName) throws CoreException;
public abstract PDOMBinding adaptBinding(IBinding binding) throws CoreException;
public final PDOMBinding adaptBinding(final IBinding inputBinding) throws CoreException {
if (inputBinding == null || inputBinding instanceof IProblemBinding) {
return null;
}
boolean isFromAST= true;
IBinding binding= inputBinding;
if (binding instanceof PDOMBinding) {
// there is no guarantee, that the binding is from the same PDOM object.
PDOMBinding pdomBinding = (PDOMBinding) binding;
if (pdomBinding.getPDOM() == getPDOM()) {
return pdomBinding;
}
// if the binding is from another pdom it has to be adapted. However don't adapt file-local bindings
if (pdomBinding.isFileLocal()) {
return null;
}
isFromAST= false;
}
PDOMBinding result= (PDOMBinding) pdom.getCachedResult(inputBinding);
if (result != null) {
return result;
}
int fileLocalRec= 0;
if (isFromAST) {
// assign names to anonymous types.
binding= PDOMASTAdapter.getAdapterIfAnonymous(binding);
if (binding == null) {
return null;
}
PDOMFile lf= getLocalToFile(binding);
if (lf != null) {
fileLocalRec= lf.getRecord();
}
}
result= doAdaptBinding(binding, fileLocalRec);
if (result != null) {
pdom.putCachedResult(inputBinding, result);
}
return result;
}
protected abstract PDOMBinding doAdaptBinding(IBinding binding, int fileLocalRec) throws CoreException;
public final PDOMBinding resolveBinding(IASTName name) throws CoreException {
IBinding binding= name.resolveBinding();
@ -199,15 +246,13 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
/**
*
* @param binding
* @param createFileLocalScope if <code>true</code> the creation of a file local
* scope object is allowed.
* @return <ul><li> null - skip this binding (don't add to pdom)
* <li>this - for filescope
* <li>a PDOMBinding instance - parent adapted binding
* </ul>
* @throws CoreException
*/
protected PDOMNode getAdaptedParent(IBinding binding, boolean createFileLocalScope, boolean addParent) throws CoreException {
protected PDOMNode getAdaptedParent(IBinding binding, boolean addParent) throws CoreException {
try {
IBinding scopeBinding = null;
if (binding instanceof ICPPTemplateInstance) {
@ -272,10 +317,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return null;
}
else if (scopeNode instanceof IASTTranslationUnit) {
if (isFileLocalBinding(binding)) {
IASTTranslationUnit tu= (IASTTranslationUnit) scopeNode;
return findFileLocalScope(tu.getFilePath(), createFileLocalScope);
}
return this;
}
else {
@ -306,8 +347,37 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
}
return null;
}
protected abstract boolean isFileLocalBinding(IBinding binding) throws DOMException;
protected PDOMFile getLocalToFile(IBinding binding) throws CoreException {
if (pdom instanceof WritablePDOM) {
final WritablePDOM wpdom= (WritablePDOM) pdom;
try {
if (binding instanceof IField) {
return null;
}
boolean isFileLocal= false;
if (binding instanceof IVariable) {
if (!(binding instanceof IField)) {
isFileLocal= ASTInternal.isStatic((IVariable) binding);
}
}
else if (binding instanceof IFunction) {
IFunction f= (IFunction) binding;
isFileLocal= ASTInternal.isStatic(f, false);
}
if (isFileLocal) {
String path= ASTInternal.getDeclaredInSourceFileOnly(binding);
if (path != null) {
return wpdom.getFileForASTPath(getLinkageID(), path);
}
}
} catch (DOMException e) {
}
}
return null;
}
public abstract int getBindingType(IBinding binding);
/**
@ -364,34 +434,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
getNestedBindingsIndex().delete(pdomBinding.getRecord());
}
}
/**
* Searches for the a file local scope object. If none is found depending
* on the value of the parameter 'create' such an object is created.
* @param fileName
* @param create
* @since 4.0
*/
final protected PDOMFileLocalScope findFileLocalScope(String fileName, boolean create) throws CoreException {
char[] fname = CIndex.getFileLocalScopeQualifier(fileName);
final PDOMFileLocalScope[] fls= new PDOMFileLocalScope[] {null};
NamedNodeCollector collector= new NamedNodeCollector(this, fname) {
public boolean addNode(PDOMNamedNode node) {
if (node instanceof PDOMFileLocalScope) {
fls[0]= (PDOMFileLocalScope) node;
return false; // done
}
return true;
}
};
getIndex().accept(collector);
if (fls[0] == null && create) {
fls[0]= new PDOMFileLocalScope(pdom, this, fname);
addChild(fls[0]);
}
return fls[0];
}
public void deleteType(IType type, int ownerRec) throws CoreException {
if (type instanceof PDOMNode) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 IBM Corporation.
* Copyright (c) 2006, 2008 IBM Corporation.
* 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
@ -60,7 +60,7 @@ public class PDOMCAnnotation {
modifiers |= (function.isAuto() ? 1 : 0) << PDOMCAnnotation.AUTO_OFFSET;
modifiers |= (function.isExtern() ? 1 : 0) << PDOMCAnnotation.EXTERN_OFFSET;
modifiers |= (function.isRegister() ? 1 : 0) << PDOMCAnnotation.REGISTER_OFFSET;
modifiers |= (ASTInternal.isStatic(function, false, true) ? 1 : 0) << PDOMCAnnotation.STATIC_OFFSET;
modifiers |= (ASTInternal.isStatic(function, false) ? 1 : 0) << PDOMCAnnotation.STATIC_OFFSET;
modifiers |= (function.isInline() ? 1 : 0) << PDOMCAnnotation.INLINE_OFFSET;
modifiers |= (function.takesVarArgs() ? 1 : 0) << PDOMCAnnotation.VARARGS_OFFSET;
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.pdom.dom.c;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -39,9 +40,10 @@ class PDOMCField extends PDOMCVariable implements IField {
}
public int getNodeType() {
return PDOMCLinkage.CFIELD;
return IIndexCBindingConstants.CFIELD;
}
@Override
public boolean isStatic() {
// ISO/IEC 9899:TC1 6.7.2.1
return false;

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -30,7 +30,6 @@ import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
@ -75,7 +74,7 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
}
}
else {
PDOMNode parent = getAdaptedParent(binding, true, false);
PDOMNode parent = getAdaptedParent(binding, false);
if (parent == null)
return null;
@ -111,6 +110,7 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
pdomBinding = new PDOMCTypedef(pdom, parent, (ITypedef)binding);
if (pdomBinding!=null) {
pdomBinding.setLocalToFile(getLocalToFile(binding));
parent.addChild(pdomBinding);
afterAddBinding(pdomBinding);
}
@ -171,41 +171,15 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
return 0;
}
public PDOMBinding adaptBinding(final IBinding inputBinding) throws CoreException {
IBinding binding= inputBinding;
if (binding instanceof PDOMBinding) {
// there is no guarantee, that the binding is from the same PDOM object.
PDOMBinding pdomBinding = (PDOMBinding) binding;
if (pdomBinding.getPDOM() == getPDOM()) {
return pdomBinding;
}
// so if the binding is from another pdom it has to be adapted.
}
else {
// assign names to anonymous types.
binding= PDOMASTAdapter.getAdapterIfAnonymous(binding);
if (binding == null) {
return null;
}
}
PDOMBinding result= (PDOMBinding) pdom.getCachedResult(inputBinding);
if (result != null) {
return result;
}
PDOMNode parent = getAdaptedParent(binding, false, false);
public final PDOMBinding doAdaptBinding(final IBinding binding, int localToFileRec) throws CoreException {
PDOMNode parent = getAdaptedParent(binding, false);
if (parent == this) {
result= FindBinding.findBinding(getIndex(), getPDOM(), binding.getNameCharArray(), new int[] {getBindingType(binding)});
} else if (parent instanceof IPDOMMemberOwner) {
result= FindBinding.findBinding(parent, getPDOM(), binding.getNameCharArray(), new int[] {getBindingType(binding)});
return FindBinding.findBinding(getIndex(), getPDOM(), binding.getNameCharArray(), new int[] {getBindingType(binding)}, localToFileRec);
}
if (parent instanceof IPDOMMemberOwner) {
return FindBinding.findBinding(parent, getPDOM(), binding.getNameCharArray(), new int[] {getBindingType(binding)}, localToFileRec);
}
if (result != null) {
pdom.putCachedResult(inputBinding, result);
}
return result;
return null;
}
public PDOMNode getNode(int record) throws CoreException {
@ -256,19 +230,4 @@ class PDOMCLinkage extends PDOMLinkage implements IIndexCBindingConstants {
public IBTreeComparator getIndexComparator() {
return new FindBinding.DefaultBindingBTreeComparator(getPDOM());
}
protected boolean isFileLocalBinding(IBinding binding) throws DOMException {
if (binding instanceof IField) {
return false;
}
if (binding instanceof IVariable) {
IVariable var= (IVariable) binding;
return ASTInternal.isStatic(var, false);
}
if (binding instanceof IFunction) {
IFunction f= (IFunction) binding;
return ASTInternal.isStatic(f, false, false);
}
return false;
}
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
@ -42,6 +43,7 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment
private static final int NEXT_PARAM = PDOMNamedNode.RECORD_SIZE + 0;
private static final int TYPE = PDOMNamedNode.RECORD_SIZE + 4;
@SuppressWarnings("hiding")
public static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 8;
public PDOMCParameter(PDOM pdom, int record) {
@ -128,6 +130,7 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment
throw new PDOMNotImplementedError();
}
@SuppressWarnings("unchecked")
public Object getAdapter(Class adapter) {
return null;
}
@ -159,13 +162,6 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment
throw new PDOMNotImplementedError();
}
public boolean isFileLocal() throws CoreException {
return true;
}
public String getFileLocalScopeQualifier() throws CoreException {
return null;
}
public String[] getQualifiedName() {
throw new PDOMNotImplementedError();
}
@ -190,4 +186,12 @@ class PDOMCParameter extends PDOMNamedNode implements IParameter, IIndexFragment
}
super.delete(linkage);
}
public boolean isFileLocal() throws CoreException {
return false;
}
public IIndexFile getLocalToFile() throws CoreException {
return null;
}
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
@ -52,6 +53,7 @@ import org.eclipse.core.runtime.Status;
public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCompositeTypeScope, IPDOMMemberOwner, IIndexType, IIndexScope {
private static final int MEMBERLIST = PDOMBinding.RECORD_SIZE;
private static final int KEY = MEMBERLIST + 4; // byte
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 8;
public PDOMCStructure(PDOM pdom, PDOMNode parent, ICompositeType compType) throws CoreException {
@ -107,7 +109,7 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
}
private static class GetFields implements IPDOMVisitor {
private List fields = new ArrayList();
private List<IPDOMNode> fields = new ArrayList<IPDOMNode>();
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof IField) {
IField field= (IField) node;
@ -120,7 +122,7 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
public void leave(IPDOMNode node) throws CoreException {
}
public IField[] getFields() {
return (IField[])fields.toArray(new IField[fields.size()]);
return fields.toArray(new IField[fields.size()]);
}
}
public IField[] getFields() throws DOMException {
@ -232,11 +234,11 @@ public class PDOMCStructure extends PDOMBinding implements ICompositeType, ICCom
fail(); return null;
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
fail(); return null;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
fail(); return null;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Symbian Software Systems and others.
* Copyright (c) 2006, 2008 Symbian Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -11,25 +11,18 @@
*******************************************************************************/
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.IBinding;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.db.IString;
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMOverloader;
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.PDOMNamedNode;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.OperationCanceledException;
/**
* Look up bindings in BTree objects and IPDOMNode objects. This additionally
@ -37,96 +30,6 @@ import org.eclipse.core.runtime.Status;
* specialization arguments for overloading, .
*/
public class CPPFindBinding extends FindBinding {
public static PDOMBinding findBinding(BTree btree, final PDOM pdom, final char[]name, final int c2, final int ty2) throws CoreException {
final PDOMBinding[] result = new PDOMBinding[1];
btree.accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
IString nm1 = PDOMNamedNode.getDBName(pdom, record);
int cmp = nm1.compareCompatibleWithIgnoreCase(name);
if (cmp == 0) {
int c1 = PDOMNode.getNodeType(pdom, record);
cmp = c1 < c2 ? -1 : (c1 > c2 ? 1 : 0);
if (cmp == 0) {
PDOMBinding binding = pdom.getBinding(record);
if (binding instanceof IPDOMOverloader) {
int ty1 = ((IPDOMOverloader) binding)
.getSignatureMemento();
cmp = ty1 < ty2 ? -1 : (ty1 > ty2 ? 1 : 0);
}
}
}
return cmp;
}
public boolean visit(int record) throws CoreException {
result[0] = pdom.getBinding(record);
return false;
}
});
return result[0];
}
public static PDOMBinding findBinding(PDOMNode node, final PDOM pdom, final char[]name, final int constant, final int ty2) {
final PDOMBinding[] result = new PDOMBinding[1];
try {
node.accept(new IPDOMVisitor() {
public boolean visit(IPDOMNode binding) throws CoreException {
if(binding instanceof PDOMNamedNode) {
PDOMNamedNode nnode = (PDOMNamedNode) binding;
if(nnode.hasName(name)) {
if(nnode.getNodeType() == constant) {
if(binding instanceof IPDOMOverloader) {
int ty1 = ((IPDOMOverloader)binding).getSignatureMemento();
if(ty1==ty2) {
result[0] = (PDOMBinding) binding;
throw new CoreException(Status.OK_STATUS);
}
}
}
}
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {}
});
} catch(CoreException ce) {
if(ce.getStatus().getCode()==IStatus.OK) {
return result[0];
} else {
CCorePlugin.log(ce);
}
}
return null;
}
public static PDOMBinding findBinding(BTree btree, PDOMLinkage linkage, IBinding binding) throws CoreException {
Integer memento = null;
try {
memento = IndexCPPSignatureUtil.getSignatureMemento(binding);
} catch (DOMException e) {
}
if(memento != null) {
return findBinding(btree, linkage.getPDOM(), binding.getNameCharArray(), linkage.getBindingType(binding), memento.intValue());
}
return findBinding(btree, linkage.getPDOM(), binding.getNameCharArray(), new int [] {linkage.getBindingType(binding)});
}
public static PDOMBinding findBinding(PDOMNode node, PDOMLinkage linkage, IBinding binding) throws CoreException {
Integer memento = null;
try {
memento = IndexCPPSignatureUtil.getSignatureMemento(binding);
} catch (DOMException e) {
}
if(memento != null) {
return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), linkage.getBindingType(binding), memento.intValue());
}
return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), new int[] {linkage.getBindingType(binding)});
}
public static class CPPBindingBTreeComparator extends FindBinding.DefaultBindingBTreeComparator {
public CPPBindingBTreeComparator(PDOM pdom) {
@ -146,4 +49,90 @@ public class CPPFindBinding extends FindBinding {
return cmp;
}
}
public static class CPPFindBindingVisitor extends FindBinding.DefaultFindBindingVisitor {
private final int fConstant;
private final int fSigMemento;
public CPPFindBindingVisitor(PDOM pdom, char[] name, int constant, int memento, int localToFile) {
super(pdom, name, new int[] {constant}, localToFile);
fConstant= constant;
fSigMemento= memento;
}
public int compare(int record) throws CoreException {
int cmp= super.compare(record);
if (cmp == 0) {
int c1 = PDOMNode.getNodeType(fPdom, record);
int c2= fConstant;
if (c1 == c2) {
PDOMBinding binding = fPdom.getBinding(record);
if (binding instanceof IPDOMOverloader) {
c1 = ((IPDOMOverloader) binding).getSignatureMemento();
c2= fSigMemento;
}
}
cmp = c1 < c2 ? -1 : (c1 > c2 ? 1 : 0);
}
return cmp;
}
@Override
public boolean visit(int record) throws CoreException {
fResult= fPdom.getBinding(record);
return false;
}
@Override
protected boolean matches(PDOMBinding binding) throws CoreException {
if (super.matches(binding)) {
if (binding instanceof IPDOMOverloader) {
int ty1 = ((IPDOMOverloader)binding).getSignatureMemento();
return fSigMemento == ty1;
}
}
return false;
}
}
public static PDOMBinding findBinding(BTree btree, final PDOM pdom, final char[]name, final int c2, final int ty2, int localToFileRec) throws CoreException {
CPPFindBindingVisitor visitor= new CPPFindBindingVisitor(pdom, name, c2, ty2, localToFileRec);
btree.accept(visitor);
return visitor.getResult();
}
public static PDOMBinding findBinding(PDOMNode node, PDOM pdom, char[]name, int constant, int ty2, int localToFileRec)
throws CoreException {
CPPFindBindingVisitor visitor= new CPPFindBindingVisitor(pdom, name, constant, ty2, localToFileRec);
try {
node.accept(visitor);
} catch(OperationCanceledException ce) {
}
return visitor.getResult();
}
public static PDOMBinding findBinding(BTree btree, PDOMLinkage linkage, IBinding binding, int localToFileRec) throws CoreException {
Integer memento= 0;
try {
memento = IndexCPPSignatureUtil.getSignatureMemento(binding);
} catch (DOMException e) {
}
if(memento != null) {
return findBinding(btree, linkage.getPDOM(), binding.getNameCharArray(), linkage.getBindingType(binding), memento.intValue(), localToFileRec);
}
return findBinding(btree, linkage.getPDOM(), binding.getNameCharArray(), new int [] {linkage.getBindingType(binding)}, localToFileRec);
}
public static PDOMBinding findBinding(PDOMNode node, PDOMLinkage linkage, IBinding binding, int localToFileRec) throws CoreException {
Integer memento = null;
try {
memento = IndexCPPSignatureUtil.getSignatureMemento(binding);
} catch (DOMException e) {
}
if(memento != null) {
return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), linkage.getBindingType(binding), memento.intValue(), localToFileRec);
}
return findBinding(node, linkage.getPDOM(), binding.getNameCharArray(), new int[] {linkage.getBindingType(binding)}, localToFileRec);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 QNX Software Systems and others.
* Copyright (c) 2007, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -33,11 +33,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -59,6 +61,7 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
/**
* The size in bytes of a PDOMCPPClassInstance record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPInstance.RECORD_SIZE + 4;
public PDOMCPPClassInstance(PDOM pdom, PDOMNode parent, ICPPClassType classType, PDOMBinding instantiated)
@ -75,7 +78,7 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_CLASS_INSTANCE;
return IIndexCPPBindingConstants.CPP_CLASS_INSTANCE;
}
public ICPPBase[] getBases() throws DOMException {
@ -83,7 +86,7 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
}
private static class ConstructorCollector implements IPDOMVisitor {
private List fConstructors = new ArrayList();
private List<IPDOMNode> fConstructors = new ArrayList<IPDOMNode>();
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof ICPPConstructor)
fConstructors.add(node);
@ -92,7 +95,7 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
public void leave(IPDOMNode node) throws CoreException {
}
public ICPPConstructor[] getConstructors() {
return (ICPPConstructor[])fConstructors.toArray(new ICPPConstructor[fConstructors.size()]);
return fConstructors.toArray(new ICPPConstructor[fConstructors.size()]);
}
}
@ -205,7 +208,7 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
return CPPSemantics.findBindings( this, name, false );
}
public IBinding getBinding(IASTName name, boolean resolve)
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet)
throws DOMException {
try {
if (getDBName().equals(name.toCharArray())) {
@ -226,8 +229,7 @@ class PDOMCPPClassInstance extends PDOMCPPInstance implements
return null;
}
public IBinding[] getBindings(IASTName name, boolean resolve,
boolean prefixLookup) throws DOMException {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
IBinding[] result = null;
try {
if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0)

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 QNX Software Systems and others.
* Copyright (c) 2007, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -34,12 +34,14 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBase;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.index.IIndexType;
import org.eclipse.cdt.internal.core.pdom.PDOM;
@ -64,6 +66,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
/**
* The size in bytes of a PDOMCPPClassSpecialization record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPSpecialization.RECORD_SIZE + 8;
public PDOMCPPClassSpecialization(PDOM pdom, PDOMNode parent, ICPPClassType classType, PDOMBinding specialized)
@ -85,7 +88,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_CLASS_SPECIALIZATION;
return IIndexCPPBindingConstants.CPP_CLASS_SPECIALIZATION;
}
public PDOMCPPBase getFirstBase() throws CoreException {
@ -135,11 +138,11 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
getSpecializedBinding() instanceof ICPPTemplateDefinition) {
//this is an explicit specialization
try {
List list = new ArrayList();
List<PDOMCPPBase> list = new ArrayList<PDOMCPPBase>();
for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase())
list.add(base);
Collections.reverse(list);
ICPPBase[] bases = (ICPPBase[])list.toArray(new ICPPBase[list.size()]);
ICPPBase[] bases = list.toArray(new ICPPBase[list.size()]);
return bases;
} catch (CoreException e) {
CCorePlugin.log(e);
@ -303,7 +306,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
return CPPSemantics.findBindings( this, name, false );
}
public IBinding getBinding(IASTName name, boolean resolve)
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet)
throws DOMException {
if (!(this instanceof ICPPTemplateDefinition) &&
getSpecializedBinding() instanceof ICPPTemplateDefinition) {
@ -383,7 +386,7 @@ class PDOMCPPClassSpecialization extends PDOMCPPSpecialization implements
return result;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
IBinding[] result = null;
if (!(this instanceof ICPPTemplateDefinition)
&& getSpecializedBinding() instanceof ICPPTemplateDefinition) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 QNX Software Systems and others.
* Copyright (c) 2007, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
@ -47,6 +48,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDelegateCreator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
@ -70,6 +72,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
/**
* The size in bytes of a PDOMCPPClassTemplate record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPClassType.RECORD_SIZE + 16;
public PDOMCPPClassTemplate(PDOM pdom, PDOMNode parent, ICPPClassTemplate template)
@ -86,11 +89,11 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_CLASS_TEMPLATE;
return IIndexCPPBindingConstants.CPP_CLASS_TEMPLATE;
}
private static class TemplateParameterCollector implements IPDOMVisitor {
private List params = new ArrayList();
private List<IPDOMNode> params = new ArrayList<IPDOMNode>();
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof ICPPTemplateParameter)
params.add(node);
@ -99,7 +102,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
public void leave(IPDOMNode node) throws CoreException {
}
public ICPPTemplateParameter[] getTemplateParameters() {
return (ICPPTemplateParameter[])params.toArray(new ICPPTemplateParameter[params.size()]);
return params.toArray(new ICPPTemplateParameter[params.size()]);
}
}
@ -129,14 +132,14 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
public ICPPClassTemplatePartialSpecialization[] getPartialSpecializations() throws DOMException {
try {
ArrayList partials = new ArrayList();
ArrayList<PDOMCPPClassTemplatePartialSpecialization> partials = new ArrayList<PDOMCPPClassTemplatePartialSpecialization>();
for (PDOMCPPClassTemplatePartialSpecialization partial = getFirstPartial();
partial != null;
partial = partial.getNextPartial()) {
partials.add(partial);
}
return (ICPPClassTemplatePartialSpecialization[]) partials
return partials
.toArray(new ICPPClassTemplatePartialSpecialization[partials
.size()]);
} catch (CoreException e) {
@ -149,7 +152,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return null;
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
try {
if (getDBName().equals(name.toCharArray())) {
if (CPPClassScope.isConstructorReference(name)){
@ -177,7 +180,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return null;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
IBinding[] result = null;
try {
if ((!prefixLookup && getDBName().compare(name.toCharArray(), true) == 0)
@ -209,7 +212,15 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return CPPSemantics.findBindings( this, name, false );
}
public IBinding getBinding(IASTName name, boolean resolve)
public final IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
return getBinding(name, resolve, IIndexFileSet.EMPTY);
}
public final IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix) throws DOMException {
return getBindings(name, resolve, prefix, IIndexFileSet.EMPTY);
}
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet)
throws DOMException {
try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray());
@ -223,7 +234,7 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
return null;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup)
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet)
throws DOMException {
IBinding[] result = null;
try {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 QNX Software Systems and others.
* Copyright (c) 2005, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -40,6 +40,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
@ -67,10 +68,13 @@ import org.eclipse.core.runtime.CoreException;
class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
ICPPClassScope, IPDOMMemberOwner, IIndexType, IIndexScope, ICPPDelegateCreator {
@SuppressWarnings("static-access")
private static final int FIRSTBASE = PDOMCPPBinding.RECORD_SIZE + 0;
@SuppressWarnings("static-access")
private static final int KEY = PDOMCPPBinding.RECORD_SIZE + 4; // byte
@SuppressWarnings("static-access")
private static final int MEMBERLIST = PDOMCPPBinding.RECORD_SIZE + 8;
@SuppressWarnings({ "static-access", "hiding" })
protected static final int RECORD_SIZE = PDOMCPPBinding.RECORD_SIZE + 12;
public PDOMCPPClassType(PDOM pdom, PDOMNode parent, ICPPClassType classType)
@ -159,11 +163,11 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
public ICPPBase[] getBases() throws DOMException {
try {
List list = new ArrayList();
List<PDOMCPPBase> list = new ArrayList<PDOMCPPBase>();
for (PDOMCPPBase base = getFirstBase(); base != null; base = base.getNextBase())
list.add(base);
Collections.reverse(list);
ICPPBase[] bases = (ICPPBase[])list.toArray(new ICPPBase[list.size()]);
ICPPBase[] bases = list.toArray(new ICPPBase[list.size()]);
return bases;
} catch (CoreException e) {
CCorePlugin.log(e);
@ -190,7 +194,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
public ICPPMethod[] getMethods() throws DOMException {
try {
PDOMClassUtil.MethodCollector methods = new PDOMClassUtil.MethodCollector(true);
acceptInHierarchy(new HashSet(), methods);
acceptInHierarchy(new HashSet<PDOMCPPClassType>(), methods);
return methods.getMethods();
} catch (CoreException e) {
CCorePlugin.log(e);
@ -208,7 +212,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
}
}
private void acceptInHierarchy(Set visited, IPDOMVisitor visitor) throws CoreException {
private void acceptInHierarchy(Set<PDOMCPPClassType> visited, IPDOMVisitor visitor) throws CoreException {
if (visited.contains(this))
return;
visited.add(this);
@ -229,7 +233,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
public ICPPMethod[] getAllDeclaredMethods() throws DOMException {
PDOMClassUtil.MethodCollector myMethods = new PDOMClassUtil.MethodCollector(false, true);
Set visited = new HashSet();
Set<PDOMCPPClassType> visited = new HashSet<PDOMCPPClassType>();
try {
acceptInHierarchy(visited, myMethods);
return myMethods.getMethods();
@ -242,7 +246,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
public IField[] getFields() throws DOMException {
try {
PDOMClassUtil.FieldCollector visitor = new PDOMClassUtil.FieldCollector();
acceptInHierarchy(new HashSet(), visitor);
acceptInHierarchy(new HashSet<PDOMCPPClassType>(), visitor);
return visitor.getFields();
} catch (CoreException e) {
CCorePlugin.log(e);
@ -262,7 +266,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
}
private static class NestedClassCollector implements IPDOMVisitor {
private List nestedClasses = new ArrayList();
private List<IPDOMNode> nestedClasses = new ArrayList<IPDOMNode>();
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof ICPPClassType)
nestedClasses.add(node);
@ -271,7 +275,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
public void leave(IPDOMNode node) throws CoreException {
}
public ICPPClassType[] getNestedClasses() {
return (ICPPClassType[])nestedClasses.toArray(new ICPPClassType[nestedClasses.size()]);
return nestedClasses.toArray(new ICPPClassType[nestedClasses.size()]);
}
}
@ -330,7 +334,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
return true;
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
try {
final char[] nameChars = name.toCharArray();
if (getDBName().equals(nameChars)) {
@ -349,7 +353,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
return null;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
IBinding[] result = null;
try {
final char[] nameChars = name.toCharArray();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 QNX Software Systems and others.
* Copyright (c) 2007, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPDeferredFunctionInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunctionTemplate;
@ -37,6 +38,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDelegateCreator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.PDOMNodeLinkedList;
@ -61,6 +63,7 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements
/**
* The size in bytes of a PDOMCPPFunctionTemplate record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMCPPFunction.RECORD_SIZE + 12;
public PDOMCPPFunctionTemplate(PDOM pdom, PDOMNode parent,
@ -81,11 +84,11 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements
}
public int getNodeType() {
return PDOMCPPLinkage.CPP_FUNCTION_TEMPLATE;
return IIndexCPPBindingConstants.CPP_FUNCTION_TEMPLATE;
}
private static class TemplateParameterCollector implements IPDOMVisitor {
private List params = new ArrayList();
private List<IPDOMNode> params = new ArrayList<IPDOMNode>();
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof ICPPTemplateParameter)
params.add(node);
@ -94,7 +97,7 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements
public void leave(IPDOMNode node) throws CoreException {
}
public ICPPTemplateParameter[] getTemplateParameters() {
return (ICPPTemplateParameter[])params.toArray(new ICPPTemplateParameter[params.size()]);
return params.toArray(new ICPPTemplateParameter[params.size()]);
}
}
@ -199,7 +202,7 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements
return CPPSemantics.findBindings( this, name, false );
}
public IBinding getBinding(IASTName name, boolean resolve)
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet)
throws DOMException {
try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray());
@ -213,7 +216,7 @@ class PDOMCPPFunctionTemplate extends PDOMCPPFunction implements
return null;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup)
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet)
throws DOMException {
IBinding[] result = null;
try {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 QNX Software Systems and others.
* Copyright (c) 2005, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -59,7 +59,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPBlockScope;
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
@ -68,6 +67,7 @@ import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
@ -94,10 +94,12 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return CPP_LINKAGE_ID;
}
@Override
protected int getRecordSize() {
return RECORD_SIZE;
}
@Override
public int getNodeType() {
return LINKAGE;
}
@ -179,7 +181,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
}
List postProcesses = new ArrayList();
List<Runnable> postProcesses = new ArrayList<Runnable>();
public PDOMBinding addBinding(IASTName name) throws CoreException {
if (name == null || name instanceof ICPPASTQualifiedName)
@ -227,7 +229,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
} else {
try {
PDOMNode parent = getAdaptedParent(binding, true, true);
PDOMNode parent = getAdaptedParent(binding, true);
if (parent == null)
return null;
pdomBinding = addBinding(parent, binding);
@ -401,6 +403,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
if(pdomBinding!=null) {
pdomBinding.setLocalToFile(getLocalToFile(binding));
parent.addChild(pdomBinding);
afterAddBinding(pdomBinding);
}
@ -451,6 +454,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
}
@Override
public int getBindingType(IBinding binding) {
if (binding instanceof ICPPSpecialization) {
if (binding instanceof ICPPDeferredTemplateInstance) {
@ -543,32 +547,8 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
/**
* Find the equivalent binding, or binding placeholder within this PDOM
*/
public PDOMBinding adaptBinding(final IBinding inputBinding) throws CoreException {
if (inputBinding == null || inputBinding instanceof IProblemBinding)
return null;
IBinding binding= inputBinding;
if (binding instanceof PDOMBinding) {
// there is no guarantee, that the binding is from the same PDOM object.
PDOMBinding pdomBinding = (PDOMBinding) binding;
if (pdomBinding.getPDOM() == getPDOM()) {
return pdomBinding;
}
// so if the binding is from another pdom it has to be adapted.
}
else {
// assign names to anonymous types.
binding= PDOMASTAdapter.getAdapterIfAnonymous(binding);
if (binding == null) {
return null;
}
}
PDOMBinding result= (PDOMBinding) pdom.getCachedResult(inputBinding);
if (result != null) {
return result;
}
@Override
public PDOMBinding doAdaptBinding(IBinding binding, int localToFileRec) throws CoreException {
if (binding instanceof ICPPUsingDeclaration) {
try {
ICPPDelegate[] delegates = ((ICPPUsingDeclaration)binding).getDelegates();
@ -580,20 +560,20 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return null;
}
}
PDOMNode parent = getAdaptedParent(binding, false, false);
PDOMNode parent = getAdaptedParent(binding, false);
if (parent == this) {
result= CPPFindBinding.findBinding(getIndex(), this, binding);
} else if (parent instanceof IPDOMMemberOwner) {
result= CPPFindBinding.findBinding(parent, this, binding);
} else if (parent instanceof PDOMCPPNamespace) {
result= CPPFindBinding.findBinding(((PDOMCPPNamespace)parent).getIndex(), this, binding);
return CPPFindBinding.findBinding(getIndex(), this, binding, localToFileRec);
}
if (parent instanceof PDOMCPPNamespace) {
return CPPFindBinding.findBinding(((PDOMCPPNamespace)parent).getIndex(), this, binding, localToFileRec);
}
if (result != null) {
pdom.putCachedResult(inputBinding, result);
if (parent instanceof IPDOMMemberOwner) {
return CPPFindBinding.findBinding(parent, this, binding, localToFileRec);
}
return result;
return null;
}
@Override
public PDOMNode addType(PDOMNode parent, IType type) throws CoreException {
if (type instanceof IProblemBinding) {
return null;
@ -651,9 +631,10 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
private Runnable popPostProcess() {
return (Runnable) postProcesses.remove(postProcesses.size() - 1);
return postProcesses.remove(postProcesses.size() - 1);
}
@Override
public PDOMNode getNode(int record) throws CoreException {
if (record == 0)
return null;
@ -753,6 +734,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
return new CPPFindBinding.CPPBindingBTreeComparator(pdom);
}
@Override
public void onCreateName(PDOMName pdomName, IASTName name) throws CoreException {
super.onCreateName(pdomName, name);
@ -785,6 +767,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
}
@Override
public void onDeleteName(PDOMName pdomName) throws CoreException {
super.onDeleteName(pdomName);
@ -803,22 +786,11 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
}
}
protected boolean isFileLocalBinding(IBinding binding) throws DOMException {
if (binding instanceof ICPPField) {
return false;
}
if (binding instanceof ICPPVariable) {
if (!(binding.getScope() instanceof CPPBlockScope)) {
return ASTInternal.isStatic((ICPPVariable) binding, false);
}
return false;
}
@Override
protected PDOMFile getLocalToFile(IBinding binding) throws CoreException {
if (binding instanceof ICPPMethod) {
return false;
return null;
}
if (binding instanceof ICPPFunction) {
return ASTInternal.isStatic((ICPPFunction) binding, false, false);
}
return false;
return super.getLocalToFile(binding);
}
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNamespace;
@ -51,6 +52,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
private static final int INDEX_OFFSET = PDOMBinding.RECORD_SIZE + 0;
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMBinding.RECORD_SIZE + 4;
public PDOMCPPNamespace(PDOM pdom, PDOMNode parent, ICPPNamespace namespace) throws CoreException {
@ -119,9 +121,12 @@ class PDOMCPPNamespace extends PDOMCPPBinding
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
}
public IBinding getBinding(IASTName name, boolean resolve) throws DOMException {
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet fileSet) throws DOMException {
try {
IBinding[] bindings= getBindingsViaCache(name.toCharArray());
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
}
return CPPSemantics.resolveAmbiguities(name, bindings);
} catch (CoreException e) {
CCorePlugin.log(e);
@ -129,7 +134,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
return null;
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) throws DOMException {
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
IBinding[] result = null;
try {
if (!prefixLookup) {
@ -137,7 +142,11 @@ class PDOMCPPNamespace extends PDOMCPPBinding
}
BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.toCharArray(), IndexFilter.ALL_DECLARED_OR_IMPLICIT, prefixLookup, !prefixLookup);
getIndex().accept(visitor);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
IBinding[] bindings = visitor.getBindings();
if (fileSet != null) {
bindings= fileSet.filterFileLocalBindings(bindings);
}
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, bindings);
} catch (CoreException e) {
CCorePlugin.log(e);
}
@ -167,7 +176,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
public IBinding[] getMemberBindings() throws DOMException {
IBinding[] result = null;
final List preresult = new ArrayList();
final List<PDOMNode> preresult = new ArrayList<PDOMNode>();
try {
getIndex().accept(new IBTreeVisitor() {
public int compare(int record) throws CoreException {
@ -178,7 +187,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
return true;
}
});
result = (IBinding[]) preresult.toArray(new IBinding[preresult.size()]);
result = preresult.toArray(new IBinding[preresult.size()]);
} catch(CoreException ce) {
CCorePlugin.log(ce);
}

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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPParameter;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDelegateCreator;
@ -65,6 +66,7 @@ class PDOMCPPParameter extends PDOMNamedNode
/**
* The size in bytes of a PDOMCPPParameter record in the database.
*/
@SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 9;
private static final byte FLAG_DEFAULT_VALUE = 0x1;
@ -192,6 +194,7 @@ class PDOMCPPParameter extends PDOMNamedNode
return null;
}
@SuppressWarnings("unchecked")
public Object getAdapter(Class adapter) {
return null;
}
@ -237,14 +240,6 @@ class PDOMCPPParameter extends PDOMNamedNode
throw new PDOMNotImplementedError();
}
public boolean isFileLocal() throws CoreException {
return true;
}
public String getFileLocalScopeQualifier() throws CoreException {
return null;
}
public int getBindingConstant() {
return getNodeType();
}
@ -261,4 +256,12 @@ class PDOMCPPParameter extends PDOMNamedNode
}
super.delete(linkage);
}
public boolean isFileLocal() throws CoreException {
return false;
}
public IIndexFile getLocalToFile() throws CoreException {
return null;
}
}