Platform.h is out of control Part 7: Split calling convention macro definitions out of Platform.h and into a new PlatformCallingConventions.h
https://bugs.webkit.org/show_bug.cgi?id=206377

Reviewed by Anders Carlsson.

As a another step towards cleaning up Platform.h, split out all the calling convention
macros into their own file.

* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
Add new header.

* wtf/Platform.h:
* wtf/PlatformCPU.h:
* wtf/PlatformEnable.h:
* wtf/PlatformHave.h:
* wtf/PlatformLegacy.h:
* wtf/PlatformOS.h:
* wtf/PlatformUse.h:
Unify indirect inclusion guard.

* wtf/PlatformCallingConventions.h: Copied from Source/WTF/wtf/Platform.h.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@254728 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog
index e4183e4..3d191fa 100644
--- a/Source/WTF/ChangeLog
+++ b/Source/WTF/ChangeLog
@@ -1,3 +1,28 @@
+2020-01-16  Sam Weinig  <weinig@apple.com>
+
+        Platform.h is out of control Part 7: Split calling convention macro definitions out of Platform.h and into a new PlatformCallingConventions.h
+        https://bugs.webkit.org/show_bug.cgi?id=206377
+
+        Reviewed by Anders Carlsson.
+
+        As a another step towards cleaning up Platform.h, split out all the calling convention
+        macros into their own file.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/CMakeLists.txt:
+        Add new header.
+
+        * wtf/Platform.h:
+        * wtf/PlatformCPU.h:
+        * wtf/PlatformEnable.h:
+        * wtf/PlatformHave.h:
+        * wtf/PlatformLegacy.h:
+        * wtf/PlatformOS.h:
+        * wtf/PlatformUse.h:
+        Unify indirect inclusion guard.
+
+        * wtf/PlatformCallingConventions.h: Copied from Source/WTF/wtf/Platform.h.
+
 2020-01-16  Robin Morisset  <rmorisset@apple.com>
 
         Use dataLogIf more regularly
diff --git a/Source/WTF/WTF.xcodeproj/project.pbxproj b/Source/WTF/WTF.xcodeproj/project.pbxproj
index f9ff508..76d880a 100644
--- a/Source/WTF/WTF.xcodeproj/project.pbxproj
+++ b/Source/WTF/WTF.xcodeproj/project.pbxproj
@@ -455,6 +455,7 @@
 		7CDD7FF7186D291E007433CD /* IteratorAdaptors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IteratorAdaptors.h; sourceTree = "<group>"; };
 		7CDD7FF9186D2A54007433CD /* IteratorRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IteratorRange.h; sourceTree = "<group>"; };
 		7CEAE5AC1EA6E10F00DB6890 /* NotFound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotFound.h; sourceTree = "<group>"; };
+		7CEF23EB23D1257900F8B904 /* PlatformCallingConventions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCallingConventions.h; sourceTree = "<group>"; };
 		7CFAF3C923D0AF1500D21BDD /* PlatformUse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformUse.h; sourceTree = "<group>"; };
 		7E29C33D15FFD79B00516D61 /* ObjCRuntimeExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjCRuntimeExtras.h; sourceTree = "<group>"; };
 		8134013615B092FD001FF0B8 /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; };
@@ -1126,6 +1127,7 @@
 				0F824A641B7443A0002E345D /* ParkingLot.cpp */,
 				0F824A651B7443A0002E345D /* ParkingLot.h */,
 				A876DBD7151816E500DADB95 /* Platform.h */,
+				7CEF23EB23D1257900F8B904 /* PlatformCallingConventions.h */,
 				7C42307223CE2D8A006E54D0 /* PlatformCPU.h */,
 				7C42307123CE2D8A006E54D0 /* PlatformEnable.h */,
 				7C3A45D023CFA883007DE3A6 /* PlatformHave.h */,
