/src/solidity/libyul/Exceptions.h
Line | Count | Source |
1 | | /* |
2 | | This file is part of solidity. |
3 | | |
4 | | solidity is free software: you can redistribute it and/or modify |
5 | | it under the terms of the GNU General Public License as published by |
6 | | the Free Software Foundation, either version 3 of the License, or |
7 | | (at your option) any later version. |
8 | | |
9 | | solidity is distributed in the hope that it will be useful, |
10 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | GNU General Public License for more details. |
13 | | |
14 | | You should have received a copy of the GNU General Public License |
15 | | along with solidity. If not, see <http://www.gnu.org/licenses/>. |
16 | | */ |
17 | | // SPDX-License-Identifier: GPL-3.0 |
18 | | /** |
19 | | * Exceptions in Yul. |
20 | | */ |
21 | | |
22 | | #pragma once |
23 | | |
24 | | #include <libsolutil/Exceptions.h> |
25 | | #include <libsolutil/Assertions.h> |
26 | | |
27 | | #include <libyul/YulName.h> |
28 | | |
29 | | #include <boost/preprocessor/cat.hpp> |
30 | | #include <boost/preprocessor/facilities/empty.hpp> |
31 | | #include <boost/preprocessor/facilities/overload.hpp> |
32 | | |
33 | | namespace solidity::yul |
34 | | { |
35 | | |
36 | | struct YulException: virtual util::Exception {}; |
37 | | struct OptimizerException: virtual YulException {}; |
38 | | struct CodegenException: virtual YulException {}; |
39 | | struct YulAssertion: virtual util::Exception {}; |
40 | | |
41 | | struct StackTooDeepError: virtual YulException |
42 | | { |
43 | | StackTooDeepError(YulName _variable, int _depth, std::string const& _message): |
44 | 132k | variable(_variable), depth(_depth) |
45 | 132k | { |
46 | 132k | *this << util::errinfo_comment(_message); |
47 | 132k | } |
48 | | StackTooDeepError(YulName _functionName, YulName _variable, int _depth, std::string const& _message): |
49 | 21.3k | functionName(_functionName), variable(_variable), depth(_depth) |
50 | 21.3k | { |
51 | 21.3k | *this << util::errinfo_comment(_message); |
52 | 21.3k | } |
53 | | YulName functionName; |
54 | | YulName variable; |
55 | | int depth; |
56 | | }; |
57 | | |
58 | | /// Assertion that throws an YulAssertion containing the given description if it is not met. |
59 | | #if !BOOST_PP_VARIADICS_MSVC |
60 | 368M | #define yulAssert(...) BOOST_PP_OVERLOAD(yulAssert_,__VA_ARGS__)(__VA_ARGS__) |
61 | | #else |
62 | | #define yulAssert(...) BOOST_PP_CAT(BOOST_PP_OVERLOAD(yulAssert_,__VA_ARGS__)(__VA_ARGS__),BOOST_PP_EMPTY()) |
63 | | #endif |
64 | | |
65 | | #define yulAssert_1(CONDITION) \ |
66 | 3.92G | yulAssert_2((CONDITION), "") |
67 | | |
68 | | #define yulAssert_2(CONDITION, DESCRIPTION) \ |
69 | 5.65G | assertThrowWithDefaultDescription( \ |
70 | 4.62G | (CONDITION), \ |
71 | 4.62G | ::solidity::yul::YulAssertion, \ |
72 | 4.62G | (DESCRIPTION), \ |
73 | 4.62G | "Yul assertion failed" \ |
74 | 4.62G | ) |
75 | | |
76 | | } |