spot  2.1.2
 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 
23 #pragma once
24 
25 #ifdef __GNUC__
26 #define SPOT_LIKELY(expr) __builtin_expect(!!(expr), 1)
27 #define SPOT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
28 #else
29 #define SPOT_LIKELY(expr) (expr)
30 #define SPOT_UNLIKELY(expr) (expr)
31 #endif
32 
33 #ifdef __GNUC__
34 #define SPOT_DEPRECATED __attribute__ ((deprecated))
35 #elif defined(_MSC_VER)
36 #define SPOT_DEPRECATED __declspec(deprecated)
37 #else
38 #define SPOT_DEPRECATED func
39 #endif
40 
41 #if defined _WIN32 || defined __CYGWIN__
42  #define SPOT_HELPER_DLL_IMPORT __declspec(dllimport)
43  #define SPOT_HELPER_DLL_EXPORT __declspec(dllexport)
44  #define SPOT_HELPER_DLL_LOCAL
45 #else
46  #if __GNUC__ >= 4
47  #define SPOT_HELPER_DLL_IMPORT __attribute__ ((visibility ("default")))
48  #define SPOT_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
49  #define SPOT_HELPER_DLL_LOCAL __attribute__ ((visibility ("hidden")))
50  #else
51  #define SPOT_HELPER_DLL_IMPORT
52  #define SPOT_HELPER_DLL_EXPORT
53  #define SPOT_HELPER_DLL_LOCAL
54  #endif
55 #endif
56 
57 #ifdef SPOT_BUILD
58  #define SPOT_DLL
59 #endif
60 
61 
62 // We should not call assert() in headers. For the rare cases where
63 // we do really want to call assert(), use spot_assert__ instead.
64 // Else use SPOT_ASSERT so the assert() are removed from user's
65 // builds.
66 #define spot_assert__ assert
67 #if defined(SPOT_BUILD) or defined(SPOT_DEBUG)
68  #define SPOT_ASSERT(x) spot_assert__(x)
69 #else
70  #define SPOT_ASSERT(x) while (0)
71 #endif
72 
73 // SPOT_API is used for the public API symbols. It either DLL imports
74 // or DLL exports (or does nothing for static build) SPOT_LOCAL is
75 // used for non-api symbols that may occur in header files.
76 #ifdef SPOT_DLL
77  #ifdef SPOT_BUILD
78  #define SPOT_API SPOT_HELPER_DLL_EXPORT
79  #else
80  #define SPOT_API SPOT_HELPER_DLL_IMPORT
81  #endif
82  #define SPOT_LOCAL SPOT_HELPER_DLL_LOCAL
83 #else
84  #define SPOT_API
85  #define SPOT_LOCAL
86 #endif
87 #define SPOT_API_VAR extern SPOT_API
88 
89 
90 // Swig 3.0.2 does not understand 'final' when used
91 // at class definition.
92 #ifdef SWIG
93  #define final
94 #endif
95 
96 
97 // Do not use those in code, prefer SPOT_UNREACHABLE() instead.
98 #if defined __clang__ || defined __GNU__
99 # define SPOT_UNREACHABLE_BUILTIN() __builtin_unreachable()
100 # elif defined _MSC_VER
101 # define SPOT_UNREACHABLE_BUILTIN() __assume(0)
102 # else
103 # define SPOT_UNREACHABLE_BUILTIN() abort()
104 #endif
105 
106 // The extra parentheses in assert() is so that this
107 // pattern is not caught by the style checker.
108 #define SPOT_UNREACHABLE() do { \
109  SPOT_ASSERT(!("unreachable code reached")); \
110  SPOT_UNREACHABLE_BUILTIN(); \
111  } while (0)
112 
113 #define SPOT_UNIMPLEMENTED() throw std::runtime_error("unimplemented");
114 
115 
116 // Useful when forwarding methods such as:
117 // auto func(int param) SPOT_RETURN(implem_.func(param));
118 #define SPOT_RETURN(code) -> decltype(code) { return code; }
119 
120 // We hope compilers that implement -Wimplicit-fallthrough
121 // also support __has_cpp_attribute and some form of [[fallthrough]].
122 #ifdef __has_cpp_attribute
123 # if __has_cpp_attribute(fallthrough)
124 # define SPOT_FALLTHROUGH [[fallthrough]]
125 # elif __has_cpp_attribute(clang::fallthrough)
126 # define SPOT_FALLTHROUGH [[clang::fallthrough]]
127 # elif __has_cpp_attribute(gcc::fallthrough)
128 # define SPOT_FALLTHROUGH [[gcc::fallthrough]]
129 # endif
130 #endif
131 #ifndef SPOT_FALLTHROUGH
132 // Clang 3.5 does not support __has_cpp_attribute but has
133 // [[clang::fallthrough]].
134 # if __clang__
135 # define SPOT_FALLTHROUGH [[clang::fallthrough]]
136 # else
137 # define SPOT_FALLTHROUGH while (0)
138 # endif
139 #endif
140 
141 namespace spot
142 {
143  struct SPOT_API parse_error: public std::runtime_error
144  {
145  parse_error(const std::string& s)
146  : std::runtime_error(s)
147  {
148  }
149  };
150 }
Definition: graph.hh:32
Definition: common.hh:143

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Fri Oct 14 2016 15:38:12 for spot by doxygen 1.8.8