| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PLATFORM_GLOBALS_H_ | 5 #ifndef PLATFORM_GLOBALS_H_ |
| 6 #define PLATFORM_GLOBALS_H_ | 6 #define PLATFORM_GLOBALS_H_ |
| 7 | 7 |
| 8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to | 8 // __STDC_FORMAT_MACROS has to be defined before including <inttypes.h> to |
| 9 // enable platform independent printf format specifiers. | 9 // enable platform independent printf format specifiers. |
| 10 #ifndef __STDC_FORMAT_MACROS | 10 #ifndef __STDC_FORMAT_MACROS |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // See: http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx for an | 166 // See: http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx for an |
| 167 // explanation of some the cases when a function can never be inlined. | 167 // explanation of some the cases when a function can never be inlined. |
| 168 #ifdef _MSC_VER | 168 #ifdef _MSC_VER |
| 169 #define DART_FORCE_INLINE __forceinline | 169 #define DART_FORCE_INLINE __forceinline |
| 170 #elif __GNUC__ | 170 #elif __GNUC__ |
| 171 #define DART_FORCE_INLINE inline __attribute__((always_inline)) | 171 #define DART_FORCE_INLINE inline __attribute__((always_inline)) |
| 172 #else | 172 #else |
| 173 #error Automatic compiler detection failed. | 173 #error Automatic compiler detection failed. |
| 174 #endif | 174 #endif |
| 175 | 175 |
| 176 // DART_UNUSED inidicates to the compiler that a variable/typedef is expected |
| 177 // to be unused and disables the related warning. |
| 178 #ifdef __GNUC__ |
| 179 #define DART_UNUSED __attribute__((unused)) |
| 180 #else |
| 181 #define DART_UNUSED |
| 182 #endif |
| 183 |
| 176 #if !defined(TARGET_ARCH_MIPS) | 184 #if !defined(TARGET_ARCH_MIPS) |
| 177 #if !defined(TARGET_ARCH_ARM) | 185 #if !defined(TARGET_ARCH_ARM) |
| 178 #if !defined(TARGET_ARCH_X64) | 186 #if !defined(TARGET_ARCH_X64) |
| 179 #if !defined(TARGET_ARCH_IA32) | 187 #if !defined(TARGET_ARCH_IA32) |
| 180 // No target architecture specified pick the one matching the host architecture. | 188 // No target architecture specified pick the one matching the host architecture. |
| 181 #if defined(HOST_ARCH_MIPS) | 189 #if defined(HOST_ARCH_MIPS) |
| 182 #define TARGET_ARCH_MIPS 1 | 190 #define TARGET_ARCH_MIPS 1 |
| 183 #elif defined(HOST_ARCH_ARM) | 191 #elif defined(HOST_ARCH_ARM) |
| 184 #define TARGET_ARCH_ARM 1 | 192 #define TARGET_ARCH_ARM 1 |
| 185 #elif defined(HOST_ARCH_X64) | 193 #elif defined(HOST_ARCH_X64) |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 // There is an additional use for bit_cast. Recent gccs will warn when | 393 // There is an additional use for bit_cast. Recent gccs will warn when |
| 386 // they see casts that may result in breakage due to the type-based | 394 // they see casts that may result in breakage due to the type-based |
| 387 // aliasing rule. If you have checked that there is no breakage you | 395 // aliasing rule. If you have checked that there is no breakage you |
| 388 // can use bit_cast to cast one pointer type to another. This confuses | 396 // can use bit_cast to cast one pointer type to another. This confuses |
| 389 // gcc enough that it can no longer see that you have cast one pointer | 397 // gcc enough that it can no longer see that you have cast one pointer |
| 390 // type to another thus avoiding the warning. | 398 // type to another thus avoiding the warning. |
| 391 template <class D, class S> | 399 template <class D, class S> |
| 392 inline D bit_cast(const S& source) { | 400 inline D bit_cast(const S& source) { |
| 393 // Compile time assertion: sizeof(D) == sizeof(S). A compile error | 401 // Compile time assertion: sizeof(D) == sizeof(S). A compile error |
| 394 // here means your D and S have different sizes. | 402 // here means your D and S have different sizes. |
| 395 typedef char VerifySizesAreEqual[sizeof(D) == sizeof(S) ? 1 : -1]; | 403 DART_UNUSED typedef char VerifySizesAreEqual[sizeof(D) == sizeof(S) ? 1 : -1]; |
| 396 | 404 |
| 397 D destination; | 405 D destination; |
| 398 // This use of memcpy is safe: source and destination cannot overlap. | 406 // This use of memcpy is safe: source and destination cannot overlap. |
| 399 memcpy(&destination, &source, sizeof(destination)); | 407 memcpy(&destination, &source, sizeof(destination)); |
| 400 return destination; | 408 return destination; |
| 401 } | 409 } |
| 402 | 410 |
| 403 | 411 |
| 404 // Similar to bit_cast, but allows copying from types of unrelated | 412 // Similar to bit_cast, but allows copying from types of unrelated |
| 405 // sizes. This method was introduced to enable the strict aliasing | 413 // sizes. This method was introduced to enable the strict aliasing |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 // N.B.: As the GCC manual states, "[s]ince non-static C++ methods | 461 // N.B.: As the GCC manual states, "[s]ince non-static C++ methods |
| 454 // have an implicit 'this' argument, the arguments of such methods | 462 // have an implicit 'this' argument, the arguments of such methods |
| 455 // should be counted from two, not one." | 463 // should be counted from two, not one." |
| 456 #define PRINTF_ATTRIBUTE(string_index, first_to_check) \ | 464 #define PRINTF_ATTRIBUTE(string_index, first_to_check) \ |
| 457 __attribute__((__format__(__printf__, string_index, first_to_check))) | 465 __attribute__((__format__(__printf__, string_index, first_to_check))) |
| 458 #else | 466 #else |
| 459 #define PRINTF_ATTRIBUTE(string_index, first_to_check) | 467 #define PRINTF_ATTRIBUTE(string_index, first_to_check) |
| 460 #endif | 468 #endif |
| 461 | 469 |
| 462 #endif // PLATFORM_GLOBALS_H_ | 470 #endif // PLATFORM_GLOBALS_H_ |
| OLD | NEW |