1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

MSVC: Add some type-traits supported by MSVC in the scanner configuration

Add existing type-traits that were implemented for GCC that are relevant to
MSVC. Some are missing but even with those parsing is improved with minimal
effort. For the LLVM codebase, I see it go from 0.46% unresolved names (16,668)
to 0.19% (6,950).
This is combined with another patch that adds temporary macro hacks.

Change-Id: I441dcfa4a986edef78b75c0d6db04b78fdbc97b3
Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
This commit is contained in:
Marc-Andre Laperle 2019-07-02 23:40:48 -04:00 committed by Marc-André Laperle
parent 96bbd4b7a8
commit dee22911a5

View file

@ -32,7 +32,7 @@ import org.eclipse.cdt.core.parser.Keywords;
*/
public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfiguration {
private static enum CompilerType {
GCC, Clang
GCC, Clang, MSVC
}
private static final int VERSION_4_2 = version(4, 2);
@ -50,6 +50,8 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
private static GPPScannerExtensionConfiguration CONFIG_8_0 = new GPPScannerExtensionConfiguration(VERSION_8_0);
private static GPPScannerExtensionConfiguration CONFIG_CLANG = new GPPScannerExtensionConfiguration(
CompilerType.Clang, 0 /* version is ignored for now */);
private static GPPScannerExtensionConfiguration CONFIG_MSVC = new GPPScannerExtensionConfiguration(
CompilerType.MSVC, 0 /* version is ignored for now */);
public static GPPScannerExtensionConfiguration getInstance() {
return CONFIG;
@ -69,6 +71,11 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
return CONFIG_CLANG;
}
String mscVer = definedSymbols.get("_MSC_VER"); //$NON-NLS-1$
if (mscVer != null && Integer.valueOf(mscVer) > 0) {
return CONFIG_MSVC;
}
// GCC
int major = Integer.valueOf(definedSymbols.get("__GNUC__")); //$NON-NLS-1$
int minor = Integer.valueOf(definedSymbols.get("__GNUC_MINOR__")); //$NON-NLS-1$
@ -189,6 +196,61 @@ public class GPPScannerExtensionConfiguration extends GNUScannerExtensionConfigu
addKeyword(GCCKeywords.cp__is_trivially_constructible, IGCCToken.tTT_is_trivially_constructible);
addKeyword(GCCKeywords.cp__is_trivially_assignable, IGCCToken.tTT_is_trivially_assignable);
addKeyword(GCCKeywords.cp__is_constructible, IGCCToken.tTT_is_constructible);
} else if (compiler == CompilerType.MSVC) {
// As documented at
// https://docs.microsoft.com/en-us/cpp/extensions/compiler-support-for-type-traits-cpp-component-extensions?view=vs-2017
// For now we don't make it dependent on the version.
addKeyword(GCCKeywords.cp__has_nothrow_assign, IGCCToken.tTT_has_nothrow_assign);
addKeyword(GCCKeywords.cp__has_nothrow_constructor, IGCCToken.tTT_has_nothrow_constructor);
addKeyword(GCCKeywords.cp__has_nothrow_copy, IGCCToken.tTT_has_nothrow_copy);
addKeyword(GCCKeywords.cp__has_trivial_assign, IGCCToken.tTT_has_trivial_assign);
addKeyword(GCCKeywords.cp__has_trivial_constructor, IGCCToken.tTT_has_trivial_constructor);
addKeyword(GCCKeywords.cp__has_trivial_copy, IGCCToken.tTT_has_trivial_copy);
addKeyword(GCCKeywords.cp__has_trivial_destructor, IGCCToken.tTT_has_trivial_destructor);
addKeyword(GCCKeywords.cp__has_virtual_destructor, IGCCToken.tTT_has_virtual_destructor);
addKeyword(GCCKeywords.cp__is_abstract, IGCCToken.tTT_is_abstract);
addKeyword(GCCKeywords.cp__is_base_of, IGCCToken.tTT_is_base_of);
addKeyword(GCCKeywords.cp__is_class, IGCCToken.tTT_is_class);
addKeyword(GCCKeywords.cp__is_empty, IGCCToken.tTT_is_empty);
addKeyword(GCCKeywords.cp__is_enum, IGCCToken.tTT_is_enum);
addKeyword(GCCKeywords.cp__is_pod, IGCCToken.tTT_is_pod);
addKeyword(GCCKeywords.cp__is_polymorphic, IGCCToken.tTT_is_polymorphic);
addKeyword(GCCKeywords.cp__is_union, IGCCToken.tTT_is_union);
// Missing from that reference page:
// - __has_assign
// - __has_copy
// - __has_finalizer
// - __has_user_destructor
// - __is_convertible_to
// - __is_delegate
// - __is_interface_class
// - __is_ref_array
// - __is_ref_class
// - __is_simple_value_class
// - __is_value_class
// These are according to:
// http://clang.llvm.org/docs/LanguageExtensions.html#checks-for-type-trait-primitives.
addKeyword(GCCKeywords.cp__is_final, IGCCToken.tTT_is_final);
addKeyword(GCCKeywords.cp__underlying_type, IGCCToken.tTT_underlying_type);
addKeyword(GCCKeywords.cp__is_trivially_constructible, IGCCToken.tTT_is_trivially_constructible);
addKeyword(GCCKeywords.cp__is_trivially_assignable, IGCCToken.tTT_is_trivially_assignable);
addKeyword(GCCKeywords.cp__is_constructible, IGCCToken.tTT_is_constructible);
// Missing from that page:
// - __is_assignable
// - __is_destructible
// - __is_nothrow_destructible
// - __is_nothrow_assignable
// - __is_nothrow_constructible
// Found by looking at some headers
addKeyword(GCCKeywords.cp__is_standard_layout, IGCCToken.tTT_is_standard_layout);
addKeyword(GCCKeywords.cp__is_literal_type, IGCCToken.tTT_is_literal_type);
addKeyword(GCCKeywords.cp__is_trivial, IGCCToken.tTT_is_trivial);
addKeyword(GCCKeywords.cp__is_trivially_copyable, IGCCToken.tTT_is_trivially_copyable);
// Missing:
// - __is_trivially_destructible
}
}