From 216bc162a4a40286abb2a131a62e8d65288a6050 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 28 Dec 2016 20:56:32 -0800 Subject: [PATCH] Bug 509749 - Find References doesn't find a reference to a function Change-Id: Id90a80e234638b590266a8671dd1bf13178e0f94 --- .../org.eclipse.cdt.core/META-INF/MANIFEST.MF | 2 +- .../org/eclipse/cdt/core/model/ILanguage.java | 21 +++--- .../internal/core/model/TranslationUnit.java | 3 - .../dom/parser/AbstractCLikeLanguage.java | 4 +- .../eclipse/cdt/core/parser/FileContent.java | 64 ++++++++++++++---- .../org/eclipse/cdt/core/parser/IScanner.java | 55 +++++++++------- .../internal/core/dom/parser/c/CFunction.java | 11 ++++ .../core/dom/parser/c/CNodeFactory.java | 5 +- .../core/dom/parser/cpp/CPPNodeFactory.java | 5 +- .../StandaloneIndexerInputAdapter.java | 9 ++- .../core/parser/scanner/CPreprocessor.java | 14 ++-- .../parser/scanner/InternalFileContent.java | 10 +++ .../core/pdom/AbstractIndexerTask.java | 15 +---- core/org.eclipse.cdt.core/pom.xml | 2 +- .../ui/tests/search/FindReferencesTest.java | 66 ++++++++++++++----- .../cdt/ui/tests/search/SearchTestBase.java | 13 ++-- .../ui/compare/CStructureCreator.java | 9 ++- .../dom/lrparser/BaseExtensibleLanguage.java | 10 +-- .../qt/core/parser/StringScanner.java | 5 -- 19 files changed, 202 insertions(+), 121 deletions(-) diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index cfd08eca523..9187ac3c88a 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true -Bundle-Version: 6.2.0.qualifier +Bundle-Version: 6.3.0.qualifier Bundle-Activator: org.eclipse.cdt.core.CCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java index 2f07b1a22fb..c177b1f6c4c 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java @@ -41,7 +41,7 @@ public interface ILanguage extends IAdaptable { public final static int OPTION_SKIP_FUNCTION_BODIES= 0x1; /** - * @deprecated, has no effect. + * @deprecated, Has no effect. * @noreference This field is not intended to be referenced by clients. */ @Deprecated @@ -55,10 +55,9 @@ public interface ILanguage extends IAdaptable { public final static int OPTION_NO_IMAGE_LOCATIONS= 0x4; /** - * Option for {@link #getASTTranslationUnit(FileContent, IScannerInfo, IncludeFileContentProvider, IIndex, int, IParserLogService)} - * Marks the ast as being based on a source-file rather than a header-file. This makes a difference - * when bindings from the AST are used for searching the index, e.g. for static variables. + * @deprecated, Has no effect. */ + @Deprecated public final static int OPTION_IS_SOURCE_UNIT= 0x8; /** @@ -97,22 +96,20 @@ public interface ILanguage extends IAdaptable { public int getLinkageID(); /** - * @return the human readable name corresponding to this language, suitable for display. + * Returns the human readable name corresponding to this language, suitable for display. * @since 4.0 */ public String getName(); /** - * Construct an AST for the source code provided by reader. - * As an option you can supply + * Constructs an AST for the source code provided by reader. + * * @param content source code to be parsed. * @param scanInfo provides include paths and defined symbols. * @param fileCreator factory that provides file content for files included - * @param index (optional) index to use to lookup symbols external to the tu. - * @param options A combination of - * {@link #OPTION_SKIP_FUNCTION_BODIES}, - * {@link #OPTION_NO_IMAGE_LOCATIONS}, {@link #OPTION_IS_SOURCE_UNIT}, - * or 0. + * @param index (optional) index to use to lookup symbols external to the translation unit. + * @param options A combination of {@link #OPTION_SKIP_FUNCTION_BODIES}, + * {@link #OPTION_NO_IMAGE_LOCATIONS}, or 0. * @param log logger * @return an AST for the source code provided by reader. * @throws CoreException diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java index 5b5f0f99b89..43418911ebd 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java @@ -864,9 +864,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit { if ((style & AST_PARSE_INACTIVE_CODE) != 0) { options |= ILanguage.OPTION_PARSE_INACTIVE_CODE; } - if (isSourceUnit()) { - options |= ILanguage.OPTION_IS_SOURCE_UNIT; - } final IParserLogService log; if (monitor instanceof ICanceler) { log= new ParserLogService(DebugLogConstants.PARSER, (ICanceler) monitor); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java index 15ee4e1d952..283398f2088 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java @@ -164,9 +164,7 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements try { // Parse - IASTTranslationUnit ast= parser.parse(); - ast.setIsHeaderUnit((options & OPTION_IS_SOURCE_UNIT) == 0); - return ast; + return parser.parse(); } catch (ParseError e) { // Only the TOO_MANY_TOKENS error can be handled here. if (e.getErrorKind() != ParseErrorKind.TOO_MANY_TOKENS) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/FileContent.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/FileContent.java index 8594ace9c3c..d8ec351a596 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/FileContent.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/FileContent.java @@ -77,6 +77,7 @@ public abstract class FileContent { /** * Creates a file content object for a fixed buffer. + * * @param filePath the path of the file as it will appear in {@link IASTFileLocation#getFileName()} * @param contents the actual content. */ @@ -84,23 +85,45 @@ public abstract class FileContent { return new InternalFileContent(filePath, new CharArray(contents)); } + /** + * Creates a file content object for a fixed buffer. + * + * @param filePath the path of the file as it will appear in {@link IASTFileLocation#getFileName()} + * @param contents the actual content. + * @since 6.3 + */ + public static FileContent create(String filePath, boolean isSource, char[] contents) { + InternalFileContent fileContent = new InternalFileContent(filePath, new CharArray(contents)); + fileContent.setIsSource(isSource); + return fileContent; + } + /** * Creates a file content object for a translation-unit, which may be a working copy. */ public static FileContent create(ITranslationUnit tu) { + InternalFileContent fileContent; + IPath location= tu.getLocation(); - if (location == null) - return create(tu.getElementName(), tu.getContents()); - - if (tu.isWorkingCopy()) { - return create(location.toOSString(), tu.getContents()); + if (location == null) { + fileContent = new InternalFileContent(tu.getElementName(), new CharArray(tu.getContents())); + } else if (tu.isWorkingCopy()) { + fileContent = new InternalFileContent(location.toOSString(), new CharArray(tu.getContents())); + } else { + IResource res= tu.getResource(); + if (res instanceof IFile) { + fileContent = InternalParserUtil.createWorkspaceFileContent((IFile) res); + } else { + fileContent = InternalParserUtil.createExternalFileContent(location.toOSString(), + InternalParserUtil.SYSTEM_DEFAULT_ENCODING); + } } - - IResource res= tu.getResource(); - if (res instanceof IFile) { - return create((IFile) res); + + if (fileContent != null) { + fileContent.setTranslationUnit(tu); + fileContent.setIsSource(tu.isSourceUnit()); } - return createForExternalFileLocation(location.toOSString()); + return fileContent; } /** @@ -111,22 +134,37 @@ public abstract class FileContent { } /** - * Creates a file content for a workspace file + * Creates a file content for a workspace header file. */ public static FileContent create(IFile file) { return InternalParserUtil.createWorkspaceFileContent(file); } + /** + * Creates a file content object for a header file that is not part of the workspace. + */ public static FileContent createForExternalFileLocation(String fileLocation) { return createForExternalFileLocation(fileLocation, InternalParserUtil.SYSTEM_DEFAULT_ENCODING); } /** - * Creates a file content object for a file location that is not part of the workspace + * Creates a file content object for a header file that is not part of the workspace. * @since 5.3 */ public static FileContent createForExternalFileLocation(String fileLocation, String encoding) { - return InternalParserUtil.createExternalFileContent(fileLocation, encoding); + return createForExternalFileLocation(fileLocation, false, encoding); + } + + /** + * Creates a file content object for a header or a source file that is not part of the workspace. + * @since 6.3 + */ + public static FileContent createForExternalFileLocation(String fileLocation, boolean isSource, + String encoding) { + InternalFileContent fileContent = InternalParserUtil.createExternalFileContent(fileLocation, encoding); + if (fileContent != null) + fileContent.setIsSource(isSource); + return fileContent; } /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java index ecaf2757a1f..7d0baaca3ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver; import org.eclipse.cdt.internal.core.parser.scanner.Lexer; /** - * Interface between the parser and the preprocessor. + * Interface between the parser and the preprocessor. * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. @@ -27,7 +27,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.Lexer; public interface IScanner { /** * Returns a map from {@link String} to {@link IMacroBinding} containing - * all the definitions that are defined at the current point in the + * all the definitions that are defined at the current point in the * process of scanning. */ public Map getMacroDefinitions(); @@ -38,25 +38,27 @@ public interface IScanner { * @throws OffsetLimitReachedException see {@link Lexer}. */ public IToken nextToken() throws EndOfFileException; - + /** - * Returns true, whenever we are processing the outermost file of the translation unit. + * Returns {@code true}, whenever we are processing the outermost file of the translation unit. */ public boolean isOnTopContext(); - + /** * Attempts to cancel the scanner. */ public void cancel(); - + /** * Returns the location resolver associated with this scanner. + * * @noreference This method is not intended to be referenced by clients. */ public ILocationResolver getLocationResolver(); - + /** * Puts the scanner into content assist mode. + * * @noreference This method is not intended to be referenced by clients. */ public void setContentAssistMode(int offset); @@ -64,25 +66,26 @@ public interface IScanner { /** * Instructs the scanner to split tokens of kind {@link IToken#tSHIFTR} into two tokens of * kind {@link IToken#tGT_in_SHIFTR}. + * * @noreference This method is not intended to be referenced by clients. */ public void setSplitShiftROperator(boolean val); - + /** - * Turns on/off creation of image locations. + * Turns on/off creation of image locations. * @see org.eclipse.cdt.core.dom.ast.IASTName#getImageLocation() + * * @noreference This method is not intended to be referenced by clients. * @since 5.0 */ public void setComputeImageLocations(boolean val); /** - * Turns on/off tracking if exported included files. + * Turns on/off tracking if exported included files. * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement#isIncludedFileExported() * @see IncludeExportPatterns * - * @param patterns if not {{@code null}, include export tracking is enabled, otherwise it is - * disabled + * @param patterns if not {@code null}, include export tracking is enabled, otherwise it is disabled * * @noreference This method is not intended to be referenced by clients. * @since 5.5 @@ -93,14 +96,16 @@ public interface IScanner { * Toggles generation of tokens for inactive code branches. When turned on, * each inactive code branch is preceded by a token of kind {@link IToken#tINACTIVE_CODE_START} and * succeeded by one of kind {@link IToken#tINACTIVE_CODE_END}. - * + * * @noreference This method is not intended to be referenced by clients. */ public void setProcessInactiveCode(boolean val); /** - * When in inactive code, skips all tokens up to the end of the inactive code section. - *

