mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 03:53:21 +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");
|
||||
waitForIndexer();
|
||||
TestScannerProvider.sIncludes= new String[] { fProject.getProject().getLocation().toOSString() };
|
||||
CharSequence[] contents= getContentsForTest(4);
|
||||
CharSequence[] contents= getContentsForTest(5);
|
||||
final CharSequence h1Contents = contents[0];
|
||||
final IFile h1= TestSourceReader.createFile(fProject.getProject(), "h1.h", h1Contents.toString());
|
||||
IFile h2= TestSourceReader.createFile(fProject.getProject(), "h2.h", contents[1].toString());
|
||||
|
@ -626,6 +626,10 @@ public class IndexIncludeTest extends IndexTestBase {
|
|||
try {
|
||||
IIndexFile[] indexFiles = fIndex.getFiles(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(h1));
|
||||
assertEquals(3, indexFiles.length);
|
||||
for (IIndexFile indexFile : indexFiles) {
|
||||
assertFalse(indexFile.hasPragmaOnceSemantics());
|
||||
assertEquals(1, fIndex.findIncludedBy(indexFile).length);
|
||||
}
|
||||
} finally {
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
|
@ -647,6 +651,9 @@ public class IndexIncludeTest extends IndexTestBase {
|
|||
assertEquals(1, indexFiles.length);
|
||||
for (IIndexFile indexFile : indexFiles) {
|
||||
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 {
|
||||
fIndex.releaseReadLock();
|
||||
|
@ -669,6 +676,8 @@ public class IndexIncludeTest extends IndexTestBase {
|
|||
assertEquals(3, indexFiles.length);
|
||||
for (IIndexFile indexFile : indexFiles) {
|
||||
assertTrue("Timestamp not ok", indexFile.getTimestamp() >= t2);
|
||||
assertFalse(indexFile.hasPragmaOnceSemantics());
|
||||
assertEquals(1, fIndex.findIncludedBy(indexFile).length);
|
||||
}
|
||||
} finally {
|
||||
fIndex.releaseReadLock();
|
||||
|
|
|
@ -295,22 +295,25 @@ public class CIndex implements IIndex {
|
|||
|
||||
public IIndexInclude[] findIncludedBy(IIndexFile file, int depth) throws CoreException {
|
||||
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()]);
|
||||
}
|
||||
|
||||
public void findIncludedBy(List<IIndexFile> in, List<IIndexInclude> out, int depth,
|
||||
HashSet<IIndexFileLocation> handled) throws CoreException {
|
||||
public void findIncludedBy(int linkageID, List<IIndexFile> in, List<IIndexInclude> out, int depth,
|
||||
HashSet<FileContentKey> handled) throws CoreException {
|
||||
List<IIndexFile> nextLevel= depth != 0 ? new LinkedList<IIndexFile>() : null;
|
||||
for (IIndexFile iIndexFile : in) {
|
||||
IIndexFragmentFile file = (IIndexFragmentFile) iIndexFile;
|
||||
for (int j = 0; j < fPrimaryFragmentCount; j++) {
|
||||
IIndexInclude[] includedBy= fFragments[j].findIncludedBy(file);
|
||||
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);
|
||||
if (nextLevel != null) {
|
||||
nextLevel.add(include.getIncludedBy());
|
||||
nextLevel.add(includer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +325,7 @@ public class CIndex implements IIndex {
|
|||
if (depth > 0) {
|
||||
depth--;
|
||||
}
|
||||
findIncludedBy(nextLevel, out, depth, handled);
|
||||
findIncludedBy(linkageID, nextLevel, out, depth, handled);
|
||||
}
|
||||
|
||||
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.CharArrayMap;
|
||||
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.internal.core.dom.IIncludeFileResolutionHeuristics;
|
||||
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 IMacroDictionary fMacroDictionaryFacade = new MacroDictionary();
|
||||
private final LocationMap fLocationMap;
|
||||
private CharArraySet fPreventInclusion= new CharArraySet(0);
|
||||
|
||||
private final Lexer fRootLexer;
|
||||
private final ScannerContext fRootContext;
|
||||
|
@ -296,7 +298,6 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
fPreIncludedFiles= new String[][] { einfo.getMacroFiles(), einfo.getIncludeFiles() };
|
||||
}
|
||||
fFileContentProvider.resetForTranslationUnit();
|
||||
detectIncludeGuard(filePath, fRootContent.getSource(), fRootContext);
|
||||
}
|
||||
|
||||
private char[] detectIncludeGuard(String filePath, AbstractCharArray source, ScannerContext ctx) {
|
||||
|
@ -442,15 +443,18 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
}
|
||||
|
||||
private void beforeFirstFetchToken() {
|
||||
if (fPreIncludedFiles != null) {
|
||||
handlePreIncludedFiles();
|
||||
fPreIncludedFiles= null;
|
||||
}
|
||||
final String location = fLocationMap.getTranslationUnitPath();
|
||||
InternalFileContent content= fFileContentProvider.getContentForContextToHeaderGap(location,
|
||||
fMacroDictionaryFacade);
|
||||
if (content != null && content.getKind() == InclusionKind.FOUND_IN_INDEX) {
|
||||
processInclusionFromIndex(0, location, content);
|
||||
fPreIncludedFiles= null;
|
||||
} else if (fPreIncludedFiles != null) {
|
||||
handlePreIncludedFiles();
|
||||
processInclusionFromIndex(0, location, content, false);
|
||||
}
|
||||
|
||||
detectIncludeGuard(location, fRootContent.getSource(), fRootContext);
|
||||
fLocationMap.parsingFile(fFileContentProvider, fRootContent);
|
||||
fRootContent= null;
|
||||
}
|
||||
|
@ -1359,9 +1363,10 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
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,
|
||||
lexer.getInputChars(poundOffset, condEndOffset), poundOffset, condEndOffset);
|
||||
fPreventInclusion.put(headerName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1432,7 +1437,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
} catch (CoreException e) {
|
||||
}
|
||||
|
||||
processInclusionFromIndex(poundOffset, path, fi);
|
||||
processInclusionFromIndex(poundOffset, path, fi, true);
|
||||
break;
|
||||
case USE_SOURCE:
|
||||
// Will be parsed
|
||||
|
@ -1445,7 +1450,6 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
|||
fctx.setFoundOnPath(fi.getFoundOnPath(), includeDirective);
|
||||
detectIncludeGuard(path, source, fctx);
|
||||
fCurrentContext= fctx;
|
||||
fLocationMap.parsingFile(fFileContentProvider, fi);
|
||||
stmt= ctx.getInclusionStatement();
|
||||
stmt.setContentsHash(source.getContentsHash());
|
||||
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();
|
||||
for (IIndexMacro macro : mdefs) {
|
||||
addMacroDefinition(macro);
|
||||
fCurrentContext.internalModification(macro.getNameCharArray());
|
||||
if (updateContext)
|
||||
fCurrentContext.internalModification(macro.getNameCharArray());
|
||||
}
|
||||
for (FileVersion version : fi.getNonPragmaOnceVersions()) {
|
||||
fFileContentProvider.addLoadedVersions(version.fPath, Integer.MAX_VALUE, version.fSigMacros);
|
||||
|
|
|
@ -801,7 +801,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
|||
if (locTask == null || locTask.isCompleted()) {
|
||||
it.remove();
|
||||
} 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 (monitor.isCanceled() || hasUrgentTasks())
|
||||
return;
|
||||
|
|
|
@ -1084,12 +1084,14 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
assert monitor != null;
|
||||
Thread th= null;
|
||||
if (waitMaxMillis != FOREVER) {
|
||||
final Thread callingThread= Thread.currentThread();
|
||||
th= new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(waitMaxMillis);
|
||||
monitor.setCanceled(true);
|
||||
callingThread.interrupt();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -224,9 +224,9 @@ public class PDOMFile implements IIndexFragmentFile {
|
|||
}
|
||||
PDOMInclude last= getFirstIncludedBy();
|
||||
if (last == null) {
|
||||
setFirstInclude(include);
|
||||
setFirstIncludedBy(include);
|
||||
} else {
|
||||
for (PDOMInclude i=include; i != null; i= i.getNextInIncludedBy()) {
|
||||
for (PDOMInclude i=last; i != null; i= i.getNextInIncludedBy()) {
|
||||
last= i;
|
||||
}
|
||||
last.setNextInIncludedBy(include);
|
||||
|
@ -529,7 +529,6 @@ public class PDOMFile implements IIndexFragmentFile {
|
|||
m.delete();
|
||||
}
|
||||
setFirstMacroReference(null);
|
||||
setPragmaOnceSemantics(false);
|
||||
setTimestamp(-1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue