mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Extracts common stuff from full and fast indexer to a base class.
This commit is contained in:
parent
0eca098d3c
commit
e62a54fcea
6 changed files with 204 additions and 283 deletions
|
@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.index;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
@ -26,6 +25,7 @@ import org.eclipse.cdt.core.dom.ICodeReaderFactory;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexFile;
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
import org.eclipse.cdt.core.index.IIndexInclude;
|
import org.eclipse.cdt.core.index.IIndexInclude;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexMacro;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
import org.eclipse.cdt.core.parser.ICodeReaderCache;
|
||||||
|
@ -33,6 +33,7 @@ import org.eclipse.cdt.core.parser.IMacro;
|
||||||
import org.eclipse.cdt.core.parser.IScanner;
|
import org.eclipse.cdt.core.parser.IScanner;
|
||||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro;
|
import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro;
|
||||||
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacro;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
|
@ -46,7 +47,6 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
|
||||||
private final IIndex index;
|
private final IIndex index;
|
||||||
private Map fileInfoCache = new HashMap(); // filename, fileInfo
|
private Map fileInfoCache = new HashMap(); // filename, fileInfo
|
||||||
private List usedMacros = new ArrayList();
|
private List usedMacros = new ArrayList();
|
||||||
private Collection fPathCollector;
|
|
||||||
|
|
||||||
private static final char[] EMPTY_CHARS = new char[0];
|
private static final char[] EMPTY_CHARS = new char[0];
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
|
||||||
private FileInfo() {}
|
private FileInfo() {}
|
||||||
public IIndexFile fFile= null;
|
public IIndexFile fFile= null;
|
||||||
public IMacro[] fMacros= null;
|
public IMacro[] fMacros= null;
|
||||||
|
// public FileInfo[] fFileInfos= null;
|
||||||
private boolean fRequested= false;
|
private boolean fRequested= false;
|
||||||
|
|
||||||
public boolean isRequested() {
|
public boolean isRequested() {
|
||||||
|
@ -75,9 +76,6 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodeReader createCodeReaderForTranslationUnit(String path) {
|
public CodeReader createCodeReaderForTranslationUnit(String path) {
|
||||||
if (fPathCollector != null) {
|
|
||||||
fPathCollector.add(path);
|
|
||||||
}
|
|
||||||
return ParserUtil.createReader(path, null);
|
return ParserUtil.createReader(path, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +106,13 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
|
||||||
FileInfo fi = (FileInfo) iter.next();
|
FileInfo fi = (FileInfo) iter.next();
|
||||||
if (fi.fMacros == null) {
|
if (fi.fMacros == null) {
|
||||||
assert fi.fFile != null;
|
assert fi.fFile != null;
|
||||||
fi.fMacros= fi.fFile.getMacros();
|
IIndexMacro[] macros= fi.fFile.getMacros();
|
||||||
|
IMacro[] converted= new IMacro[macros.length];
|
||||||
|
for (int i = 0; i < macros.length; i++) {
|
||||||
|
IIndexMacro macro = macros[i];
|
||||||
|
converted[i]= ((PDOMMacro)macro).getMacro();
|
||||||
|
}
|
||||||
|
fi.fMacros= converted;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < fi.fMacros.length; ++i) {
|
for (int i = 0; i < fi.fMacros.length; ++i) {
|
||||||
scanner.addDefinition(fi.fMacros[i]);
|
scanner.addDefinition(fi.fMacros[i]);
|
||||||
|
@ -126,9 +130,6 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
|
||||||
// still try to parse the file.
|
// still try to parse the file.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fPathCollector != null) {
|
|
||||||
fPathCollector.add(canonicalPath);
|
|
||||||
}
|
|
||||||
return ParserUtil.createReader(canonicalPath, null);
|
return ParserUtil.createReader(canonicalPath, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,8 +188,4 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
|
||||||
public FileInfo createFileInfo(ITranslationUnit tu) throws CoreException {
|
public FileInfo createFileInfo(ITranslationUnit tu) throws CoreException {
|
||||||
return createInfo(tu.getLocation().toOSString(), null);
|
return createInfo(tu.getLocation().toOSString(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPathCollector(Collection paths) {
|
|
||||||
fPathCollector= paths;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,11 @@ package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||||
|
@ -137,6 +135,53 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void parseTUs(Collection sources, Collection headers, IProgressMonitor monitor) throws CoreException, InterruptedException {
|
||||||
|
// sources first
|
||||||
|
Iterator iter;
|
||||||
|
for (iter = sources.iterator(); iter.hasNext();) {
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
return;
|
||||||
|
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
||||||
|
String path = tu.getLocation().toOSString();
|
||||||
|
if (needToUpdate(path)) {
|
||||||
|
parseTU(tu, monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// headers with context
|
||||||
|
for (iter = headers.iterator(); iter.hasNext();) {
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
return;
|
||||||
|
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
||||||
|
String path = tu.getLocation().toOSString();
|
||||||
|
if (!needToUpdate(path)) {
|
||||||
|
iter.remove();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ITranslationUnit context= findContext(getIndex(), path);
|
||||||
|
if (context != null) {
|
||||||
|
parseTU(context, monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// headers without context
|
||||||
|
if (getIndexAllFiles()) {
|
||||||
|
for (iter = headers.iterator(); iter.hasNext();) {
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
return;
|
||||||
|
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
||||||
|
String path = tu.getLocation().toOSString();
|
||||||
|
if (!needToUpdate(path)) {
|
||||||
|
iter.remove();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
parseTU(tu, monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void parseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException {
|
protected void parseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException {
|
||||||
IPath path= tu.getPath();
|
IPath path= tu.getPath();
|
||||||
try {
|
try {
|
||||||
|
@ -246,40 +291,101 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
||||||
return fCompletedSources;
|
return fCompletedSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts a map of names from the ast and returns an array defining the order in
|
protected void addSymbols(IASTTranslationUnit ast, IProgressMonitor pm) throws InterruptedException, CoreException {
|
||||||
* which the symbols should be added to the index.
|
final Map symbolMap= new HashMap();
|
||||||
* @since 4.0
|
|
||||||
*/
|
String[] orderedPaths= extractSymbols(ast, symbolMap);
|
||||||
protected String[] extractSymbols(IASTTranslationUnit ast, Set legalPaths, final LinkedHashMap symbolMap) {
|
for (int i=0; i<orderedPaths.length; i++) {
|
||||||
// includes
|
if (pm.isCanceled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String path= orderedPaths[i];
|
||||||
|
ArrayList[] arrayLists = ((ArrayList[]) symbolMap.get(path));
|
||||||
|
|
||||||
|
// resolve the names
|
||||||
|
ArrayList names= arrayLists[2];
|
||||||
|
for (int j=0; j<names.size(); j++) {
|
||||||
|
((IASTName[]) names.get(j))[0].resolveBinding();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isFirstRequest= true;
|
||||||
|
boolean isFirstAddition= true;
|
||||||
|
IWritableIndex index= getIndex();
|
||||||
|
index.acquireWriteLock(getReadlockCount());
|
||||||
|
try {
|
||||||
|
for (int i=0; i<orderedPaths.length; i++) {
|
||||||
|
if (pm.isCanceled())
|
||||||
|
return;
|
||||||
|
|
||||||
|
String path = orderedPaths[i];
|
||||||
|
if (path != null) {
|
||||||
|
if (fTrace) {
|
||||||
|
System.out.println("Indexer: adding " + path); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
IIndexFile file= addToIndex(index, path, symbolMap);
|
||||||
|
if (postAddToIndex(path, file)) {
|
||||||
|
if (isFirstRequest)
|
||||||
|
isFirstRequest= false;
|
||||||
|
else
|
||||||
|
fTotalSourcesEstimate--;
|
||||||
|
}
|
||||||
|
if (isFirstAddition)
|
||||||
|
isFirstAddition= false;
|
||||||
|
else
|
||||||
|
fCompletedHeaders++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
index.releaseWriteLock(getReadlockCount());
|
||||||
|
}
|
||||||
|
fCompletedSources++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] extractSymbols(IASTTranslationUnit ast, final Map symbolMap) throws CoreException {
|
||||||
|
LinkedHashSet orderedIncludes= new LinkedHashSet();
|
||||||
|
ArrayList stack= new ArrayList();
|
||||||
|
|
||||||
final String astFilePath = ast.getFilePath();
|
final String astFilePath = ast.getFilePath();
|
||||||
|
String currentPath= astFilePath;
|
||||||
|
|
||||||
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
|
IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
|
||||||
for (int i = includes.length-1; i >= 0; --i) {
|
for (int i= 0; i < includes.length; i++) {
|
||||||
IASTPreprocessorIncludeStatement include = includes[i];
|
IASTPreprocessorIncludeStatement include = includes[i];
|
||||||
IASTFileLocation sourceLoc = include.getFileLocation();
|
IASTFileLocation sourceLoc = include.getFileLocation();
|
||||||
String path= sourceLoc != null ? sourceLoc.getFileName() : astFilePath; // command-line includes
|
String newPath= sourceLoc != null ? sourceLoc.getFileName() : astFilePath; // command-line includes
|
||||||
if (legalPaths.contains(path)) {
|
while (!stack.isEmpty() && !currentPath.equals(newPath)) {
|
||||||
prepareInMap(symbolMap, path);
|
if (needToUpdate(currentPath)) {
|
||||||
addToMap(symbolMap, 0, path, include);
|
prepareInMap(symbolMap, currentPath);
|
||||||
|
orderedIncludes.add(currentPath);
|
||||||
|
}
|
||||||
|
currentPath= (String) stack.remove(stack.size()-1);
|
||||||
}
|
}
|
||||||
path= include.getPath();
|
if (needToUpdate(newPath)) {
|
||||||
if (legalPaths.contains(path)) {
|
prepareInMap(symbolMap, newPath);
|
||||||
prepareInMap(symbolMap, path);
|
addToMap(symbolMap, 0, newPath, include);
|
||||||
|
}
|
||||||
|
stack.add(currentPath);
|
||||||
|
currentPath= include.getPath();
|
||||||
|
}
|
||||||
|
stack.add(currentPath);
|
||||||
|
while (!stack.isEmpty()) {
|
||||||
|
currentPath= (String) stack.remove(stack.size()-1);
|
||||||
|
if (needToUpdate(currentPath)) {
|
||||||
|
prepareInMap(symbolMap, currentPath);
|
||||||
|
orderedIncludes.add(currentPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (legalPaths.contains(astFilePath)) {
|
|
||||||
prepareInMap(symbolMap, ast.getFilePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
// macros
|
// macros
|
||||||
IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions();
|
IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions();
|
||||||
for (int i = 0; i < macros.length; ++i) {
|
for (int i2 = 0; i2 < macros.length; ++i2) {
|
||||||
IASTPreprocessorMacroDefinition macro = macros[i];
|
IASTPreprocessorMacroDefinition macro = macros[i2];
|
||||||
IASTFileLocation sourceLoc = macro.getFileLocation();
|
IASTFileLocation sourceLoc = macro.getFileLocation();
|
||||||
if (sourceLoc != null) { // skip built-ins and command line macros
|
if (sourceLoc != null) { // skip built-ins and command line macros
|
||||||
String path = sourceLoc.getFileName();
|
String path2 = sourceLoc.getFileName();
|
||||||
addToMap(symbolMap, 1, path, macro);
|
addToMap(symbolMap, 1, path2, macro);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,17 +398,16 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return (String[]) orderedIncludes.toArray(new String[orderedIncludes.size()]);
|
||||||
Collection temp= symbolMap.keySet();
|
|
||||||
int size= temp.size();
|
|
||||||
String[] result= new String[temp.size()];
|
|
||||||
for (Iterator iter = temp.iterator(); iter.hasNext();) {
|
|
||||||
result[--size]= (String) iter.next();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToMap(HashMap map, int idx, String path, Object thing) {
|
protected abstract IWritableIndex getIndex();
|
||||||
|
protected abstract int getReadlockCount();
|
||||||
|
protected abstract boolean needToUpdate(String path) throws CoreException;
|
||||||
|
protected abstract boolean postAddToIndex(String path, IIndexFile file) throws CoreException;
|
||||||
|
|
||||||
|
|
||||||
|
private void addToMap(Map map, int idx, String path, Object thing) {
|
||||||
List[] lists= (List[]) map.get(path);
|
List[] lists= (List[]) map.get(path);
|
||||||
if (lists != null)
|
if (lists != null)
|
||||||
lists[idx].add(thing);
|
lists[idx].add(thing);
|
||||||
|
@ -316,20 +421,7 @@ public abstract class PDOMIndexerTask implements IPDOMIndexerTask {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void prepareIndexInsertion(String path, Map symbolMap) {
|
private IIndexFragmentFile addToIndex(IWritableIndex index, String location, Map symbolMap) throws CoreException {
|
||||||
ArrayList[] arrayLists = ((ArrayList[]) symbolMap.get(path));
|
|
||||||
|
|
||||||
// reverse the includes
|
|
||||||
Collections.reverse(arrayLists[0]);
|
|
||||||
|
|
||||||
// resolve the names
|
|
||||||
ArrayList names= arrayLists[2];
|
|
||||||
for (int j=0; j<names.size(); j++) {
|
|
||||||
((IASTName[]) names.get(j))[0].resolveBinding();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IIndexFragmentFile addToIndex(IWritableIndex index, String location, Map symbolMap) throws CoreException {
|
|
||||||
// Remove the old symbols in the tu
|
// Remove the old symbols in the tu
|
||||||
Path path= new Path(location);
|
Path path= new Path(location);
|
||||||
IIndexFragmentFile file= (IIndexFragmentFile) index.getFile(path);
|
IIndexFragmentFile file= (IIndexFragmentFile) index.getFile(path);
|
||||||
|
|
|
@ -13,15 +13,13 @@
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
package org.eclipse.cdt.internal.core.pdom.indexer.fast;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
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.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
|
@ -85,9 +83,6 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet paths= new HashSet();
|
|
||||||
paths.add(path.toOSString());
|
|
||||||
codeReaderFactory.setPathCollector(paths);
|
|
||||||
index.acquireReadLock();
|
index.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
// get the AST in a "Fast" way
|
// get the AST in a "Fast" way
|
||||||
|
@ -99,118 +94,34 @@ abstract class PDOMFastIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
|
||||||
codeReaderFactory.clearMacroAttachements();
|
codeReaderFactory.clearMacroAttachements();
|
||||||
|
|
||||||
// Add the new symbols
|
// Add the new symbols
|
||||||
addSymbols(paths, ast, pm);
|
addSymbols(ast, pm);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
index.releaseReadLock();
|
index.releaseReadLock();
|
||||||
codeReaderFactory.setPathCollector(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addSymbols(HashSet paths, IASTTranslationUnit ast, IProgressMonitor pm) throws InterruptedException, CoreException {
|
protected IWritableIndex getIndex() {
|
||||||
// Add in the includes
|
return index;
|
||||||
final LinkedHashMap symbolMap= new LinkedHashMap();
|
|
||||||
String[] orderedPaths= extractSymbols(ast, paths, symbolMap);
|
|
||||||
|
|
||||||
for (int i=0; i<orderedPaths.length; i++) {
|
|
||||||
if (pm.isCanceled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String path= orderedPaths[i];
|
|
||||||
FileInfo info= codeReaderFactory.createFileInfo(path);
|
|
||||||
|
|
||||||
// file is requested or is not yet indexed.
|
|
||||||
if (info.isRequested() || info.fFile == null) {
|
|
||||||
prepareIndexInsertion(path, symbolMap);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (fTrace) {
|
|
||||||
System.out.println("Indexer: skipping " + path); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
orderedPaths[i]= null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isFirstRequest= true;
|
|
||||||
boolean isFirstAddition= true;
|
|
||||||
index.acquireWriteLock(1);
|
|
||||||
try {
|
|
||||||
for (int i=0; i<orderedPaths.length; i++) {
|
|
||||||
if (pm.isCanceled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
String path = orderedPaths[i];
|
|
||||||
if (path != null) {
|
|
||||||
FileInfo info= codeReaderFactory.createFileInfo(path);
|
|
||||||
if (info.isRequested()) {
|
|
||||||
info.setRequested(false);
|
|
||||||
|
|
||||||
if (isFirstRequest)
|
|
||||||
isFirstRequest= false;
|
|
||||||
else
|
|
||||||
fTotalSourcesEstimate--;
|
|
||||||
}
|
|
||||||
if (fTrace) {
|
|
||||||
System.out.println("Indexer: adding " + path); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
info.fFile= addToIndex(index, path, symbolMap);
|
|
||||||
|
|
||||||
if (isFirstAddition)
|
|
||||||
isFirstAddition= false;
|
|
||||||
else
|
|
||||||
fCompletedHeaders++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
index.releaseWriteLock(1);
|
|
||||||
}
|
|
||||||
fCompletedSources++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int getReadlockCount() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
protected void parseTUs(List sources, List headers, IProgressMonitor monitor) throws CoreException, InterruptedException {
|
protected boolean needToUpdate(String path) throws CoreException {
|
||||||
// sources first
|
// file is requested or is not yet indexed.
|
||||||
Iterator iter;
|
FileInfo info= codeReaderFactory.createFileInfo(path);
|
||||||
for (iter= sources.iterator(); iter.hasNext();) {
|
return info.isRequested() || info.fFile == null;
|
||||||
if (monitor.isCanceled())
|
}
|
||||||
return;
|
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
|
||||||
parseTU(tu, monitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
// headers with context
|
protected boolean postAddToIndex(String path, IIndexFile file) throws CoreException {
|
||||||
for (iter= headers.iterator(); iter.hasNext();) {
|
FileInfo info= codeReaderFactory.createFileInfo(path);
|
||||||
if (monitor.isCanceled())
|
info.fFile= file;
|
||||||
return;
|
if (info.isRequested()) {
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
info.setRequested(false);
|
||||||
FileInfo info= codeReaderFactory.createFileInfo(tu);
|
return true;
|
||||||
// check if header was handled while parsing a source
|
|
||||||
if (!info.isRequested()) {
|
|
||||||
iter.remove();
|
|
||||||
}
|
|
||||||
else if (info.fFile != null) {
|
|
||||||
ITranslationUnit context= findContext(index, info.fFile.getLocation());
|
|
||||||
if (context != null) {
|
|
||||||
parseTU(context, monitor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// headers without context
|
|
||||||
if (getIndexAllFiles()) {
|
|
||||||
for (iter= headers.iterator(); iter.hasNext();) {
|
|
||||||
if (monitor.isCanceled())
|
|
||||||
return;
|
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
|
||||||
FileInfo info= codeReaderFactory.createFileInfo(tu);
|
|
||||||
// check if header was handled while parsing a source
|
|
||||||
if (!info.isRequested()) {
|
|
||||||
iter.remove();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
parseTU(tu, monitor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,8 @@ class PDOMFullHandleDelta extends PDOMFullIndexerJob {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerTUsInReaderFactory(sources, headers, true);
|
registerTUsInReaderFactory(sources);
|
||||||
|
registerTUsInReaderFactory(headers);
|
||||||
|
|
||||||
Iterator i= removed.iterator();
|
Iterator i= removed.iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
|
|
|
@ -15,13 +15,13 @@ package org.eclipse.cdt.internal.core.pdom.indexer.full;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
import org.eclipse.cdt.core.dom.IPDOMIndexer;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
import org.eclipse.cdt.internal.core.index.IWritableIndex;
|
||||||
import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
|
import org.eclipse.cdt.internal.core.index.IWritableIndexManager;
|
||||||
|
@ -35,10 +35,13 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexerTask {
|
abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexerTask {
|
||||||
|
final static Object REQUIRED= new Object();
|
||||||
|
final static Object MISSING = new Object();
|
||||||
|
final static Object SKIP= new Object();
|
||||||
|
|
||||||
protected final PDOMFullIndexer indexer;
|
protected final PDOMFullIndexer indexer;
|
||||||
protected IWritableIndex index= null;
|
protected IWritableIndex index= null;
|
||||||
private Map filePathsToParse= null;
|
private Map filePathsToParse= new HashMap();
|
||||||
|
|
||||||
public PDOMFullIndexerJob(PDOMFullIndexer indexer) throws CoreException {
|
public PDOMFullIndexerJob(PDOMFullIndexer indexer) throws CoreException {
|
||||||
this.indexer = indexer;
|
this.indexer = indexer;
|
||||||
|
@ -52,68 +55,15 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
|
||||||
this.index = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(indexer.getProject());
|
this.index = ((IWritableIndexManager) CCorePlugin.getIndexManager()).getWritableIndex(indexer.getProject());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void registerTUsInReaderFactory(Collection sources, Collection headers,
|
protected void registerTUsInReaderFactory(Collection sources) throws CoreException {
|
||||||
boolean requireHeaders) throws CoreException {
|
|
||||||
filePathsToParse= new HashMap();
|
filePathsToParse= new HashMap();
|
||||||
|
|
||||||
for (Iterator iter = sources.iterator(); iter.hasNext();) {
|
for (Iterator iter = sources.iterator(); iter.hasNext();) {
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
||||||
filePathsToParse.put(tu.getLocation().toOSString(), Boolean.TRUE);
|
filePathsToParse.put(tu.getLocation().toOSString(), REQUIRED);
|
||||||
}
|
|
||||||
Boolean required= Boolean.valueOf(requireHeaders);
|
|
||||||
for (Iterator iter = headers.iterator(); iter.hasNext();) {
|
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
|
||||||
filePathsToParse.put(tu.getLocation().toOSString(), required);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseTUs(Collection sources, Collection headers, IProgressMonitor monitor) throws CoreException, InterruptedException {
|
|
||||||
// sources first
|
|
||||||
Iterator iter;
|
|
||||||
for (iter = sources.iterator(); iter.hasNext();) {
|
|
||||||
if (monitor.isCanceled())
|
|
||||||
return;
|
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
|
||||||
String path = tu.getLocation().toOSString();
|
|
||||||
if (filePathsToParse.get(path) != null) {
|
|
||||||
parseTU(tu, monitor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// headers with context
|
|
||||||
for (iter = headers.iterator(); iter.hasNext();) {
|
|
||||||
if (monitor.isCanceled())
|
|
||||||
return;
|
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
|
||||||
String path = tu.getLocation().toOSString();
|
|
||||||
if (filePathsToParse.get(path)==null) {
|
|
||||||
iter.remove();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ITranslationUnit context= findContext(index, path);
|
|
||||||
if (context != null) {
|
|
||||||
parseTU(context, monitor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// headers without context
|
|
||||||
if (getIndexAllFiles()) {
|
|
||||||
for (iter = headers.iterator(); iter.hasNext();) {
|
|
||||||
if (monitor.isCanceled())
|
|
||||||
return;
|
|
||||||
ITranslationUnit tu = (ITranslationUnit) iter.next();
|
|
||||||
String path = tu.getLocation().toOSString();
|
|
||||||
if (filePathsToParse.get(path)==null) {
|
|
||||||
iter.remove();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
parseTU(tu, monitor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void doParseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException {
|
protected void doParseTU(ITranslationUnit tu, IProgressMonitor pm) throws CoreException, InterruptedException {
|
||||||
IPath path = tu.getLocation();
|
IPath path = tu.getLocation();
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
|
@ -128,51 +78,27 @@ abstract class PDOMFullIndexerJob extends PDOMIndexerTask implements IPDOMIndexe
|
||||||
addSymbols(ast, pm);
|
addSymbols(ast, pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addSymbols(IASTTranslationUnit ast, IProgressMonitor pm) throws InterruptedException, CoreException {
|
|
||||||
// Add in the includes
|
protected IWritableIndex getIndex() {
|
||||||
final LinkedHashMap symbolMap= new LinkedHashMap();
|
return index;
|
||||||
String[] orderedPaths= extractSymbols(ast, filePathsToParse.keySet(), symbolMap);
|
}
|
||||||
|
|
||||||
for (int i=0; i<orderedPaths.length; i++) {
|
|
||||||
if (pm.isCanceled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String path= orderedPaths[i];
|
|
||||||
prepareIndexInsertion(path, symbolMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isFirstRequest= true;
|
protected int getReadlockCount() {
|
||||||
boolean isFirstAddition= true;
|
return 0;
|
||||||
index.acquireWriteLock(0);
|
}
|
||||||
try {
|
|
||||||
for (int i=0; i<orderedPaths.length; i++) {
|
|
||||||
if (pm.isCanceled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
String path = orderedPaths[i];
|
|
||||||
Boolean required= (Boolean) filePathsToParse.remove(path);
|
|
||||||
if (required != null) {
|
|
||||||
if (required.booleanValue()) {
|
|
||||||
if (isFirstRequest)
|
|
||||||
isFirstRequest= false;
|
|
||||||
else
|
|
||||||
fTotalSourcesEstimate--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fTrace)
|
protected boolean needToUpdate(String path) throws CoreException {
|
||||||
System.out.println("Indexer: adding " + path); //$NON-NLS-1$
|
Object required= filePathsToParse.get(path);
|
||||||
|
if (required == null) {
|
||||||
addToIndex(index, path, symbolMap);
|
required= MISSING;
|
||||||
|
filePathsToParse.put(path, required);
|
||||||
if (isFirstAddition)
|
|
||||||
isFirstAddition= false;
|
|
||||||
else
|
|
||||||
fCompletedHeaders++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
index.releaseWriteLock(0);
|
|
||||||
}
|
}
|
||||||
fCompletedSources++;
|
return required != SKIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean postAddToIndex(String path, IIndexFile file) throws CoreException {
|
||||||
|
Object required= filePathsToParse.get(path);
|
||||||
|
filePathsToParse.put(path, SKIP);
|
||||||
|
return required == REQUIRED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,15 +34,12 @@ class PDOMFullReindex extends PDOMFullIndexerJob {
|
||||||
public void run(final IProgressMonitor monitor) {
|
public void run(final IProgressMonitor monitor) {
|
||||||
try {
|
try {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
boolean allfiles= getIndexAllFiles();
|
boolean allFiles= getIndexAllFiles();
|
||||||
List headers= new ArrayList();
|
|
||||||
List sources= new ArrayList();
|
List sources= new ArrayList();
|
||||||
|
List headers= new ArrayList();
|
||||||
|
|
||||||
collectSources(indexer.getProject(), sources, headers, allfiles);
|
collectSources(indexer.getProject(), sources, allFiles ? headers : null, allFiles);
|
||||||
|
fTotalSourcesEstimate= sources.size() + headers.size();
|
||||||
fTotalSourcesEstimate= sources.size();
|
|
||||||
if (allfiles)
|
|
||||||
fTotalSourcesEstimate+= headers.size();
|
|
||||||
|
|
||||||
setupIndexAndReaderFactory();
|
setupIndexAndReaderFactory();
|
||||||
clearIndex(index);
|
clearIndex(index);
|
||||||
|
@ -51,10 +48,7 @@ class PDOMFullReindex extends PDOMFullIndexerJob {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerTUsInReaderFactory(sources, headers, allfiles);
|
registerTUsInReaderFactory(sources);
|
||||||
if (!allfiles)
|
|
||||||
headers.clear();
|
|
||||||
|
|
||||||
parseTUs(sources, headers, monitor);
|
parseTUs(sources, headers, monitor);
|
||||||
|
|
||||||
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
|
String showTimings = Platform.getDebugOption(CCorePlugin.PLUGIN_ID
|
||||||
|
|
Loading…
Add table
Reference in a new issue