mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Fix for 178088, options to skip references during indexing.
This commit is contained in:
parent
8067e74e3f
commit
ad8800e447
13 changed files with 277 additions and 97 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -13,6 +13,10 @@ package org.eclipse.cdt.core.model;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IParserLogService;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
|
@ -21,13 +25,44 @@ import org.eclipse.core.runtime.PlatformObject;
|
|||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractLanguage extends PlatformObject implements ILanguage {
|
||||
/**
|
||||
* Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
|
||||
* Instructs the parser to skip function and method bodies.
|
||||
*/
|
||||
public final static int OPTION_SKIP_FUNCTION_BODIES= 1;
|
||||
|
||||
/**
|
||||
* @deprecated, throws an UnsupportedOperationException
|
||||
*/
|
||||
final public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated, throws an UnsupportedOperationException
|
||||
*/
|
||||
final public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, ICodeReaderFactory codeReaderFactory,
|
||||
int style) throws CoreException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an AST for the source code provided by <code>reader</code>.
|
||||
* As an option you can supply
|
||||
* @param reader source code to be parsed.
|
||||
* @param scanInfo provides include paths and defined symbols.
|
||||
* @param fileCreator factory that provides CodeReaders for files included
|
||||
* by the source code being parsed.
|
||||
* @param index (optional) index to use to provide support for ambiguity
|
||||
* resolution.
|
||||
* @param options {@link #OPTION_SKIP_FUNCTION_BODIES} or <code>0</code>.
|
||||
* @param log logger
|
||||
* @return an AST for the source code provided by reader.
|
||||
* @throws CoreException
|
||||
*/
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log)
|
||||
throws CoreException {
|
||||
// for backwards compatibility
|
||||
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, log);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.parser.c;
|
||||
|
||||
|
@ -88,10 +89,15 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
|
|||
}
|
||||
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory codeReaderFactory, IIndex index, IParserLogService log) throws CoreException {
|
||||
ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) throws CoreException {
|
||||
return getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log);
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory codeReaderFactory, IIndex index, int options, IParserLogService log) throws CoreException {
|
||||
|
||||
IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log);
|
||||
ISourceCodeParser parser= createParser(scanner, log, index, false);
|
||||
ISourceCodeParser parser= createParser(scanner, log, index, false, options);
|
||||
|
||||
// Parse
|
||||
IASTTranslationUnit ast= parser.parse();
|
||||
|
@ -104,7 +110,7 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
|
|||
IScanner scanner= createScanner(reader, scanInfo, fileCreator, log);
|
||||
scanner.setContentAssistMode(offset);
|
||||
|
||||
ISourceCodeParser parser= createParser(scanner, log, index, true);
|
||||
ISourceCodeParser parser= createParser(scanner, log, index, true, 0);
|
||||
|
||||
// Run the parse and return the completion node
|
||||
parser.parse();
|
||||
|
@ -153,10 +159,20 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
|
|||
* @param log the parser log service
|
||||
* @param index the index to help resolve bindings
|
||||
* @param forCompletion whether the parser is used for code completion
|
||||
* @param options for valid options see {@link AbstractLanguage#getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
|
||||
* @return an instance of ISourceCodeParser
|
||||
*/
|
||||
protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion) {
|
||||
ParserMode mode= forCompletion ? ParserMode.COMPLETION_PARSE : ParserMode.COMPLETE_PARSE;
|
||||
protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion, int options) {
|
||||
ParserMode mode= null;
|
||||
if (forCompletion) {
|
||||
mode= ParserMode.COMPLETION_PARSE;
|
||||
}
|
||||
else if ((options & OPTION_SKIP_FUNCTION_BODIES) != 0) {
|
||||
mode= ParserMode.STRUCTURAL_PARSE;
|
||||
}
|
||||
else {
|
||||
mode= ParserMode.COMPLETE_PARSE;
|
||||
}
|
||||
return new GNUCSourceParser(scanner, mode, log, getParserExtensionConfiguration(), index);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.parser.cpp;
|
||||
|
||||
|
@ -87,10 +88,15 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC
|
|||
}
|
||||
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory codeReaderFactory, IIndex index, IParserLogService log) throws CoreException {
|
||||
ICodeReaderFactory codeReaderFactory, IIndex index,IParserLogService log) throws CoreException {
|
||||
return getASTTranslationUnit(reader, scanInfo, codeReaderFactory, index, 0, log);
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo,
|
||||
ICodeReaderFactory codeReaderFactory, IIndex index, int options, IParserLogService log) throws CoreException {
|
||||
|
||||
IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log);
|
||||
ISourceCodeParser parser= createParser(scanner, log, index, false);
|
||||
ISourceCodeParser parser= createParser(scanner, log, index, false, options);
|
||||
|
||||
// Parse
|
||||
IASTTranslationUnit ast= parser.parse();
|
||||
|
@ -102,7 +108,7 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC
|
|||
IScanner scanner= createScanner(reader, scanInfo, fileCreator, log);
|
||||
scanner.setContentAssistMode(offset);
|
||||
|
||||
ISourceCodeParser parser= createParser(scanner, log, index, true);
|
||||
ISourceCodeParser parser= createParser(scanner, log, index, true, 0);
|
||||
|
||||
// Run the parse and return the completion node
|
||||
parser.parse();
|
||||
|
@ -150,10 +156,20 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC
|
|||
* @param log the parser log service
|
||||
* @param index the index to help resolve bindings
|
||||
* @param forCompletion whether the parser is used for code completion
|
||||
* @param options for valid options see {@link AbstractLanguage#getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)}
|
||||
* @return an instance of ISourceCodeParser
|
||||
*/
|
||||
protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion) {
|
||||
ParserMode mode= forCompletion ? ParserMode.COMPLETION_PARSE : ParserMode.COMPLETE_PARSE;
|
||||
protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion, int options) {
|
||||
ParserMode mode= null;
|
||||
if (forCompletion) {
|
||||
mode= ParserMode.COMPLETION_PARSE;
|
||||
}
|
||||
else if ((options & OPTION_SKIP_FUNCTION_BODIES) != 0) {
|
||||
mode= ParserMode.STRUCTURAL_PARSE;
|
||||
}
|
||||
else {
|
||||
mode= ParserMode.COMPLETE_PARSE;
|
||||
}
|
||||
return new GNUCPPSourceParser(scanner, mode, log, getParserExtensionConfiguration(), index);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,13 +17,22 @@ import java.util.LinkedHashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||
|
@ -40,12 +49,17 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
* @since 4.0
|
||||
*/
|
||||
abstract public class PDOMWriter {
|
||||
public static int SKIP_ALL_REFERENCES= -1;
|
||||
public static int SKIP_TYPE_REFERENCES= 1;
|
||||
public static int SKIP_NO_REFERENCES= 0;
|
||||
|
||||
protected boolean fShowActivity;
|
||||
protected boolean fShowProblems;
|
||||
protected IndexerStatistics fStatistics;
|
||||
|
||||
private IndexerProgress fInfo= new IndexerProgress();
|
||||
|
||||
private int fSkipReferences= SKIP_NO_REFERENCES;
|
||||
|
||||
public PDOMWriter() {
|
||||
fStatistics= new IndexerStatistics();
|
||||
}
|
||||
|
@ -58,6 +72,14 @@ abstract public class PDOMWriter {
|
|||
fShowProblems= val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether references are skipped or not. Provide one of
|
||||
* {@link #SKIP_ALL_REFERENCES}, {@link #SKIP_TYPE_REFERENCES} or {@link #SKIP_NO_REFERENCES}.
|
||||
*/
|
||||
public void setSkipReferences(int options) {
|
||||
fSkipReferences= options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to check whether a translation unit still needs to be updated.
|
||||
* @see #addSymbols(IASTTranslationUnit, IWritableIndex, int, IProgressMonitor)
|
||||
|
@ -103,14 +125,23 @@ abstract public class PDOMWriter {
|
|||
long start= System.currentTimeMillis();
|
||||
ArrayList names= arrayLists[2];
|
||||
for (int j=0; j<names.size(); j++) {
|
||||
final IASTName name = ((IASTName[]) names.get(j))[0];
|
||||
final IASTName[] na= (IASTName[]) names.get(j);
|
||||
final IASTName name = na[0];
|
||||
final IBinding binding= name.resolveBinding();
|
||||
if (binding instanceof IProblemBinding)
|
||||
reportProblem((IProblemBinding) binding);
|
||||
else if (name.isReference())
|
||||
else if (name.isReference()) {
|
||||
if (fSkipReferences == SKIP_TYPE_REFERENCES) {
|
||||
if (isTypeReferenceBinding(binding) && !isInheritanceSpec(name)) {
|
||||
na[0]= null;
|
||||
fStatistics.fReferenceCount--;
|
||||
}
|
||||
}
|
||||
fStatistics.fReferenceCount++;
|
||||
else
|
||||
}
|
||||
else {
|
||||
fStatistics.fDeclarationCount++;
|
||||
}
|
||||
}
|
||||
fStatistics.fResolutionTime += System.currentTimeMillis()-start;
|
||||
}
|
||||
|
@ -127,7 +158,7 @@ abstract public class PDOMWriter {
|
|||
IIndexFileLocation path = orderedPaths[i];
|
||||
if (path != null) {
|
||||
if (fShowActivity) {
|
||||
System.out.println("Indexer: adding " + path.getURI()); //$NON-NLS-1$
|
||||
System.out.println("Indexer: adding " + path.getURI()); //$NON-NLS-1$
|
||||
}
|
||||
IIndexFile file= addToIndex(index, path, symbolMap);
|
||||
boolean wasRequested= postAddToIndex(path, file);
|
||||
|
@ -210,10 +241,17 @@ abstract public class PDOMWriter {
|
|||
// names
|
||||
ast.accept(new IndexerASTVisitor() {
|
||||
public void visit(IASTName name, IASTName caller) {
|
||||
if (fSkipReferences == SKIP_ALL_REFERENCES) {
|
||||
if (name.isReference()) {
|
||||
if (!isInheritanceSpec(name)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// assign a location to anonymous types.
|
||||
name= PDOMASTAdapter.getAdapterIfAnonymous(name);
|
||||
IASTFileLocation nameLoc = name.getFileLocation();
|
||||
|
||||
if (nameLoc != null) {
|
||||
IIndexFileLocation location = findLocation(nameLoc.getFileName());
|
||||
addToMap(symbolMap, 2, location, new IASTName[]{name, caller});
|
||||
|
@ -223,6 +261,31 @@ abstract public class PDOMWriter {
|
|||
return (IIndexFileLocation[]) orderedIncludes.toArray(new IIndexFileLocation[orderedIncludes.size()]);
|
||||
}
|
||||
|
||||
protected boolean isInheritanceSpec(IASTName name) {
|
||||
IASTNode parentNode= name.getParent();
|
||||
if (parentNode instanceof ICPPASTBaseSpecifier) {
|
||||
return true;
|
||||
}
|
||||
else if (parentNode instanceof IASTDeclSpecifier) {
|
||||
IASTDeclSpecifier ds= (IASTDeclSpecifier) parentNode;
|
||||
return ds.getStorageClass() == IASTDeclSpecifier.sc_typedef;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isTypeReferenceBinding(IBinding binding) {
|
||||
if (binding instanceof ICompositeType ||
|
||||
binding instanceof IEnumeration ||
|
||||
binding instanceof ITypedef ||
|
||||
binding instanceof ICPPNamespace ||
|
||||
binding instanceof ICPPNamespaceAlias ||
|
||||
binding instanceof ICPPClassTemplate) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void reportProblem(IProblemBinding problem) {
|
||||
fStatistics.fProblemBindingCount++;
|
||||
if (fShowProblems) {
|
||||
|
@ -234,7 +297,6 @@ abstract public class PDOMWriter {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void addToMap(Map map, int idx, IIndexFileLocation location, Object thing) {
|
||||
List[] lists= (List[]) map.get(location);
|
||||
if (lists != null)
|
||||
|
|
|
@ -193,17 +193,19 @@ public class PDOMFile implements IIndexFragmentFile {
|
|||
PDOMName lastName= null;
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
IASTName[] name = names[i];
|
||||
PDOMName caller= (PDOMName) nameCache.get(name[1]);
|
||||
PDOMName pdomName = createPDOMName(name[0], caller);
|
||||
if (pdomName != null) {
|
||||
nameCache.put(name[0], pdomName);
|
||||
if (lastName == null) {
|
||||
setFirstName(pdomName);
|
||||
if (name[0] != null) {
|
||||
PDOMName caller= (PDOMName) nameCache.get(name[1]);
|
||||
PDOMName pdomName = createPDOMName(name[0], caller);
|
||||
if (pdomName != null) {
|
||||
nameCache.put(name[0], pdomName);
|
||||
if (lastName == null) {
|
||||
setFirstName(pdomName);
|
||||
}
|
||||
else {
|
||||
lastName.setNextInFile(pdomName);
|
||||
}
|
||||
lastName= pdomName;
|
||||
}
|
||||
else {
|
||||
lastName.setNextInFile(pdomName);
|
||||
}
|
||||
lastName= pdomName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ public abstract class AbstractPDOMIndexer implements IPDOMIndexer {
|
|||
public AbstractPDOMIndexer() {
|
||||
fProperties.put(IndexerPreferences.KEY_INDEX_ALL_FILES, String.valueOf(false));
|
||||
fProperties.put(IndexerPreferences.KEY_FILES_TO_PARSE_UP_FRONT, ""); //$NON-NLS-1$
|
||||
fProperties.put(IndexerPreferences.KEY_SKIP_ALL_REFERENCES, String.valueOf(false));
|
||||
fProperties.put(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES, String.valueOf(false));
|
||||
}
|
||||
|
||||
public ICProject getProject() {
|
||||
|
|
|
@ -43,6 +43,8 @@ public class IndexerPreferences {
|
|||
public static final String KEY_INDEXER_ID= "indexerId"; //$NON-NLS-1$
|
||||
public static final String KEY_INDEX_ALL_FILES= "indexAllFiles"; //$NON-NLS-1$
|
||||
public static final String KEY_FILES_TO_PARSE_UP_FRONT= "filesToParseUpFront"; //$NON-NLS-1$
|
||||
public static final String KEY_SKIP_ALL_REFERENCES= "skipReferences"; //$NON-NLS-1$
|
||||
public static final String KEY_SKIP_TYPE_REFERENCES= "skipTypeReferences"; //$NON-NLS-1$
|
||||
|
||||
private static final String DEFAULT_INDEX_IMPORT_LOCATION = ".settings/cdt-index.zip"; //$NON-NLS-1$
|
||||
private static final String DEFAULT_FILES_TO_PARSE_UP_FRONT= "stdarg.h, stddef.h, sys/types.h"; //$NON-NLS-1$
|
||||
|
@ -270,6 +272,8 @@ public class IndexerPreferences {
|
|||
Preferences prefs= defaultPreferences.node(INDEXER_NODE);
|
||||
prefs.put(KEY_INDEXER_ID, IPDOMManager.ID_FAST_INDEXER);
|
||||
prefs.putBoolean(KEY_INDEX_ALL_FILES, false);
|
||||
prefs.putBoolean(KEY_SKIP_ALL_REFERENCES, false);
|
||||
prefs.putBoolean(KEY_SKIP_TYPE_REFERENCES, false);
|
||||
prefs.put(KEY_INDEX_IMPORT_LOCATION, DEFAULT_INDEX_IMPORT_LOCATION);
|
||||
prefs.put(KEY_FILES_TO_PARSE_UP_FRONT, DEFAULT_FILES_TO_PARSE_UP_FRONT);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.cdt.core.index.IIndexFile;
|
|||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IIndexInclude;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
@ -73,6 +74,12 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
fIndexer= indexer;
|
||||
setShowActivity(checkDebugOption(TRACE_ACTIVITY, TRUE));
|
||||
setShowProblems(checkDebugOption(TRACE_PROBLEMS, TRUE));
|
||||
if (checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES)) {
|
||||
setSkipReferences(SKIP_ALL_REFERENCES);
|
||||
}
|
||||
else if (checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES)) {
|
||||
setSkipReferences(SKIP_TYPE_REFERENCES);
|
||||
}
|
||||
}
|
||||
|
||||
final public IPDOMIndexer getIndexer() {
|
||||
|
@ -112,28 +119,46 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
* @since 4.0
|
||||
*/
|
||||
final protected boolean getIndexAllFiles() {
|
||||
return TRUE.equals(getIndexer().getProperty(IndexerPreferences.KEY_INDEX_ALL_FILES));
|
||||
return checkProperty(IndexerPreferences.KEY_INDEX_ALL_FILES);
|
||||
}
|
||||
|
||||
private boolean checkProperty(String key) {
|
||||
return TRUE.equals(getIndexer().getProperty(key));
|
||||
}
|
||||
|
||||
private IASTTranslationUnit createAST(ITranslationUnit tu, int options, IProgressMonitor pm) throws CoreException {
|
||||
IPath path = tu.getLocation();
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (! (language instanceof AbstractLanguage))
|
||||
return null;
|
||||
|
||||
// skip if no scanner info
|
||||
IScannerInfo scanner= tu.getScannerInfo(getIndexAllFiles());
|
||||
if (scanner == null) {
|
||||
return null;
|
||||
}
|
||||
CodeReader codeReader = tu.getCodeReader();
|
||||
if (codeReader == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return createAST((AbstractLanguage)language, codeReader, scanner, options, pm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to create the ast for a translation unit. May return <code>null</code>.
|
||||
* Called to create the ast for a translation unit or a pre-parsed file.
|
||||
* May return <code>null</code>.
|
||||
* @see #parseTUs(IWritableIndex, int, Collection, Collection, IProgressMonitor)
|
||||
* @since 4.0
|
||||
*/
|
||||
abstract protected IASTTranslationUnit createAST(ITranslationUnit tu, IProgressMonitor pm) throws CoreException;
|
||||
|
||||
/**
|
||||
* Called to create the ast for pre-parsed files. May return <code>null</code>.
|
||||
* @throws CoreException
|
||||
* @since 4.0
|
||||
*/
|
||||
protected IASTTranslationUnit createAST(ILanguage lang, CodeReader codeReader, IScannerInfo scanInfo, IProgressMonitor pm) throws CoreException {
|
||||
return null;
|
||||
}
|
||||
abstract protected IASTTranslationUnit createAST(AbstractLanguage lang, CodeReader codeReader, IScannerInfo scanInfo, int options, IProgressMonitor pm) throws CoreException;
|
||||
|
||||
/**
|
||||
* Convenience method for subclasses, parses the files calling out to the methods
|
||||
* {@link #createAST(ITranslationUnit, IProgressMonitor)},
|
||||
* {@link #createAST(AbstractLanguage, CodeReader, IScannerInfo, int, IProgressMonitor)},
|
||||
* {@link #needToUpdate(IIndexFileLocation)},
|
||||
* {@link #addSymbols(IASTTranslationUnit, IWritableIndex, int, IProgressMonitor)}
|
||||
* {@link #postAddToIndex(IIndexFileLocation, IIndexFile)},
|
||||
|
@ -142,9 +167,13 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
* @since 4.0
|
||||
*/
|
||||
protected void parseTUs(IWritableIndex index, int readlockCount, Collection sources, Collection headers, IProgressMonitor monitor) throws CoreException, InterruptedException {
|
||||
int options= 0;
|
||||
if (checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES)) {
|
||||
options |= AbstractLanguage.OPTION_SKIP_FUNCTION_BODIES;
|
||||
}
|
||||
for (Iterator iter = fFilesUpFront.iterator(); iter.hasNext();) {
|
||||
String upfront= (String) iter.next();
|
||||
parseUpFront(upfront, index, readlockCount, monitor);
|
||||
parseUpFront(upfront, options, index, readlockCount, monitor);
|
||||
}
|
||||
|
||||
// sources first
|
||||
|
@ -157,7 +186,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
updateInfo(0,0,-1);
|
||||
}
|
||||
else if (needToUpdate(ifl)) {
|
||||
parseTU(tu, index, readlockCount, monitor);
|
||||
parseTU(tu, options, index, readlockCount, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +206,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
else {
|
||||
ITranslationUnit context= findContext(index, location);
|
||||
if (context != null) {
|
||||
parseTU(context, index, readlockCount, monitor);
|
||||
parseTU(context, options, index, readlockCount, monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,7 +226,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
iter.remove();
|
||||
}
|
||||
else {
|
||||
parseTU(tu, index, readlockCount, monitor);
|
||||
parseTU(tu, options, index, readlockCount, monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +247,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
}
|
||||
|
||||
|
||||
private void parseTU(ITranslationUnit tu, IWritableIndex index, int readlockCount, IProgressMonitor pm) throws CoreException, InterruptedException {
|
||||
private void parseTU(ITranslationUnit tu, int options, IWritableIndex index, int readlockCount, IProgressMonitor pm) throws CoreException, InterruptedException {
|
||||
IPath path= tu.getPath();
|
||||
try {
|
||||
if (fShowActivity) {
|
||||
|
@ -227,7 +256,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
pm.subTask(MessageFormat.format(Messages.PDOMIndexerTask_parsingFileTask,
|
||||
new Object[]{path.lastSegment(), path.removeLastSegments(1).toString()}));
|
||||
long start= System.currentTimeMillis();
|
||||
IASTTranslationUnit ast= createAST(tu, pm);
|
||||
IASTTranslationUnit ast= createAST(tu, options, pm);
|
||||
fStatistics.fParsingTime += System.currentTimeMillis()-start;
|
||||
if (ast != null) {
|
||||
addSymbols(ast, index, readlockCount, pm);
|
||||
|
@ -244,7 +273,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
}
|
||||
}
|
||||
|
||||
private void parseUpFront(String file, IWritableIndex index, int readlockCount, IProgressMonitor pm) throws CoreException, InterruptedException {
|
||||
private void parseUpFront(String file, int options, IWritableIndex index, int readlockCount, IProgressMonitor pm) throws CoreException, InterruptedException {
|
||||
file= file.trim();
|
||||
if (file.length() == 0) {
|
||||
return;
|
||||
|
@ -262,8 +291,9 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
final IProject project = getProject().getProject();
|
||||
IContentType ct= CContentTypes.getContentType(project, file);
|
||||
if (ct != null) {
|
||||
ILanguage lang = LanguageManager.getInstance().getLanguage(ct);
|
||||
if (lang != null) {
|
||||
ILanguage l = LanguageManager.getInstance().getLanguage(ct);
|
||||
if (l instanceof AbstractLanguage) {
|
||||
AbstractLanguage lang= (AbstractLanguage) l;
|
||||
IScannerInfoProvider provider= CCorePlugin.getDefault().getScannerInfoProvider(project);
|
||||
IScannerInfo scanInfo;
|
||||
if (provider != null) {
|
||||
|
@ -278,7 +308,7 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
fDummyFileURI= findLocation(fDummyFileName).getURI();
|
||||
}
|
||||
CodeReader codeReader= new CodeReader(fDummyFileName, code.toCharArray());
|
||||
ast= createAST(lang, codeReader, scanInfo, pm);
|
||||
ast= createAST(lang, codeReader, scanInfo, options, pm);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,7 +417,14 @@ public abstract class PDOMIndexerTask extends PDOMWriter implements IPDOMIndexer
|
|||
System.out.println(name + " " + getProject().getElementName() //$NON-NLS-1$
|
||||
+ " (" + info.fCompletedSources + " sources, " //$NON-NLS-1$ //$NON-NLS-2$
|
||||
+ info.fCompletedHeaders + " headers)"); //$NON-NLS-1$
|
||||
|
||||
boolean allFiles= getIndexAllFiles();
|
||||
boolean skipRefs= checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES);
|
||||
boolean skipTypeRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES);
|
||||
System.out.println(name + " Options: " //$NON-NLS-1$
|
||||
+ "parseAllFiles=" + allFiles //$NON-NLS-1$
|
||||
+ ",skipReferences=" + skipRefs //$NON-NLS-1$
|
||||
+ ", skipTypeReferences=" + skipTypeRefs //$NON-NLS-1$
|
||||
+ "."); //$NON-NLS-1$
|
||||
System.out.println(name + " Timings: " //$NON-NLS-1$
|
||||
+ (System.currentTimeMillis() - start) + " total, " //$NON-NLS-1$
|
||||
+ fStatistics.fParsingTime + " parser, " //$NON-NLS-1$
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
@ -36,7 +36,6 @@ import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory;
|
|||
import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory.FileInfo;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMIndexerTask;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
class PDOMFastIndexerTask extends PDOMIndexerTask {
|
||||
|
@ -128,31 +127,9 @@ class PDOMFastIndexerTask extends PDOMIndexerTask {
|
|||
return result;
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit createAST(ITranslationUnit tu, IProgressMonitor pm) throws CoreException {
|
||||
IPath path = tu.getLocation();
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
ILanguage language = tu.getLanguage();
|
||||
if (language == null)
|
||||
return null;
|
||||
|
||||
// skip if no scanner info
|
||||
IScannerInfo scanner= tu.getScannerInfo(getIndexAllFiles());
|
||||
if (scanner == null) {
|
||||
return null;
|
||||
}
|
||||
CodeReader codeReader = tu.getCodeReader();
|
||||
if (codeReader == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return createAST(language, codeReader, scanner, pm);
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit createAST(ILanguage lang, CodeReader codeReader, IScannerInfo scanInfo, IProgressMonitor pm) throws CoreException {
|
||||
protected IASTTranslationUnit createAST(AbstractLanguage lang, CodeReader codeReader, IScannerInfo scanInfo, int options, IProgressMonitor pm) throws CoreException {
|
||||
// get the AST in a "Fast" way
|
||||
IASTTranslationUnit ast= lang.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory, fIndex, ParserUtil.getParserLogService());
|
||||
IASTTranslationUnit ast= lang.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory, fIndex, options, ParserUtil.getParserLogService());
|
||||
if (pm.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|||
import org.eclipse.cdt.core.index.IIndexFile;
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.AbstractLanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
|
@ -35,7 +35,6 @@ import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
|||
import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMIndexerTask;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
|
@ -110,6 +109,9 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
|||
}
|
||||
|
||||
private void setupIndex() throws CoreException {
|
||||
// there is no mechanism to clear dirty files from the cache, so flush it.
|
||||
SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush();
|
||||
|
||||
fIndex = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(getProject());
|
||||
fIndex.resetCacheCounters();
|
||||
}
|
||||
|
@ -132,21 +134,9 @@ class PDOMFullIndexerTask extends PDOMIndexerTask {
|
|||
return result;
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit createAST(ITranslationUnit tu, IProgressMonitor pm) throws CoreException {
|
||||
IPath path = tu.getLocation();
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
int options= 0;
|
||||
if (!getIndexAllFiles()) {
|
||||
options |= ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO;
|
||||
}
|
||||
return tu.getAST(null, options);
|
||||
}
|
||||
|
||||
protected IASTTranslationUnit createAST(ILanguage lang, CodeReader codeReader, IScannerInfo scanInfo, IProgressMonitor pm) throws CoreException {
|
||||
protected IASTTranslationUnit createAST(AbstractLanguage lang, CodeReader codeReader, IScannerInfo scanInfo, int options, IProgressMonitor pm) throws CoreException {
|
||||
SavedCodeReaderFactory codeReaderFactory= SavedCodeReaderFactory.getInstance();
|
||||
IASTTranslationUnit ast= lang.getASTTranslationUnit(codeReader, scanInfo, codeReaderFactory, null, ParserUtil.getParserLogService());
|
||||
IASTTranslationUnit ast= lang.getASTTranslationUnit(codeReader, scanInfo, codeReaderFactory, null, options, ParserUtil.getParserLogService());
|
||||
if (pm.isCanceled()) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ import java.util.Properties;
|
|||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
@ -35,6 +37,8 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
|||
|
||||
private Button fAllFiles;
|
||||
private Text fFilesToParseUpFront;
|
||||
private Button fSkipReferences;
|
||||
private Button fSkipTypeReferences;
|
||||
|
||||
protected AbstractIndexerPage() {
|
||||
super();
|
||||
|
@ -51,7 +55,15 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
|||
public void createControl(Composite parent) {
|
||||
Composite page = ControlFactory.createComposite(parent, 1);
|
||||
fAllFiles= createAllFilesButton(page);
|
||||
fSkipReferences= createSkipReferencesButton(page);
|
||||
fSkipTypeReferences= createSkipTypeReferencesButton(page);
|
||||
fFilesToParseUpFront= createParseUpFrontTextField(page);
|
||||
|
||||
fSkipReferences.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
updateEnablement();
|
||||
}
|
||||
});
|
||||
setControl(page);
|
||||
}
|
||||
|
||||
|
@ -65,10 +77,19 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
|||
boolean indexAllFiles= TRUE.equals(properties.get(IndexerPreferences.KEY_INDEX_ALL_FILES));
|
||||
fAllFiles.setSelection(indexAllFiles);
|
||||
}
|
||||
if (fSkipReferences != null) {
|
||||
boolean skipReferences= TRUE.equals(properties.get(IndexerPreferences.KEY_SKIP_ALL_REFERENCES));
|
||||
fSkipReferences.setSelection(skipReferences);
|
||||
}
|
||||
if (fSkipTypeReferences != null) {
|
||||
boolean skipTypeReferences= TRUE.equals(properties.get(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES));
|
||||
fSkipTypeReferences.setSelection(skipTypeReferences);
|
||||
}
|
||||
if (fFilesToParseUpFront != null) {
|
||||
String files = getNotNull(properties, IndexerPreferences.KEY_FILES_TO_PARSE_UP_FRONT);
|
||||
fFilesToParseUpFront.setText(files);
|
||||
}
|
||||
updateEnablement();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,6 +104,12 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
|||
if (fFilesToParseUpFront != null) {
|
||||
props.put(IndexerPreferences.KEY_FILES_TO_PARSE_UP_FRONT, fFilesToParseUpFront.getText());
|
||||
}
|
||||
if (fSkipReferences != null) {
|
||||
props.put(IndexerPreferences.KEY_SKIP_ALL_REFERENCES, String.valueOf(fSkipReferences.getSelection()));
|
||||
}
|
||||
if (fSkipTypeReferences != null) {
|
||||
props.put(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES, String.valueOf(fSkipTypeReferences.getSelection()));
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
|
@ -100,10 +127,10 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated, never called.
|
||||
*/
|
||||
public void updateEnablement() {
|
||||
if (fSkipReferences != null && fSkipTypeReferences != null) {
|
||||
fSkipTypeReferences.setEnabled(!fSkipReferences.getSelection());
|
||||
}
|
||||
}
|
||||
|
||||
private String getNotNull(Properties properties, String key) {
|
||||
|
@ -123,4 +150,12 @@ public abstract class AbstractIndexerPage extends AbstractCOptionPage {
|
|||
private Button createAllFilesButton(Composite page) {
|
||||
return ControlFactory.createCheckBox(page, INDEX_ALL_FILES);
|
||||
}
|
||||
|
||||
private Button createSkipReferencesButton(Composite page) {
|
||||
return ControlFactory.createCheckBox(page, DialogsMessages.AbstractIndexerPage_skipAllReferences);
|
||||
}
|
||||
|
||||
private Button createSkipTypeReferencesButton(Composite page) {
|
||||
return ControlFactory.createCheckBox(page, DialogsMessages.AbstractIndexerPage_skipTypeReferences);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ public class DialogsMessages extends NLS {
|
|||
private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.dialogs.DialogsMessages"; //$NON-NLS-1$
|
||||
public static String AbstractIndexerPage_indexAllFiles;
|
||||
public static String AbstractIndexerPage_indexUpFront;
|
||||
public static String AbstractIndexerPage_skipAllReferences;
|
||||
public static String AbstractIndexerPage_skipTypeReferences;
|
||||
public static String PreferenceScopeBlock_enableProjectSettings;
|
||||
public static String PreferenceScopeBlock_preferenceLink;
|
||||
public static String PreferenceScopeBlock_storeWithProject;
|
||||
|
|
|
@ -12,4 +12,6 @@ PreferenceScopeBlock_enableProjectSettings=Enable project specific settings
|
|||
PreferenceScopeBlock_storeWithProject=Store settings with project
|
||||
PreferenceScopeBlock_preferenceLink=<a>Configure Workspace Settings...</a>
|
||||
AbstractIndexerPage_indexAllFiles=Index all files (files neither built nor included, also)
|
||||
AbstractIndexerPage_skipAllReferences=Skip all references (Call Hierarchy and Search will not work)
|
||||
AbstractIndexerPage_skipTypeReferences=Skip type references (Search for type references will not work)
|
||||
AbstractIndexerPage_indexUpFront=Files to index up-front:
|
||||
|
|
Loading…
Add table
Reference in a new issue