1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Fix for Bug 172312 - No difference between SKIP_ALL and SKIP_INDEXED mode

This commit is contained in:
Anton Leherbauer 2007-02-05 15:44:28 +00:00
parent 7829540568
commit d686621b48
9 changed files with 119 additions and 60 deletions

View file

@ -93,14 +93,12 @@ public abstract class IntegratedCModelTest extends TestCase {
protected ITranslationUnit getTU() throws CModelException {
ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(sourceFile);
CCorePlugin.getDefault().setUseNewModelBuilder(useNewModelBuilder());
CCorePlugin.getDefault().setStructuralParseMode(isStructuralParse());
// parse the translation unit to get the elements tree
// Force the parsing now to do this in the right ParseMode.
tu.close();
tu.open(new NullProgressMonitor());
CCorePlugin.getDefault().setStructuralParseMode(false);
CCorePlugin.getDefault().setUseNewModelBuilder(true);
return tu;
}
/**

View file

@ -34,18 +34,30 @@ import org.eclipse.core.runtime.IProgressMonitor;
public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISourceReference, ISourceManipulation {
/**
* Style for {@link #getAST(IIndex, int)}. Don't parse header files.
* Style constant for {@link #getAST(IIndex, int)}.
* Meaning: Skip over headers that are found in the index, parse all others.
* Macro definitions and bindings are taken from index for skipped files.
*/
public static final int AST_SKIP_ALL_HEADERS = 2;
public static final int AST_SKIP_INDEXED_HEADERS = 2;
/**
* Style for {@link #getAST(IIndex, int)}. Skips over headers that are found in the index.
* Style constant for {@link #getAST(IIndex, int)}.
* Meaning: Skip headers even if they are not found in the index.
* Makes practically only sense in combination with {@link AST_SKIP_INDEXED_HEADERS}.
*/
public static final int AST_SKIP_INDEXED_HEADERS = 4;
public static final int AST_SKIP_NONINDEXED_HEADERS = 4;
/**
* Style for {@link #getAST(IIndex, int)}. Don't parse the file if there is no build
* information for it.
* Style constant for {@link #getAST(IIndex, int)}.
* A combination of {@link AST_SKIP_INDEXED_HEADERS} and {@link AST_SKIP_NONINDEXED_HEADERS}.
* Meaning: Don't parse header files at all, be they indexed or not.
* Macro definitions and bindings are taken from the index if available.
*/
public static final int AST_SKIP_ALL_HEADERS = AST_SKIP_INDEXED_HEADERS | AST_SKIP_NONINDEXED_HEADERS;
/**
* Style constant for {@link #getAST(IIndex, int)}.
* Meaning: Don't parse the file if there is no build information for it.
*/
public static final int AST_SKIP_IF_NO_BUILD_INFO = 8;

View file

@ -12,12 +12,10 @@ package org.eclipse.cdt.internal.core.model;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
@ -82,7 +80,6 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.IASTDeclarationAmbiguity;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
@ -227,13 +224,8 @@ public class CModelBuilder2 implements IContributedModelBuilder {
* @see org.eclipse.cdt.core.model.IContributedModelBuilder#parse(boolean)
*/
public void parse(boolean quickParseMode) throws Exception {
if (isIndexerDisabled()) {
// fallback to old model builder
new CModelBuilder(fTranslationUnit, new HashMap()).parse(true);
return;
}
final IIndexManager indexManager= CCorePlugin.getIndexManager();
IIndex index= indexManager.getIndex(fTranslationUnit.getCProject());
IIndex index= indexManager.getIndex(fTranslationUnit.getCProject(), IIndexManager.ADD_DEPENDENCIES);
try {
if (index != null) {
@ -245,10 +237,10 @@ public class CModelBuilder2 implements IContributedModelBuilder {
}
checkCanceled();
long startTime= System.currentTimeMillis();
final IASTTranslationUnit ast= fTranslationUnit.getAST(index, ITranslationUnit.AST_SKIP_ALL_HEADERS);
final IASTTranslationUnit ast= fTranslationUnit.getAST(index, quickParseMode ? ITranslationUnit.AST_SKIP_ALL_HEADERS : ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
Util.debugLog("CModelBuilder2: parsing " //$NON-NLS-1$
+ fTranslationUnit.getElementName()
+ " mode="+ (quickParseMode ? "fast " : "full ") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " mode="+ (quickParseMode ? "skip all " : "skip indexed ") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ " time="+ ( System.currentTimeMillis() - startTime ) + "ms", //$NON-NLS-1$ //$NON-NLS-2$
IDebugLogConstants.MODEL, false);
@ -286,16 +278,6 @@ public class CModelBuilder2 implements IContributedModelBuilder {
}
}
private boolean isIndexerDisabled() {
final IPDOMManager pdomManager= CCorePlugin.getPDOMManager();
try {
return IPDOMManager.ID_NO_INDEXER.equals(pdomManager.getIndexerId(fTranslationUnit.getCProject()));
} catch (CoreException exc) {
CCorePlugin.log(exc.getStatus());
}
return true;
}
/**
* Build the model from the given AST.
* @param ast

View file

@ -49,6 +49,7 @@ import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.dom.NullCodeReaderFactory;
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory;
import org.eclipse.core.resources.IFile;
@ -610,12 +611,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
*/
private void parseUsingCModelBuilder(Map newElements, boolean quickParseMode, IProgressMonitor monitor) {
try {
boolean useNewModelBuilder= CCorePlugin.getDefault().useNewModelBuilder();
if (useNewModelBuilder) {
new CModelBuilder2(this, monitor).parse(quickParseMode);
} else {
new CModelBuilder(this, newElements).parse(quickParseMode);
}
new CModelBuilder2(this, monitor).parse(quickParseMode);
} catch (OperationCanceledException oce) {
if (isWorkingCopy()) {
throw oce;
@ -741,11 +737,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
public IASTTranslationUnit getAST(IIndex index, int style) throws CoreException {
ICodeReaderFactory codeReaderFactory;
if (index != null && (style & (ITranslationUnit.AST_SKIP_INDEXED_HEADERS | ITranslationUnit.AST_SKIP_ALL_HEADERS)) != 0) {
codeReaderFactory= new IndexBasedCodeReaderFactory(index);
if ((style & ITranslationUnit.AST_SKIP_NONINDEXED_HEADERS) != 0) {
codeReaderFactory= NullCodeReaderFactory.getInstance();
} else {
codeReaderFactory= SavedCodeReaderFactory.getInstance();
}
else {
codeReaderFactory = SavedCodeReaderFactory.getInstance();
if (index != null && (style & ITranslationUnit.AST_SKIP_INDEXED_HEADERS) != 0) {
codeReaderFactory= new IndexBasedCodeReaderFactory(index, codeReaderFactory);
}
IScannerInfo scanInfo = getScannerInfo( (style & ITranslationUnit.AST_SKIP_IF_NO_BUILD_INFO) == 0);
@ -766,7 +764,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
public ASTCompletionNode getCompletionNode(IIndex index, int style, int offset) throws CoreException {
ICodeReaderFactory codeReaderFactory;
if (index != null && (style & (ITranslationUnit.AST_SKIP_INDEXED_HEADERS | ITranslationUnit.AST_SKIP_ALL_HEADERS)) != 0) {
codeReaderFactory= new IndexBasedCodeReaderFactory(index);
ICodeReaderFactory fallbackFactory;
if ((style & ITranslationUnit.AST_SKIP_ALL_HEADERS) != 0) {
fallbackFactory= NullCodeReaderFactory.getInstance();
} else {
fallbackFactory= SavedCodeReaderFactory.getInstance();
}
codeReaderFactory= new IndexBasedCodeReaderFactory(index, fallbackFactory);
}
else {
codeReaderFactory = SavedCodeReaderFactory.getInstance();

View file

@ -49,6 +49,8 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
private Map/*<IIndexFileLocation,FileInfo>*/ fileInfoCache;
private Map/*<String,IIndexFileLocation>*/ iflCache;
private List usedMacros = new ArrayList();
/** The fallback code reader factory used in case a header file is not indexed */
private ICodeReaderFactory fFallBackFactory;
private static final char[] EMPTY_CHARS = new char[0];
@ -73,13 +75,22 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
public IndexBasedCodeReaderFactory(IIndex index) {
this(index, new HashMap/*<String,IIndexFileLocation>*/());
}
public IndexBasedCodeReaderFactory(IIndex index, ICodeReaderFactory fallbackFactory) {
this(index, new HashMap/*<String,IIndexFileLocation>*/(), fallbackFactory);
}
public IndexBasedCodeReaderFactory(IIndex index, Map iflCache) {
this(index, iflCache, null);
}
public IndexBasedCodeReaderFactory(IIndex index, Map iflCache, ICodeReaderFactory fallbackFactory) {
this.index = index;
this.fileInfoCache = new HashMap/*<IIndexFileLocation,FileInfo>*/();
this.iflCache = iflCache;
this.fFallBackFactory= fallbackFactory;
}
public int getUniqueIdentifier() {
return 0;
}
@ -140,6 +151,9 @@ public class IndexBasedCodeReaderFactory implements ICodeReaderFactory {
// still try to parse the file.
}
if (fFallBackFactory != null) {
return fFallBackFactory.createCodeReaderForInclusion(scanner, canonicalPath);
}
return ParserUtil.createReader(canonicalPath, null);
}

View file

@ -989,16 +989,6 @@ public class CCorePlugin extends Plugin {
return getPluginPreferences().getBoolean(PREF_USE_STRUCTURAL_PARSE_MODE);
}
// Preference to turn on/off the use of the new model builder to build the CModel
public void setUseNewModelBuilder(boolean useNewModelBuilder) {
getPluginPreferences().setValue(PREF_USE_NEW_MODEL_BUILDER, useNewModelBuilder);
savePluginPreferences();
}
public boolean useNewModelBuilder() {
return getPluginPreferences().getBoolean(PREF_USE_NEW_MODEL_BUILDER);
}
public CDOM getDOM() {
return CDOM.getInstance();
}

View file

@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.ICodeReaderCache;
import org.eclipse.cdt.core.parser.IScanner;
/**
* A <code>ICodeReaderFactory</code> which creates dummy <code>CodeReader</code>s without content.
*
* @since 4.0
*/
public class NullCodeReaderFactory implements ICodeReaderFactory {
private static final char[] EMPTY_CHARS = new char[0];
private static final ICodeReaderFactory INSTANCE= new NullCodeReaderFactory();
public static ICodeReaderFactory getInstance() {
return INSTANCE;
}
private NullCodeReaderFactory() {
// singleton
}
/*
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(org.eclipse.cdt.core.parser.IScanner, java.lang.String)
*/
public CodeReader createCodeReaderForInclusion(IScanner scanner, String path) {
return new CodeReader(path, EMPTY_CHARS);
}
/*
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForTranslationUnit(java.lang.String)
*/
public CodeReader createCodeReaderForTranslationUnit(String path) {
return new CodeReader(path, EMPTY_CHARS);
}
/*
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#getCodeReaderCache()
*/
public ICodeReaderCache getCodeReaderCache() {
return null;
}
/*
* @see org.eclipse.cdt.core.dom.ICodeReaderFactory#getUniqueIdentifier()
*/
public int getUniqueIdentifier() {
// is this used somewhere?
return 7;
}
}

View file

@ -683,12 +683,12 @@
class="org.eclipse.cdt.internal.ui.preferences.IndexerPreferencePage"
id="org.eclipse.cdt.ui.preferences.IndexerPreferencePage"
name="%indexerPrefName"/>
<page
<!--page
name="%WorkInProgress.name"
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
class="org.eclipse.cdt.internal.ui.preferences.WorkInProgressPreferencePage"
id="org.eclipse.cdt.ui.preferneces.WorkInProgressPreferencePage">
</page>
</page-->
</extension>
<extension
point="org.eclipse.ui.editorActions">

View file

@ -29,7 +29,6 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.ui.CUIPlugin;
/**
@ -85,7 +84,6 @@ public class WorkInProgressPreferencePage extends PreferencePage implements IWor
result.setLayout(layout);
// Add your controls here
addCheckBox(result, "Use new model builder", CCorePlugin.PREF_USE_NEW_MODEL_BUILDER); //$NON-NLS-1$
applyDialogFont(result);
return result;
@ -158,15 +156,11 @@ public class WorkInProgressPreferencePage extends PreferencePage implements IWor
String key= (String) text.getData();
store.setValue(key, text.getText());
}
CCorePlugin.getDefault().setUseNewModelBuilder(store.getBoolean(CCorePlugin.PREF_USE_NEW_MODEL_BUILDER));
CUIPlugin.getDefault().savePluginPreferences();
return super.performOk();
}
public static void initDefaults(IPreferenceStore store) {
// Initialize your defaults here
boolean coreDefault= CCorePlugin.getDefault().getPluginPreferences().getDefaultBoolean(CCorePlugin.PREF_USE_NEW_MODEL_BUILDER);
store.setDefault(CCorePlugin.PREF_USE_NEW_MODEL_BUILDER, coreDefault);
CCorePlugin.getDefault().setUseNewModelBuilder(store.getBoolean(CCorePlugin.PREF_USE_NEW_MODEL_BUILDER));
}
}