diff options
author | Alain Magloire | 2004-05-21 05:43:43 +0000 |
---|---|---|
committer | Alain Magloire | 2004-05-21 05:43:43 +0000 |
commit | ecdcf0a446a02a6d00637fe46b95f38657d1b616 (patch) | |
tree | f9f1f0a7a60c78e68519915bcb714c6a33306c05 /core | |
parent | 4ee5d85a60ed5bdb17a43017de1a1a8b13dd4b3b (diff) | |
download | org.eclipse.cdt-ecdcf0a446a02a6d00637fe46b95f38657d1b616.tar.gz org.eclipse.cdt-ecdcf0a446a02a6d00637fe46b95f38657d1b616.tar.xz org.eclipse.cdt-ecdcf0a446a02a6d00637fe46b95f38657d1b616.zip |
2004-05-21 Alain Magloire
Remove TranslationUnitProblemFinder, we can not use the same
approach as the JDT i.e. to reparse. Parsing is way to costly
for C/C++ because of the Preprocessor, instead we set the problem
requestor in the translationUnit.
Diffstat (limited to 'core')
6 files changed, 65 insertions, 125 deletions
diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index e6cd065a907..6697e9c0972 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,9 @@ +2004-05-21 Alain Magloire + Remove TranslationUnitProblemFinder, we can not use the same + approach as the JDT i.e. to reparse. Parsing is way to costly + for C/C++ because of the Preprocessor, instead we set the problem + requestor in the translationUnit. + 2004-05-20 Bogdan Gheorghe Modified updateCurrentDeltaAndIndex inDeltaProcessor.java to return whether we need to traverse a delta's children. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java index 8777456ebb0..ce33a95207f 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder.java @@ -21,9 +21,10 @@ import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IParent; +import org.eclipse.cdt.core.model.IProblemRequestor; import org.eclipse.cdt.core.model.ITemplate; -import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.IParser; +import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IQuickParseCallback; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfoProvider; @@ -60,6 +61,8 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner; import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.internal.core.parser.ParserException; +import org.eclipse.cdt.internal.core.parser.QuickParseCallback; +import org.eclipse.cdt.internal.core.parser.StructuralParseCallback; import org.eclipse.cdt.internal.core.parser.util.ASTUtil; import org.eclipse.core.resources.IProject; @@ -78,7 +81,7 @@ public class CModelBuilder { this.newElements = new HashMap(); } - private IASTCompilationUnit parse( ITranslationUnit translationUnit, boolean quickParseMode, boolean throwExceptionOnError ) throws ParserException + private IASTCompilationUnit parse(boolean quickParseMode, boolean throwExceptionOnError) throws ParserException { IProject currentProject = null; boolean hasCppNature = true; @@ -99,12 +102,36 @@ public class CModelBuilder { } catch (CModelException e) { } + + final IProblemRequestor problemRequestor = translationUnit.getProblemRequestor(); // use quick or structural parse mode ParserMode mode = quickParseMode ? ParserMode.QUICK_PARSE : ParserMode.STRUCTURAL_PARSE; - if(quickParseMode) - quickParseCallback = ParserFactory.createQuickParseCallback(); - else - quickParseCallback = ParserFactory.createStructuralParseCallback(); + if (problemRequestor == null) { + quickParseCallback = (quickParseMode) ? ParserFactory.createQuickParseCallback() : + ParserFactory.createStructuralParseCallback(); + } else { + if (quickParseMode) { + quickParseCallback = new QuickParseCallback() { + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.QuickParseCallback#acceptProblem(org.eclipse.cdt.core.parser.IProblem) + */ + public boolean acceptProblem(IProblem problem) { + problemRequestor.acceptProblem(problem); + return true; + } + }; + } else { + quickParseCallback = new StructuralParseCallback() { + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.QuickParseCallback#acceptProblem(org.eclipse.cdt.core.parser.IProblem) + */ + public boolean acceptProblem(IProblem problem) { + problemRequestor.acceptProblem(problem); + return true; + } + }; + } + } // pick the language ParserLanguage language = hasCppNature ? ParserLanguage.CPP : ParserLanguage.C; @@ -144,7 +171,13 @@ public class CModelBuilder { throw new ParserException( CCorePlugin.getResourceString("CModelBuilder.Parser_Construction_Failure")); //$NON-NLS-1$ } // call parse + if (problemRequestor != null) { + problemRequestor.beginReporting(); + } hasNoErrors = parser.parse(); + if (problemRequestor != null) { + problemRequestor.endReporting(); + } if( (!hasNoErrors) && throwExceptionOnError ) throw new ParserException(CCorePlugin.getResourceString("CModelBuilder.Parse_Failure")); //$NON-NLS-1$ return quickParseCallback.getCompilationUnit(); @@ -155,7 +188,7 @@ public class CModelBuilder { long startTime = System.currentTimeMillis(); try { - compilationUnit = parse( translationUnit, quickParseMode, true); + compilationUnit = parse(quickParseMode, true); } catch( ParserException e ) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ReconcileWorkingCopyOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ReconcileWorkingCopyOperation.java index 83c2adf700f..b6b608bdfe5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ReconcileWorkingCopyOperation.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ReconcileWorkingCopyOperation.java @@ -14,7 +14,6 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICModelStatus; import org.eclipse.cdt.core.model.ICModelStatusConstants; -import org.eclipse.cdt.core.model.IProblemRequestor; /** * Reconcile a working copy and signal the changes through a delta. @@ -56,14 +55,7 @@ public class ReconcileWorkingCopyOperation extends CModelOperation { // force problem detection? - if structure was consistent if (forceProblemDetection && wasConsistent){ - if (fMonitor != null && fMonitor.isCanceled()) return; - - IProblemRequestor problemRequestor = workingCopy.problemRequestor; - if (problemRequestor != null && problemRequestor.isActive()){ - problemRequestor.beginReporting(); - TranslationUnitProblemFinder.process(workingCopy, problemRequestor, fMonitor); - problemRequestor.endReporting(); - } + if (fMonitor != null && fMonitor.isCanceled()) return; } // register the deltas diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java index 39e00500a1a..57acce9bcbb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java @@ -39,6 +39,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit { IPath location = null; + /** + * If set, this is the problem requestor which will be used to notify problems + * detected during reconciling. + */ + protected IProblemRequestor problemRequestor; + + SourceManipulationInfo sourceManipulationInfo = null; public TranslationUnit(ICElement parent, IFile file) { @@ -517,6 +524,10 @@ public class TranslationUnit extends Openable implements ITranslationUnit { } } + public IProblemRequestor getProblemRequestor() { + return problemRequestor; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.model.ITranslationUnit#isHeaderUnit() */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnitProblemFinder.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnitProblemFinder.java deleted file mode 100644 index 2d440a31e49..00000000000 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnitProblemFinder.java +++ /dev/null @@ -1,96 +0,0 @@ -/********************************************************************** - * Copyright (c) 2002,2003,2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - ***********************************************************************/ - -package org.eclipse.cdt.internal.core.model; - -import java.io.StringReader; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IProblemRequestor; -import org.eclipse.cdt.core.parser.IParser; -import org.eclipse.cdt.core.parser.IProblem; -import org.eclipse.cdt.core.parser.IScanner; -import org.eclipse.cdt.core.parser.IScannerInfo; -import org.eclipse.cdt.core.parser.IScannerInfoProvider; -import org.eclipse.cdt.core.parser.NullSourceElementRequestor; -import org.eclipse.cdt.core.parser.ParserFactory; -import org.eclipse.cdt.core.parser.ParserFactoryError; -import org.eclipse.cdt.core.parser.ParserLanguage; -import org.eclipse.cdt.core.parser.ParserMode; -import org.eclipse.cdt.core.parser.ScannerInfo; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * TranslationUnitProblemFinder - */ -public class TranslationUnitProblemFinder extends NullSourceElementRequestor { - - IProblemRequestor requestor; - /** - * - */ - public TranslationUnitProblemFinder(IProblemRequestor requestor) { - super(); - this.requestor = requestor; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.parser.ISourceElementRequestor#acceptProblem(org.eclipse.cdt.core.parser.IProblem) - */ - public boolean acceptProblem(IProblem problem) { - requestor.acceptProblem(problem); - return true; - } - - /** - * @param copy - * @param requestor - * @param monitor - */ - public static void process(WorkingCopy copy, IProblemRequestor requestor, IProgressMonitor monitor) { - - TranslationUnitProblemFinder problemFinder = new TranslationUnitProblemFinder(requestor); - IProject project = copy.getCProject().getProject(); - String code = new String(); - try{ - code = copy.getBuffer().getContents(); - } catch (CModelException e) { - // - } - - // pick the language - ParserLanguage language = copy.isCXXLanguage()? ParserLanguage.CPP : ParserLanguage.C; - - IParser parser = null; - try { - IScannerInfo scanInfo = new ScannerInfo(); - IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(project); - if (provider != null){ - IScannerInfo buildScanInfo = provider.getScannerInformation(project); - if (buildScanInfo != null){ - scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths()); - } - } - - boolean quickParseMode = ! (CCorePlugin.getDefault().useStructuralParseMode()); - ParserMode mode = quickParseMode ? ParserMode.QUICK_PARSE : ParserMode.STRUCTURAL_PARSE; - IScanner scanner = ParserFactory.createScanner(new StringReader(code), copy.getPath().toOSString(), - scanInfo, mode, language, problemFinder, null, null); - parser = ParserFactory.createParser(scanner, problemFinder, mode, language, null); - parser.parse(); - } catch(ParserFactoryError pfe) { - // - } - - } -} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java index 6067bed8df8..556ae4eea61 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java @@ -48,12 +48,6 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy { protected int useCount = 1; /** - * If set, this is the problem requestor which will be used to notify problems - * detected during reconciling. - */ - protected IProblemRequestor problemRequestor; - - /** * Creates a working copy of this element */ public WorkingCopy(ICElement parent, IFile file, IBufferFactory bufferFactory) { @@ -65,7 +59,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy { bufferFactory == null ? getBufferManager() : bufferFactory; - this.problemRequestor = requestor; + problemRequestor = requestor; } public WorkingCopy(ICElement parent, IPath path, IBufferFactory bufferFactory) { @@ -222,12 +216,12 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy { throw newNotPresentException(); } else { super.open(monitor); - if (monitor != null && monitor.isCanceled()) return; - if (this.problemRequestor != null && this.problemRequestor.isActive()){ - this.problemRequestor.beginReporting(); - TranslationUnitProblemFinder.process(this, this.problemRequestor, monitor); - this.problemRequestor.endReporting(); - } + //if (monitor != null && monitor.isCanceled()) return; + //if (this.problemRequestor != null && this.problemRequestor.isActive()){ + // this.problemRequestor.beginReporting(); + // TranslationUnitProblemFinder.process(this, this.problemRequestor, monitor); + // this.problemRequestor.endReporting(); + //} } } /** |