1
0
Fork 0
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:
Markus Schorn 2008-02-15 16:33:11 +00:00
parent 34a4df0832
commit bad35ab17a
3 changed files with 59 additions and 57 deletions

View file

@ -68,9 +68,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
fUri= uri;
fLinkageID= linkageID;
}
@Override
public int hashCode() {
return fUri.hashCode() * 31 + fLinkageID;
}
@Override
public boolean equals(Object obj) {
FileKey other = (FileKey) obj;
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);
parseFile(header, linkageID, ifl, scannerInfo, monitor);
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();
}
}
@ -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 {
HashSet<String> enteredASTFilePaths= new HashSet<String>();
HashSet<IIndexFileLocation> enteredFiles= new HashSet<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();
IASTInclusionNode[] inclusions= tree.getInclusions();
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, ifl);
FileContent info= getFileInfo(linkageID, topIfl);
if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
orderedIFLs.add(fResolver.resolveASTPath(astPath));
orderedIFLs.add(topIfl);
}
IIndexFileLocation[] ifls= orderedIFLs.toArray(new IIndexFileLocation[orderedIFLs.size()]);
addSymbols(ast, ifls, fIndex, 1, false, configHash, fTodoTaskUpdater, pm);
for (int i = 0; i < ifls.length; i++) {
ifl= ifls[i];
for (IIndexFileLocation ifl : ifls) {
info= getFileInfo(linkageID, ifl);
assert 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();
if (id.isActive() && id.isResolved()) {
final String path= id.getPath();
final boolean isFirst= enteredASTFilePaths.add(path);
final IIndexFileLocation ifl= fResolver.resolveASTPath(id.getPath());
final boolean isFirstEntry= enteredFiles.add(ifl);
IASTInclusionNode[] nested= inclusion.getNestedInclusions();
for (int i = 0; i < nested.length; i++) {
collectOrderedIFLs(linkageID, nested[i], enteredASTFilePaths, orderedIFLs);
collectOrderedIFLs(linkageID, nested[i], enteredFiles, orderedIFLs);
}
if (isFirst) {
final IIndexFileLocation ifl= fResolver.resolveASTPath(path);
if (needToUpdateHeader(linkageID, ifl)) {
orderedIFLs.add(ifl);
}
if (isFirstEntry && needToUpdateHeader(linkageID, ifl)) {
orderedIFLs.add(ifl);
}
}
}

View file

@ -224,45 +224,47 @@ abstract public class PDOMWriter {
IIndexFileLocation path= ifls[i];
Symbols symbols= symbolMap.get(path);
ArrayList<IASTName[]> names= symbols.fNames;
final ArrayList<IASTName[]> names= symbols.fNames;
boolean reported= false;
for (Iterator<IASTName[]> j = names.iterator(); j.hasNext();) {
final IASTName[] na= j.next();
final IASTName name = na[0];
try {
final IBinding binding = name.resolveBinding();
if (binding instanceof IProblemBinding) {
fStatistics.fProblemBindingCount++;
if (fShowProblems) {
reportProblem((IProblemBinding) binding);
}
}
else if (name.isReference()) {
if (fSkipReferences == SKIP_TYPE_REFERENCES) {
if (isTypeReferenceBinding(binding) && !isRequiredReference(name)) {
na[0]= null;
fStatistics.fReferenceCount--;
if (name != null) { // should not be null, just be defensive.
try {
final IBinding binding = name.resolveBinding();
if (binding instanceof IProblemBinding) {
fStatistics.fProblemBindingCount++;
if (fShowProblems) {
reportProblem((IProblemBinding) binding);
}
}
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.fPreprocessorProblemCount+= ast.getPreprocessorProblemsCount() - unresolvedIncludes;
if (fShowScannerProblems || fShowSyntaxProblems) {
final boolean reportAll= fShowScannerProblems && fShowSyntaxProblems;
if (fShowScannerProblems || fShowInclusionProblems) {
final boolean reportAll= fShowScannerProblems && fShowInclusionProblems;
IASTProblem[] scannerProblems= ast.getPreprocessorProblems();
for (IASTProblem problem : scannerProblems) {
if (reportAll || (problem.getID() == IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND) == fShowInclusionProblems) {

View file

@ -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$
IFile file= project.getFile(filename);
scanInfo= provider.getScannerInformation(file);
if (scanInfo == null || scanInfo.getDefinedSymbols().isEmpty()) {
scanInfo= provider.getScannerInformation(project);
}
}
else {
scanInfo= new ScannerInfo();
@ -203,10 +206,10 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
+ fStatistics.fResolutionTime + " resolution, " //$NON-NLS-1$
+ fStatistics.fAddToIndexTime + " index update."); //$NON-NLS-1$
System.out.println(name + " Errors: " //$NON-NLS-1$
+ fStatistics.fUnresolvedIncludesCount + " include, " //$NON-NLS-1$
+ fStatistics.fPreprocessorProblemCount + " scanner, " //$NON-NLS-1$
+ fStatistics.fSyntaxProblemsCount + " syntax, " //$NON-NLS-1$
+ fStatistics.fErrorCount + " internal errors."); //$NON-NLS-1$
+ fStatistics.fErrorCount + " internal, " //$NON-NLS-1$
+ fStatistics.fUnresolvedIncludesCount + " include, " //$NON-NLS-1$
+ fStatistics.fPreprocessorProblemCount + " scanner, " //$NON-NLS-1$
+ fStatistics.fSyntaxProblemsCount + " syntax errors."); //$NON-NLS-1$
int sum= fStatistics.fDeclarationCount+fStatistics.fReferenceCount+fStatistics.fProblemBindingCount;
double problemPct= sum==0 ? 0.0 : (double) fStatistics.fProblemBindingCount / (double) sum;