diff --git a/Source/WTF/wtf/CMakeLists.txt b/Source/WTF/wtf/CMakeLists.txt
index 8c7b051..9664262 100644
--- a/Source/WTF/wtf/CMakeLists.txt
+++ b/Source/WTF/wtf/CMakeLists.txt
@@ -170,6 +170,7 @@
     ParallelVectorIterator.h
     ParkingLot.h
     Platform.h
+    PlatformCallingConventions.h
     PlatformCPU.h
     PlatformEnable.h
     PlatformHave.h
diff --git a/Source/WTF/wtf/Platform.h b/Source/WTF/wtf/Platform.h
index aa9f8ea..cefc287 100644
--- a/Source/WTF/wtf/Platform.h
+++ b/Source/WTF/wtf/Platform.h
@@ -30,8 +30,9 @@
 /* Include compiler specific macros */
 #include <wtf/Compiler.h>
 
-/* __PLATFORM_INDIRECT__ ensures that users #include <wtf/Platform.h> rather than one of the helper files files directly. */
-#define __PLATFORM_INDIRECT__
+/* This ensures that users #include <wtf/Platform.h> rather than one of the helper files files directly. */
+#define WTF_PLATFORM_GUARD_AGAINST_INDIRECT_INCLUSION
+
 
 /* ==== Platform adaptation macros: these describe properties of the target environment. ==== */
 
@@ -50,6 +51,7 @@
 /* HAVE() - specific system features (headers, functions or similar) that are present or not */
 #include <wtf/PlatformHave.h>
 
+
 /* ==== Policy decision macros: these define policy choices for a particular port. ==== */
 
 /* USE() - use a particular third-party library or optional OS service */
@@ -58,7 +60,14 @@
 /* ENABLE() - turn on a specific feature of WebKit */
 #include <wtf/PlatformEnable.h>
 
-#undef __PLATFORM_INDIRECT__
+
+/* ==== Helper macros ==== */
+
+/* Macros for specifing specific calling conventions. */
+#include <wtf/PlatformCallingConventions.h>
+
+
+/* ==== Platform additions: additions to Platform.h from outside the main repository ==== */
 
 #if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/AdditionalPlatform.h>)
 #include <WebKitAdditions/AdditionalPlatform.h>
@@ -69,6 +78,8 @@
 #endif
 
 
+#undef WTF_PLATFORM_GUARD_AGAINST_INDIRECT_INCLUSION
+
 
 /* FIXME: The following are currenly positioned at the bottom of this file as they either
    are currently dependent on macros they should not be and need to be refined or do not
@@ -78,7 +89,7 @@
 
 /* FIXME: Rename WTF_CPU_EFFECTIVE_ADDRESS_WIDTH to WTF_OS_EFFECTIVE_ADDRESS_WIDTH, as it is an OS feature, not a CPU feature. */
 #if CPU(ADDRESS64)
-#if OS(DARWIN) && CPU(ARM64)
+#if (OS(IOS) || OS(TVOS) || OS(WATCHOS)) && CPU(ARM64)
 #define WTF_CPU_EFFECTIVE_ADDRESS_WIDTH 36
 #else
 /* We strongly assume that effective address width is <= 48 in 64bit architectures (e.g. NaN boxing). */
@@ -207,46 +218,3 @@
 #if PLATFORM(COCOA) && ENABLE(ACCESSIBILITY)
 #define USE_ACCESSIBILITY_CONTEXT_MENUS 1
 #endif
