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