mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
Fix bugs revealed by the testcases.
This commit is contained in:
parent
6f7c1b7904
commit
24864f8821
6 changed files with 43 additions and 21 deletions
|
@ -613,7 +613,7 @@ public class IndexIncludeTest extends IndexTestBase {
|
||||||
IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "false");
|
IndexerPreferences.set(fProject.getProject(), IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "false");
|
||||||
waitForIndexer();
|
waitForIndexer();
|
||||||
TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() };
|
TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() };
|
||||||
CharSequence[] contents= getContentsForTest(4);
|
CharSequence[] contents= getContentsForTest(5);
|
||||||
final CharSequence h1Contents = contents[0];
|
final CharSequence h1Contents = contents[0];
|
||||||
final IFile h1= TestSourceReader.createFile(fProject.getProject(), "h1.h", h1Contents.toString());
|
final IFile h1= TestSourceReader.createFile(fProject.getProject(), "h1.h", h1Contents.toString());
|
||||||
IFile h2= TestSourceReader.createFile(fProject.getProject(), "h2.h", contents[1].toString());
|
IFile h2= TestSourceReader.createFile(fProject.getProject(), "h2.h", contents[1].toString());
|
||||||
|
@ -626,6 +626,10 @@ public class IndexIncludeTest extends IndexTestBase {
|
||||||
try {
|
try {
|
||||||
IIndexFile[] indexFiles = fIndex.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(h1));
|
IIndexFile[] indexFiles = fIndex.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(h1));
|
||||||
assertEquals(3, indexFiles.length);
|
assertEquals(3, indexFiles.length);
|
||||||
|
for (IIndexFile indexFile : indexFiles) {
|
||||||
|
assertFalse(indexFile.hasPragmaOnceSemantics());
|
||||||
|
assertEquals(1, fIndex.findIncludedBy(indexFile).length);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
fIndex.releaseReadLock();
|
fIndex.releaseReadLock();
|
||||||
}
|
}
|
||||||
|
@ -647,6 +651,9 @@ public class IndexIncludeTest extends IndexTestBase {
|
||||||
assertEquals(1, indexFiles.length);
|
assertEquals(1, indexFiles.length);
|
||||||
for (IIndexFile indexFile : indexFiles) {
|
for (IIndexFile indexFile : indexFiles) {
|
||||||
assertTrue("Timestamp not ok", indexFile.getTimestamp() >= t1);
|
assertTrue("Timestamp not ok", indexFile.getTimestamp() >= t1);
|
||||||
|
assertTrue(indexFile.hasPragmaOnceSemantics());
|
||||||
|
// Included twice by h2.h and once by s1.cpp
|
||||||
|
assertEquals(2, fIndex.findIncludedBy(indexFile).length);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
fIndex.releaseReadLock();
|
fIndex.releaseReadLock();
|
||||||
|
@ -669,6 +676,8 @@ public class IndexIncludeTest extends IndexTestBase {
|
||||||
assertEquals(3, indexFiles.length);
|
assertEquals(3, indexFiles.length);
|
||||||
for (IIndexFile indexFile : indexFiles) {
|
for (IIndexFile indexFile : indexFiles) {
|
||||||
assertTrue("Timestamp not ok", indexFile.getTimestamp() >= t2);
|
assertTrue("Timestamp not ok", indexFile.getTimestamp() >= t2);
|
||||||
|
assertFalse(indexFile.hasPragmaOnceSemantics());
|
||||||
|
assertEquals(1, fIndex.findIncludedBy(indexFile).length);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
fIndex.releaseReadLock();
|
fIndex.releaseReadLock();
|
||||||
|
|
|
@ -295,22 +295,25 @@ public class CIndex implements IIndex {
|
||||||
|
|
||||||
public IIndexInclude[] findIncludedBy(IIndexFile file, int depth) throws CoreException {
|
public IIndexInclude[] findIncludedBy(IIndexFile file, int depth) throws CoreException {
|
||||||
List<IIndexInclude> result= new ArrayList<IIndexInclude>();
|
List<IIndexInclude> result= new ArrayList<IIndexInclude>();
|
||||||
findIncludedBy(Collections.singletonList(file), result, depth, new HashSet<IIndexFileLocation>());
|
findIncludedBy(file.getLinkageID(), Collections.singletonList(file), result, depth,
|
||||||
|
new HashSet<FileContentKey>());
|
||||||
return result.toArray(new IIndexInclude[result.size()]);
|
return result.toArray(new IIndexInclude[result.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void findIncludedBy(List<IIndexFile> in, List<IIndexInclude> out, int depth,
|
public void findIncludedBy(int linkageID, List<IIndexFile> in, List<IIndexInclude> out, int depth,
|
||||||
HashSet<IIndexFileLocation> handled) throws CoreException {
|
HashSet<FileContentKey> handled) throws CoreException {
|
||||||
List<IIndexFile> nextLevel= depth != 0 ? new LinkedList<IIndexFile>() : null;
|
List<IIndexFile> nextLevel= depth != 0 ? new LinkedList<IIndexFile>() : null;
|
||||||
for (IIndexFile iIndexFile : in) {
|
for (IIndexFile iIndexFile : in) {
|
||||||
IIndexFragmentFile file = (IIndexFragmentFile) iIndexFile;
|
IIndexFragmentFile file = (IIndexFragmentFile) iIndexFile;
|
||||||
for (int j = 0; j < fPrimaryFragmentCount; j++) {
|
for (int j = 0; j < fPrimaryFragmentCount; j++) {
|
||||||
IIndexInclude[] includedBy= fFragments[j].findIncludedBy(file);
|
IIndexInclude[] includedBy= fFragments[j].findIncludedBy(file);
|
||||||
for (IIndexInclude include : includedBy) {
|
for (IIndexInclude include : includedBy) {
|
||||||
if (handled.add(include.getIncludedByLocation())) {
|
final IIndexFile includer = include.getIncludedBy();
|
||||||
|
FileContentKey key= new FileContentKey(linkageID, includer.getLocation(), includer.getSignificantMacros());
|
||||||
|
if (handled.add(key)) {
|
||||||
out.add(include);
|
out.add(include);
|
||||||
if (nextLevel != null) {
|
if (nextLevel != null) {
|
||||||
nextLevel.add(include.getIncludedBy());
|
nextLevel.add(includer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,7 +325,7 @@ public class CIndex implements IIndex {
|
||||||
if (depth > 0) {
|
if (depth > 0) {
|
||||||
depth--;
|
depth--;
|
||||||
}
|
}
|
||||||
findIncludedBy(nextLevel, out, depth, handled);
|
findIncludedBy(linkageID, nextLevel, out, depth, handled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexInclude[] findIncludes(IIndexFile file) throws CoreException {
|
public IIndexInclude[] findIncludes(IIndexFile file) throws CoreException {
|
||||||
|
|
|
@ -49,6 +49,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayMap;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
|
||||||
|
import org.eclipse.cdt.core.parser.util.CharArraySet;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||||
import org.eclipse.cdt.internal.core.parser.EmptyFilesProvider;
|
import org.eclipse.cdt.internal.core.parser.EmptyFilesProvider;
|
||||||
|
@ -232,6 +233,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
private final CharArrayMap<PreprocessorMacro> fMacroDictionary = new CharArrayMap<PreprocessorMacro>(512);
|
private final CharArrayMap<PreprocessorMacro> fMacroDictionary = new CharArrayMap<PreprocessorMacro>(512);
|
||||||
private final IMacroDictionary fMacroDictionaryFacade = new MacroDictionary();
|
private final IMacroDictionary fMacroDictionaryFacade = new MacroDictionary();
|
||||||
private final LocationMap fLocationMap;
|
private final LocationMap fLocationMap;
|
||||||
|
private CharArraySet fPreventInclusion= new CharArraySet(0);
|
||||||
|
|
||||||
private final Lexer fRootLexer;
|
private final Lexer fRootLexer;
|
||||||
private final ScannerContext fRootContext;
|
private final ScannerContext fRootContext;
|
||||||
|
@ -296,7 +298,6 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
fPreIncludedFiles= new String[][] { einfo.getMacroFiles(), einfo.getIncludeFiles() };
|
fPreIncludedFiles= new String[][] { einfo.getMacroFiles(), einfo.getIncludeFiles() };
|
||||||
}
|
}
|
||||||
fFileContentProvider.resetForTranslationUnit();
|
fFileContentProvider.resetForTranslationUnit();
|
||||||
detectIncludeGuard(filePath, fRootContent.getSource(), fRootContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private char[] detectIncludeGuard(String filePath, AbstractCharArray source, ScannerContext ctx) {
|
private char[] detectIncludeGuard(String filePath, AbstractCharArray source, ScannerContext ctx) {
|
||||||
|
@ -442,15 +443,18 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void beforeFirstFetchToken() {
|
private void beforeFirstFetchToken() {
|
||||||
|
if (fPreIncludedFiles != null) {
|
||||||
|
handlePreIncludedFiles();
|
||||||
|
fPreIncludedFiles= null;
|
||||||
|
}
|
||||||
final String location = fLocationMap.getTranslationUnitPath();
|
final String location = fLocationMap.getTranslationUnitPath();
|
||||||
InternalFileContent content= fFileContentProvider.getContentForContextToHeaderGap(location,
|
InternalFileContent content= fFileContentProvider.getContentForContextToHeaderGap(location,
|
||||||
fMacroDictionaryFacade);
|
fMacroDictionaryFacade);
|
||||||
if (content != null && content.getKind() == InclusionKind.FOUND_IN_INDEX) {
|
if (content != null && content.getKind() == InclusionKind.FOUND_IN_INDEX) {
|
||||||
processInclusionFromIndex(0, location, content);
|
processInclusionFromIndex(0, location, content, false);
|
||||||
fPreIncludedFiles= null;
|
|
||||||
} else if (fPreIncludedFiles != null) {
|
|
||||||
handlePreIncludedFiles();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
detectIncludeGuard(location, fRootContent.getSource(), fRootContext);
|
||||||
fLocationMap.parsingFile(fFileContentProvider, fRootContent);
|
fLocationMap.parsingFile(fFileContentProvider, fRootContent);
|
||||||
fRootContent= null;
|
fRootContent= null;
|
||||||
}
|
}
|
||||||
|
@ -1359,9 +1363,10 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (active && fCurrentContext.getDepth() == MAX_INCLUSION_DEPTH) {
|
if (active && fCurrentContext.getDepth() == MAX_INCLUSION_DEPTH || fPreventInclusion.containsKey(headerName)) {
|
||||||
handleProblem(IProblem.PREPROCESSOR_EXCEEDS_MAXIMUM_INCLUSION_DEPTH,
|
handleProblem(IProblem.PREPROCESSOR_EXCEEDS_MAXIMUM_INCLUSION_DEPTH,
|
||||||
lexer.getInputChars(poundOffset, condEndOffset), poundOffset, condEndOffset);
|
lexer.getInputChars(poundOffset, condEndOffset), poundOffset, condEndOffset);
|
||||||
|
fPreventInclusion.put(headerName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1432,7 +1437,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
processInclusionFromIndex(poundOffset, path, fi);
|
processInclusionFromIndex(poundOffset, path, fi, true);
|
||||||
break;
|
break;
|
||||||
case USE_SOURCE:
|
case USE_SOURCE:
|
||||||
// Will be parsed
|
// Will be parsed
|
||||||
|
@ -1445,7 +1450,6 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
fctx.setFoundOnPath(fi.getFoundOnPath(), includeDirective);
|
fctx.setFoundOnPath(fi.getFoundOnPath(), includeDirective);
|
||||||
detectIncludeGuard(path, source, fctx);
|
detectIncludeGuard(path, source, fctx);
|
||||||
fCurrentContext= fctx;
|
fCurrentContext= fctx;
|
||||||
fLocationMap.parsingFile(fFileContentProvider, fi);
|
|
||||||
stmt= ctx.getInclusionStatement();
|
stmt= ctx.getInclusionStatement();
|
||||||
stmt.setContentsHash(source.getContentsHash());
|
stmt.setContentsHash(source.getContentsHash());
|
||||||
if (!fCurrentContext.isPragmaOnce()) {
|
if (!fCurrentContext.isPragmaOnce()) {
|
||||||
|
@ -1472,11 +1476,12 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processInclusionFromIndex(int offset, String path, InternalFileContent fi) {
|
private void processInclusionFromIndex(int offset, String path, InternalFileContent fi, boolean updateContext) {
|
||||||
List<IIndexMacro> mdefs= fi.getMacroDefinitions();
|
List<IIndexMacro> mdefs= fi.getMacroDefinitions();
|
||||||
for (IIndexMacro macro : mdefs) {
|
for (IIndexMacro macro : mdefs) {
|
||||||
addMacroDefinition(macro);
|
addMacroDefinition(macro);
|
||||||
fCurrentContext.internalModification(macro.getNameCharArray());
|
if (updateContext)
|
||||||
|
fCurrentContext.internalModification(macro.getNameCharArray());
|
||||||
}
|
}
|
||||||
for (FileVersion version : fi.getNonPragmaOnceVersions()) {
|
for (FileVersion version : fi.getNonPragmaOnceVersions()) {
|
||||||
fFileContentProvider.addLoadedVersions(version.fPath, Integer.MAX_VALUE, version.fSigMacros);
|
fFileContentProvider.addLoadedVersions(version.fPath, Integer.MAX_VALUE, version.fSigMacros);
|
||||||
|
|
|
@ -801,7 +801,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
if (locTask == null || locTask.isCompleted()) {
|
if (locTask == null || locTask.isCompleted()) {
|
||||||
it.remove();
|
it.remove();
|
||||||
} else {
|
} else {
|
||||||
for (FileVersionTask versionTask : locTask.fVersionTasks) {
|
// Additional version tasks may be added while parsing a file,
|
||||||
|
// use an integer to iterate over the list.
|
||||||
|
final List<FileVersionTask> versionTasks = locTask.fVersionTasks;
|
||||||
|
for (int i=0; i<versionTasks.size(); i++) {
|
||||||
|
FileVersionTask versionTask = versionTasks.get(i);
|
||||||
if (versionTask.fUpdateRequested) {
|
if (versionTask.fUpdateRequested) {
|
||||||
if (monitor.isCanceled() || hasUrgentTasks())
|
if (monitor.isCanceled() || hasUrgentTasks())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1084,12 +1084,14 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
||||||
assert monitor != null;
|
assert monitor != null;
|
||||||
Thread th= null;
|
Thread th= null;
|
||||||
if (waitMaxMillis != FOREVER) {
|
if (waitMaxMillis != FOREVER) {
|
||||||
|
final Thread callingThread= Thread.currentThread();
|
||||||
th= new Thread() {
|
th= new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(waitMaxMillis);
|
Thread.sleep(waitMaxMillis);
|
||||||
monitor.setCanceled(true);
|
monitor.setCanceled(true);
|
||||||
|
callingThread.interrupt();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,9 +224,9 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
}
|
}
|
||||||
PDOMInclude last= getFirstIncludedBy();
|
PDOMInclude last= getFirstIncludedBy();
|
||||||
if (last == null) {
|
if (last == null) {
|
||||||
setFirstInclude(include);
|
setFirstIncludedBy(include);
|
||||||
} else {
|
} else {
|
||||||
for (PDOMInclude i=include; i != null; i= i.getNextInIncludedBy()) {
|
for (PDOMInclude i=last; i != null; i= i.getNextInIncludedBy()) {
|
||||||
last= i;
|
last= i;
|
||||||
}
|
}
|
||||||
last.setNextInIncludedBy(include);
|
last.setNextInIncludedBy(include);
|
||||||
|
@ -529,7 +529,6 @@ public class PDOMFile implements IIndexFragmentFile {
|
||||||
m.delete();
|
m.delete();
|
||||||
}
|
}
|
||||||
setFirstMacroReference(null);
|
setFirstMacroReference(null);
|
||||||
setPragmaOnceSemantics(false);
|
|
||||||
setTimestamp(-1);
|
setTimestamp(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue