diff --git a/include/chaiscript/dispatchkit/any.hpp b/include/chaiscript/dispatchkit/any.hpp index 4d47b88..ae8035c 100644 --- a/include/chaiscript/dispatchkit/any.hpp +++ b/include/chaiscript/dispatchkit/any.hpp @@ -72,7 +72,7 @@ namespace chaiscript { { } - virtual void *data() override + void *data() override { return &m_data; } diff --git a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp index d0b7c94..8547b97 100644 --- a/include/chaiscript/dispatchkit/bad_boxed_cast.hpp +++ b/include/chaiscript/dispatchkit/bad_boxed_cast.hpp @@ -31,12 +31,12 @@ namespace chaiscript public: bad_boxed_cast(Type_Info t_from, const std::type_info &t_to, std::string t_what) noexcept - : from(std::move(t_from)), to(&t_to), m_what(std::move(t_what)) + : from(t_from), to(&t_to), m_what(std::move(t_what)) { } bad_boxed_cast(Type_Info t_from, const std::type_info &t_to) - : from(std::move(t_from)), to(&t_to), m_what("Cannot perform boxed_cast: " + t_from.name() + " to: " + t_to.name()) + : from(t_from), to(&t_to), m_what("Cannot perform boxed_cast: " + t_from.name() + " to: " + t_to.name()) { } @@ -46,10 +46,10 @@ namespace chaiscript } bad_boxed_cast(const bad_boxed_cast &) = default; - virtual ~bad_boxed_cast() noexcept = default; + ~bad_boxed_cast() noexcept override = default; /// \brief Description of what error occurred - virtual const char * what() const noexcept override + const char * what() const noexcept override { return m_what.c_str(); } diff --git a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp index 6347437..999ccf3 100644 --- a/include/chaiscript/dispatchkit/boxed_cast_helper.hpp +++ b/include/chaiscript/dispatchkit/boxed_cast_helper.hpp @@ -25,7 +25,7 @@ namespace chaiscript template T* throw_if_null(T *t) { - if (t) return t; + if (t) { return t; } throw std::runtime_error("Attempted to dereference null Boxed_Value"); } diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index 4517de2..fe4abfc 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -30,7 +30,7 @@ namespace chaiscript { arithmetic_error(const std::string& reason) : std::runtime_error("Arithmetic error: " + reason) {} arithmetic_error(const arithmetic_error &) = default; - virtual ~arithmetic_error() noexcept = default; + ~arithmetic_error() noexcept override = default; }; } } diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 70a1b96..16595cd 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -54,7 +54,7 @@ namespace chaiscript if (rhs.m_attrs) { - m_attrs = std::unique_ptr>>(new std::map>(*rhs.m_attrs)); + m_attrs = std::make_unique>>(*rhs.m_attrs); } return *this; @@ -302,7 +302,7 @@ namespace chaiscript { if (!m_data->m_attrs) { - m_data->m_attrs = std::unique_ptr>>(new std::map>()); + m_data->m_attrs = std::make_unique>>(); } auto &attr = (*m_data->m_attrs)[t_name]; @@ -319,7 +319,7 @@ namespace chaiscript { if (t_obj.m_data->m_attrs) { - m_data->m_attrs = std::unique_ptr>>(new std::map>(*t_obj.m_data->m_attrs)); + m_data->m_attrs = std::make_unique>>(*t_obj.m_data->m_attrs); } return *this; } @@ -342,8 +342,8 @@ namespace chaiscript // necessary to avoid hitting the templated && constructor of Boxed_Value struct Internal_Construction{}; - Boxed_Value(const std::shared_ptr &t_data, Internal_Construction) - : m_data(t_data) { + Boxed_Value(std::shared_ptr t_data, Internal_Construction) + : m_data(std::move(t_data)) { } std::shared_ptr m_data = Object_Data::get(); diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index eab58b9..0d86744 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -67,7 +67,7 @@ namespace chaiscript reserved_word_error(const reserved_word_error &) = default; - virtual ~reserved_word_error() noexcept = default; + ~reserved_word_error() noexcept override = default; std::string word() const { @@ -89,7 +89,7 @@ namespace chaiscript illegal_name_error(const illegal_name_error &) = default; - virtual ~illegal_name_error() noexcept = default; + ~illegal_name_error() noexcept override = default; std::string name() const { @@ -112,7 +112,7 @@ namespace chaiscript name_conflict_error(const name_conflict_error &) = default; - virtual ~name_conflict_error() noexcept = default; + ~name_conflict_error() noexcept override = default; std::string name() const { @@ -135,7 +135,7 @@ namespace chaiscript } global_non_const(const global_non_const &) = default; - virtual ~global_non_const() noexcept = default; + ~global_non_const() noexcept override = default; }; } @@ -147,7 +147,7 @@ namespace chaiscript public: Module &add(Type_Info ti, std::string name) { - m_typeinfos.emplace_back(std::move(ti), std::move(name)); + m_typeinfos.emplace_back(ti, std::move(name)); return *this; } @@ -356,7 +356,7 @@ namespace chaiscript ++begin; } - assert(type_infos.size() > 0 && " type_info vector size is < 0, this is only possible if something else is broken"); + assert(!type_infos.empty() && " type_info vector size is < 0, this is only possible if something else is broken"); if (size_mismatch) { @@ -681,7 +681,7 @@ namespace chaiscript } t_loc = static_cast(Loc::located); - } else if (loc & static_cast(Loc::is_local)) { + } else if ((loc & static_cast(Loc::is_local)) != 0u) { auto &stack = get_stack_data(t_holder); return stack[stack.size() - 1 - ((loc & static_cast(Loc::stack_mask)) >> 16)][loc & static_cast(Loc::loc_mask)].second; @@ -698,9 +698,9 @@ namespace chaiscript // no? is it a function object? auto obj = get_function_object_int(name, loc); - if (obj.first != loc) t_loc = uint_fast32_t(obj.first); - return obj.second; + if (obj.first != loc) { t_loc = uint_fast32_t(obj.first); } + return obj.second; } @@ -763,7 +763,10 @@ namespace chaiscript { uint_fast32_t method_missing_loc = m_method_missing_loc; auto method_missing_funs = get_function("method_missing", method_missing_loc); - if (method_missing_funs.first != method_missing_loc) m_method_missing_loc = uint_fast32_t(method_missing_funs.first); + if (method_missing_funs.first != method_missing_loc) { + m_method_missing_loc = uint_fast32_t(method_missing_funs.first); + } + return std::move(method_missing_funs.second); } @@ -954,7 +957,7 @@ namespace chaiscript { uint_fast32_t loc = t_loc; const auto funs = get_function(t_name, loc); - if (funs.first != loc) t_loc = uint_fast32_t(funs.first); + if (funs.first != loc) { t_loc = uint_fast32_t(funs.first); } const auto do_attribute_call = [this](int l_num_params, const std::vector &l_params, const std::vector &l_funs, const Type_Conversions_State &l_conversions)->Boxed_Value @@ -1074,7 +1077,8 @@ namespace chaiscript { uint_fast32_t loc = t_loc; const auto funs = get_function(t_name, loc); - if (funs.first != loc) t_loc = uint_fast32_t(funs.first); + if (funs.first != loc) { t_loc = uint_fast32_t(funs.first); +} return dispatch::dispatch(*funs.second, params, t_conversions); } @@ -1198,7 +1202,7 @@ namespace chaiscript static void save_function_params(Stack_Holder &t_s, std::initializer_list t_params) { - t_s.call_params.back().insert(t_s.call_params.back().begin(), std::move(t_params)); + t_s.call_params.back().insert(t_s.call_params.back().begin(), t_params); } static void save_function_params(Stack_Holder &t_s, std::vector &&t_params) @@ -1216,7 +1220,7 @@ namespace chaiscript void save_function_params(std::initializer_list t_params) { - save_function_params(*m_stack_holder, std::move(t_params)); + save_function_params(*m_stack_holder, t_params); } void save_function_params(std::vector &&t_params) diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index e89d380..557a9d5 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -33,7 +33,7 @@ namespace chaiscript option_explicit_set(const option_explicit_set &) = default; - virtual ~option_explicit_set() noexcept = default; + ~option_explicit_set() noexcept override = default; }; class Dynamic_Object diff --git a/include/chaiscript/dispatchkit/dynamic_object_detail.hpp b/include/chaiscript/dispatchkit/dynamic_object_detail.hpp index 93031cf..8fbc373 100644 --- a/include/chaiscript/dispatchkit/dynamic_object_detail.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object_detail.hpp @@ -99,7 +99,7 @@ namespace chaiscript } protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions_State &t_conversions) const override + Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions_State &t_conversions) const override { if (dynamic_object_typename_match(params, m_type_name, m_ti, t_conversions)) { @@ -109,7 +109,7 @@ namespace chaiscript } } - virtual bool compare_first_type(const Boxed_Value &bv, const Type_Conversions_State &t_conversions) const override + bool compare_first_type(const Boxed_Value &bv, const Type_Conversions_State &t_conversions) const override { return dynamic_object_typename_match(bv, m_type_name, m_ti, t_conversions); } @@ -151,7 +151,7 @@ namespace chaiscript bool dynamic_object_typename_match(const std::vector &bvs, const std::string &name, const std::unique_ptr &ti, const Type_Conversions_State &t_conversions) const { - if (bvs.size() > 0) + if (!bvs.empty()) { return dynamic_object_typename_match(bvs[0], name, ti, t_conversions); } else { @@ -202,7 +202,7 @@ namespace chaiscript bool operator==(const Proxy_Function_Base &f) const override { const Dynamic_Object_Constructor *dc = dynamic_cast(&f); - return dc && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func); + return (dc != nullptr) && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func); } bool call_match(const std::vector &vals, const Type_Conversions_State &t_conversions) const override diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index 8ed6115..93e3e61 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -33,7 +33,7 @@ namespace chaiscript static Ret call(const std::vector &t_funcs, const std::vector ¶ms, const Type_Conversions_State *t_conversions) { - if (t_conversions) { + if (t_conversions != nullptr) { return boxed_cast(dispatch::dispatch(t_funcs, params, *t_conversions), t_conversions); } else { Type_Conversions conv; @@ -52,7 +52,7 @@ namespace chaiscript static Ret call(const std::vector &t_funcs, const std::vector ¶ms, const Type_Conversions_State *t_conversions) { - if (t_conversions) { + if (t_conversions != nullptr) { return Boxed_Number(dispatch::dispatch(t_funcs, params, *t_conversions)).get_as(); } else { Type_Conversions conv; @@ -72,7 +72,7 @@ namespace chaiscript static void call(const std::vector &t_funcs, const std::vector ¶ms, const Type_Conversions_State *t_conversions) { - if (t_conversions) { + if (t_conversions != nullptr) { dispatch::dispatch(t_funcs, params, *t_conversions); } else { Type_Conversions conv; diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index e9f803d..b24b000 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -63,7 +63,7 @@ namespace chaiscript void push_front(std::string t_name, Type_Info t_ti) { - m_types.emplace(m_types.begin(), std::move(t_name), std::move(t_ti)); + m_types.emplace(m_types.begin(), std::move(t_name), t_ti); update_has_types(); } @@ -74,8 +74,8 @@ namespace chaiscript bool match(const std::vector &vals, const Type_Conversions_State &t_conversions) const { - if (!m_has_types) return true; - if (vals.size() != m_types.size()) return false; + if (!m_has_types) { return true; } + if (vals.size() != m_types.size()) { return false; } for (size_t i = 0; i < vals.size(); ++i) { @@ -282,7 +282,7 @@ namespace chaiscript guard_error(const guard_error &) = default; - virtual ~guard_error() noexcept = default; + ~guard_error() noexcept override = default; }; } @@ -307,18 +307,18 @@ namespace chaiscript } - virtual bool operator==(const Proxy_Function_Base &rhs) const override + bool operator==(const Proxy_Function_Base &rhs) const override { const Dynamic_Proxy_Function *prhs = dynamic_cast(&rhs); return this == &rhs - || (prhs + || ((prhs != nullptr) && this->m_arity == prhs->m_arity && !this->m_guard && !prhs->m_guard && this->m_param_types == prhs->m_param_types); } - virtual bool call_match(const std::vector &vals, const Type_Conversions_State &t_conversions) const override + bool call_match(const std::vector &vals, const Type_Conversions_State &t_conversions) const override { return (m_arity < 0 || (vals.size() == size_t(m_arity) && m_param_types.match(vals, t_conversions))) && test_guard(vals, t_conversions); @@ -516,7 +516,7 @@ namespace chaiscript return retval; } - virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions_State &t_conversions) const override + Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions_State &t_conversions) const override { return (*m_f)(build_param_list(params), t_conversions); } @@ -742,7 +742,7 @@ namespace chaiscript dispatch_error(const dispatch_error &) = default; - virtual ~dispatch_error() noexcept = default; + ~dispatch_error() noexcept override = default; std::vector parameters; std::vector functions; @@ -759,7 +759,7 @@ namespace chaiscript { const std::vector &types = t_func->get_param_types(); - if (t_func->get_arity() == -1) return false; + if (t_func->get_arity() == -1) { return false; } assert(plist.size() == types.size() - 1); diff --git a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp index 8258521..f00eeef 100644 --- a/include/chaiscript/dispatchkit/proxy_functions_detail.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions_detail.hpp @@ -44,7 +44,7 @@ namespace chaiscript arity_error(const arity_error &) = default; - virtual ~arity_error() noexcept {} + ~arity_error() noexcept override = default; int got; int expected; diff --git a/include/chaiscript/dispatchkit/short_alloc.hpp b/include/chaiscript/dispatchkit/short_alloc.hpp index 3cb0422..0805587 100644 --- a/include/chaiscript/dispatchkit/short_alloc.hpp +++ b/include/chaiscript/dispatchkit/short_alloc.hpp @@ -84,12 +84,14 @@ arena::deallocate(char* p, std::size_t n) noexcept assert(pointer_in_buffer(ptr_) && "short_alloc has outlived arena"); if (pointer_in_buffer(p)) { - n = align_up(n); - if (p + n == ptr_) - ptr_ = p; + n = align_up(n); + if (p + n == ptr_) { + ptr_ = p; + } + } + else { + ::operator delete(p); } - else - ::operator delete(p); } template diff --git a/include/chaiscript/dispatchkit/type_conversions.hpp b/include/chaiscript/dispatchkit/type_conversions.hpp index 6660b25..5572bc4 100644 --- a/include/chaiscript/dispatchkit/type_conversions.hpp +++ b/include/chaiscript/dispatchkit/type_conversions.hpp @@ -46,7 +46,7 @@ namespace chaiscript bad_boxed_dynamic_cast(const bad_boxed_dynamic_cast &) = default; - virtual ~bad_boxed_dynamic_cast() noexcept = default; + ~bad_boxed_dynamic_cast() noexcept override = default; }; class bad_boxed_type_cast : public bad_boxed_cast @@ -70,7 +70,7 @@ namespace chaiscript bad_boxed_type_cast(const bad_boxed_type_cast &) = default; - virtual ~bad_boxed_type_cast() noexcept = default; + ~bad_boxed_type_cast() noexcept override = default; }; } @@ -100,8 +100,8 @@ namespace chaiscript virtual ~Type_Conversion_Base() = default; protected: - Type_Conversion_Base(const Type_Info &t_to, const Type_Info &t_from) - : m_to(t_to), m_from(t_from) + Type_Conversion_Base(Type_Info t_to, Type_Info t_from) + : m_to(std::move(t_to)), m_from(std::move(t_from)) { } @@ -286,7 +286,7 @@ namespace chaiscript { public: Type_Conversion_Impl(Type_Info t_from, Type_Info t_to, Callable t_func) - : Type_Conversion_Base(std::move(t_to), std::move(t_from)), + : Type_Conversion_Base(t_to, t_from), m_func(std::move(t_func)) { } @@ -302,7 +302,7 @@ namespace chaiscript return m_func(t_from); } - virtual bool bidir() const override + bool bidir() const override { return false; } @@ -399,7 +399,7 @@ namespace chaiscript { try { Boxed_Value ret = get_conversion(user_type(), from.get_type_info())->convert(from); - if (t_saves.enabled) t_saves.saves.push_back(ret); + if (t_saves.enabled) { t_saves.saves.push_back(ret); } return ret; } catch (const std::out_of_range &) { throw exception::bad_boxed_dynamic_cast(from.get_type_info(), typeid(To), "No known conversion"); @@ -413,7 +413,7 @@ namespace chaiscript { try { Boxed_Value ret = get_conversion(to.get_type_info(), user_type())->convert_down(to); - if (t_saves.enabled) t_saves.saves.push_back(ret); + if (t_saves.enabled) { t_saves.saves.push_back(ret); } return ret; } catch (const std::out_of_range &) { throw exception::bad_boxed_dynamic_cast(to.get_type_info(), typeid(From), "No known conversion"); diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index 7a70892..9898d6d 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -72,7 +72,7 @@ namespace chaiscript namespace { /// Helper lookup to get the name of each node type - const char *ast_node_type_to_string(AST_Node_Type ast_node_type) { + inline const char *ast_node_type_to_string(AST_Node_Type ast_node_type) { static const char * const ast_node_types[] = { "Id", "Fun_Call", "Unused_Return_Fun_Call", "Arg_List", "Equation", "Var_Decl", "Array_Call", "Dot_Access", "Lambda", "Block", "Scopeless_Block", "Def", "While", "If", "For", "Ranged_For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Continue", "Map_Pair", "Value_Range", @@ -141,7 +141,7 @@ namespace chaiscript } load_module_error(const load_module_error &) = default; - virtual ~load_module_error() noexcept = default; + ~load_module_error() noexcept override = default; static std::string format_error(const std::string &t_name, const std::vector &t_errors) { @@ -200,7 +200,7 @@ namespace chaiscript std::ostringstream ss; ss << what(); - if (call_stack.size() > 0) { + if (!call_stack.empty()) { ss << "during evaluation at (" << fname(call_stack[0]) << " " << startpos(call_stack[0]) << ")\n"; ss << '\n' << detail << '\n'; ss << " " << fname(call_stack[0]) << " (" << startpos(call_stack[0]) << ") '" << pretty(call_stack[0]) << "'"; @@ -217,7 +217,7 @@ namespace chaiscript return ss.str(); } - virtual ~eval_error() noexcept = default; + ~eval_error() noexcept override = default; private: @@ -481,7 +481,7 @@ namespace chaiscript { } file_not_found_error(const file_not_found_error &) = default; - virtual ~file_not_found_error() noexcept {} + ~file_not_found_error() noexcept override = default; }; } @@ -603,13 +603,13 @@ namespace chaiscript /// Special type indicating a call to 'break' struct Break_Loop { - Break_Loop() { } + Break_Loop() = default; }; /// Special type indicating a call to 'continue' struct Continue_Loop { - Continue_Loop() { } + Continue_Loop() = default; }; @@ -663,7 +663,7 @@ namespace chaiscript void save_params(std::initializer_list t_params) { - m_ds->save_function_params(std::move(t_params)); + m_ds->save_function_params(t_params); } diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index a582dc2..36567fd 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -255,7 +255,7 @@ namespace chaiscript memset( &rInfo, 0, sizeof(rInfo) ); cast_union u; u.in_ptr = &ChaiScript_Basic::use; - if ( dladdr(static_cast(u.out_ptr), &rInfo) && rInfo.dli_fname ) { + if ( (dladdr(static_cast(u.out_ptr), &rInfo) != 0) && (rInfo.dli_fname != nullptr) ) { std::string dllpath(rInfo.dli_fname); const size_t lastslash = dllpath.rfind('/'); if (lastslash != std::string::npos) diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index bc80b79..722fe67 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -64,7 +64,7 @@ namespace chaiscript }(); chaiscript::eval::detail::Stack_Push_Pop tpp(state); - if (thisobj) state.add_object("this", *thisobj); + if (thisobj) { state.add_object("this", *thisobj); } if (t_locals) { for (const auto &local : *t_locals) { @@ -91,7 +91,7 @@ namespace chaiscript { AST_Node_Impl(std::string t_ast_node_text, AST_Node_Type t_id, Parse_Location t_loc, std::vector> t_children = std::vector>()) - : AST_Node(std::move(t_ast_node_text), std::move(t_id), std::move(t_loc)), + : AST_Node(std::move(t_ast_node_text), t_id, std::move(t_loc)), children(std::move(t_children)) { } @@ -851,7 +851,7 @@ namespace chaiscript const auto get_function = [&t_ss](const std::string &t_name, auto &t_hint){ uint_fast32_t hint = t_hint; auto funs = t_ss->get_function(t_name, hint); - if (funs.first != hint) t_hint = uint_fast32_t(funs.first); + if (funs.first != hint) { t_hint = uint_fast32_t(funs.first); } return std::move(funs.second); }; diff --git a/include/chaiscript/language/chaiscript_optimizer.hpp b/include/chaiscript/language/chaiscript_optimizer.hpp index 125782b..c7dd265 100644 --- a/include/chaiscript/language/chaiscript_optimizer.hpp +++ b/include/chaiscript/language/chaiscript_optimizer.hpp @@ -165,7 +165,7 @@ namespace chaiscript { auto optimize(const eval::AST_Node_Impl_Ptr &node) { if ((node->identifier == AST_Node_Type::Block || node->identifier == AST_Node_Type::Scopeless_Block) - && node->children.size() > 0) + && !node->children.empty()) { for (size_t i = 0; i < node->children.size()-1; ++i) { auto child = node->children[i]; diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index 9eafa03..75dce56 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -243,7 +243,7 @@ namespace chaiscript Position() = default; Position(std::string::const_iterator t_pos, std::string::const_iterator t_end) - : line(1), col(1), m_pos(std::move(t_pos)), m_end(std::move(t_end)), m_last_col(1) + : line(1), col(1), m_pos(t_pos), m_end(t_end), m_last_col(1) { } @@ -868,7 +868,7 @@ namespace chaiscript }(); m_match_stack.push_back(make_node>(text, start.line, start.col, - const_var(std::move(fun_name)))); + const_var(fun_name))); } else if (text == "__CLASS__") { const std::string fun_name = [&]()->std::string{ for (size_t idx = m_match_stack.size() - 1; idx > 1; --idx) @@ -883,7 +883,7 @@ namespace chaiscript }(); m_match_stack.push_back(make_node>(text, start.line, start.col, - const_var(std::move(fun_name)))); + const_var(fun_name))); } else if (text == "_") { m_match_stack.push_back(make_node>(text, start.line, start.col, Boxed_Value(std::make_shared()))); @@ -1009,7 +1009,7 @@ namespace chaiscript void process_hex() { - auto val = stoll(hex_matches, 0, 16); + auto val = stoll(hex_matches, nullptr, 16); match.push_back(char_type(val)); hex_matches.clear(); is_escaped = false; @@ -1019,7 +1019,7 @@ namespace chaiscript void process_octal() { - auto val = stoll(octal_matches, 0, 8); + auto val = stoll(octal_matches, nullptr, 8); match.push_back(char_type(val)); octal_matches.clear(); is_escaped = false; @@ -1029,7 +1029,7 @@ namespace chaiscript void process_unicode() { - auto val = stoll(hex_matches, 0, 16); + auto val = stoll(hex_matches, nullptr, 16); hex_matches.clear(); match += detail::Char_Parser_Helper::str_from_ll(val); is_escaped = false; @@ -2072,17 +2072,21 @@ namespace chaiscript /// \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) { - if (m_match_stack.empty()) throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); - if (m_match_stack.back()->children.empty()) throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); + if (m_match_stack.empty()) { throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); +} + if (m_match_stack.back()->children.empty()) { throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); +} auto dot_access = m_match_stack.back()->children[0]; auto func_call = m_match_stack.back(); m_match_stack.pop_back(); func_call->children.erase(func_call->children.begin()); - if (dot_access->children.empty()) throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); + if (dot_access->children.empty()) { throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); +} func_call->children.insert(func_call->children.begin(), dot_access->children.back()); dot_access->children.pop_back(); dot_access->children.push_back(std::move(func_call)); - if (dot_access->children.size() != 2) throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); + if (dot_access->children.size() != 2) { throw exception::eval_error("Incomplete dot access fun call", File_Position(m_position.line, m_position.col), *m_filename); +} m_match_stack.push_back(std::move(dot_access)); } } @@ -2192,7 +2196,7 @@ namespace chaiscript if (!Char(']')) { throw exception::eval_error("Missing closing square bracket ']' in container initializer", File_Position(m_position.line, m_position.col), *m_filename); } - if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) { + if ((prev_stack_top != m_match_stack.size()) && (!m_match_stack.back()->children.empty())) { if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) { build_match>(prev_stack_top); } diff --git a/include/chaiscript/language/chaiscript_posix.hpp b/include/chaiscript/language/chaiscript_posix.hpp index c22fe87..f6caec0 100644 --- a/include/chaiscript/language/chaiscript_posix.hpp +++ b/include/chaiscript/language/chaiscript_posix.hpp @@ -18,7 +18,7 @@ namespace chaiscript DLModule(const std::string &t_filename) : m_data(dlopen(t_filename.c_str(), RTLD_NOW)) { - if (!m_data) + if (m_data == nullptr) { throw chaiscript::exception::load_module_error(dlerror()); } diff --git a/include/chaiscript/utility/json.hpp b/include/chaiscript/utility/json.hpp index 561b93e..96decc0 100644 --- a/include/chaiscript/utility/json.hpp +++ b/include/chaiscript/utility/json.hpp @@ -386,12 +386,12 @@ class JSON return "null"; case Class::Object: { std::string pad = ""; - for( long i = 0; i < depth; ++i, pad += tab ); + for( long i = 0; i < depth; ++i, pad += tab ) { } std::string s = "{\n"; bool skip = true; for( auto &p : *internal.Map ) { - if( !skip ) s += ",\n"; + if( !skip ) { s += ",\n"; } s += ( pad + "\"" + p.first + "\" : " + p.second.dump( depth + 1, tab ) ); skip = false; } @@ -402,7 +402,7 @@ class JSON std::string s = "["; bool skip = true; for( auto &p : *internal.List ) { - if( !skip ) s += ", "; + if( !skip ) { s += ", "; } s += p.dump( depth + 1, tab ); skip = false; } @@ -426,8 +426,8 @@ class JSON private: static std::string json_escape( const std::string &str ) { std::string output; - for( size_t i = 0; i < str.length(); ++i ) - switch( str[i] ) { + for(char i : str) { + switch( i ) { case '\"': output += "\\\""; break; case '\\': output += "\\\\"; break; case '\b': output += "\\b"; break; @@ -435,8 +435,9 @@ class JSON case '\n': output += "\\n"; break; case '\r': output += "\\r"; break; case '\t': output += "\\t"; break; - default : output += str[i]; break; + default : output += i; break; } +} return output; } @@ -462,7 +463,7 @@ struct JSONParser { } static void consume_ws( const std::string &str, size_t &offset ) { - while( isspace( str[offset] ) && offset <= str.size() ) ++offset; + while( isspace( str[offset] ) && offset <= str.size() ) { ++offset; } } static JSON parse_object( const std::string &str, size_t &offset ) { @@ -544,9 +545,9 @@ struct JSONParser { val += "\\u" ; for( size_t i = 1; i <= 4; ++i ) { c = str[offset+i]; - if( (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ) + if( (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') ) { val += c; - else { + } else { throw std::runtime_error(std::string("JSON ERROR: String: Expected hex character in unicode escape, found '") + c + "'"); } } @@ -554,9 +555,9 @@ struct JSONParser { } break; default : val += '\\'; break; } - } - else + } else { val += c; + } } ++offset; return JSON(val); @@ -569,30 +570,35 @@ struct JSONParser { long exp = 0; for (; offset < str.size() ;) { c = str[offset++]; - if( (c == '-') || (c >= '0' && c <= '9') ) + if( (c == '-') || (c >= '0' && c <= '9') ) { val += c; - else if( c == '.' ) { + } else if( c == '.' ) { val += c; isDouble = true; - } - else + } else { break; + } } if( offset < str.size() && (c == 'E' || c == 'e' )) { c = str[ offset++ ]; - if( c == '-' ) { exp_str += '-';} - else if( c == '+' ) { } - else --offset; + if( c == '-' ) { + exp_str += '-'; + } else if( c == '+' ) { + // do nothing + } else { + --offset; + } for (; offset < str.size() ;) { c = str[ offset++ ]; - if( c >= '0' && c <= '9' ) + if( c >= '0' && c <= '9' ) { exp_str += c; - else if( !isspace( c ) && c != ',' && c != ']' && c != '}' ) { + } else if( !isspace( c ) && c != ',' && c != ']' && c != '}' ) { throw std::runtime_error(std::string("JSON ERROR: Number: Expected a number for exponent, found '") + c + "'"); } - else + else { break; +} } exp = chaiscript::parse_num( exp_str ); } @@ -643,8 +649,9 @@ struct JSONParser { case 't' : case 'f' : return parse_bool( str, offset ); case 'n' : return parse_null( str, offset ); - default : if( ( value <= '9' && value >= '0' ) || value == '-' ) + default : if( ( value <= '9' && value >= '0' ) || value == '-' ) { return parse_number( str, offset ); + } } throw std::runtime_error(std::string("JSON ERROR: Parse: Unexpected starting character '") + value + "'"); } diff --git a/src/main.cpp b/src/main.cpp index 61ca7c1..ae2d490 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,7 +25,7 @@ char *mystrdup (const char *s) { size_t len = strlen(s); // Space for length plus nul char *d = static_cast(malloc (len+1)); - if (d == nullptr) return nullptr; // No memory + if (d == nullptr) { return nullptr; } // No memory #ifdef CHAISCRIPT_MSVC strcpy_s(d, len+1, s); // Copy the characters #else @@ -44,7 +44,7 @@ char* readline(const char* p) } -void add_history(const char*){} +void add_history(const char* /*unused*/){} void using_history(){} #endif @@ -116,7 +116,7 @@ std::vector default_search_paths() { Dl_info rInfo; memset( &rInfo, 0, sizeof(rInfo) ); - if ( !dladdr(cast_module_symbol(&default_search_paths), &rInfo) || !rInfo.dli_fname ) { + if ( dladdr(cast_module_symbol(&default_search_paths), &rInfo) == 0 || rInfo.dli_fname == nullptr ) { return paths; } @@ -184,7 +184,7 @@ std::string get_next_command() { std::string retval("quit"); if ( ! std::cin.eof() ) { char *input_raw = readline("eval> "); - if ( input_raw ) { + if ( input_raw != nullptr ) { add_history(input_raw); std::string val(input_raw); @@ -240,7 +240,7 @@ void interactive(chaiscript::ChaiScript_Basic& chai) } catch (const chaiscript::exception::eval_error &ee) { std::cout << ee.what(); - if (ee.call_stack.size() > 0) { + if ( !ee.call_stack.empty() ) { std::cout << "during evaluation at (" << ee.call_stack[0]->start().line << ", " << ee.call_stack[0]->start().column << ")"; } std::cout << '\n'; @@ -277,7 +277,7 @@ int main(int argc, char *argv[]) std::vector usepaths; usepaths.push_back(""); - if (usepath) + if (usepath != nullptr) { usepaths.push_back(usepath); } @@ -286,7 +286,7 @@ int main(int argc, char *argv[]) std::vector searchpaths = default_search_paths(); modulepaths.insert(modulepaths.end(), searchpaths.begin(), searchpaths.end()); modulepaths.push_back(""); - if (modulepath) + if (modulepath != nullptr) { modulepaths.push_back(modulepath); } @@ -308,7 +308,7 @@ int main(int argc, char *argv[]) ++i; } - std::string arg( i ? argv[i] : "--interactive" ); + std::string arg( i != 0 ? argv[i] : "--interactive" ); enum { eInteractive , eCommand @@ -319,9 +319,9 @@ int main(int argc, char *argv[]) if ( (i+1) >= argc ) { std::cout << "insufficient input following " << arg << '\n'; return EXIT_FAILURE; - } else { + } arg = argv[++i]; - } + } else if ( arg == "-" || arg == "--stdin" ) { arg = "" ; std::string line;