1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 11:55:40 +02:00

Code formatting.

This commit is contained in:
Sergey Prigogin 2008-11-23 03:54:00 +00:00
parent d33651d578
commit b45aa845c2

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom; package org.eclipse.cdt.internal.core.pdom;
import java.net.URI; import java.net.URI;
@ -151,7 +151,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return "______"; //$NON-NLS-1$ return "______"; //$NON-NLS-1$
} }
private final IASTTranslationUnit createAST(String code, AbstractLanguage lang, IScannerInfo scanInfo, private final IASTTranslationUnit createAST(String code, AbstractLanguage lang, IScannerInfo scanInfo,
int options, IProgressMonitor monitor) throws CoreException { int options, IProgressMonitor monitor) throws CoreException {
String dummyName= getASTPathForParsingUpFront(); String dummyName= getASTPathForParsingUpFront();
if (dummyName != null) { if (dummyName != null) {
@ -180,24 +180,23 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
IScannerInfo scanInfo, int options, IProgressMonitor pm) throws CoreException { IScannerInfo scanInfo, int options, IProgressMonitor pm) throws CoreException {
if (fCodeReaderFactory == null) { if (fCodeReaderFactory == null) {
if (fIsFastIndexer) { if (fIsFastIndexer) {
fCodeReaderFactory= new IndexBasedCodeReaderFactory(fIndex, createIncludeHeuristics(), fResolver, language.getLinkageID(), createReaderFactory(), this); fCodeReaderFactory= new IndexBasedCodeReaderFactory(fIndex, createIncludeHeuristics(),
} fResolver, language.getLinkageID(), createReaderFactory(), this);
else { } else {
fCodeReaderFactory= createReaderFactory(); fCodeReaderFactory= createReaderFactory();
} }
} } else if (fIsFastIndexer) {
else if (fIsFastIndexer) {
((IndexBasedCodeReaderFactory) fCodeReaderFactory).setLinkage(language.getLinkageID()); ((IndexBasedCodeReaderFactory) fCodeReaderFactory).setLinkage(language.getLinkageID());
} }
try { try {
IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory, fIndex, options, getLogService()); IASTTranslationUnit ast= language.getASTTranslationUnit(codeReader, scanInfo, fCodeReaderFactory,
fIndex, options, getLogService());
if (pm.isCanceled()) { if (pm.isCanceled()) {
return null; return null;
} }
return ast; return ast;
} } finally {
finally {
if (fIsFastIndexer) { if (fIsFastIndexer) {
((IndexBasedCodeReaderFactory) fCodeReaderFactory).cleanupAfterTranslationUnit(); ((IndexBasedCodeReaderFactory) fCodeReaderFactory).cleanupAfterTranslationUnit();
} }
@ -219,7 +218,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
fTodoTaskUpdater= createTodoTaskUpdater(); fTodoTaskUpdater= createTodoTaskUpdater();
fASTOptions= ILanguage.OPTION_ADD_COMMENTS | ILanguage.OPTION_NO_IMAGE_LOCATIONS fASTOptions= ILanguage.OPTION_ADD_COMMENTS | ILanguage.OPTION_NO_IMAGE_LOCATIONS
| ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS; | ILanguage.OPTION_SKIP_TRIVIAL_EXPRESSIONS_IN_AGGREGATE_INITIALIZERS;
if (getSkipReferences() == SKIP_ALL_REFERENCES) { if (getSkipReferences() == SKIP_ALL_REFERENCES) {
fASTOptions |= ILanguage.OPTION_SKIP_FUNCTION_BODIES; fASTOptions |= ILanguage.OPTION_SKIP_FUNCTION_BODIES;
@ -228,7 +227,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
fIndex.resetCacheCounters(); fIndex.resetCacheCounters();
fIndex.acquireReadLock(); fIndex.acquireReadLock();
try { try {
try { try {
// split into sources and headers, remove excluded sources. // split into sources and headers, remove excluded sources.
final HashMap<Integer, List<Object>> files= new HashMap<Integer, List<Object>>(); final HashMap<Integer, List<Object>> files= new HashMap<Integer, List<Object>>();
@ -242,20 +241,18 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
parseLinkage(ILinkage.CPP_LINKAGE_ID, files, monitor); parseLinkage(ILinkage.CPP_LINKAGE_ID, files, monitor);
parseLinkage(ILinkage.C_LINKAGE_ID, files, monitor); parseLinkage(ILinkage.C_LINKAGE_ID, files, monitor);
parseLinkage(ILinkage.FORTRAN_LINKAGE_ID, files, monitor); parseLinkage(ILinkage.FORTRAN_LINKAGE_ID, files, monitor);
} } finally {
finally {
fIndex.flush(); fIndex.flush();
} }
} } catch (CoreException e) {
catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} } finally {
finally {
fIndex.releaseReadLock(); fIndex.releaseReadLock();
} }
} }
private void extractFiles(Map<Integer, List<Object>> files, List<IIndexFragmentFile> iFilesToRemove, IProgressMonitor monitor) throws CoreException { private void extractFiles(Map<Integer, List<Object>> files, List<IIndexFragmentFile> iFilesToRemove,
IProgressMonitor monitor) throws CoreException {
final boolean forceAll= (fUpdateFlags & IIndexManager.UPDATE_ALL) != 0; final boolean forceAll= (fUpdateFlags & IIndexManager.UPDATE_ALL) != 0;
final boolean checkTimestamps= (fUpdateFlags & IIndexManager.UPDATE_CHECK_TIMESTAMPS) != 0; final boolean checkTimestamps= (fUpdateFlags & IIndexManager.UPDATE_CHECK_TIMESTAMPS) != 0;
final boolean checkConfig= (fUpdateFlags & IIndexManager.UPDATE_CHECK_CONFIGURATION) != 0; final boolean checkConfig= (fUpdateFlags & IIndexManager.UPDATE_CHECK_CONFIGURATION) != 0;
@ -268,7 +265,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
final boolean force= forceAll || --forceFirst >= 0; final boolean force= forceAll || --forceFirst >= 0;
final IIndexFileLocation ifl= fResolver.resolveFile(tu); final IIndexFileLocation ifl= fResolver.resolveFile(tu);
if (ifl == null) if (ifl == null)
continue; continue;
final boolean isSourceUnit= fResolver.isSourceUnit(tu); final boolean isSourceUnit= fResolver.isSourceUnit(tu);
@ -285,8 +282,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
store(tu, linkageID, isSourceUnit, files); store(tu, linkageID, isSourceUnit, files);
requestUpdate(linkageID, ifl, null); requestUpdate(linkageID, ifl, null);
count++; count++;
} } else {
else {
takeFile(ifile, indexFiles); takeFile(ifile, indexFiles);
boolean update= false; boolean update= false;
if (checkConfig) { if (checkConfig) {
@ -309,8 +305,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (ctx == null) { if (ctx == null) {
iFilesToRemove.add(ifile); iFilesToRemove.add(ifile);
count++; count++;
} } else {
else {
boolean update= false; boolean update= false;
if (checkConfig && ifile.getParsedInContext() != null) { if (checkConfig && ifile.getParsedInContext() != null) {
update= isHeaderConfigChange(tu, ifile); update= isHeaderConfigChange(tu, ifile);
@ -403,7 +398,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return key; return key;
} }
private void removeFilesInIndex(List<Object> filesToRemove, List<IIndexFragmentFile> ifilesToRemove, IProgressMonitor monitor) throws InterruptedException, CoreException { private void removeFilesInIndex(List<Object> filesToRemove, List<IIndexFragmentFile> ifilesToRemove,
IProgressMonitor monitor) throws InterruptedException, CoreException {
if (!filesToRemove.isEmpty() || !ifilesToRemove.isEmpty()) { if (!filesToRemove.isEmpty() || !ifilesToRemove.isEmpty()) {
fIndex.acquireWriteLock(1); fIndex.acquireWriteLock(1);
try { try {
@ -470,23 +466,23 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
} }
} }
} } catch (Exception e) {
catch (Exception e) { swallowError(path, e);
swallowError(path, e);
} }
} }
fFilesUpFront.clear(); fFilesUpFront.clear();
} }
private void parseLinkage(int linkageID, Map<Integer, List<Object>> fileListMap, IProgressMonitor monitor) throws CoreException, InterruptedException { private void parseLinkage(int linkageID, Map<Integer, List<Object>> fileListMap, IProgressMonitor monitor)
throws CoreException, InterruptedException {
// sources // sources
List<Object> files= fileListMap.get(getFileListKey(linkageID, true)); List<Object> files= fileListMap.get(getFileListKey(linkageID, true));
if (files != null) { if (files != null) {
for (Object tu : files) { for (Object tu : files) {
if (monitor.isCanceled()) if (monitor.isCanceled())
return; return;
final IIndexFileLocation ifl = fResolver.resolveFile(tu); final IIndexFileLocation ifl = fResolver.resolveFile(tu);
if (ifl == null) if (ifl == null)
continue; continue;
final FileContent info= getFileInfo(linkageID, ifl); final FileContent info= getFileInfo(linkageID, ifl);
if (info != null && info.fRequestUpdate && !info.fIsUpdated) { if (info != null && info.fRequestUpdate && !info.fIsUpdated) {
@ -506,7 +502,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
files= fileListMap.get(getFileListKey(linkageID, false)); files= fileListMap.get(getFileListKey(linkageID, false));
if (files != null) { if (files != null) {
for (Iterator<Object> iter = files.iterator(); iter.hasNext();) { for (Iterator<Object> iter = files.iterator(); iter.hasNext();) {
if (monitor.isCanceled()) if (monitor.isCanceled())
return; return;
final Object header= iter.next(); final Object header= iter.next();
final IIndexFileLocation ifl = fResolver.resolveFile(header); final IIndexFileLocation ifl = fResolver.resolveFile(header);
@ -524,8 +520,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
} }
} }
} } else {
else {
// file was already parsed. // file was already parsed.
iter.remove(); iter.remove();
} }
@ -534,7 +529,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
// headers without context // headers without context
contextMap= null; contextMap= null;
for (Iterator<Object> iter = files.iterator(); iter.hasNext();) { for (Iterator<Object> iter = files.iterator(); iter.hasNext();) {
if (monitor.isCanceled()) if (monitor.isCanceled())
return; return;
final Object header= iter.next(); final Object header= iter.next();
final IIndexFileLocation ifl = fResolver.resolveFile(header); final IIndexFileLocation ifl = fResolver.resolveFile(header);
@ -561,7 +556,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
try { try {
Object context= fResolver.getInputFile(ifile.getLocation()); Object context= fResolver.getInputFile(ifile.getLocation());
if (context != null && fResolver.isSourceUnit(context)) { if (context != null && fResolver.isSourceUnit(context)) {
contextMap.put(ifile, context); contextMap.put(ifile, context);
return context; return context;
} }
@ -581,7 +576,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return null; return null;
} }
private void parseFile(Object tu, int linkageID, IIndexFileLocation ifl, IScannerInfo scanInfo, IProgressMonitor pm) throws CoreException, InterruptedException { private void parseFile(Object tu, int linkageID, IIndexFileLocation ifl, IScannerInfo scanInfo,
IProgressMonitor pm) throws CoreException, InterruptedException {
IPath path= getPathForLabel(ifl); IPath path= getPathForLabel(ifl);
AbstractLanguage[] langs= fResolver.getLanguages(tu); AbstractLanguage[] langs= fResolver.getLanguages(tu);
AbstractLanguage lang= null; AbstractLanguage lang= null;
@ -611,15 +607,16 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} catch (CoreException e) { } catch (CoreException e) {
th= e; th= e;
} catch (RuntimeException e) { } catch (RuntimeException e) {
th= e; th= e;
} catch (PDOMNotImplementedError e) { } catch (PDOMNotImplementedError e) {
th= e; th= e;
} catch (StackOverflowError e) { } catch (StackOverflowError e) {
th= e; th= e;
} catch (Error e) { } catch (Error e) {
try { try {
swallowError(path, e); swallowError(path, e);
} catch (Throwable ignore) {} } catch (Throwable ignore) {
}
throw e; throw e;
} }
if (th != null) { if (th != null) {
@ -627,7 +624,8 @@ 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<IIndexFileLocation> enteredFiles= new HashSet<IIndexFileLocation>(); HashSet<IIndexFileLocation> enteredFiles= new HashSet<IIndexFileLocation>();
ArrayList<IIndexFileLocation> orderedIFLs= new ArrayList<IIndexFileLocation>(); ArrayList<IIndexFileLocation> orderedIFLs= new ArrayList<IIndexFileLocation>();
@ -647,8 +645,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
IIndexFileLocation[] ifls= orderedIFLs.toArray(new IIndexFileLocation[orderedIFLs.size()]); IIndexFileLocation[] ifls= orderedIFLs.toArray(new IIndexFileLocation[orderedIFLs.size()]);
try { try {
addSymbols(ast, ifls, fIndex, 1, false, configHash, fTodoTaskUpdater, pm); addSymbols(ast, ifls, fIndex, 1, false, configHash, fTodoTaskUpdater, pm);
} } finally {
finally {
// mark as updated in any case, to avoid parsing files that caused an exception to be thrown. // mark as updated in any case, to avoid parsing files that caused an exception to be thrown.
for (IIndexFileLocation ifl : ifls) { for (IIndexFileLocation ifl : ifls) {
info= getFileInfo(linkageID, ifl); info= getFileInfo(linkageID, ifl);
@ -658,7 +655,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
} }
} }
private void collectOrderedIFLs(final int linkageID, IASTInclusionNode inclusion, HashSet<IIndexFileLocation> enteredFiles, 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 IIndexFileLocation ifl= fResolver.resolveASTPath(id.getPath()); final IIndexFileLocation ifl= fResolver.resolveASTPath(id.getPath());
@ -679,8 +677,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
IIndexFile ifile= null; IIndexFile ifile= null;
if (fResolver.canBePartOfSDK(ifl)) { if (fResolver.canBePartOfSDK(ifl)) {
ifile= fIndex.getFile(linkageID, ifl); ifile= fIndex.getFile(linkageID, ifl);
} } else {
else {
IIndexFragmentFile fragFile= fIndex.getWritableFile(linkageID, ifl); IIndexFragmentFile fragFile= fIndex.getWritableFile(linkageID, ifl);
if (fragFile != null && fragFile.hasContent()) { if (fragFile != null && fragFile.hasContent()) {
ifile= fragFile; ifile= fragFile;
@ -691,7 +688,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
info.fRequestIsCounted= false; info.fRequestIsCounted= false;
info.fRequestUpdate= true; info.fRequestUpdate= true;
} }
} }
final boolean needUpdate= !info.fIsUpdated && info.fRequestUpdate; final boolean needUpdate= !info.fIsUpdated && info.fRequestUpdate;
if (needUpdate && info.fRequestIsCounted) { if (needUpdate && info.fRequestIsCounted) {
updateFileCount(0, 1, 0); // total headers will be counted when written to db updateFileCount(0, 1, 0); // total headers will be counted when written to db
@ -720,8 +717,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (s.getException() == null) { if (s.getException() == null) {
s= new Status(s.getSeverity(), s.getPlugin(), s.getCode(), s.getMessage(), e); s= new Status(s.getSeverity(), s.getPlugin(), s.getCode(), s.getMessage(), e);
} }
} } else {
else {
s= CCorePlugin.createStatus(getMessage(MessageKind.errorWhileParsing, file), e); s= CCorePlugin.createStatus(getMessage(MessageKind.errorWhileParsing, file), e);
} }
logError(s); logError(s);