From a8aa4ce273821ca8f48e7073306e292e33eaa19d Mon Sep 17 00:00:00 2001 From: jrp2014 Date: Sat, 24 Mar 2018 18:19:07 +0000 Subject: [PATCH] Further small refactorings, tweaks. --- include/chaiscript/dispatchkit/dispatchkit.hpp | 2 +- include/chaiscript/language/chaiscript_eval.hpp | 6 +++--- samples/example.cpp | 6 +++--- samples/factory.cpp | 2 +- samples/fun_call_performance.cpp | 3 ++- samples/inheritance.cpp | 2 +- unittests/catch.hpp | 14 +++++++------- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 112e8b7f..215cbbc1 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -1286,7 +1286,7 @@ namespace chaiscript return m_stack_holder->stacks.back(); } - parser::ChaiScript_Parser_Base &get_parser() + parser::ChaiScript_Parser_Base &get_parser() const { return m_parser.get(); } diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index ba80058b..d87ab551 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -629,7 +629,7 @@ namespace chaiscript fpp.save_params(params); try { - retval = t_ss->call_member(m_fun_name, m_loc, std::move(params), has_function_params, t_ss.conversions()); + retval = t_ss->call_member(m_fun_name, m_loc, params, has_function_params, t_ss.conversions()); } catch(const exception::dispatch_error &e){ if (e.functions.empty()) @@ -1097,7 +1097,7 @@ namespace chaiscript vec.push_back(detail::clone_if_necessary(child->eval(t_ss), m_loc, t_ss)); } } - return const_var(std::move(vec)); + return const_var(vec); } catch (const exception::dispatch_error &) { throw exception::eval_error("Can not find appropriate 'clone' or copy constructor for vector elements"); @@ -1123,7 +1123,7 @@ namespace chaiscript detail::clone_if_necessary(child->children[1]->eval(t_ss), m_loc, t_ss))); } - return const_var(std::move(retval)); + return const_var(retval); } catch (const exception::dispatch_error &e) { throw exception::eval_error("Can not find appropriate copy constructor or 'clone' while inserting into Map.", e.parameters, e.functions, false, *t_ss); diff --git a/samples/example.cpp b/samples/example.cpp index 656725d3..ed50ef30 100644 --- a/samples/example.cpp +++ b/samples/example.cpp @@ -113,7 +113,7 @@ int main(int /*argc*/, char * /*argv*/[]) { //Call bound version of do_callbacks chai("do_callbacks()"); - std::function caller = chai.eval >( + const std::function caller = chai.eval >( R"(fun() { system.do_callbacks("From Functor"); })" ); caller(); @@ -165,8 +165,8 @@ int main(int /*argc*/, char * /*argv*/[]) { chai.add(fun(&bound_log, std::string("Msg")), "BoundFun"); //Dynamic objects test - chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Function("TestType", fun(&hello_world))), "hello_world"); - chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Constructor("TestType", fun(&hello_constructor))), "TestType"); + chai.add(std::static_pointer_cast(std::make_shared("TestType", fun(&hello_world))), "hello_world"); + chai.add(std::static_pointer_cast(std::make_shared("TestType", fun(&hello_constructor))), "TestType"); // chai.add(fun(std::function(std::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", std::placeholders::_1))), "attr"); chai.eval("var x = TestType()"); diff --git a/samples/factory.cpp b/samples/factory.cpp index bb886a9a..8809727a 100644 --- a/samples/factory.cpp +++ b/samples/factory.cpp @@ -75,7 +75,7 @@ int main() Factory f{}; chai.add(chaiscript::var(&f), "f"); - std::string script = R""( + const std::string script = R""( f.make_entity(10,10,1,1,"entity1").updater = fun(e){ e.x += 1; e.y += 1 }; f.make_entity(10,10,10,10,"entity2").updater = fun(e){ e.x += 2; e.y += 2 }; f.make_entity(10,10,20,20,"entity3"); diff --git a/samples/fun_call_performance.cpp b/samples/fun_call_performance.cpp index 8e64aab1..46c9a6f2 100644 --- a/samples/fun_call_performance.cpp +++ b/samples/fun_call_performance.cpp @@ -272,6 +272,7 @@ int main(int argc, char *argv[]) #pragma warning(disable : 4996) #endif + // TODO:: Use _dupenv_s instead const char *usepath = getenv("CHAI_USE_PATH"); const char *modulepath = getenv("CHAI_MODULE_PATH"); @@ -375,7 +376,7 @@ int main(int argc, char *argv[]) mode = eFile; } - chaiscript::Boxed_Value val; /* never accessed? */ + chaiscript::Boxed_Value val; try { switch (mode) { case eInteractive: interactive(chai); break; diff --git a/samples/inheritance.cpp b/samples/inheritance.cpp index 92e320bf..0d674859 100644 --- a/samples/inheritance.cpp +++ b/samples/inheritance.cpp @@ -76,7 +76,7 @@ int main() chai.add(chaiscript::user_type(), "BaseClass"); chai.add(chaiscript::user_type(), "ChaiScriptDerived"); - std::string script = R""( + const std::string script = R""( def MakeDerived() { return ChaiScriptDerived( // create a dynamically created array and pass it in to the constructor diff --git a/unittests/catch.hpp b/unittests/catch.hpp index a5396fdb..82f06b4a 100644 --- a/unittests/catch.hpp +++ b/unittests/catch.hpp @@ -4931,17 +4931,17 @@ inline void AssertionHandler::handleExceptionNotThrownAsExpected() { m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); } - void AssertionHandler::handleUnexpectedExceptionNotThrown() { +inline void AssertionHandler::handleUnexpectedExceptionNotThrown() { m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction ); } - void AssertionHandler::handleThrowingCallSkipped() { +inline void AssertionHandler::handleThrowingCallSkipped() { m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); } // This is the overload that takes a string and infers the Equals matcher from it // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp - void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) { +inline void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) { handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); } @@ -4950,11 +4950,11 @@ inline void AssertionHandler::handleExceptionNotThrownAsExpected() { // start catch_assertionresult.cpp namespace Catch { - AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): +inline AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): lazyExpression(_lazyExpression), resultType(_resultType) {} - std::string AssertionResultData::reconstructExpression() const { +inline std::string AssertionResultData::reconstructExpression() const { if( reconstructedExpression.empty() ) { if( lazyExpression ) { @@ -4966,13 +4966,13 @@ namespace Catch { return reconstructedExpression; } - AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) +inline AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) : m_info( info ), m_resultData( data ) {} // Result was a success - bool AssertionResult::succeeded() const { +inline bool AssertionResult::succeeded() const { return Catch::isOk( m_resultData.resultType ); }