/src/spirv-cross/spirv_cross_error_handling.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2015-2021 Arm Limited |
3 | | * SPDX-License-Identifier: Apache-2.0 OR MIT |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | |
18 | | /* |
19 | | * At your option, you may choose to accept this material under either: |
20 | | * 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or |
21 | | * 2. The MIT License, found at <http://opensource.org/licenses/MIT>. |
22 | | */ |
23 | | |
24 | | #ifndef SPIRV_CROSS_ERROR_HANDLING |
25 | | #define SPIRV_CROSS_ERROR_HANDLING |
26 | | |
27 | | #include <stdio.h> |
28 | | #include <stdlib.h> |
29 | | #include <string> |
30 | | #ifndef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS |
31 | | #include <stdexcept> |
32 | | #endif |
33 | | |
34 | | #ifdef SPIRV_CROSS_NAMESPACE_OVERRIDE |
35 | | #define SPIRV_CROSS_NAMESPACE SPIRV_CROSS_NAMESPACE_OVERRIDE |
36 | | #else |
37 | | #define SPIRV_CROSS_NAMESPACE spirv_cross |
38 | | #endif |
39 | | |
40 | | namespace SPIRV_CROSS_NAMESPACE |
41 | | { |
42 | | #ifdef SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS |
43 | | #if !defined(_MSC_VER) || defined(__clang__) |
44 | | [[noreturn]] |
45 | | #elif defined(_MSC_VER) |
46 | | __declspec(noreturn) |
47 | | #endif |
48 | | inline void |
49 | | report_and_abort(const std::string &msg) |
50 | | { |
51 | | #ifdef NDEBUG |
52 | | (void)msg; |
53 | | #else |
54 | | fprintf(stderr, "There was a compiler error: %s\n", msg.c_str()); |
55 | | #endif |
56 | | fflush(stderr); |
57 | | abort(); |
58 | | } |
59 | | |
60 | | #define SPIRV_CROSS_THROW(x) report_and_abort(x) |
61 | | #else |
62 | | class CompilerError : public std::runtime_error |
63 | | { |
64 | | public: |
65 | | explicit CompilerError(const std::string &str) |
66 | | : std::runtime_error(str) |
67 | 0 | { |
68 | 0 | } |
69 | | |
70 | | explicit CompilerError(const char *str) |
71 | 235 | : std::runtime_error(str) |
72 | 235 | { |
73 | 235 | } |
74 | | }; |
75 | | |
76 | 235 | #define SPIRV_CROSS_THROW(x) throw CompilerError(x) |
77 | | #endif |
78 | | |
79 | | // MSVC 2013 does not have noexcept. We need this for Variant to get move constructor to work correctly |
80 | | // instead of copy constructor. |
81 | | // MSVC 2013 ignores that move constructors cannot throw in std::vector, so just don't define it. |
82 | | #if defined(_MSC_VER) && _MSC_VER < 1900 |
83 | | #define SPIRV_CROSS_NOEXCEPT |
84 | | #else |
85 | | #define SPIRV_CROSS_NOEXCEPT noexcept |
86 | | #endif |
87 | | |
88 | | #if __cplusplus >= 201402l |
89 | | #define SPIRV_CROSS_DEPRECATED(reason) [[deprecated(reason)]] |
90 | | #elif defined(__GNUC__) |
91 | | #define SPIRV_CROSS_DEPRECATED(reason) __attribute__((deprecated)) |
92 | | #elif defined(_MSC_VER) |
93 | | #define SPIRV_CROSS_DEPRECATED(reason) __declspec(deprecated(reason)) |
94 | | #else |
95 | | #define SPIRV_CROSS_DEPRECATED(reason) |
96 | | #endif |
97 | | } // namespace SPIRV_CROSS_NAMESPACE |
98 | | |
99 | | #endif |