Note, token after calling this method may be another token of type {@link IToken#tINACTIVE_CODE_START}. + * When in inactive code, skips all tokens up to the end of the inactive code section. + *

Note, token after calling this method may be another token of type + * {@link IToken#tINACTIVE_CODE_START}. + * * @noreference This method is not intended to be referenced by clients. */ public void skipInactiveCode() throws OffsetLimitReachedException; @@ -109,21 +114,23 @@ public interface IScanner { * Returns the current nesting in code branches. * @see IInactiveCodeToken#getOldNesting() * @see IInactiveCodeToken#getNewNesting() + * * @noreference This method is not intended to be referenced by clients. */ public int getCodeBranchNesting(); - + + /** + * Returns a list of additional (compiler specific) suffixes which can + * be placed on numbers. e.g. 'u' 'l' -> 1l or 1u. + * + * @noreference This method is not intended to be referenced by clients. + */ + public char[] getAdditionalNumericLiteralSuffixes(); + /** * @deprecated Has no effect. * @noreference This method is not intended to be referenced by clients. */ @Deprecated - public void setScanComments(boolean val); - - /** - * Returns a list of additional (compiler specific) suffixes which can - * be placed on numbers. e.g. 'u' 'l' -> 1l or 1u. - * @noreference This method is not intended to be referenced by clients. - */ - public char[] getAdditionalNumericLiteralSuffixes(); + public default void setScanComments(boolean val) {} } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java index 66f5668cb76..e0309e78031 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.dom.parser.c; import org.eclipse.cdt.core.dom.ILinkage; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; @@ -506,4 +507,14 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu } return null; } + + /** For debugging only. */ + @Override + public String toString() { + StringBuilder result = new StringBuilder(); + result.append(getName()); + IFunctionType t = getType(); + result.append(t != null ? ASTTypeUtil.getParameterTypeStringAndQualifiers(t) : "()"); //$NON-NLS-1$ + return result.toString(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java index bfb27578ae8..4a81d8f03b4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java @@ -447,7 +447,10 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory { if (scanner != null) { tu.setLocationResolver(scanner.getLocationResolver()); if (scanner instanceof CPreprocessor) { - tu.setIsForContentAssist(((CPreprocessor) scanner).isContentAssistMode()); + CPreprocessor cPreprocessor = (CPreprocessor) scanner; + tu.setIsForContentAssist(cPreprocessor.isContentAssistMode()); + tu.setOriginatingTranslationUnit(cPreprocessor.getTranslationUnit()); + tu.setIsHeaderUnit(!cPreprocessor.isSource()); } } tu.setASTNodeFactory(this); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java index 3712859eaee..2492e217808 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java @@ -770,7 +770,10 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory { if (scanner != null) { tu.setLocationResolver(scanner.getLocationResolver()); if (scanner instanceof CPreprocessor) { - tu.setIsForContentAssist(((CPreprocessor) scanner).isContentAssistMode()); + CPreprocessor cPreprocessor = (CPreprocessor) scanner; + tu.setIsForContentAssist(cPreprocessor.isContentAssistMode()); + tu.setOriginatingTranslationUnit(cPreprocessor.getTranslationUnit()); + tu.setIsHeaderUnit(!cPreprocessor.isSource()); } } tu.setASTNodeFactory(this); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java index e38fe25da9a..201168d4062 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java @@ -166,18 +166,17 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter { String stu = tu.toString(); String fileEncoding = getFileEncoding(stu); - return FileContent.createForExternalFileLocation(stu, fileEncoding); + return FileContent.createForExternalFileLocation(stu, isSource(stu), fileEncoding); } public String getFileEncoding(String stu) { String fileEncoding = null; - // query file's encoding, if we find it and use it to create CodeReader + // Query file's encoding, if we find it and use it to create CodeReader FileEncodingRegistry fileEncodingRegistry = fIndexer.getFileEncodingRegistry(); - if(fileEncodingRegistry != null){ + if (fileEncodingRegistry != null) fileEncoding = fileEncodingRegistry.getFileEncoding(stu); - } if (fileEncoding == null) - return InternalParserUtil.SYSTEM_DEFAULT_ENCODING; + fileEncoding = InternalParserUtil.SYSTEM_DEFAULT_ENCODING; return fileEncoding; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index ed9673134bc..9198bbbfbc9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IFileNomination; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.index.IIndexMacro; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.AbstractParserLogService; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.ExtendedScannerInfo; @@ -262,7 +263,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { private final ScannerContext fRootContext; protected ScannerContext fCurrentContext; - private boolean isCancelled= false; + private boolean isCancelled; private boolean fIsFirstFetchToken= true; private Token fPrefetchedTokens; @@ -273,8 +274,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { // Detection of include guards used around an include directive private char[] fExternIncludeGuard; - private Set fTracedGuards; - + private Set fTracedGuards; public CPreprocessor(FileContent fileContent, IScannerInfo info, ParserLanguage language, IParserLogService log, IScannerExtensionConfiguration configuration, @@ -386,8 +386,12 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { fRootContext.setParseInactiveCode(val); } - @Override - public void setScanComments(boolean val) { + public ITranslationUnit getTranslationUnit() { + return fRootContent.getTranslationUnit(); + } + + public boolean isSource() { + return fRootContent.isSource(); } @Override diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/InternalFileContent.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/InternalFileContent.java index 77b0c0a27c6..798b4c1c545 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/InternalFileContent.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/InternalFileContent.java @@ -16,6 +16,7 @@ import java.util.List; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexMacro; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.FileContent; import org.eclipse.cdt.core.parser.ISignificantMacros; @@ -56,6 +57,7 @@ public class InternalFileContent extends FileContent { private final List fNonPragmaOnceFiles; private boolean fHeuristic; private boolean fIsSource; + private ITranslationUnit fTranslationUnit; private List fFiles; private IncludeSearchPathElement fFoundOnPath; private final long fTimestamp; @@ -246,6 +248,14 @@ public class InternalFileContent extends FileContent { fIsSource= isSource; } + public ITranslationUnit getTranslationUnit() { + return fTranslationUnit; + } + + public void setTranslationUnit(ITranslationUnit tu) { + fTranslationUnit = tu; + } + public IncludeSearchPathElement getFoundOnPath() { return fFoundOnPath; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java index 95dcb4ad34f..a56cef418d7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java @@ -53,7 +53,6 @@ import org.eclipse.cdt.core.index.IPDOMASTProcessor; import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.model.AbstractLanguage; import org.eclipse.cdt.core.model.ILanguage; -import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.ExtendedScannerInfo; import org.eclipse.cdt.core.parser.FileContent; import org.eclipse.cdt.core.parser.IParserLogService; @@ -63,7 +62,6 @@ import org.eclipse.cdt.core.parser.ISignificantMacros; import org.eclipse.cdt.core.parser.IncludeExportPatterns; import org.eclipse.cdt.core.parser.IncludeFileContentProvider; import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics; -import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit; import org.eclipse.cdt.internal.core.index.FileContentKey; import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; @@ -1088,19 +1086,15 @@ public abstract class AbstractIndexerTask extends PDOMWriter { progress.subTask(getMessage(MessageKind.parsingFileTask, path.lastSegment(), path.removeLastSegments(1).toString())); FileContent codeReader= fResolver.getCodeReader(tu); - final boolean isSource = fResolver.isSourceUnit(tu); long start= System.currentTimeMillis(); ASTTypeUtil.startTranslationUnit(); IASTTranslationUnit ast= - createAST(lang, codeReader, scanInfo, isSource, fASTOptions, ctx, progress.split(10)); + createAST(lang, codeReader, scanInfo, fASTOptions, ctx, progress.split(10)); fStatistics.fParsingTime += System.currentTimeMillis() - start; if (ast == null) { ++fStatistics.fTooManyTokensCount; } else { - // Give the new AST a chance to recognize its translation unit before it is written - // to the index. - ((ASTTranslationUnit) ast).setOriginatingTranslationUnit((ITranslationUnit) tu); writeToIndex(lang.getLinkageID(), ast, codeReader, ctx, progress.split(10)); resultCacheCleared = true; // The cache was cleared while writing to the index. } @@ -1204,14 +1198,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } private final IASTTranslationUnit createAST(AbstractLanguage language, FileContent codeReader, - IScannerInfo scanInfo, boolean isSource, int options, - FileContext ctx, IProgressMonitor monitor) throws CoreException { + IScannerInfo scanInfo, int options, FileContext ctx, IProgressMonitor monitor) + throws CoreException { if (codeReader == null) { return null; } - if (isSource) { - options |= ILanguage.OPTION_IS_SOURCE_UNIT; - } if (fTranslationUnitSizeLimit > 0 && fResolver.getFileSize(codeReader.getFileLocation()) > fTranslationUnitSizeLimit) { if (fShowActivity) { trace("Indexer: Skipping large file " + codeReader.getFileLocation()); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/pom.xml b/core/org.eclipse.cdt.core/pom.xml index 5ae406875be..0204b6ad6eb 100644 --- a/core/org.eclipse.cdt.core/pom.xml +++ b/core/org.eclipse.cdt.core/pom.xml @@ -11,7 +11,7 @@ ../../pom.xml - 6.2.0-SNAPSHOT + 6.3.0-SNAPSHOT org.eclipse.cdt.core eclipse-plugin diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/FindReferencesTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/FindReferencesTest.java index 6844efb2a7b..963a1017f3b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/FindReferencesTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/FindReferencesTest.java @@ -7,6 +7,7 @@ *******************************************************************************/ package org.eclipse.cdt.ui.tests.search; +import org.eclipse.core.resources.IFile; import org.eclipse.jface.text.TextSelection; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPage; @@ -38,11 +39,11 @@ public class FindReferencesTest extends SearchTestBase { return suite(FindReferencesTest.class); } - private CSearchQuery makeProjectQuery(int offset, int length) { + private CSearchQuery makeSearchQuery(IFile file, TextSelection selection) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart part = null; try { - part = page.openEditor(new FileEditorInput(fHeaderFile), "org.eclipse.cdt.ui.editor.CEditor"); //$NON-NLS-1$ + part = page.openEditor(new FileEditorInput(file), "org.eclipse.cdt.ui.editor.CEditor"); //$NON-NLS-1$ } catch (PartInitException e) { assertFalse(true); } @@ -50,27 +51,41 @@ public class FindReferencesTest extends SearchTestBase { CEditor editor = (CEditor) part; EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 5000, 10); ITranslationUnit tu = editor.getInputCElement(); - return new CSearchTextSelectionQuery(new ICElement[] { fCProject }, tu, new TextSelection(offset, length), - CSearchQuery.FIND_REFERENCES); + return new CSearchTextSelectionQuery(new ICElement[] { fCProject }, tu, selection, CSearchQuery.FIND_REFERENCES); + } + + private TextSelection selectSection(String section, String context, String code) { + int contextOffset; + if (context == null) { + context = code; + contextOffset = 0; + } else { + contextOffset = code.indexOf(context); + if (contextOffset < 0) + fail("Didn't find \"" + context + "\" in \"" + code + "\""); + } + int offset = context.indexOf(section); + if (offset < 0) + fail("Didn't find \"" + section + "\" in \"" + context + "\""); + return new TextSelection(contextOffset + offset, section.length()); } // struct A { - // virtual void waldo(); + // virtual void waldo(); // }; // // struct B : public A { - // virtual void waldo() override; + // virtual void waldo() override; // }; // // int main() { - // A* a = new B(); - // a->waldo(); + // A* a = new B(); + // a->waldo(); // } // // empty file public void testOnlyPolymorphicMatches_bug491343() throws Exception { - int offset = fHeaderContents.indexOf("waldo() override"); - CSearchQuery query = makeProjectQuery(offset, 5); + CSearchQuery query = makeSearchQuery(fHeaderFile, selectSection("waldo", "waldo() override", fHeaderContents)); assertOccurrences(query, 1); } @@ -78,15 +93,14 @@ public class FindReferencesTest extends SearchTestBase { // #define waldo() // // struct S { - // void foo() { - // waldo(); - // } + // void foo() { + // waldo(); + // } // }; // // empty file public void testEnclosingDefinitionOfMacroReference_508216() throws Exception { - int offset = fHeaderContents.indexOf("define waldo") + 7; - CSearchQuery query = makeProjectQuery(offset, 5); + CSearchQuery query = makeSearchQuery(fHeaderFile, selectSection("waldo", "#define waldo", fHeaderContents)); CSearchResult result = getSearchResult(query); Object[] elements = result.getElements(); assertEquals(1, elements.length); @@ -97,14 +111,30 @@ public class FindReferencesTest extends SearchTestBase { } // namespace N { - // void foo(); + // void foo(); // } // using N::foo; // // empty file public void testUsingDeclaration_399147() throws Exception { - int offset = fHeaderContents.indexOf("void foo") + 5; - CSearchQuery query = makeProjectQuery(offset, 3); + CSearchQuery query = makeSearchQuery(fHeaderFile, selectSection("foo", "void foo", fHeaderContents)); + assertOccurrences(query, 1); + } + + // // empty file + + // namespace { struct A {}; } + // + // template + // class B {}; + // + // void findMe(B b) {} + // + // void test(B b) { + // findMe(b); + // } + public void testAnonymousNamespace_509749() throws Exception { + CSearchQuery query = makeSearchQuery(fSourceFile, selectSection("findMe", "findMe(b)", fSourceContents)); assertOccurrences(query, 1); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/SearchTestBase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/SearchTestBase.java index 4c294fd225b..20792fdbf61 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/SearchTestBase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/SearchTestBase.java @@ -26,10 +26,12 @@ import org.eclipse.cdt.internal.ui.search.CSearchResult; * Base class for tests that test functionality based on CSearchQuery. */ public abstract class SearchTestBase extends BaseUITestCase { - ICProject fCProject; - String fHeaderContents; - IFile fHeaderFile; - CharSequence[] testData; + protected ICProject fCProject; + protected String fHeaderContents; + protected IFile fHeaderFile; + protected String fSourceContents; + protected IFile fSourceFile; + protected CharSequence[] testData; @Override protected void setUp() throws Exception { @@ -44,7 +46,8 @@ public abstract class SearchTestBase extends BaseUITestCase { CCorePlugin.getIndexManager().setIndexerId(fCProject, IPDOMManager.ID_FAST_INDEXER); waitForIndexer(fCProject); - IFile cppfile= TestSourceReader.createFile(fCProject.getProject(), new Path("references.cpp"), testData[1].toString()); + fSourceContents = testData[1].toString(); + fSourceFile = TestSourceReader.createFile(fCProject.getProject(), new Path("references.cpp"), fSourceContents); waitForIndexer(fCProject); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java index 92623bc933f..9eb452f0063 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java @@ -106,16 +106,15 @@ public class CStructureCreator extends StructureCreator { // empty scanner info IScannerInfo scanInfo= new ScannerInfo(); - FileContent content = FileContent.create("", document.get().toCharArray()); //$NON-NLS-1$ - // determine the language boolean isSource[]= {false}; ILanguage language= determineLanguage(element, isSource); + FileContent content = FileContent.create("", isSource[0], document.get().toCharArray()); //$NON-NLS-1$ + try { - IASTTranslationUnit ast; - int options= isSource[0] ? ILanguage.OPTION_IS_SOURCE_UNIT : 0; - ast= language.getASTTranslationUnit(content, scanInfo, contentProvider, null, options, ParserUtil.getParserLogService()); + IASTTranslationUnit ast = language.getASTTranslationUnit(content, scanInfo, contentProvider, null, + 0, ParserUtil.getParserLogService()); CStructureCreatorVisitor structureCreator= new CStructureCreatorVisitor(root); // build structure ast.accept(structureCreator); diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java index a3430d0dd7f..737930f8c58 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/BaseExtensibleLanguage.java @@ -17,10 +17,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import lpg.lpgjavaruntime.IToken; -import lpg.lpgjavaruntime.PrsStream; -import lpg.lpgjavaruntime.Token; - import org.eclipse.cdt.core.dom.ICodeReaderFactory; import org.eclipse.cdt.core.dom.ast.IASTCompletionNode; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -51,6 +47,9 @@ import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory; import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory; import org.eclipse.core.runtime.CoreException; +import lpg.lpgjavaruntime.IToken; +import lpg.lpgjavaruntime.PrsStream; + /** * Implementation of the ILanguage extension point, @@ -269,9 +268,6 @@ public abstract class BaseExtensibleLanguage extends AbstractLanguage { log.traceLog("^^^^^^ core parser parses " + reader.getFileLocation() + " in " + (coreFinishTime - lpr_fail_time)/1000 + " seconds"); } } - if(tu!=null){ - tu.setIsHeaderUnit((options & OPTION_IS_SOURCE_UNIT) == 0); // the TU is marked as either a source file or a header file - } if(DEBUG_PRINT_AST) { System.out.println("Base Extensible Language AST:"); diff --git a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/parser/StringScanner.java b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/parser/StringScanner.java index 58404b14302..765ed4b3485 100644 --- a/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/parser/StringScanner.java +++ b/qt/org.eclipse.cdt.qt.core/src/org/eclipse/cdt/internal/qt/core/parser/StringScanner.java @@ -112,11 +112,6 @@ public class StringScanner implements IScanner { return 0; } - @Override - @Deprecated - public void setScanComments(boolean val) { - } - @Override public char[] getAdditionalNumericLiteralSuffixes() { return new char[] {};