mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Enforce pragma once semantics for headers shown in editor, bug 249884.
This commit is contained in:
parent
3f17f6cdbd
commit
67b68db542
4 changed files with 64 additions and 2 deletions
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.IName;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
@ -1423,4 +1424,50 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
fIndex.releaseReadLock();
|
fIndex.releaseReadLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #ifndef B_H
|
||||||
|
// #include "b.h"
|
||||||
|
// #endif
|
||||||
|
//
|
||||||
|
// #ifndef A_H_
|
||||||
|
// #define A_H_
|
||||||
|
// int aOK;
|
||||||
|
// #endif /* A_H_ */
|
||||||
|
|
||||||
|
// #ifndef A_H_
|
||||||
|
// #include "a.h"
|
||||||
|
// #endif
|
||||||
|
//
|
||||||
|
// #ifndef B_H_
|
||||||
|
// #define B_H_
|
||||||
|
// int bOK;
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// #include "a.h"
|
||||||
|
public void testStrangeIncludeStrategy_Bug249884() throws Exception {
|
||||||
|
String[] contents= getContentsForTest(3);
|
||||||
|
final IIndexManager indexManager = CCorePlugin.getIndexManager();
|
||||||
|
IFile ah= TestSourceReader.createFile(fCProject.getProject(), "a.h", contents[0]);
|
||||||
|
TestSourceReader.createFile(fCProject.getProject(), "b.h", contents[1]);
|
||||||
|
TestSourceReader.createFile(fCProject.getProject(), "source.cpp", contents[2]);
|
||||||
|
indexManager.reindex(fCProject);
|
||||||
|
waitForIndexer();
|
||||||
|
ITranslationUnit tu= (ITranslationUnit) CoreModel.getDefault().create(ah);
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
IIndexBinding[] bindings= fIndex.findBindings("aOK".toCharArray(), IndexFilter.ALL_DECLARED, new NullProgressMonitor());
|
||||||
|
assertEquals(1, bindings.length);
|
||||||
|
fIndex.findBindings("bOK".toCharArray(), IndexFilter.ALL_DECLARED, new NullProgressMonitor());
|
||||||
|
assertEquals(1, bindings.length);
|
||||||
|
IASTTranslationUnit ast= tu.getAST(fIndex, ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
|
||||||
|
final IASTDeclaration[] decls = ast.getDeclarations();
|
||||||
|
assertEquals(1, decls.length);
|
||||||
|
IASTSimpleDeclaration decl= (IASTSimpleDeclaration) decls[0];
|
||||||
|
assertEquals("aOK", decl.getDeclarators()[0].getName().toString());
|
||||||
|
} finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -115,6 +115,11 @@ public final class IndexBasedCodeReaderFactory extends AbstractCodeReaderFactory
|
||||||
return fPathResolver.doesIncludeFileExist(path);
|
return fPathResolver.doesIncludeFileExist(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reportTranslationUnitFile(String path) {
|
||||||
|
IIndexFileLocation ifl= fPathResolver.resolveASTPath(path);
|
||||||
|
fIncludedFiles.add(ifl);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
public boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
||||||
IIndexFileLocation ifl= fPathResolver.resolveASTPath(path);
|
IIndexFileLocation ifl= fPathResolver.resolveASTPath(path);
|
||||||
return fIncludedFiles.contains(ifl);
|
return fIncludedFiles.contains(ifl);
|
||||||
|
|
|
@ -180,7 +180,9 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
|
|
||||||
final String filePath= new String(reader.filename);
|
final String filePath= new String(reader.filename);
|
||||||
fAllIncludedFiles.add(filePath);
|
fAllIncludedFiles.add(filePath);
|
||||||
ILocationCtx ctx= fLocationMap.pushTranslationUnit(filePath, reader.buffer);
|
ILocationCtx ctx= fLocationMap.pushTranslationUnit(filePath, reader.buffer);
|
||||||
|
fCodeReaderFactory.reportTranslationUnitFile(filePath);
|
||||||
|
fAllIncludedFiles.add(filePath);
|
||||||
fRootLexer= new Lexer(reader.buffer, fLexOptions, this, this);
|
fRootLexer= new Lexer(reader.buffer, fLexOptions, this, this);
|
||||||
fRootContext= fCurrentContext= new ScannerContext(ctx, null, fRootLexer);
|
fRootContext= fCurrentContext= new ScannerContext(ctx, null, fRootLexer);
|
||||||
if (info instanceof IExtendedScannerInfo) {
|
if (info instanceof IExtendedScannerInfo) {
|
||||||
|
@ -207,6 +209,9 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public void reportTranslationUnitFile(String path) {
|
||||||
|
fAllIncludedFiles.add(path);
|
||||||
|
}
|
||||||
public boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
public boolean hasFileBeenIncludedInCurrentTranslationUnit(String path) {
|
||||||
return fAllIncludedFiles.contains(path);
|
return fAllIncludedFiles.contains(path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,12 @@ public interface IIndexBasedCodeReaderFactory extends ICodeReaderFactory {
|
||||||
* Returns whether or not the file has been included.
|
* Returns whether or not the file has been included.
|
||||||
*/
|
*/
|
||||||
boolean hasFileBeenIncludedInCurrentTranslationUnit(String path);
|
boolean hasFileBeenIncludedInCurrentTranslationUnit(String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports the path of the translation unit, such that it is known as included.
|
||||||
|
*/
|
||||||
|
void reportTranslationUnitFile(String path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an InclusionContent object for the given location.
|
* Create an InclusionContent object for the given location.
|
||||||
* return an inclusion content or <code>null</code> if the location does not exist.
|
* return an inclusion content or <code>null</code> if the location does not exist.
|
||||||
|
|
Loading…
Add table
Reference in a new issue