diff --git a/CMakeLists.txt b/CMakeLists.txt index cb483c0..3108d94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,13 @@ endif() option(BUILD_MODULES "Build Extra Modules (stl)" TRUE) option(BUILD_SAMPLES "Build Samples Folder" FALSE) +option(USE_STD_MAKE_SHARED "Use std::make_shared instead of chaiscript::make_shared" FALSE) +mark_as_advanced(USE_STD_MAKE_SHARED) + +if(USE_STD_MAKE_SHARED) + add_definitions(-DCHAISCRIPT_USE_STD_MAKE_SHARED) +endif() if(CMAKE_COMPILER_IS_GNUCC) option(ENABLE_COVERAGE "Enable Coverage Reporting in GCC" FALSE) @@ -278,8 +284,6 @@ if(BUILD_TESTING) get_target_property(target_files ${executable} SOURCES) - message("Files: ${target_files}") - foreach(source ${target_files}) if(NOT "${source}" MATCHES "/moc_.*cxx") string(REGEX MATCH .*cpp source "${source}") @@ -287,7 +291,6 @@ if(BUILD_TESTING) file(READ "${source}" contents) string(REGEX MATCHALL "TEST_CASE\\([ ]*\"[^\"]+\"" found_tests ${contents}) foreach(hit ${found_tests}) - message("Found Test: ${hit}") string(REGEX REPLACE "TEST_CASE\\([ ]*(\"[^\"]+\").*" "\\1" test_name ${hit}) add_test(${test_name} "${executable}" ${test_name}) set_tests_properties(${test_name} PROPERTIES TIMEOUT 660 ENVIRONMENT "PATH=${NEWPATH}") diff --git a/include/chaiscript/chaiscript_defines.hpp b/include/chaiscript/chaiscript_defines.hpp index 09930c5..38952e5 100644 --- a/include/chaiscript/chaiscript_defines.hpp +++ b/include/chaiscript/chaiscript_defines.hpp @@ -52,11 +52,23 @@ #define CHAISCRIPT_CONSTEXPR constexpr #endif +#include + namespace chaiscript { static const int version_major = 5; static const int version_minor = 7; static const int version_patch = 0; -} + template + inline std::shared_ptr make_shared(Arg && ... arg) + { +#ifdef CHAISCRIPT_USE_STD_MAKE_SHARED + return std::make_shared(std::forward(arg)...); +#else + return std::shared_ptr(static_cast(new D(std::forward(arg)...))); +#endif + } + +} #endif diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 1dc0c44..291a75f 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -10,14 +10,13 @@ #include #include #include -#include -#include #include #include #include #include #include #include +#include #include "bad_boxed_cast.hpp" #include "boxed_cast.hpp" @@ -53,7 +52,7 @@ namespace chaiscript } template::value>::type > - ModulePtr array(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr array(const std::string &type, ModulePtr m = std::make_shared()) { typedef typename std::remove_extent::type ReturnType; const auto extent = std::extent::value; @@ -95,7 +94,7 @@ namespace chaiscript /// \tparam T The type to add a copy constructor for /// \returns The passed in ModulePtr, or the newly constructed one if the default param is used template - ModulePtr copy_constructor(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr copy_constructor(const std::string &type, ModulePtr m = std::make_shared()) { m->add(constructor(), type); return m; @@ -106,7 +105,7 @@ namespace chaiscript /// \param[in,out] m module to add comparison operators to /// \returns the passed in ModulePtr or the newly constructed one if the default params are used. template - ModulePtr opers_comparison(ModulePtr m = ModulePtr(new Module())) + ModulePtr opers_comparison(ModulePtr m = std::make_shared()) { operators::equal(m); operators::greater_than(m); @@ -127,7 +126,7 @@ namespace chaiscript /// \sa copy_constructor /// \sa constructor template - ModulePtr basic_constructors(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr basic_constructors(const std::string &type, ModulePtr m = std::make_shared()) { m->add(constructor(), type); copy_constructor(type, m); @@ -139,7 +138,7 @@ namespace chaiscript /// \param[in] type The name of the type /// \param[in,out] m The Module to add the constructor to template - ModulePtr construct_pod(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr construct_pod(const std::string &type, ModulePtr m = std::make_shared()) { m->add(fun(&detail::construct_pod), type); return m; @@ -170,7 +169,7 @@ namespace chaiscript /// Add all common functions for a POD type. All operators, and /// common conversions template - ModulePtr bootstrap_pod_type(const std::string &name, ModulePtr m = ModulePtr(new Module())) + ModulePtr bootstrap_pod_type(const std::string &name, ModulePtr m = std::make_shared()) { m->add(user_type(), name); m->add(constructor(), name); @@ -251,7 +250,7 @@ namespace chaiscript /// Add all arithmetic operators for PODs - static void opers_arithmetic_pod(ModulePtr m = ModulePtr(new Module())) + static void opers_arithmetic_pod(ModulePtr m = std::make_shared()) { m->add(fun(&Boxed_Number::equals), "=="); m->add(fun(&Boxed_Number::less_than), "<"); @@ -390,7 +389,7 @@ namespace chaiscript /// \brief perform all common bootstrap functions for std::string, void and POD types /// \param[in,out] m Module to add bootstrapped functions to /// \returns passed in ModulePtr, or newly created one if default argument is used - static ModulePtr bootstrap(ModulePtr m = ModulePtr(new Module())) + static ModulePtr bootstrap(ModulePtr m = std::make_shared()) { m->add(user_type(), "void"); m->add(user_type(), "bool"); @@ -498,7 +497,7 @@ namespace chaiscript m->add(fun(&print), "print_string"); m->add(fun(&println), "println_string"); - m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(&bind_function)), "bind"); + m->add(chaiscript::make_shared(&bind_function), "bind"); m->add(fun(&shared_ptr_unconst_clone), "clone"); m->add(fun(&ptr_assign::type>), "="); diff --git a/include/chaiscript/dispatchkit/bootstrap_stl.hpp b/include/chaiscript/dispatchkit/bootstrap_stl.hpp index 3eb7e9e..260dc99 100644 --- a/include/chaiscript/dispatchkit/bootstrap_stl.hpp +++ b/include/chaiscript/dispatchkit/bootstrap_stl.hpp @@ -14,10 +14,8 @@ #define CHAISCRIPT_BOOTSTRAP_STL_HPP_ #include -#include #include #include -#include #include #include @@ -179,7 +177,7 @@ namespace chaiscript /// Add Bidir_Range support for the given ContainerType template - ModulePtr input_range_type_impl(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr input_range_type_impl(const std::string &type, ModulePtr m = std::make_shared()) { m->add(user_type(), type + "_Range"); @@ -232,7 +230,7 @@ namespace chaiscript } template - ModulePtr input_range_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr input_range_type(const std::string &type, ModulePtr m = std::make_shared()) { detail::input_range_type_impl >(type,m); detail::input_range_type_impl >("Const_" + type, m); @@ -243,7 +241,7 @@ namespace chaiscript /// Add random_access_container concept to the given ContainerType /// http://www.sgi.com/tech/stl/RandomAccessContainer.html template - ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) + ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared()) { // cppcheck-suppress syntaxError typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t); @@ -266,7 +264,7 @@ namespace chaiscript /// Add assignable concept to the given ContainerType /// http://www.sgi.com/tech/stl/Assignable.html template - ModulePtr assignable_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr assignable_type(const std::string &type, ModulePtr m = std::make_shared()) { copy_constructor(type, m); operators::assign(m); @@ -277,7 +275,7 @@ namespace chaiscript /// Add container concept to the given ContainerType /// http://www.sgi.com/tech/stl/Container.html template - ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) + ModulePtr container_type(const std::string &/*type*/, ModulePtr m = std::make_shared()) { m->add(fun([](const ContainerType *a) { return a->size(); } ), "size"); m->add(fun([](const ContainerType *a) { return a->empty(); } ), "empty"); @@ -289,7 +287,7 @@ namespace chaiscript /// Add default constructable concept to the given Type /// http://www.sgi.com/tech/stl/DefaultConstructible.html template - ModulePtr default_constructible_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr default_constructible_type(const std::string &type, ModulePtr m = std::make_shared()) { m->add(constructor(), type); return m; @@ -301,7 +299,7 @@ namespace chaiscript /// Add sequence concept to the given ContainerType /// http://www.sgi.com/tech/stl/Sequence.html template - ModulePtr sequence_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) + ModulePtr sequence_type(const std::string &/*type*/, ModulePtr m = std::make_shared()) { m->add(fun(&detail::insert_at), []()->std::string{ @@ -321,7 +319,7 @@ namespace chaiscript /// Add back insertion sequence concept to the given ContainerType /// http://www.sgi.com/tech/stl/BackInsertionSequence.html template - ModulePtr back_insertion_sequence_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) + ModulePtr back_insertion_sequence_type(const std::string &/*type*/, ModulePtr m = std::make_shared()) { typedef typename ContainerType::reference (ContainerType::*backptr)(); @@ -347,7 +345,7 @@ namespace chaiscript /// Front insertion sequence /// http://www.sgi.com/tech/stl/FrontInsertionSequence.html template - ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = ModulePtr(new Module())) + ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = std::make_shared()) { typedef typename ContainerType::reference (ContainerType::*front_ptr)(); typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const; @@ -374,7 +372,7 @@ namespace chaiscript /// bootstrap a given PairType /// http://www.sgi.com/tech/stl/pair.html template - ModulePtr pair_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr pair_type(const std::string &type, ModulePtr m = std::make_shared()) { m->add(user_type(), type); @@ -397,7 +395,7 @@ namespace chaiscript /// http://www.sgi.com/tech/stl/PairAssociativeContainer.html template - ModulePtr pair_associative_container_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr pair_associative_container_type(const std::string &type, ModulePtr m = std::make_shared()) { pair_type(type + "_Pair", m); @@ -408,7 +406,7 @@ namespace chaiscript /// Add unique associative container concept to the given ContainerType /// http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html template - ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) + ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared()) { m->add(fun(detail::count), "count"); @@ -435,7 +433,7 @@ namespace chaiscript /// Add a MapType container /// http://www.sgi.com/tech/stl/Map.html template - ModulePtr map_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr map_type(const std::string &type, ModulePtr m = std::make_shared()) { m->add(user_type(), type); @@ -457,7 +455,7 @@ namespace chaiscript /// hopefully working List type /// http://www.sgi.com/tech/stl/List.html template - ModulePtr list_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr list_type(const std::string &type, ModulePtr m = std::make_shared()) { m->add(user_type(), type); @@ -476,7 +474,7 @@ namespace chaiscript /// Create a vector type with associated concepts /// http://www.sgi.com/tech/stl/Vector.html template - ModulePtr vector_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr vector_type(const std::string &type, ModulePtr m = std::make_shared()) { m->add(user_type(), type); @@ -525,7 +523,7 @@ namespace chaiscript /// Add a String container /// http://www.sgi.com/tech/stl/basic_string.html template - ModulePtr string_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr string_type(const std::string &type, ModulePtr m = std::make_shared()) { m->add(user_type(), type); operators::addition(m); @@ -575,7 +573,7 @@ namespace chaiscript /// Add a MapType container /// http://www.sgi.com/tech/stl/Map.html template - ModulePtr future_type(const std::string &type, ModulePtr m = ModulePtr(new Module())) + ModulePtr future_type(const std::string &type, ModulePtr m = std::make_shared()) { m->add(user_type(), type); diff --git a/include/chaiscript/dispatchkit/boxed_cast.hpp b/include/chaiscript/dispatchkit/boxed_cast.hpp index d7ba410..106b9d8 100644 --- a/include/chaiscript/dispatchkit/boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast.hpp @@ -7,10 +7,7 @@ #ifndef CHAISCRIPT_BOXED_CAST_HPP_ #define CHAISCRIPT_BOXED_CAST_HPP_ -#include - #include "../chaiscript_defines.hpp" -#include "../chaiscript_threading.hpp" #include "bad_boxed_cast.hpp" #include "boxed_cast_helper.hpp" #include "boxed_value.hpp" diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index a2a1331..3c96931 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -7,7 +7,6 @@ #ifndef CHAISCRIPT_BOXED_CAST_HELPER_HPP_ #define CHAISCRIPT_BOXED_CAST_HELPER_HPP_ -#include #include #include @@ -34,7 +33,7 @@ namespace chaiscript template struct Cast_Helper_Inner { - typedef typename std::reference_wrapper::type > Result_Type; + typedef std::reference_wrapper::type > Result_Type; static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { @@ -112,9 +111,9 @@ namespace chaiscript /// Cast_Helper_Inner for casting to a std::shared_ptr<> type template - struct Cast_Helper_Inner > + struct Cast_Helper_Inner > { - typedef typename std::shared_ptr Result_Type; + typedef std::shared_ptr Result_Type; static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { @@ -124,9 +123,9 @@ namespace chaiscript /// Cast_Helper_Inner for casting to a std::shared_ptr type template - struct Cast_Helper_Inner > + struct Cast_Helper_Inner > { - typedef typename std::shared_ptr Result_Type; + typedef std::shared_ptr Result_Type; static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *) { diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index 1d164e3..a57ed7a 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -26,7 +26,7 @@ namespace chaiscript { namespace exception { - struct arithmetic_error : public std::runtime_error + struct arithmetic_error : std::runtime_error { arithmetic_error(const std::string& reason) : std::runtime_error("Arithmetic error: " + reason) {} arithmetic_error(const arithmetic_error &) = default; @@ -60,7 +60,7 @@ namespace chaiscript { private: template - static void check_divide_by_zero(T t, typename std::enable_if::value>::type* = 0) + static void check_divide_by_zero(T t, typename std::enable_if::value>::type* = nullptr) { #ifndef CHAISCRIPT_NO_PROTECT_DIVIDEBYZERO if (t == 0) { @@ -70,7 +70,7 @@ namespace chaiscript } template - static void check_divide_by_zero(T, typename std::enable_if::value>::type* = 0) + static void check_divide_by_zero(T, typename std::enable_if::value>::type* = nullptr) { } diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 9c50c6b..08a115c 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -7,12 +7,10 @@ #ifndef CHAISCRIPT_BOXED_VALUE_HPP_ #define CHAISCRIPT_BOXED_VALUE_HPP_ -#include #include #include #include -#include "../chaiscript_threading.hpp" #include "../chaiscript_defines.hpp" #include "any.hpp" #include "type_info.hpp" diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 2d1026e..e1cb285 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -8,10 +8,8 @@ #define CHAISCRIPT_DISPATCHKIT_HPP_ #include -#include #include #include -#include #include #include #include diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index bd6c843..5a9ccaa 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -7,19 +7,11 @@ #ifndef CHAISCRIPT_DYNAMIC_OBJECT_HPP_ #define CHAISCRIPT_DYNAMIC_OBJECT_HPP_ -#include #include -#include #include -#include #include -#include -#include "../chaiscript_defines.hpp" -#include "boxed_cast.hpp" -#include "boxed_cast_helper.hpp" #include "boxed_value.hpp" -#include "type_info.hpp" namespace chaiscript { class Type_Conversions; diff --git a/include/chaiscript/dispatchkit/function_call.hpp b/include/chaiscript/dispatchkit/function_call.hpp index 578c4ce..3c8e3c5 100644 --- a/include/chaiscript/dispatchkit/function_call.hpp +++ b/include/chaiscript/dispatchkit/function_call.hpp @@ -8,7 +8,6 @@ #define CHAISCRIPT_FUNCTION_CALL_HPP_ #include -#include #include #include diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index 798053d..9410d15 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -7,7 +7,6 @@ #ifndef CHAISCRIPT_FUNCTION_CALL_DETAIL_HPP_ #define CHAISCRIPT_FUNCTION_CALL_DETAIL_HPP_ -#include #include #include #include diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index 335d02a..ed165e0 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -9,14 +9,11 @@ #include #include -#include #include -#include #include #include "boxed_number.hpp" #include "boxed_value.hpp" -#include "type_info.hpp" namespace chaiscript { class Boxed_Number; diff --git a/include/chaiscript/dispatchkit/operators.hpp b/include/chaiscript/dispatchkit/operators.hpp index ce1bd97..a04cba4 100644 --- a/include/chaiscript/dispatchkit/operators.hpp +++ b/include/chaiscript/dispatchkit/operators.hpp @@ -229,231 +229,231 @@ namespace chaiscript template - ModulePtr assign(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign), "="); return m; } template - ModulePtr assign_bitwise_and(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign_bitwise_and(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign_bitwise_and), "&="); return m; } template - ModulePtr assign_xor(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign_xor(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign_xor), "^="); return m; } template - ModulePtr assign_bitwise_or(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign_bitwise_or(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign_bitwise_or), "|="); return m; } template - ModulePtr assign_difference(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign_difference(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign_difference), "-="); return m; } template - ModulePtr assign_left_shift(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign_left_shift(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign_left_shift), "<<="); return m; } template - ModulePtr assign_product(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign_product(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign_product), "*="); return m; } template - ModulePtr assign_quotient(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign_quotient(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign_quotient), "/="); return m; } template - ModulePtr assign_remainder(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign_remainder(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign_remainder), "%="); return m; } template - ModulePtr assign_right_shift(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign_right_shift(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign_right_shift), ">>="); return m; } template - ModulePtr assign_sum(ModulePtr m = ModulePtr(new Module())) + ModulePtr assign_sum(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::assign_sum), "+="); return m; } template - ModulePtr prefix_decrement(ModulePtr m = ModulePtr(new Module())) + ModulePtr prefix_decrement(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::prefix_decrement), "--"); return m; } template - ModulePtr prefix_increment(ModulePtr m = ModulePtr(new Module())) + ModulePtr prefix_increment(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::prefix_increment), "++"); return m; } template - ModulePtr equal(ModulePtr m = ModulePtr(new Module())) + ModulePtr equal(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::equal), "=="); return m; } template - ModulePtr greater_than(ModulePtr m = ModulePtr(new Module())) + ModulePtr greater_than(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::greater_than), ">"); return m; } template - ModulePtr greater_than_equal(ModulePtr m = ModulePtr(new Module())) + ModulePtr greater_than_equal(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::greater_than_equal), ">="); return m; } template - ModulePtr less_than(ModulePtr m = ModulePtr(new Module())) + ModulePtr less_than(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::less_than), "<"); return m; } template - ModulePtr less_than_equal(ModulePtr m = ModulePtr(new Module())) + ModulePtr less_than_equal(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::less_than_equal), "<="); return m; } template - ModulePtr logical_compliment(ModulePtr m = ModulePtr(new Module())) + ModulePtr logical_compliment(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::logical_compliment), "!"); return m; } template - ModulePtr not_equal(ModulePtr m = ModulePtr(new Module())) + ModulePtr not_equal(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::not_equal), "!="); return m; } template - ModulePtr addition(ModulePtr m = ModulePtr(new Module())) + ModulePtr addition(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::addition), "+"); return m; } template - ModulePtr unary_plus(ModulePtr m = ModulePtr(new Module())) + ModulePtr unary_plus(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::unary_plus), "+"); return m; } template - ModulePtr subtraction(ModulePtr m = ModulePtr(new Module())) + ModulePtr subtraction(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::subtraction), "-"); return m; } template - ModulePtr unary_minus(ModulePtr m = ModulePtr(new Module())) + ModulePtr unary_minus(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::unary_minus), "-"); return m; } template - ModulePtr bitwise_and(ModulePtr m = ModulePtr(new Module())) + ModulePtr bitwise_and(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::bitwise_and), "&"); return m; } template - ModulePtr bitwise_compliment(ModulePtr m = ModulePtr(new Module())) + ModulePtr bitwise_compliment(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::bitwise_compliment), "~"); return m; } template - ModulePtr bitwise_xor(ModulePtr m = ModulePtr(new Module())) + ModulePtr bitwise_xor(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::bitwise_xor), "^"); return m; } template - ModulePtr bitwise_or(ModulePtr m = ModulePtr(new Module())) + ModulePtr bitwise_or(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::bitwise_or), "|"); return m; } template - ModulePtr division(ModulePtr m = ModulePtr(new Module())) + ModulePtr division(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::division), "/"); return m; } template - ModulePtr left_shift(ModulePtr m = ModulePtr(new Module())) + ModulePtr left_shift(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::left_shift), "<<"); return m; } template - ModulePtr multiplication(ModulePtr m = ModulePtr(new Module())) + ModulePtr multiplication(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::multiplication), "*"); return m; } template - ModulePtr remainder(ModulePtr m = ModulePtr(new Module())) + ModulePtr remainder(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::remainder), "%"); return m; } template - ModulePtr right_shift(ModulePtr m = ModulePtr(new Module())) + ModulePtr right_shift(ModulePtr m = std::make_shared()) { m->add(chaiscript::fun(&detail::right_shift), ">>"); return m; diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 6f686f6..39011ca 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -9,7 +9,6 @@ #define CHAISCRIPT_PROXY_FUNCTIONS_HPP_ -#include #include #include #include @@ -20,7 +19,6 @@ #include "../chaiscript_defines.hpp" #include "boxed_cast.hpp" -#include "boxed_cast_helper.hpp" #include "boxed_value.hpp" #include "proxy_functions_detail.hpp" #include "type_info.hpp" @@ -582,7 +580,7 @@ namespace chaiscript } protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const + virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { return detail::Do_Call::result_type>::go(m_f, params, t_conversions); } @@ -638,12 +636,12 @@ namespace chaiscript return m_f.get(); } - virtual void assign(const std::shared_ptr &t_rhs) { + virtual void assign(const std::shared_ptr &t_rhs) CHAISCRIPT_OVERRIDE { m_f.get() = dispatch::functor(t_rhs, nullptr); } protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const + virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE { return detail::Do_Call::result_type>::go(m_f.get(), params, t_conversions); } diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 5cb1d82..b90c8d6 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -7,10 +7,8 @@ #ifndef CHAISCRIPT_PROXY_FUNCTIONS_DETAIL_HPP_ #define CHAISCRIPT_PROXY_FUNCTIONS_DETAIL_HPP_ -#include #include #include -#include #include #include "../chaiscript_defines.hpp" diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 8dd51f6..ccfdb49 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -11,7 +11,6 @@ #include #include "bind_first.hpp" -#include "dispatchkit.hpp" #include "proxy_functions.hpp" namespace chaiscript @@ -90,28 +89,28 @@ namespace chaiscript Proxy_Function fun(const T &t) { return Proxy_Function( - static_cast(new dispatch::Proxy_Function_Impl::Signature>(dispatch::detail::to_function(t)))); + chaiscript::make_shared::Signature>>(dispatch::detail::to_function(t))); } template Proxy_Function fun(Ret (Class::*func)(Param...) const) { return Proxy_Function( - static_cast(new dispatch::Proxy_Function_Impl::Signature>(dispatch::detail::to_function(func)))); + chaiscript::make_shared::Signature>>(dispatch::detail::to_function(func))); } template Proxy_Function fun(Ret (Class::*func)(Param...)) { return Proxy_Function( - static_cast(new dispatch::Proxy_Function_Impl::Signature>(dispatch::detail::to_function(func)))); + chaiscript::make_shared::Signature>>(dispatch::detail::to_function(func))); } template::value>::type*/> Proxy_Function fun(T Class::* m /*, typename std::enable_if::value>::type* = 0*/ ) { - return Proxy_Function(new dispatch::Attribute_Access(m)); + return Proxy_Function(chaiscript::make_shared>(m)); } @@ -129,7 +128,7 @@ namespace chaiscript template Proxy_Function fun(const std::function &f) { - return Proxy_Function(static_cast(new dispatch::Proxy_Function_Impl(f))); + return Proxy_Function(chaiscript::make_shared>(f)); } diff --git a/include/chaiscript/dispatchkit/type_conversions.hpp b/include/chaiscript/dispatchkit/type_conversions.hpp index fe6663b..72d2315 100644 --- a/include/chaiscript/dispatchkit/type_conversions.hpp +++ b/include/chaiscript/dispatchkit/type_conversions.hpp @@ -92,13 +92,14 @@ namespace chaiscript return m_from; } + virtual ~Type_Conversion_Base() {} + protected: Type_Conversion_Base(const Type_Info &t_to, const Type_Info &t_from) : m_to(t_to), m_from(t_from) { } - virtual ~Type_Conversion_Base() {} private: Type_Info m_to; @@ -424,14 +425,14 @@ namespace chaiscript static_assert(std::is_polymorphic::value, "Base class must be polymorphic"); static_assert(std::is_polymorphic::value, "Derived class must be polymorphic"); - return std::make_shared>(); + return chaiscript::make_shared>(); } template Type_Conversion type_conversion(const Type_Info &t_from, const Type_Info &t_to, const Callable &t_func) { - return std::make_shared>(t_from, t_to, t_func); + return chaiscript::make_shared>(t_from, t_to, t_func); } template @@ -442,7 +443,7 @@ namespace chaiscript return chaiscript::Boxed_Value(t_function(detail::Cast_Helper::cast(t_bv, nullptr))); }; - return std::make_shared>(user_type(), user_type(), func); + return chaiscript::make_shared>(user_type(), user_type(), func); } template @@ -454,7 +455,7 @@ namespace chaiscript return chaiscript::Boxed_Value(To(detail::Cast_Helper::cast(t_bv, nullptr))); }; - return std::make_shared>(user_type(), user_type(), func); + return chaiscript::make_shared>(user_type(), user_type(), func); } } diff --git a/include/chaiscript/dispatchkit/type_info.hpp b/include/chaiscript/dispatchkit/type_info.hpp index cf038e2..de61ab6 100644 --- a/include/chaiscript/dispatchkit/type_info.hpp +++ b/include/chaiscript/dispatchkit/type_info.hpp @@ -7,11 +7,10 @@ #ifndef CHAISCRIPT_TYPE_INFO_HPP_ #define CHAISCRIPT_TYPE_INFO_HPP_ -#include #include -#include #include #include +#include namespace chaiscript { diff --git a/include/chaiscript/language/chaiscript_algebraic.hpp b/include/chaiscript/language/chaiscript_algebraic.hpp index aab4af7..151a94b 100644 --- a/include/chaiscript/language/chaiscript_algebraic.hpp +++ b/include/chaiscript/language/chaiscript_algebraic.hpp @@ -9,8 +9,6 @@ #include -#include "../dispatchkit/dispatchkit.hpp" - namespace chaiscript { diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index e02a997..0b64aec 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -26,6 +26,7 @@ struct AST_Node; namespace chaiscript { + /// Signature of module entry point that all binary loadable modules must implement. typedef ModulePtr (*Create_Module_Func)(); @@ -77,7 +78,7 @@ namespace chaiscript { /// Errors generated during parsing or evaluation - struct eval_error : public std::runtime_error { + struct eval_error : std::runtime_error { std::string reason; File_Position start_position; File_Position end_position; @@ -391,7 +392,7 @@ namespace chaiscript /// Errors generated when loading a file - struct file_not_found_error : public std::runtime_error { + struct file_not_found_error : std::runtime_error { file_not_found_error(const std::string &t_filename) CHAISCRIPT_NOEXCEPT : std::runtime_error("File Not Found: " + t_filename) { } @@ -465,6 +466,8 @@ namespace chaiscript std::replace(children.begin(), children.end(), t_child, t_new_child); } + virtual ~AST_Node() {} + protected: AST_Node(std::string t_ast_node_text, int t_id, const std::shared_ptr &t_fname, int t_start_line, int t_start_col, int t_end_line, int t_end_col) : @@ -476,7 +479,6 @@ namespace chaiscript AST_Node(std::string t_ast_node_text, int t_id, const std::shared_ptr &t_fname) : identifier(t_id), text(std::move(t_ast_node_text)), filename(t_fname) {} - virtual ~AST_Node() {} virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &) const { diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 675188c..e617562 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -8,8 +8,6 @@ #define CHAISCRIPT_ENGINE_HPP_ #include -#include -#include #include #include #include @@ -18,7 +16,6 @@ #include #include #include -#include #include #include "../chaiscript_defines.hpp" @@ -363,10 +360,10 @@ namespace chaiscript m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists"); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_function_objects, std::ref(m_engine)), "get_functions"); m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_scripting_objects, std::ref(m_engine)), "get_objects"); - m_engine.add(Proxy_Function(new dispatch::Dynamic_Proxy_Function( + m_engine.add(chaiscript::make_shared( [this](const std::vector &t_params) { return m_engine.call_exists(t_params); - })), "call_exists"); + }), "call_exists"); // m_engine.add(fun &)>(std::bind(&chaiscript::dispatch::Proxy_Function_Base::operator(), std::placeholders::_1, std::placeholders::_2, std::ref(m_engine.conversions()))), "call"); // diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 53dfdcf..0012eca 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -7,8 +7,6 @@ #ifndef CHAISCRIPT_EVAL_HPP_ #define CHAISCRIPT_EVAL_HPP_ -#include -#include #include #include #include @@ -21,7 +19,6 @@ #include "../chaiscript_defines.hpp" #include "../dispatchkit/boxed_cast.hpp" -#include "../dispatchkit/boxed_cast_helper.hpp" #include "../dispatchkit/boxed_number.hpp" #include "../dispatchkit/boxed_value.hpp" #include "../dispatchkit/dispatchkit.hpp" @@ -803,12 +800,12 @@ namespace chaiscript const auto &lambda_node = this->children.back(); - return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function( + return Boxed_Value(chaiscript::make_shared( [&t_ss, lambda_node, param_names, captures](const std::vector &t_params) { return detail::eval_function(t_ss, lambda_node, param_names, t_params, captures); }, - static_cast(numparams), lambda_node, param_types))); + static_cast(numparams), lambda_node, param_types)); } @@ -864,23 +861,23 @@ namespace chaiscript std::shared_ptr guard; if (guardnode) { - guard = std::shared_ptr - (new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, t_param_names](const std::vector &t_params) + guard = std::make_shared + ([&t_ss, guardnode, t_param_names](const std::vector &t_params) { return detail::eval_function(t_ss, guardnode, t_param_names, t_params); - }, static_cast(numparams), guardnode)); + }, static_cast(numparams), guardnode); } try { const std::string & l_function_name = this->children[0]->text; const std::string & l_annotation = this->annotation?this->annotation->text:""; const auto & func_node = this->children.back(); - t_ss.add(Proxy_Function - (new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, func_node, t_param_names](const std::vector &t_params) + t_ss.add(chaiscript::make_shared + ([&t_ss, guardnode, func_node, t_param_names](const std::vector &t_params) { return detail::eval_function(t_ss, func_node, t_param_names, t_params); }, static_cast(numparams), this->children.back(), - param_types, l_annotation, guard)), l_function_name); + param_types, l_annotation, guard), l_function_name); } catch (const exception::reserved_word_error &e) { throw exception::eval_error("Reserved word used as function name '" + e.word() + "'"); diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 1acb4f1..9a0cecc 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -229,7 +228,7 @@ namespace chaiscript for (const auto &count : counts) { // std::cout << " Fun Call Count: " << count.first << " " << count.second << '\n'; if (count.second > 1) { - children_to_add.push_back(std::make_shared(count.first)); + children_to_add.push_back(chaiscript::make_shared(count.first)); } } c->children.back()->children.insert(c->children.back()->children.begin(), children_to_add.begin(), children_to_add.end()); @@ -277,7 +276,7 @@ namespace chaiscript for (auto &c : p->children) { if (c->identifier == AST_Node_Type::Fun_Call && c->children.size() == 2 && c->children[1]->children.size() == 1) { - c = std::make_shared(dynamic_cast(*c)); + c = chaiscript::make_shared(dynamic_cast(*c)); // std::cout << "optimized unary fun call\n"; } optimize_fun_calls(c); @@ -728,7 +727,7 @@ namespace chaiscript if (has_more_input() && char_in_alphabet(*m_input_pos, detail::float_alphabet) ) { if (Hex_()) { std::string match(start, m_input_pos); - m_match_stack.emplace_back(std::make_shared(std::move(match), buildInt(std::hex, match), m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.emplace_back(chaiscript::make_shared(std::move(match), buildInt(std::hex, match), m_filename, prev_line, prev_col, m_line, m_col)); return true; } @@ -754,22 +753,22 @@ namespace chaiscript i = const_var(temp_int); } - m_match_stack.push_back(std::make_shared(std::move(match), std::move(i), m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(std::move(match), std::move(i), m_filename, prev_line, prev_col, m_line, m_col)); return true; } if (Float_()) { std::string match(start, m_input_pos); - m_match_stack.push_back(std::make_shared(std::move(match), buildFloat(match), m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(std::move(match), buildFloat(match), m_filename, prev_line, prev_col, m_line, m_col)); return true; } else { IntSuffix_(); std::string match(start, m_input_pos); if (!match.empty() && (match[0] == '0')) { - m_match_stack.push_back(std::make_shared(std::move(match), buildInt(std::oct, match), m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(std::move(match), buildInt(std::oct, match), m_filename, prev_line, prev_col, m_line, m_col)); } else { - m_match_stack.push_back(std::make_shared(std::move(match), buildInt(std::dec, match), m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(std::move(match), buildInt(std::dec, match), m_filename, prev_line, prev_col, m_line, m_col)); } return true; } @@ -827,7 +826,7 @@ namespace chaiscript const auto prev_col = m_col; const auto prev_line = m_line; if (Id_()) { - m_match_stack.push_back(std::make_shared( + m_match_stack.push_back(chaiscript::make_shared( [&]()->std::string{ if (*start == '`') { //Id Literal @@ -858,7 +857,7 @@ namespace chaiscript Id(); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); return true; } @@ -885,7 +884,7 @@ namespace chaiscript } while (Symbol("#")); std::string match(start, m_input_pos); - m_match_stack.push_back(std::make_shared(std::move(match), m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(std::move(match), m_filename, prev_line, prev_col, m_line, m_col)); return true; } else { @@ -951,11 +950,11 @@ namespace chaiscript if (is_interpolated) { //If we've seen previous interpolation, add on instead of making a new one - m_match_stack.push_back(std::make_shared(match, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(match, m_filename, prev_line, prev_col, m_line, m_col)); - build_match(std::make_shared("+"), prev_stack_top); + build_match(chaiscript::make_shared("+"), prev_stack_top); } else { - m_match_stack.push_back(std::make_shared(match, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(match, m_filename, prev_line, prev_col, m_line, m_col)); } //We've finished with the part of the string up to this point, so clear it @@ -975,22 +974,22 @@ namespace chaiscript const auto tostr_stack_top = m_match_stack.size(); - m_match_stack.push_back(std::make_shared("to_string", m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared("to_string", m_filename, prev_line, prev_col, m_line, m_col)); const auto ev_stack_top = m_match_stack.size(); /// \todo can we evaluate this in place and save the runtime cost of evaluating with each execution of the node? - m_match_stack.push_back(std::make_shared("eval", m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared("eval", m_filename, prev_line, prev_col, m_line, m_col)); const auto arg_stack_top = m_match_stack.size(); - m_match_stack.push_back(std::make_shared(eval_match, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(eval_match, m_filename, prev_line, prev_col, m_line, m_col)); - build_match(std::make_shared(), arg_stack_top); - build_match(std::make_shared(), ev_stack_top); - build_match(std::make_shared(), ev_stack_top); - build_match(std::make_shared(), tostr_stack_top); - build_match(std::make_shared("+"), prev_stack_top); + build_match(chaiscript::make_shared(), arg_stack_top); + build_match(chaiscript::make_shared(), ev_stack_top); + build_match(chaiscript::make_shared(), ev_stack_top); + build_match(chaiscript::make_shared(), tostr_stack_top); + build_match(chaiscript::make_shared("+"), prev_stack_top); } else { throw exception::eval_error("Unclosed in-string eval", File_Position(prev_line, prev_col), *m_filename); } @@ -1031,11 +1030,11 @@ namespace chaiscript } if (is_interpolated) { - m_match_stack.push_back(std::make_shared(match, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(match, m_filename, prev_line, prev_col, m_line, m_col)); - build_match(std::make_shared("+"), prev_stack_top); + build_match(chaiscript::make_shared("+"), prev_stack_top); } else { - m_match_stack.push_back(std::make_shared(match, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(match, m_filename, prev_line, prev_col, m_line, m_col)); } return true; } else { @@ -1114,7 +1113,7 @@ namespace chaiscript is_escaped = false; } } - m_match_stack.push_back(std::make_shared(match, m_filename, prev_line, prev_col, m_line, m_col)); + m_match_stack.push_back(chaiscript::make_shared(match, m_filename, prev_line, prev_col, m_line, m_col)); return true; } else { @@ -1146,7 +1145,7 @@ namespace chaiscript const auto prev_line = m_line; if (Char_(t_c)) { m_match_stack.push_back( - std::make_shared(std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col)); + chaiscript::make_shared(std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col)); return true; } else { return false; @@ -1190,7 +1189,7 @@ namespace chaiscript } if ( t_capture && retval ) { - m_match_stack.push_back(std::make_shared( + m_match_stack.push_back(chaiscript::make_shared( std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col)); } return retval; @@ -1233,7 +1232,7 @@ namespace chaiscript } if ( t_capture && retval ) { - m_match_stack.push_back(std::make_shared( + m_match_stack.push_back(chaiscript::make_shared( std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col)); } @@ -1266,7 +1265,7 @@ namespace chaiscript const auto prev_col = m_col; const auto prev_line = m_line; if (Eol_()) { - m_match_stack.push_back(std::make_shared( + m_match_stack.push_back(chaiscript::make_shared( std::string(start, m_input_pos), m_filename, prev_line, prev_col, m_line, m_col)); return true; } else { @@ -1294,7 +1293,7 @@ namespace chaiscript } while (Char(',')); } } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); SkipWS(true); @@ -1320,7 +1319,7 @@ namespace chaiscript } while (Char(',')); } } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); SkipWS(true); @@ -1348,7 +1347,7 @@ namespace chaiscript } } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); SkipWS(true); @@ -1364,7 +1363,7 @@ namespace chaiscript if (Value_Range()) { retval = true; - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else if (Map_Pair()) { retval = true; while (Eol()) {} @@ -1376,7 +1375,7 @@ namespace chaiscript } } while (Char(',')); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else if (Operator()) { retval = true; while (Eol()) {} @@ -1388,7 +1387,7 @@ namespace chaiscript } } while (Char(',')); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } SkipWS(true); @@ -1412,7 +1411,7 @@ namespace chaiscript } } else { // make sure we always have the same number of nodes - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } if (Char('(')) { @@ -1431,7 +1430,7 @@ namespace chaiscript throw exception::eval_error("Incomplete anonymous function", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return retval; @@ -1489,9 +1488,9 @@ namespace chaiscript } if (is_method || t_class_context) { - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else { - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } if (annotation) { @@ -1539,7 +1538,7 @@ namespace chaiscript if (!Block()) { throw exception::eval_error("Incomplete 'catch' block", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), catch_stack_top); + build_match(chaiscript::make_shared(), catch_stack_top); has_matches = true; } } @@ -1552,10 +1551,10 @@ namespace chaiscript if (!Block()) { throw exception::eval_error("Incomplete 'finally' block", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), finally_stack_top); + build_match(chaiscript::make_shared(), finally_stack_top); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return retval; @@ -1591,7 +1590,7 @@ namespace chaiscript if (Keyword("else", true)) { if (Keyword("if")) { const AST_NodePtr back(m_match_stack.back()); - m_match_stack.back() = std::make_shared("else if"); + m_match_stack.back() = chaiscript::make_shared("else if"); m_match_stack.back()->start = back->start; m_match_stack.back()->end = back->end; m_match_stack.back()->children = back->children; @@ -1621,7 +1620,7 @@ namespace chaiscript } } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return retval; @@ -1647,7 +1646,7 @@ namespace chaiscript throw exception::eval_error("Incomplete 'class' block", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return retval; @@ -1677,7 +1676,7 @@ namespace chaiscript throw exception::eval_error("Incomplete 'while' block", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return retval; @@ -1692,7 +1691,7 @@ namespace chaiscript { throw exception::eval_error("'for' loop initial statment missing", File_Position(m_line, m_col), *m_filename); } else { - m_match_stack.push_back(std::make_shared()); + m_match_stack.push_back(chaiscript::make_shared()); } } @@ -1702,13 +1701,13 @@ namespace chaiscript { throw exception::eval_error("'for' loop condition missing", File_Position(m_line, m_col), *m_filename); } else { - m_match_stack.push_back(std::make_shared()); + m_match_stack.push_back(chaiscript::make_shared()); } } if (!Equation()) { - m_match_stack.push_back(std::make_shared()); + m_match_stack.push_back(chaiscript::make_shared()); } return true; @@ -1739,7 +1738,7 @@ namespace chaiscript throw exception::eval_error("Incomplete 'for' block", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return retval; @@ -1768,7 +1767,7 @@ namespace chaiscript throw exception::eval_error("Incomplete 'case' block", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else if (Keyword("default")) { while (Eol()) {} @@ -1776,7 +1775,7 @@ namespace chaiscript throw exception::eval_error("Incomplete 'default' block", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return retval; @@ -1816,7 +1815,7 @@ namespace chaiscript throw exception::eval_error("Incomplete block", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); return true; } else { @@ -1841,10 +1840,10 @@ namespace chaiscript } if (m_match_stack.size() == prev_stack_top) { - m_match_stack.push_back(std::make_shared()); + m_match_stack.push_back(chaiscript::make_shared()); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return retval; @@ -1865,10 +1864,10 @@ namespace chaiscript } if (m_match_stack.size() == prev_stack_top) { - m_match_stack.push_back(std::make_shared()); + m_match_stack.push_back(chaiscript::make_shared()); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return retval; @@ -1880,7 +1879,7 @@ namespace chaiscript if (Keyword("return")) { Operator(); - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); return true; } else { return false; @@ -1892,7 +1891,7 @@ namespace chaiscript const auto prev_stack_top = m_match_stack.size(); if (Keyword("break")) { - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); return true; } else { return false; @@ -1904,7 +1903,7 @@ namespace chaiscript const auto prev_stack_top = m_match_stack.size(); if (Keyword("continue")) { - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); return true; } else { return false; @@ -1933,7 +1932,7 @@ namespace chaiscript throw exception::eval_error("Incomplete function call", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); /// \todo Work around for method calls until we have a better solution if (!m_match_stack.back()->children.empty()) { if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Dot_Access) { @@ -1954,7 +1953,7 @@ namespace chaiscript throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else if (Symbol(".", true)) { has_more = true; @@ -1962,7 +1961,7 @@ namespace chaiscript throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } } } @@ -1983,7 +1982,7 @@ namespace chaiscript throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else if (Keyword("auto") || Keyword("var")) { retval = true; @@ -1991,7 +1990,7 @@ namespace chaiscript throw exception::eval_error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else if (Keyword("attr")) { retval = true; @@ -2006,7 +2005,7 @@ namespace chaiscript } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return retval; @@ -2039,17 +2038,17 @@ namespace chaiscript } if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) { - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Map_Pair) { - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else { - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } } else { - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } return true; @@ -2067,7 +2066,7 @@ namespace chaiscript throw exception::eval_error("Incomplete '&' expression", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); return true; } else { return false; @@ -2088,7 +2087,7 @@ namespace chaiscript throw exception::eval_error("Incomplete prefix '" + oper + "' expression", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(Operators::to_operator(oper, true)), prev_stack_top); + build_match(chaiscript::make_shared(Operators::to_operator(oper, true)), prev_stack_top); return true; } } @@ -2138,7 +2137,7 @@ namespace chaiscript + std::string(ast_node_type_to_string(m_operators[t_precedence])) + " expression", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else { throw exception::eval_error("Incomplete " @@ -2157,14 +2156,14 @@ namespace chaiscript case(AST_Node_Type::Comparison) : assert(m_match_stack.size() > 1); m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2, m_match_stack.begin() + m_match_stack.size() - 1); - build_match(std::make_shared(oper->text), prev_stack_top); + build_match(chaiscript::make_shared(oper->text), prev_stack_top); break; case(AST_Node_Type::Logical_And) : - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); break; case(AST_Node_Type::Logical_Or) : - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); break; default: @@ -2196,7 +2195,7 @@ namespace chaiscript throw exception::eval_error("Incomplete map pair", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else { m_input_pos = prev_pos; @@ -2225,7 +2224,7 @@ namespace chaiscript throw exception::eval_error("Incomplete value range", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } else { m_input_pos = prev_pos; @@ -2256,7 +2255,7 @@ namespace chaiscript throw exception::eval_error("Incomplete equation", File_Position(m_line, m_col), *m_filename); } - build_match(std::make_shared(), prev_stack_top); + build_match(chaiscript::make_shared(), prev_stack_top); } } @@ -2350,7 +2349,7 @@ namespace chaiscript if (m_input_pos != m_input_end) { throw exception::eval_error("Unparsed input", File_Position(m_line, m_col), t_fname); } else { - build_match(std::make_shared(), 0); + build_match(chaiscript::make_shared(), 0); return true; } } else { diff --git a/unittests/multithreaded_test.cpp b/unittests/multithreaded_test.cpp index 9b4d6a5..866a3ca 100644 --- a/unittests/multithreaded_test.cpp +++ b/unittests/multithreaded_test.cpp @@ -1,6 +1,5 @@ #include -#include #include #include @@ -74,7 +73,7 @@ int main() for (int i = 0; i < num_threads; ++i) { - threads.push_back(std::shared_ptr(new std::thread(do_work, std::ref(chai), i))); + threads.push_back(std::make_shared(do_work, std::ref(chai), i)); } for (int i = 0; i < num_threads; ++i)