mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Search for macro references, bug 156561.
This commit is contained in:
parent
db312ccd1b
commit
bb469b32ee
53 changed files with 1383 additions and 386 deletions
|
@ -145,7 +145,7 @@ public class LocationMapTests extends BaseTestCase {
|
||||||
String filename, int offset, int length, int line, int endline, String sig) {
|
String filename, int offset, int length, int line, int endline, String sig) {
|
||||||
assertSame(binding, name.getBinding());
|
assertSame(binding, name.getBinding());
|
||||||
assertSame(binding, name.resolveBinding());
|
assertSame(binding, name.resolveBinding());
|
||||||
assertEquals(Linkage.NO_LINKAGE, name.getLinkage());
|
assertEquals(Linkage.CPP_LINKAGE, name.getLinkage());
|
||||||
assertEquals(nameString, name.toString());
|
assertEquals(nameString, name.toString());
|
||||||
checkASTNode(name, parent, property, filename, offset, length, line, endline, sig);
|
checkASTNode(name, parent, property, filename, offset, length, line, endline, sig);
|
||||||
assertEquals(name.isDeclaration(), role == IASTNameOwner.r_declaration);
|
assertEquals(name.isDeclaration(), role == IASTNameOwner.r_declaration);
|
||||||
|
|
|
@ -79,6 +79,10 @@ public class EmptyIndexFragment implements IIndexFragment {
|
||||||
return IIndexFragmentName.EMPTY_NAME_ARRAY;
|
return IIndexFragmentName.EMPTY_NAME_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IIndexFragmentBinding[] findMacroContainers(Pattern pattern, IndexFilter filter, IProgressMonitor monitor) {
|
||||||
|
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
|
||||||
|
}
|
||||||
|
|
||||||
public long getCacheHits() {
|
public long getCacheHits() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 Symbian Software Systems and others.
|
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -93,6 +93,7 @@ public class IndexProviderManagerTest extends IndexTestBase {
|
||||||
return suite(IndexProviderManagerTest.class);
|
return suite(IndexProviderManagerTest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
IndexProviderManager ipm= ((PDOMManager)CCorePlugin.getIndexManager()).getIndexProviderManager();
|
IndexProviderManager ipm= ((PDOMManager)CCorePlugin.getIndexManager()).getIndexProviderManager();
|
||||||
ipm.reset(); ipm.startup();
|
ipm.reset(); ipm.startup();
|
||||||
|
@ -526,7 +527,7 @@ class MockStateIndexFragmentProvider extends MockStateIndexProvider implements I
|
||||||
|
|
||||||
fragments = new IIndexFragment[MockState.states.size()];
|
fragments = new IIndexFragment[MockState.states.size()];
|
||||||
for(int i=0; i<MockState.states.size(); i++) {
|
for(int i=0; i<MockState.states.size(); i++) {
|
||||||
fragments[i] = new MockPDOM("mock.test.index."+System.identityHashCode(this)+"."+i, ""+PDOM.CURRENT_VERSION);
|
fragments[i] = new MockPDOM("mock.test.index."+System.identityHashCode(this)+"."+i, ""+PDOM.MAJOR_VERSION+'.'+PDOM.MINOR_VERSION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -726,6 +727,7 @@ class MockPDOM extends EmptyIndexFragment {
|
||||||
this.version= version;
|
this.version= version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getProperty(String propertyName) throws CoreException {
|
public String getProperty(String propertyName) throws CoreException {
|
||||||
if(IIndexFragment.PROPERTY_FRAGMENT_ID.equals(propertyName)) {
|
if(IIndexFragment.PROPERTY_FRAGMENT_ID.equals(propertyName)) {
|
||||||
return id;
|
return id;
|
||||||
|
@ -739,6 +741,7 @@ class MockPDOM extends EmptyIndexFragment {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[Mock index fragment "+id+"."+System.identityHashCode(this)+"]";
|
return "[Mock index fragment "+id+"."+System.identityHashCode(this)+"]";
|
||||||
}
|
}
|
||||||
|
|
|
@ -351,22 +351,9 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
private IndexTypeReference createReference(IIndexMacro macro) throws CoreException {
|
private IndexTypeReference createReference(IIndexMacro macro) throws CoreException {
|
||||||
IIndexFileLocation ifl = macro.getFile().getLocation();
|
IIndexName def= macro.getDefinition();
|
||||||
String fullPath = ifl.getFullPath();
|
if (def != null) {
|
||||||
if (fullPath != null) {
|
return createReference(macro, def);
|
||||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath));
|
|
||||||
if(file!=null) {
|
|
||||||
return new IndexTypeReference(
|
|
||||||
macro, file, file.getProject(), macro.getNodeOffset(), macro.getNodeLength()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
IPath path = URIUtil.toPath(ifl.getURI());
|
|
||||||
if(path!=null) {
|
|
||||||
return new IndexTypeReference(
|
|
||||||
macro, path, null, macro.getNodeOffset(), macro.getNodeLength()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 QNX Software Systems and others.
|
* Copyright (c) 2006, 2008 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -22,12 +22,14 @@ import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexMacroContainer;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,6 +138,9 @@ public class IndexModelUtil {
|
||||||
if (binding instanceof IEnumerator) {
|
if (binding instanceof IEnumerator) {
|
||||||
elementType = ICElement.C_ENUMERATOR;
|
elementType = ICElement.C_ENUMERATOR;
|
||||||
}
|
}
|
||||||
|
if (binding instanceof IMacroBinding || binding instanceof IIndexMacroContainer) {
|
||||||
|
elementType= ICElement.C_MACRO;
|
||||||
|
}
|
||||||
return elementType;
|
return elementType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,6 +260,18 @@ public interface IIndex {
|
||||||
*/
|
*/
|
||||||
public IIndexBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
|
public IIndexBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for all macro containers (one for macros with the same name) with names that
|
||||||
|
* match the given pattern. In case a binding exists in multiple projects, no duplicate bindings
|
||||||
|
* are returned.
|
||||||
|
* @param pattern a pattern the name of the bindings have to match.
|
||||||
|
* @param filter a filter that allows for skipping parts of the index
|
||||||
|
* @param monitor a monitor to report progress, may be <code>null</code>
|
||||||
|
* @return an array of bindings matching the pattern
|
||||||
|
* @throws CoreException
|
||||||
|
*/
|
||||||
|
IIndexBinding[] findMacroContainers(Pattern pattern, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for all bindings in global scope with a given name. In case a binding exists in multiple projects, no duplicate bindings are returned.
|
* 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.
|
* This method makes use of the BTree and is faster than the methods using patterns.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -29,30 +29,25 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public interface IIndexMacro extends IMacroBinding {
|
public interface IIndexMacro extends IMacroBinding, IIndexBinding {
|
||||||
|
|
||||||
IIndexMacro[] EMPTY_INDEX_MACRO_ARRAY = new IIndexMacro[0];
|
IIndexMacro[] EMPTY_INDEX_MACRO_ARRAY = new IIndexMacro[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If available, return the file location for this macro definition
|
* If available, return the file location for the macro definition of this macro,
|
||||||
* otherwise return null
|
* otherwise return <code>null</code>.
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
IASTFileLocation getFileLocation();
|
IASTFileLocation getFileLocation();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the file this macro belongs to.
|
* Returns the file in which this macro is defined and belongs to.
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
*/
|
*/
|
||||||
IIndexFile getFile() throws CoreException;
|
IIndexFile getFile() throws CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the character offset of the location of the name.
|
* Returns the name of the definition of this macro, or <code>null</code> if not available.
|
||||||
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public int getNodeOffset();
|
IIndexName getDefinition();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the length of the name.
|
|
||||||
*/
|
|
||||||
public int getNodeLength();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a binding for all macros with the same name. When you try to adapt a macro binding in an index
|
||||||
|
* you'll get the container as a result.
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
|
public interface IIndexMacroContainer extends IIndexBinding {
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -32,6 +32,8 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public interface IIndexName extends IName {
|
public interface IIndexName extends IName {
|
||||||
|
IIndexName[] EMPTY_ARRAY= {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the file the name belongs to.
|
* Returns the file the name belongs to.
|
||||||
* @throws CoreException
|
* @throws CoreException
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -10,9 +10,6 @@
|
||||||
* Andrew Ferguson (Symbian)
|
* Andrew Ferguson (Symbian)
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
|
||||||
* Created on May 28, 2004
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.core.parser.util;
|
package org.eclipse.cdt.core.parser.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,15 +231,16 @@ public class CharArrayUtils {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int indexOf( char toBeFound, char[] buffer, int start, int len ) {
|
public static int indexOf( char toBeFound, char[] buffer, int start, int end ) {
|
||||||
if( start < 0 || start > buffer.length || start + len > buffer.length )
|
if( start < 0 || start > buffer.length || end > buffer.length )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (int i = start; i < len; i++)
|
for (int i = start; i < end; i++)
|
||||||
if (toBeFound == buffer[i])
|
if (toBeFound == buffer[i])
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int indexOf( char[] toBeFound, char[] array ){
|
public static final int indexOf( char[] toBeFound, char[] array ){
|
||||||
if( toBeFound.length > array.length )
|
if( toBeFound.length > array.length )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,10 +8,11 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.dom;
|
package org.eclipse.cdt.internal.core.dom;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ILinkage;
|
import org.eclipse.cdt.core.dom.ILinkage;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
public class Linkage implements ILinkage {
|
public class Linkage implements ILinkage {
|
||||||
|
|
||||||
|
@ -26,6 +27,16 @@ public class Linkage implements ILinkage {
|
||||||
return LINKAGES;
|
return LINKAGES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getLinkageName(int linkageID) throws CoreException {
|
||||||
|
switch(linkageID) {
|
||||||
|
case NO_LINKAGE_ID: return NO_LINKAGE_NAME;
|
||||||
|
case C_LINKAGE_ID: return C_LINKAGE_NAME;
|
||||||
|
case CPP_LINKAGE_ID: return CPP_LINKAGE_NAME;
|
||||||
|
case FORTRAN_LINKAGE_ID: return FORTRAN_LINKAGE_NAME;
|
||||||
|
}
|
||||||
|
throw new CoreException(CCorePlugin.createStatus("Unsupported linkage id: " + linkageID)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
private int fID;
|
private int fID;
|
||||||
private String fName;
|
private String fName;
|
||||||
private Linkage(int id, String name) {
|
private Linkage(int id, String name) {
|
||||||
|
|
|
@ -119,6 +119,33 @@ public class CIndex implements IIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IIndexBinding[] findMacroContainers(Pattern pattern, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
|
if(SPECIALCASE_SINGLES && fFragments.length==1) {
|
||||||
|
return fFragments[0].findMacroContainers(pattern, filter, monitor);
|
||||||
|
} else {
|
||||||
|
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
|
||||||
|
ILinkage[] linkages = Linkage.getAllLinkages();
|
||||||
|
for(int j=0; j < linkages.length; j++) {
|
||||||
|
if(filter.acceptLinkage(linkages[j])) {
|
||||||
|
IIndexFragmentBinding[][] fragmentBindings = new IIndexFragmentBinding[fPrimaryFragmentCount][];
|
||||||
|
for (int i = 0; i < fPrimaryFragmentCount; i++) {
|
||||||
|
try {
|
||||||
|
IBinding[] part = fFragments[i].findMacroContainers(pattern, retargetFilter(linkages[j], filter), monitor);
|
||||||
|
fragmentBindings[i] = new IIndexFragmentBinding[part.length];
|
||||||
|
System.arraycopy(part, 0, fragmentBindings[i], 0, part.length);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
fragmentBindings[i] = IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ICompositesFactory factory = getCompositesFactory(linkages[j].getLinkageID());
|
||||||
|
result.add(factory.getCompositeBindings(fragmentBindings));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flatten(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IIndexName[] findNames(IBinding binding, int flags) throws CoreException {
|
public IIndexName[] findNames(IBinding binding, int flags) throws CoreException {
|
||||||
LinkedList<IIndexFragmentName> result= new LinkedList<IIndexFragmentName>();
|
LinkedList<IIndexFragmentName> result= new LinkedList<IIndexFragmentName>();
|
||||||
if (binding instanceof ICPPUsingDeclaration) {
|
if (binding instanceof ICPPUsingDeclaration) {
|
||||||
|
|
|
@ -138,4 +138,8 @@ final public class EmptyCIndex implements IIndex {
|
||||||
public IIndexBinding[] findBindings(char[] name, boolean fileScopeOnly, IndexFilter filter, IProgressMonitor monitor) {
|
public IIndexBinding[] findBindings(char[] name, boolean fileScopeOnly, IndexFilter filter, IProgressMonitor monitor) {
|
||||||
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
|
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IIndexBinding[] findMacroContainers(Pattern pattern, IndexFilter filter, IProgressMonitor monitor) {
|
||||||
|
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -17,5 +17,7 @@ public interface IIndexBindingConstants {
|
||||||
int POINTER_TYPE= 1;
|
int POINTER_TYPE= 1;
|
||||||
int ARRAY_TYPE= 2;
|
int ARRAY_TYPE= 2;
|
||||||
int QUALIFIER_TYPE= 3;
|
int QUALIFIER_TYPE= 3;
|
||||||
int LAST_CONSTANT= QUALIFIER_TYPE;
|
int MACRO_DEFINITION = 4;
|
||||||
|
int MACRO_CONTAINER = 5;
|
||||||
|
int LAST_CONSTANT= MACRO_CONTAINER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,6 +140,19 @@ public interface IIndexFragment {
|
||||||
*/
|
*/
|
||||||
IIndexFragmentBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
|
IIndexFragmentBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for all macro containers (one for macros with the same name) with names that
|
||||||
|
* match the given pattern. In case a binding exists in multiple projects, no duplicate bindings
|
||||||
|
* are returned.
|
||||||
|
* @param pattern a pattern the name of the bindings have to match.
|
||||||
|
* @param filter a filter that allows for skipping parts of the index
|
||||||
|
* @param monitor a monitor to report progress, may be <code>null</code>
|
||||||
|
* @return an array of bindings matching the pattern
|
||||||
|
* @throws CoreException
|
||||||
|
*/
|
||||||
|
IIndexFragmentBinding[] findMacroContainers(Pattern pattern, IndexFilter filter, IProgressMonitor monitor) throws CoreException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for all bindings with qualified names that seen as an array of simple names equals
|
* Searches for all bindings with qualified names that seen as an array of simple names equals
|
||||||
* the given array of names.
|
* the given array of names.
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.composite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.index.IIndexMacroContainer;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Composite binding for macro containers.
|
||||||
|
*
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
|
public class CompositeMacroContainer extends CompositeIndexBinding implements IIndexMacroContainer {
|
||||||
|
public CompositeMacroContainer(ICompositesFactory cf, IIndexFragmentBinding rbinding) {
|
||||||
|
super(cf, rbinding);
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,12 +29,14 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexMacroContainer;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.AbstractCompositeFactory;
|
import org.eclipse.cdt.internal.core.index.composite.AbstractCompositeFactory;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositeArrayType;
|
import org.eclipse.cdt.internal.core.index.composite.CompositeArrayType;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositeFunctionType;
|
import org.eclipse.cdt.internal.core.index.composite.CompositeFunctionType;
|
||||||
|
import org.eclipse.cdt.internal.core.index.composite.CompositeMacroContainer;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositePointerType;
|
import org.eclipse.cdt.internal.core.index.composite.CompositePointerType;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositeQualifierType;
|
import org.eclipse.cdt.internal.core.index.composite.CompositeQualifierType;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError;
|
import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError;
|
||||||
|
@ -120,6 +122,8 @@ public class CCompositesFactory extends AbstractCompositeFactory implements ICom
|
||||||
result = new CompositeCEnumerator(this, rbinding);
|
result = new CompositeCEnumerator(this, rbinding);
|
||||||
} else if(rbinding instanceof ITypedef) {
|
} else if(rbinding instanceof ITypedef) {
|
||||||
result = new CompositeCTypedef(this, rbinding);
|
result = new CompositeCTypedef(this, rbinding);
|
||||||
|
} else if(rbinding instanceof IIndexMacroContainer) {
|
||||||
|
result= new CompositeMacroContainer(this, rbinding);
|
||||||
} else {
|
} else {
|
||||||
throw new CompositingNotImplementedError("composite binding unavailable for "+rbinding+" "+rbinding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
|
throw new CompositingNotImplementedError("composite binding unavailable for "+rbinding+" "+rbinding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,12 +48,14 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexMacroContainer;
|
||||||
import org.eclipse.cdt.internal.core.index.CIndex;
|
import org.eclipse.cdt.internal.core.index.CIndex;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.AbstractCompositeFactory;
|
import org.eclipse.cdt.internal.core.index.composite.AbstractCompositeFactory;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositeArrayType;
|
import org.eclipse.cdt.internal.core.index.composite.CompositeArrayType;
|
||||||
|
import org.eclipse.cdt.internal.core.index.composite.CompositeMacroContainer;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositePointerType;
|
import org.eclipse.cdt.internal.core.index.composite.CompositePointerType;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositeQualifierType;
|
import org.eclipse.cdt.internal.core.index.composite.CompositeQualifierType;
|
||||||
import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError;
|
import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError;
|
||||||
|
@ -154,6 +156,7 @@ public class CPPCompositesFactory extends AbstractCompositeFactory implements IC
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected IIndexFragmentBinding findOneDefinition(IBinding binding) {
|
protected IIndexFragmentBinding findOneDefinition(IBinding binding) {
|
||||||
return super.findOneDefinition(binding);
|
return super.findOneDefinition(binding);
|
||||||
}
|
}
|
||||||
|
@ -266,6 +269,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory implements IC
|
||||||
result = new CompositeCPPTypedef(this, (ICPPBinding) binding);
|
result = new CompositeCPPTypedef(this, (ICPPBinding) binding);
|
||||||
} else if(binding instanceof ICPPTemplateTypeParameter) {
|
} else if(binding instanceof ICPPTemplateTypeParameter) {
|
||||||
result = new CompositeCPPTemplateTypeParameter(this, (ICPPTemplateTypeParameter) binding);
|
result = new CompositeCPPTemplateTypeParameter(this, (ICPPTemplateTypeParameter) binding);
|
||||||
|
} else if(binding instanceof IIndexMacroContainer) {
|
||||||
|
result= new CompositeMacroContainer(this, binding);
|
||||||
} else {
|
} else {
|
||||||
throw new CompositingNotImplementedError("composite binding unavailable for "+binding+" "+binding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
|
throw new CompositingNotImplementedError("composite binding unavailable for "+binding+" "+binding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ public final class IndexProviderManager implements IElementChangedListener {
|
||||||
* <b>Note: This method should not be called by clients for purposes other than testing</b>
|
* <b>Note: This method should not be called by clients for purposes other than testing</b>
|
||||||
*/
|
*/
|
||||||
public void reset() {
|
public void reset() {
|
||||||
reset(new VersionRange("["+PDOM.MIN_SUPPORTED_VERSION+','+PDOM.CURRENT_VERSION+']')); //$NON-NLS-1$
|
reset(new VersionRange(new Version(PDOM.MAJOR_VERSION,0, 0), true, new Version(PDOM.MAJOR_VERSION+1, 0, 0), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -43,7 +43,8 @@ class ASTPreprocessorName extends ASTPreprocessorNode implements IASTName {
|
||||||
return fBinding;
|
return fBinding;
|
||||||
}
|
}
|
||||||
public ILinkage getLinkage() {
|
public ILinkage getLinkage() {
|
||||||
return Linkage.NO_LINKAGE;
|
final IASTTranslationUnit tu= getTranslationUnit();
|
||||||
|
return tu == null ? Linkage.NO_LINKAGE : tu.getLinkage();
|
||||||
}
|
}
|
||||||
public IASTCompletionContext getCompletionContext() {
|
public IASTCompletionContext getCompletionContext() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -679,6 +679,10 @@ public class LocationMap implements ILocationResolver {
|
||||||
return result.toArray(new IASTName[result.size()]);
|
return result.toArray(new IASTName[result.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IASTName[] getMacroReferences() {
|
||||||
|
return fMacroReferences.toArray(new IASTName[fMacroReferences.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
public ASTPreprocessorName[] getNestedMacroReferences(ASTMacroExpansion expansion) {
|
public ASTPreprocessorName[] getNestedMacroReferences(ASTMacroExpansion expansion) {
|
||||||
final IASTName explicitRef= expansion.getMacroReference();
|
final IASTName explicitRef= expansion.getMacroReference();
|
||||||
List<ASTPreprocessorName> result= new ArrayList<ASTPreprocessorName>();
|
List<ASTPreprocessorName> result= new ArrayList<ASTPreprocessorName>();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -31,7 +31,6 @@ public class Messages extends NLS {
|
||||||
public static String TeamPDOMExportOperation_errorWriteTempFile;
|
public static String TeamPDOMExportOperation_errorWriteTempFile;
|
||||||
public static String TeamPDOMExportOperation_subtaskCreateDatabase;
|
public static String TeamPDOMExportOperation_subtaskCreateDatabase;
|
||||||
public static String TeamPDOMExportOperation_taskExportIndex;
|
public static String TeamPDOMExportOperation_taskExportIndex;
|
||||||
public static String WritablePDOM_error_unknownLinkage;
|
|
||||||
public static String AbstractIndexerTask_parsingFileTask;
|
public static String AbstractIndexerTask_parsingFileTask;
|
||||||
public static String AbstractIndexerTask_errorWhileParsing;
|
public static String AbstractIndexerTask_errorWhileParsing;
|
||||||
public static String AbstractIndexerTask_tooManyIndexProblems;
|
public static String AbstractIndexerTask_tooManyIndexProblems;
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IField;
|
import org.eclipse.cdt.core.dom.ast.IField;
|
||||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||||
|
@ -46,6 +47,7 @@ import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.index.IIndexLinkage;
|
import org.eclipse.cdt.core.index.IIndexLinkage;
|
||||||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexMacroContainer;
|
||||||
import org.eclipse.cdt.core.index.IndexFilter;
|
import org.eclipse.cdt.core.index.IndexFilter;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
|
import org.eclipse.cdt.internal.core.index.IIndexCBindingConstants;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
|
@ -62,13 +64,16 @@ import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
|
import org.eclipse.cdt.internal.core.pdom.dom.BindingCollector;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
|
import org.eclipse.cdt.internal.core.pdom.dom.FindBinding;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
|
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.MacroCollector;
|
import org.eclipse.cdt.internal.core.pdom.dom.MacroContainerCollector;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.MacroContainerPatternCollector;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.NamedNodeCollector;
|
import org.eclipse.cdt.internal.core.pdom.dom.NamedNodeCollector;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
|
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.PDOMFile;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMInclude;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacro;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacro;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacroContainer;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacroReferenceName;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNamedNode;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
|
||||||
|
@ -91,18 +96,16 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
*/
|
*/
|
||||||
public static final String FRAGMENT_PROPERTY_VALUE_FORMAT_ID= "org.eclipse.cdt.internal.core.pdom.PDOM"; //$NON-NLS-1$
|
public static final String FRAGMENT_PROPERTY_VALUE_FORMAT_ID= "org.eclipse.cdt.internal.core.pdom.PDOM"; //$NON-NLS-1$
|
||||||
|
|
||||||
public static final int CURRENT_VERSION = 56;
|
public static int version(int major, int minor) {
|
||||||
public static final int MIN_SUPPORTED_VERSION= CURRENT_VERSION;
|
return major << 16 + minor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public static final int MAJOR_VERSION = 57;
|
||||||
* The earliest PDOM version that the CURRENT_VERSION can be read as. For example,
|
public static final int MINOR_VERSION = 0; // minor versions must be compatible
|
||||||
* versions 37,38 and 39 may be safely read by code from the version of CDT (4.0.0)
|
|
||||||
* released at PDOM version 36.
|
public static final int CURRENT_VERSION= version(MAJOR_VERSION, MINOR_VERSION);
|
||||||
* <p>
|
public static final int MIN_SUPPORTED_VERSION= version(MAJOR_VERSION, 0);
|
||||||
* Ideally this would always be CURRENT_VERSION on the basis that CURRENT_VERSION is
|
public static final int MAX_SUPPORTED_VERSION= version(MAJOR_VERSION+1, 0)-1;
|
||||||
* not incrementing.
|
|
||||||
*/
|
|
||||||
public static final int EARLIEST_FORWARD_COMPATIBLE_VERSION= CURRENT_VERSION;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PDOM internal format history
|
* PDOM internal format history
|
||||||
|
@ -157,13 +160,13 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
* 54 - optimization of database size (bug 210392)
|
* 54 - optimization of database size (bug 210392)
|
||||||
* 55 - generalization of local bindings (bug 215783)
|
* 55 - generalization of local bindings (bug 215783)
|
||||||
* 56 - using directives (bug 216527)
|
* 56 - using directives (bug 216527)
|
||||||
|
* 57.0 - macro references (bug 156561)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static final int LINKAGES = Database.DATA_AREA;
|
public static final int LINKAGES = Database.DATA_AREA;
|
||||||
public static final int FILE_INDEX = Database.DATA_AREA + 4;
|
public static final int FILE_INDEX = Database.DATA_AREA + 4;
|
||||||
public static final int PROPERTIES = Database.DATA_AREA + 8;
|
public static final int PROPERTIES = Database.DATA_AREA + 8;
|
||||||
public static final int MACRO_BTREE= Database.DATA_AREA + 12;
|
public static final int END= Database.DATA_AREA + 12;
|
||||||
public static final int END= Database.DATA_AREA + 16;
|
|
||||||
static {
|
static {
|
||||||
assert END <= Database.CHUNK_SIZE;
|
assert END <= Database.CHUNK_SIZE;
|
||||||
}
|
}
|
||||||
|
@ -195,7 +198,6 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
// Local caches
|
// Local caches
|
||||||
protected Database db;
|
protected Database db;
|
||||||
private BTree fileIndex;
|
private BTree fileIndex;
|
||||||
private BTree fMacroIndex= null;
|
|
||||||
private Map<String, PDOMLinkage> fLinkageIDCache = new HashMap<String, PDOMLinkage>();
|
private Map<String, PDOMLinkage> fLinkageIDCache = new HashMap<String, PDOMLinkage>();
|
||||||
private File fPath;
|
private File fPath;
|
||||||
private IIndexLocationConverter locationConverter;
|
private IIndexLocationConverter locationConverter;
|
||||||
|
@ -225,13 +227,11 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
fPath= dbPath;
|
fPath= dbPath;
|
||||||
final boolean lockDB= db == null || lockCount != 0;
|
final boolean lockDB= db == null || lockCount != 0;
|
||||||
|
|
||||||
|
clearCaches();
|
||||||
db = new Database(fPath, cache, CURRENT_VERSION, isPermanentlyReadOnly());
|
db = new Database(fPath, cache, CURRENT_VERSION, isPermanentlyReadOnly());
|
||||||
fileIndex= null; // holds on to the database, so clear it.
|
|
||||||
fMacroIndex= null; // same here
|
|
||||||
|
|
||||||
db.setLocked(lockDB);
|
db.setLocked(lockDB);
|
||||||
int version= db.getVersion();
|
if (isSupportedVersion()) {
|
||||||
if (version >= MIN_SUPPORTED_VERSION) {
|
|
||||||
readLinkages();
|
readLinkages();
|
||||||
}
|
}
|
||||||
db.setLocked(lockCount != 0);
|
db.setLocked(lockCount != 0);
|
||||||
|
@ -246,7 +246,8 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSupportedVersion() throws CoreException {
|
public boolean isSupportedVersion() throws CoreException {
|
||||||
return db.getVersion() >= MIN_SUPPORTED_VERSION;
|
final int version = db.getVersion();
|
||||||
|
return version >= MIN_SUPPORTED_VERSION && version <= MAX_SUPPORTED_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void accept(IPDOMVisitor visitor) throws CoreException {
|
public void accept(IPDOMVisitor visitor) throws CoreException {
|
||||||
|
@ -353,9 +354,12 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexFragmentBinding findBinding(IASTName name) throws CoreException {
|
public IIndexFragmentBinding findBinding(IASTName name) throws CoreException {
|
||||||
|
IBinding binding= name.resolveBinding();
|
||||||
|
if (binding != null) {
|
||||||
PDOMLinkage linkage= adaptLinkage(name.getLinkage());
|
PDOMLinkage linkage= adaptLinkage(name.getLinkage());
|
||||||
if (linkage != null) {
|
if (linkage != null) {
|
||||||
return linkage.resolveBinding(name);
|
return findBindingInLinkage(linkage, binding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -461,6 +465,27 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
return finder.getBindings();
|
return finder.getBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IIndexFragmentBinding[] findMacroContainers(Pattern pattern, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
|
if (monitor == null) {
|
||||||
|
monitor= new NullProgressMonitor();
|
||||||
|
}
|
||||||
|
MacroContainerPatternCollector finder = new MacroContainerPatternCollector(this, pattern, monitor);
|
||||||
|
for (Iterator<PDOMLinkage> iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
|
||||||
|
PDOMLinkage linkage = iter.next();
|
||||||
|
if (filter.acceptLinkage(linkage)) {
|
||||||
|
try {
|
||||||
|
linkage.getMacroIndex().accept(finder);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
if (e.getStatus() != Status.OK_STATUS)
|
||||||
|
throw e;
|
||||||
|
else
|
||||||
|
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return finder.getMacroContainers();
|
||||||
|
}
|
||||||
|
|
||||||
public IIndexFragmentBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
public IIndexFragmentBinding[] findBindings(char[][] names, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
if (names.length == 0) {
|
if (names.length == 0) {
|
||||||
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
|
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
|
||||||
|
@ -688,18 +713,25 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
if (binding == null) {
|
if (binding == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
PDOMBinding pdomBinding= (PDOMBinding) binding.getAdapter(PDOMBinding.class);
|
PDOMNode pdomNode= (PDOMNode) binding.getAdapter(PDOMNode.class);
|
||||||
if (pdomBinding != null && pdomBinding.getPDOM() == this) {
|
if (pdomNode instanceof IIndexFragmentBinding && pdomNode.getPDOM() == this) {
|
||||||
return pdomBinding;
|
return (IIndexFragmentBinding) pdomNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
PDOMLinkage linkage= adaptLinkage(binding.getLinkage());
|
PDOMLinkage linkage= adaptLinkage(binding.getLinkage());
|
||||||
if (linkage != null) {
|
if (linkage != null) {
|
||||||
return linkage.adaptBinding(binding);
|
return findBindingInLinkage(linkage, binding);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IIndexFragmentBinding findBindingInLinkage(PDOMLinkage linkage, IBinding binding) throws CoreException {
|
||||||
|
if (binding instanceof IMacroBinding || binding instanceof IIndexMacroContainer) {
|
||||||
|
return linkage.findMacroContainer(binding.getNameCharArray());
|
||||||
|
}
|
||||||
|
return linkage.adaptBinding(binding);
|
||||||
|
}
|
||||||
|
|
||||||
public IIndexFragmentBinding findBinding(IIndexFragmentName indexName) throws CoreException {
|
public IIndexFragmentBinding findBinding(IIndexFragmentName indexName) throws CoreException {
|
||||||
if (indexName instanceof PDOMName) {
|
if (indexName instanceof PDOMName) {
|
||||||
PDOMName pdomName= (PDOMName) indexName;
|
PDOMName pdomName= (PDOMName) indexName;
|
||||||
|
@ -709,22 +741,25 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexFragmentName[] findNames(IBinding binding, int options) throws CoreException {
|
public IIndexFragmentName[] findNames(IBinding binding, int options) throws CoreException {
|
||||||
ArrayList<PDOMName> names= new ArrayList<PDOMName>();
|
ArrayList<IIndexFragmentName> names= new ArrayList<IIndexFragmentName>();
|
||||||
PDOMBinding pdomBinding = (PDOMBinding) adaptBinding(binding);
|
IIndexFragmentBinding myBinding= adaptBinding(binding);
|
||||||
if (pdomBinding != null) {
|
if (myBinding instanceof PDOMBinding) {
|
||||||
names= new ArrayList<PDOMName>();
|
PDOMBinding pdomBinding = (PDOMBinding) myBinding;
|
||||||
findNamesForMyBinding(pdomBinding, options, names);
|
findNamesForMyBinding(pdomBinding, options, names);
|
||||||
}
|
|
||||||
if ((options & SEARCH_ACCROSS_LANGUAGE_BOUNDARIES) != 0) {
|
if ((options & SEARCH_ACCROSS_LANGUAGE_BOUNDARIES) != 0) {
|
||||||
PDOMBinding[] xlangBindings= getCrossLanguageBindings(binding);
|
PDOMBinding[] xlangBindings= getCrossLanguageBindings(binding);
|
||||||
for (int j = 0; j < xlangBindings.length; j++) {
|
for (int j = 0; j < xlangBindings.length; j++) {
|
||||||
findNamesForMyBinding(xlangBindings[j], options, names);
|
findNamesForMyBinding(xlangBindings[j], options, names);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (myBinding instanceof PDOMMacroContainer) {
|
||||||
|
findNamesForMyBinding((PDOMMacroContainer) myBinding, options, names);
|
||||||
|
}
|
||||||
return names.toArray(new IIndexFragmentName[names.size()]);
|
return names.toArray(new IIndexFragmentName[names.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findNamesForMyBinding(PDOMBinding pdomBinding, int options, ArrayList<PDOMName> names)
|
private void findNamesForMyBinding(PDOMBinding pdomBinding, int options, ArrayList<IIndexFragmentName> names)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
PDOMName name;
|
PDOMName name;
|
||||||
if ((options & FIND_DECLARATIONS) != 0) {
|
if ((options & FIND_DECLARATIONS) != 0) {
|
||||||
|
@ -744,6 +779,20 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void findNamesForMyBinding(PDOMMacroContainer container, int options, ArrayList<IIndexFragmentName> names)
|
||||||
|
throws CoreException {
|
||||||
|
if ((options & FIND_DEFINITIONS) != 0) {
|
||||||
|
for (PDOMMacro macro= container.getFirstDefinition(); macro != null; macro= macro.getNextInContainer()) {
|
||||||
|
names.add(macro.getDefinition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((options & FIND_REFERENCES) != 0) {
|
||||||
|
for (PDOMMacroReferenceName name = container.getFirstReference(); name != null; name= name.getNextInContainer()) {
|
||||||
|
names.add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException {
|
public IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException {
|
||||||
PDOMFile pdomFile= adaptFile(file);
|
PDOMFile pdomFile= adaptFile(file);
|
||||||
if (pdomFile != null) {
|
if (pdomFile != null) {
|
||||||
|
@ -822,38 +871,31 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
|
|
||||||
public IIndexMacro[] findMacros(char[] prefix, boolean isPrefix, boolean isCaseSensitive, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
public IIndexMacro[] findMacros(char[] prefix, boolean isPrefix, boolean isCaseSensitive, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
|
||||||
ArrayList<IIndexMacro> result= new ArrayList<IIndexMacro>();
|
ArrayList<IIndexMacro> result= new ArrayList<IIndexMacro>();
|
||||||
MacroCollector visitor = new MacroCollector(this, prefix, isPrefix, isCaseSensitive);
|
MacroContainerCollector visitor = new MacroContainerCollector(this, prefix, isPrefix, isCaseSensitive);
|
||||||
visitor.setMonitor(monitor);
|
visitor.setMonitor(monitor);
|
||||||
try {
|
try {
|
||||||
getMacroIndex().accept(visitor);
|
for (Iterator<PDOMLinkage> iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
|
||||||
result.addAll(visitor.getMacroList());
|
PDOMLinkage linkage = iter.next();
|
||||||
|
if (filter.acceptLinkage(linkage)) {
|
||||||
|
linkage.getMacroIndex().accept(visitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (PDOMMacroContainer mcont : visitor.getMacroList()) {
|
||||||
|
result.addAll(Arrays.asList(mcont.getDefinitions()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException e) {
|
catch (OperationCanceledException e) {
|
||||||
}
|
}
|
||||||
return result.toArray(new IIndexMacro[result.size()]);
|
return result.toArray(new IIndexMacro[result.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BTree getMacroIndex() {
|
|
||||||
if (fMacroIndex == null) {
|
|
||||||
fMacroIndex= new BTree(db, MACRO_BTREE, new FindBinding.MacroBTreeComparator(this));
|
|
||||||
}
|
|
||||||
return fMacroIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterAddMacro(PDOMMacro macro) throws CoreException {
|
|
||||||
getMacroIndex().insert(macro.getRecord());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void beforeRemoveMacro(PDOMMacro macro) throws CoreException {
|
|
||||||
getMacroIndex().delete(macro.getRecord());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getProperty(String propertyName) throws CoreException {
|
public String getProperty(String propertyName) throws CoreException {
|
||||||
if(IIndexFragment.PROPERTY_FRAGMENT_FORMAT_ID.equals(propertyName)) {
|
if(IIndexFragment.PROPERTY_FRAGMENT_FORMAT_ID.equals(propertyName)) {
|
||||||
return FRAGMENT_PROPERTY_VALUE_FORMAT_ID;
|
return FRAGMENT_PROPERTY_VALUE_FORMAT_ID;
|
||||||
}
|
}
|
||||||
if(IIndexFragment.PROPERTY_FRAGMENT_FORMAT_VERSION.equals(propertyName)) {
|
if(IIndexFragment.PROPERTY_FRAGMENT_FORMAT_VERSION.equals(propertyName)) {
|
||||||
return ""+db.getVersion(); //$NON-NLS-1$
|
int version= db.getVersion();
|
||||||
|
return ""+(version >> 16) + '.' + (version & 0xffff); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
return new DBProperties(db, PROPERTIES).getProperty(propertyName);
|
return new DBProperties(db, PROPERTIES).getProperty(propertyName);
|
||||||
}
|
}
|
||||||
|
@ -865,7 +907,6 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
|
|
||||||
private void clearCaches() {
|
private void clearCaches() {
|
||||||
fileIndex= null;
|
fileIndex= null;
|
||||||
fMacroIndex= null;
|
|
||||||
fLinkageIDCache.clear();
|
fLinkageIDCache.clear();
|
||||||
clearResultCache();
|
clearResultCache();
|
||||||
}
|
}
|
||||||
|
@ -892,9 +933,9 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
db.flush();
|
db.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getCachedResult(Object binding) {
|
public Object getCachedResult(Object key) {
|
||||||
synchronized(fResultCache) {
|
synchronized(fResultCache) {
|
||||||
return fResultCache.get(binding);
|
return fResultCache.get(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -905,7 +946,7 @@ public class PDOM extends PlatformObject implements IPDOM {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createKeyForCache(int record, char[] name) {
|
public String createKeyForCache(int record, char[] name) {
|
||||||
return new StringBuffer(name.length+2).append((char) (record >> 16)).append((char) record).append(name).toString();
|
return new StringBuilder(name.length+2).append((char) (record >> 16)).append((char) record).append(name).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PDOMBinding[] getCrossLanguageBindings(IBinding binding) throws CoreException {
|
private PDOMBinding[] getCrossLanguageBindings(IBinding binding) throws CoreException {
|
||||||
|
|
|
@ -240,4 +240,15 @@ public class PDOMProxy implements IPDOM {
|
||||||
return fDelegate.getAllFiles();
|
return fDelegate.getAllFiles();
|
||||||
return IIndexFragmentFile.EMPTY_ARRAY;
|
return IIndexFragmentFile.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.index.IIndexFragment#findMacroContainers(java.util.regex.Pattern, org.eclipse.cdt.core.index.IndexFilter, org.eclipse.core.runtime.IProgressMonitor)
|
||||||
|
*/
|
||||||
|
public synchronized IIndexFragmentBinding[] findMacroContainers(Pattern pattern, IndexFilter filter,
|
||||||
|
IProgressMonitor monitor) throws CoreException {
|
||||||
|
if (fDelegate != null) {
|
||||||
|
return fDelegate.findMacroContainers(pattern, filter, monitor);
|
||||||
|
}
|
||||||
|
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
|
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner.LocationMap;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMASTAdapter;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerASTVisitor;
|
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerASTVisitor;
|
||||||
|
@ -63,6 +64,7 @@ import org.eclipse.osgi.util.NLS;
|
||||||
abstract public class PDOMWriter {
|
abstract public class PDOMWriter {
|
||||||
public static int SKIP_ALL_REFERENCES= -1;
|
public static int SKIP_ALL_REFERENCES= -1;
|
||||||
public static int SKIP_TYPE_REFERENCES= 1;
|
public static int SKIP_TYPE_REFERENCES= 1;
|
||||||
|
public static int SKIP_MACRO_REFERENCES= 2;
|
||||||
public static int SKIP_NO_REFERENCES= 0;
|
public static int SKIP_NO_REFERENCES= 0;
|
||||||
|
|
||||||
private static class Symbols {
|
private static class Symbols {
|
||||||
|
@ -108,7 +110,8 @@ abstract public class PDOMWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether references are skipped or not. Provide one of
|
* Determines whether references are skipped or not. Provide one of
|
||||||
* {@link #SKIP_ALL_REFERENCES}, {@link #SKIP_TYPE_REFERENCES} or {@link #SKIP_NO_REFERENCES}.
|
* {@link #SKIP_ALL_REFERENCES}, {@link #SKIP_NO_REFERENCES} or a combination of
|
||||||
|
* {@link #SKIP_TYPE_REFERENCES} or {@link #SKIP_MACRO_REFERENCES}.
|
||||||
*/
|
*/
|
||||||
public void setSkipReferences(int options) {
|
public void setSkipReferences(int options) {
|
||||||
fSkipReferences= options;
|
fSkipReferences= options;
|
||||||
|
@ -335,6 +338,20 @@ abstract public class PDOMWriter {
|
||||||
};
|
};
|
||||||
ast.accept(visitor);
|
ast.accept(visitor);
|
||||||
|
|
||||||
|
if ((fSkipReferences & SKIP_MACRO_REFERENCES) == 0) {
|
||||||
|
LocationMap lm= (LocationMap) ast.getAdapter(LocationMap.class);
|
||||||
|
if (lm != null) {
|
||||||
|
IASTName[] refs= lm.getMacroReferences();
|
||||||
|
for (IASTName name : refs) {
|
||||||
|
IASTFileLocation nameLoc = name.getFileLocation();
|
||||||
|
if (nameLoc != null) {
|
||||||
|
IIndexFileLocation location = fResolver.resolveASTPath(nameLoc.getFileName());
|
||||||
|
addToMap(symbolMap, location, new IASTName[]{name, null});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fStatistics.fUnresolvedIncludesCount += unresolvedIncludes;
|
fStatistics.fUnresolvedIncludesCount += unresolvedIncludes;
|
||||||
fStatistics.fPreprocessorProblemCount+= ast.getPreprocessorProblemsCount() - unresolvedIncludes;
|
fStatistics.fPreprocessorProblemCount+= ast.getPreprocessorProblemsCount() - unresolvedIncludes;
|
||||||
if (fShowScannerProblems || fShowInclusionProblems) {
|
if (fShowScannerProblems || fShowInclusionProblems) {
|
||||||
|
|
|
@ -12,14 +12,12 @@
|
||||||
package org.eclipse.cdt.internal.core.pdom;
|
package org.eclipse.cdt.internal.core.pdom;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
|
@ -32,9 +30,7 @@ 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.DBProperties;
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
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.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.PDOMFile;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
public class WritablePDOM extends PDOM implements IWritableIndexFragment {
|
public class WritablePDOM extends PDOM implements IWritableIndexFragment {
|
||||||
|
@ -97,18 +93,6 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
|
||||||
super.flush();
|
super.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMBinding addBinding(IASTName name) throws CoreException {
|
|
||||||
PDOMBinding result= null;
|
|
||||||
PDOMLinkage linkage= createLinkage(name.getLinkage().getLinkageName());
|
|
||||||
if (linkage == null) {
|
|
||||||
CCorePlugin.log(MessageFormat.format(Messages.WritablePDOM_error_unknownLinkage, new Object[]{name.getLinkage()}));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result= linkage.addBinding(name);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.index.IWritableIndexFragment#setProperty(java.lang.String, java.lang.String)
|
* @see org.eclipse.cdt.internal.core.index.IWritableIndexFragment#setProperty(java.lang.String, java.lang.String)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 QNX Software Systems and others.
|
* Copyright (c) 2006, 2008 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -41,6 +41,7 @@ public final class BindingCollector extends NamedNodeCollector {
|
||||||
this.filter= filter;
|
this.filter= filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean addNode(PDOMNamedNode tBinding) throws CoreException {
|
public boolean addNode(PDOMNamedNode tBinding) throws CoreException {
|
||||||
if (tBinding instanceof PDOMBinding) {
|
if (tBinding instanceof PDOMBinding) {
|
||||||
if (filter == null || filter.acceptBinding((IBinding) tBinding)) {
|
if (filter == null || filter.acceptBinding((IBinding) tBinding)) {
|
||||||
|
@ -51,7 +52,7 @@ public final class BindingCollector extends NamedNodeCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMBinding[] getBindings() {
|
public PDOMBinding[] getBindings() {
|
||||||
List bindings= getNodeList();
|
List<PDOMNamedNode> bindings= getNodeList();
|
||||||
return (PDOMBinding[])bindings.toArray(new PDOMBinding[bindings.size()]);
|
return bindings.toArray(new PDOMBinding[bindings.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,7 @@ public class FindBinding {
|
||||||
super(linkage.pdom);
|
super(linkage.pdom);
|
||||||
this.linkage= linkage;
|
this.linkage= linkage;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public int compare(int record1, int record2) throws CoreException {
|
public int compare(int record1, int record2) throws CoreException {
|
||||||
int cmp= super.compare(record1, record2); // compare names
|
int cmp= super.compare(record1, record2); // compare names
|
||||||
if (cmp==0) { // any order will do.
|
if (cmp==0) { // any order will do.
|
||||||
|
@ -144,16 +145,7 @@ public class FindBinding {
|
||||||
fPDom= pdom;
|
fPDom= pdom;
|
||||||
}
|
}
|
||||||
public int compare(int record1, int record2) throws CoreException {
|
public int compare(int record1, int record2) throws CoreException {
|
||||||
int cmp= compare(PDOMMacro.getNameInDB(fPDom, record1), PDOMMacro.getNameInDB(fPDom, record2)); // compare names
|
return compare(PDOMNamedNode.getDBName(fPDom, record1), PDOMNamedNode.getDBName(fPDom, record2)); // compare names
|
||||||
if (cmp==0) { // any order will do.
|
|
||||||
if (record1 < record2) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else if (record1 > record2) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cmp;
|
|
||||||
}
|
}
|
||||||
private int compare(IString nameInDB, IString nameInDB2) throws CoreException {
|
private int compare(IString nameInDB, IString nameInDB2) throws CoreException {
|
||||||
return nameInDB.compareCompatibleWithIgnoreCase(nameInDB2);
|
return nameInDB.compareCompatibleWithIgnoreCase(nameInDB2);
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
* Visitor to find macros in a BTree.
|
* Visitor to find macros in a BTree.
|
||||||
* @since 4.0.2
|
* @since 4.0.2
|
||||||
*/
|
*/
|
||||||
public final class MacroCollector implements IBTreeVisitor {
|
public final class MacroContainerCollector implements IBTreeVisitor {
|
||||||
private final PDOM pdom;
|
private final PDOM pdom;
|
||||||
private final char[] name;
|
private final char[] name;
|
||||||
private final boolean prefixLookup;
|
private final boolean prefixLookup;
|
||||||
|
@ -32,14 +32,14 @@ public final class MacroCollector implements IBTreeVisitor {
|
||||||
private IProgressMonitor monitor= null;
|
private IProgressMonitor monitor= null;
|
||||||
private int monitorCheckCounter= 0;
|
private int monitorCheckCounter= 0;
|
||||||
|
|
||||||
private List<PDOMMacro> macros = new ArrayList<PDOMMacro>();
|
private List<PDOMMacroContainer> macros = new ArrayList<PDOMMacroContainer>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects all nodes with given name, passing the filter. If prefixLookup is set to
|
* Collects all nodes with given name, passing the filter. If prefixLookup is set to
|
||||||
* <code>true</code> a binding is considered if its name starts with the given prefix.
|
* <code>true</code> a binding is considered if its name starts with the given prefix.
|
||||||
*/
|
*/
|
||||||
public MacroCollector(PDOM pdom, char[] name, boolean prefixLookup, boolean caseSensitive) {
|
public MacroContainerCollector(PDOM pdom, char[] name, boolean prefixLookup, boolean caseSensitive) {
|
||||||
this.name= name;
|
this.name= name;
|
||||||
this.pdom= pdom;
|
this.pdom= pdom;
|
||||||
this.prefixLookup= prefixLookup;
|
this.prefixLookup= prefixLookup;
|
||||||
|
@ -57,7 +57,7 @@ public final class MacroCollector implements IBTreeVisitor {
|
||||||
final public int compare(int record) throws CoreException {
|
final public int compare(int record) throws CoreException {
|
||||||
if (monitor != null)
|
if (monitor != null)
|
||||||
checkCancelled();
|
checkCancelled();
|
||||||
IString name= PDOMMacro.getNameInDB(pdom, record);
|
IString name= PDOMNamedNode.getDBName(pdom, record);
|
||||||
return compare(name);
|
return compare(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,11 +87,11 @@ public final class MacroCollector implements IBTreeVisitor {
|
||||||
if (record == 0)
|
if (record == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
macros.add(new PDOMMacro(pdom, record));
|
macros.add(new PDOMMacroContainer(pdom, record));
|
||||||
return true; // look for more
|
return true; // look for more
|
||||||
}
|
}
|
||||||
|
|
||||||
final public List<PDOMMacro> getMacroList() {
|
final public List<PDOMMacroContainer> getMacroList() {
|
||||||
return macros;
|
return macros;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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 (Wind River Systems)
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.db.IString;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visitor to find a macro container in a BTree.
|
||||||
|
*/
|
||||||
|
public final class MacroContainerFinder implements IBTreeVisitor {
|
||||||
|
private final PDOM fPdom;
|
||||||
|
private final char[] fName;
|
||||||
|
private PDOMMacroContainer fMacroContainer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collects all nodes with given name, passing the filter. If prefixLookup is set to
|
||||||
|
* <code>true</code> a binding is considered if its name starts with the given prefix.
|
||||||
|
*/
|
||||||
|
public MacroContainerFinder(PDOM pdom, char[] name) {
|
||||||
|
fName= name;
|
||||||
|
fPdom= pdom;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public int compare(int record) throws CoreException {
|
||||||
|
IString name= PDOMNamedNode.getDBName(fPdom, record);
|
||||||
|
return compare(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int compare(IString rhsName) throws CoreException {
|
||||||
|
return rhsName.compareCompatibleWithIgnoreCase(fName);
|
||||||
|
}
|
||||||
|
|
||||||
|
final public boolean visit(int record) throws CoreException {
|
||||||
|
if (record == 0)
|
||||||
|
return true;
|
||||||
|
fMacroContainer= new PDOMMacroContainer(fPdom, record);
|
||||||
|
return false; // we are done.
|
||||||
|
}
|
||||||
|
|
||||||
|
final public PDOMMacroContainer getMacroContainer() {
|
||||||
|
return fMacroContainer;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visitor to find macros in a BTree.
|
||||||
|
* @since 4.0.2
|
||||||
|
*/
|
||||||
|
public final class MacroContainerPatternCollector implements IBTreeVisitor {
|
||||||
|
private final PDOM fPDOM;
|
||||||
|
|
||||||
|
private final List<PDOMMacroContainer> macros = new ArrayList<PDOMMacroContainer>();
|
||||||
|
private final Pattern fPattern;
|
||||||
|
private final IProgressMonitor fMonitor;
|
||||||
|
private int fMonitorCheckCounter= 0;
|
||||||
|
|
||||||
|
|
||||||
|
public MacroContainerPatternCollector(PDOM pdom, Pattern pattern, IProgressMonitor monitor) {
|
||||||
|
fPDOM= pdom;
|
||||||
|
fPattern= pattern;
|
||||||
|
fMonitor= monitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
final public int compare(int record) throws CoreException {
|
||||||
|
if (fMonitor != null)
|
||||||
|
checkCancelled();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public boolean visit(int record) throws CoreException {
|
||||||
|
if (record == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
String name= PDOMNamedNode.getDBName(fPDOM, record).getString();
|
||||||
|
if (fPattern.matcher(name).matches()) {
|
||||||
|
macros.add(new PDOMMacroContainer(fPDOM, record));
|
||||||
|
}
|
||||||
|
return true; // look for more
|
||||||
|
}
|
||||||
|
|
||||||
|
final public PDOMMacroContainer[] getMacroContainers() {
|
||||||
|
return macros.toArray(new PDOMMacroContainer[macros.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkCancelled() {
|
||||||
|
if (++fMonitorCheckCounter % 0x1000 == 0 && fMonitor.isCanceled()) {
|
||||||
|
throw new OperationCanceledException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
|
||||||
import org.eclipse.cdt.internal.core.index.ArrayTypeClone;
|
import org.eclipse.cdt.internal.core.index.ArrayTypeClone;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexType;
|
import org.eclipse.cdt.internal.core.index.IIndexType;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||||
|
@ -27,6 +28,7 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
public class PDOMArrayType extends PDOMNode implements IIndexType, IArrayType, ITypeContainer {
|
public class PDOMArrayType extends PDOMNode implements IIndexType, IArrayType, ITypeContainer {
|
||||||
|
|
||||||
private static final int TYPE = PDOMNode.RECORD_SIZE;
|
private static final int TYPE = PDOMNode.RECORD_SIZE;
|
||||||
|
@SuppressWarnings("hiding")
|
||||||
private static final int RECORD_SIZE= TYPE+4;
|
private static final int RECORD_SIZE= TYPE+4;
|
||||||
|
|
||||||
public PDOMArrayType(PDOM pdom, int record) {
|
public PDOMArrayType(PDOM pdom, int record) {
|
||||||
|
@ -48,12 +50,14 @@ public class PDOMArrayType extends PDOMNode implements IIndexType, IArrayType, I
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int getRecordSize() {
|
protected int getRecordSize() {
|
||||||
return RECORD_SIZE;
|
return RECORD_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getNodeType() {
|
public int getNodeType() {
|
||||||
return PDOMLinkage.ARRAY_TYPE;
|
return IIndexBindingConstants.ARRAY_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTExpression getArraySizeExpression() throws DOMException {
|
public IASTExpression getArraySizeExpression() throws DOMException {
|
||||||
|
@ -93,10 +97,12 @@ public class PDOMArrayType extends PDOMNode implements IIndexType, IArrayType, I
|
||||||
throw new PDOMNotImplementedError();
|
throw new PDOMNotImplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new ArrayTypeClone(this);
|
return new ArrayTypeClone(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void delete(PDOMLinkage linkage) throws CoreException {
|
public void delete(PDOMLinkage linkage) throws CoreException {
|
||||||
linkage.deleteType(getType(), record);
|
linkage.deleteType(getType(), record);
|
||||||
super.delete(linkage);
|
super.delete(linkage);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||||
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBindingComparator;
|
||||||
|
@ -81,6 +82,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
|
||||||
&& db.getInt(record + FIRST_REF_OFFSET) == 0;
|
&& db.getInt(record + FIRST_REF_OFFSET) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getRecord() {
|
public int getRecord() {
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
@ -174,13 +176,14 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
|
||||||
return ""; //$NON-NLS-1$
|
return ""; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public char[] getNameCharArray() {
|
public char[] getNameCharArray() {
|
||||||
try {
|
try {
|
||||||
return super.getNameCharArray();
|
return super.getNameCharArray();
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
return new char[0];
|
return CharArrayUtils.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexScope getParent() {
|
public IIndexScope getParent() {
|
||||||
|
@ -219,12 +222,14 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
|
||||||
return pdom;
|
return pdom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
abstract protected int getRecordSize(); // superclass's implementation is no longer valid
|
abstract protected int getRecordSize(); // superclass's implementation is no longer valid
|
||||||
|
|
||||||
/* For debug purposes only
|
/* For debug purposes only
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
try {
|
||||||
return getName() + " " + getConstantNameForValue(getLinkageImpl(), getNodeType()); //$NON-NLS-1$
|
return getName() + " " + getConstantNameForValue(getLinkageImpl(), getNodeType()); //$NON-NLS-1$
|
||||||
|
@ -381,6 +386,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
|
||||||
public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
|
public void update(PDOMLinkage linkage, IBinding newBinding) throws CoreException {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
final public void delete(PDOMLinkage linkage) throws CoreException {
|
final public void delete(PDOMLinkage linkage) throws CoreException {
|
||||||
assert false;
|
assert false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import org.eclipse.cdt.core.dom.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMNode;
|
import org.eclipse.cdt.core.dom.IPDOMNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IParameter;
|
import org.eclipse.cdt.core.dom.ast.IParameter;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
|
@ -30,12 +32,13 @@ import org.eclipse.cdt.core.index.IIndexInclude;
|
||||||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.Linkage;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
|
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
|
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
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.BTree;
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
|
||||||
|
@ -53,6 +56,7 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
private final PDOM pdom;
|
private final PDOM pdom;
|
||||||
private final int record;
|
private final int record;
|
||||||
private IIndexFileLocation location;
|
private IIndexFileLocation location;
|
||||||
|
private PDOMLinkage fLinkage;
|
||||||
|
|
||||||
private static final int FIRST_NAME = 0;
|
private static final int FIRST_NAME = 0;
|
||||||
private static final int FIRST_INCLUDE = 4;
|
private static final int FIRST_INCLUDE = 4;
|
||||||
|
@ -63,8 +67,9 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
private static final int TIME_STAMP = 24;
|
private static final int TIME_STAMP = 24;
|
||||||
private static final int SCANNER_CONFIG_HASH= 32;
|
private static final int SCANNER_CONFIG_HASH= 32;
|
||||||
private static final int FIRST_USING_DIRECTIVE= 36;
|
private static final int FIRST_USING_DIRECTIVE= 36;
|
||||||
|
private static final int FIRST_MACRO_REFERENCE= 40;
|
||||||
|
|
||||||
private static final int RECORD_SIZE= 40;
|
private static final int RECORD_SIZE= 44;
|
||||||
|
|
||||||
public static class Comparator implements IBTreeComparator {
|
public static class Comparator implements IBTreeComparator {
|
||||||
private Database db;
|
private Database db;
|
||||||
|
@ -167,16 +172,26 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
db.putInt(record + SCANNER_CONFIG_HASH, hashcode);
|
db.putInt(record + SCANNER_CONFIG_HASH, hashcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMName getFirstName() throws CoreException {
|
private PDOMName getFirstName() throws CoreException {
|
||||||
int namerec = pdom.getDB().getInt(record + FIRST_NAME);
|
int namerec = pdom.getDB().getInt(record + FIRST_NAME);
|
||||||
return namerec != 0 ? new PDOMName(pdom, namerec) : null;
|
return namerec != 0 ? new PDOMName(pdom, namerec) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstName(PDOMName firstName) throws CoreException {
|
private void setFirstName(PDOMName firstName) throws CoreException {
|
||||||
int namerec = firstName != null ? firstName.getRecord() : 0;
|
int namerec = firstName != null ? firstName.getRecord() : 0;
|
||||||
pdom.getDB().putInt(record + FIRST_NAME, namerec);
|
pdom.getDB().putInt(record + FIRST_NAME, namerec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PDOMMacroReferenceName getFirstMacroReference() throws CoreException {
|
||||||
|
int namerec = pdom.getDB().getInt(record + FIRST_MACRO_REFERENCE);
|
||||||
|
return namerec != 0 ? new PDOMMacroReferenceName(pdom, namerec) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFirstMacroReference(PDOMMacroReferenceName firstName) throws CoreException {
|
||||||
|
int namerec = firstName != null ? firstName.getRecord() : 0;
|
||||||
|
pdom.getDB().putInt(record + FIRST_MACRO_REFERENCE, namerec);
|
||||||
|
}
|
||||||
|
|
||||||
public PDOMInclude getFirstInclude() throws CoreException {
|
public PDOMInclude getFirstInclude() throws CoreException {
|
||||||
int increc = pdom.getDB().getInt(record + FIRST_INCLUDE);
|
int increc = pdom.getDB().getInt(record + FIRST_INCLUDE);
|
||||||
return increc != 0 ? new PDOMInclude(pdom, increc) : null;
|
return increc != 0 ? new PDOMInclude(pdom, increc) : null;
|
||||||
|
@ -215,9 +230,11 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
assert getFirstMacro() == null;
|
assert getFirstMacro() == null;
|
||||||
|
|
||||||
PDOMMacro lastMacro= null;
|
PDOMMacro lastMacro= null;
|
||||||
|
final PDOMLinkage linkage = getLinkage();
|
||||||
for (int i = 0; i < macros.length; i++) {
|
for (int i = 0; i < macros.length; i++) {
|
||||||
IASTPreprocessorMacroDefinition macro = macros[i];
|
IASTPreprocessorMacroDefinition macro = macros[i];
|
||||||
PDOMMacro pdomMacro = new PDOMMacro(pdom, macro, this);
|
PDOMMacroContainer container= linkage.getMacroContainer(macro.getName().toCharArray());
|
||||||
|
PDOMMacro pdomMacro = new PDOMMacro(pdom, container, macro, this);
|
||||||
if (lastMacro == null) {
|
if (lastMacro == null) {
|
||||||
setFirstMacro(pdomMacro);
|
setFirstMacro(pdomMacro);
|
||||||
}
|
}
|
||||||
|
@ -225,20 +242,34 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
lastMacro.setNextMacro(pdomMacro);
|
lastMacro.setNextMacro(pdomMacro);
|
||||||
}
|
}
|
||||||
lastMacro= pdomMacro;
|
lastMacro= pdomMacro;
|
||||||
pdom.afterAddMacro(pdomMacro);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PDOMLinkage getLinkage() throws CoreException {
|
||||||
|
if (fLinkage == null) {
|
||||||
|
final String linkageName = Linkage.getLinkageName(getLinkageID());
|
||||||
|
fLinkage= pdom.createLinkage(linkageName);
|
||||||
|
if (fLinkage == null) {
|
||||||
|
throw new CoreException(CCorePlugin.createStatus("Unsupported linkage: " + linkageName)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fLinkage;
|
||||||
|
}
|
||||||
|
|
||||||
public void addNames(IASTName[][] names) throws CoreException {
|
public void addNames(IASTName[][] names) throws CoreException {
|
||||||
assert getFirstName() == null;
|
assert getFirstName() == null;
|
||||||
|
assert getFirstMacroReference() == null;
|
||||||
|
final PDOMLinkage linkage= getLinkage();
|
||||||
HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>();
|
HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>();
|
||||||
PDOMName lastName= null;
|
PDOMName lastName= null;
|
||||||
|
PDOMMacroReferenceName lastMacroName= null;
|
||||||
for (int i = 0; i < names.length; i++) {
|
for (int i = 0; i < names.length; i++) {
|
||||||
IASTName[] name = names[i];
|
IASTName[] name = names[i];
|
||||||
if (name[0] != null) {
|
if (name[0] != null) {
|
||||||
PDOMName caller= nameCache.get(name[1]);
|
PDOMName caller= nameCache.get(name[1]);
|
||||||
PDOMName pdomName = createPDOMName(name[0], caller);
|
IIndexFragmentName fname= createPDOMName(linkage, name[0], caller);
|
||||||
if (pdomName != null) {
|
if (fname instanceof PDOMName) {
|
||||||
|
PDOMName pdomName = (PDOMName) fname;
|
||||||
nameCache.put(name[0], pdomName);
|
nameCache.put(name[0], pdomName);
|
||||||
if (lastName == null) {
|
if (lastName == null) {
|
||||||
setFirstName(pdomName);
|
setFirstName(pdomName);
|
||||||
|
@ -248,25 +279,46 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
}
|
}
|
||||||
lastName= pdomName;
|
lastName= pdomName;
|
||||||
}
|
}
|
||||||
|
else if (fname instanceof PDOMMacroReferenceName) {
|
||||||
|
PDOMMacroReferenceName macroName = (PDOMMacroReferenceName) fname;
|
||||||
|
if (lastMacroName == null) {
|
||||||
|
setFirstMacroReference(macroName);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lastMacroName.setNextInFile(macroName);
|
||||||
|
}
|
||||||
|
lastMacroName= macroName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PDOMName createPDOMName(IASTName name, PDOMName caller) {
|
private IIndexFragmentName createPDOMName(PDOMLinkage linkage, IASTName name, PDOMName caller) {
|
||||||
if (name.getBinding() instanceof IParameter) {
|
final IBinding binding = name.getBinding();
|
||||||
|
if (binding instanceof IParameter) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
PDOMName result= null;
|
|
||||||
try {
|
try {
|
||||||
PDOMBinding binding = ((WritablePDOM) pdom).addBinding(name);
|
if (binding instanceof IMacroBinding) {
|
||||||
if (binding != null) {
|
return createPDOMMacroReferenceName(linkage, name);
|
||||||
result= new PDOMName(pdom, name, this, binding, caller);
|
}
|
||||||
binding.getLinkageImpl().onCreateName(this, name, result);
|
else {
|
||||||
|
PDOMBinding pdomBinding = linkage.addBinding(name);
|
||||||
|
if (pdomBinding != null) {
|
||||||
|
final PDOMName result= new PDOMName(pdom, name, this, pdomBinding, caller);
|
||||||
|
linkage.onCreateName(this, name, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
return result;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IIndexFragmentName createPDOMMacroReferenceName(PDOMLinkage linkage, IASTName name) throws CoreException {
|
||||||
|
PDOMMacroContainer cont= linkage.getMacroContainer(name.toCharArray());
|
||||||
|
return new PDOMMacroReferenceName(pdom, name, this, cont);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear(Collection<IIndexFileLocation> contextsRemoved) throws CoreException {
|
public void clear(Collection<IIndexFileLocation> contextsRemoved) throws CoreException {
|
||||||
|
@ -293,7 +345,6 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
// Delete all the macros in this file
|
// Delete all the macros in this file
|
||||||
PDOMMacro macro = getFirstMacro();
|
PDOMMacro macro = getFirstMacro();
|
||||||
while (macro != null) {
|
while (macro != null) {
|
||||||
pdom.beforeRemoveMacro(macro);
|
|
||||||
PDOMMacro nextMacro = macro.getNextMacro();
|
PDOMMacro nextMacro = macro.getNextMacro();
|
||||||
macro.delete();
|
macro.delete();
|
||||||
macro = nextMacro;
|
macro = nextMacro;
|
||||||
|
@ -301,19 +352,32 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
setFirstMacro(null);
|
setFirstMacro(null);
|
||||||
|
|
||||||
// Delete all the names in this file
|
// Delete all the names in this file
|
||||||
|
PDOMLinkage linkage= getLinkage();
|
||||||
ArrayList<PDOMName> names= new ArrayList<PDOMName>();
|
ArrayList<PDOMName> names= new ArrayList<PDOMName>();
|
||||||
PDOMName name = getFirstName();
|
PDOMName name = getFirstName();
|
||||||
while (name != null) {
|
while (name != null) {
|
||||||
names.add(name);
|
names.add(name);
|
||||||
name.getBinding().getLinkageImpl().onDeleteName(name);
|
linkage.onDeleteName(name);
|
||||||
name= name.getNextInFile();
|
name= name.getNextInFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Iterator<PDOMName> iterator = names.iterator(); iterator.hasNext();) {
|
for (Iterator<PDOMName> iterator = names.iterator(); iterator.hasNext();) {
|
||||||
name = iterator.next();
|
name = iterator.next();
|
||||||
name.delete();
|
name.delete();
|
||||||
}
|
}
|
||||||
setFirstName(null);
|
setFirstName(null);
|
||||||
|
|
||||||
|
// Delete all macro references
|
||||||
|
ArrayList<PDOMMacroReferenceName> mrefs= new ArrayList<PDOMMacroReferenceName>();
|
||||||
|
PDOMMacroReferenceName mref = getFirstMacroReference();
|
||||||
|
while (mref != null) {
|
||||||
|
mrefs.add(mref);
|
||||||
|
mref= mref.getNextInFile();
|
||||||
|
}
|
||||||
|
for (PDOMMacroReferenceName m : mrefs) {
|
||||||
|
m.delete();
|
||||||
|
}
|
||||||
|
setFirstMacroReference(null);
|
||||||
|
|
||||||
setTimestamp(-1);
|
setTimestamp(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,7 +452,7 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexName[] findNames(int offset, int length) throws CoreException {
|
public IIndexName[] findNames(int offset, int length) throws CoreException {
|
||||||
ArrayList<PDOMName> result= new ArrayList<PDOMName>();
|
ArrayList<IIndexName> result= new ArrayList<IIndexName>();
|
||||||
for (PDOMName name= getFirstName(); name != null; name= name.getNextInFile()) {
|
for (PDOMName name= getFirstName(); name != null; name= name.getNextInFile()) {
|
||||||
int nameOffset= name.getNodeOffset();
|
int nameOffset= name.getNodeOffset();
|
||||||
if (nameOffset >= offset) {
|
if (nameOffset >= offset) {
|
||||||
|
@ -403,6 +467,28 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
for (PDOMMacro name= getFirstMacro(); name != null; name= name.getNextMacro()) {
|
||||||
|
int nameOffset= name.getNodeOffset();
|
||||||
|
if (nameOffset >= offset) {
|
||||||
|
if (nameOffset + name.getNodeLength() <= offset+length) {
|
||||||
|
result.add(name.getDefinition());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (PDOMMacroReferenceName name= getFirstMacroReference(); name != null; name= name.getNextInFile()) {
|
||||||
|
int nameOffset= name.getNodeOffset();
|
||||||
|
if (nameOffset >= offset) {
|
||||||
|
if (nameOffset + name.getNodeLength() <= offset+length) {
|
||||||
|
result.add(name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return result.toArray(new IIndexName[result.size()]);
|
return result.toArray(new IIndexName[result.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,13 +57,16 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
private static final int NEXT_OFFSET = PDOMNamedNode.RECORD_SIZE + 4;
|
private static final int NEXT_OFFSET = PDOMNamedNode.RECORD_SIZE + 4;
|
||||||
private static final int INDEX_OFFSET = PDOMNamedNode.RECORD_SIZE + 8;
|
private static final int INDEX_OFFSET = PDOMNamedNode.RECORD_SIZE + 8;
|
||||||
private static final int NESTED_BINDINGS_INDEX = PDOMNamedNode.RECORD_SIZE + 12;
|
private static final int NESTED_BINDINGS_INDEX = PDOMNamedNode.RECORD_SIZE + 12;
|
||||||
|
private static final int MACRO_BTREE = PDOMNamedNode.RECORD_SIZE + 16;
|
||||||
|
|
||||||
@SuppressWarnings("hiding")
|
@SuppressWarnings("hiding")
|
||||||
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 16;
|
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 20;
|
||||||
|
|
||||||
// node types
|
// node types
|
||||||
protected static final int LINKAGE= 0; // special one for myself
|
protected static final int LINKAGE= 0; // special one for myself
|
||||||
|
|
||||||
|
private BTree fMacroIndex= null;
|
||||||
|
|
||||||
public PDOMLinkage(PDOM pdom, int record) {
|
public PDOMLinkage(PDOM pdom, int record) {
|
||||||
super(pdom, record);
|
super(pdom, record);
|
||||||
}
|
}
|
||||||
|
@ -78,10 +81,12 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
pdom.insertLinkage(this);
|
pdom.insertLinkage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int getRecordSize() {
|
protected int getRecordSize() {
|
||||||
return RECORD_SIZE;
|
return RECORD_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getNodeType() {
|
public int getNodeType() {
|
||||||
return LINKAGE;
|
return LINKAGE;
|
||||||
}
|
}
|
||||||
|
@ -113,6 +118,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
return new BTree(getPDOM().getDB(), record + NESTED_BINDINGS_INDEX, getNestedBindingsComparator());
|
return new BTree(getPDOM().getDB(), record + NESTED_BINDINGS_INDEX, getNestedBindingsComparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
||||||
if (visitor instanceof IBTreeVisitor) {
|
if (visitor instanceof IBTreeVisitor) {
|
||||||
getIndex().accept((IBTreeVisitor) visitor);
|
getIndex().accept((IBTreeVisitor) visitor);
|
||||||
|
@ -134,10 +140,12 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ILinkage getLinkage() throws CoreException {
|
public ILinkage getLinkage() throws CoreException {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final void addChild(PDOMNode child) throws CoreException {
|
public final void addChild(PDOMNode child) throws CoreException {
|
||||||
getIndex().insert(child.getRecord());
|
getIndex().insert(child.getRecord());
|
||||||
}
|
}
|
||||||
|
@ -213,14 +221,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
|
|
||||||
protected abstract PDOMBinding doAdaptBinding(IBinding binding) throws CoreException;
|
protected abstract PDOMBinding doAdaptBinding(IBinding binding) throws CoreException;
|
||||||
|
|
||||||
public final PDOMBinding resolveBinding(IASTName name) throws CoreException {
|
|
||||||
IBinding binding= name.resolveBinding();
|
|
||||||
if (binding != null) {
|
|
||||||
return adaptBinding(binding);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final protected int getLocalToFileRec(PDOMNode parent, IBinding binding) throws CoreException {
|
final protected int getLocalToFileRec(PDOMNode parent, IBinding binding) throws CoreException {
|
||||||
int rec= 0;
|
int rec= 0;
|
||||||
if (parent instanceof PDOMBinding) {
|
if (parent instanceof PDOMBinding) {
|
||||||
|
@ -341,6 +341,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
// no implementation, yet.
|
// no implementation, yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void delete(PDOMLinkage linkage) throws CoreException {
|
public void delete(PDOMLinkage linkage) throws CoreException {
|
||||||
assert false; // no need to delete linkages.
|
assert false; // no need to delete linkages.
|
||||||
}
|
}
|
||||||
|
@ -348,4 +349,48 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
|
||||||
public ICPPUsingDirective[] getUsingDirectives(PDOMFile file) throws CoreException {
|
public ICPPUsingDirective[] getUsingDirectives(PDOMFile file) throws CoreException {
|
||||||
return ICPPUsingDirective.EMPTY_ARRAY;
|
return ICPPUsingDirective.EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BTree getMacroIndex() {
|
||||||
|
if (fMacroIndex == null) {
|
||||||
|
fMacroIndex= new BTree(pdom.getDB(), record + MACRO_BTREE, new FindBinding.MacroBTreeComparator(pdom));
|
||||||
|
}
|
||||||
|
return fMacroIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMMacroContainer findMacroContainer(final char[] name) throws CoreException {
|
||||||
|
return findMacroContainer(name, pdom.createKeyForCache(record, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
private PDOMMacroContainer findMacroContainer(final char[] name, final String key) throws CoreException {
|
||||||
|
Object result= pdom.getCachedResult(key);
|
||||||
|
if (result instanceof PDOMMacroContainer) {
|
||||||
|
return ((PDOMMacroContainer) result);
|
||||||
|
}
|
||||||
|
assert result==null;
|
||||||
|
|
||||||
|
MacroContainerFinder visitor = new MacroContainerFinder(pdom, name);
|
||||||
|
getMacroIndex().accept(visitor);
|
||||||
|
PDOMMacroContainer container= visitor.getMacroContainer();
|
||||||
|
if (container != null) {
|
||||||
|
pdom.putCachedResult(key, container);
|
||||||
|
}
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMMacroContainer getMacroContainer(char[] name) throws CoreException {
|
||||||
|
String key= pdom.createKeyForCache(record, name);
|
||||||
|
PDOMMacroContainer result= findMacroContainer(name, key);
|
||||||
|
if (result == null) {
|
||||||
|
result= new PDOMMacroContainer(pdom, this, name);
|
||||||
|
getMacroIndex().insert(result.getRecord());
|
||||||
|
pdom.putCachedResult(key, result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeMacroContainer (PDOMMacroContainer container) throws CoreException {
|
||||||
|
String key= pdom.createKeyForCache(record, container.getNameCharArray());
|
||||||
|
pdom.putCachedResult(key, null);
|
||||||
|
getMacroIndex().delete(container.getRecord());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,17 +19,19 @@ import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.ILinkage;
|
import org.eclipse.cdt.core.dom.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
|
||||||
import org.eclipse.cdt.core.index.IIndexFile;
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
import org.eclipse.cdt.core.index.IIndexMacro;
|
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||||
import org.eclipse.cdt.core.parser.Keywords;
|
import org.eclipse.cdt.core.parser.Keywords;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner.MacroDefinitionParser;
|
import org.eclipse.cdt.internal.core.parser.scanner.MacroDefinitionParser;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||||
|
@ -37,99 +39,121 @@ import org.eclipse.cdt.internal.core.pdom.db.IString;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents macros.
|
* Represents macro definitions. They are stored with the file and with a PDOMMacroContainer. The latter also
|
||||||
*
|
* contains the references to all macros with the same name.
|
||||||
* @author Doug Schaefer
|
|
||||||
*/
|
*/
|
||||||
public class PDOMMacro implements IIndexMacro, IASTFileLocation {
|
public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLocation {
|
||||||
|
|
||||||
private static final byte MACROSTYLE_OBJECT = 1;
|
private static final int CONTAINER = 0;
|
||||||
private static final byte MACROSTYLE_FUNCTION= 2;
|
|
||||||
|
|
||||||
private static final int NAME = 0;
|
|
||||||
private static final int FILE = 4;
|
private static final int FILE = 4;
|
||||||
private static final int NAME_OFFSET = 8;
|
private static final int PARAMETERS= 8;
|
||||||
private static final int NAME_LENGTH = 12; // short
|
private static final int EXPANSION = 12;
|
||||||
private static final int FIRST_PARAMETER = 14;
|
private static final int NEXT_IN_FILE = 16;
|
||||||
private static final int EXPANSION = 18;
|
private static final int NEXT_IN_CONTAINER = 20;
|
||||||
private static final int NEXT_MACRO = 22;
|
private static final int PREV_IN_CONTAINER = 24;
|
||||||
private static final int MACRO_STYLE = 26; // byte
|
private static final int NAME_OFFSET = 28;
|
||||||
|
private static final int NAME_LENGTH = 32; // short
|
||||||
|
|
||||||
private static final int RECORD_SIZE = 27;
|
private static final int RECORD_SIZE = 34;
|
||||||
private static final char[][] UNINITIALIZED= {};
|
private static final char[][] UNINITIALIZED= {};
|
||||||
|
|
||||||
private final PDOM pdom;
|
private final PDOM fPDOM;
|
||||||
private final int record;
|
private final int fRecord;
|
||||||
|
|
||||||
private char[][] fParameterList= UNINITIALIZED;
|
private char[][] fParameterList= UNINITIALIZED;
|
||||||
private char[] fName;
|
|
||||||
private char[] fExpansion;
|
private char[] fExpansion;
|
||||||
|
private PDOMMacroContainer fContainer;
|
||||||
|
private PDOMMacroDefinitionName fDefinition;
|
||||||
|
|
||||||
public PDOMMacro(PDOM pdom, int record) {
|
public PDOMMacro(PDOM pdom, int record) {
|
||||||
this.pdom = pdom;
|
fPDOM = pdom;
|
||||||
this.record = record;
|
fRecord = record;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PDOMMacro(PDOM pdom, IASTPreprocessorMacroDefinition macro, PDOMFile file) throws CoreException {
|
public PDOMMacro(PDOM pdom, PDOMMacroContainer container, IASTPreprocessorMacroDefinition macro, PDOMFile file) throws CoreException {
|
||||||
this.pdom = pdom;
|
final Database db= pdom.getDB();
|
||||||
|
|
||||||
Database db = pdom.getDB();
|
fPDOM = pdom;
|
||||||
this.record = db.malloc(RECORD_SIZE);
|
fRecord = db.malloc(RECORD_SIZE);
|
||||||
IASTName name = macro.getName();
|
fContainer= container;
|
||||||
IMacroBinding binding= (IMacroBinding) name.getBinding();
|
|
||||||
|
|
||||||
db.putInt(record + NAME, db.newString(name.toCharArray()).getRecord());
|
final IASTName name = macro.getName();
|
||||||
db.putInt(record + FILE, file.getRecord());
|
final IASTFileLocation fileloc = name.getFileLocation();
|
||||||
IASTFileLocation fileloc = name.getFileLocation();
|
final IMacroBinding binding= (IMacroBinding) name.getBinding();
|
||||||
db.putInt(record + NAME_OFFSET, fileloc.getNodeOffset());
|
final char[][] params= binding.getParameterList();
|
||||||
db.putShort(record + NAME_LENGTH, (short) fileloc.getNodeLength());
|
|
||||||
db.putInt(record + EXPANSION, db.newString(binding.getExpansionImage()).getRecord());
|
db.putInt(fRecord + CONTAINER, container.getRecord());
|
||||||
setNextMacro(0);
|
db.putInt(fRecord + FILE, file.getRecord());
|
||||||
|
db.putInt(fRecord + EXPANSION, db.newString(binding.getExpansionImage()).getRecord());
|
||||||
|
db.putInt(fRecord + NAME_OFFSET, fileloc.getNodeOffset());
|
||||||
|
db.putShort(fRecord + NAME_LENGTH, (short) fileloc.getNodeLength());
|
||||||
|
|
||||||
byte macroStyle= MACROSTYLE_OBJECT;
|
|
||||||
PDOMMacroParameter last = null;
|
|
||||||
char[][] params= binding.getParameterList();
|
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
macroStyle= MACROSTYLE_FUNCTION;
|
StringBuilder buf= new StringBuilder();
|
||||||
for (int i = params.length - 1; i >= 0; --i) {
|
for (int i= 0; i < params.length; i++) {
|
||||||
PDOMMacroParameter pdomParam = new PDOMMacroParameter(pdom, params[i]);
|
buf.append(params[i]);
|
||||||
if (last != null)
|
buf.append(',');
|
||||||
pdomParam.setNextParameter(last);
|
|
||||||
last = pdomParam;
|
|
||||||
}
|
}
|
||||||
|
db.putInt(fRecord + PARAMETERS, db.newString(buf.toString().toCharArray()).getRecord());
|
||||||
}
|
}
|
||||||
db.putInt(record + FIRST_PARAMETER, last != null ? last.getRecord() : 0);
|
|
||||||
db.putByte(record + MACRO_STYLE, macroStyle);
|
fContainer.addDefinition(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOM getPDOM() {
|
||||||
|
return fPDOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRecord() {
|
public int getRecord() {
|
||||||
return record;
|
return fRecord;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() throws CoreException {
|
public void delete() throws CoreException {
|
||||||
getNameInDB(pdom, record).delete();
|
// Delete from the binding chain
|
||||||
|
PDOMMacro prevName = getPrevInContainer();
|
||||||
|
PDOMMacro nextName = getNextInContainer();
|
||||||
|
if (prevName != null)
|
||||||
|
prevName.setNextInContainer(nextName);
|
||||||
|
else {
|
||||||
|
PDOMMacroContainer container= getContainer();
|
||||||
|
container.setFirstDefinition(nextName);
|
||||||
|
if (nextName == null && container.isOrphaned()) {
|
||||||
|
container.delete(container.getLinkageImpl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nextName != null)
|
||||||
|
nextName.setPrevInContainer(prevName);
|
||||||
|
|
||||||
|
|
||||||
getExpansionInDB().delete();
|
getExpansionInDB().delete();
|
||||||
PDOMMacroParameter param = getFirstParameter();
|
final IString params = getParamListInDB();
|
||||||
if (param != null)
|
if (params != null) {
|
||||||
param.delete();
|
params.delete();
|
||||||
pdom.getDB().free(record);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IString getNameInDB(PDOM pdom, int record) throws CoreException {
|
public PDOMMacroContainer getContainer() throws CoreException {
|
||||||
Database db = pdom.getDB();
|
if (fContainer == null) {
|
||||||
int rec = db.getInt(record + NAME);
|
fContainer= new PDOMMacroContainer(fPDOM, fPDOM.getDB().getInt(fRecord + CONTAINER));
|
||||||
return db.getString(rec);
|
}
|
||||||
|
return fContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IString getExpansionInDB() throws CoreException {
|
private IString getExpansionInDB() throws CoreException {
|
||||||
Database db = pdom.getDB();
|
Database db = fPDOM.getDB();
|
||||||
int rec = db.getInt(record + EXPANSION);
|
int rec = db.getInt(fRecord + EXPANSION);
|
||||||
return db.getString(rec);
|
return db.getString(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IString getParamListInDB() throws CoreException {
|
||||||
|
Database db = fPDOM.getDB();
|
||||||
|
int rec = db.getInt(fRecord + PARAMETERS);
|
||||||
|
return rec == 0 ? null : db.getString(rec);
|
||||||
|
}
|
||||||
|
|
||||||
public PDOMMacro getNextMacro() throws CoreException {
|
public PDOMMacro getNextMacro() throws CoreException {
|
||||||
int rec = pdom.getDB().getInt(record + NEXT_MACRO);
|
int rec = fPDOM.getDB().getInt(fRecord + NEXT_IN_FILE);
|
||||||
return rec != 0 ? new PDOMMacro(pdom, rec) : null;
|
return rec != 0 ? new PDOMMacro(fPDOM, rec) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNextMacro(PDOMMacro macro) throws CoreException {
|
public void setNextMacro(PDOMMacro macro) throws CoreException {
|
||||||
|
@ -137,25 +161,50 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNextMacro(int rec) throws CoreException {
|
private void setNextMacro(int rec) throws CoreException {
|
||||||
pdom.getDB().putInt(record + NEXT_MACRO, rec);
|
fPDOM.getDB().putInt(fRecord + NEXT_IN_FILE, rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PDOMMacroParameter getFirstParameter() throws CoreException {
|
private PDOMMacro getPrevInContainer() throws CoreException {
|
||||||
int rec = pdom.getDB().getInt(record + FIRST_PARAMETER);
|
return getMacroField(PREV_IN_CONTAINER);
|
||||||
return rec != 0 ? new PDOMMacroParameter(pdom, rec) : null;
|
}
|
||||||
|
|
||||||
|
void setPrevInContainer(PDOMMacro macro) throws CoreException {
|
||||||
|
setMacroField(PREV_IN_CONTAINER, macro);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMMacro getNextInContainer() throws CoreException {
|
||||||
|
return getMacroField(NEXT_IN_CONTAINER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setNextInContainer(PDOMMacro macro) throws CoreException {
|
||||||
|
setMacroField(NEXT_IN_CONTAINER, macro);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMacroField(int offset, PDOMMacro macro) throws CoreException {
|
||||||
|
int namerec = macro != null ? macro.getRecord() : 0;
|
||||||
|
fPDOM.getDB().putInt(fRecord + offset, namerec);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PDOMMacro getMacroField(int offset) throws CoreException {
|
||||||
|
int namerec= fPDOM.getDB().getInt(fRecord + offset);
|
||||||
|
return namerec != 0 ? new PDOMMacro(fPDOM, namerec) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public char[][] getParameterList() {
|
public char[][] getParameterList() {
|
||||||
if (fParameterList == UNINITIALIZED) {
|
if (fParameterList == UNINITIALIZED) {
|
||||||
fParameterList= null;
|
fParameterList= null;
|
||||||
try {
|
try {
|
||||||
byte style= pdom.getDB().getByte(record + MACRO_STYLE);
|
IString plist= getParamListInDB();
|
||||||
if (style == MACROSTYLE_FUNCTION) {
|
if (plist != null) {
|
||||||
List<char[]> paramList = new ArrayList<char[]>();
|
List<char[]> paramList = new ArrayList<char[]>();
|
||||||
PDOMMacroParameter param= getFirstParameter();
|
final char[] cplist= plist.getChars();
|
||||||
while (param != null) {
|
final int end = cplist.length;
|
||||||
paramList.add(param.getName().getChars());
|
int from= 0;
|
||||||
param = param.getNextParameter();
|
int to= CharArrayUtils.indexOf(',', cplist, from, end);
|
||||||
|
while (to > from) {
|
||||||
|
paramList.add(CharArrayUtils.extract(cplist, from, to-from));
|
||||||
|
from= to+1;
|
||||||
|
to= CharArrayUtils.indexOf(',', cplist, from, end);
|
||||||
}
|
}
|
||||||
fParameterList= paramList.toArray(new char[paramList.size()][]);
|
fParameterList= paramList.toArray(new char[paramList.size()][]);
|
||||||
}
|
}
|
||||||
|
@ -179,24 +228,22 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
|
||||||
}
|
}
|
||||||
|
|
||||||
public char[] getNameCharArray() {
|
public char[] getNameCharArray() {
|
||||||
if (fName == null) {
|
|
||||||
try {
|
try {
|
||||||
fName= getNameInDB(pdom, record).getChars();
|
return getContainer().getNameCharArray();
|
||||||
} catch (CoreException e) {
|
}
|
||||||
|
catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
fName= new char[] { ' ' };
|
return new char[]{' '};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return new String(getNameCharArray());
|
return new String(getNameCharArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexFile getFile() throws CoreException {
|
public PDOMFile getFile() throws CoreException {
|
||||||
int filerec = pdom.getDB().getInt(record + FILE);
|
int filerec = fPDOM.getDB().getInt(fRecord + FILE);
|
||||||
return filerec != 0 ? new PDOMFile(pdom, filerec) : null;
|
return filerec != 0 ? new PDOMFile(fPDOM, filerec) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndingLineNumber() {
|
public int getEndingLineNumber() {
|
||||||
|
@ -205,7 +252,7 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
try {
|
try {
|
||||||
PDOMFile file = (PDOMFile) getFile();
|
PDOMFile file = getFile();
|
||||||
if(file!=null) {
|
if(file!=null) {
|
||||||
/*
|
/*
|
||||||
* We need to spec. what this method can return to know
|
* We need to spec. what this method can return to know
|
||||||
|
@ -236,7 +283,7 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
|
||||||
|
|
||||||
public int getNodeLength() {
|
public int getNodeLength() {
|
||||||
try {
|
try {
|
||||||
return pdom.getDB().getShort(record + NAME_LENGTH);
|
return fPDOM.getDB().getShort(fRecord + NAME_LENGTH);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -245,7 +292,7 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
|
||||||
|
|
||||||
public int getNodeOffset() {
|
public int getNodeOffset() {
|
||||||
try {
|
try {
|
||||||
return pdom.getDB().getInt(record + NAME_OFFSET);
|
return fPDOM.getDB().getInt(fRecord + NAME_OFFSET);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -281,15 +328,53 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILinkage getLinkage() throws CoreException {
|
public ILinkage getLinkage() throws CoreException {
|
||||||
return Linkage.NO_LINKAGE;
|
return getFile().getLinkage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IScope getScope() throws DOMException {
|
public IIndexScope getScope() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Object getAdapter(Class adapter) {
|
public Object getAdapter(Class adapter) {
|
||||||
|
if (adapter.isAssignableFrom(PDOMMacro.class)) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IIndexFragmentName getDefinition() {
|
||||||
|
if (fDefinition == null) {
|
||||||
|
fDefinition= new PDOMMacroDefinitionName(this);
|
||||||
|
}
|
||||||
|
return fDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexFile getLocalToFile() throws CoreException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getQualifiedName() {
|
||||||
|
return new String[]{getName()};
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFileLocal() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBindingConstant() {
|
||||||
|
return IIndexBindingConstants.MACRO_DEFINITION;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexFragment getFragment() {
|
||||||
|
return fPDOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasDeclaration() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasDefinition() throws CoreException {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,175 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexMacroContainer;
|
||||||
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexBindingConstants;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A container collecting definitions and references for macros.
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
|
public class PDOMMacroContainer extends PDOMNamedNode implements IIndexMacroContainer, IIndexFragmentBinding {
|
||||||
|
private static final int FIRST_DEF_OFFSET = PDOMNamedNode.RECORD_SIZE + 0; // size 4
|
||||||
|
private static final int FIRST_REF_OFFSET = PDOMNamedNode.RECORD_SIZE + 4; // size 4
|
||||||
|
|
||||||
|
@SuppressWarnings("hiding")
|
||||||
|
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 8;
|
||||||
|
|
||||||
|
public PDOMMacroContainer(PDOM pdom, PDOMLinkage linkage, char[] name) throws CoreException {
|
||||||
|
super(pdom, linkage, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
PDOMMacroContainer(PDOM pdom, int record) {
|
||||||
|
super(pdom, record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNodeType() {
|
||||||
|
return IIndexBindingConstants.MACRO_CONTAINER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getRecordSize() {
|
||||||
|
return RECORD_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOrphaned() throws CoreException {
|
||||||
|
Database db = pdom.getDB();
|
||||||
|
return db.getInt(record + FIRST_DEF_OFFSET) == 0
|
||||||
|
&& db.getInt(record + FIRST_REF_OFFSET) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDefinition(PDOMMacro name) throws CoreException {
|
||||||
|
PDOMMacro first = getFirstDefinition();
|
||||||
|
if (first != null) {
|
||||||
|
first.setPrevInContainer(name);
|
||||||
|
name.setNextInContainer(first);
|
||||||
|
}
|
||||||
|
setFirstDefinition(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addReference(PDOMMacroReferenceName name) throws CoreException {
|
||||||
|
PDOMMacroReferenceName first = getFirstReference();
|
||||||
|
if (first != null) {
|
||||||
|
first.setPrevInContainer(name);
|
||||||
|
name.setNextInContainer(first);
|
||||||
|
}
|
||||||
|
setFirstReference(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMMacro getFirstDefinition() throws CoreException {
|
||||||
|
int namerec = pdom.getDB().getInt(record + FIRST_DEF_OFFSET);
|
||||||
|
return namerec != 0 ? new PDOMMacro(pdom, namerec) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFirstDefinition(PDOMMacro macro) throws CoreException {
|
||||||
|
int namerec = macro != null ? macro.getRecord() : 0;
|
||||||
|
pdom.getDB().putInt(record + FIRST_DEF_OFFSET, namerec);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMMacroReferenceName getFirstReference() throws CoreException {
|
||||||
|
int namerec = pdom.getDB().getInt(record + FIRST_REF_OFFSET);
|
||||||
|
return namerec != 0 ? new PDOMMacroReferenceName(pdom, namerec) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFirstReference(PDOMMacroReferenceName nextName) throws CoreException {
|
||||||
|
int namerec = nextName != null ? nextName.getRecord() : 0;
|
||||||
|
pdom.getDB().putInt(record + FIRST_REF_OFFSET, namerec);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexMacro[] getDefinitions() throws CoreException {
|
||||||
|
PDOMMacro macro;
|
||||||
|
List<PDOMMacro> macros= new ArrayList<PDOMMacro>();
|
||||||
|
for (macro= getFirstDefinition(); macro != null; macro= macro.getNextInContainer()) {
|
||||||
|
macros.add(macro);
|
||||||
|
}
|
||||||
|
return macros.toArray(new IIndexMacro[macros.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(PDOMLinkage linkage) throws CoreException {
|
||||||
|
if (linkage != null) {
|
||||||
|
linkage.removeMacroContainer(this);
|
||||||
|
}
|
||||||
|
super.delete(linkage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBindingConstant() {
|
||||||
|
return IIndexBindingConstants.MACRO_CONTAINER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.internal.core.index.IIndexFragmentBinding#getFragment()
|
||||||
|
*/
|
||||||
|
public IIndexFragment getFragment() {
|
||||||
|
return pdom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexScope getScope() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasDeclaration() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasDefinition() throws CoreException {
|
||||||
|
return pdom.getDB().getInt(record + FIRST_DEF_OFFSET) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexFile getLocalToFile() throws CoreException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getQualifiedName() {
|
||||||
|
return new String[]{getName()};
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFileLocal() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char[] getNameCharArray() {
|
||||||
|
try {
|
||||||
|
return super.getNameCharArray();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
return CharArrayUtils.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return new String(getNameCharArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Object getAdapter(Class adapter) {
|
||||||
|
if (adapter.isAssignableFrom(PDOMMacroContainer.class)) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008 Wind River Systems, Inc. and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
class PDOMMacroDefinitionName implements IIndexFragmentName {
|
||||||
|
private final PDOMMacro fMacro;
|
||||||
|
|
||||||
|
PDOMMacroDefinitionName(PDOMMacro macro) {
|
||||||
|
fMacro = macro;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMMacro getMacro() {
|
||||||
|
return fMacro;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean couldBePolymorphicMethodCall() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public IIndexName[] getEnclosedNames() throws CoreException {
|
||||||
|
return IIndexName.EMPTY_ARRAY;
|
||||||
|
}
|
||||||
|
public IIndexName getEnclosingDefinition() throws CoreException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public IIndexFile getFile() throws CoreException {
|
||||||
|
return fMacro.getFile();
|
||||||
|
}
|
||||||
|
public int getNodeLength() {
|
||||||
|
return fMacro.getNodeLength();
|
||||||
|
}
|
||||||
|
public int getNodeOffset() {
|
||||||
|
return fMacro.getNodeOffset();
|
||||||
|
}
|
||||||
|
public boolean isBaseSpecifier() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public boolean isReadAccess() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public boolean isWriteAccess() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public IASTFileLocation getFileLocation() {
|
||||||
|
return fMacro;
|
||||||
|
}
|
||||||
|
public boolean isDeclaration() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public boolean isDefinition() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public boolean isReference() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public char[] toCharArray() {
|
||||||
|
return fMacro.getNameCharArray();
|
||||||
|
}
|
||||||
|
public IIndexFragmentBinding getBinding() {
|
||||||
|
return fMacro;
|
||||||
|
}
|
||||||
|
public IIndexFragment getIndexFragment() {
|
||||||
|
return fMacro.getFragment();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,76 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2006, 2008 QNX Software Systems and others.
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* QNX - Initial API and implementation
|
|
||||||
* Markus Schorn (Wind River Systems)
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.db.IString;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Doug Schaefer
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class PDOMMacroParameter {
|
|
||||||
|
|
||||||
private final PDOM pdom;
|
|
||||||
private final int record;
|
|
||||||
|
|
||||||
private static final int NEXT = 0;
|
|
||||||
private static final int NAME = 4;
|
|
||||||
|
|
||||||
private static final int RECORD_SIZE = 8;
|
|
||||||
|
|
||||||
public PDOMMacroParameter(PDOM pdom, int record) {
|
|
||||||
this.pdom = pdom;
|
|
||||||
this.record = record;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PDOMMacroParameter(PDOM pdom, char[] name) throws CoreException {
|
|
||||||
Database db = pdom.getDB();
|
|
||||||
|
|
||||||
this.pdom = pdom;
|
|
||||||
this.record = db.malloc(RECORD_SIZE);
|
|
||||||
|
|
||||||
db.putInt(record + NEXT, 0);
|
|
||||||
db.putInt(record + NAME, db.newString(name).getRecord());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRecord() {
|
|
||||||
return record;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delete() throws CoreException {
|
|
||||||
PDOMMacroParameter next = getNextParameter();
|
|
||||||
if (next != null)
|
|
||||||
next.delete();
|
|
||||||
getName().delete();
|
|
||||||
pdom.getDB().free(record);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNextParameter(PDOMMacroParameter next) throws CoreException {
|
|
||||||
int rec = next != null ? next.getRecord() : 0;
|
|
||||||
pdom.getDB().putInt(record + NEXT, rec);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PDOMMacroParameter getNextParameter() throws CoreException {
|
|
||||||
int rec = pdom.getDB().getInt(record + NEXT);
|
|
||||||
return rec != 0 ? new PDOMMacroParameter(pdom, rec) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IString getName() throws CoreException {
|
|
||||||
Database db = pdom.getDB();
|
|
||||||
return db.getString(db.getInt(record + NAME));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,255 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* QNX - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.db.Database;
|
||||||
|
import org.eclipse.core.filesystem.EFS;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents declarations, definitions and references to bindings, except for macros.
|
||||||
|
*/
|
||||||
|
public final class PDOMMacroReferenceName implements IIndexFragmentName, IASTFileLocation {
|
||||||
|
|
||||||
|
private final PDOM pdom;
|
||||||
|
private final int record;
|
||||||
|
|
||||||
|
private static final int FILE_REC_OFFSET = 0;
|
||||||
|
private static final int FILE_NEXT_OFFSET = 4;
|
||||||
|
private static final int CONTAINER_REC_OFFSET = 8;
|
||||||
|
private static final int CONTAINER_PREV_OFFSET = 12;
|
||||||
|
private static final int CONTAINER_NEXT_OFFSET = 16;
|
||||||
|
private static final int NODE_OFFSET_OFFSET = 20;
|
||||||
|
private static final int NODE_LENGTH_OFFSET = 24;
|
||||||
|
|
||||||
|
private static final int RECORD_SIZE = 26;
|
||||||
|
|
||||||
|
public PDOMMacroReferenceName(PDOM pdom, IASTName name, PDOMFile file, PDOMMacroContainer container) throws CoreException {
|
||||||
|
this.pdom = pdom;
|
||||||
|
Database db = pdom.getDB();
|
||||||
|
record = db.malloc(RECORD_SIZE);
|
||||||
|
|
||||||
|
db.putInt(record + CONTAINER_REC_OFFSET, container.getRecord());
|
||||||
|
db.putInt(record + FILE_REC_OFFSET, file.getRecord());
|
||||||
|
|
||||||
|
// Record our location in the file
|
||||||
|
IASTFileLocation fileloc = name.getFileLocation();
|
||||||
|
db.putInt(record + NODE_OFFSET_OFFSET, fileloc.getNodeOffset());
|
||||||
|
db.putShort(record + NODE_LENGTH_OFFSET, (short) fileloc.getNodeLength());
|
||||||
|
container.addReference(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMMacroReferenceName(PDOM pdom, int nameRecord) {
|
||||||
|
this.pdom = pdom;
|
||||||
|
this.record = nameRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRecord() {
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getRecField(int offset) throws CoreException {
|
||||||
|
return pdom.getDB().getInt(record + offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRecField(int offset, int fieldrec) throws CoreException {
|
||||||
|
pdom.getDB().putInt(record + offset, fieldrec);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMMacroContainer getContainer() throws CoreException {
|
||||||
|
int bindingrec = getRecField(CONTAINER_REC_OFFSET);
|
||||||
|
return new PDOMMacroContainer(pdom, bindingrec);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PDOMMacroReferenceName getNameField(int offset) throws CoreException {
|
||||||
|
int namerec = getRecField(offset);
|
||||||
|
return namerec != 0 ? new PDOMMacroReferenceName(pdom, namerec) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNameField(int offset, PDOMMacroReferenceName name) throws CoreException {
|
||||||
|
int namerec = name != null ? name.getRecord() : 0;
|
||||||
|
setRecField(offset, namerec);
|
||||||
|
}
|
||||||
|
|
||||||
|
PDOMMacroReferenceName getPrevInContainer() throws CoreException {
|
||||||
|
return getNameField(CONTAINER_PREV_OFFSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPrevInContainer(PDOMMacroReferenceName name) throws CoreException {
|
||||||
|
setNameField(CONTAINER_PREV_OFFSET, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PDOMMacroReferenceName getNextInContainer() throws CoreException {
|
||||||
|
return getNameField(CONTAINER_NEXT_OFFSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setNextInContainer(PDOMMacroReferenceName name) throws CoreException {
|
||||||
|
setNameField(CONTAINER_NEXT_OFFSET, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexFile getFile() throws CoreException {
|
||||||
|
int filerec = pdom.getDB().getInt(record + FILE_REC_OFFSET);
|
||||||
|
return filerec != 0 ? new PDOMFile(pdom, filerec) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
PDOMMacroReferenceName getNextInFile() throws CoreException {
|
||||||
|
return getNameField(FILE_NEXT_OFFSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setNextInFile(PDOMMacroReferenceName name) throws CoreException {
|
||||||
|
setNameField(FILE_NEXT_OFFSET, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public char[] toCharArray() {
|
||||||
|
try {
|
||||||
|
return getContainer().getNameCharArray();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
return CharArrayUtils.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new String(toCharArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBaseSpecifier() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean couldBePolymorphicMethodCall() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReadAccess() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWriteAccess() throws CoreException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDeclaration() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReference() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDefinition() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IASTFileLocation getFileLocation() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
try {
|
||||||
|
PDOMFile file = (PDOMFile) getFile();
|
||||||
|
if(file!=null) {
|
||||||
|
/*
|
||||||
|
* We need to spec. what this method can return to know
|
||||||
|
* how to implement this. Existing implmentations return
|
||||||
|
* the absolute path, so here we attempt to do the same.
|
||||||
|
*/
|
||||||
|
URI uri = file.getLocation().getURI();
|
||||||
|
if ("file".equals(uri.getScheme())) //$NON-NLS-1$
|
||||||
|
return uri.getSchemeSpecificPart();
|
||||||
|
File f = EFS.getStore(uri).toLocalFile(0, null);
|
||||||
|
if( f != null )
|
||||||
|
return f.getAbsolutePath();
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartingLineNumber() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndingLineNumber() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IASTFileLocation asFileLocation() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNodeLength() {
|
||||||
|
try {
|
||||||
|
return (pdom.getDB().getShort(record + NODE_LENGTH_OFFSET)) & 0xffff;
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNodeOffset() {
|
||||||
|
try {
|
||||||
|
return pdom.getDB().getInt(record + NODE_OFFSET_OFFSET);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete() throws CoreException {
|
||||||
|
// Delete from the binding chain
|
||||||
|
PDOMMacroReferenceName prevName = getPrevInContainer();
|
||||||
|
PDOMMacroReferenceName nextName = getNextInContainer();
|
||||||
|
if (prevName != null)
|
||||||
|
prevName.setNextInContainer(nextName);
|
||||||
|
else {
|
||||||
|
getContainer().setFirstReference(nextName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextName != null)
|
||||||
|
nextName.setPrevInContainer(prevName);
|
||||||
|
|
||||||
|
// Delete our record
|
||||||
|
pdom.getDB().free(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexFragment getIndexFragment() {
|
||||||
|
return pdom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexName[] getEnclosedNames() throws CoreException {
|
||||||
|
return IIndexName.EMPTY_ARRAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexFragmentBinding getBinding() throws CoreException {
|
||||||
|
return getContainer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIndexName getEnclosingDefinition() throws CoreException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 QNX Software Systems and others.
|
* Copyright (c) 2006, 2008 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -32,8 +32,11 @@ public abstract class PDOMNamedNode extends PDOMNode {
|
||||||
/**
|
/**
|
||||||
* The size in bytes of a PDOMNamedNode record in the database.
|
* The size in bytes of a PDOMNamedNode record in the database.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("hiding")
|
||||||
protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
|
protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
|
||||||
|
|
||||||
|
private char[] fName;
|
||||||
|
|
||||||
public PDOMNamedNode(PDOM pdom, int record) {
|
public PDOMNamedNode(PDOM pdom, int record) {
|
||||||
super(pdom, record);
|
super(pdom, record);
|
||||||
}
|
}
|
||||||
|
@ -41,11 +44,13 @@ public abstract class PDOMNamedNode extends PDOMNode {
|
||||||
public PDOMNamedNode(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
|
public PDOMNamedNode(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
|
||||||
super(pdom, parent);
|
super(pdom, parent);
|
||||||
|
|
||||||
|
fName= name;
|
||||||
Database db = pdom.getDB();
|
Database db = pdom.getDB();
|
||||||
db.putInt(record + NAME,
|
db.putInt(record + NAME,
|
||||||
name != null ? db.newString(name).getRecord() : 0);
|
name != null ? db.newString(name).getRecord() : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
abstract protected int getRecordSize();
|
abstract protected int getRecordSize();
|
||||||
|
|
||||||
public IString getDBName() throws CoreException {
|
public IString getDBName() throws CoreException {
|
||||||
|
@ -61,13 +66,17 @@ public abstract class PDOMNamedNode extends PDOMNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public char[] getNameCharArray() throws CoreException {
|
public char[] getNameCharArray() throws CoreException {
|
||||||
return getDBName().getChars();
|
if (fName == null) {
|
||||||
|
fName= getDBName().getChars();
|
||||||
|
}
|
||||||
|
return fName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasName(char[] name) throws CoreException {
|
public boolean hasName(char[] name) throws CoreException {
|
||||||
return getDBName().equals(name);
|
return getDBName().equals(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void delete(PDOMLinkage linkage) throws CoreException {
|
public void delete(PDOMLinkage linkage) throws CoreException {
|
||||||
final Database db = pdom.getDB();
|
final Database db = pdom.getDB();
|
||||||
final int namerec= db.getInt(record + NAME);
|
final int namerec= db.getInt(record + NAME);
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.eclipse.cdt.core.index.export.IExportProjectProvider;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.LanguageManager;
|
import org.eclipse.cdt.core.model.LanguageManager;
|
||||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
||||||
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -87,9 +86,6 @@ public class GeneratePDOM implements ISafeRunnable {
|
||||||
exportedPDOM.setProperty(entry.getKey(), entry.getValue());
|
exportedPDOM.setProperty(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fake PDOM-version to that which can be safely read by the CDT-version
|
|
||||||
// (and following CDT-versions) released at that PDOM-version.
|
|
||||||
exportedPDOM.getDB().setVersion(PDOM.EARLIEST_FORWARD_COMPATIBLE_VERSION);
|
|
||||||
exportedPDOM.close();
|
exportedPDOM.close();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -31,6 +30,7 @@ public abstract class AbstractPDOMIndexer implements IPDOMIndexer {
|
||||||
fProperties.put(IndexerPreferences.KEY_FILES_TO_PARSE_UP_FRONT, ""); //$NON-NLS-1$
|
fProperties.put(IndexerPreferences.KEY_FILES_TO_PARSE_UP_FRONT, ""); //$NON-NLS-1$
|
||||||
fProperties.put(IndexerPreferences.KEY_SKIP_ALL_REFERENCES, String.valueOf(false));
|
fProperties.put(IndexerPreferences.KEY_SKIP_ALL_REFERENCES, String.valueOf(false));
|
||||||
fProperties.put(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES, String.valueOf(false));
|
fProperties.put(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES, String.valueOf(false));
|
||||||
|
fProperties.put(IndexerPreferences.KEY_SKIP_MACRO_REFERENCES, String.valueOf(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICProject getProject() {
|
public ICProject getProject() {
|
||||||
|
@ -46,8 +46,7 @@ public abstract class AbstractPDOMIndexer implements IPDOMIndexer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean needsToRebuildForProperties(Properties props) {
|
public boolean needsToRebuildForProperties(Properties props) {
|
||||||
for (Iterator i= fProperties.entrySet().iterator(); i.hasNext();) {
|
for (Map.Entry<Object,Object> entry : fProperties.entrySet()) {
|
||||||
Map.Entry entry = (Map.Entry) i.next();
|
|
||||||
String key = (String) entry.getKey();
|
String key = (String) entry.getKey();
|
||||||
String myval = (String) entry.getValue();
|
String myval = (String) entry.getValue();
|
||||||
|
|
||||||
|
@ -63,8 +62,7 @@ public abstract class AbstractPDOMIndexer implements IPDOMIndexer {
|
||||||
|
|
||||||
public void setProperties(Properties props) {
|
public void setProperties(Properties props) {
|
||||||
// only set relevant properties as initialized in the constructor
|
// only set relevant properties as initialized in the constructor
|
||||||
for (Iterator i= props.entrySet().iterator(); i.hasNext();) {
|
for (Map.Entry<Object,Object> entry : props.entrySet()) {
|
||||||
Map.Entry entry = (Map.Entry) i.next();
|
|
||||||
String key = (String) entry.getKey();
|
String key = (String) entry.getKey();
|
||||||
String val = (String) entry.getValue();
|
String val = (String) entry.getValue();
|
||||||
|
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -50,6 +49,7 @@ public class IndexerPreferences {
|
||||||
public static final String KEY_FILES_TO_PARSE_UP_FRONT= "filesToParseUpFront"; //$NON-NLS-1$
|
public static final String KEY_FILES_TO_PARSE_UP_FRONT= "filesToParseUpFront"; //$NON-NLS-1$
|
||||||
public static final String KEY_SKIP_ALL_REFERENCES= "skipReferences"; //$NON-NLS-1$
|
public static final String KEY_SKIP_ALL_REFERENCES= "skipReferences"; //$NON-NLS-1$
|
||||||
public static final String KEY_SKIP_TYPE_REFERENCES= "skipTypeReferences"; //$NON-NLS-1$
|
public static final String KEY_SKIP_TYPE_REFERENCES= "skipTypeReferences"; //$NON-NLS-1$
|
||||||
|
public static final String KEY_SKIP_MACRO_REFERENCES= "skipMacroReferences"; //$NON-NLS-1$
|
||||||
public static final String KEY_UPDATE_POLICY= "updatePolicy"; //$NON-NLS-1$
|
public static final String KEY_UPDATE_POLICY= "updatePolicy"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static final String KEY_INDEXER_PREFS_SCOPE = "preferenceScope"; //$NON-NLS-1$
|
private static final String KEY_INDEXER_PREFS_SCOPE = "preferenceScope"; //$NON-NLS-1$
|
||||||
|
@ -185,8 +185,7 @@ public class IndexerPreferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setProperties(Preferences prefs, Properties props) {
|
private static void setProperties(Preferences prefs, Properties props) {
|
||||||
for (Iterator i = props.entrySet().iterator(); i.hasNext();) {
|
for (Map.Entry<Object,Object> entry : props.entrySet()) {
|
||||||
Map.Entry entry = (Map.Entry) i.next();
|
|
||||||
String key = (String) entry.getKey();
|
String key = (String) entry.getKey();
|
||||||
String val = (String) entry.getValue();
|
String val = (String) entry.getValue();
|
||||||
prefs.put(key, val);
|
prefs.put(key, val);
|
||||||
|
@ -314,6 +313,7 @@ public class IndexerPreferences {
|
||||||
prefs.putBoolean(KEY_INDEX_ALL_FILES, false);
|
prefs.putBoolean(KEY_INDEX_ALL_FILES, false);
|
||||||
prefs.putBoolean(KEY_SKIP_ALL_REFERENCES, false);
|
prefs.putBoolean(KEY_SKIP_ALL_REFERENCES, false);
|
||||||
prefs.putBoolean(KEY_SKIP_TYPE_REFERENCES, false);
|
prefs.putBoolean(KEY_SKIP_TYPE_REFERENCES, false);
|
||||||
|
prefs.putBoolean(KEY_SKIP_MACRO_REFERENCES, false);
|
||||||
prefs.put(KEY_INDEX_IMPORT_LOCATION, DEFAULT_INDEX_IMPORT_LOCATION);
|
prefs.put(KEY_INDEX_IMPORT_LOCATION, DEFAULT_INDEX_IMPORT_LOCATION);
|
||||||
prefs.put(KEY_FILES_TO_PARSE_UP_FRONT, DEFAULT_FILES_TO_PARSE_UP_FRONT);
|
prefs.put(KEY_FILES_TO_PARSE_UP_FRONT, DEFAULT_FILES_TO_PARSE_UP_FRONT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,17 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
|
||||||
if (checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES)) {
|
if (checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES)) {
|
||||||
setSkipReferences(SKIP_ALL_REFERENCES);
|
setSkipReferences(SKIP_ALL_REFERENCES);
|
||||||
}
|
}
|
||||||
else if (checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES)) {
|
else {
|
||||||
setSkipReferences(SKIP_TYPE_REFERENCES);
|
int skipRefs= 0;
|
||||||
|
if (checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES)) {
|
||||||
|
skipRefs |= SKIP_TYPE_REFERENCES;
|
||||||
|
}
|
||||||
|
if (checkProperty(IndexerPreferences.KEY_SKIP_MACRO_REFERENCES)) {
|
||||||
|
skipRefs |= SKIP_MACRO_REFERENCES;
|
||||||
|
}
|
||||||
|
if (skipRefs != 0) {
|
||||||
|
setSkipReferences(skipRefs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (getIndexAllFiles()) {
|
if (getIndexAllFiles()) {
|
||||||
setIndexFilesWithoutBuildConfiguration(true);
|
setIndexFilesWithoutBuildConfiguration(true);
|
||||||
|
@ -236,11 +245,13 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
|
||||||
boolean allFiles= getIndexAllFiles();
|
boolean allFiles= getIndexAllFiles();
|
||||||
boolean skipRefs= checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES);
|
boolean skipRefs= checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES);
|
||||||
boolean skipTypeRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES);
|
boolean skipTypeRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES);
|
||||||
|
boolean skipMacroRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_MACRO_REFERENCES);
|
||||||
System.out.println(ident + " Options: " //$NON-NLS-1$
|
System.out.println(ident + " Options: " //$NON-NLS-1$
|
||||||
+ "indexer='" + kind //$NON-NLS-1$
|
+ "indexer='" + kind //$NON-NLS-1$
|
||||||
+ "', parseAllFiles=" + allFiles //$NON-NLS-1$
|
+ "', parseAllFiles=" + allFiles //$NON-NLS-1$
|
||||||
+ ", skipReferences=" + skipRefs //$NON-NLS-1$
|
+ ", skipReferences=" + skipRefs //$NON-NLS-1$
|
||||||
+ ", skipTypeReferences=" + skipTypeRefs //$NON-NLS-1$
|
+ ", skipTypeReferences=" + skipTypeRefs //$NON-NLS-1$
|
||||||
|
+ ", skipMacroReferences=" + skipMacroRefs //$NON-NLS-1$
|
||||||
+ "."); //$NON-NLS-1$
|
+ "."); //$NON-NLS-1$
|
||||||
System.out.println(ident + " Database: " + dbSize + " bytes"); //$NON-NLS-1$ //$NON-NLS-2$
|
System.out.println(ident + " Database: " + dbSize + " bytes"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
System.out.println(ident + " Timings: " //$NON-NLS-1$
|
System.out.println(ident + " Timings: " //$NON-NLS-1$
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
# Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
|
||||||
# All rights reserved. This program and the accompanying materials
|
# All rights reserved. This program and the accompanying materials
|
||||||
# are made available under the terms of the Eclipse Public License v1.0
|
# are made available under the terms of the Eclipse Public License v1.0
|
||||||
# which accompanies this distribution, and is available at
|
# which accompanies this distribution, and is available at
|
||||||
|
@ -8,7 +8,6 @@
|
||||||
# Contributors:
|
# Contributors:
|
||||||
# Markus Schorn (Wind River Systems)
|
# Markus Schorn (Wind River Systems)
|
||||||
###############################################################################
|
###############################################################################
|
||||||
WritablePDOM_error_unknownLinkage=AST specifies unknown linkage ''{0}''
|
|
||||||
PDOMManager_notifyJob_label=Notify Index Change Listeners
|
PDOMManager_notifyJob_label=Notify Index Change Listeners
|
||||||
PDOMManager_JoinIndexerTask=Join Indexer
|
PDOMManager_JoinIndexerTask=Join Indexer
|
||||||
PDOMManager_StartJob_name=Initialize Indexing
|
PDOMManager_StartJob_name=Initialize Indexing
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.ui.tests.text.selection;
|
package org.eclipse.cdt.ui.tests.text.selection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -47,6 +46,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
|
||||||
sourceIndexerID= indexerID;
|
sourceIndexerID= indexerID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
|
||||||
index= CCorePlugin.getIndexManager().getIndex(fCProject);
|
index= CCorePlugin.getIndexManager().getIndex(fCProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
closeAllEditors();
|
closeAllEditors();
|
||||||
CProjectHelper.delete(fCProject);
|
CProjectHelper.delete(fCProject);
|
||||||
|
@ -511,7 +512,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
|
||||||
String hcode= buffers[0].toString();
|
String hcode= buffers[0].toString();
|
||||||
String scode= buffers[1].toString();
|
String scode= buffers[1].toString();
|
||||||
IFile hfile = importFile("aheader.h", hcode);
|
IFile hfile = importFile("aheader.h", hcode);
|
||||||
IFile file = importFile("source.cpp", scode);
|
IFile file = importFile("source.c", scode);
|
||||||
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
|
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
|
||||||
IASTNode decl;
|
IASTNode decl;
|
||||||
int offset0, offset1;
|
int offset0, offset1;
|
||||||
|
@ -520,7 +521,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe
|
||||||
testF3(hfile, offset1);
|
testF3(hfile, offset1);
|
||||||
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||||
IEditorInput input = part.getEditorInput();
|
IEditorInput input = part.getEditorInput();
|
||||||
assertEquals("source.cpp", ((FileEditorInput)input).getFile().getName());
|
assertEquals("source.c", ((FileEditorInput)input).getFile().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// int myFunc();
|
// int myFunc();
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
* IBM Corporation
|
* IBM Corporation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.search;
|
package org.eclipse.cdt.internal.ui.search;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -85,7 +84,7 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
this.patternStr = patternStr.trim();
|
this.patternStr = patternStr.trim();
|
||||||
|
|
||||||
// Parse the pattern string
|
// Parse the pattern string
|
||||||
List patternList = new ArrayList();
|
List<Pattern> patternList = new ArrayList<Pattern>();
|
||||||
StringBuffer buff = new StringBuffer();
|
StringBuffer buff = new StringBuffer();
|
||||||
int n = patternStr.length();
|
int n = patternStr.length();
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
|
@ -120,9 +119,10 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
patternList.add(Pattern.compile(buff.toString(),Pattern.CASE_INSENSITIVE));
|
patternList.add(Pattern.compile(buff.toString(),Pattern.CASE_INSENSITIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
pattern = (Pattern[])patternList.toArray(new Pattern[patternList.size()]);
|
pattern = patternList.toArray(new Pattern[patternList.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
|
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
|
||||||
try {
|
try {
|
||||||
IndexFilter filter= IndexFilter.ALL;
|
IndexFilter filter= IndexFilter.ALL;
|
||||||
|
@ -179,6 +179,12 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
createMatches(index, pdomBinding);
|
createMatches(index, pdomBinding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ((flags & FIND_MACRO) != 0 && pattern.length == 1) {
|
||||||
|
bindings = index.findMacroContainers(pattern[0], filter, monitor);
|
||||||
|
for (IIndexBinding indexBinding : bindings) {
|
||||||
|
createMatches(index, indexBinding);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
return e.getStatus();
|
return e.getStatus();
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
|
@ -188,8 +194,8 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return Messages.format(CSearchMessages.PDOMSearchPatternQuery_PatternQuery_labelPatternInScope, super.getLabel(), patternStr, scopeDesc);
|
return Messages.format(CSearchMessages.PDOMSearchPatternQuery_PatternQuery_labelPatternInScope, super.getLabel(), patternStr, scopeDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
IASTName searchName= ast.getNodeSelector(null).findEnclosingName(selection.getOffset(), selection.getLength());
|
IASTName searchName= ast.getNodeSelector(null).findEnclosingName(selection.getOffset(), selection.getLength());
|
||||||
if (searchName != null) {
|
if (searchName != null) {
|
||||||
IBinding binding = searchName.resolveBinding();
|
IBinding binding = index.findBinding(searchName);
|
||||||
if (binding != null)
|
if (binding != null)
|
||||||
createMatches(index, binding);
|
createMatches(index, binding);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
* Ed Swartz (Nokia)
|
* Ed Swartz (Nokia)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.viewsupport;
|
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -346,10 +345,13 @@ public class IndexUI {
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
ITranslationUnit tu= getTranslationUnit(preferProject, macro.getFileLocation());
|
ITranslationUnit tu= getTranslationUnit(preferProject, macro.getFileLocation());
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
IRegion region= new Region(macro.getNodeOffset(), macro.getNodeLength());
|
IIndexName def= macro.getDefinition();
|
||||||
|
if (def != null) {
|
||||||
|
IRegion region= new Region(def.getNodeOffset(), def.getNodeLength());
|
||||||
long timestamp= macro.getFile().getTimestamp();
|
long timestamp= macro.getFile().getTimestamp();
|
||||||
return CElementHandleFactory.create(tu, macro, region, timestamp);
|
return CElementHandleFactory.create(tu, macro, region, timestamp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -39,6 +39,7 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
||||||
private Text fFilesToParseUpFront;
|
private Text fFilesToParseUpFront;
|
||||||
private Button fSkipReferences;
|
private Button fSkipReferences;
|
||||||
private Button fSkipTypeReferences;
|
private Button fSkipTypeReferences;
|
||||||
|
private Button fSkipMacroReferences;
|
||||||
|
|
||||||
protected AbstractIndexerPage() {
|
protected AbstractIndexerPage() {
|
||||||
super();
|
super();
|
||||||
|
@ -52,14 +53,17 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void createControl(Composite parent) {
|
public void createControl(Composite parent) {
|
||||||
Composite page = ControlFactory.createComposite(parent, 1);
|
Composite page = ControlFactory.createComposite(parent, 1);
|
||||||
fAllFiles= createAllFilesButton(page);
|
fAllFiles= createAllFilesButton(page);
|
||||||
fSkipReferences= createSkipReferencesButton(page);
|
fSkipReferences= createSkipReferencesButton(page);
|
||||||
fSkipTypeReferences= createSkipTypeReferencesButton(page);
|
fSkipTypeReferences= createSkipTypeReferencesButton(page);
|
||||||
|
fSkipMacroReferences= createSkipMacroReferencesButton(page);
|
||||||
fFilesToParseUpFront= createParseUpFrontTextField(page);
|
fFilesToParseUpFront= createParseUpFrontTextField(page);
|
||||||
|
|
||||||
fSkipReferences.addSelectionListener(new SelectionAdapter() {
|
fSkipReferences.addSelectionListener(new SelectionAdapter() {
|
||||||
|
@Override
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
updateEnablement();
|
updateEnablement();
|
||||||
}
|
}
|
||||||
|
@ -85,6 +89,10 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
||||||
boolean skipTypeReferences= TRUE.equals(properties.get(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES));
|
boolean skipTypeReferences= TRUE.equals(properties.get(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES));
|
||||||
fSkipTypeReferences.setSelection(skipTypeReferences);
|
fSkipTypeReferences.setSelection(skipTypeReferences);
|
||||||
}
|
}
|
||||||
|
if (fSkipMacroReferences != null) {
|
||||||
|
boolean skipMacroReferences= TRUE.equals(properties.get(IndexerPreferences.KEY_SKIP_MACRO_REFERENCES));
|
||||||
|
fSkipMacroReferences.setSelection(skipMacroReferences);
|
||||||
|
}
|
||||||
if (fFilesToParseUpFront != null) {
|
if (fFilesToParseUpFront != null) {
|
||||||
String files = getNotNull(properties, IndexerPreferences.KEY_FILES_TO_PARSE_UP_FRONT);
|
String files = getNotNull(properties, IndexerPreferences.KEY_FILES_TO_PARSE_UP_FRONT);
|
||||||
fFilesToParseUpFront.setText(files);
|
fFilesToParseUpFront.setText(files);
|
||||||
|
@ -110,12 +118,16 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
||||||
if (fSkipTypeReferences != null) {
|
if (fSkipTypeReferences != null) {
|
||||||
props.put(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES, String.valueOf(fSkipTypeReferences.getSelection()));
|
props.put(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES, String.valueOf(fSkipTypeReferences.getSelection()));
|
||||||
}
|
}
|
||||||
|
if (fSkipMacroReferences != null) {
|
||||||
|
props.put(IndexerPreferences.KEY_SKIP_MACRO_REFERENCES, String.valueOf(fSkipMacroReferences.getSelection()));
|
||||||
|
}
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link #getProperties()} will be called instead.
|
* {@link #getProperties()} will be called instead.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
final public void performApply(IProgressMonitor monitor) {
|
final public void performApply(IProgressMonitor monitor) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
@ -123,14 +135,20 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
||||||
/**
|
/**
|
||||||
* {@link #setProperties(Properties)} will be called instead.
|
* {@link #setProperties(Properties)} will be called instead.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
final public void performDefaults() {
|
final public void performDefaults() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateEnablement() {
|
public void updateEnablement() {
|
||||||
if (fSkipReferences != null && fSkipTypeReferences != null) {
|
if (fSkipReferences != null) {
|
||||||
|
if (fSkipTypeReferences != null) {
|
||||||
fSkipTypeReferences.setEnabled(!fSkipReferences.getSelection());
|
fSkipTypeReferences.setEnabled(!fSkipReferences.getSelection());
|
||||||
}
|
}
|
||||||
|
if (fSkipMacroReferences != null) {
|
||||||
|
fSkipMacroReferences.setEnabled(!fSkipReferences.getSelection());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getNotNull(Properties properties, String key) {
|
private String getNotNull(Properties properties, String key) {
|
||||||
|
@ -158,4 +176,8 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
||||||
private Button createSkipTypeReferencesButton(Composite page) {
|
private Button createSkipTypeReferencesButton(Composite page) {
|
||||||
return ControlFactory.createCheckBox(page, DialogsMessages.AbstractIndexerPage_skipTypeReferences);
|
return ControlFactory.createCheckBox(page, DialogsMessages.AbstractIndexerPage_skipTypeReferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Button createSkipMacroReferencesButton(Composite page) {
|
||||||
|
return ControlFactory.createCheckBox(page, DialogsMessages.AbstractIndexerPage_skipMacroReferences);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
* IBM Corporation
|
* IBM Corporation
|
||||||
* Andrew Ferguson (Symbian)
|
* Andrew Ferguson (Symbian)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.ui.dialogs;
|
package org.eclipse.cdt.ui.dialogs;
|
||||||
|
|
||||||
import org.eclipse.osgi.util.NLS;
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
@ -21,6 +20,7 @@ public class DialogsMessages extends NLS {
|
||||||
public static String AbstractIndexerPage_indexUpFront;
|
public static String AbstractIndexerPage_indexUpFront;
|
||||||
public static String AbstractIndexerPage_skipAllReferences;
|
public static String AbstractIndexerPage_skipAllReferences;
|
||||||
public static String AbstractIndexerPage_skipTypeReferences;
|
public static String AbstractIndexerPage_skipTypeReferences;
|
||||||
|
public static String AbstractIndexerPage_skipMacroReferences;
|
||||||
public static String CacheSizeBlock_MB;
|
public static String CacheSizeBlock_MB;
|
||||||
public static String IndexerBlock_fixedBuildConfig;
|
public static String IndexerBlock_fixedBuildConfig;
|
||||||
public static String IndexerStrategyBlock_activeBuildConfig;
|
public static String IndexerStrategyBlock_activeBuildConfig;
|
||||||
|
|
|
@ -16,6 +16,7 @@ PreferenceScopeBlock_preferenceLink=<a>Configure Workspace Settings...</a>
|
||||||
AbstractIndexerPage_indexAllFiles=Index all files (files neither built nor included, also)
|
AbstractIndexerPage_indexAllFiles=Index all files (files neither built nor included, also)
|
||||||
AbstractIndexerPage_skipAllReferences=Skip all references (Call Hierarchy and Search will not work)
|
AbstractIndexerPage_skipAllReferences=Skip all references (Call Hierarchy and Search will not work)
|
||||||
AbstractIndexerPage_skipTypeReferences=Skip type references (Search for type references will not work)
|
AbstractIndexerPage_skipTypeReferences=Skip type references (Search for type references will not work)
|
||||||
|
AbstractIndexerPage_skipMacroReferences=Skip macro references (Search for macro references will not work)
|
||||||
AbstractIndexerPage_indexUpFront=Files to index up-front:
|
AbstractIndexerPage_indexUpFront=Files to index up-front:
|
||||||
CacheSizeBlock_cacheLimitGroup=Cache limits
|
CacheSizeBlock_cacheLimitGroup=Cache limits
|
||||||
CacheSizeBlock_indexDatabaseCache=Index database cache:
|
CacheSizeBlock_indexDatabaseCache=Index database cache:
|
||||||
|
|
Loading…
Add table
Reference in a new issue