-
-
-/* FIXME: These calling convention macros should move to their own file. They are at the bottom currently because they depend on FeatureDefines.h */
-
-#if CPU(X86) && COMPILER(MSVC)
-#define JSC_HOST_CALL __fastcall
-#elif CPU(X86) && COMPILER(GCC_COMPATIBLE)
-#define JSC_HOST_CALL __attribute__ ((fastcall))
-#else
-#define JSC_HOST_CALL
-#endif
-
-#if CPU(X86) && OS(WINDOWS)
-#define CALLING_CONVENTION_IS_STDCALL 1
-#ifndef CDECL
-#if COMPILER(MSVC)
-#define CDECL __cdecl
-#else
-#define CDECL __attribute__ ((__cdecl))
-#endif
-#endif
-#else
-#define CALLING_CONVENTION_IS_STDCALL 0
-#endif
-
-#if CPU(X86)
-#define WTF_COMPILER_SUPPORTS_FASTCALL_CALLING_CONVENTION 1
-#ifndef FASTCALL
-#if COMPILER(MSVC)
-#define FASTCALL __fastcall
-#else
-#define FASTCALL  __attribute__ ((fastcall))
-#endif
-#endif
-#else
-#define WTF_COMPILER_SUPPORTS_FASTCALL_CALLING_CONVENTION 0
-#endif
-
-#if ENABLE(JIT) && CALLING_CONVENTION_IS_STDCALL
-#define JIT_OPERATION CDECL
-#else
-#define JIT_OPERATION
-#endif
diff --git a/Source/WTF/wtf/PlatformCPU.h b/Source/WTF/wtf/PlatformCPU.h
index b32a88a..bce23e0 100644
--- a/Source/WTF/wtf/PlatformCPU.h
+++ b/Source/WTF/wtf/PlatformCPU.h
@@ -25,8 +25,9 @@
 
 #pragma once
 
-/* Include compiler specific macros */
-#include <wtf/Compiler.h>
+#ifndef WTF_PLATFORM_GUARD_AGAINST_INDIRECT_INCLUSION
+#error "Please #include <wtf/Platform.h> instead of this file directly."
+#endif
 
 /* CPU() - the target CPU architecture */
 #define CPU(WTF_FEATURE) (defined WTF_CPU_##WTF_FEATURE  && WTF_CPU_##WTF_FEATURE)
diff --git a/Source/WTF/wtf/PlatformCallingConventions.h b/Source/WTF/wtf/PlatformCallingConventions.h
new file mode 100644
index 0000000..d40c5de
--- /dev/null
+++ b/Source/WTF/wtf/PlatformCallingConventions.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2009 Torch Mobile, Inc.
+ * Copyright (C) 2010, 2011 Research In Motion Limited. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#ifndef WTF_PLATFORM_GUARD_AGAINST_INDIRECT_INCLUSION
+#error "Please #include <wtf/Platform.h> instead of this file directly."
+#endif
+
+/* Macros for specifing specific calling conventions. */
+
+
+#if CPU(X86) && COMPILER(MSVC)
+#define JSC_HOST_CALL __fastcall
+#elif CPU(X86) && COMPILER(GCC_COMPATIBLE)
+#define JSC_HOST_CALL __attribute__ ((fastcall))
+#else
+#define JSC_HOST_CALL
+#endif
+
+#if CPU(X86) && OS(WINDOWS)
+#define CALLING_CONVENTION_IS_STDCALL 1
+#ifndef CDECL
+#if COMPILER(MSVC)
+#define CDECL __cdecl
+#else
+#define CDECL __attribute__ ((__cdecl))
+#endif
+#endif
+#else
+#define CALLING_CONVENTION_IS_STDCALL 0
+#endif
+
+#if CPU(X86)
+#define WTF_COMPILER_SUPPORTS_FASTCALL_CALLING_CONVENTION 1
+#ifndef FASTCALL
+#if COMPILER(MSVC)
+#define FASTCALL __fastcall
+#else
+#define FASTCALL  __attribute__ ((fastcall))
+#endif
+#endif
+#else
+#define WTF_COMPILER_SUPPORTS_FASTCALL_CALLING_CONVENTION 0
+#endif
+
+#if ENABLE(JIT) && CALLING_CONVENTION_IS_STDCALL
+#define JIT_OPERATION CDECL
+#else
+#define JIT_OPERATION
+#endif
diff --git a/Source/WTF/wtf/PlatformEnable.h b/Source/WTF/wtf/PlatformEnable.h
index b462b35..4f307e9 100644
--- a/Source/WTF/wtf/PlatformEnable.h
+++ b/Source/WTF/wtf/PlatformEnable.h
@@ -28,10 +28,11 @@
 
 #pragma once
 
