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

Fix for 164500, macro redefinitions in index.

This commit is contained in:
Markus Schorn 2006-11-15 09:49:36 +00:00
parent c8a56d7cb3
commit d6eadac266
11 changed files with 118 additions and 185 deletions

View file

@ -251,7 +251,7 @@ public class IndexBugsTests extends BaseTestCase {
// #define macro164500 1
// #undef macro164500
// #define macro164500 2
public void _test164500() throws Exception {
public void test164500() throws Exception {
waitForIndexer();
String content= readTaggedComment("test164500");

View file

@ -31,19 +31,11 @@ public interface IWritableIndex extends IIndex {
IIndexFragmentFile addFile(IPath fileLocation) throws CoreException;
/**
* Adds an AST name to the given file.
* Adds content to the given file.
*/
void addName(IIndexFragmentFile sourceFile, IASTName name) throws CoreException;
/**
* Adds a AST macro to the given file.
*/
void addMacro(IIndexFragmentFile sourceFile, IASTPreprocessorMacroDefinition macro) throws CoreException;
/**
* Adds an include to the given file.
*/
void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile, IASTPreprocessorIncludeStatement directive) throws CoreException;
void setFileContent(IIndexFragmentFile sourceFile,
IASTPreprocessorIncludeStatement[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[] names) throws CoreException;
/**
* Clears the entire index.

View file

@ -39,17 +39,9 @@ public interface IWritableIndexFragment extends IIndexFragment {
/**
* Adds an include to the given file.
*/
void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile, IASTPreprocessorIncludeStatement include) throws CoreException;
/**
* Adds a AST macro to the given file.
*/
void addMacro(IIndexFragmentFile sourceFile, IASTPreprocessorMacroDefinition macro) throws CoreException;
/**
* Adds an AST name to the given file.
*/
void addName(IIndexFragmentFile sourceFile, IASTName name) throws CoreException;
void addFileContent(IIndexFragmentFile sourceFile,
IASTPreprocessorIncludeStatement[] includes, IIndexFragmentFile[] destFiles,
IASTPreprocessorMacroDefinition[] macros, IASTName[] names) throws CoreException;
/**
* Acquires a write lock, while giving up a certain amount of read locks.

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
public class WritableCIndex extends CIndex implements IWritableIndex {
@ -45,15 +46,6 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
return fWritableFragments[0];
}
public void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile,
IASTPreprocessorIncludeStatement include) throws CoreException {
IIndexFragment indexFragment = sourceFile.getIndexFragment();
assert isWritableFragment(indexFragment);
assert isWritableFragment(destFile.getIndexFragment());
((IWritableIndexFragment) indexFragment).addInclude(sourceFile, destFile, include);
}
private boolean isWritableFragment(IIndexFragment frag) {
for (int i = 0; i < fWritableFragments.length; i++) {
if (fWritableFragments[i] == frag) {
@ -62,19 +54,21 @@ public class WritableCIndex extends CIndex implements IWritableIndex {
}
return false;
}
public void addMacro(IIndexFragmentFile sourceFile, IASTPreprocessorMacroDefinition macro) throws CoreException {
IIndexFragment indexFragment = sourceFile.getIndexFragment();
assert isWritableFragment(indexFragment);
((IWritableIndexFragment) indexFragment).addMacro(sourceFile, macro);
}
public void addName(IIndexFragmentFile sourceFile, IASTName name) throws CoreException {
IIndexFragment indexFragment = sourceFile.getIndexFragment();
public void setFileContent(IIndexFragmentFile file,
IASTPreprocessorIncludeStatement[] includes,
IASTPreprocessorMacroDefinition[] macros, IASTName[] names) throws CoreException {
IIndexFragment indexFragment = file.getIndexFragment();
assert isWritableFragment(indexFragment);
((IWritableIndexFragment) indexFragment).addName(sourceFile, name);
IIndexFragmentFile[] destFiles= new IIndexFragmentFile[includes.length];
for (int i = 0; i < includes.length; i++) {
IASTPreprocessorIncludeStatement statement = includes[i];
destFiles[i]= addFile(new Path(statement.getPath()));
}
((IWritableIndexFragment) indexFragment).addFileContent(file,
includes, destFiles, macros, names);
}
public void clear() throws CoreException {

View file

@ -114,16 +114,21 @@ public class PDOMIndexerJob extends Job {
protected IStatus run(IProgressMonitor m) {
String taskName = CCorePlugin.getResourceString("pdom.indexer.task"); //$NON-NLS-1$
monitor.beginTask(taskName, 1000);
int currentTick= 0;
while(!m.isCanceled()) {
currentTick= pdomManager.getMonitorMessage(monitor, currentTick, 1000);
try {
Thread.sleep(350);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
try {
int currentTick= 0;
while(!m.isCanceled()) {
currentTick= pdomManager.getMonitorMessage(monitor, currentTick, 1000);
try {
Thread.sleep(350);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
}
return Status.OK_STATUS;
}
finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
fMonitorJob.setSystem(true);

View file

@ -33,26 +33,23 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
return super.addFile(filename);
}
public void addInclude(IIndexFragmentFile sourceFile, IIndexFragmentFile destFile,
IASTPreprocessorIncludeStatement include) throws CoreException {
public void addFileContent(IIndexFragmentFile sourceFile,
IASTPreprocessorIncludeStatement[] includes, IIndexFragmentFile[] destFiles,
IASTPreprocessorMacroDefinition[] macros, IASTName[] names) throws CoreException {
assert sourceFile.getIndexFragment() == this;
assert destFile.getIndexFragment() == this;
((PDOMFile) sourceFile).addIncludeTo((PDOMFile) destFile, include);
}
public void addMacro(IIndexFragmentFile sourceFile, IASTPreprocessorMacroDefinition macro) throws CoreException {
assert sourceFile.getIndexFragment() == this;
((PDOMFile) sourceFile).addMacro(macro);
}
public void addName(IIndexFragmentFile sourceFile, IASTName name) throws CoreException {
assert sourceFile.getIndexFragment() == this;
PDOMLinkage linkage= createLinkage(name.getLinkage().getID());
if (linkage == null) {
CCorePlugin.log(MessageFormat.format(Messages.WritablePDOM_error_unknownLinkage, new Object[]{name.getLinkage()}));
}
else {
linkage.addName(name, (PDOMFile) sourceFile);
PDOMFile pdomFile = (PDOMFile) sourceFile;
pdomFile.addIncludesTo(destFiles, includes);
pdomFile.addMacros(macros);
for (int i = 0; i < names.length; i++) {
IASTName name= names[i];
PDOMLinkage linkage= createLinkage(name.getLinkage().getID());
if (linkage == null) {
CCorePlugin.log(MessageFormat.format(Messages.WritablePDOM_error_unknownLinkage, new Object[]{name.getLinkage()}));
}
else {
linkage.addName(name, pdomFile);
}
}
}

View file

@ -12,7 +12,6 @@
package org.eclipse.cdt.internal.core.pdom.dom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
@ -21,6 +20,7 @@ import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
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.IBTreeComparator;
@ -188,23 +188,21 @@ public class PDOMFile implements IIndexFragmentFile {
pdom.getDB().putInt(record + FIRST_MACRO, rec);
}
public void addMacro(IASTPreprocessorMacroDefinition macro) throws CoreException {
PDOMMacro firstMacro = getFirstMacro();
// mstodo revisit: this can probably be done more efficiently
// Make sure we don't already have one
char[] name = macro.getName().toCharArray();
PDOMMacro pdomMacro = firstMacro;
while (pdomMacro != null) {
if (pdomMacro.getNameInDB().equals(name))
return;
pdomMacro = pdomMacro.getNextMacro();
public void addMacros(IASTPreprocessorMacroDefinition[] macros) throws CoreException {
assert getFirstMacro() == null;
PDOMMacro lastMacro= null;
for (int i = 0; i < macros.length; i++) {
IASTPreprocessorMacroDefinition macro = macros[i];
PDOMMacro pdomMacro = new PDOMMacro(pdom, macro);
if (lastMacro == null) {
setFirstMacro(pdomMacro);
}
else {
lastMacro.setNextMacro(pdomMacro);
}
lastMacro= pdomMacro;
}
// Nope, add it in
pdomMacro = new PDOMMacro(pdom, macro);
pdomMacro.setNextMacro(getFirstMacro());
setFirstMacro(pdomMacro);
}
public void clear() throws CoreException {
@ -236,19 +234,29 @@ public class PDOMFile implements IIndexFragmentFile {
setFirstName(null);
}
public PDOMInclude addIncludeTo(PDOMFile file, IASTPreprocessorIncludeStatement include) throws CoreException {
PDOMInclude pdomInclude = new PDOMInclude(pdom, include);
pdomInclude.setIncludedBy(this);
pdomInclude.setIncludes(file);
public void addIncludesTo(IIndexFragmentFile[] files, IASTPreprocessorIncludeStatement[] includes) throws CoreException {
assert files.length == includes.length;
assert getFirstInclude() == null;
PDOMInclude firstInclude = getFirstInclude();
if (firstInclude != null) {
pdomInclude.setNextInIncludes(firstInclude);
PDOMInclude lastInclude= null;
for (int i = 0; i < includes.length; i++) {
IASTPreprocessorIncludeStatement statement = includes[i];
PDOMFile file= (PDOMFile) files[i];
assert file.getIndexFragment() instanceof IWritableIndexFragment;
PDOMInclude pdomInclude = new PDOMInclude(pdom, statement);
pdomInclude.setIncludedBy(this);
pdomInclude.setIncludes(file);
file.addIncludedBy(pdomInclude);
if (lastInclude == null) {
setFirstInclude(pdomInclude);
}
else {
lastInclude.setNextInIncludes(pdomInclude);
}
lastInclude= pdomInclude;
}
setFirstInclude(pdomInclude);
file.addIncludedBy(pdomInclude);
return pdomInclude;
}
public void addIncludedBy(PDOMInclude include) throws CoreException {
@ -269,7 +277,6 @@ public class PDOMFile implements IIndexFragmentFile {
result.add(include);
include = include.getNextInIncludes();
}
Collections.reverse(result);
return (IIndexInclude[]) result.toArray(new IIndexInclude[result.size()]);
}

View file

@ -20,6 +20,9 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude;
@ -42,7 +45,7 @@ import org.eclipse.core.runtime.Platform;
public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
private static final Object NO_CONTEXT = new Object();
protected static final int MAX_ERRORS = 10;
protected static final int MAX_ERRORS = 500;
protected volatile int fTotalSourcesEstimate= 0;
protected volatile int fCompletedSources= 0;
@ -92,7 +95,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
}
protected void collectSources(ICProject project, final Collection sources, final Collection headers, final boolean allFiles) throws CoreException {
fMessage= Messages.PDOMIndexerTask_collectingFilesTask;
fMessage= MessageFormat.format(Messages.PDOMIndexerTask_collectingFilesTask, new Object[]{project.getElementName()});
project.accept(new ICElementVisitor() {
public boolean visit(ICElement element) throws CoreException {
switch (element.getElementType()) {
@ -239,4 +242,28 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
public int getCompletedSourcesCount() {
return fCompletedSources;
}
protected IIndexFragmentFile addToIndex(IWritableIndex index, String location, ArrayList[] lists) throws CoreException {
// Remove the old symbols in the tu
Path path= new Path(location);
IIndexFragmentFile file= (IIndexFragmentFile) index.getFile(path);
if (file != null) {
index.clearFile(file);
}
else {
file= index.addFile(path);
}
file.setTimestamp(path.toFile().lastModified());
if (lists != null) {
ArrayList list= lists[0];
IASTPreprocessorIncludeStatement[] includes= (IASTPreprocessorIncludeStatement[]) list.toArray(new IASTPreprocessorIncludeStatement[list.size()]);
list= lists[1];
IASTPreprocessorMacroDefinition[] macros= (IASTPreprocessorMacroDefinition[]) list.toArray(new IASTPreprocessorMacroDefinition[list.size()]);
list= lists[2];
IASTName[] names= (IASTName[]) list.toArray(new IASTName[list.size()]);
index.setFileContent(file, includes, macros, names);
}
return file;
}
}

View file

@ -33,7 +33,6 @@ import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndex;
import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory;
@ -42,7 +41,6 @@ import org.eclipse.cdt.internal.core.pdom.indexer.PDOMIndexerTask;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
/**
* @author Doug Schaefer
@ -205,7 +203,7 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
if (fTrace) {
System.out.println("Indexer: adding " + path); //$NON-NLS-1$
}
addToIndex(path, info, (ArrayList[]) symbolMap.get(path));
info.fFile= addToIndex(index, path, (ArrayList[]) symbolMap.get(path));
if (isFirstAddition)
isFirstAddition= false;
@ -227,50 +225,6 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
lists[idx].add(thing);
}
private void addToIndex(String location, FileInfo info, ArrayList[] lists) throws CoreException {
// Remove the old symbols in the tu
Path path= new Path(location);
IIndexFragmentFile file= (IIndexFragmentFile) info.fFile;
if (file != null) {
index.clearFile(file);
}
else {
file= index.addFile(path);
info.fFile= file;
}
file.setTimestamp(path.toFile().lastModified());
if (lists != null) {
// includes
ArrayList list= lists[0];
for (int i = 0; i < list.size(); i++) {
IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) list.get(i);
IIndexFragmentFile destFile= createIndexFile(include.getPath());
index.addInclude(file, destFile, include);
}
// macros
list= lists[1];
for (int i = 0; i < list.size(); i++) {
index.addMacro(file, (IASTPreprocessorMacroDefinition) list.get(i));
}
// symbols
list= lists[2];
for (int i = 0; i < list.size(); i++) {
index.addName(file, (IASTName) list.get(i));
}
}
}
private IIndexFragmentFile createIndexFile(String path) throws CoreException {
FileInfo info= codeReaderFactory.createFileInfo(path);
if (info.fFile == null) {
info.fFile= index.addFile(new Path(path));
}
return (IIndexFragmentFile) info.fFile;
}
protected void parseTUs(List sources, List headers, IProgressMonitor monitor) throws CoreException, InterruptedException {
// sources first
Iterator iter;

View file

@ -30,14 +30,12 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndex;
import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMIndexerTask;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
/**
* @author Doug Schaefer
@ -219,7 +217,7 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
if (fTrace)
System.out.println("Indexer: adding " + path); //$NON-NLS-1$
addToIndex(path, (ArrayList[]) entry.getValue());
addToIndex(index, path, (ArrayList[]) entry.getValue());
if (isFirstAddition)
isFirstAddition= false;
@ -248,37 +246,4 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
lists[idx].add(thing);
}
}
private void addToIndex(String location, ArrayList[] lists) throws CoreException {
// Remove the old symbols in the tu
Path path= new Path(location);
IIndexFragmentFile file= (IIndexFragmentFile) index.getFile(new Path(location));
if (file != null) {
index.clearFile(file);
}
else {
file= index.addFile(path);
}
file.setTimestamp(path.toFile().lastModified());
// includes
ArrayList list= lists[0];
for (int i = 0; i < list.size(); i++) {
IASTPreprocessorIncludeStatement include= (IASTPreprocessorIncludeStatement) list.get(i);
IIndexFragmentFile destFile= index.addFile(new Path(include.getPath()));
index.addInclude(file, destFile, include);
}
// macros
list= lists[1];
for (int i = 0; i < list.size(); i++) {
index.addMacro(file, (IASTPreprocessorMacroDefinition) list.get(i));
}
// symbols
list= lists[2];
for (int i = 0; i < list.size(); i++) {
index.addName(file, (IASTName) list.get(i));
}
}
}

View file

@ -1,3 +1,3 @@
PDOMIndexerTask_collectingFilesTask=Collecting files to parse
PDOMIndexerTask_collectingFilesTask=Collecting files to parse (project ''{0}'')
PDOMIndexerTask_parsingFileTask=parsing {0} ({1})
PDOMIndexerTask_errorWhileParsing=Error while parsing {0}.