You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2020 Ian McInerney <ian.s.mcinerney@ieee.org>
  5. * Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  6. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.TXT for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file macros.h
  27. * @brief This file contains miscellaneous commonly used macros and functions.
  28. */
  29. #ifndef MACROS_H
  30. #define MACROS_H
  31. #include <wx/string.h>
  32. #if defined( __has_attribute )
  33. #define KI_HAS_ATTRIBUTE( x ) __has_attribute( x )
  34. #else
  35. #define KI_HAS_ATTRIBUTE( x ) 0
  36. #endif
  37. // Based on the declaration inside the LLVM source code
  38. #if defined( __cplusplus ) && defined( __has_cpp_attribute )
  39. #define KI_HAS_CPP_ATTRIBUTE( x ) __has_cpp_attribute( x )
  40. #else
  41. #define KI_HAS_CPP_ATTRIBUTE( x ) 0
  42. #endif
  43. /**
  44. * The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely
  45. * fallthrough from one to the next. It must be followed by a ";".
  46. *
  47. * Sample code:
  48. * switch( a )
  49. * {
  50. * case 1:
  51. * // Some code
  52. * KI_FALLTHROUGH;
  53. *
  54. * case 2:
  55. * // More code
  56. * break;
  57. * }
  58. */
  59. #if __cplusplus >= 201703L
  60. // C++ 17 includes this macro on all compilers
  61. #define KI_FALLTHROUGH [[fallthrough]]
  62. #elif KI_HAS_CPP_ATTRIBUTE( clang::fallthrough )
  63. // Clang provides this attribute to silence the "-Wimplicit-fallthrough" warning
  64. #define KI_FALLTHROUGH [[clang::fallthrough]]
  65. #elif KI_HAS_CPP_ATTRIBUTE( gnu::fallthrough )
  66. // GNU-specific C++ attribute to silencing the warning
  67. #define KI_FALLTHROUGH [[gnu::fallthrough]]
  68. #elif defined( __GNUC__ ) && __GNUC__ >= 7
  69. // GCC 7+ includes the "-Wimplicit-fallthrough" warning, and this attribute to silence it
  70. #define KI_FALLTHROUGH __attribute__ ((fallthrough))
  71. #else
  72. // In every other case, don't do anything
  73. #define KI_FALLTHROUGH ( ( void ) 0 )
  74. #endif
  75. /**
  76. * Stringifies the given parameter by placing in quotes.
  77. *
  78. * @param cstring STRING (no spaces)
  79. * @return "STRING"
  80. */
  81. #define TO_STR2(x) #x
  82. #define TO_STR(x) TO_STR2(x)
  83. #define UNIMPLEMENTED_FOR( type ) \
  84. wxFAIL_MSG( wxString::Format( wxT( "%s: unimplemented for %s" ), __FUNCTION__, type ) )
  85. #endif // MACROS_H