Embedded Template Library 1.0
platform.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2016 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_PLATFORM_INCLUDED
32#define ETL_PLATFORM_INCLUDED
33
34//*************************************
35// Enable all limit macros
36// Note: This macro must be defined before the first include of stdint.h
37#if !defined(__STDC_LIMIT_MACROS)
38 #define __STDC_LIMIT_MACROS
39#endif
40
41//*************************************
42// Enable all constant macros
43// Note: This macro must be defined before the first include of stdint.h
44#if !defined(__STDC_CONSTANT_MACROS)
45 #define __STDC_CONSTANT_MACROS
46#endif
47
48#include <stddef.h>
49#include <stdint.h>
50#include <limits.h>
51
52#include "file_error_numbers.h"
53
54//*************************************
55// Include the user's profile definition.
56#if !defined(ETL_NO_PROFILE_HEADER) && defined(__has_include)
57 #if !__has_include("etl_profile.h")
58 #define ETL_NO_PROFILE_HEADER
59 #endif
60#endif
61
62#if !defined(ETL_NO_PROFILE_HEADER)
63 #include "etl_profile.h"
64#endif
65
66// Determine the bit width of the platform.
67#define ETL_PLATFORM_16BIT (UINT16_MAX == UINTPTR_MAX)
68#define ETL_PLATFORM_32BIT (UINT32_MAX == UINTPTR_MAX)
69#define ETL_PLATFORM_64BIT (UINT64_MAX == UINTPTR_MAX)
70
71//*************************************
72// Define debug macros.
73#if (defined(_DEBUG) || defined(DEBUG)) && !defined(ETL_DEBUG)
74 #define ETL_DEBUG
75#endif
76
77#if defined(ETL_DEBUG)
78 #define ETL_IS_DEBUG_BUILD 1
79#else
80 #define ETL_IS_DEBUG_BUILD 0
81#endif
82
83//*************************************
84// Helper macros, so we don't have to use double negatives.
85// The ETL will use the STL, unless ETL_NO_STL is defined.
86// With this macro we can use '#if ETL_USING_STL' instead of '#if !ETL_NO_STL' in the code.
87#if defined(ETL_NO_STL)
88 #define ETL_USING_STL 0
89 #define ETL_NOT_USING_STL 1
90#else
91 #define ETL_USING_STL 1
92 #define ETL_NOT_USING_STL 0
93#endif
94
95//*************************************
96// Helper macros for ETL_STLPORT.
97#if defined(ETL_STLPORT)
98 #define ETL_USING_STLPORT 1
99 #define ETL_NOT_USING_STLPORT 0
100#else
101 #define ETL_USING_STLPORT 0
102 #define ETL_NOT_USING_STLPORT 1
103#endif
104
105//*************************************
106// Some targets do not support 8bit types.
107#if (CHAR_BIT == 8)
108 #define ETL_USING_8BIT_TYPES 1
109 #define ETL_NOT_USING_8BIT_TYPES 0
110#else
111 #define ETL_USING_8BIT_TYPES 0
112 #define ETL_NOT_USING_8BIT_TYPES 1
113#endif
114
115#define ETL_8BIT_SUPPORT (CHAR_BIT == 8) // Deprecated
116
117//*************************************
118// Helper macro for ETL_NO_64BIT_TYPES.
119#if defined(ETL_NO_64BIT_TYPES)
120 #define ETL_USING_64BIT_TYPES 0
121 #define ETL_NOT_USING_64BIT_TYPES 1
122#else
123 #define ETL_USING_64BIT_TYPES 1
124 #define ETL_NOT_USING_64BIT_TYPES 0
125#endif
126
127//*************************************
128// Figure out things about the compiler, if haven't already done so in etl_profile.h
131
132//*************************************
133// See if we can determine the OS we're compiling on, if haven't already done so in etl_profile.h
135
136//*************************************
137// Check WCHAR_MIN and WCHAR_MAX
138#if !defined(WCHAR_MIN)
139 #define WCHAR_MIN 0x0000
140#endif
141
142#if !defined(WCHAR_MAX)
143 #define WCHAR_MAX 0xFFFF
144#endif
145
146//*************************************
147// Option to force string construction from a character pointer to be explicit.
148#if defined(ETL_FORCE_EXPLICIT_STRING_CONVERSION_FROM_CHAR)
149 #define ETL_EXPLICIT_STRING_FROM_CHAR explicit
150#else
151 #define ETL_EXPLICIT_STRING_FROM_CHAR
152#endif
153
154//*************************************
155// Option to disable truncation checks for strings.
156#if defined(ETL_DISABLE_STRING_TRUNCATION_CHECKS)
157 #define ETL_HAS_STRING_TRUNCATION_CHECKS 0
158#else
159 #define ETL_HAS_STRING_TRUNCATION_CHECKS 1
160#endif
161
162//*************************************
163// Option to disable clear-after-use functionality for strings.
164#if defined(ETL_DISABLE_STRING_CLEAR_AFTER_USE)
165 #define ETL_HAS_STRING_CLEAR_AFTER_USE 0
166#else
167 #define ETL_HAS_STRING_CLEAR_AFTER_USE 1
168#endif
169
170//*************************************
171// Option to make string truncation an error.
172#if defined(ETL_ENABLE_ERROR_ON_STRING_TRUNCATION)
173 #define ETL_HAS_ERROR_ON_STRING_TRUNCATION 1
174#else
175 #define ETL_HAS_ERROR_ON_STRING_TRUNCATION 0
176#endif
177
178//*************************************
179// Option to enable repair-after-memcpy for istrings.
180#if defined(ETL_ISTRING_REPAIR_ENABLE)
181 #define ETL_HAS_ISTRING_REPAIR 1
182#else
183 #define ETL_HAS_ISTRING_REPAIR 0
184#endif
185
186//*************************************
187// Option to enable repair-after-memcpy for ivector.
188#if defined(ETL_IVECTOR_REPAIR_ENABLE)
189 #define ETL_HAS_IVECTOR_REPAIR 1
190#else
191 #define ETL_HAS_IVECTOR_REPAIR 0
192#endif
193
194//*************************************
195// Option to enable repair-after-memcpy for ideque.
196#if defined(ETL_IDEQUE_REPAIR_ENABLE)
197 #define ETL_HAS_IDEQUE_REPAIR 1
198#else
199 #define ETL_HAS_IDEQUE_REPAIR 0
200#endif
201
202//*************************************
203// Indicate if C++ exceptions are enabled.
204#if defined(ETL_THROW_EXCEPTIONS)
205 #define ETL_USING_EXCEPTIONS 1
206#else
207 #define ETL_USING_EXCEPTIONS 0
208#endif
209
210//*************************************
211// Indicate if nullptr is used.
212#if ETL_NO_NULLPTR_SUPPORT
213 #define ETL_HAS_NULLPTR 0
214#else
215 #define ETL_HAS_NULLPTR 1
216#endif
217
218//*************************************
219// Indicate if legacy bitset is used.
220#if defined(ETL_USE_LEGACY_BITSET)
221 #define ETL_USING_LEGACY_BITSET 1
222#else
223 #define ETL_USING_LEGACY_BITSET 0
224#endif
225
226//*************************************
227// Indicate if array_view is mutable.
228#if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
229 #define ETL_HAS_MUTABLE_ARRAY_VIEW 1
230#else
231 #define ETL_HAS_MUTABLE_ARRAY_VIEW 0
232#endif
233
234//*************************************
235// The macros below are dependent on the profile.
236// C++11
237#if ETL_USING_CPP11 && !defined(ETL_FORCE_NO_ADVANCED_CPP)
238 #define ETL_CONSTEXPR constexpr
239 #define ETL_CONSTEXPR11 constexpr // Synonym for ETL_CONSTEXPR
240 #define ETL_CONSTANT constexpr
241 #define ETL_STATIC_CONSTANT constexpr
242 #define ETL_DELETE = delete
243 #define ETL_EXPLICIT explicit
244 #define ETL_OVERRIDE override
245 #define ETL_FINAL final
246 #define ETL_NORETURN [[noreturn]]
247 #define ETL_MOVE(x) etl::move(x)
248 #define ETL_ENUM_CLASS(name) enum class name
249 #define ETL_ENUM_CLASS_TYPE(name, type) enum class name : type
250 #define ETL_LVALUE_REF_QUALIFIER &
251
252 #if ETL_USING_EXCEPTIONS
253 #define ETL_NOEXCEPT noexcept
254 #define ETL_NOEXCEPT_EXPR(...) noexcept(__VA_ARGS__)
255 #else
256 #define ETL_NOEXCEPT
257 #define ETL_NOEXCEPT_EXPR(...)
258 #endif
259#else
260 #define ETL_CONSTEXPR
261 #define ETL_CONSTEXPR11
262 #define ETL_CONSTANT const
263 #define ETL_STATIC_CONSTANT static const
264 #define ETL_DELETE
265 #define ETL_EXPLICIT
266 #define ETL_OVERRIDE
267 #define ETL_FINAL
268 #define ETL_NORETURN
269 #define ETL_NOEXCEPT
270 #define ETL_NOEXCEPT_EXPR(...)
271 #define ETL_MOVE(x) x
272 #define ETL_ENUM_CLASS(name) enum name
273 #define ETL_ENUM_CLASS_TYPE(name, type) enum name
274 #define ETL_LVALUE_REF_QUALIFIER
275#endif
276
277//*************************************
278// C++14
279#if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP)
280 #define ETL_CONSTEXPR14 constexpr
281 #define ETL_DEPRECATED [[deprecated]]
282 #define ETL_DEPRECATED_REASON(reason) [[deprecated(reason)]]
283#else
284 #define ETL_CONSTEXPR14
285 #define ETL_DEPRECATED
286 #define ETL_DEPRECATED_REASON(reason)
287#endif
288
289//*************************************
290// C++17
291#if ETL_USING_CPP17 && !defined(ETL_FORCE_NO_ADVANCED_CPP)
292 #define ETL_CONSTEXPR17 constexpr
293 #define ETL_IF_CONSTEXPR constexpr
294 #define ETL_NODISCARD [[nodiscard]]
295 #define ETL_MAYBE_UNUSED [[maybe_unused]]
296 #define ETL_FALLTHROUGH [[fallthrough]]
297 #define ETL_INLINE_VAR inline
298#else
299 #define ETL_CONSTEXPR17
300 #define ETL_IF_CONSTEXPR
301 #define ETL_NODISCARD
302 #define ETL_MAYBE_UNUSED
303 #define ETL_FALLTHROUGH
304 #define ETL_INLINE_VAR
305#endif
306
307//*************************************
308// C++20
309#if ETL_USING_CPP20 && !defined(ETL_FORCE_NO_ADVANCED_CPP)
310 #define ETL_LIKELY [[likely]]
311 #define ETL_UNLIKELY [[unlikely]]
312 #define ETL_CONSTEXPR20 constexpr
313 #define ETL_CONSTEVAL consteval
314 #define ETL_CONSTINIT constinit
315 #define ETL_NO_UNIQUE_ADDRESS [[no_unique_address]]
316 #define ETL_EXPLICIT_EXPR(...) explicit(__VA_ARGS__)
317#else
318 #define ETL_LIKELY
319 #define ETL_UNLIKELY
320 #define ETL_CONSTEXPR20
321 #define ETL_CONSTEVAL
322 #define ETL_CONSTINIT
323 #define ETL_NO_UNIQUE_ADDRESS
324 #define ETL_EXPLICIT_EXPR(...) explicit
325#endif
326
327#if ETL_USING_CPP20 && ETL_USING_STL
328 #define ETL_CONSTEXPR20_STL constexpr
329#else
330 #define ETL_CONSTEXPR20_STL
331#endif
332
333//*************************************
334// Determine if the ETL can use char8_t type.
335#if ETL_USING_8BIT_TYPES
336 #if ETL_NO_SMALL_CHAR_SUPPORT
337 typedef int8_t char8_t;
338 #define ETL_HAS_CHAR8_T 1
339 #define ETL_HAS_NATIVE_CHAR8_T 0
340 #else
341 #define ETL_HAS_CHAR8_T 1
342 #define ETL_HAS_NATIVE_CHAR8_T 1
343 #endif
344#else
345 #define ETL_HAS_CHAR8_T 0
346 #define ETL_HAS_NATIVE_CHAR8_T 0
347#endif
348
349//*************************************
350// Define the large character types if necessary.
351#if ETL_NO_LARGE_CHAR_SUPPORT
352 typedef int16_t char16_t;
353 typedef int32_t char32_t;
354 #define ETL_HAS_NATIVE_CHAR16_T 0
355 #define ETL_HAS_NATIVE_CHAR32_T 0
356#else
357 #define ETL_HAS_NATIVE_CHAR16_T 1
358 #define ETL_HAS_NATIVE_CHAR32_T 1
359#endif
360
361//*************************************
362// Determine if the ETL can use std::array
363#if !defined(ETL_HAS_STD_ARRAY)
364 #if ETL_USING_STL && ETL_USING_CPP11
365 #define ETL_HAS_STD_ARRAY 1
366 #else
367 #define ETL_HAS_STD_ARRAY 0
368 #endif
369#endif
370
371//*************************************
372// Determine if the ETL should support atomics.
373#if defined(ETL_NO_ATOMICS) || \
374 defined(ETL_TARGET_DEVICE_ARM_CORTEX_M0) || \
375 defined(ETL_TARGET_DEVICE_ARM_CORTEX_M0_PLUS) || \
376 defined(__STDC_NO_ATOMICS__)
377 #define ETL_HAS_ATOMIC 0
378#else
379 #if ((ETL_USING_CPP11 && (ETL_USING_STL || defined(ETL_IN_UNIT_TEST))) || \
380 defined(ETL_COMPILER_ARM5) || \
381 defined(ETL_COMPILER_ARM6) || \
382 defined(ETL_COMPILER_GCC) || \
383 defined(ETL_COMPILER_CLANG))
384 #define ETL_HAS_ATOMIC 1
385 #else
386 #define ETL_HAS_ATOMIC 0
387 #endif
388#endif
389
390//*************************************
391// Determine if the ETL should use std::initializer_list.
392#if (defined(ETL_FORCE_ETL_INITIALIZER_LIST) && defined(ETL_FORCE_STD_INITIALIZER_LIST))
393 #error ETL_FORCE_ETL_INITIALIZER_LIST and ETL_FORCE_STD_INITIALIZER_LIST both been defined. Choose one or neither.
394#endif
395
396#if (ETL_USING_CPP11 && !defined(ETL_NO_INITIALIZER_LIST))
397 // Use the compiler's std::initializer_list?
398 #if (ETL_USING_STL && ETL_NOT_USING_STLPORT && !defined(ETL_FORCE_ETL_INITIALIZER_LIST)) || defined(ETL_IN_UNIT_TEST) || defined(ETL_FORCE_STD_INITIALIZER_LIST)
399 #define ETL_HAS_INITIALIZER_LIST 1
400 #else
401 // Use the ETL's compatible version?
402 #if defined(ETL_COMPILER_MICROSOFT) || defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_CLANG) || \
403 defined(ETL_COMPILER_ARM6) || defined(ETL_COMPILER_ARM7) || defined(ETL_COMPILER_IAR) || \
404 defined(ETL_COMPILER_TEXAS_INSTRUMENTS) || defined(ETL_COMPILER_INTEL)
405 #define ETL_HAS_INITIALIZER_LIST 1
406 #else
407 #define ETL_HAS_INITIALIZER_LIST 0
408 #endif
409 #endif
410#else
411 #define ETL_HAS_INITIALIZER_LIST 0
412#endif
413
414//*************************************
415// Check for availability of certain builtins
417
418//*************************************
419// Sort out namespaces for STL/No STL options.
421
422namespace etl
423{
424 namespace traits
425 {
426 // Documentation: https://www.etlcpp.com/etl_traits.html
427 // General
428 static ETL_CONSTANT long cplusplus = __cplusplus;
429 static ETL_CONSTANT int language_standard = ETL_LANGUAGE_STANDARD;
430
431 // Using...
432 static ETL_CONSTANT bool using_stl = (ETL_USING_STL == 1);
433 static ETL_CONSTANT bool using_stlport = (ETL_USING_STLPORT == 1);
434 static ETL_CONSTANT bool using_cpp11 = (ETL_USING_CPP11 == 1);
435 static ETL_CONSTANT bool using_cpp14 = (ETL_USING_CPP14 == 1);
436 static ETL_CONSTANT bool using_cpp17 = (ETL_USING_CPP17 == 1);
437 static ETL_CONSTANT bool using_cpp20 = (ETL_USING_CPP20 == 1);
438 static ETL_CONSTANT bool using_cpp23 = (ETL_USING_CPP23 == 1);
439 static ETL_CONSTANT bool using_gcc_compiler = (ETL_USING_GCC_COMPILER == 1);
440 static ETL_CONSTANT bool using_microsoft_compiler = (ETL_USING_MICROSOFT_COMPILER == 1);
441 static ETL_CONSTANT bool using_arm5_compiler = (ETL_USING_ARM5_COMPILER == 1);
442 static ETL_CONSTANT bool using_arm6_compiler = (ETL_USING_ARM6_COMPILER == 1);
443 static ETL_CONSTANT bool using_arm7_compiler = (ETL_USING_ARM7_COMPILER == 1);
444 static ETL_CONSTANT bool using_clang_compiler = (ETL_USING_CLANG_COMPILER == 1);
445 static ETL_CONSTANT bool using_green_hills_compiler = (ETL_USING_GREEN_HILLS_COMPILER == 1);
446 static ETL_CONSTANT bool using_iar_compiler = (ETL_USING_IAR_COMPILER == 1);
447 static ETL_CONSTANT bool using_intel_compiler = (ETL_USING_INTEL_COMPILER == 1);
448 static ETL_CONSTANT bool using_texas_instruments_compiler = (ETL_USING_TEXAS_INSTRUMENTS_COMPILER == 1);
449 static ETL_CONSTANT bool using_generic_compiler = (ETL_USING_GENERIC_COMPILER == 1);
450 static ETL_CONSTANT bool using_legacy_bitset = (ETL_USING_LEGACY_BITSET == 1);
451 static ETL_CONSTANT bool using_exceptions = (ETL_USING_EXCEPTIONS == 1);
452
453 // Has...
454 static ETL_CONSTANT bool has_initializer_list = (ETL_HAS_INITIALIZER_LIST == 1);
455 static ETL_CONSTANT bool has_8bit_types = (ETL_USING_8BIT_TYPES == 1);
456 static ETL_CONSTANT bool has_64bit_types = (ETL_USING_64BIT_TYPES == 1);
457 static ETL_CONSTANT bool has_atomic = (ETL_HAS_ATOMIC == 1);
458 static ETL_CONSTANT bool has_nullptr = (ETL_HAS_NULLPTR == 1);
459 static ETL_CONSTANT bool has_char8_t = (ETL_HAS_CHAR8_T == 1);
460 static ETL_CONSTANT bool has_native_char8_t = (ETL_HAS_NATIVE_CHAR8_T == 1);
461 static ETL_CONSTANT bool has_native_char16_t = (ETL_HAS_NATIVE_CHAR16_T == 1);
462 static ETL_CONSTANT bool has_native_char32_t = (ETL_HAS_NATIVE_CHAR32_T == 1);
463 static ETL_CONSTANT bool has_string_truncation_checks = (ETL_HAS_STRING_TRUNCATION_CHECKS == 1);
464 static ETL_CONSTANT bool has_error_on_string_truncation = (ETL_HAS_ERROR_ON_STRING_TRUNCATION == 1);
465 static ETL_CONSTANT bool has_string_clear_after_use = (ETL_HAS_STRING_CLEAR_AFTER_USE == 1);
466 static ETL_CONSTANT bool has_istring_repair = (ETL_HAS_ISTRING_REPAIR == 1);
467 static ETL_CONSTANT bool has_ivector_repair = (ETL_HAS_IVECTOR_REPAIR == 1);
468 static ETL_CONSTANT bool has_mutable_array_view = (ETL_HAS_MUTABLE_ARRAY_VIEW == 1);
469 static ETL_CONSTANT bool has_ideque_repair = (ETL_HAS_IDEQUE_REPAIR == 1);
470
471 // Is...
472 static ETL_CONSTANT bool is_debug_build = (ETL_IS_DEBUG_BUILD == 1);
473
474 }
475}
476
477#endif
bitset_ext
Definition: absolute.h:38