Commit 7a2c253e authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Move OS/compiler/feature detection to public v8config.h header.

From now on the v8config.h header should be the one and
only file where we do (freaky) checks to detect OS, C++
compiler or certain compiler features. Since we need that
both internally and for the public API, the new v8config.h
is the proper place to add (everything is prefixed with V8_
so we are safe).

R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/23248006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16281 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent be48c5ae
......@@ -43,7 +43,7 @@
// We reserve the V8_* prefix for macros defined in V8 public API and
// assume there are no name conflicts with the embedder's code.
#ifdef _WIN32
#ifdef V8_OS_WIN
// Setup for Windows DLL export/import. When building the V8 DLL the
// BUILDING_V8_SHARED needs to be defined. When building a program which uses
......@@ -56,52 +56,27 @@
#endif
#ifdef BUILDING_V8_SHARED
#define V8_EXPORT __declspec(dllexport)
# define V8_EXPORT __declspec(dllexport)
#elif USING_V8_SHARED
#define V8_EXPORT __declspec(dllimport)
# define V8_EXPORT __declspec(dllimport)
#else
#define V8_EXPORT
# define V8_EXPORT
#endif // BUILDING_V8_SHARED
#else // _WIN32
#else // V8_OS_WIN
// Setup for Linux shared library export.
#if defined(__GNUC__) && ((__GNUC__ >= 4) || \
(__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(V8_SHARED)
#ifdef BUILDING_V8_SHARED
#define V8_EXPORT __attribute__ ((visibility("default")))
#else
#define V8_EXPORT
#endif
#else
#define V8_EXPORT
#endif
#endif // _WIN32
#if defined(__GNUC__) && !defined(DEBUG)
#define V8_INLINE(declarator) inline __attribute__((always_inline)) declarator
#elif defined(_MSC_VER) && !defined(DEBUG)
#define V8_INLINE(declarator) __forceinline declarator
#else
#define V8_INLINE(declarator) inline declarator
#endif
#if defined(__GNUC__) && !V8_DISABLE_DEPRECATIONS
#define V8_DEPRECATED(declarator) declarator __attribute__ ((deprecated))
#elif defined(_MSC_VER) && !V8_DISABLE_DEPRECATIONS
#define V8_DEPRECATED(declarator) __declspec(deprecated) declarator
#if V8_HAS_ATTRIBUTE_VISIBILITY && defined(V8_SHARED)
# ifdef BUILDING_V8_SHARED
# define V8_EXPORT __attribute__ ((visibility("default")))
# else
# define V8_EXPORT
# endif
#else
#define V8_DEPRECATED(declarator) declarator
# define V8_EXPORT
#endif
#if __GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))
#define V8_UNLIKELY(condition) __builtin_expect((condition), 0)
#define V8_LIKELY(condition) __builtin_expect((condition), 1)
#else
#define V8_UNLIKELY(condition) (condition)
#define V8_LIKELY(condition) (condition)
#endif
#endif // V8_OS_WIN
/**
* The v8 JavaScript engine.
......
This diff is collapsed.
......@@ -33,7 +33,9 @@
#include <stddef.h>
#include <stdio.h>
#if defined(_WIN32) && !defined(__MINGW32__)
#include "v8config.h"
#if V8_OS_WIN && !V8_CC_MINGW
typedef signed char int8_t;
typedef unsigned char uint8_t;
......@@ -47,7 +49,7 @@ typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#include <stdint.h> // NOLINT
#endif
......
......@@ -30,7 +30,7 @@
#include <string.h>
#include "globals.h"
#include "../include/v8stdint.h"
extern "C" void V8_Fatal(const char* file, int line, const char* format, ...);
......@@ -233,7 +233,7 @@ inline void CheckNonEqualsHelper(const char* file,
// Use C++11 static_assert if possible, which gives error
// messages that are easier to understand on first sight.
#if defined(V8_HAVE_CXX11_STATIC_ASSERT)
#if V8_HAS_CXX11_STATIC_ASSERT
#define STATIC_CHECK(test) static_assert(test, #test)
#else
// This is inspired by the static assertion facility in boost. This
......
......@@ -28,93 +28,27 @@
#ifndef V8_GLOBALS_H_
#define V8_GLOBALS_H_
#include "../include/v8stdint.h"
// Compiler feature/bug detection.
#if defined(__clang__)
// Don't treat clang as GCC.
# define V8_GNUC_PREREQ(major, minor, patchlevel) 0
# if __has_feature(cxx_deleted_functions)
# define V8_HAVE_CXX11_DELETE
# endif
# if __has_feature(cxx_override_control)
# define V8_HAVE_CXX11_FINAL
# define V8_HAVE_CXX11_OVERRIDE
# endif
# if __has_feature(cxx_static_assert)
# define V8_HAVE_CXX11_STATIC_ASSERT
# endif
# define V8_INFINITY INFINITY
#elif defined(__GNUC__)
// GCC version detection.
# define V8_GNUC_PREREQ(major, minor, patchlevel) \
((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \
((major) * 10000 + (minor) * 100 + (patchlevel)))
// g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality
// without warnings (functionality used by the macros below). These modes
// are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or,
// more standardly, by checking whether __cplusplus has a C++11 or greater
// value. Current versions of g++ do not correctly set __cplusplus, so we check
// both for forward compatibility.
# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
# if V8_GNUC_PREREQ(4, 3, 0)
# define V8_HAVE_CXX11_STATIC_ASSERT
# endif
# if V8_GNUC_PREREQ(4, 4, 0)
# define V8_HAVE_CXX11_DELETE
# endif
# if V8_GNUC_PREREQ(4, 7, 0)
# define V8_HAVE_CXX11_OVERRIDE
# define V8_HAVE_CXX11_FINAL
# endif
# else
// '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655.
# if V8_GNUC_PREREQ(4, 7, 0)
# define V8_HAVE_GXX_FINAL
# endif
# endif
// Find a working V8_INFINITY.
#if V8_CC_GNU
// Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
// warning flag and certain versions of GCC due to a bug:
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
// For now, we use the more involved template-based version from <limits>, but
// only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
# if V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0)
# include <limits>
# include <limits> // NOLINT
# define V8_INFINITY std::numeric_limits<double>::infinity()
# else
# define V8_INFINITY INFINITY
# endif
#elif defined(_MSC_VER)
# define V8_GNUC_PREREQ(major, minor, patchlevel) 0
// Override control was added with Visual Studio 2005.
# if _MSC_VER >= 1400
# if _MSC_VER >= 1700
# define V8_HAVE_CXX11_FINAL
# else
// Visual Studio 2010 and earlier spell "final" as "sealed".
# define V8_HAVE_MSVC_SEALED
# endif
# define V8_HAVE_CXX11_OVERRIDE
# endif
#elif V8_CC_MSVC
# define V8_INFINITY HUGE_VAL
#else
# define V8_INFINITY INFINITY
#endif
#include "../include/v8stdint.h"
namespace v8 {
namespace internal {
......@@ -386,53 +320,6 @@ F FUNCTION_CAST(Address addr) {
}
// A macro to specify that a method is deleted from the corresponding class.
// Any attempt to use the method will always produce an error at compile time
// when this macro can be implemented (i.e. if the compiler supports C++11).
// If the current compiler does not support C++11, use of the annotated method
// will still cause an error, but the error will most likely occur at link time
// rather than at compile time. As a backstop, method declarations using this
// macro should be private.
// Use like:
// class A {
// private:
// A(const A& other) V8_DELETE;
// A& operator=(const A& other) V8_DELETE;
// };
#if defined(V8_HAVE_CXX11_DELETE)
# define V8_DELETE = delete
#else
# define V8_DELETE /* NOT SUPPORTED */
#endif
// Annotate a virtual method indicating it must be overriding a virtual
// method in the parent class.
// Use like:
// virtual void bar() V8_OVERRIDE;
#if defined(V8_HAVE_CXX11_OVERRIDE)
# define V8_OVERRIDE override
#else
# define V8_OVERRIDE /* NOT SUPPORTED */
#endif
// Annotate a virtual method indicating that subclasses must not override it,
// or annotate a class to indicate that it cannot be subclassed.
// Use like:
// class B V8_FINAL : public A {};
// virtual void bar() V8_FINAL;
#if defined(V8_HAVE_CXX11_FINAL)
# define V8_FINAL final
#elif defined(V8_HAVE_GXX_FINAL)
# define V8_FINAL __final
#elif defined(V8_HAVE_MSVC_SEALED)
# define V8_FINAL sealed
#else
# define V8_FINAL /* NOT SUPPORTED */
#endif
// A macro to disallow the evil copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment