Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java17
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexBindingConstants.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeMacroContainer.java25
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/IndexProviderManager.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java161
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java21
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java18
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBinding.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerCollector.java (renamed from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroCollector.java)12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerFinder.java54
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerPatternCollector.java69
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java126
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java63
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java267
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java175
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroDefinitionName.java80
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroParameter.java76
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroReferenceName.java255
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java15
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOM.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/AbstractPDOMIndexer.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java15
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/messages.properties3
36 files changed, 1265 insertions, 326 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java
index d7bc638cb7e..3e7fb405d4f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/Linkage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,10 +8,11 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.dom;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
+import org.eclipse.core.runtime.CoreException;
public class Linkage implements ILinkage {
@@ -25,7 +26,17 @@ public class Linkage implements ILinkage {
public static final ILinkage[] getAllLinkages() {
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 String fName;
private Linkage(int id, String name) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java
index e251b6e6657..f40ca27ce73 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java
@@ -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 {
LinkedList<IIndexFragmentName> result= new LinkedList<IIndexFragmentName>();
if (binding instanceof ICPPUsingDeclaration) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java
index 71e2039001b..5d9ffa85dbf 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java
@@ -138,4 +138,8 @@ final public class EmptyCIndex implements IIndex {
public IIndexBinding[] findBindings(char[] name, boolean fileScopeOnly, IndexFilter filter, IProgressMonitor monitor) {
return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
}
+
+ public IIndexBinding[] findMacroContainers(Pattern pattern, IndexFilter filter, IProgressMonitor monitor) {
+ return IIndexBinding.EMPTY_INDEX_BINDING_ARRAY;
+ }
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexBindingConstants.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexBindingConstants.java
index 10d3d0e6479..1ea24109f87 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexBindingConstants.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexBindingConstants.java
@@ -17,5 +17,7 @@ public interface IIndexBindingConstants {
int POINTER_TYPE= 1;
int ARRAY_TYPE= 2;
int QUALIFIER_TYPE= 3;
- int LAST_CONSTANT= QUALIFIER_TYPE;
+ int MACRO_DEFINITION = 4;
+ int MACRO_CONTAINER = 5;
+ int LAST_CONSTANT= MACRO_CONTAINER;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java
index 8cf38880770..5308ae8a8e7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IIndexFragment.java
@@ -141,6 +141,19 @@ public interface IIndexFragment {
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
* the given array of names.
* @param names an array of names the qualified name of the bindings have to match.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeMacroContainer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeMacroContainer.java
new file mode 100644
index 00000000000..fdf07f33d2a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeMacroContainer.java
@@ -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);
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java
index f5c40d5aa3c..5211c6b4c2b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/c/CCompositesFactory.java
@@ -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.index.IIndex;
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.IIndexScope;
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.CompositeArrayType;
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.CompositeQualifierType;
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);
} else if(rbinding instanceof ITypedef) {
result = new CompositeCTypedef(this, rbinding);
+ } else if(rbinding instanceof IIndexMacroContainer) {
+ result= new CompositeMacroContainer(this, rbinding);
} else {
throw new CompositingNotImplementedError("composite binding unavailable for "+rbinding+" "+rbinding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java
index 861c4fb1c8e..2c6a9bbce69 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CPPCompositesFactory.java
@@ -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.index.IIndex;
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.IIndexFragmentBinding;
import org.eclipse.cdt.internal.core.index.IIndexScope;
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.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.CompositeQualifierType;
import org.eclipse.cdt.internal.core.index.composite.CompositingNotImplementedError;
@@ -154,6 +156,7 @@ public class CPPCompositesFactory extends AbstractCompositeFactory implements IC
return index;
}
+ @Override
protected IIndexFragmentBinding findOneDefinition(IBinding binding) {
return super.findOneDefinition(binding);
}
@@ -266,6 +269,8 @@ public class CPPCompositesFactory extends AbstractCompositeFactory implements IC
result = new CompositeCPPTypedef(this, (ICPPBinding) binding);
} else if(binding instanceof ICPPTemplateTypeParameter) {
result = new CompositeCPPTemplateTypeParameter(this, (ICPPTemplateTypeParameter) binding);
+ } else if(binding instanceof IIndexMacroContainer) {
+ result= new CompositeMacroContainer(this, binding);
} else {
throw new CompositingNotImplementedError("composite binding unavailable for "+binding+" "+binding.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/IndexProviderManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/IndexProviderManager.java
index e5a6960f894..6eb60025c01 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/IndexProviderManager.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/IndexProviderManager.java
@@ -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>
*/
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));
}
/**
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java
index 04456fcabc6..02191d88239 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java
@@ -43,7 +43,8 @@ class ASTPreprocessorName extends ASTPreprocessorNode implements IASTName {
return fBinding;
}
public ILinkage getLinkage() {
- return Linkage.NO_LINKAGE;
+ final IASTTranslationUnit tu= getTranslationUnit();
+ return tu == null ? Linkage.NO_LINKAGE : tu.getLinkage();
}
public IASTCompletionContext getCompletionContext() {
return null;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
index 0208d7cbce7..3483c7a5b74 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
@@ -679,6 +679,10 @@ public class LocationMap implements ILocationResolver {
return result.toArray(new IASTName[result.size()]);
}
+ public IASTName[] getMacroReferences() {
+ return fMacroReferences.toArray(new IASTName[fMacroReferences.size()]);
+ }
+
public ASTPreprocessorName[] getNestedMacroReferences(ASTMacroExpansion expansion) {
final IASTName explicitRef= expansion.getMacroReference();
List<ASTPreprocessorName> result= new ArrayList<ASTPreprocessorName>();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java
index 4558752d4ed..c0900c8afd0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/Messages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -31,7 +31,6 @@ public class Messages extends NLS {
public static String TeamPDOMExportOperation_errorWriteTempFile;
public static String TeamPDOMExportOperation_subtaskCreateDatabase;
public static String TeamPDOMExportOperation_taskExportIndex;
- public static String WritablePDOM_error_unknownLinkage;
public static String AbstractIndexerTask_parsingFileTask;
public static String AbstractIndexerTask_errorWhileParsing;
public static String AbstractIndexerTask_tooManyIndexProblems;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
index bd8c67663c0..91bad01c326 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java
@@ -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.IField;
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.IVariable;
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.IIndexLocationConverter;
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.internal.core.index.IIndexCBindingConstants;
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.FindBinding;
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.PDOMBinding;
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.PDOMLinkage;
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.PDOMNamedNode;
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 int CURRENT_VERSION = 56;
- public static final int MIN_SUPPORTED_VERSION= CURRENT_VERSION;
+ public static int version(int major, int minor) {
+ return major << 16 + minor;
+ }
- /**
- * The earliest PDOM version that the CURRENT_VERSION can be read as. For example,
- * versions 37,38 and 39 may be safely read by code from the version of CDT (4.0.0)
- * released at PDOM version 36.
- * <p>
- * Ideally this would always be CURRENT_VERSION on the basis that CURRENT_VERSION is
- * not incrementing.
- */
- public static final int EARLIEST_FORWARD_COMPATIBLE_VERSION= CURRENT_VERSION;
+ public static final int MAJOR_VERSION = 57;
+ public static final int MINOR_VERSION = 0; // minor versions must be compatible
+
+ public static final int CURRENT_VERSION= version(MAJOR_VERSION, MINOR_VERSION);
+ public static final int MIN_SUPPORTED_VERSION= version(MAJOR_VERSION, 0);
+ public static final int MAX_SUPPORTED_VERSION= version(MAJOR_VERSION+1, 0)-1;
/*
* PDOM internal format history
@@ -157,13 +160,13 @@ public class PDOM extends PlatformObject implements IPDOM {
* 54 - optimization of database size (bug 210392)
* 55 - generalization of local bindings (bug 215783)
* 56 - using directives (bug 216527)
+ * 57.0 - macro references (bug 156561)
*/
public static final int LINKAGES = Database.DATA_AREA;
public static final int FILE_INDEX = Database.DATA_AREA + 4;
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 + 16;
+ public static final int END= Database.DATA_AREA + 12;
static {
assert END <= Database.CHUNK_SIZE;
}
@@ -195,7 +198,6 @@ public class PDOM extends PlatformObject implements IPDOM {
// Local caches
protected Database db;
private BTree fileIndex;
- private BTree fMacroIndex= null;
private Map<String, PDOMLinkage> fLinkageIDCache = new HashMap<String, PDOMLinkage>();
private File fPath;
private IIndexLocationConverter locationConverter;
@@ -225,13 +227,11 @@ public class PDOM extends PlatformObject implements IPDOM {
fPath= dbPath;
final boolean lockDB= db == null || lockCount != 0;
+ clearCaches();
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);
- int version= db.getVersion();
- if (version >= MIN_SUPPORTED_VERSION) {
+ if (isSupportedVersion()) {
readLinkages();
}
db.setLocked(lockCount != 0);
@@ -246,7 +246,8 @@ public class PDOM extends PlatformObject implements IPDOM {
}
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 {
@@ -353,9 +354,12 @@ public class PDOM extends PlatformObject implements IPDOM {
}
public IIndexFragmentBinding findBinding(IASTName name) throws CoreException {
- PDOMLinkage linkage= adaptLinkage(name.getLinkage());
- if (linkage != null) {
- return linkage.resolveBinding(name);
+ IBinding binding= name.resolveBinding();
+ if (binding != null) {
+ PDOMLinkage linkage= adaptLinkage(name.getLinkage());
+ if (linkage != null) {
+ return findBindingInLinkage(linkage, binding);
+ }
}
return null;
}
@@ -461,6 +465,27 @@ public class PDOM extends PlatformObject implements IPDOM {
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 {
if (names.length == 0) {
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
@@ -688,18 +713,25 @@ public class PDOM extends PlatformObject implements IPDOM {
if (binding == null) {
return null;
}
- PDOMBinding pdomBinding= (PDOMBinding) binding.getAdapter(PDOMBinding.class);
- if (pdomBinding != null && pdomBinding.getPDOM() == this) {
- return pdomBinding;
+ PDOMNode pdomNode= (PDOMNode) binding.getAdapter(PDOMNode.class);
+ if (pdomNode instanceof IIndexFragmentBinding && pdomNode.getPDOM() == this) {
+ return (IIndexFragmentBinding) pdomNode;
}
PDOMLinkage linkage= adaptLinkage(binding.getLinkage());
if (linkage != null) {
- return linkage.adaptBinding(binding);
+ return findBindingInLinkage(linkage, binding);
}
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 {
if (indexName instanceof PDOMName) {
PDOMName pdomName= (PDOMName) indexName;
@@ -709,22 +741,25 @@ public class PDOM extends PlatformObject implements IPDOM {
}
public IIndexFragmentName[] findNames(IBinding binding, int options) throws CoreException {
- ArrayList<PDOMName> names= new ArrayList<PDOMName>();
- PDOMBinding pdomBinding = (PDOMBinding) adaptBinding(binding);
- if (pdomBinding != null) {
- names= new ArrayList<PDOMName>();
+ ArrayList<IIndexFragmentName> names= new ArrayList<IIndexFragmentName>();
+ IIndexFragmentBinding myBinding= adaptBinding(binding);
+ if (myBinding instanceof PDOMBinding) {
+ PDOMBinding pdomBinding = (PDOMBinding) myBinding;
findNamesForMyBinding(pdomBinding, options, names);
- }
- if ((options & SEARCH_ACCROSS_LANGUAGE_BOUNDARIES) != 0) {
- PDOMBinding[] xlangBindings= getCrossLanguageBindings(binding);
- for (int j = 0; j < xlangBindings.length; j++) {
- findNamesForMyBinding(xlangBindings[j], options, names);
+ if ((options & SEARCH_ACCROSS_LANGUAGE_BOUNDARIES) != 0) {
+ PDOMBinding[] xlangBindings= getCrossLanguageBindings(binding);
+ for (int j = 0; j < xlangBindings.length; j++) {
+ findNamesForMyBinding(xlangBindings[j], options, names);
+ }
}
}
+ else if (myBinding instanceof PDOMMacroContainer) {
+ findNamesForMyBinding((PDOMMacroContainer) myBinding, options, names);
+ }
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 {
PDOMName name;
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 {
PDOMFile pdomFile= adaptFile(file);
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 {
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);
try {
- getMacroIndex().accept(visitor);
- result.addAll(visitor.getMacroList());
+ for (Iterator<PDOMLinkage> iter = fLinkageIDCache.values().iterator(); iter.hasNext();) {
+ 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) {
}
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 {
if(IIndexFragment.PROPERTY_FRAGMENT_FORMAT_ID.equals(propertyName)) {
return FRAGMENT_PROPERTY_VALUE_FORMAT_ID;
}
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);
}
@@ -865,7 +907,6 @@ public class PDOM extends PlatformObject implements IPDOM {
private void clearCaches() {
fileIndex= null;
- fMacroIndex= null;
fLinkageIDCache.clear();
clearResultCache();
}
@@ -892,9 +933,9 @@ public class PDOM extends PlatformObject implements IPDOM {
db.flush();
}
- public Object getCachedResult(Object binding) {
+ public Object getCachedResult(Object key) {
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) {
- 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 {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java
index 387c9274d2c..2ff6f60ba52 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java
@@ -240,4 +240,15 @@ public class PDOMProxy implements IPDOM {
return fDelegate.getAllFiles();
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;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java
index 399a5096e78..47addfae0c2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java
@@ -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.IWritableIndex;
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.PDOMNotImplementedError;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerASTVisitor;
@@ -62,7 +63,8 @@ import org.eclipse.osgi.util.NLS;
*/
abstract public class PDOMWriter {
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;
private static class Symbols {
@@ -108,7 +110,8 @@ abstract public class PDOMWriter {
/**
* 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) {
fSkipReferences= options;
@@ -335,6 +338,20 @@ abstract public class PDOMWriter {
};
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.fPreprocessorProblemCount+= ast.getPreprocessorProblemsCount() - unresolvedIncludes;
if (fShowScannerProblems || fShowInclusionProblems) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
index ebac516694c..5f07fb394c2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/WritablePDOM.java
@@ -12,14 +12,12 @@
package org.eclipse.cdt.internal.core.pdom;
import java.io.File;
-import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
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.IASTPreprocessorMacroDefinition;
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.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
-import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMFile;
-import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.core.runtime.CoreException;
public class WritablePDOM extends PDOM implements IWritableIndexFragment {
@@ -96,19 +92,7 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
public void flush() throws CoreException {
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)
* @see org.eclipse.cdt.internal.core.index.IWritableIndexFragment#setProperty(java.lang.String, java.lang.String)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java
index 97d74261d4f..650ef027b79 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/BindingCollector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 QNX Software Systems and others.
+ * Copyright (c) 2006, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -41,6 +41,7 @@ public final class BindingCollector extends NamedNodeCollector {
this.filter= filter;
}
+ @Override
public boolean addNode(PDOMNamedNode tBinding) throws CoreException {
if (tBinding instanceof PDOMBinding) {
if (filter == null || filter.acceptBinding((IBinding) tBinding)) {
@@ -51,7 +52,7 @@ public final class BindingCollector extends NamedNodeCollector {
}
public PDOMBinding[] getBindings() {
- List bindings= getNodeList();
- return (PDOMBinding[])bindings.toArray(new PDOMBinding[bindings.size()]);
+ List<PDOMNamedNode> bindings= getNodeList();
+ return bindings.toArray(new PDOMBinding[bindings.size()]);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBinding.java
index 09fcb7be4c3..1d871343145 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBinding.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/FindBinding.java
@@ -123,6 +123,7 @@ public class FindBinding {
super(linkage.pdom);
this.linkage= linkage;
}
+ @Override
public int compare(int record1, int record2) throws CoreException {
int cmp= super.compare(record1, record2); // compare names
if (cmp==0) { // any order will do.
@@ -144,16 +145,7 @@ public class FindBinding {
fPDom= pdom;
}
public int compare(int record1, int record2) throws CoreException {
- int cmp= compare(PDOMMacro.getNameInDB(fPDom, record1), PDOMMacro.getNameInDB(fPDom, record2)); // compare names
- if (cmp==0) { // any order will do.
- if (record1 < record2) {
- return -1;
- }
- else if (record1 > record2) {
- return 1;
- }
- }
- return cmp;
+ return compare(PDOMNamedNode.getDBName(fPDom, record1), PDOMNamedNode.getDBName(fPDom, record2)); // compare names
}
private int compare(IString nameInDB, IString nameInDB2) throws CoreException {
return nameInDB.compareCompatibleWithIgnoreCase(nameInDB2);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerCollector.java
index dbc553823eb..17bc033d94c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroCollector.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerCollector.java
@@ -24,7 +24,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
* Visitor to find macros in a BTree.
* @since 4.0.2
*/
-public final class MacroCollector implements IBTreeVisitor {
+public final class MacroContainerCollector implements IBTreeVisitor {
private final PDOM pdom;
private final char[] name;
private final boolean prefixLookup;
@@ -32,14 +32,14 @@ public final class MacroCollector implements IBTreeVisitor {
private IProgressMonitor monitor= null;
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
* <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.pdom= pdom;
this.prefixLookup= prefixLookup;
@@ -57,7 +57,7 @@ public final class MacroCollector implements IBTreeVisitor {
final public int compare(int record) throws CoreException {
if (monitor != null)
checkCancelled();
- IString name= PDOMMacro.getNameInDB(pdom, record);
+ IString name= PDOMNamedNode.getDBName(pdom, record);
return compare(name);
}
@@ -87,11 +87,11 @@ public final class MacroCollector implements IBTreeVisitor {
if (record == 0)
return true;
- macros.add(new PDOMMacro(pdom, record));
+ macros.add(new PDOMMacroContainer(pdom, record));
return true; // look for more
}
- final public List<PDOMMacro> getMacroList() {
+ final public List<PDOMMacroContainer> getMacroList() {
return macros;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerFinder.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerFinder.java
new file mode 100644
index 00000000000..392a14033aa
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerFinder.java
@@ -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;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerPatternCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerPatternCollector.java
new file mode 100644
index 00000000000..a5c977b3843
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/MacroContainerPatternCollector.java
@@ -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();
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java
index c7d1b086dfa..eab4f3c5b9c 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMArrayType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
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.pdom.PDOM;
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 {
private static final int TYPE = PDOMNode.RECORD_SIZE;
+ @SuppressWarnings("hiding")
private static final int RECORD_SIZE= TYPE+4;
public PDOMArrayType(PDOM pdom, int record) {
@@ -48,12 +50,14 @@ public class PDOMArrayType extends PDOMNode implements IIndexType, IArrayType, I
}
}
+ @Override
protected int getRecordSize() {
return RECORD_SIZE;
}
+ @Override
public int getNodeType() {
- return PDOMLinkage.ARRAY_TYPE;
+ return IIndexBindingConstants.ARRAY_TYPE;
}
public IASTExpression getArraySizeExpression() throws DOMException {
@@ -93,10 +97,12 @@ public class PDOMArrayType extends PDOMNode implements IIndexType, IArrayType, I
throw new PDOMNotImplementedError();
}
+ @Override
public Object clone() {
return new ArrayTypeClone(this);
}
+ @Override
public void delete(PDOMLinkage linkage) throws CoreException {
linkage.deleteType(getType(), record);
super.delete(linkage);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
index b9dcb7b7362..17d54eefebb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java
@@ -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.index.IIndexBinding;
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.IIndexFragmentBinding;
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;
}
+ @Override
public int getRecord() {
return record;
}
@@ -174,13 +176,14 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
return ""; //$NON-NLS-1$
}
+ @Override
public char[] getNameCharArray() {
try {
return super.getNameCharArray();
} catch (CoreException e) {
CCorePlugin.log(e);
}
- return new char[0];
+ return CharArrayUtils.EMPTY;
}
public IIndexScope getParent() {
@@ -219,12 +222,14 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen
return pdom;
}
+ @Override
abstract protected int getRecordSize(); // superclass's implementation is no longer valid
/* For debug purposes only
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
+ @Override
public String toString() {
try {
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 {
}
+ @Override
final public void delete(PDOMLinkage linkage) throws CoreException {
assert false;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
index 0bd4595e8ce..f8d8f15454f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java
@@ -23,6 +23,8 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
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.IIndexMacro;
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.IIndexFragmentFile;
+import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
import org.eclipse.cdt.internal.core.index.IWritableIndex.IncludeInformation;
import org.eclipse.cdt.internal.core.pdom.PDOM;
-import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
import org.eclipse.cdt.internal.core.pdom.db.BTree;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeComparator;
@@ -53,6 +56,7 @@ public class PDOMFile implements IIndexFragmentFile {
private final PDOM pdom;
private final int record;
private IIndexFileLocation location;
+ private PDOMLinkage fLinkage;
private static final int FIRST_NAME = 0;
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 SCANNER_CONFIG_HASH= 32;
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 {
private Database db;
@@ -167,16 +172,26 @@ public class PDOMFile implements IIndexFragmentFile {
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);
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;
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 {
int increc = pdom.getDB().getInt(record + FIRST_INCLUDE);
return increc != 0 ? new PDOMInclude(pdom, increc) : null;
@@ -215,9 +230,11 @@ public class PDOMFile implements IIndexFragmentFile {
assert getFirstMacro() == null;
PDOMMacro lastMacro= null;
+ final PDOMLinkage linkage = getLinkage();
for (int i = 0; i < macros.length; 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) {
setFirstMacro(pdomMacro);
}
@@ -225,20 +242,34 @@ public class PDOMFile implements IIndexFragmentFile {
lastMacro.setNextMacro(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 {
assert getFirstName() == null;
+ assert getFirstMacroReference() == null;
+ final PDOMLinkage linkage= getLinkage();
HashMap<IASTName, PDOMName> nameCache= new HashMap<IASTName, PDOMName>();
PDOMName lastName= null;
+ PDOMMacroReferenceName lastMacroName= null;
for (int i = 0; i < names.length; i++) {
IASTName[] name = names[i];
if (name[0] != null) {
PDOMName caller= nameCache.get(name[1]);
- PDOMName pdomName = createPDOMName(name[0], caller);
- if (pdomName != null) {
+ IIndexFragmentName fname= createPDOMName(linkage, name[0], caller);
+ if (fname instanceof PDOMName) {
+ PDOMName pdomName = (PDOMName) fname;
nameCache.put(name[0], pdomName);
if (lastName == null) {
setFirstName(pdomName);
@@ -248,25 +279,46 @@ public class PDOMFile implements IIndexFragmentFile {
}
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) {
- if (name.getBinding() instanceof IParameter) {
+ private IIndexFragmentName createPDOMName(PDOMLinkage linkage, IASTName name, PDOMName caller) {
+ final IBinding binding = name.getBinding();
+ if (binding instanceof IParameter) {
return null;
}
- PDOMName result= null;
try {
- PDOMBinding binding = ((WritablePDOM) pdom).addBinding(name);
- if (binding != null) {
- result= new PDOMName(pdom, name, this, binding, caller);
- binding.getLinkageImpl().onCreateName(this, name, result);
+ if (binding instanceof IMacroBinding) {
+ return createPDOMMacroReferenceName(linkage, name);
+ }
+ 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) {
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 {
@@ -293,7 +345,6 @@ public class PDOMFile implements IIndexFragmentFile {
// Delete all the macros in this file
PDOMMacro macro = getFirstMacro();
while (macro != null) {
- pdom.beforeRemoveMacro(macro);
PDOMMacro nextMacro = macro.getNextMacro();
macro.delete();
macro = nextMacro;
@@ -301,19 +352,32 @@ public class PDOMFile implements IIndexFragmentFile {
setFirstMacro(null);
// Delete all the names in this file
+ PDOMLinkage linkage= getLinkage();
ArrayList<PDOMName> names= new ArrayList<PDOMName>();
PDOMName name = getFirstName();
while (name != null) {
names.add(name);
- name.getBinding().getLinkageImpl().onDeleteName(name);
+ linkage.onDeleteName(name);
name= name.getNextInFile();
}
-
for (Iterator<PDOMName> iterator = names.iterator(); iterator.hasNext();) {
name = iterator.next();
name.delete();
}
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);
}
@@ -388,7 +452,7 @@ public class PDOMFile implements IIndexFragmentFile {
}
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()) {
int nameOffset= name.getNodeOffset();
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()]);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
index 5d56fe12063..013602bca85 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java
@@ -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 INDEX_OFFSET = PDOMNamedNode.RECORD_SIZE + 8;
private static final int NESTED_BINDINGS_INDEX = PDOMNamedNode.RECORD_SIZE + 12;
+ private static final int MACRO_BTREE = PDOMNamedNode.RECORD_SIZE + 16;
@SuppressWarnings("hiding")
- protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 16;
+ protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 20;
// node types
protected static final int LINKAGE= 0; // special one for myself
+ private BTree fMacroIndex= null;
+
public PDOMLinkage(PDOM pdom, int record) {
super(pdom, record);
}
@@ -78,10 +81,12 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
pdom.insertLinkage(this);
}
+ @Override
protected int getRecordSize() {
return RECORD_SIZE;
}
+ @Override
public int getNodeType() {
return LINKAGE;
}
@@ -113,6 +118,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return new BTree(getPDOM().getDB(), record + NESTED_BINDINGS_INDEX, getNestedBindingsComparator());
}
+ @Override
public void accept(final IPDOMVisitor visitor) throws CoreException {
if (visitor instanceof IBTreeVisitor) {
getIndex().accept((IBTreeVisitor) visitor);
@@ -134,10 +140,12 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
}
}
+ @Override
public ILinkage getLinkage() throws CoreException {
return this;
}
+ @Override
public final void addChild(PDOMNode child) throws CoreException {
getIndex().insert(child.getRecord());
}
@@ -212,14 +220,6 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
}
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 {
int rec= 0;
@@ -341,6 +341,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
// no implementation, yet.
}
+ @Override
public void delete(PDOMLinkage linkage) throws CoreException {
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 {
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());
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java
index 6276fee6216..fed4a1793e0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java
@@ -19,17 +19,19 @@ import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
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.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
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.IIndexMacro;
import org.eclipse.cdt.core.parser.Keywords;
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.pdom.PDOM;
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;
/**
- * Represents macros.
- *
- * @author Doug Schaefer
+ * 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.
*/
-public class PDOMMacro implements IIndexMacro, IASTFileLocation {
-
- private static final byte MACROSTYLE_OBJECT = 1;
- private static final byte MACROSTYLE_FUNCTION= 2;
+public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLocation {
- private static final int NAME = 0;
+ private static final int CONTAINER = 0;
private static final int FILE = 4;
- private static final int NAME_OFFSET = 8;
- private static final int NAME_LENGTH = 12; // short
- private static final int FIRST_PARAMETER = 14;
- private static final int EXPANSION = 18;
- private static final int NEXT_MACRO = 22;
- private static final int MACRO_STYLE = 26; // byte
+ private static final int PARAMETERS= 8;
+ private static final int EXPANSION = 12;
+ private static final int NEXT_IN_FILE = 16;
+ private static final int NEXT_IN_CONTAINER = 20;
+ private static final int PREV_IN_CONTAINER = 24;
+ 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 final PDOM pdom;
- private final int record;
-
+ private final PDOM fPDOM;
+ private final int fRecord;
+
private char[][] fParameterList= UNINITIALIZED;
- private char[] fName;
private char[] fExpansion;
+ private PDOMMacroContainer fContainer;
+ private PDOMMacroDefinitionName fDefinition;
public PDOMMacro(PDOM pdom, int record) {
- this.pdom = pdom;
- this.record = record;
+ fPDOM = pdom;
+ fRecord = record;
}
- public PDOMMacro(PDOM pdom, IASTPreprocessorMacroDefinition macro, PDOMFile file) throws CoreException {
- this.pdom = pdom;
+ public PDOMMacro(PDOM pdom, PDOMMacroContainer container, IASTPreprocessorMacroDefinition macro, PDOMFile file) throws CoreException {
+ final Database db= pdom.getDB();
+
+ fPDOM = pdom;
+ fRecord = db.malloc(RECORD_SIZE);
+ fContainer= container;
- Database db = pdom.getDB();
- this.record = db.malloc(RECORD_SIZE);
- IASTName name = macro.getName();
- IMacroBinding binding= (IMacroBinding) name.getBinding();
+ final IASTName name = macro.getName();
+ final IASTFileLocation fileloc = name.getFileLocation();
+ final IMacroBinding binding= (IMacroBinding) name.getBinding();
+ final char[][] params= binding.getParameterList();
- db.putInt(record + NAME, db.newString(name.toCharArray()).getRecord());
- db.putInt(record + FILE, file.getRecord());
- IASTFileLocation fileloc = name.getFileLocation();
- db.putInt(record + NAME_OFFSET, fileloc.getNodeOffset());
- db.putShort(record + NAME_LENGTH, (short) fileloc.getNodeLength());
- db.putInt(record + EXPANSION, db.newString(binding.getExpansionImage()).getRecord());
- setNextMacro(0);
+ db.putInt(fRecord + CONTAINER, container.getRecord());
+ 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) {
- macroStyle= MACROSTYLE_FUNCTION;
- for (int i = params.length - 1; i >= 0; --i) {
- PDOMMacroParameter pdomParam = new PDOMMacroParameter(pdom, params[i]);
- if (last != null)
- pdomParam.setNextParameter(last);
- last = pdomParam;
+ StringBuilder buf= new StringBuilder();
+ for (int i= 0; i < params.length; i++) {
+ buf.append(params[i]);
+ buf.append(',');
}
+ 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() {
- return record;
+ return fRecord;
}
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();
- PDOMMacroParameter param = getFirstParameter();
- if (param != null)
- param.delete();
- pdom.getDB().free(record);
+ final IString params = getParamListInDB();
+ if (params != null) {
+ params.delete();
+ }
}
- public static IString getNameInDB(PDOM pdom, int record) throws CoreException {
- Database db = pdom.getDB();
- int rec = db.getInt(record + NAME);
- return db.getString(rec);
+ public PDOMMacroContainer getContainer() throws CoreException {
+ if (fContainer == null) {
+ fContainer= new PDOMMacroContainer(fPDOM, fPDOM.getDB().getInt(fRecord + CONTAINER));
+ }
+ return fContainer;
}
-
+
private IString getExpansionInDB() throws CoreException {
- Database db = pdom.getDB();
- int rec = db.getInt(record + EXPANSION);
+ Database db = fPDOM.getDB();
+ int rec = db.getInt(fRecord + EXPANSION);
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 {
- int rec = pdom.getDB().getInt(record + NEXT_MACRO);
- return rec != 0 ? new PDOMMacro(pdom, rec) : null;
+ int rec = fPDOM.getDB().getInt(fRecord + NEXT_IN_FILE);
+ return rec != 0 ? new PDOMMacro(fPDOM, rec) : null;
}
public void setNextMacro(PDOMMacro macro) throws CoreException {
@@ -137,25 +161,50 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
}
private void setNextMacro(int rec) throws CoreException {
- pdom.getDB().putInt(record + NEXT_MACRO, rec);
+ fPDOM.getDB().putInt(fRecord + NEXT_IN_FILE, rec);
+ }
+
+ private PDOMMacro getPrevInContainer() throws CoreException {
+ return getMacroField(PREV_IN_CONTAINER);
+ }
+
+ 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 PDOMMacroParameter getFirstParameter() throws CoreException {
- int rec = pdom.getDB().getInt(record + FIRST_PARAMETER);
- return rec != 0 ? new PDOMMacroParameter(pdom, rec) : null;
+ 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() {
if (fParameterList == UNINITIALIZED) {
fParameterList= null;
try {
- byte style= pdom.getDB().getByte(record + MACRO_STYLE);
- if (style == MACROSTYLE_FUNCTION) {
+ IString plist= getParamListInDB();
+ if (plist != null) {
List<char[]> paramList = new ArrayList<char[]>();
- PDOMMacroParameter param= getFirstParameter();
- while (param != null) {
- paramList.add(param.getName().getChars());
- param = param.getNextParameter();
+ final char[] cplist= plist.getChars();
+ final int end = cplist.length;
+ int from= 0;
+ 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()][]);
}
@@ -179,24 +228,22 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
}
public char[] getNameCharArray() {
- if (fName == null) {
- try {
- fName= getNameInDB(pdom, record).getChars();
- } catch (CoreException e) {
- CCorePlugin.log(e);
- fName= new char[] { ' ' };
- }
+ try {
+ return getContainer().getNameCharArray();
+ }
+ catch (CoreException e) {
+ CCorePlugin.log(e);
+ return new char[]{' '};
}
- return fName;
}
public String getName() {
return new String(getNameCharArray());
}
- public IIndexFile getFile() throws CoreException {
- int filerec = pdom.getDB().getInt(record + FILE);
- return filerec != 0 ? new PDOMFile(pdom, filerec) : null;
+ public PDOMFile getFile() throws CoreException {
+ int filerec = fPDOM.getDB().getInt(fRecord + FILE);
+ return filerec != 0 ? new PDOMFile(fPDOM, filerec) : null;
}
public int getEndingLineNumber() {
@@ -205,7 +252,7 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
public String getFileName() {
try {
- PDOMFile file = (PDOMFile) getFile();
+ PDOMFile file = getFile();
if(file!=null) {
/*
* We need to spec. what this method can return to know
@@ -236,7 +283,7 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
public int getNodeLength() {
try {
- return pdom.getDB().getShort(record + NAME_LENGTH);
+ return fPDOM.getDB().getShort(fRecord + NAME_LENGTH);
} catch (CoreException e) {
CCorePlugin.log(e);
return 0;
@@ -245,7 +292,7 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
public int getNodeOffset() {
try {
- return pdom.getDB().getInt(record + NAME_OFFSET);
+ return fPDOM.getDB().getInt(fRecord + NAME_OFFSET);
} catch (CoreException e) {
CCorePlugin.log(e);
return 0;
@@ -281,15 +328,53 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
}
public ILinkage getLinkage() throws CoreException {
- return Linkage.NO_LINKAGE;
+ return getFile().getLinkage();
}
- public IScope getScope() throws DOMException {
+ public IIndexScope getScope() {
return null;
}
@SuppressWarnings("unchecked")
public Object getAdapter(Class adapter) {
+ if (adapter.isAssignableFrom(PDOMMacro.class)) {
+ return this;
+ }
+ 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;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java
new file mode 100644
index 00000000000..7a720448ade
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java
@@ -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;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroDefinitionName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroDefinitionName.java
new file mode 100644
index 00000000000..696a7b32c68
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroDefinitionName.java
@@ -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();
+ }
+} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroParameter.java
deleted file mode 100644
index 7ef84c32692..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroParameter.java
+++ /dev/null
@@ -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));
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroReferenceName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroReferenceName.java
new file mode 100644
index 00000000000..4c57cdf31df
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroReferenceName.java
@@ -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;
+ }
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java
index bda40e23e34..071c87fc022 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMNamedNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 QNX Software Systems and others.
+ * Copyright (c) 2006, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -32,7 +32,10 @@ public abstract class PDOMNamedNode extends PDOMNode {
/**
* The size in bytes of a PDOMNamedNode record in the database.
*/
+ @SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMNode.RECORD_SIZE + 4;
+
+ private char[] fName;
public PDOMNamedNode(PDOM pdom, int record) {
super(pdom, record);
@@ -40,12 +43,14 @@ public abstract class PDOMNamedNode extends PDOMNode {
public PDOMNamedNode(PDOM pdom, PDOMNode parent, char[] name) throws CoreException {
super(pdom, parent);
-
+
+ fName= name;
Database db = pdom.getDB();
db.putInt(record + NAME,
name != null ? db.newString(name).getRecord() : 0);
}
+ @Override
abstract protected int getRecordSize();
public IString getDBName() throws CoreException {
@@ -61,13 +66,17 @@ public abstract class PDOMNamedNode extends PDOMNode {
}
public char[] getNameCharArray() throws CoreException {
- return getDBName().getChars();
+ if (fName == null) {
+ fName= getDBName().getChars();
+ }
+ return fName;
}
public boolean hasName(char[] name) throws CoreException {
return getDBName().equals(name);
}
+ @Override
public void delete(PDOMLinkage linkage) throws CoreException {
final Database db = pdom.getDB();
final int namerec= db.getInt(record + NAME);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOM.java
index 15a5de9474b..d38103d1b31 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOM.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/export/GeneratePDOM.java
@@ -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.LanguageManager;
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.indexer.IndexerPreferences;
import org.eclipse.core.runtime.CoreException;
@@ -87,9 +86,6 @@ public class GeneratePDOM implements ISafeRunnable {
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();
}
finally {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/AbstractPDOMIndexer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/AbstractPDOMIndexer.java
index 289d7bfe057..f9bcc0da5a8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/AbstractPDOMIndexer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/AbstractPDOMIndexer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.core.pdom.indexer;
-import java.util.Iterator;
import java.util.Map;
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_SKIP_ALL_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() {
@@ -46,8 +46,7 @@ public abstract class AbstractPDOMIndexer implements IPDOMIndexer {
}
public boolean needsToRebuildForProperties(Properties props) {
- for (Iterator i= fProperties.entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry) i.next();
+ for (Map.Entry<Object,Object> entry : fProperties.entrySet()) {
String key = (String) entry.getKey();
String myval = (String) entry.getValue();
@@ -63,8 +62,7 @@ public abstract class AbstractPDOMIndexer implements IPDOMIndexer {
public void setProperties(Properties props) {
// only set relevant properties as initialized in the constructor
- for (Iterator i= props.entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry) i.next();
+ for (Map.Entry<Object,Object> entry : props.entrySet()) {
String key = (String) entry.getKey();
String val = (String) entry.getValue();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java
index 37f5a0b4f1b..cb7f51c8a3b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerPreferences.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.core.pdom.indexer;
-import java.util.Iterator;
import java.util.Map;
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_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_MACRO_REFERENCES= "skipMacroReferences"; //$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$
@@ -185,8 +185,7 @@ public class IndexerPreferences {
}
private static void setProperties(Preferences prefs, Properties props) {
- for (Iterator i = props.entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry) i.next();
+ for (Map.Entry<Object,Object> entry : props.entrySet()) {
String key = (String) entry.getKey();
String val = (String) entry.getValue();
prefs.put(key, val);
@@ -314,6 +313,7 @@ public class IndexerPreferences {
prefs.putBoolean(KEY_INDEX_ALL_FILES, false);
prefs.putBoolean(KEY_SKIP_ALL_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_FILES_TO_PARSE_UP_FRONT, DEFAULT_FILES_TO_PARSE_UP_FRONT);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java
index 766a630e070..2b3db58e436 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java
@@ -65,8 +65,17 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
if (checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES)) {
setSkipReferences(SKIP_ALL_REFERENCES);
}
- else if (checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES)) {
- setSkipReferences(SKIP_TYPE_REFERENCES);
+ else {
+ 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()) {
setIndexFilesWithoutBuildConfiguration(true);
@@ -236,11 +245,13 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
boolean allFiles= getIndexAllFiles();
boolean skipRefs= checkProperty(IndexerPreferences.KEY_SKIP_ALL_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$
+ "indexer='" + kind //$NON-NLS-1$
+ "', parseAllFiles=" + allFiles //$NON-NLS-1$
+ ", skipReferences=" + skipRefs //$NON-NLS-1$
+ ", skipTypeReferences=" + skipTypeRefs //$NON-NLS-1$
+ + ", skipMacroReferences=" + skipMacroRefs //$NON-NLS-1$
+ "."); //$NON-NLS-1$
System.out.println(ident + " Database: " + dbSize + " bytes"); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println(ident + " Timings: " //$NON-NLS-1$
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/messages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/messages.properties
index db91077ef8c..1ca3af025c5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/messages.properties
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/messages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+# Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -8,7 +8,6 @@
# Contributors:
# Markus Schorn (Wind River Systems)
###############################################################################
-WritablePDOM_error_unknownLinkage=AST specifies unknown linkage ''{0}''
PDOMManager_notifyJob_label=Notify Index Change Listeners
PDOMManager_JoinIndexerTask=Join Indexer
PDOMManager_StartJob_name=Initialize Indexing

Back to the top