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
40namespace 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
48inline void
49report_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
62class CompilerError : public std::runtime_error
63{
64public:
65 explicit CompilerError(const std::string &str)
66 : std::runtime_error(str)
67 {
68 }
69};
70
71#define SPIRV_CROSS_THROW(x) throw CompilerError(x)
72#endif
73
74// MSVC 2013 does not have noexcept. We need this for Variant to get move constructor to work correctly
75// instead of copy constructor.
76// MSVC 2013 ignores that move constructors cannot throw in std::vector, so just don't define it.
77#if defined(_MSC_VER) && _MSC_VER < 1900
78#define SPIRV_CROSS_NOEXCEPT
79#else
80#define SPIRV_CROSS_NOEXCEPT noexcept
81#endif
82
83#if __cplusplus >= 201402l
84#define SPIRV_CROSS_DEPRECATED(reason) [[deprecated(reason)]]
85#elif defined(__GNUC__)
86#define SPIRV_CROSS_DEPRECATED(reason) __attribute__((deprecated))
87#elif defined(_MSC_VER)
88#define SPIRV_CROSS_DEPRECATED(reason) __declspec(deprecated(reason))
89#else
90#define SPIRV_CROSS_DEPRECATED(reason)
91#endif
92} // namespace SPIRV_CROSS_NAMESPACE
93
94#endif
95