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.

88 lines
2.6KB

  1. // <experimental/source_location> -*- C++ -*-
  2. // Copyright (C) 2015-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file experimental/source_location
  21. * This is a TS C++ Library header.
  22. * @ingroup libfund-ts
  23. */
  24. #ifndef _GLIBCXX_EXPERIMENTAL_SRCLOC
  25. #define _GLIBCXX_EXPERIMENTAL_SRCLOC 1
  26. #include <cstdint>
  27. namespace std {
  28. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  29. namespace experimental {
  30. inline namespace fundamentals_v2 {
  31. #define __cpp_lib_experimental_source_location 201505
  32. struct source_location
  33. {
  34. #ifndef _GLIBCXX_USE_C99_STDINT_TR1
  35. private:
  36. using uint_least32_t = unsigned;
  37. public:
  38. #endif
  39. // 14.1.2, source_location creation
  40. static constexpr source_location
  41. current(const char* __file = __builtin_FILE(),
  42. const char* __func = __builtin_FUNCTION(),
  43. int __line = __builtin_LINE(),
  44. int __col = 0) noexcept
  45. {
  46. source_location __loc;
  47. __loc._M_file = __file;
  48. __loc._M_func = __func;
  49. __loc._M_line = __line;
  50. __loc._M_col = __col;
  51. return __loc;
  52. }
  53. constexpr source_location() noexcept
  54. : _M_file("unknown"), _M_func(_M_file), _M_line(0), _M_col(0)
  55. { }
  56. // 14.1.3, source_location field access
  57. constexpr uint_least32_t line() const noexcept { return _M_line; }
  58. constexpr uint_least32_t column() const noexcept { return _M_col; }
  59. constexpr const char* file_name() const noexcept { return _M_file; }
  60. constexpr const char* function_name() const noexcept { return _M_func; }
  61. private:
  62. const char* _M_file;
  63. const char* _M_func;
  64. uint_least32_t _M_line;
  65. uint_least32_t _M_col;
  66. };
  67. } // namespace fundamentals_v2
  68. } // namespace experimental
  69. _GLIBCXX_END_NAMESPACE_VERSION
  70. } // namespace std
  71. #endif