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