1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-12 18:55:38 +02:00

Bug 509749 - Find References doesn't find a reference to a function

Change-Id: Id90a80e234638b590266a8671dd1bf13178e0f94
This commit is contained in:
Sergey Prigogin 2016-12-28 20:56:32 -08:00
parent 63d3ab9cbe
commit 216bc162a4
19 changed files with 202 additions and 121 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: %pluginName Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true 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-Activator: org.eclipse.cdt.core.CCorePlugin
Bundle-Vendor: %providerName Bundle-Vendor: %providerName
Bundle-Localization: plugin Bundle-Localization: plugin

View file

@ -41,7 +41,7 @@ public interface ILanguage extends IAdaptable {
public final static int OPTION_SKIP_FUNCTION_BODIES= 0x1; 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. * @noreference This field is not intended to be referenced by clients.
*/ */
@Deprecated @Deprecated
@ -55,10 +55,9 @@ public interface ILanguage extends IAdaptable {
public final static int OPTION_NO_IMAGE_LOCATIONS= 0x4; public final static int OPTION_NO_IMAGE_LOCATIONS= 0x4;
/** /**
* Option for {@link #getASTTranslationUnit(FileContent, IScannerInfo, IncludeFileContentProvider, IIndex, int, IParserLogService)} * @deprecated, Has no effect.
* 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
public final static int OPTION_IS_SOURCE_UNIT= 0x8; public final static int OPTION_IS_SOURCE_UNIT= 0x8;
/** /**
@ -97,22 +96,20 @@ public interface ILanguage extends IAdaptable {
public int getLinkageID(); 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 * @since 4.0
*/ */
public String getName(); public String getName();
/** /**
* Construct an AST for the source code provided by <code>reader</code>. * Constructs an AST for the source code provided by <code>reader</code>.
* As an option you can supply *
* @param content source code to be parsed. * @param content source code to be parsed.
* @param scanInfo provides include paths and defined symbols. * @param scanInfo provides include paths and defined symbols.
* @param fileCreator factory that provides file content for files included * @param fileCreator factory that provides file content for files included
* @param index (optional) index to use to lookup symbols external to the tu. * @param index (optional) index to use to lookup symbols external to the translation unit.
* @param options A combination of * @param options A combination of {@link #OPTION_SKIP_FUNCTION_BODIES},
* {@link #OPTION_SKIP_FUNCTION_BODIES}, * {@link #OPTION_NO_IMAGE_LOCATIONS}, or <code>0</code>.
* {@link #OPTION_NO_IMAGE_LOCATIONS}, {@link #OPTION_IS_SOURCE_UNIT},
* or <code>0</code>.
* @param log logger * @param log logger
* @return an AST for the source code provided by reader. * @return an AST for the source code provided by reader.
* @throws CoreException * @throws CoreException

View file

@ -864,9 +864,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
if ((style & AST_PARSE_INACTIVE_CODE) != 0) { if ((style & AST_PARSE_INACTIVE_CODE) != 0) {
options |= ILanguage.OPTION_PARSE_INACTIVE_CODE; options |= ILanguage.OPTION_PARSE_INACTIVE_CODE;
} }
if (isSourceUnit()) {
options |= ILanguage.OPTION_IS_SOURCE_UNIT;
}
final IParserLogService log; final IParserLogService log;
if (monitor instanceof ICanceler) { if (monitor instanceof ICanceler) {
log= new ParserLogService(DebugLogConstants.PARSER, (ICanceler) monitor); log= new ParserLogService(DebugLogConstants.PARSER, (ICanceler) monitor);

View file

@ -164,9 +164,7 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
try { try {
// Parse // Parse
IASTTranslationUnit ast= parser.parse(); return parser.parse();
ast.setIsHeaderUnit((options & OPTION_IS_SOURCE_UNIT) == 0);
return ast;
} catch (ParseError e) { } catch (ParseError e) {
// Only the TOO_MANY_TOKENS error can be handled here. // Only the TOO_MANY_TOKENS error can be handled here.
if (e.getErrorKind() != ParseErrorKind.TOO_MANY_TOKENS) if (e.getErrorKind() != ParseErrorKind.TOO_MANY_TOKENS)

View file

@ -77,6 +77,7 @@ public abstract class FileContent {
/** /**
* Creates a file content object for a fixed buffer. * 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 filePath the path of the file as it will appear in {@link IASTFileLocation#getFileName()}
* @param contents the actual content. * @param contents the actual content.
*/ */
@ -84,23 +85,45 @@ public abstract class FileContent {
return new InternalFileContent(filePath, new CharArray(contents)); 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. * Creates a file content object for a translation-unit, which may be a working copy.
*/ */
public static FileContent create(ITranslationUnit tu) { public static FileContent create(ITranslationUnit tu) {
InternalFileContent fileContent;
IPath location= tu.getLocation(); IPath location= tu.getLocation();
if (location == null) if (location == null) {
return create(tu.getElementName(), tu.getContents()); fileContent = new InternalFileContent(tu.getElementName(), new CharArray(tu.getContents()));
} else if (tu.isWorkingCopy()) {
if (tu.isWorkingCopy()) { fileContent = new InternalFileContent(location.toOSString(), new CharArray(tu.getContents()));
return create(location.toOSString(), 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 (fileContent != null) {
if (res instanceof IFile) { fileContent.setTranslationUnit(tu);
return create((IFile) res); 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) { public static FileContent create(IFile file) {
return InternalParserUtil.createWorkspaceFileContent(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) { public static FileContent createForExternalFileLocation(String fileLocation) {
return createForExternalFileLocation(fileLocation, InternalParserUtil.SYSTEM_DEFAULT_ENCODING); 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 * @since 5.3
*/ */
public static FileContent createForExternalFileLocation(String fileLocation, String encoding) { 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;
} }
/** /**

View file

@ -19,7 +19,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
import org.eclipse.cdt.internal.core.parser.scanner.Lexer; 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. * @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented 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 { public interface IScanner {
/** /**
* Returns a map from {@link String} to {@link IMacroBinding} containing * 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. * process of scanning.
*/ */
public Map<String, IMacroBinding> getMacroDefinitions(); public Map<String, IMacroBinding> getMacroDefinitions();
@ -38,25 +38,27 @@ public interface IScanner {
* @throws OffsetLimitReachedException see {@link Lexer}. * @throws OffsetLimitReachedException see {@link Lexer}.
*/ */
public IToken nextToken() throws EndOfFileException; public IToken nextToken() throws EndOfFileException;
/** /**
* Returns <code>true</code>, 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(); public boolean isOnTopContext();
/** /**
* Attempts to cancel the scanner. * Attempts to cancel the scanner.
*/ */
public void cancel(); public void cancel();
/** /**
* Returns the location resolver associated with this scanner. * Returns the location resolver associated with this scanner.
*
* @noreference This method is not intended to be referenced by clients. * @noreference This method is not intended to be referenced by clients.
*/ */
public ILocationResolver getLocationResolver(); public ILocationResolver getLocationResolver();
/** /**
* Puts the scanner into content assist mode. * Puts the scanner into content assist mode.
*
* @noreference This method is not intended to be referenced by clients. * @noreference This method is not intended to be referenced by clients.
*/ */
public void setContentAssistMode(int offset); 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 * Instructs the scanner to split tokens of kind {@link IToken#tSHIFTR} into two tokens of
* kind {@link IToken#tGT_in_SHIFTR}. * kind {@link IToken#tGT_in_SHIFTR}.
*
* @noreference This method is not intended to be referenced by clients. * @noreference This method is not intended to be referenced by clients.
*/ */
public void setSplitShiftROperator(boolean val); 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() * @see org.eclipse.cdt.core.dom.ast.IASTName#getImageLocation()
*
* @noreference This method is not intended to be referenced by clients. * @noreference This method is not intended to be referenced by clients.
* @since 5.0 * @since 5.0
*/ */
public void setComputeImageLocations(boolean val); 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 org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement#isIncludedFileExported()
* @see IncludeExportPatterns * @see IncludeExportPatterns
* *
* @param patterns if not {{@code null}, include export tracking is enabled, otherwise it is * @param patterns if not {@code null}, include export tracking is enabled, otherwise it is disabled
* disabled
* *
* @noreference This method is not intended to be referenced by clients. * @noreference This method is not intended to be referenced by clients.
* @since 5.5 * @since 5.5
@ -93,14 +96,16 @@ public interface IScanner {
* Toggles generation of tokens for inactive code branches. When turned on, * 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 * 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}. * succeeded by one of kind {@link IToken#tINACTIVE_CODE_END}.
* *
* @noreference This method is not intended to be referenced by clients. * @noreference This method is not intended to be referenced by clients.
*/ */
public void setProcessInactiveCode(boolean val); public void setProcessInactiveCode(boolean val);
/** /**
* When in inactive code, skips all tokens up to the end of the inactive code section. * When in inactive code, skips all tokens up to the end of the inactive code section.
* <p> Note, token after calling this method may be another token of type {@link IToken#tINACTIVE_CODE_START}. * <p> 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. * @noreference This method is not intended to be referenced by clients.
*/ */
public void skipInactiveCode() throws OffsetLimitReachedException; public void skipInactiveCode() throws OffsetLimitReachedException;
@ -109,21 +114,23 @@ public interface IScanner {
* Returns the current nesting in code branches. * Returns the current nesting in code branches.
* @see IInactiveCodeToken#getOldNesting() * @see IInactiveCodeToken#getOldNesting()
* @see IInactiveCodeToken#getNewNesting() * @see IInactiveCodeToken#getNewNesting()
*
* @noreference This method is not intended to be referenced by clients. * @noreference This method is not intended to be referenced by clients.
*/ */
public int getCodeBranchNesting(); 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. * @deprecated Has no effect.
* @noreference This method is not intended to be referenced by clients. * @noreference This method is not intended to be referenced by clients.
*/ */
@Deprecated @Deprecated
public void setScanComments(boolean val); public default 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();
} }

View file

@ -13,6 +13,7 @@
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage; 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.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
@ -506,4 +507,14 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
} }
return null; 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();
}
} }

View file

@ -447,7 +447,10 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
if (scanner != null) { if (scanner != null) {
tu.setLocationResolver(scanner.getLocationResolver()); tu.setLocationResolver(scanner.getLocationResolver());
if (scanner instanceof CPreprocessor) { 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); tu.setASTNodeFactory(this);

View file

@ -770,7 +770,10 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
if (scanner != null) { if (scanner != null) {
tu.setLocationResolver(scanner.getLocationResolver()); tu.setLocationResolver(scanner.getLocationResolver());
if (scanner instanceof CPreprocessor) { 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); tu.setASTNodeFactory(this);

View file

@ -166,18 +166,17 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter {
String stu = tu.toString(); String stu = tu.toString();
String fileEncoding = getFileEncoding(stu); String fileEncoding = getFileEncoding(stu);
return FileContent.createForExternalFileLocation(stu, fileEncoding); return FileContent.createForExternalFileLocation(stu, isSource(stu), fileEncoding);
} }
public String getFileEncoding(String stu) { public String getFileEncoding(String stu) {
String fileEncoding = null; 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(); FileEncodingRegistry fileEncodingRegistry = fIndexer.getFileEncodingRegistry();
if(fileEncodingRegistry != null){ if (fileEncodingRegistry != null)
fileEncoding = fileEncodingRegistry.getFileEncoding(stu); fileEncoding = fileEncodingRegistry.getFileEncoding(stu);
}
if (fileEncoding == null) if (fileEncoding == null)
return InternalParserUtil.SYSTEM_DEFAULT_ENCODING; fileEncoding = InternalParserUtil.SYSTEM_DEFAULT_ENCODING;
return fileEncoding; return fileEncoding;
} }

View file

@ -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.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration; import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndexMacro; 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.AbstractParserLogService;
import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.ExtendedScannerInfo; import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
@ -262,7 +263,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private final ScannerContext fRootContext; private final ScannerContext fRootContext;
protected ScannerContext fCurrentContext; protected ScannerContext fCurrentContext;
private boolean isCancelled= false; private boolean isCancelled;
private boolean fIsFirstFetchToken= true; private boolean fIsFirstFetchToken= true;
private Token fPrefetchedTokens; private Token fPrefetchedTokens;
@ -273,8 +274,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
// Detection of include guards used around an include directive // Detection of include guards used around an include directive
private char[] fExternIncludeGuard; private char[] fExternIncludeGuard;
private Set<String> fTracedGuards; private Set<String> fTracedGuards;
public CPreprocessor(FileContent fileContent, IScannerInfo info, ParserLanguage language, public CPreprocessor(FileContent fileContent, IScannerInfo info, ParserLanguage language,
IParserLogService log, IScannerExtensionConfiguration configuration, IParserLogService log, IScannerExtensionConfiguration configuration,
@ -386,8 +386,12 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
fRootContext.setParseInactiveCode(val); fRootContext.setParseInactiveCode(val);
} }
@Override public ITranslationUnit getTranslationUnit() {
public void setScanComments(boolean val) { return fRootContent.getTranslationUnit();
}
public boolean isSource() {
return fRootContent.isSource();
} }
@Override @Override

View file

@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexMacro; 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.FileContent;
import org.eclipse.cdt.core.parser.ISignificantMacros; import org.eclipse.cdt.core.parser.ISignificantMacros;
@ -56,6 +57,7 @@ public class InternalFileContent extends FileContent {
private final List<FileVersion> fNonPragmaOnceFiles; private final List<FileVersion> fNonPragmaOnceFiles;
private boolean fHeuristic; private boolean fHeuristic;
private boolean fIsSource; private boolean fIsSource;
private ITranslationUnit fTranslationUnit;
private List<IIndexFile> fFiles; private List<IIndexFile> fFiles;
private IncludeSearchPathElement fFoundOnPath; private IncludeSearchPathElement fFoundOnPath;
private final long fTimestamp; private final long fTimestamp;
@ -246,6 +248,14 @@ public class InternalFileContent extends FileContent {
fIsSource= isSource; fIsSource= isSource;
} }
public ITranslationUnit getTranslationUnit() {
return fTranslationUnit;
}
public void setTranslationUnit(ITranslationUnit tu) {
fTranslationUnit = tu;
}
public IncludeSearchPathElement getFoundOnPath() { public IncludeSearchPathElement getFoundOnPath() {
return fFoundOnPath; return fFoundOnPath;
} }

View file

@ -53,7 +53,6 @@ import org.eclipse.cdt.core.index.IPDOMASTProcessor;
import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.AbstractLanguage; import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.model.ILanguage; 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.ExtendedScannerInfo;
import org.eclipse.cdt.core.parser.FileContent; import org.eclipse.cdt.core.parser.FileContent;
import org.eclipse.cdt.core.parser.IParserLogService; 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.IncludeExportPatterns;
import org.eclipse.cdt.core.parser.IncludeFileContentProvider; import org.eclipse.cdt.core.parser.IncludeFileContentProvider;
import org.eclipse.cdt.internal.core.dom.IIncludeFileResolutionHeuristics; 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.FileContentKey;
import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
@ -1088,19 +1086,15 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
progress.subTask(getMessage(MessageKind.parsingFileTask, progress.subTask(getMessage(MessageKind.parsingFileTask,
path.lastSegment(), path.removeLastSegments(1).toString())); path.lastSegment(), path.removeLastSegments(1).toString()));
FileContent codeReader= fResolver.getCodeReader(tu); FileContent codeReader= fResolver.getCodeReader(tu);
final boolean isSource = fResolver.isSourceUnit(tu);
long start= System.currentTimeMillis(); long start= System.currentTimeMillis();
ASTTypeUtil.startTranslationUnit(); ASTTypeUtil.startTranslationUnit();
IASTTranslationUnit ast= 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; fStatistics.fParsingTime += System.currentTimeMillis() - start;
if (ast == null) { if (ast == null) {
++fStatistics.fTooManyTokensCount; ++fStatistics.fTooManyTokensCount;
} else { } 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)); writeToIndex(lang.getLinkageID(), ast, codeReader, ctx, progress.split(10));
resultCacheCleared = true; // The cache was cleared while writing to the index. 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, private final IASTTranslationUnit createAST(AbstractLanguage language, FileContent codeReader,
IScannerInfo scanInfo, boolean isSource, int options, IScannerInfo scanInfo, int options, FileContext ctx, IProgressMonitor monitor)
FileContext ctx, IProgressMonitor monitor) throws CoreException { throws CoreException {
if (codeReader == null) { if (codeReader == null) {
return null; return null;
} }
if (isSource) {
options |= ILanguage.OPTION_IS_SOURCE_UNIT;
}
if (fTranslationUnitSizeLimit > 0 && fResolver.getFileSize(codeReader.getFileLocation()) > fTranslationUnitSizeLimit) { if (fTranslationUnitSizeLimit > 0 && fResolver.getFileSize(codeReader.getFileLocation()) > fTranslationUnitSizeLimit) {
if (fShowActivity) { if (fShowActivity) {
trace("Indexer: Skipping large file " + codeReader.getFileLocation()); //$NON-NLS-1$ trace("Indexer: Skipping large file " + codeReader.getFileLocation()); //$NON-NLS-1$

View file

@ -11,7 +11,7 @@
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<version>6.2.0-SNAPSHOT</version> <version>6.3.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.core</artifactId> <artifactId>org.eclipse.cdt.core</artifactId>
<packaging>eclipse-plugin</packaging> <packaging>eclipse-plugin</packaging>
</project> </project>

View file

@ -7,6 +7,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.search; package org.eclipse.cdt.ui.tests.search;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.TextSelection;
import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPage;
@ -38,11 +39,11 @@ public class FindReferencesTest extends SearchTestBase {
return suite(FindReferencesTest.class); return suite(FindReferencesTest.class);
} }
private CSearchQuery makeProjectQuery(int offset, int length) { private CSearchQuery makeSearchQuery(IFile file, TextSelection selection) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart part = null; IEditorPart part = null;
try { 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) { } catch (PartInitException e) {
assertFalse(true); assertFalse(true);
} }
@ -50,27 +51,41 @@ public class FindReferencesTest extends SearchTestBase {
CEditor editor = (CEditor) part; CEditor editor = (CEditor) part;
EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 5000, 10); EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 5000, 10);
ITranslationUnit tu = editor.getInputCElement(); ITranslationUnit tu = editor.getInputCElement();
return new CSearchTextSelectionQuery(new ICElement[] { fCProject }, tu, new TextSelection(offset, length), return new CSearchTextSelectionQuery(new ICElement[] { fCProject }, tu, selection, CSearchQuery.FIND_REFERENCES);
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 { // struct A {
// virtual void waldo(); // virtual void waldo();
// }; // };
// //
// struct B : public A { // struct B : public A {
// virtual void waldo() override; // virtual void waldo() override;
// }; // };
// //
// int main() { // int main() {
// A* a = new B(); // A* a = new B();
// a->waldo(); // a->waldo();
// } // }
// // empty file // // empty file
public void testOnlyPolymorphicMatches_bug491343() throws Exception { public void testOnlyPolymorphicMatches_bug491343() throws Exception {
int offset = fHeaderContents.indexOf("waldo() override"); CSearchQuery query = makeSearchQuery(fHeaderFile, selectSection("waldo", "waldo() override", fHeaderContents));
CSearchQuery query = makeProjectQuery(offset, 5);
assertOccurrences(query, 1); assertOccurrences(query, 1);
} }
@ -78,15 +93,14 @@ public class FindReferencesTest extends SearchTestBase {
// #define waldo() // #define waldo()
// //
// struct S { // struct S {
// void foo() { // void foo() {
// waldo(); // waldo();
// } // }
// }; // };
// // empty file // // empty file
public void testEnclosingDefinitionOfMacroReference_508216() throws Exception { public void testEnclosingDefinitionOfMacroReference_508216() throws Exception {
int offset = fHeaderContents.indexOf("define waldo") + 7; CSearchQuery query = makeSearchQuery(fHeaderFile, selectSection("waldo", "#define waldo", fHeaderContents));
CSearchQuery query = makeProjectQuery(offset, 5);
CSearchResult result = getSearchResult(query); CSearchResult result = getSearchResult(query);
Object[] elements = result.getElements(); Object[] elements = result.getElements();
assertEquals(1, elements.length); assertEquals(1, elements.length);
@ -97,14 +111,30 @@ public class FindReferencesTest extends SearchTestBase {
} }
// namespace N { // namespace N {
// void foo(); // void foo();
// } // }
// using N::foo; // using N::foo;
// // empty file // // empty file
public void testUsingDeclaration_399147() throws Exception { public void testUsingDeclaration_399147() throws Exception {
int offset = fHeaderContents.indexOf("void foo") + 5; CSearchQuery query = makeSearchQuery(fHeaderFile, selectSection("foo", "void foo", fHeaderContents));
CSearchQuery query = makeProjectQuery(offset, 3); assertOccurrences(query, 1);
}
// // empty file
// namespace { struct A {}; }
//
// template <typename T>
// class B {};
//
// void findMe(B<A> b) {}
//
// void test(B<A> b) {
// findMe(b);
// }
public void testAnonymousNamespace_509749() throws Exception {
CSearchQuery query = makeSearchQuery(fSourceFile, selectSection("findMe", "findMe(b)", fSourceContents));
assertOccurrences(query, 1); assertOccurrences(query, 1);
} }
} }

View file

@ -26,10 +26,12 @@ import org.eclipse.cdt.internal.ui.search.CSearchResult;
* Base class for tests that test functionality based on CSearchQuery. * Base class for tests that test functionality based on CSearchQuery.
*/ */
public abstract class SearchTestBase extends BaseUITestCase { public abstract class SearchTestBase extends BaseUITestCase {
ICProject fCProject; protected ICProject fCProject;
String fHeaderContents; protected String fHeaderContents;
IFile fHeaderFile; protected IFile fHeaderFile;
CharSequence[] testData; protected String fSourceContents;
protected IFile fSourceFile;
protected CharSequence[] testData;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
@ -44,7 +46,8 @@ public abstract class SearchTestBase extends BaseUITestCase {
CCorePlugin.getIndexManager().setIndexerId(fCProject, IPDOMManager.ID_FAST_INDEXER); CCorePlugin.getIndexManager().setIndexerId(fCProject, IPDOMManager.ID_FAST_INDEXER);
waitForIndexer(fCProject); 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); waitForIndexer(fCProject);
} }

View file

@ -106,16 +106,15 @@ public class CStructureCreator extends StructureCreator {
// empty scanner info // empty scanner info
IScannerInfo scanInfo= new ScannerInfo(); IScannerInfo scanInfo= new ScannerInfo();
FileContent content = FileContent.create("<text>", document.get().toCharArray()); //$NON-NLS-1$
// determine the language // determine the language
boolean isSource[]= {false}; boolean isSource[]= {false};
ILanguage language= determineLanguage(element, isSource); ILanguage language= determineLanguage(element, isSource);
FileContent content = FileContent.create("<text>", isSource[0], document.get().toCharArray()); //$NON-NLS-1$
try { try {
IASTTranslationUnit ast; IASTTranslationUnit ast = language.getASTTranslationUnit(content, scanInfo, contentProvider, null,
int options= isSource[0] ? ILanguage.OPTION_IS_SOURCE_UNIT : 0; 0, ParserUtil.getParserLogService());
ast= language.getASTTranslationUnit(content, scanInfo, contentProvider, null, options, ParserUtil.getParserLogService());
CStructureCreatorVisitor structureCreator= new CStructureCreatorVisitor(root); CStructureCreatorVisitor structureCreator= new CStructureCreatorVisitor(root);
// build structure // build structure
ast.accept(structureCreator); ast.accept(structureCreator);

View file

@ -17,10 +17,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode; import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTName; 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.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import lpg.lpgjavaruntime.IToken;
import lpg.lpgjavaruntime.PrsStream;
/** /**
* Implementation of the ILanguage extension point, * 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"); 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) { if(DEBUG_PRINT_AST) {
System.out.println("Base Extensible Language AST:"); System.out.println("Base Extensible Language AST:");

View file

@ -112,11 +112,6 @@ public class StringScanner implements IScanner {
return 0; return 0;
} }
@Override
@Deprecated
public void setScanComments(boolean val) {
}
@Override @Override
public char[] getAdditionalNumericLiteralSuffixes() { public char[] getAdditionalNumericLiteralSuffixes() {
return new char[] {}; return new char[] {};