spot 2.3

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
common.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2013, 2014, 2015, 2016 Laboratoire de Recherche et
3 // Développement de l'Epita (LRDE).
4 //
5 // This file is part of Spot, a model checking library.
6 //
7 // Spot is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Spot is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 #include <cstdlib>
21 #include <stdexcept>
22 #include <cassert>
23
24 #pragma once
25
26 #ifdef __GNUC__
27 #define SPOT_LIKELY(expr) __builtin_expect(!!(expr), 1)
28 #define SPOT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
29 #else
30 #define SPOT_LIKELY(expr) (expr)
31 #define SPOT_UNLIKELY(expr) (expr)
32 #endif
33
34 #ifdef __has_cpp_attribute
35 # if __has_cpp_attribute(deprecated)
36 # define SPOT_DEPRECATED [[deprecated]]
37 # endif
38 #endif
39 #ifndef SPOT_DEPRECATED
40 # ifdef __GNUC__
41 # define SPOT_DEPRECATED __attribute__ ((deprecated))
42 # elif defined(_MSC_VER)
43 # define SPOT_DEPRECATED __declspec(deprecated)
44 # else
45 # define SPOT_DEPRECATED
46 # endif
47 #endif
48
49 #if defined _WIN32 || defined __CYGWIN__
50 #define SPOT_HELPER_DLL_IMPORT __declspec(dllimport)
51 #define SPOT_HELPER_DLL_EXPORT __declspec(dllexport)
52 #define SPOT_HELPER_DLL_LOCAL
53 #else
54 #if __GNUC__ >= 4
55 #define SPOT_HELPER_DLL_IMPORT __attribute__ ((visibility ("default")))
56 #define SPOT_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
57 #define SPOT_HELPER_DLL_LOCAL __attribute__ ((visibility ("hidden")))
58 #else
59 #define SPOT_HELPER_DLL_IMPORT
60 #define SPOT_HELPER_DLL_EXPORT
61 #define SPOT_HELPER_DLL_LOCAL
62 #endif
63 #endif
64
65 #ifdef SPOT_BUILD
66 #define SPOT_DLL
67 #endif
68
69
70 // We should not call assert() in headers. For the rare cases where
71 // we do really want to call assert(), use spot_assert__ instead.
72 // Else use SPOT_ASSERT so the assert() are removed from user's
73 // builds.
74 #define spot_assert__ assert
75 #if defined(SPOT_BUILD) or defined(SPOT_DEBUG)
76 #define SPOT_ASSERT(x) spot_assert__(x)
77 #else
78 #define SPOT_ASSERT(x) while (0)
79 #endif
80
81 // SPOT_API is used for the public API symbols. It either DLL imports
82 // or DLL exports (or does nothing for static build) SPOT_LOCAL is
83 // used for non-api symbols that may occur in header files.
84 #ifdef SPOT_DLL
85 #ifdef SPOT_BUILD
86 #define SPOT_API SPOT_HELPER_DLL_EXPORT
87 #else
88 #define SPOT_API SPOT_HELPER_DLL_IMPORT
89 #endif
90 #define SPOT_LOCAL SPOT_HELPER_DLL_LOCAL
91 #else
92 #define SPOT_API
93 #define SPOT_LOCAL
94 #endif
95 #define SPOT_API_VAR extern SPOT_API
96
97
98 // Swig 3.0.2 does not understand 'final' when used
99 // at class definition.
100 #ifdef SWIG
101 #define final
102 #endif
103
104
105 // Do not use those in code, prefer SPOT_UNREACHABLE() instead.
106 #if defined __clang__ || defined __GNU__
107 # define SPOT_UNREACHABLE_BUILTIN() __builtin_unreachable()
108 # elif defined _MSC_VER
109 # define SPOT_UNREACHABLE_BUILTIN() __assume(0)
110 # else
111 # define SPOT_UNREACHABLE_BUILTIN() abort()
112 #endif
113
114 // The extra parentheses in assert() is so that this
115 // pattern is not caught by the style checker.
116 #define SPOT_UNREACHABLE() do { \
117 SPOT_ASSERT(!("unreachable code reached")); \
118 SPOT_UNREACHABLE_BUILTIN(); \
119 } while (0)
120
121 #define SPOT_UNIMPLEMENTED() throw std::runtime_error("unimplemented");
122
123
124 // Useful when forwarding methods such as:
125 // auto func(int param) SPOT_RETURN(implem_.func(param));
126 #define SPOT_RETURN(code) -> decltype(code) { return code; }
127
128 // We hope compilers that implement -Wimplicit-fallthrough
129 // also support __has_cpp_attribute and some form of [[fallthrough]].
130 #ifdef __has_cpp_attribute
131 # if __has_cpp_attribute(fallthrough)
132 # define SPOT_FALLTHROUGH [[fallthrough]]
133 # elif __has_cpp_attribute(clang::fallthrough)
134 # define SPOT_FALLTHROUGH [[clang::fallthrough]]
135 # elif __has_cpp_attribute(gcc::fallthrough)
136 # define SPOT_FALLTHROUGH [[gcc::fallthrough]]
137 # endif
138 #endif
139 #ifndef SPOT_FALLTHROUGH
140 // Clang 3.5 does not support __has_cpp_attribute but has
141 // [[clang::fallthrough]].
142 # if __clang__
143 # define SPOT_FALLTHROUGH [[clang::fallthrough]]
144 # else
145 # define SPOT_FALLTHROUGH while (0)
146 # endif
147 #endif
148
149 namespace spot
150 {
151 struct SPOT_API parse_error: public std::runtime_error
152 {
153 parse_error(const std::string& s)
154 : std::runtime_error(s)
155 {
156 }
157 };
158 }
spot
Definition: graph.hh:33
spot::parse_error
Definition: common.hh:151

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.