diff --git a/liblangutil/Exceptions.h b/liblangutil/Exceptions.h index 9a4051a87..6946ff463 100644 --- a/liblangutil/Exceptions.h +++ b/liblangutil/Exceptions.h @@ -28,6 +28,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -45,18 +49,68 @@ struct FatalError: virtual util::Exception {}; struct UnimplementedFeatureError: virtual util::Exception {}; struct InvalidAstError: virtual util::Exception {}; + /// Assertion that throws an InternalCompilerError containing the given description if it is not met. -#define solAssert(CONDITION, DESCRIPTION) \ - assertThrowWithDefaultDescription(CONDITION, ::solidity::langutil::InternalCompilerError, DESCRIPTION, "Solidity assertion failed") +#if !BOOST_PP_VARIADICS_MSVC +#define solAssert(...) BOOST_PP_OVERLOAD(solAssert_,__VA_ARGS__)(__VA_ARGS__) +#else +#define solAssert(...) BOOST_PP_CAT(BOOST_PP_OVERLOAD(solAssert_,__VA_ARGS__)(__VA_ARGS__),BOOST_PP_EMPTY()) +#endif -#define solUnimplementedAssert(CONDITION, DESCRIPTION) \ - assertThrowWithDefaultDescription(CONDITION, ::solidity::langutil::UnimplementedFeatureError, DESCRIPTION, "Unimplemented feature") +#define solAssert_1(CONDITION) \ + solAssert_2(CONDITION, "") +#define solAssert_2(CONDITION, DESCRIPTION) \ + assertThrowWithDefaultDescription( \ + CONDITION, \ + ::solidity::langutil::InternalCompilerError, \ + DESCRIPTION, \ + "Solidity assertion failed" \ + ) + + +/// Assertion that throws an UnimplementedFeatureError containing the given description if it is not met. +#if !BOOST_PP_VARIADICS_MSVC +#define solUnimplementedAssert(...) BOOST_PP_OVERLOAD(solUnimplementedAssert_,__VA_ARGS__)(__VA_ARGS__) +#else +#define solUnimplementedAssert(...) BOOST_PP_CAT(BOOST_PP_OVERLOAD(solUnimplementedAssert_,__VA_ARGS__)(__VA_ARGS__),BOOST_PP_EMPTY()) +#endif + +#define solUnimplementedAssert_1(CONDITION) \ + solUnimplementedAssert_2(CONDITION, "") + +#define solUnimplementedAssert_2(CONDITION, DESCRIPTION) \ + assertThrowWithDefaultDescription( \ + CONDITION, \ + ::solidity::langutil::UnimplementedFeatureError, \ + DESCRIPTION, \ + "Unimplemented feature" \ + ) + + +/// Helper that unconditionally reports an unimplemented feature. #define solUnimplemented(DESCRIPTION) \ solUnimplementedAssert(false, DESCRIPTION) -#define astAssert(CONDITION, DESCRIPTION) \ - assertThrowWithDefaultDescription(CONDITION, ::solidity::langutil::InvalidAstError, DESCRIPTION, "AST assertion failed") + +/// Assertion that throws an InvalidAstError containing the given description if it is not met. +#if !BOOST_PP_VARIADICS_MSVC +#define astAssert(...) BOOST_PP_OVERLOAD(astAssert_,__VA_ARGS__)(__VA_ARGS__) +#else +#define astAssert(...) BOOST_PP_CAT(BOOST_PP_OVERLOAD(astAssert_,__VA_ARGS__)(__VA_ARGS__),BOOST_PP_EMPTY()) +#endif + +#define astAssert_1(CONDITION) \ + astAssert_2(CONDITION, "") + +#define astAssert_2(CONDITION, DESCRIPTION) \ + assertThrowWithDefaultDescription( \ + CONDITION, \ + ::solidity::langutil::InvalidAstError, \ + DESCRIPTION, \ + "AST assertion failed" \ + ) + using errorSourceLocationInfo = std::pair; diff --git a/libsmtutil/Exceptions.h b/libsmtutil/Exceptions.h index 85f751f08..fd144ca72 100644 --- a/libsmtutil/Exceptions.h +++ b/libsmtutil/Exceptions.h @@ -21,12 +21,31 @@ #include #include +#include +#include +#include + namespace solidity::smtutil { struct SMTLogicError: virtual util::Exception {}; -#define smtAssert(CONDITION, DESCRIPTION) \ - assertThrowWithDefaultDescription(CONDITION, SMTLogicError, DESCRIPTION, "SMT assertion failed") +/// Assertion that throws an SMTLogicError containing the given description if it is not met. +#if !BOOST_PP_VARIADICS_MSVC +#define smtAssert(...) BOOST_PP_OVERLOAD(smtAssert_,__VA_ARGS__)(__VA_ARGS__) +#else +#define smtAssert(...) BOOST_PP_CAT(BOOST_PP_OVERLOAD(smtAssert_,__VA_ARGS__)(__VA_ARGS__),BOOST_PP_EMPTY()) +#endif + +#define smtAssert_1(CONDITION) \ + smtAssert_2(CONDITION, "") + +#define smtAssert_2(CONDITION, DESCRIPTION) \ + assertThrowWithDefaultDescription( \ + CONDITION, \ + ::solidity::smtutil::SMTLogicError, \ + DESCRIPTION, \ + "SMT assertion failed" \ + ) } diff --git a/libyul/Exceptions.h b/libyul/Exceptions.h index 96e07d620..1ad7785e9 100644 --- a/libyul/Exceptions.h +++ b/libyul/Exceptions.h @@ -26,6 +26,10 @@ #include +#include +#include +#include + namespace solidity::yul { @@ -52,7 +56,21 @@ struct StackTooDeepError: virtual YulException }; /// Assertion that throws an YulAssertion containing the given description if it is not met. -#define yulAssert(CONDITION, DESCRIPTION) \ - assertThrowWithDefaultDescription(CONDITION, ::solidity::yul::YulAssertion, DESCRIPTION, "Yul assertion failed") +#if !BOOST_PP_VARIADICS_MSVC +#define yulAssert(...) BOOST_PP_OVERLOAD(yulAssert_,__VA_ARGS__)(__VA_ARGS__) +#else +#define yulAssert(...) BOOST_PP_CAT(BOOST_PP_OVERLOAD(yulAssert_,__VA_ARGS__)(__VA_ARGS__),BOOST_PP_EMPTY()) +#endif + +#define yulAssert_1(CONDITION) \ + yulAssert_2(CONDITION, "") + +#define yulAssert_2(CONDITION, DESCRIPTION) \ + assertThrowWithDefaultDescription( \ + CONDITION, \ + ::solidity::yul::YulAssertion, \ + DESCRIPTION, \ + "Yul assertion failed" \ + ) }