1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

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.
This commit is contained in:
Alain Magloire 2004-05-21 05:43:43 +00:00
parent 4ee5d85a60
commit ecdcf0a446
6 changed files with 65 additions and 125 deletions

View file

@ -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.

View file

@ -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 )

View file

@ -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

View file

@ -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()
*/

View file

@ -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) {
//
}
}
}

View file

@ -47,12 +47,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
*/
@ -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();
//}
}
}
/**