-#ifndef __PLATFORM_INDIRECT__
+#ifndef WTF_PLATFORM_GUARD_AGAINST_INDIRECT_INCLUSION
 #error "Please #include <wtf/Platform.h> instead of this file directly."
 #endif
 
+
 #define ENABLE(WTF_FEATURE) (defined ENABLE_##WTF_FEATURE && ENABLE_##WTF_FEATURE)
 
 /* Use this file to list _all_ ENABLE() macros. Define the macros to be one of the following values:
diff --git a/Source/WTF/wtf/PlatformHave.h b/Source/WTF/wtf/PlatformHave.h
index c0951f4..33f8884 100644
--- a/Source/WTF/wtf/PlatformHave.h
+++ b/Source/WTF/wtf/PlatformHave.h
@@ -27,6 +27,11 @@
 
 #pragma once
 
+#ifndef WTF_PLATFORM_GUARD_AGAINST_INDIRECT_INCLUSION
+#error "Please #include <wtf/Platform.h> instead of this file directly."
+#endif
+
+
 /* HAVE() - specific system features (headers, functions or similar) that are present or not */
 #define HAVE(WTF_FEATURE) (defined HAVE_##WTF_FEATURE && HAVE_##WTF_FEATURE)
 
diff --git a/Source/WTF/wtf/PlatformLegacy.h b/Source/WTF/wtf/PlatformLegacy.h
index 7679b5d..5902afd 100644
--- a/Source/WTF/wtf/PlatformLegacy.h
+++ b/Source/WTF/wtf/PlatformLegacy.h
@@ -27,6 +27,11 @@
 
 #pragma once
 
+#ifndef WTF_PLATFORM_GUARD_AGAINST_INDIRECT_INCLUSION
+#error "Please #include <wtf/Platform.h> instead of this file directly."
+#endif
+
+
 /* PLATFORM() - handles OS, operating environment, graphics API, and
    CPU. This macro will be phased out in favor of platform adaptation
    macros, policy decision macros, and top-level port definitions. */
diff --git a/Source/WTF/wtf/PlatformOS.h b/Source/WTF/wtf/PlatformOS.h
index 4ca18df..28a9101 100644
--- a/Source/WTF/wtf/PlatformOS.h
+++ b/Source/WTF/wtf/PlatformOS.h
@@ -27,8 +27,10 @@
 
 #pragma once
 
-/* Include compiler specific macros */
-#include <wtf/Compiler.h>
+#ifndef WTF_PLATFORM_GUARD_AGAINST_INDIRECT_INCLUSION
+#error "Please #include <wtf/Platform.h> instead of this file directly."
+#endif
+
 
 #if defined(__APPLE__)
 #include <Availability.h>
@@ -65,6 +67,16 @@
 #define WTF_OS_IOS 1
 #endif
 
+/* OS(TVOS) - tvOS */
+#if OS(DARWIN) && TARGET_OS_TV
+#define WTF_OS_TVOS 1
+#endif
+
+/* OS(WATCHOS) - watchOS */
+#if OS(DARWIN) && TARGET_OS_WATCH
+#define WTF_OS_WATCHOS 1
+#endif
+
 /* FIXME: Rename this to drop the X, as that is no longer the name of the operating system. */
 /* OS(MAC_OS_X) - macOS (not including iOS family) */
 #if OS(DARWIN) && TARGET_OS_OSX
diff --git a/Source/WTF/wtf/PlatformUse.h b/Source/WTF/wtf/PlatformUse.h
index 53d39a2..8e0f7e9 100644
--- a/Source/WTF/wtf/PlatformUse.h
+++ b/Source/WTF/wtf/PlatformUse.h
@@ -27,7 +27,7 @@
 
 #pragma once
 
-#ifndef __PLATFORM_INDIRECT__
+#ifndef WTF_PLATFORM_GUARD_AGAINST_INDIRECT_INCLUSION
 #error "Please #include <wtf/Platform.h> instead of this file directly."
 #endif