mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Improvements for writing to the index (potential NPE, progress reporting, tracing).
This commit is contained in:
parent
34a4df0832
commit
bad35ab17a
3 changed files with 59 additions and 57 deletions
|
@ -68,9 +68,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
fUri= uri;
|
fUri= uri;
|
||||||
fLinkageID= linkageID;
|
fLinkageID= linkageID;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return fUri.hashCode() * 31 + fLinkageID;
|
return fUri.hashCode() * 31 + fLinkageID;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
FileKey other = (FileKey) obj;
|
FileKey other = (FileKey) obj;
|
||||||
return fLinkageID == other.fLinkageID && fUri.equals(other.fUri);
|
return fLinkageID == other.fLinkageID && fUri.equals(other.fUri);
|
||||||
|
@ -525,7 +527,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, header);
|
final IScannerInfo scannerInfo= fResolver.getBuildConfiguration(linkageID, header);
|
||||||
parseFile(header, linkageID, ifl, scannerInfo, monitor);
|
parseFile(header, linkageID, ifl, scannerInfo, monitor);
|
||||||
if (info.fIsUpdated) {
|
if (info.fIsUpdated) {
|
||||||
updateInfo(-1, 1, 0); // a header was parsed without context
|
updateInfo(0, 1, -1); // a header was parsed without context
|
||||||
iter.remove();
|
iter.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -601,27 +603,25 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeToIndex(final int linkageID, IASTTranslationUnit ast, int configHash, IProgressMonitor pm) throws CoreException, InterruptedException {
|
private void writeToIndex(final int linkageID, IASTTranslationUnit ast, int configHash, IProgressMonitor pm) throws CoreException, InterruptedException {
|
||||||
HashSet<String> enteredASTFilePaths= new HashSet<String>();
|
HashSet<IIndexFileLocation> enteredFiles= new HashSet<IIndexFileLocation>();
|
||||||
ArrayList<IIndexFileLocation> orderedIFLs= new ArrayList<IIndexFileLocation>();
|
ArrayList<IIndexFileLocation> orderedIFLs= new ArrayList<IIndexFileLocation>();
|
||||||
final String astPath = ast.getFilePath();
|
|
||||||
enteredASTFilePaths.add(astPath);
|
|
||||||
|
|
||||||
|
final IIndexFileLocation topIfl = fResolver.resolveASTPath(ast.getFilePath());
|
||||||
|
enteredFiles.add(topIfl);
|
||||||
IDependencyTree tree= ast.getDependencyTree();
|
IDependencyTree tree= ast.getDependencyTree();
|
||||||
IASTInclusionNode[] inclusions= tree.getInclusions();
|
IASTInclusionNode[] inclusions= tree.getInclusions();
|
||||||
for (int i=0; i < inclusions.length; i++) {
|
for (int i=0; i < inclusions.length; i++) {
|
||||||
collectOrderedIFLs(linkageID, inclusions[i], enteredASTFilePaths, orderedIFLs);
|
collectOrderedIFLs(linkageID, inclusions[i], enteredFiles, orderedIFLs);
|
||||||
}
|
}
|
||||||
|
|
||||||
IIndexFileLocation ifl= fResolver.resolveASTPath(astPath);
|
FileContent info= getFileInfo(linkageID, topIfl);
|
||||||
FileContent info= getFileInfo(linkageID, ifl);
|
|
||||||
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
|
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
|
||||||
orderedIFLs.add(fResolver.resolveASTPath(astPath));
|
orderedIFLs.add(topIfl);
|
||||||
}
|
}
|
||||||
|
|
||||||
IIndexFileLocation[] ifls= orderedIFLs.toArray(new IIndexFileLocation[orderedIFLs.size()]);
|
IIndexFileLocation[] ifls= orderedIFLs.toArray(new IIndexFileLocation[orderedIFLs.size()]);
|
||||||
addSymbols(ast, ifls, fIndex, 1, false, configHash, fTodoTaskUpdater, pm);
|
addSymbols(ast, ifls, fIndex, 1, false, configHash, fTodoTaskUpdater, pm);
|
||||||
for (int i = 0; i < ifls.length; i++) {
|
for (IIndexFileLocation ifl : ifls) {
|
||||||
ifl= ifls[i];
|
|
||||||
info= getFileInfo(linkageID, ifl);
|
info= getFileInfo(linkageID, ifl);
|
||||||
assert info != null;
|
assert info != null;
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
|
@ -630,20 +630,17 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void collectOrderedIFLs(final int linkageID, IASTInclusionNode inclusion, HashSet<String> enteredASTFilePaths, ArrayList<IIndexFileLocation> orderedIFLs) throws CoreException {
|
private void collectOrderedIFLs(final int linkageID, IASTInclusionNode inclusion, HashSet<IIndexFileLocation> enteredFiles, ArrayList<IIndexFileLocation> orderedIFLs) throws CoreException {
|
||||||
final IASTPreprocessorIncludeStatement id= inclusion.getIncludeDirective();
|
final IASTPreprocessorIncludeStatement id= inclusion.getIncludeDirective();
|
||||||
if (id.isActive() && id.isResolved()) {
|
if (id.isActive() && id.isResolved()) {
|
||||||
final String path= id.getPath();
|
final IIndexFileLocation ifl= fResolver.resolveASTPath(id.getPath());
|
||||||
final boolean isFirst= enteredASTFilePaths.add(path);
|
final boolean isFirstEntry= enteredFiles.add(ifl);
|
||||||
IASTInclusionNode[] nested= inclusion.getNestedInclusions();
|
IASTInclusionNode[] nested= inclusion.getNestedInclusions();
|
||||||
for (int i = 0; i < nested.length; i++) {
|
for (int i = 0; i < nested.length; i++) {
|
||||||
collectOrderedIFLs(linkageID, nested[i], enteredASTFilePaths, orderedIFLs);
|
collectOrderedIFLs(linkageID, nested[i], enteredFiles, orderedIFLs);
|
||||||
}
|
}
|
||||||
if (isFirst) {
|
if (isFirstEntry && needToUpdateHeader(linkageID, ifl)) {
|
||||||
final IIndexFileLocation ifl= fResolver.resolveASTPath(path);
|
orderedIFLs.add(ifl);
|
||||||
if (needToUpdateHeader(linkageID, ifl)) {
|
|
||||||
orderedIFLs.add(ifl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,45 +224,47 @@ abstract public class PDOMWriter {
|
||||||
IIndexFileLocation path= ifls[i];
|
IIndexFileLocation path= ifls[i];
|
||||||
Symbols symbols= symbolMap.get(path);
|
Symbols symbols= symbolMap.get(path);
|
||||||
|
|
||||||
ArrayList<IASTName[]> names= symbols.fNames;
|
final ArrayList<IASTName[]> names= symbols.fNames;
|
||||||
boolean reported= false;
|
boolean reported= false;
|
||||||
for (Iterator<IASTName[]> j = names.iterator(); j.hasNext();) {
|
for (Iterator<IASTName[]> j = names.iterator(); j.hasNext();) {
|
||||||
final IASTName[] na= j.next();
|
final IASTName[] na= j.next();
|
||||||
final IASTName name = na[0];
|
final IASTName name = na[0];
|
||||||
try {
|
if (name != null) { // should not be null, just be defensive.
|
||||||
final IBinding binding = name.resolveBinding();
|
try {
|
||||||
if (binding instanceof IProblemBinding) {
|
final IBinding binding = name.resolveBinding();
|
||||||
fStatistics.fProblemBindingCount++;
|
if (binding instanceof IProblemBinding) {
|
||||||
if (fShowProblems) {
|
fStatistics.fProblemBindingCount++;
|
||||||
reportProblem((IProblemBinding) binding);
|
if (fShowProblems) {
|
||||||
}
|
reportProblem((IProblemBinding) binding);
|
||||||
}
|
|
||||||
else if (name.isReference()) {
|
|
||||||
if (fSkipReferences == SKIP_TYPE_REFERENCES) {
|
|
||||||
if (isTypeReferenceBinding(binding) && !isRequiredReference(name)) {
|
|
||||||
na[0]= null;
|
|
||||||
fStatistics.fReferenceCount--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fStatistics.fReferenceCount++;
|
else if (name.isReference()) {
|
||||||
|
if (fSkipReferences == SKIP_TYPE_REFERENCES) {
|
||||||
|
if (isTypeReferenceBinding(binding) && !isRequiredReference(name)) {
|
||||||
|
na[0]= null;
|
||||||
|
fStatistics.fReferenceCount--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fStatistics.fReferenceCount++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fStatistics.fDeclarationCount++;
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
if (!reported) {
|
||||||
|
stati.add(CCorePlugin.createStatus(
|
||||||
|
NLS.bind(Messages.PDOMWriter_errorResolvingName, name.toString(), path.getURI().getPath()), e));
|
||||||
|
}
|
||||||
|
reported= true;
|
||||||
|
j.remove();
|
||||||
|
} catch (PDOMNotImplementedError e) {
|
||||||
|
if (!reported) {
|
||||||
|
stati.add(CCorePlugin.createStatus(
|
||||||
|
NLS.bind(Messages.PDOMWriter_errorResolvingName, name.toString(), path.getURI().getPath()), e));
|
||||||
|
}
|
||||||
|
reported= true;
|
||||||
|
j.remove();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
fStatistics.fDeclarationCount++;
|
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
if (!reported) {
|
|
||||||
stati.add(CCorePlugin.createStatus(
|
|
||||||
NLS.bind(Messages.PDOMWriter_errorResolvingName, name.toString(), path.getURI().getPath()), e));
|
|
||||||
}
|
|
||||||
reported= true;
|
|
||||||
j.remove();
|
|
||||||
} catch (PDOMNotImplementedError e) {
|
|
||||||
if (!reported) {
|
|
||||||
stati.add(CCorePlugin.createStatus(
|
|
||||||
NLS.bind(Messages.PDOMWriter_errorResolvingName, name.toString(), path.getURI().getPath()), e));
|
|
||||||
}
|
|
||||||
reported= true;
|
|
||||||
j.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -337,8 +339,8 @@ abstract public class PDOMWriter {
|
||||||
|
|
||||||
fStatistics.fUnresolvedIncludesCount += unresolvedIncludes;
|
fStatistics.fUnresolvedIncludesCount += unresolvedIncludes;
|
||||||
fStatistics.fPreprocessorProblemCount+= ast.getPreprocessorProblemsCount() - unresolvedIncludes;
|
fStatistics.fPreprocessorProblemCount+= ast.getPreprocessorProblemsCount() - unresolvedIncludes;
|
||||||
if (fShowScannerProblems || fShowSyntaxProblems) {
|
if (fShowScannerProblems || fShowInclusionProblems) {
|
||||||
final boolean reportAll= fShowScannerProblems && fShowSyntaxProblems;
|
final boolean reportAll= fShowScannerProblems && fShowInclusionProblems;
|
||||||
IASTProblem[] scannerProblems= ast.getPreprocessorProblems();
|
IASTProblem[] scannerProblems= ast.getPreprocessorProblems();
|
||||||
for (IASTProblem problem : scannerProblems) {
|
for (IASTProblem problem : scannerProblems) {
|
||||||
if (reportAll || (problem.getID() == IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND) == fShowInclusionProblems) {
|
if (reportAll || (problem.getID() == IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND) == fShowInclusionProblems) {
|
||||||
|
|
|
@ -152,6 +152,9 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
|
||||||
String filename= linkageID == ILinkage.C_LINKAGE_ID ? "__cdt__.c" : "__cdt__.cpp"; //$NON-NLS-1$//$NON-NLS-2$
|
String filename= linkageID == ILinkage.C_LINKAGE_ID ? "__cdt__.c" : "__cdt__.cpp"; //$NON-NLS-1$//$NON-NLS-2$
|
||||||
IFile file= project.getFile(filename);
|
IFile file= project.getFile(filename);
|
||||||
scanInfo= provider.getScannerInformation(file);
|
scanInfo= provider.getScannerInformation(file);
|
||||||
|
if (scanInfo == null || scanInfo.getDefinedSymbols().isEmpty()) {
|
||||||
|
scanInfo= provider.getScannerInformation(project);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
scanInfo= new ScannerInfo();
|
scanInfo= new ScannerInfo();
|
||||||
|
@ -203,10 +206,10 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
|
||||||
+ fStatistics.fResolutionTime + " resolution, " //$NON-NLS-1$
|
+ fStatistics.fResolutionTime + " resolution, " //$NON-NLS-1$
|
||||||
+ fStatistics.fAddToIndexTime + " index update."); //$NON-NLS-1$
|
+ fStatistics.fAddToIndexTime + " index update."); //$NON-NLS-1$
|
||||||
System.out.println(name + " Errors: " //$NON-NLS-1$
|
System.out.println(name + " Errors: " //$NON-NLS-1$
|
||||||
+ fStatistics.fUnresolvedIncludesCount + " include, " //$NON-NLS-1$
|
+ fStatistics.fErrorCount + " internal, " //$NON-NLS-1$
|
||||||
+ fStatistics.fPreprocessorProblemCount + " scanner, " //$NON-NLS-1$
|
+ fStatistics.fUnresolvedIncludesCount + " include, " //$NON-NLS-1$
|
||||||
+ fStatistics.fSyntaxProblemsCount + " syntax, " //$NON-NLS-1$
|
+ fStatistics.fPreprocessorProblemCount + " scanner, " //$NON-NLS-1$
|
||||||
+ fStatistics.fErrorCount + " internal errors."); //$NON-NLS-1$
|
+ fStatistics.fSyntaxProblemsCount + " syntax errors."); //$NON-NLS-1$
|
||||||
|
|
||||||
int sum= fStatistics.fDeclarationCount+fStatistics.fReferenceCount+fStatistics.fProblemBindingCount;
|
int sum= fStatistics.fDeclarationCount+fStatistics.fReferenceCount+fStatistics.fProblemBindingCount;
|
||||||
double problemPct= sum==0 ? 0.0 : (double) fStatistics.fProblemBindingCount / (double) sum;
|
double problemPct= sum==0 ? 0.0 : (double) fStatistics.fProblemBindingCount / (double) sum;
|
||||||
|
|
Loading…
Add table
Reference in a new issue