diff options
author | Marc-Andre Laperle | 2019-09-29 03:02:05 +0000 |
---|---|---|
committer | Marc-André Laperle | 2019-10-04 03:14:32 +0000 |
commit | 4e16631f30de08444342b0ad6622cfcf3cd39fd4 (patch) | |
tree | 2e8f4cbb89441d717d93021b2cba5e65d87de9ba /core/org.eclipse.cdt.core/parser/org/eclipse/cdt | |
parent | 232e3d71536134a8fe722f133a8af7d785345790 (diff) | |
download | org.eclipse.cdt-4e16631f30de08444342b0ad6622cfcf3cd39fd4.tar.gz org.eclipse.cdt-4e16631f30de08444342b0ad6622cfcf3cd39fd4.tar.xz org.eclipse.cdt-4e16631f30de08444342b0ad6622cfcf3cd39fd4.zip |
Bug 360919 - [MSVC] preprocessor symbol __STDC__ always defined
Move the __STDC__ macro to the scanner configuration extension, where we can
differentiate compiler type. Only add it when compiler type is not MSVC.
This will miss the case where MSVC is compiling in C mode and /Za is used,
then __STDC__ should be defined but this is a much less common case and would be
addressed likely outside scanner configuration.
See also
https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
Change-Id: Icc5d3ef038fb468efe33802a04fc78fc1e5e583e
Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt')
3 files changed, 30 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java index 7a2e0b6e8d8..68693ca572a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java @@ -27,11 +27,17 @@ import org.eclipse.cdt.core.parser.IScannerInfo; * Configures the preprocessor for parsing c-sources as accepted by gcc. */ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfiguration { + private static enum CompilerType { + GCC, MSVC + } + private static final int VERSION_4_2 = version(4, 2); private static final int VERSION_4_7 = version(4, 7); private static GCCScannerExtensionConfiguration CONFIG = new GCCScannerExtensionConfiguration(); private static GCCScannerExtensionConfiguration CONFIG_4_2 = new GCCScannerExtensionConfiguration(VERSION_4_2); private static GCCScannerExtensionConfiguration CONFIG_4_7 = new GCCScannerExtensionConfiguration(VERSION_4_7); + private static GCCScannerExtensionConfiguration CONFIG_MSVC = new GCCScannerExtensionConfiguration( + CompilerType.MSVC, 0 /* version is ignored for now */); /** * @since 5.1 @@ -47,6 +53,12 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu if (info != null) { try { final Map<String, String> definedSymbols = info.getDefinedSymbols(); + + String mscVer = definedSymbols.get("_MSC_VER"); //$NON-NLS-1$ + if (mscVer != null && Integer.valueOf(mscVer) > 0) { + return CONFIG_MSVC; + } + int major = Integer.valueOf(definedSymbols.get("__GNUC__")); //$NON-NLS-1$ int minor = Integer.valueOf(definedSymbols.get("__GNUC_MINOR__")); //$NON-NLS-1$ int version = version(major, minor); @@ -70,11 +82,23 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu /** * @since 5.5 */ - @SuppressWarnings("nls") public GCCScannerExtensionConfiguration(int version) { + this(CompilerType.GCC, version); + } + + /** + * @since 6.9 + */ + @SuppressWarnings("nls") + public GCCScannerExtensionConfiguration(CompilerType compiler, int version) { addMacro("__null", "(void *)0"); addMacro("__builtin_offsetof(T,m)", "((size_t) &((T *)0)->m)"); + if (compiler != CompilerType.MSVC) { + // MSVC only defines this when compiling in C mode and /Za is used. + addMacro("__STDC__", "1"); + } + if (version >= VERSION_4_2) { addKeyword(GCCKeywords.cp_decimal32, IGCCToken.t_decimal32); addKeyword(GCCKeywords.cp_decimal64, IGCCToken.t_decimal64); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java index fa83f023354..c3dc69c9c3d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/GPPScannerExtensionConfiguration.java @@ -127,6 +127,11 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu addKeyword(Keywords.c_COMPLEX, IToken.t__Complex); addKeyword(Keywords.c_IMAGINARY, IToken.t__Imaginary); + if (compiler != CompilerType.MSVC) { + // MSVC only defines this when compiling in C mode and /Za is used. + addMacro("__STDC__", "1"); + } + if (compiler == CompilerType.GCC) { if (version >= VERSION_4_2) { addKeyword(GCCKeywords.cp_decimal32, IGCCToken.t_decimal32); 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 4b82a263411..2f06777d22c 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 @@ -103,7 +103,6 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { Integer.toString(getCDTVersion()).toCharArray()); private static final ObjectStyleMacro __cplusplus = new ObjectStyleMacro("__cplusplus".toCharArray(), //$NON-NLS-1$ "201103L".toCharArray()); //$NON-NLS-1$ - private static final ObjectStyleMacro __STDC__ = new ObjectStyleMacro("__STDC__".toCharArray(), ONE); //$NON-NLS-1$ private static final ObjectStyleMacro __STDC_HOSTED__ = new ObjectStyleMacro("__STDC_HOSTED__".toCharArray(), ONE); //$NON-NLS-1$ private static final ObjectStyleMacro __STDC_VERSION__ = new ObjectStyleMacro("__STDC_VERSION__".toCharArray(), //$NON-NLS-1$ "199901L".toCharArray()); //$NON-NLS-1$ @@ -507,7 +506,6 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { private void setupMacroDictionary(IScannerExtensionConfiguration config, IScannerInfo info, ParserLanguage lang) { // Built-in macros fMacroDictionary.put(__CDT_PARSER__.getNameCharArray(), __CDT_PARSER__); - fMacroDictionary.put(__STDC__.getNameCharArray(), __STDC__); fMacroDictionary.put(__FILE__.getNameCharArray(), __FILE__); fMacroDictionary.put(__DATE__.getNameCharArray(), __DATE__); fMacroDictionary.put(__TIME__.getNameCharArray(), __TIME__); |