Fix some boxed_cast and exception issues
This commit is contained in:
@@ -548,9 +548,11 @@ namespace chaiscript
|
||||
m.add(chaiscript::fun(&get_parse_tree), "get_parse_tree");
|
||||
|
||||
m.add(chaiscript::base_class<std::runtime_error, chaiscript::exception::eval_error>());
|
||||
m.add(chaiscript::base_class<std::exception, chaiscript::exception::eval_error>());
|
||||
|
||||
m.add(chaiscript::user_type<chaiscript::exception::arithmetic_error>(), "arithmetic_error");
|
||||
m.add(chaiscript::base_class<std::runtime_error, chaiscript::exception::arithmetic_error>());
|
||||
m.add(chaiscript::base_class<std::exception, chaiscript::exception::arithmetic_error>());
|
||||
|
||||
|
||||
// chaiscript::bootstrap::standard_library::vector_type<std::vector<std::shared_ptr<chaiscript::AST_Node> > >("AST_NodeVector", m);
|
||||
|
@@ -69,11 +69,11 @@ namespace chaiscript
|
||||
/// assert(i == 5);
|
||||
/// \endcode
|
||||
template<typename Type>
|
||||
auto boxed_cast(const Boxed_Value &bv, const Type_Conversions_State *t_conversions = nullptr) -> decltype(detail::Cast_Helper<Type>::cast(bv, nullptr))
|
||||
decltype(auto) boxed_cast(const Boxed_Value &bv, const Type_Conversions_State *t_conversions = nullptr)
|
||||
{
|
||||
if (!t_conversions || bv.get_type_info().bare_equal(user_type<Type>()) || (t_conversions && !(*t_conversions)->convertable_type<Type>())) {
|
||||
try {
|
||||
return detail::Cast_Helper<Type>::cast(bv, t_conversions);
|
||||
return(detail::Cast_Helper<Type>::cast(bv, t_conversions));
|
||||
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
||||
}
|
||||
}
|
||||
@@ -84,11 +84,11 @@ namespace chaiscript
|
||||
try {
|
||||
// We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it
|
||||
// either way, we are not responsible if it doesn't work
|
||||
return detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_conversion<Type>(t_conversions->saves(), bv), t_conversions);
|
||||
return(detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_conversion<Type>(t_conversions->saves(), bv), t_conversions));
|
||||
} catch (...) {
|
||||
try {
|
||||
// try going the other way
|
||||
return detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_down_conversion<Type>(t_conversions->saves(), bv), t_conversions);
|
||||
return(detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_down_conversion<Type>(t_conversions->saves(), bv), t_conversions));
|
||||
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
||||
throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type));
|
||||
}
|
||||
|
@@ -30,18 +30,18 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
static const void *verify_type(const Boxed_Value &ob, const std::type_info &ti, const void *ptr) {
|
||||
if (!ob.get_type_info().bare_equal_type_info(ti)) {
|
||||
throw chaiscript::detail::exception::bad_any_cast();
|
||||
} else {
|
||||
if (ob.get_type_info().bare_equal_type_info(ti)) {
|
||||
return throw_if_null(ptr);
|
||||
} else {
|
||||
throw chaiscript::detail::exception::bad_any_cast();
|
||||
}
|
||||
}
|
||||
|
||||
static void *verify_type(const Boxed_Value &ob, const std::type_info &ti, void *ptr) {
|
||||
if (ptr == nullptr || !ob.get_type_info().bare_equal_type_info(ti)) {
|
||||
throw chaiscript::detail::exception::bad_any_cast();
|
||||
if (!ob.is_const() && ob.get_type_info().bare_equal_type_info(ti)) {
|
||||
return throw_if_null(ptr);
|
||||
} else {
|
||||
return ptr;
|
||||
throw chaiscript::detail::exception::bad_any_cast();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,9 +242,9 @@ namespace chaiscript
|
||||
template<typename T>
|
||||
struct Cast_Helper
|
||||
{
|
||||
static auto cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions) -> decltype(Cast_Helper_Inner<T>::cast(ob, t_conversions))
|
||||
static decltype(auto) cast(const Boxed_Value &ob, const Type_Conversions_State *t_conversions)
|
||||
{
|
||||
return Cast_Helper_Inner<T>::cast(ob, t_conversions);
|
||||
return(Cast_Helper_Inner<T>::cast(ob, t_conversions));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -424,10 +424,10 @@ namespace chaiscript
|
||||
|
||||
/// \brief casts an object while applying any Dynamic_Conversion available
|
||||
template<typename Type>
|
||||
auto boxed_cast(const Boxed_Value &bv) const -> decltype(chaiscript::boxed_cast<Type>(bv, nullptr))
|
||||
decltype(auto) boxed_cast(const Boxed_Value &bv) const
|
||||
{
|
||||
Type_Conversions_State state(m_conversions, m_conversions.conversion_saves());
|
||||
return chaiscript::boxed_cast<Type>(bv, &state);
|
||||
return(chaiscript::boxed_cast<Type>(bv, &state));
|
||||
}
|
||||
|
||||
/// Add a new conversion for upcasting to a base class
|
||||
|
@@ -690,9 +690,9 @@ namespace chaiscript
|
||||
|
||||
/// \brief casts an object while applying any Dynamic_Conversion available
|
||||
template<typename Type>
|
||||
auto boxed_cast(const Boxed_Value &bv) const -> decltype(m_engine.boxed_cast<Type>(bv))
|
||||
decltype(auto) boxed_cast(const Boxed_Value &bv) const
|
||||
{
|
||||
return m_engine.boxed_cast<Type>(bv);
|
||||
return(m_engine.boxed_cast<Type>(bv));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
#include "../chaiscript.hpp"
|
||||
#include "../dispatchkit/proxy_functions.hpp"
|
||||
#include "../dispatchkit/type_info.hpp"
|
||||
#include "../dispatchkit/operators.hpp"
|
||||
//#include "../dispatchkit/operators.hpp"
|
||||
|
||||
|
||||
namespace chaiscript
|
||||
|
Reference in New Issue
Block a user