reader
.
- * As an option you can supply
+ * Constructs an AST for the source code provided by reader
.
+ *
* @param content source code to be parsed.
* @param scanInfo provides include paths and defined symbols.
* @param fileCreator factory that provides file content for files included
- * @param index (optional) index to use to lookup symbols external to the tu.
- * @param options A combination of
- * {@link #OPTION_SKIP_FUNCTION_BODIES},
- * {@link #OPTION_NO_IMAGE_LOCATIONS}, {@link #OPTION_IS_SOURCE_UNIT},
- * or 0
.
+ * @param index (optional) index to use to lookup symbols external to the translation unit.
+ * @param options A combination of {@link #OPTION_SKIP_FUNCTION_BODIES},
+ * {@link #OPTION_NO_IMAGE_LOCATIONS}, or 0
.
* @param log logger
* @return an AST for the source code provided by reader.
* @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 5b5f0f99b89..43418911ebd 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
@@ -864,9 +864,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
if ((style & AST_PARSE_INACTIVE_CODE) != 0) {
options |= ILanguage.OPTION_PARSE_INACTIVE_CODE;
}
- if (isSourceUnit()) {
- options |= ILanguage.OPTION_IS_SOURCE_UNIT;
- }
final IParserLogService log;
if (monitor instanceof ICanceler) {
log= new ParserLogService(DebugLogConstants.PARSER, (ICanceler) monitor);
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 15ee4e1d952..283398f2088 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
@@ -164,9 +164,7 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
try {
// Parse
- IASTTranslationUnit ast= parser.parse();
- ast.setIsHeaderUnit((options & OPTION_IS_SOURCE_UNIT) == 0);
- return ast;
+ return parser.parse();
} catch (ParseError e) {
// Only the TOO_MANY_TOKENS error can be handled here.
if (e.getErrorKind() != ParseErrorKind.TOO_MANY_TOKENS)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/FileContent.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/FileContent.java
index 8594ace9c3c..d8ec351a596 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/FileContent.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/FileContent.java
@@ -77,6 +77,7 @@ public abstract class FileContent {
/**
* Creates a file content object for a fixed buffer.
+ *
* @param filePath the path of the file as it will appear in {@link IASTFileLocation#getFileName()}
* @param contents the actual content.
*/
@@ -84,23 +85,45 @@ public abstract class FileContent {
return new InternalFileContent(filePath, new CharArray(contents));
}
+ /**
+ * Creates a file content object for a fixed buffer.
+ *
+ * @param filePath the path of the file as it will appear in {@link IASTFileLocation#getFileName()}
+ * @param contents the actual content.
+ * @since 6.3
+ */
+ public static FileContent create(String filePath, boolean isSource, char[] contents) {
+ InternalFileContent fileContent = new InternalFileContent(filePath, new CharArray(contents));
+ fileContent.setIsSource(isSource);
+ return fileContent;
+ }
+
/**
* Creates a file content object for a translation-unit, which may be a working copy.
*/
public static FileContent create(ITranslationUnit tu) {
+ InternalFileContent fileContent;
+
IPath location= tu.getLocation();
- if (location == null)
- return create(tu.getElementName(), tu.getContents());
-
- if (tu.isWorkingCopy()) {
- return create(location.toOSString(), tu.getContents());
+ if (location == null) {
+ fileContent = new InternalFileContent(tu.getElementName(), new CharArray(tu.getContents()));
+ } else if (tu.isWorkingCopy()) {
+ fileContent = new InternalFileContent(location.toOSString(), new CharArray(tu.getContents()));
+ } else {
+ IResource res= tu.getResource();
+ if (res instanceof IFile) {
+ fileContent = InternalParserUtil.createWorkspaceFileContent((IFile) res);
+ } else {
+ fileContent = InternalParserUtil.createExternalFileContent(location.toOSString(),
+ InternalParserUtil.SYSTEM_DEFAULT_ENCODING);
+ }
}
-
- IResource res= tu.getResource();
- if (res instanceof IFile) {
- return create((IFile) res);
+
+ if (fileContent != null) {
+ fileContent.setTranslationUnit(tu);
+ fileContent.setIsSource(tu.isSourceUnit());
}
- return createForExternalFileLocation(location.toOSString());
+ return fileContent;
}
/**
@@ -111,22 +134,37 @@ public abstract class FileContent {
}
/**
- * Creates a file content for a workspace file
+ * Creates a file content for a workspace header file.
*/
public static FileContent create(IFile file) {
return InternalParserUtil.createWorkspaceFileContent(file);
}
+ /**
+ * Creates a file content object for a header file that is not part of the workspace.
+ */
public static FileContent createForExternalFileLocation(String fileLocation) {
return createForExternalFileLocation(fileLocation, InternalParserUtil.SYSTEM_DEFAULT_ENCODING);
}
/**
- * Creates a file content object for a file location that is not part of the workspace
+ * Creates a file content object for a header file that is not part of the workspace.
* @since 5.3
*/
public static FileContent createForExternalFileLocation(String fileLocation, String encoding) {
- return InternalParserUtil.createExternalFileContent(fileLocation, encoding);
+ return createForExternalFileLocation(fileLocation, false, encoding);
+ }
+
+ /**
+ * Creates a file content object for a header or a source file that is not part of the workspace.
+ * @since 6.3
+ */
+ public static FileContent createForExternalFileLocation(String fileLocation, boolean isSource,
+ String encoding) {
+ InternalFileContent fileContent = InternalParserUtil.createExternalFileContent(fileLocation, encoding);
+ if (fileContent != null)
+ fileContent.setIsSource(isSource);
+ return fileContent;
}
/**
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
index ecaf2757a1f..7d0baaca3ce 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
@@ -19,7 +19,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
import org.eclipse.cdt.internal.core.parser.scanner.Lexer;
/**
- * Interface between the parser and the preprocessor.
+ * Interface between the parser and the preprocessor.
*
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
@@ -27,7 +27,7 @@ import org.eclipse.cdt.internal.core.parser.scanner.Lexer;
public interface IScanner {
/**
* Returns a map from {@link String} to {@link IMacroBinding} containing
- * all the definitions that are defined at the current point in the
+ * all the definitions that are defined at the current point in the
* process of scanning.
*/
public Maptrue
, whenever we are processing the outermost file of the translation unit.
+ * Returns {@code true}, whenever we are processing the outermost file of the translation unit.
*/
public boolean isOnTopContext();
-
+
/**
* Attempts to cancel the scanner.
*/
public void cancel();
-
+
/**
* Returns the location resolver associated with this scanner.
+ *
* @noreference This method is not intended to be referenced by clients.
*/
public ILocationResolver getLocationResolver();
-
+
/**
* Puts the scanner into content assist mode.
+ *
* @noreference This method is not intended to be referenced by clients.
*/
public void setContentAssistMode(int offset);
@@ -64,25 +66,26 @@ public interface IScanner {
/**
* Instructs the scanner to split tokens of kind {@link IToken#tSHIFTR} into two tokens of
* kind {@link IToken#tGT_in_SHIFTR}.
+ *
* @noreference This method is not intended to be referenced by clients.
*/
public void setSplitShiftROperator(boolean val);
-
+
/**
- * Turns on/off creation of image locations.
+ * Turns on/off creation of image locations.
* @see org.eclipse.cdt.core.dom.ast.IASTName#getImageLocation()
+ *
* @noreference This method is not intended to be referenced by clients.
* @since 5.0
*/
public void setComputeImageLocations(boolean val);
/**
- * Turns on/off tracking if exported included files.
+ * Turns on/off tracking if exported included files.
* @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement#isIncludedFileExported()
* @see IncludeExportPatterns
*
- * @param patterns if not {{@code null}, include export tracking is enabled, otherwise it is
- * disabled
+ * @param patterns if not {@code null}, include export tracking is enabled, otherwise it is disabled
*
* @noreference This method is not intended to be referenced by clients.
* @since 5.5
@@ -93,14 +96,16 @@ public interface IScanner {
* Toggles generation of tokens for inactive code branches. When turned on,
* each inactive code branch is preceded by a token of kind {@link IToken#tINACTIVE_CODE_START} and
* succeeded by one of kind {@link IToken#tINACTIVE_CODE_END}.
- *
+ *
* @noreference This method is not intended to be referenced by clients.
*/
public void setProcessInactiveCode(boolean val);
/**
- * When in inactive code, skips all tokens up to the end of the inactive code section.
- * Note, token after calling this method may be another token of type {@link IToken#tINACTIVE_CODE_START}. + * When in inactive code, skips all tokens up to the end of the inactive code section. + *
Note, token after calling this method may be another token of type
+ * {@link IToken#tINACTIVE_CODE_START}.
+ *
* @noreference This method is not intended to be referenced by clients.
*/
public void skipInactiveCode() throws OffsetLimitReachedException;
@@ -109,21 +114,23 @@ public interface IScanner {
* Returns the current nesting in code branches.
* @see IInactiveCodeToken#getOldNesting()
* @see IInactiveCodeToken#getNewNesting()
+ *
* @noreference This method is not intended to be referenced by clients.
*/
public int getCodeBranchNesting();
-
+
+ /**
+ * Returns a list of additional (compiler specific) suffixes which can
+ * be placed on numbers. e.g. 'u' 'l' -> 1l or 1u.
+ *
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ public char[] getAdditionalNumericLiteralSuffixes();
+
/**
* @deprecated Has no effect.
* @noreference This method is not intended to be referenced by clients.
*/
@Deprecated
- public void setScanComments(boolean val);
-
- /**
- * Returns a list of additional (compiler specific) suffixes which can
- * be placed on numbers. e.g. 'u' 'l' -> 1l or 1u.
- * @noreference This method is not intended to be referenced by clients.
- */
- public char[] getAdditionalNumericLiteralSuffixes();
+ public default void setScanComments(boolean val) {}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java
index 66f5668cb76..e0309e78031 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CFunction.java
@@ -13,6 +13,7 @@
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
+import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
@@ -506,4 +507,14 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
}
return null;
}
+
+ /** For debugging only. */
+ @Override
+ public String toString() {
+ StringBuilder result = new StringBuilder();
+ result.append(getName());
+ IFunctionType t = getType();
+ result.append(t != null ? ASTTypeUtil.getParameterTypeStringAndQualifiers(t) : "()"); //$NON-NLS-1$
+ return result.toString();
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
index bfb27578ae8..4a81d8f03b4 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CNodeFactory.java
@@ -447,7 +447,10 @@ public class CNodeFactory extends NodeFactory implements ICNodeFactory {
if (scanner != null) {
tu.setLocationResolver(scanner.getLocationResolver());
if (scanner instanceof CPreprocessor) {
- tu.setIsForContentAssist(((CPreprocessor) scanner).isContentAssistMode());
+ CPreprocessor cPreprocessor = (CPreprocessor) scanner;
+ tu.setIsForContentAssist(cPreprocessor.isContentAssistMode());
+ tu.setOriginatingTranslationUnit(cPreprocessor.getTranslationUnit());
+ tu.setIsHeaderUnit(!cPreprocessor.isSource());
}
}
tu.setASTNodeFactory(this);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
index 3712859eaee..2492e217808 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPNodeFactory.java
@@ -770,7 +770,10 @@ public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
if (scanner != null) {
tu.setLocationResolver(scanner.getLocationResolver());
if (scanner instanceof CPreprocessor) {
- tu.setIsForContentAssist(((CPreprocessor) scanner).isContentAssistMode());
+ CPreprocessor cPreprocessor = (CPreprocessor) scanner;
+ tu.setIsForContentAssist(cPreprocessor.isContentAssistMode());
+ tu.setOriginatingTranslationUnit(cPreprocessor.getTranslationUnit());
+ tu.setIsHeaderUnit(!cPreprocessor.isSource());
}
}
tu.setASTNodeFactory(this);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java
index e38fe25da9a..201168d4062 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/indexer/StandaloneIndexerInputAdapter.java
@@ -166,18 +166,17 @@ public class StandaloneIndexerInputAdapter extends IndexerInputAdapter {
String stu = tu.toString();
String fileEncoding = getFileEncoding(stu);
- return FileContent.createForExternalFileLocation(stu, fileEncoding);
+ return FileContent.createForExternalFileLocation(stu, isSource(stu), fileEncoding);
}
public String getFileEncoding(String stu) {
String fileEncoding = null;
- // query file's encoding, if we find it and use it to create CodeReader
+ // Query file's encoding, if we find it and use it to create CodeReader
FileEncodingRegistry fileEncodingRegistry = fIndexer.getFileEncodingRegistry();
- if(fileEncodingRegistry != null){
+ if (fileEncodingRegistry != null)
fileEncoding = fileEncodingRegistry.getFileEncoding(stu);
- }
if (fileEncoding == null)
- return InternalParserUtil.SYSTEM_DEFAULT_ENCODING;
+ fileEncoding = InternalParserUtil.SYSTEM_DEFAULT_ENCODING;
return fileEncoding;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
index ed9673134bc..9198bbbfbc9 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java
@@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IFileNomination;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
import org.eclipse.cdt.core.index.IIndexMacro;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.AbstractParserLogService;
import org.eclipse.cdt.core.parser.EndOfFileException;
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
@@ -262,7 +263,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private final ScannerContext fRootContext;
protected ScannerContext fCurrentContext;
- private boolean isCancelled= false;
+ private boolean isCancelled;
private boolean fIsFirstFetchToken= true;
private Token fPrefetchedTokens;
@@ -273,8 +274,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
// Detection of include guards used around an include directive
private char[] fExternIncludeGuard;
- private Set