FIRMessagingDefines.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef FIRMessaging_xcodeproj_FIRMessagingDefines_h
  17. #define FIRMessaging_xcodeproj_FIRMessagingDefines_h
  18. #define _FIRMessaging_VERBOSE_LOGGING 1
  19. // Verbose Logging
  20. #if (_FIRMessaging_VERBOSE_LOGGING)
  21. #define FIRMessaging_DEV_VERBOSE_LOG(...) NSLog(__VA_ARGS__)
  22. #else
  23. #define FIRMessaging_DEV_VERBOSE_LOG(...) do { } while (0)
  24. #endif // FIRMessaging_VERBOSE_LOGGING
  25. // FIRMessaging_FAIL
  26. #ifdef DEBUG
  27. #define FIRMessaging_FAIL(format, ...) \
  28. do { \
  29. NSLog(format, ##__VA_ARGS__); \
  30. __builtin_trap(); \
  31. } while (false)
  32. #else
  33. #define FIRMessaging_FAIL(...) do { } while (0)
  34. #endif
  35. // WEAKIFY & STRONGIFY
  36. // Helper macro.
  37. #define _FIRMessaging_WEAKNAME(VAR) VAR ## _weak_
  38. #define FIRMessaging_WEAKIFY(VAR) __weak __typeof__(VAR) _FIRMessaging_WEAKNAME(VAR) = (VAR);
  39. #define FIRMessaging_STRONGIFY(VAR) \
  40. _Pragma("clang diagnostic push") \
  41. _Pragma("clang diagnostic ignored \"-Wshadow\"") \
  42. __strong __typeof__(VAR) VAR = _FIRMessaging_WEAKNAME(VAR); \
  43. _Pragma("clang diagnostic pop")
  44. // Type Conversions (used for NSInteger etc)
  45. #ifndef _FIRMessaging_L
  46. #define _FIRMessaging_L(v) (long)(v)
  47. #endif
  48. #ifndef _FIRMessaging_UL
  49. #define _FIRMessaging_UL(v) (unsigned long)(v)
  50. #endif
  51. #endif
  52. // Debug Assert
  53. #ifndef _FIRMessagingDevAssert
  54. // we directly invoke the NSAssert handler so we can pass on the varargs
  55. // (NSAssert doesn't have a macro we can use that takes varargs)
  56. #if !defined(NS_BLOCK_ASSERTIONS)
  57. #define _FIRMessagingDevAssert(condition, ...) \
  58. do { \
  59. if (!(condition)) { \
  60. [[NSAssertionHandler currentHandler] \
  61. handleFailureInFunction:(NSString *) \
  62. [NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
  63. file:(NSString *)[NSString stringWithUTF8String:__FILE__] \
  64. lineNumber:__LINE__ \
  65. description:__VA_ARGS__]; \
  66. } \
  67. } while(0)
  68. #else // !defined(NS_BLOCK_ASSERTIONS)
  69. #define _FIRMessagingDevAssert(condition, ...) do { } while (0)
  70. #endif // !defined(NS_BLOCK_ASSERTIONS)
  71. #endif // _FIRMessagingDevAssert
  72. // Invalidates the initializer from which it's called.
  73. #ifndef FIRMessagingInvalidateInitializer
  74. #define FIRMessagingInvalidateInitializer() \
  75. do { \
  76. [self class]; /* Avoid warning of dead store to |self|. */ \
  77. _FIRMessagingDevAssert(NO, @"Invalid initializer."); \
  78. return nil; \
  79. } while (0)
  80. #endif