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::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::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::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::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);
|
// 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);
|
/// assert(i == 5);
|
||||||
/// \endcode
|
/// \endcode
|
||||||
template<typename Type>
|
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>())) {
|
if (!t_conversions || bv.get_type_info().bare_equal(user_type<Type>()) || (t_conversions && !(*t_conversions)->convertable_type<Type>())) {
|
||||||
try {
|
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 &) {
|
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,11 +84,11 @@ namespace chaiscript
|
|||||||
try {
|
try {
|
||||||
// We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it
|
// 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
|
// 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 (...) {
|
} catch (...) {
|
||||||
try {
|
try {
|
||||||
// try going the other way
|
// 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 &) {
|
} catch (const chaiscript::detail::exception::bad_any_cast &) {
|
||||||
throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type));
|
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) {
|
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)) {
|
if (ob.get_type_info().bare_equal_type_info(ti)) {
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
|
||||||
} else {
|
|
||||||
return throw_if_null(ptr);
|
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) {
|
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)) {
|
if (!ob.is_const() && ob.get_type_info().bare_equal_type_info(ti)) {
|
||||||
throw chaiscript::detail::exception::bad_any_cast();
|
return throw_if_null(ptr);
|
||||||
} else {
|
} else {
|
||||||
return ptr;
|
throw chaiscript::detail::exception::bad_any_cast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,9 +242,9 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct Cast_Helper
|
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
|
/// \brief casts an object while applying any Dynamic_Conversion available
|
||||||
template<typename Type>
|
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());
|
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
|
/// 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
|
/// \brief casts an object while applying any Dynamic_Conversion available
|
||||||
template<typename Type>
|
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 "../chaiscript.hpp"
|
||||||
#include "../dispatchkit/proxy_functions.hpp"
|
#include "../dispatchkit/proxy_functions.hpp"
|
||||||
#include "../dispatchkit/type_info.hpp"
|
#include "../dispatchkit/type_info.hpp"
|
||||||
#include "../dispatchkit/operators.hpp"
|
//#include "../dispatchkit/operators.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
|
Reference in New Issue
Block a user