micro-test-plus 3.2.2
µTest++ Testing Framework
Loading...
Searching...
No Matches
reflection-inlines.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 *
11 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12 * released under the terms of the Boost Version 1.0 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
47
48#ifndef MICRO_TEST_PLUS_REFLECTION_INLINES_H_
49#define MICRO_TEST_PLUS_REFLECTION_INLINES_H_
50
51// ----------------------------------------------------------------------------
52
53#ifdef __cplusplus
54
55// ----------------------------------------------------------------------------
56
57#include <cstdint>
58
59// #include "type-traits.h"
60
61// ----------------------------------------------------------------------------
62
63#if defined(__GNUC__)
64#pragma GCC diagnostic push
65#pragma GCC diagnostic ignored "-Waggregate-return"
66#if defined(__clang__)
67#pragma clang diagnostic ignored "-Wc++98-compat"
68#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
69#endif
70#endif
71
73{
74 // --------------------------------------------------------------------------
75
76 namespace reflection
77 {
78 // ------------------------------------------------------------------------
79
80#if !defined(__cpp_lib_source_location)
81
90 [[nodiscard]] constexpr auto
91 source_location::current (const char* file, unsigned int line) noexcept
92 {
93 source_location sl{};
94 sl.file_ = file;
95 sl.line_ = line;
96 return sl;
97 }
98
103 [[nodiscard]] constexpr auto
104 source_location::file_name (void) const noexcept
105 {
106 return file_;
107 }
108
113 [[nodiscard]] constexpr auto
114 source_location::line (void) const noexcept
115 {
116 return line_;
117 }
118
119#endif
120
131 template <class T>
132 [[nodiscard]] constexpr auto
133 type_name (void) -> std::string_view
134 {
135#if defined(__clang__)
136#pragma GCC diagnostic push
137#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
138 // printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
139 // (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[78]);
140 return { &__PRETTY_FUNCTION__[78], sizeof (__PRETTY_FUNCTION__) - 80 };
141#pragma GCC diagnostic pop
142#elif defined(__GNUC__)
143 // printf("|%s|%zu|\n", __PRETTY_FUNCTION__, sizeof
144 // (__PRETTY_FUNCTION__)); printf("|%s|\n", &__PRETTY_FUNCTION__[93]);
145 return { &__PRETTY_FUNCTION__[93], sizeof (__PRETTY_FUNCTION__) - 144 };
146#else
147#error "Unsupported compiler"
148 return "Unsupported compiler";
149#endif
150 }
151
152 // ------------------------------------------------------------------------
153 } // namespace reflection
154
155 // --------------------------------------------------------------------------
156} // namespace micro_os_plus::micro_test_plus
157
158#if defined(__GNUC__)
159#pragma GCC diagnostic pop
160#endif
161
162// ----------------------------------------------------------------------------
163
164#endif // __cplusplus
165
166// ----------------------------------------------------------------------------
167
168#endif // MICRO_TEST_PLUS_REFLECTION_INLINES_H_
169
170// ----------------------------------------------------------------------------
Local implementation of source location information for diagnostics.
Definition reflection.h:137
unsigned int line_
The line number where the source location was captured.
Definition reflection.h:185
constexpr auto file_name(void) const noexcept
Retrieve the file name associated with this source location.
constexpr auto line(void) const noexcept
Retrieve the line number associated with this source location.
static constexpr auto current(const char *file="unknown", unsigned int line={}) noexcept
Obtain the current source location.
const char * file_
The file name where the source location was captured.
Definition reflection.h:180
Reflection utilities for the µTest++ testing framework.
constexpr auto type_name(void) -> std::string_view
Extract the type name from the __PRETTY_FUNCTION__ macro.
Primary namespace for the µTest++ testing framework.