Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/pcre2/src/pcre2_util.h
21681 views
1
/*************************************************
2
* Perl-Compatible Regular Expressions *
3
*************************************************/
4
5
/* PCRE2 is a library of functions to support regular expressions whose syntax
6
and semantics are as close as possible to those of the Perl 5 language.
7
8
Written by Philip Hazel
9
Original API code Copyright (c) 1997-2012 University of Cambridge
10
New API code Copyright (c) 2016-2024 University of Cambridge
11
12
-----------------------------------------------------------------------------
13
Redistribution and use in source and binary forms, with or without
14
modification, are permitted provided that the following conditions are met:
15
16
* Redistributions of source code must retain the above copyright notice,
17
this list of conditions and the following disclaimer.
18
19
* Redistributions in binary form must reproduce the above copyright
20
notice, this list of conditions and the following disclaimer in the
21
documentation and/or other materials provided with the distribution.
22
23
* Neither the name of the University of Cambridge nor the names of its
24
contributors may be used to endorse or promote products derived from
25
this software without specific prior written permission.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
POSSIBILITY OF SUCH DAMAGE.
38
-----------------------------------------------------------------------------
39
*/
40
41
#ifndef PCRE2_UTIL_H_IDEMPOTENT_GUARD
42
#define PCRE2_UTIL_H_IDEMPOTENT_GUARD
43
44
/* Assertion macros */
45
46
#ifdef PCRE2_DEBUG
47
48
#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)
49
#include <assert.h>
50
#endif
51
52
/* PCRE2_ASSERT(x) can be used to inject an assert() for conditions
53
that the code below doesn't support. It is a NOP for non debug builds
54
but in debug builds will print information about the location of the
55
code where it triggered and crash.
56
57
It is meant to work like assert(), and therefore the expression used
58
should indicate what the expected state is, and shouldn't have any
59
side-effects. */
60
61
#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)
62
#define PCRE2_ASSERT(x) assert(x)
63
#else
64
#define PCRE2_ASSERT(x) do \
65
{ \
66
if (!(x)) \
67
{ \
68
fprintf(stderr, "Assertion failed at " __FILE__ ":%d\n", __LINE__); \
69
abort(); \
70
} \
71
} while(0)
72
#endif
73
74
/* LCOV_EXCL_START */
75
76
/* PCRE2_UNREACHABLE() can be used to mark locations on the code that
77
shouldn't be reached. In non debug builds is defined as a hint for
78
the compiler to eliminate any code after it, so it is useful also for
79
performance reasons, but should be used with care because if it is
80
ever reached will trigger Undefined Behaviour and if you are lucky a
81
crash. In debug builds it will report the location where it was triggered
82
and crash. One important point to consider when using this macro, is
83
that it is only implemented for a few compilers, and therefore can't
84
be relied on to always be active either, so if it is followed by some
85
code it is important to make sure that the whole thing is safe to
86
use even if the macro is not there (ex: make sure there is a `break`
87
after it if used at the end of a `case`) and to test your code also
88
with a configuration where the macro will be a NOP. */
89
90
#if defined(HAVE_ASSERT_H) && !defined(NDEBUG)
91
#define PCRE2_UNREACHABLE() \
92
assert(((void)"Execution reached unexpected point", 0))
93
#else
94
#define PCRE2_UNREACHABLE() do \
95
{ \
96
fprintf(stderr, "Execution reached unexpected point at " __FILE__ \
97
":%d\n", __LINE__); \
98
abort(); \
99
} while(0)
100
#endif
101
102
/* PCRE2_DEBUG_UNREACHABLE() is a debug only version of the previous
103
macro. It is meant to be used in places where the code is handling
104
an error situation in code that shouldn't be reached, but that has
105
some sort of fallback code to normally handle the error. When in
106
doubt you should use this instead of the previous macro. Like in
107
the previous case, it is a good idea to document as much as possible
108
the reason and the actions that should be taken if it ever triggers. */
109
110
#define PCRE2_DEBUG_UNREACHABLE() PCRE2_UNREACHABLE()
111
112
/* LCOV_EXCL_STOP */
113
114
#endif /* PCRE2_DEBUG */
115
116
#ifndef PCRE2_ASSERT
117
#define PCRE2_ASSERT(x) do {} while(0)
118
#endif
119
120
/* LCOV_EXCL_START */
121
122
#ifndef PCRE2_DEBUG_UNREACHABLE
123
#define PCRE2_DEBUG_UNREACHABLE() do {} while(0)
124
#endif
125
126
#ifndef PCRE2_UNREACHABLE
127
#ifdef HAVE_BUILTIN_UNREACHABLE
128
#define PCRE2_UNREACHABLE() __builtin_unreachable()
129
#elif defined(HAVE_BUILTIN_ASSUME)
130
#define PCRE2_UNREACHABLE() __assume(0)
131
#else
132
#define PCRE2_UNREACHABLE() do {} while(0)
133
#endif
134
#endif /* !PCRE2_UNREACHABLE */
135
136
/* LCOV_EXCL_STOP */
137
138
/* We define this fallthrough macro for suppressing -Wimplicit-fallthrough warnings.
139
Clang only allows this via an attribute, whereas other compilers (eg. GCC) match attributes
140
and also specially-formatted comments.
141
142
This macro should be used with no following semicolon, and ideally with a comment: */
143
144
// PCRE2_FALLTHROUGH /* Fall through */
145
146
#ifndef PCRE2_FALLTHROUGH
147
148
#if defined(__cplusplus) && __cplusplus >= 202002L && \
149
defined(__has_cpp_attribute)
150
/* Standards-compatible C++ variant. */
151
#if __has_cpp_attribute(fallthrough)
152
#define PCRE2_FALLTHROUGH [[fallthrough]];
153
#endif
154
#elif !defined(__cplusplus) && \
155
defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L && \
156
defined(__has_c_attribute)
157
/* Standards-compatible C variant. */
158
#if __has_c_attribute(fallthrough)
159
#define PCRE2_FALLTHROUGH [[fallthrough]];
160
#endif
161
#elif ((defined(__clang__) && __clang_major__ >= 10) || \
162
(defined(__GNUC__) && __GNUC__ >= 7)) && \
163
defined(__has_attribute)
164
/* Clang and GCC syntax. Rule out old versions because apparently Clang at
165
least has a broken implementation of __has_attribute. */
166
#if __has_attribute(fallthrough)
167
#define PCRE2_FALLTHROUGH __attribute__((fallthrough));
168
#endif
169
#endif
170
171
#endif /* !PCRE2_FALLTHROUGH */
172
173
#ifndef PCRE2_FALLTHROUGH
174
#define PCRE2_FALLTHROUGH
175
#endif
176
177
#endif /* PCRE2_UTIL_H_IDEMPOTENT_GUARD */
178
179
/* End of pcre2_util.h */
180
181