diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java index 4f98e6c9977..c645b0e5806 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/AbstractLanguage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 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 @@ -9,11 +9,9 @@ * Markus Schorn - initial API and implementation * Anton Leherbauer (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.core.model; import org.eclipse.cdt.core.dom.ICodeReaderFactory; -import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.parser.CodeReader; @@ -27,40 +25,6 @@ import org.eclipse.core.runtime.PlatformObject; * @since 4.0 */ public abstract class AbstractLanguage extends PlatformObject implements ILanguage { - /** - * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} - * Instructs the parser to skip function and method bodies. - */ - public final static int OPTION_SKIP_FUNCTION_BODIES= 1; - - /** - * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} - * Instructs the parser to add comment nodes to the ast. - */ - public final static int OPTION_ADD_COMMENTS= 2; - - /** - * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} - * Performance optimization, instructs the parser not to create image-locations. - * When using this option {@link IASTName#getImageLocation()} will always return null. - */ - public final static int OPTION_NO_IMAGE_LOCATIONS= 4; - - /** - * @deprecated, throws an UnsupportedOperationException - */ - final public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, int style) throws CoreException { - throw new UnsupportedOperationException(); - } - - /** - * @deprecated, throws an UnsupportedOperationException - */ - final public IASTTranslationUnit getASTTranslationUnit(ITranslationUnit file, ICodeReaderFactory codeReaderFactory, - int style) throws CoreException { - throw new UnsupportedOperationException(); - } - /* * @see org.eclipse.cdt.core.model.ILanguage#getName() */ @@ -72,21 +36,6 @@ public abstract class AbstractLanguage extends PlatformObject implements ILangua return getId(); } - /** - * Construct an AST for the source code provided by reader. - * As an option you can supply - * @param reader source code to be parsed. - * @param scanInfo provides include paths and defined symbols. - * @param fileCreator factory that provides CodeReaders for files included - * by the source code being parsed. - * @param index (optional) index to use to provide support for ambiguity - * resolution. - * @param options A combination of - * {@link #OPTION_SKIP_FUNCTION_BODIES} and {@link #OPTION_ADD_COMMENTS} or 0. - * @param log logger - * @return an AST for the source code provided by reader. - * @throws CoreException - */ public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log) throws CoreException { // for backwards compatibility diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java index 811d8f00bac..3d7c49cdbd4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ILanguage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 QNX Software Systems and others. + * Copyright (c) 2005, 2008 QNX Software Systems 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 @@ -10,7 +10,6 @@ * Markus Schorn (Wind River Systems) * IBM Corporation *******************************************************************************/ - package org.eclipse.cdt.core.model; import org.eclipse.cdt.core.dom.ICodeReaderFactory; @@ -32,8 +31,31 @@ import org.eclipse.core.runtime.IAdaptable; */ public interface ILanguage extends IAdaptable { - //public static final QualifiedName KEY = new QualifiedName(CCorePlugin.PLUGIN_ID, "language"); //$NON-NLS-1$ - public static final String KEY = "language"; //$NON-NLS-1$ + /** + * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} + * Instructs the parser to skip function and method bodies. + */ + public final static int OPTION_SKIP_FUNCTION_BODIES= 1; + + /** + * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} + * Instructs the parser to add comment nodes to the ast. + */ + public final static int OPTION_ADD_COMMENTS= 2; + + /** + * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} + * Performance optimization, instructs the parser not to create image-locations. + * When using this option {@link IASTName#getImageLocation()} will always return null. + */ + public final static int OPTION_NO_IMAGE_LOCATIONS= 4; + + /** + * Option for {@link #getASTTranslationUnit(CodeReader, IScannerInfo, ICodeReaderFactory, IIndex, int, IParserLogService)} + * Marks the ast as being based on a source-file rather than a header-file. This makes a difference + * when bindings from the AST are used for searching the index, e.g. for static variables. + */ + public final static int OPTION_IS_SOURCE_UNIT= 8; /** * Return the language id for this language. @@ -55,21 +77,6 @@ public interface ILanguage extends IAdaptable { */ public String getName(); - /** - * @deprecated use {@link ITranslationUnit#getAST()}. - */ - public IASTTranslationUnit getASTTranslationUnit( - ITranslationUnit file, - int style) throws CoreException; - - /** - * @deprecated use {@link ITranslationUnit#getAST(...)}. - */ - public IASTTranslationUnit getASTTranslationUnit( - ITranslationUnit file, - ICodeReaderFactory codeReaderFactory, - int style) throws CoreException; - /** * Return the AST completion node for the given offset. * @@ -109,6 +116,8 @@ public interface ILanguage extends IAdaptable { /** * Construct an AST for the source code provided by reader. + * Fully equivalent to + * getASTTranslationUnit(reader, scanInfo, fileCreator, index, 0, log) * @param reader source code to be parsed. * @param scanInfo provides include paths and defined symbols. * @param fileCreator factory that provides CodeReaders for files included @@ -119,5 +128,29 @@ public interface ILanguage extends IAdaptable { * @return an AST for the source code provided by reader. * @throws CoreException */ - public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) throws CoreException; + public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, + ICodeReaderFactory fileCreator, IIndex index, IParserLogService log) + throws CoreException; + + /** + * Construct an AST for the source code provided by reader. + * As an option you can supply + * @param reader source code to be parsed. + * @param scanInfo provides include paths and defined symbols. + * @param fileCreator factory that provides CodeReaders for files included + * by the source code being parsed. + * @param index (optional) index to use to provide support for ambiguity + * resolution. + * @param options A combination of + * {@link #OPTION_SKIP_FUNCTION_BODIES}, {@link #OPTION_ADD_COMMENTS}, + * {@link #OPTION_NO_IMAGE_LOCATIONS}, {@link #OPTION_IS_SOURCE_UNIT}, + * or 0. + * @param log logger + * @return an AST for the source code provided by reader. + * @throws CoreException + */ + public IASTTranslationUnit getASTTranslationUnit(CodeReader reader, IScannerInfo scanInfo, + ICodeReaderFactory fileCreator, IIndex index, int options, IParserLogService log) + throws CoreException; + } 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 c496de54972..c83ded1e388 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 @@ -11,7 +11,6 @@ * IBM Corporation * Anton Leherbauer (Wind River Systems) *******************************************************************************/ - package org.eclipse.cdt.internal.core.model; import java.io.FileInputStream; @@ -221,13 +220,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit { public IInclude[] getIncludes() throws CModelException { ICElement[] celements = getChildren(); - ArrayList aList = new ArrayList(); + ArrayList aList = new ArrayList(); for (int i = 0; i < celements.length; i++) { if (celements[i].getElementType() == ICElement.C_INCLUDE) { aList.add(celements[i]); } } - return (IInclude[]) aList.toArray(new IInclude[0]); + return aList.toArray(new IInclude[0]); } public IUsing getUsing(String name) { @@ -247,13 +246,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit { public IUsing[] getUsings() throws CModelException { ICElement[] celements = getChildren(); - ArrayList aList = new ArrayList(); + ArrayList aList = new ArrayList(); for (int i = 0; i < celements.length; i++) { if (celements[i].getElementType() == ICElement.C_USING) { aList.add(celements[i]); } } - return (IUsing[]) aList.toArray(new IUsing[0]); + return aList.toArray(new IUsing[0]); } public INamespace getNamespace(String name) { @@ -286,13 +285,13 @@ public class TranslationUnit extends Openable implements ITranslationUnit { public INamespace[] getNamespaces() throws CModelException { ICElement[] celements = getChildren(); - ArrayList aList = new ArrayList(); + ArrayList aList = new ArrayList(); for (int i = 0; i < celements.length; i++) { if (celements[i].getElementType() == ICElement.C_NAMESPACE) { aList.add(celements[i]); } } - return (INamespace[]) aList.toArray(new INamespace[0]); + return aList.toArray(new INamespace[0]); } protected void setLocationURI(URI loc) { @@ -786,24 +785,17 @@ public class TranslationUnit extends Openable implements ITranslationUnit { fLanguageOfContext= language; if (language != null) { ICodeReaderFactory crf= getCodeReaderFactory(style, index, language.getLinkageID()); - IASTTranslationUnit ast= null; - if (language instanceof AbstractLanguage) { - int options= 0; - if ((style & AST_SKIP_FUNCTION_BODIES) != 0) { - options |= AbstractLanguage.OPTION_SKIP_FUNCTION_BODIES; - } - if ((style & AST_CREATE_COMMENT_NODES) != 0) { - options |= AbstractLanguage.OPTION_ADD_COMMENTS; - } - ast= ((AbstractLanguage)language).getASTTranslationUnit(reader, scanInfo, crf, index, options, ParserUtil.getParserLogService()); + int options= 0; + if ((style & AST_SKIP_FUNCTION_BODIES) != 0) { + options |= ILanguage.OPTION_SKIP_FUNCTION_BODIES; } - else { - ast= language.getASTTranslationUnit(reader, scanInfo, crf, index, ParserUtil.getParserLogService()); + if ((style & AST_CREATE_COMMENT_NODES) != 0) { + options |= ILanguage.OPTION_ADD_COMMENTS; } - if (ast != null) { - ast.setIsHeaderUnit(isHeaderUnit()); + if (isSourceUnit()) { + options |= ILanguage.OPTION_IS_SOURCE_UNIT; } - return ast; + return ((AbstractLanguage)language).getASTTranslationUnit(reader, scanInfo, crf, index, options, ParserUtil.getParserLogService()); } } return null; @@ -836,7 +828,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit { IIndexFile indexFile= index.getFile(CTX_LINKAGES[i], ifl); if (indexFile != null) { // bug 199412, when a source-file includes itself the context may recurse. - HashSet visited= new HashSet(); + HashSet visited= new HashSet(); visited.add(indexFile); indexFile = getParsedInContext(indexFile); while (indexFile != null && visited.add(indexFile)) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java index 1f1bc78b238..3bc79dd7596 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractCLikeLanguage.java @@ -115,12 +115,13 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements IScanner scanner= createScanner(reader, scanInfo, codeReaderFactory, log); scanner.setScanComments((options & OPTION_ADD_COMMENTS) != 0); - scanner.setComputeImageLocations((options & AbstractLanguage.OPTION_NO_IMAGE_LOCATIONS) == 0); + scanner.setComputeImageLocations((options & OPTION_NO_IMAGE_LOCATIONS) == 0); ISourceCodeParser parser= createParser(scanner, log, index, false, options); // Parse IASTTranslationUnit ast= parser.parse(); + ast.setIsHeaderUnit((options & OPTION_IS_SOURCE_UNIT) == 0); return ast; } @@ -204,8 +205,8 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements CharArrayIntMap additionalKeywords = getScannerExtensionConfiguration().getAdditionalKeywords(); if (additionalKeywords != null) { - for (Iterator iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) { - char[] name = (char[]) iterator.next(); + for (Iterator iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) { + char[] name = iterator.next(); keywords.add(new String(name)); } } @@ -223,8 +224,8 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements Set keywords = new HashSet(KeywordSets.getKeywords(KeywordSetKey.PP_DIRECTIVE, getParserLanguage())); CharArrayIntMap additionalKeywords= getScannerExtensionConfiguration().getAdditionalPreprocessorKeywords(); if (additionalKeywords != null) { - for (Iterator iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) { - char[] name = (char[]) iterator.next(); + for (Iterator iterator = additionalKeywords.toList().iterator(); iterator.hasNext(); ) { + char[] name = iterator.next(); keywords.add(new String(name)); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharTable.java index 73e8e7aff24..325441df6d2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharTable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharTable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation 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 @@ -111,8 +111,8 @@ public class CharTable extends HashTable { removeEntry(i, hash); } - public List toList(){ - List list = new ArrayList( size() ); + public List toList(){ + List list = new ArrayList( size() ); int size = size(); for( int i = 0; i < size; i++ ){ list.add( keyAt( i ) ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index 5654c70295a..c9c584a757c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -70,7 +70,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit private CScope compilationUnit = null; private ILocationResolver resolver; private IIndex index; - private boolean fIsHeader; + private boolean fIsHeader= true; private IIndexFileSet fIndexFileSet; public IASTTranslationUnit getTranslationUnit() { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 27b6d703ce5..41d976295d2 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -87,9 +87,12 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat private ILocationResolver resolver; private IIndex index; private IIndexFileSet fIndexFileSet; - private boolean fIsHeader; + private boolean fIsHeader= true; private HashMap fMappedScopes= new HashMap(); - + + public CPPASTTranslationUnit() { + } + public IASTTranslationUnit getTranslationUnit() { return this; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java index 0dcd99419ff..af9683f0682 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 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 @@ -36,6 +36,7 @@ import org.eclipse.cdt.core.index.IIndexMacro; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.model.AbstractLanguage; +import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IExtendedScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo; @@ -86,11 +87,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter { private int fUpdateFlags= IIndexManager.UPDATE_ALL; private boolean fIndexHeadersWithoutContext= true; private boolean fIndexFilesWithoutConfiguration= true; - private HashMap fFileInfos= new HashMap(); + private HashMap fFileInfos= new HashMap(); private Object[] fFilesToUpdate; - private List fFilesToRemove = new ArrayList(); - private List fFilesUpFront= new ArrayList(); + private List fFilesToRemove = new ArrayList(); + private List fFilesUpFront= new ArrayList(); private int fASTOptions; protected IWritableIndex fIndex; @@ -135,8 +136,6 @@ public abstract class AbstractIndexerTask extends PDOMWriter { return "______"; //$NON-NLS-1$ } - - private final IASTTranslationUnit createAST(String code, AbstractLanguage lang, IScannerInfo scanInfo, int options, IProgressMonitor monitor) throws CoreException { String dummyName= getASTPathForParsingUpFront(); @@ -156,12 +155,10 @@ public abstract class AbstractIndexerTask extends PDOMWriter { if (codeReader == null) { return null; } - - IASTTranslationUnit ast= createAST(language, codeReader, scanInfo, options, pm); - if (ast != null && !fResolver.isSourceUnit(tu)) { - ast.setIsHeaderUnit(true); + if (fResolver.isSourceUnit(tu)) { + options |= ILanguage.OPTION_IS_SOURCE_UNIT; } - return ast; + return createAST(language, codeReader, scanInfo, options, pm); } private final IASTTranslationUnit createAST(AbstractLanguage language, CodeReader codeReader, @@ -203,9 +200,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } fTodoTaskUpdater= createTodoTaskUpdater(); - fASTOptions= AbstractLanguage.OPTION_ADD_COMMENTS | AbstractLanguage.OPTION_NO_IMAGE_LOCATIONS; + fASTOptions= ILanguage.OPTION_ADD_COMMENTS | ILanguage.OPTION_NO_IMAGE_LOCATIONS; if (getSkipReferences() == SKIP_ALL_REFERENCES) { - fASTOptions |= AbstractLanguage.OPTION_SKIP_FUNCTION_BODIES; + fASTOptions |= ILanguage.OPTION_SKIP_FUNCTION_BODIES; } fIndex.resetCacheCounters(); @@ -214,8 +211,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter { try { try { // split into sources and headers, remove excluded sources. - final HashMap files= new HashMap(); - final ArrayList ifilesToRemove= new ArrayList(); + final HashMap> files= new HashMap>(); + final ArrayList ifilesToRemove= new ArrayList(); extractFiles(files, ifilesToRemove, monitor); // remove files from index @@ -237,7 +234,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } } - private void extractFiles(Map files, List iFilesToRemove, IProgressMonitor monitor) throws CoreException { + private void extractFiles(Map> files, List iFilesToRemove, IProgressMonitor monitor) throws CoreException { final boolean force= (fUpdateFlags & IIndexManager.UPDATE_ALL) != 0; final boolean checkTimestamps= (fUpdateFlags & IIndexManager.UPDATE_CHECK_TIMESTAMPS) != 0; final boolean checkConfig= (fUpdateFlags & IIndexManager.UPDATE_CHECK_CONFIGURATION) != 0; @@ -311,7 +308,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { private void requestUpdate(int linkageID, IIndexFileLocation ifl, IIndexFragmentFile ifile) { FileKey key= new FileKey(linkageID, ifl.getURI()); - FileInfo info= (FileInfo) fFileInfos.get(key); + FileInfo info= fFileInfos.get(key); if (info == null) { info= createFileInfo(key, null); } @@ -321,7 +318,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { private void setIndexed(int linkageID, IIndexFileLocation ifl) { FileKey key= new FileKey(linkageID, ifl.getURI()); - FileInfo info= (FileInfo) fFileInfos.get(key); + FileInfo info= fFileInfos.get(key); if (info == null) { info= createFileInfo(key, null); } @@ -338,7 +335,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { private FileInfo getFileInfo(int linkageID, IIndexFileLocation ifl) { FileKey key= new FileKey(linkageID, ifl.getURI()); - return (FileInfo) fFileInfos.get(key); + return fFileInfos.get(key); } private boolean isSourceUnitConfigChange(Object tu, IIndexFragmentFile ifile) { @@ -368,11 +365,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } } - private void store(Object tu, int linkageID, boolean isSourceUnit, Map files) { + private void store(Object tu, int linkageID, boolean isSourceUnit, Map> files) { Integer key = getFileListKey(linkageID, isSourceUnit); - List list= (List) files.get(key); + List list= files.get(key); if (list == null) { - list= new LinkedList(); + list= new LinkedList(); files.put(key, list); } list.add(tu); @@ -383,11 +380,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter { return key; } - private void removeFilesInIndex(List filesToRemove, List ifilesToRemove, IProgressMonitor monitor) throws InterruptedException, CoreException { + private void removeFilesInIndex(List filesToRemove, List ifilesToRemove, IProgressMonitor monitor) throws InterruptedException, CoreException { if (!filesToRemove.isEmpty() || !ifilesToRemove.isEmpty()) { fIndex.acquireWriteLock(1); try { - for (Iterator iterator = fFilesToRemove.iterator(); iterator.hasNext();) { + for (Iterator iterator = fFilesToRemove.iterator(); iterator.hasNext();) { if (monitor.isCanceled()) { return; } @@ -400,11 +397,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } updateInfo(0, 0, -1); } - for (Iterator iterator = ifilesToRemove.iterator(); iterator.hasNext();) { + for (Iterator iterator = ifilesToRemove.iterator(); iterator.hasNext();) { if (monitor.isCanceled()) { return; } - IIndexFragmentFile ifile= (IIndexFragmentFile) iterator.next(); + IIndexFragmentFile ifile= iterator.next(); fIndex.clearFile(ifile, null); updateInfo(0, 0, -1); } @@ -416,11 +413,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } private void parseFilesUpFront(IProgressMonitor monitor) throws CoreException { - for (Iterator iter = fFilesUpFront.iterator(); iter.hasNext();) { + for (Iterator iter = fFilesUpFront.iterator(); iter.hasNext();) { if (monitor.isCanceled()) { return; } - String upfront= (String) iter.next(); + String upfront= iter.next(); String filePath = upfront; filePath= filePath.trim(); if (filePath.length() == 0) { @@ -461,11 +458,11 @@ public abstract class AbstractIndexerTask extends PDOMWriter { fFilesUpFront.clear(); } - private void parseLinkage(int linkageID, Map fileListMap, IProgressMonitor monitor) throws CoreException, InterruptedException { + private void parseLinkage(int linkageID, Map> fileListMap, IProgressMonitor monitor) throws CoreException, InterruptedException { // sources - List files= (List) fileListMap.get(getFileListKey(linkageID, true)); + List files= fileListMap.get(getFileListKey(linkageID, true)); if (files != null) { - for (Iterator iter = files.iterator(); iter.hasNext();) { + for (Iterator iter = files.iterator(); iter.hasNext();) { if (monitor.isCanceled()) return; final Object tu= iter.next(); @@ -484,10 +481,10 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } // headers with context - HashMap contextMap= new HashMap(); - files= (List) fileListMap.get(getFileListKey(linkageID, false)); + HashMap contextMap= new HashMap(); + files= fileListMap.get(getFileListKey(linkageID, false)); if (files != null) { - for (Iterator iter = files.iterator(); iter.hasNext();) { + for (Iterator iter = files.iterator(); iter.hasNext();) { if (monitor.isCanceled()) return; final Object header= iter.next(); @@ -515,7 +512,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { // headers without context contextMap= null; - for (Iterator iter = files.iterator(); iter.hasNext();) { + for (Iterator iter = files.iterator(); iter.hasNext();) { if (monitor.isCanceled()) return; final Object header= iter.next(); @@ -535,7 +532,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } private static Object NO_CONTEXT= new Object(); - private Object findContext(IIndexFragmentFile ifile, HashMap contextMap) { + private Object findContext(IIndexFragmentFile ifile, HashMap contextMap) { Object cachedContext= contextMap.get(ifile); if (cachedContext != null) { return cachedContext == NO_CONTEXT ? null : cachedContext; @@ -602,8 +599,8 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } private void writeToIndex(final int linkageID, IASTTranslationUnit ast, int configHash, IProgressMonitor pm) throws CoreException, InterruptedException { - HashSet enteredASTFilePaths= new HashSet(); - ArrayList orderedIFLs= new ArrayList(); + HashSet enteredASTFilePaths= new HashSet(); + ArrayList orderedIFLs= new ArrayList(); final String astPath = ast.getFilePath(); enteredASTFilePaths.add(astPath); @@ -619,7 +616,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { orderedIFLs.add(fResolver.resolveASTPath(astPath)); } - IIndexFileLocation[] ifls= (IIndexFileLocation[]) orderedIFLs.toArray(new IIndexFileLocation[orderedIFLs.size()]); + 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]; @@ -631,7 +628,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter { } } - private void collectOrderedIFLs(final int linkageID, IASTInclusionNode inclusion, HashSet enteredASTFilePaths, ArrayList orderedIFLs) throws CoreException { + private void collectOrderedIFLs(final int linkageID, IASTInclusionNode inclusion, HashSet enteredASTFilePaths, ArrayList orderedIFLs) throws CoreException { final IASTPreprocessorIncludeStatement id= inclusion.getIncludeDirective(); if (id.isActive() && id.isResolved()) { final String path= id.getPath(); @@ -705,12 +702,12 @@ public abstract class AbstractIndexerTask extends PDOMWriter { private static int computeHashCode(IScannerInfo scannerInfo) { int result= 0; - Map macros= scannerInfo.getDefinedSymbols(); + Map macros= scannerInfo.getDefinedSymbols(); if (macros != null) { - for (Iterator i = macros.entrySet().iterator(); i.hasNext();) { - Map.Entry entry = (Map.Entry) i.next(); - String key = (String) entry.getKey(); - String value = (String) entry.getValue(); + for (Iterator> i = macros.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = i.next(); + String key = entry.getKey(); + String value = entry.getValue(); result= addToHashcode(result, key); if (value != null && value.length() > 0) { result= addToHashcode(result, value); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java index d4b13a80a2c..70fedb0deaa 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation 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 @@ -115,10 +115,11 @@ public class InternalASTServiceProvider implements IASTServiceProvider { return null; IScanner scanner = null; ISourceCodeParser parser = null; + boolean[] isSource= {false}; if( configuration == null || configuration.getParserDialect() == null) { - ParserLanguage l = getLanguage(filename, project); + ParserLanguage l = getLanguage(filename, project, isSource); IScannerExtensionConfiguration scannerExtensionConfiguration; if( l == ParserLanguage.CPP ) scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION; @@ -169,7 +170,9 @@ public class InternalASTServiceProvider implements IASTServiceProvider { } } // Parse - return parser.parse(); + IASTTranslationUnit ast= parser.parse(); + ast.setIsHeaderUnit(!isSource[0]); + return ast; } public IASTCompletionNode getCompletionNode(IStorage fileToParse, IProject project, int offset, @@ -199,7 +202,8 @@ public class InternalASTServiceProvider implements IASTServiceProvider { CodeReader reader = fileCreator.createCodeReaderForTranslationUnit(filename); - ParserLanguage l = getLanguage(filename, project); + boolean[] isSource= {false}; + ParserLanguage l = getLanguage(filename, project, isSource); IScannerExtensionConfiguration scannerExtensionConfiguration = null; if (l == ParserLanguage.CPP) scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION; @@ -242,23 +246,25 @@ public class InternalASTServiceProvider implements IASTServiceProvider { return dialects; } - private ParserLanguage getLanguage( String filename, IProject project ) - { + private ParserLanguage getLanguage( String filename, IProject project, boolean[] isSource ) { //FIXME: ALAIN, for headers should we assume CPP ?? // The problem is that it really depends on how the header was included. String id = null; + isSource[0]= false; IContentType contentType = CCorePlugin.getContentType(project, filename); if (contentType != null) { id = contentType.getId(); } if (id != null) { if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)) { + isSource[0]= true; return ParserLanguage.CPP; } else if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) { return ParserLanguage.CPP; } else if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)) { return ParserLanguage.C; } else if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) { + isSource[0]= true; return ParserLanguage.C; } else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) { // ??? diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java index 1516c23e1f0..251977a7c20 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/compare/CStructureCreator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation 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 @@ -104,11 +104,13 @@ public class CStructureCreator extends StructureCreator { CodeReader reader= new CodeReader(document.get().toCharArray()); // determine the language - ILanguage language= determineLanguage(element); + boolean isSource[]= {false}; + ILanguage language= determineLanguage(element, isSource); try { IASTTranslationUnit ast; - ast= language.getASTTranslationUnit(reader, scanInfo, codeReaderFactory, null, ParserUtil.getParserLogService()); + int options= isSource[0] ? ILanguage.OPTION_IS_SOURCE_UNIT : 0; + ast= language.getASTTranslationUnit(reader, scanInfo, codeReaderFactory, null, options, ParserUtil.getParserLogService()); CStructureCreatorVisitor structureCreator= new CStructureCreatorVisitor(root); // build structure ast.accept(structureCreator); @@ -125,7 +127,7 @@ public class CStructureCreator extends StructureCreator { * @param element * @return a language instance */ - private ILanguage determineLanguage(Object element) { + private ILanguage determineLanguage(Object element, boolean[] isSource) { ILanguage language= null; if (element instanceof ResourceNode) { IResource resource= ((ResourceNode)element).getResource(); @@ -134,6 +136,7 @@ public class CStructureCreator extends StructureCreator { if (tUnit != null) { try { language= tUnit.getLanguage(); + isSource[0]= tUnit.isSourceUnit(); } catch (CoreException exc) { // silently ignored }