Some cleanups found by clang's analyzer
This commit is contained in:
parent
359897a442
commit
b1f1803759
@ -72,7 +72,7 @@ namespace chaiscript {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void *data() override
|
void *data() override
|
||||||
{
|
{
|
||||||
return &m_data;
|
return &m_data;
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,12 @@ namespace chaiscript
|
|||||||
public:
|
public:
|
||||||
bad_boxed_cast(Type_Info t_from, const std::type_info &t_to,
|
bad_boxed_cast(Type_Info t_from, const std::type_info &t_to,
|
||||||
std::string t_what) noexcept
|
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)
|
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;
|
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
|
/// \brief Description of what error occurred
|
||||||
virtual const char * what() const noexcept override
|
const char * what() const noexcept override
|
||||||
{
|
{
|
||||||
return m_what.c_str();
|
return m_what.c_str();
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
T* throw_if_null(T *t)
|
T* throw_if_null(T *t)
|
||||||
{
|
{
|
||||||
if (t) return t;
|
if (t) { return t; }
|
||||||
throw std::runtime_error("Attempted to dereference null Boxed_Value");
|
throw std::runtime_error("Attempted to dereference null Boxed_Value");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
arithmetic_error(const std::string& reason) : std::runtime_error("Arithmetic error: " + reason) {}
|
arithmetic_error(const std::string& reason) : std::runtime_error("Arithmetic error: " + reason) {}
|
||||||
arithmetic_error(const arithmetic_error &) = default;
|
arithmetic_error(const arithmetic_error &) = default;
|
||||||
virtual ~arithmetic_error() noexcept = default;
|
~arithmetic_error() noexcept override = default;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
if (rhs.m_attrs)
|
if (rhs.m_attrs)
|
||||||
{
|
{
|
||||||
m_attrs = std::unique_ptr<std::map<std::string, std::shared_ptr<Data>>>(new std::map<std::string, std::shared_ptr<Data>>(*rhs.m_attrs));
|
m_attrs = std::make_unique<std::map<std::string, std::shared_ptr<Data>>>(*rhs.m_attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -302,7 +302,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
if (!m_data->m_attrs)
|
if (!m_data->m_attrs)
|
||||||
{
|
{
|
||||||
m_data->m_attrs = std::unique_ptr<std::map<std::string, std::shared_ptr<Data>>>(new std::map<std::string, std::shared_ptr<Data>>());
|
m_data->m_attrs = std::make_unique<std::map<std::string, std::shared_ptr<Data>>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &attr = (*m_data->m_attrs)[t_name];
|
auto &attr = (*m_data->m_attrs)[t_name];
|
||||||
@ -319,7 +319,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
if (t_obj.m_data->m_attrs)
|
if (t_obj.m_data->m_attrs)
|
||||||
{
|
{
|
||||||
m_data->m_attrs = std::unique_ptr<std::map<std::string, std::shared_ptr<Data>>>(new std::map<std::string, std::shared_ptr<Data>>(*t_obj.m_data->m_attrs));
|
m_data->m_attrs = std::make_unique<std::map<std::string, std::shared_ptr<Data>>>(*t_obj.m_data->m_attrs);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -342,8 +342,8 @@ namespace chaiscript
|
|||||||
// necessary to avoid hitting the templated && constructor of Boxed_Value
|
// necessary to avoid hitting the templated && constructor of Boxed_Value
|
||||||
struct Internal_Construction{};
|
struct Internal_Construction{};
|
||||||
|
|
||||||
Boxed_Value(const std::shared_ptr<Data> &t_data, Internal_Construction)
|
Boxed_Value(std::shared_ptr<Data> t_data, Internal_Construction)
|
||||||
: m_data(t_data) {
|
: m_data(std::move(t_data)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Data> m_data = Object_Data::get();
|
std::shared_ptr<Data> m_data = Object_Data::get();
|
||||||
|
@ -67,7 +67,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
reserved_word_error(const reserved_word_error &) = default;
|
reserved_word_error(const reserved_word_error &) = default;
|
||||||
|
|
||||||
virtual ~reserved_word_error() noexcept = default;
|
~reserved_word_error() noexcept override = default;
|
||||||
|
|
||||||
std::string word() const
|
std::string word() const
|
||||||
{
|
{
|
||||||
@ -89,7 +89,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
illegal_name_error(const illegal_name_error &) = default;
|
illegal_name_error(const illegal_name_error &) = default;
|
||||||
|
|
||||||
virtual ~illegal_name_error() noexcept = default;
|
~illegal_name_error() noexcept override = default;
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
{
|
{
|
||||||
@ -112,7 +112,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
name_conflict_error(const name_conflict_error &) = default;
|
name_conflict_error(const name_conflict_error &) = default;
|
||||||
|
|
||||||
virtual ~name_conflict_error() noexcept = default;
|
~name_conflict_error() noexcept override = default;
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
{
|
{
|
||||||
@ -135,7 +135,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
global_non_const(const global_non_const &) = default;
|
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:
|
public:
|
||||||
Module &add(Type_Info ti, std::string name)
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ namespace chaiscript
|
|||||||
++begin;
|
++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)
|
if (size_mismatch)
|
||||||
{
|
{
|
||||||
@ -681,7 +681,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
t_loc = static_cast<uint_fast32_t>(Loc::located);
|
t_loc = static_cast<uint_fast32_t>(Loc::located);
|
||||||
} else if (loc & static_cast<uint_fast32_t>(Loc::is_local)) {
|
} else if ((loc & static_cast<uint_fast32_t>(Loc::is_local)) != 0u) {
|
||||||
auto &stack = get_stack_data(t_holder);
|
auto &stack = get_stack_data(t_holder);
|
||||||
|
|
||||||
return stack[stack.size() - 1 - ((loc & static_cast<uint_fast32_t>(Loc::stack_mask)) >> 16)][loc & static_cast<uint_fast32_t>(Loc::loc_mask)].second;
|
return stack[stack.size() - 1 - ((loc & static_cast<uint_fast32_t>(Loc::stack_mask)) >> 16)][loc & static_cast<uint_fast32_t>(Loc::loc_mask)].second;
|
||||||
@ -698,9 +698,9 @@ namespace chaiscript
|
|||||||
|
|
||||||
// no? is it a function object?
|
// no? is it a function object?
|
||||||
auto obj = get_function_object_int(name, loc);
|
auto obj = get_function_object_int(name, loc);
|
||||||
if (obj.first != loc) t_loc = uint_fast32_t(obj.first);
|
if (obj.first != loc) { t_loc = uint_fast32_t(obj.first); }
|
||||||
return obj.second;
|
|
||||||
|
|
||||||
|
return obj.second;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,7 +763,10 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
uint_fast32_t method_missing_loc = m_method_missing_loc;
|
uint_fast32_t method_missing_loc = m_method_missing_loc;
|
||||||
auto method_missing_funs = get_function("method_missing", 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);
|
return std::move(method_missing_funs.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -954,7 +957,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
uint_fast32_t loc = t_loc;
|
uint_fast32_t loc = t_loc;
|
||||||
const auto funs = get_function(t_name, 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 =
|
const auto do_attribute_call =
|
||||||
[this](int l_num_params, const std::vector<Boxed_Value> &l_params, const std::vector<Proxy_Function> &l_funs, const Type_Conversions_State &l_conversions)->Boxed_Value
|
[this](int l_num_params, const std::vector<Boxed_Value> &l_params, const std::vector<Proxy_Function> &l_funs, const Type_Conversions_State &l_conversions)->Boxed_Value
|
||||||
@ -1074,7 +1077,8 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
uint_fast32_t loc = t_loc;
|
uint_fast32_t loc = t_loc;
|
||||||
const auto funs = get_function(t_name, 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);
|
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<Boxed_Value> t_params)
|
static void save_function_params(Stack_Holder &t_s, std::initializer_list<Boxed_Value> 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<Boxed_Value> &&t_params)
|
static void save_function_params(Stack_Holder &t_s, std::vector<Boxed_Value> &&t_params)
|
||||||
@ -1216,7 +1220,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
void save_function_params(std::initializer_list<Boxed_Value> t_params)
|
void save_function_params(std::initializer_list<Boxed_Value> 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<Boxed_Value> &&t_params)
|
void save_function_params(std::vector<Boxed_Value> &&t_params)
|
||||||
|
@ -33,7 +33,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
option_explicit_set(const option_explicit_set &) = default;
|
option_explicit_set(const option_explicit_set &) = default;
|
||||||
|
|
||||||
virtual ~option_explicit_set() noexcept = default;
|
~option_explicit_set() noexcept override = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Dynamic_Object
|
class Dynamic_Object
|
||||||
|
@ -99,7 +99,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
||||||
{
|
{
|
||||||
if (dynamic_object_typename_match(params, m_type_name, m_ti, t_conversions))
|
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);
|
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<Boxed_Value> &bvs, const std::string &name,
|
bool dynamic_object_typename_match(const std::vector<Boxed_Value> &bvs, const std::string &name,
|
||||||
const std::unique_ptr<Type_Info> &ti, const Type_Conversions_State &t_conversions) const
|
const std::unique_ptr<Type_Info> &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);
|
return dynamic_object_typename_match(bvs[0], name, ti, t_conversions);
|
||||||
} else {
|
} else {
|
||||||
@ -202,7 +202,7 @@ namespace chaiscript
|
|||||||
bool operator==(const Proxy_Function_Base &f) const override
|
bool operator==(const Proxy_Function_Base &f) const override
|
||||||
{
|
{
|
||||||
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
|
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&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<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
||||||
|
@ -33,7 +33,7 @@ namespace chaiscript
|
|||||||
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
|
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State *t_conversions)
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State *t_conversions)
|
||||||
{
|
{
|
||||||
if (t_conversions) {
|
if (t_conversions != nullptr) {
|
||||||
return boxed_cast<Ret>(dispatch::dispatch(t_funcs, params, *t_conversions), t_conversions);
|
return boxed_cast<Ret>(dispatch::dispatch(t_funcs, params, *t_conversions), t_conversions);
|
||||||
} else {
|
} else {
|
||||||
Type_Conversions conv;
|
Type_Conversions conv;
|
||||||
@ -52,7 +52,7 @@ namespace chaiscript
|
|||||||
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
|
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State *t_conversions)
|
const std::vector<Boxed_Value> ¶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<Ret>();
|
return Boxed_Number(dispatch::dispatch(t_funcs, params, *t_conversions)).get_as<Ret>();
|
||||||
} else {
|
} else {
|
||||||
Type_Conversions conv;
|
Type_Conversions conv;
|
||||||
@ -72,7 +72,7 @@ namespace chaiscript
|
|||||||
static void call(const std::vector<Const_Proxy_Function> &t_funcs,
|
static void call(const std::vector<Const_Proxy_Function> &t_funcs,
|
||||||
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State *t_conversions)
|
const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State *t_conversions)
|
||||||
{
|
{
|
||||||
if (t_conversions) {
|
if (t_conversions != nullptr) {
|
||||||
dispatch::dispatch(t_funcs, params, *t_conversions);
|
dispatch::dispatch(t_funcs, params, *t_conversions);
|
||||||
} else {
|
} else {
|
||||||
Type_Conversions conv;
|
Type_Conversions conv;
|
||||||
|
@ -63,7 +63,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
void push_front(std::string t_name, Type_Info t_ti)
|
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();
|
update_has_types();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,8 +74,8 @@ namespace chaiscript
|
|||||||
|
|
||||||
bool match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const
|
bool match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const
|
||||||
{
|
{
|
||||||
if (!m_has_types) return true;
|
if (!m_has_types) { return true; }
|
||||||
if (vals.size() != m_types.size()) return false;
|
if (vals.size() != m_types.size()) { return false; }
|
||||||
|
|
||||||
for (size_t i = 0; i < vals.size(); ++i)
|
for (size_t i = 0; i < vals.size(); ++i)
|
||||||
{
|
{
|
||||||
@ -282,7 +282,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
guard_error(const guard_error &) = default;
|
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<const Dynamic_Proxy_Function *>(&rhs);
|
const Dynamic_Proxy_Function *prhs = dynamic_cast<const Dynamic_Proxy_Function *>(&rhs);
|
||||||
|
|
||||||
return this == &rhs
|
return this == &rhs
|
||||||
|| (prhs
|
|| ((prhs != nullptr)
|
||||||
&& this->m_arity == prhs->m_arity
|
&& this->m_arity == prhs->m_arity
|
||||||
&& !this->m_guard && !prhs->m_guard
|
&& !this->m_guard && !prhs->m_guard
|
||||||
&& this->m_param_types == prhs->m_param_types);
|
&& this->m_param_types == prhs->m_param_types);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
bool call_match(const std::vector<Boxed_Value> &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)))
|
return (m_arity < 0 || (vals.size() == size_t(m_arity) && m_param_types.match(vals, t_conversions)))
|
||||||
&& test_guard(vals, t_conversions);
|
&& test_guard(vals, t_conversions);
|
||||||
@ -516,7 +516,7 @@ namespace chaiscript
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
Boxed_Value do_call(const std::vector<Boxed_Value> ¶ms, const Type_Conversions_State &t_conversions) const override
|
||||||
{
|
{
|
||||||
return (*m_f)(build_param_list(params), t_conversions);
|
return (*m_f)(build_param_list(params), t_conversions);
|
||||||
}
|
}
|
||||||
@ -742,7 +742,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
dispatch_error(const dispatch_error &) = default;
|
dispatch_error(const dispatch_error &) = default;
|
||||||
virtual ~dispatch_error() noexcept = default;
|
~dispatch_error() noexcept override = default;
|
||||||
|
|
||||||
std::vector<Boxed_Value> parameters;
|
std::vector<Boxed_Value> parameters;
|
||||||
std::vector<Const_Proxy_Function> functions;
|
std::vector<Const_Proxy_Function> functions;
|
||||||
@ -759,7 +759,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
const std::vector<Type_Info> &types = t_func->get_param_types();
|
const std::vector<Type_Info> &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);
|
assert(plist.size() == types.size() - 1);
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
arity_error(const arity_error &) = default;
|
arity_error(const arity_error &) = default;
|
||||||
|
|
||||||
virtual ~arity_error() noexcept {}
|
~arity_error() noexcept override = default;
|
||||||
|
|
||||||
int got;
|
int got;
|
||||||
int expected;
|
int expected;
|
||||||
|
@ -85,11 +85,13 @@ arena<N, alignment>::deallocate(char* p, std::size_t n) noexcept
|
|||||||
if (pointer_in_buffer(p))
|
if (pointer_in_buffer(p))
|
||||||
{
|
{
|
||||||
n = align_up(n);
|
n = align_up(n);
|
||||||
if (p + n == ptr_)
|
if (p + n == ptr_) {
|
||||||
ptr_ = p;
|
ptr_ = p;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
::operator delete(p);
|
::operator delete(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T, std::size_t N, std::size_t Align = alignof(std::max_align_t)>
|
template <class T, std::size_t N, std::size_t Align = alignof(std::max_align_t)>
|
||||||
|
@ -46,7 +46,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
bad_boxed_dynamic_cast(const bad_boxed_dynamic_cast &) = default;
|
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
|
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;
|
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;
|
virtual ~Type_Conversion_Base() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Type_Conversion_Base(const Type_Info &t_to, const Type_Info &t_from)
|
Type_Conversion_Base(Type_Info t_to, Type_Info t_from)
|
||||||
: m_to(t_to), m_from(t_from)
|
: m_to(std::move(t_to)), m_from(std::move(t_from))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Type_Conversion_Impl(Type_Info t_from, Type_Info t_to, Callable t_func)
|
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))
|
m_func(std::move(t_func))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ namespace chaiscript
|
|||||||
return m_func(t_from);
|
return m_func(t_from);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool bidir() const override
|
bool bidir() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -399,7 +399,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Boxed_Value ret = get_conversion(user_type<To>(), from.get_type_info())->convert(from);
|
Boxed_Value ret = get_conversion(user_type<To>(), 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;
|
return ret;
|
||||||
} catch (const std::out_of_range &) {
|
} catch (const std::out_of_range &) {
|
||||||
throw exception::bad_boxed_dynamic_cast(from.get_type_info(), typeid(To), "No known conversion");
|
throw exception::bad_boxed_dynamic_cast(from.get_type_info(), typeid(To), "No known conversion");
|
||||||
@ -413,7 +413,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Boxed_Value ret = get_conversion(to.get_type_info(), user_type<From>())->convert_down(to);
|
Boxed_Value ret = get_conversion(to.get_type_info(), user_type<From>())->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;
|
return ret;
|
||||||
} catch (const std::out_of_range &) {
|
} catch (const std::out_of_range &) {
|
||||||
throw exception::bad_boxed_dynamic_cast(to.get_type_info(), typeid(From), "No known conversion");
|
throw exception::bad_boxed_dynamic_cast(to.get_type_info(), typeid(From), "No known conversion");
|
||||||
|
@ -72,7 +72,7 @@ namespace chaiscript
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
/// Helper lookup to get the name of each node type
|
/// 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",
|
static const char * const ast_node_types[] = { "Id", "Fun_Call", "Unused_Return_Fun_Call", "Arg_List", "Equation", "Var_Decl",
|
||||||
"Array_Call", "Dot_Access",
|
"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",
|
"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;
|
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<load_module_error> &t_errors)
|
static std::string format_error(const std::string &t_name, const std::vector<load_module_error> &t_errors)
|
||||||
{
|
{
|
||||||
@ -200,7 +200,7 @@ namespace chaiscript
|
|||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
|
|
||||||
ss << what();
|
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 << "during evaluation at (" << fname(call_stack[0]) << " " << startpos(call_stack[0]) << ")\n";
|
||||||
ss << '\n' << detail << '\n';
|
ss << '\n' << detail << '\n';
|
||||||
ss << " " << fname(call_stack[0]) << " (" << startpos(call_stack[0]) << ") '" << pretty(call_stack[0]) << "'";
|
ss << " " << fname(call_stack[0]) << " (" << startpos(call_stack[0]) << ") '" << pretty(call_stack[0]) << "'";
|
||||||
@ -217,7 +217,7 @@ namespace chaiscript
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~eval_error() noexcept = default;
|
~eval_error() noexcept override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -481,7 +481,7 @@ namespace chaiscript
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
file_not_found_error(const file_not_found_error &) = default;
|
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'
|
/// Special type indicating a call to 'break'
|
||||||
struct Break_Loop {
|
struct Break_Loop {
|
||||||
Break_Loop() { }
|
Break_Loop() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Special type indicating a call to 'continue'
|
/// Special type indicating a call to 'continue'
|
||||||
struct Continue_Loop {
|
struct Continue_Loop {
|
||||||
Continue_Loop() { }
|
Continue_Loop() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -663,7 +663,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
void save_params(std::initializer_list<Boxed_Value> t_params)
|
void save_params(std::initializer_list<Boxed_Value> t_params)
|
||||||
{
|
{
|
||||||
m_ds->save_function_params(std::move(t_params));
|
m_ds->save_function_params(t_params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ namespace chaiscript
|
|||||||
memset( &rInfo, 0, sizeof(rInfo) );
|
memset( &rInfo, 0, sizeof(rInfo) );
|
||||||
cast_union u;
|
cast_union u;
|
||||||
u.in_ptr = &ChaiScript_Basic::use;
|
u.in_ptr = &ChaiScript_Basic::use;
|
||||||
if ( dladdr(static_cast<void*>(u.out_ptr), &rInfo) && rInfo.dli_fname ) {
|
if ( (dladdr(static_cast<void*>(u.out_ptr), &rInfo) != 0) && (rInfo.dli_fname != nullptr) ) {
|
||||||
std::string dllpath(rInfo.dli_fname);
|
std::string dllpath(rInfo.dli_fname);
|
||||||
const size_t lastslash = dllpath.rfind('/');
|
const size_t lastslash = dllpath.rfind('/');
|
||||||
if (lastslash != std::string::npos)
|
if (lastslash != std::string::npos)
|
||||||
|
@ -64,7 +64,7 @@ namespace chaiscript
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
chaiscript::eval::detail::Stack_Push_Pop tpp(state);
|
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) {
|
if (t_locals) {
|
||||||
for (const auto &local : *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,
|
AST_Node_Impl(std::string t_ast_node_text, AST_Node_Type t_id, Parse_Location t_loc,
|
||||||
std::vector<AST_Node_Impl_Ptr<T>> t_children = std::vector<AST_Node_Impl_Ptr<T>>())
|
std::vector<AST_Node_Impl_Ptr<T>> t_children = std::vector<AST_Node_Impl_Ptr<T>>())
|
||||||
: 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))
|
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){
|
const auto get_function = [&t_ss](const std::string &t_name, auto &t_hint){
|
||||||
uint_fast32_t hint = t_hint;
|
uint_fast32_t hint = t_hint;
|
||||||
auto funs = t_ss->get_function(t_name, 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);
|
return std::move(funs.second);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ namespace chaiscript {
|
|||||||
auto optimize(const eval::AST_Node_Impl_Ptr<T> &node) {
|
auto optimize(const eval::AST_Node_Impl_Ptr<T> &node) {
|
||||||
if ((node->identifier == AST_Node_Type::Block
|
if ((node->identifier == AST_Node_Type::Block
|
||||||
|| node->identifier == AST_Node_Type::Scopeless_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) {
|
for (size_t i = 0; i < node->children.size()-1; ++i) {
|
||||||
auto child = node->children[i];
|
auto child = node->children[i];
|
||||||
|
@ -243,7 +243,7 @@ namespace chaiscript
|
|||||||
Position() = default;
|
Position() = default;
|
||||||
|
|
||||||
Position(std::string::const_iterator t_pos, std::string::const_iterator t_end)
|
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<eval::Constant_AST_Node<Tracer>>(text, start.line, start.col,
|
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(text, start.line, start.col,
|
||||||
const_var(std::move(fun_name))));
|
const_var(fun_name)));
|
||||||
} else if (text == "__CLASS__") {
|
} else if (text == "__CLASS__") {
|
||||||
const std::string fun_name = [&]()->std::string{
|
const std::string fun_name = [&]()->std::string{
|
||||||
for (size_t idx = m_match_stack.size() - 1; idx > 1; --idx)
|
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<eval::Constant_AST_Node<Tracer>>(text, start.line, start.col,
|
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(text, start.line, start.col,
|
||||||
const_var(std::move(fun_name))));
|
const_var(fun_name)));
|
||||||
} else if (text == "_") {
|
} else if (text == "_") {
|
||||||
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(text, start.line, start.col,
|
m_match_stack.push_back(make_node<eval::Constant_AST_Node<Tracer>>(text, start.line, start.col,
|
||||||
Boxed_Value(std::make_shared<dispatch::Placeholder_Object>())));
|
Boxed_Value(std::make_shared<dispatch::Placeholder_Object>())));
|
||||||
@ -1009,7 +1009,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
void process_hex()
|
void process_hex()
|
||||||
{
|
{
|
||||||
auto val = stoll(hex_matches, 0, 16);
|
auto val = stoll(hex_matches, nullptr, 16);
|
||||||
match.push_back(char_type(val));
|
match.push_back(char_type(val));
|
||||||
hex_matches.clear();
|
hex_matches.clear();
|
||||||
is_escaped = false;
|
is_escaped = false;
|
||||||
@ -1019,7 +1019,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
void process_octal()
|
void process_octal()
|
||||||
{
|
{
|
||||||
auto val = stoll(octal_matches, 0, 8);
|
auto val = stoll(octal_matches, nullptr, 8);
|
||||||
match.push_back(char_type(val));
|
match.push_back(char_type(val));
|
||||||
octal_matches.clear();
|
octal_matches.clear();
|
||||||
is_escaped = false;
|
is_escaped = false;
|
||||||
@ -1029,7 +1029,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
void process_unicode()
|
void process_unicode()
|
||||||
{
|
{
|
||||||
auto val = stoll(hex_matches, 0, 16);
|
auto val = stoll(hex_matches, nullptr, 16);
|
||||||
hex_matches.clear();
|
hex_matches.clear();
|
||||||
match += detail::Char_Parser_Helper<string_type>::str_from_ll(val);
|
match += detail::Char_Parser_Helper<string_type>::str_from_ll(val);
|
||||||
is_escaped = false;
|
is_escaped = false;
|
||||||
@ -2072,17 +2072,21 @@ namespace chaiscript
|
|||||||
/// \todo Work around for method calls until we have a better solution
|
/// \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.empty()) {
|
||||||
if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Dot_Access) {
|
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.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.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 dot_access = m_match_stack.back()->children[0];
|
||||||
auto func_call = m_match_stack.back();
|
auto func_call = m_match_stack.back();
|
||||||
m_match_stack.pop_back();
|
m_match_stack.pop_back();
|
||||||
func_call->children.erase(func_call->children.begin());
|
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());
|
func_call->children.insert(func_call->children.begin(), dot_access->children.back());
|
||||||
dot_access->children.pop_back();
|
dot_access->children.pop_back();
|
||||||
dot_access->children.push_back(std::move(func_call));
|
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));
|
m_match_stack.push_back(std::move(dot_access));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2192,7 +2196,7 @@ namespace chaiscript
|
|||||||
if (!Char(']')) {
|
if (!Char(']')) {
|
||||||
throw exception::eval_error("Missing closing square bracket ']' in container initializer", File_Position(m_position.line, m_position.col), *m_filename);
|
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) {
|
if (m_match_stack.back()->children[0]->identifier == AST_Node_Type::Value_Range) {
|
||||||
build_match<eval::Inline_Range_AST_Node<Tracer>>(prev_stack_top);
|
build_match<eval::Inline_Range_AST_Node<Tracer>>(prev_stack_top);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ namespace chaiscript
|
|||||||
DLModule(const std::string &t_filename)
|
DLModule(const std::string &t_filename)
|
||||||
: m_data(dlopen(t_filename.c_str(), RTLD_NOW))
|
: m_data(dlopen(t_filename.c_str(), RTLD_NOW))
|
||||||
{
|
{
|
||||||
if (!m_data)
|
if (m_data == nullptr)
|
||||||
{
|
{
|
||||||
throw chaiscript::exception::load_module_error(dlerror());
|
throw chaiscript::exception::load_module_error(dlerror());
|
||||||
}
|
}
|
||||||
|
@ -386,12 +386,12 @@ class JSON
|
|||||||
return "null";
|
return "null";
|
||||||
case Class::Object: {
|
case Class::Object: {
|
||||||
std::string pad = "";
|
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";
|
std::string s = "{\n";
|
||||||
bool skip = true;
|
bool skip = true;
|
||||||
for( auto &p : *internal.Map ) {
|
for( auto &p : *internal.Map ) {
|
||||||
if( !skip ) s += ",\n";
|
if( !skip ) { s += ",\n"; }
|
||||||
s += ( pad + "\"" + p.first + "\" : " + p.second.dump( depth + 1, tab ) );
|
s += ( pad + "\"" + p.first + "\" : " + p.second.dump( depth + 1, tab ) );
|
||||||
skip = false;
|
skip = false;
|
||||||
}
|
}
|
||||||
@ -402,7 +402,7 @@ class JSON
|
|||||||
std::string s = "[";
|
std::string s = "[";
|
||||||
bool skip = true;
|
bool skip = true;
|
||||||
for( auto &p : *internal.List ) {
|
for( auto &p : *internal.List ) {
|
||||||
if( !skip ) s += ", ";
|
if( !skip ) { s += ", "; }
|
||||||
s += p.dump( depth + 1, tab );
|
s += p.dump( depth + 1, tab );
|
||||||
skip = false;
|
skip = false;
|
||||||
}
|
}
|
||||||
@ -426,8 +426,8 @@ class JSON
|
|||||||
private:
|
private:
|
||||||
static std::string json_escape( const std::string &str ) {
|
static std::string json_escape( const std::string &str ) {
|
||||||
std::string output;
|
std::string output;
|
||||||
for( size_t i = 0; i < str.length(); ++i )
|
for(char i : str) {
|
||||||
switch( str[i] ) {
|
switch( i ) {
|
||||||
case '\"': output += "\\\""; break;
|
case '\"': output += "\\\""; break;
|
||||||
case '\\': output += "\\\\"; break;
|
case '\\': output += "\\\\"; break;
|
||||||
case '\b': output += "\\b"; break;
|
case '\b': output += "\\b"; break;
|
||||||
@ -435,8 +435,9 @@ class JSON
|
|||||||
case '\n': output += "\\n"; break;
|
case '\n': output += "\\n"; break;
|
||||||
case '\r': output += "\\r"; break;
|
case '\r': output += "\\r"; break;
|
||||||
case '\t': output += "\\t"; break;
|
case '\t': output += "\\t"; break;
|
||||||
default : output += str[i]; break;
|
default : output += i; break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,7 +463,7 @@ struct JSONParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void consume_ws( const std::string &str, size_t &offset ) {
|
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 ) {
|
static JSON parse_object( const std::string &str, size_t &offset ) {
|
||||||
@ -544,9 +545,9 @@ struct JSONParser {
|
|||||||
val += "\\u" ;
|
val += "\\u" ;
|
||||||
for( size_t i = 1; i <= 4; ++i ) {
|
for( size_t i = 1; i <= 4; ++i ) {
|
||||||
c = str[offset+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;
|
val += c;
|
||||||
else {
|
} else {
|
||||||
throw std::runtime_error(std::string("JSON ERROR: String: Expected hex character in unicode escape, found '") + c + "'");
|
throw std::runtime_error(std::string("JSON ERROR: String: Expected hex character in unicode escape, found '") + c + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -554,10 +555,10 @@ struct JSONParser {
|
|||||||
} break;
|
} break;
|
||||||
default : val += '\\'; break;
|
default : val += '\\'; break;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
val += c;
|
val += c;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
++offset;
|
++offset;
|
||||||
return JSON(val);
|
return JSON(val);
|
||||||
}
|
}
|
||||||
@ -569,30 +570,35 @@ struct JSONParser {
|
|||||||
long exp = 0;
|
long exp = 0;
|
||||||
for (; offset < str.size() ;) {
|
for (; offset < str.size() ;) {
|
||||||
c = str[offset++];
|
c = str[offset++];
|
||||||
if( (c == '-') || (c >= '0' && c <= '9') )
|
if( (c == '-') || (c >= '0' && c <= '9') ) {
|
||||||
val += c;
|
val += c;
|
||||||
else if( c == '.' ) {
|
} else if( c == '.' ) {
|
||||||
val += c;
|
val += c;
|
||||||
isDouble = true;
|
isDouble = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if( offset < str.size() && (c == 'E' || c == 'e' )) {
|
if( offset < str.size() && (c == 'E' || c == 'e' )) {
|
||||||
c = str[ offset++ ];
|
c = str[ offset++ ];
|
||||||
if( c == '-' ) { exp_str += '-';}
|
if( c == '-' ) {
|
||||||
else if( c == '+' ) { }
|
exp_str += '-';
|
||||||
else --offset;
|
} else if( c == '+' ) {
|
||||||
|
// do nothing
|
||||||
|
} else {
|
||||||
|
--offset;
|
||||||
|
}
|
||||||
|
|
||||||
for (; offset < str.size() ;) {
|
for (; offset < str.size() ;) {
|
||||||
c = str[ offset++ ];
|
c = str[ offset++ ];
|
||||||
if( c >= '0' && c <= '9' )
|
if( c >= '0' && c <= '9' ) {
|
||||||
exp_str += c;
|
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 + "'");
|
throw std::runtime_error(std::string("JSON ERROR: Number: Expected a number for exponent, found '") + c + "'");
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exp = chaiscript::parse_num<long>( exp_str );
|
exp = chaiscript::parse_num<long>( exp_str );
|
||||||
}
|
}
|
||||||
@ -643,9 +649,10 @@ struct JSONParser {
|
|||||||
case 't' :
|
case 't' :
|
||||||
case 'f' : return parse_bool( str, offset );
|
case 'f' : return parse_bool( str, offset );
|
||||||
case 'n' : return parse_null( 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 );
|
return parse_number( str, offset );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
throw std::runtime_error(std::string("JSON ERROR: Parse: Unexpected starting character '") + value + "'");
|
throw std::runtime_error(std::string("JSON ERROR: Parse: Unexpected starting character '") + value + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
src/main.cpp
20
src/main.cpp
@ -25,7 +25,7 @@
|
|||||||
char *mystrdup (const char *s) {
|
char *mystrdup (const char *s) {
|
||||||
size_t len = strlen(s); // Space for length plus nul
|
size_t len = strlen(s); // Space for length plus nul
|
||||||
char *d = static_cast<char*>(malloc (len+1));
|
char *d = static_cast<char*>(malloc (len+1));
|
||||||
if (d == nullptr) return nullptr; // No memory
|
if (d == nullptr) { return nullptr; } // No memory
|
||||||
#ifdef CHAISCRIPT_MSVC
|
#ifdef CHAISCRIPT_MSVC
|
||||||
strcpy_s(d, len+1, s); // Copy the characters
|
strcpy_s(d, len+1, s); // Copy the characters
|
||||||
#else
|
#else
|
||||||
@ -44,7 +44,7 @@ char* readline(const char* p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void add_history(const char*){}
|
void add_history(const char* /*unused*/){}
|
||||||
void using_history(){}
|
void using_history(){}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ std::vector<std::string> default_search_paths()
|
|||||||
{
|
{
|
||||||
Dl_info rInfo;
|
Dl_info rInfo;
|
||||||
memset( &rInfo, 0, sizeof(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;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ std::string get_next_command() {
|
|||||||
std::string retval("quit");
|
std::string retval("quit");
|
||||||
if ( ! std::cin.eof() ) {
|
if ( ! std::cin.eof() ) {
|
||||||
char *input_raw = readline("eval> ");
|
char *input_raw = readline("eval> ");
|
||||||
if ( input_raw ) {
|
if ( input_raw != nullptr ) {
|
||||||
add_history(input_raw);
|
add_history(input_raw);
|
||||||
|
|
||||||
std::string val(input_raw);
|
std::string val(input_raw);
|
||||||
@ -240,7 +240,7 @@ void interactive(chaiscript::ChaiScript_Basic& chai)
|
|||||||
}
|
}
|
||||||
catch (const chaiscript::exception::eval_error &ee) {
|
catch (const chaiscript::exception::eval_error &ee) {
|
||||||
std::cout << ee.what();
|
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 << "during evaluation at (" << ee.call_stack[0]->start().line << ", " << ee.call_stack[0]->start().column << ")";
|
||||||
}
|
}
|
||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
@ -277,7 +277,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
std::vector<std::string> usepaths;
|
std::vector<std::string> usepaths;
|
||||||
usepaths.push_back("");
|
usepaths.push_back("");
|
||||||
if (usepath)
|
if (usepath != nullptr)
|
||||||
{
|
{
|
||||||
usepaths.push_back(usepath);
|
usepaths.push_back(usepath);
|
||||||
}
|
}
|
||||||
@ -286,7 +286,7 @@ int main(int argc, char *argv[])
|
|||||||
std::vector<std::string> searchpaths = default_search_paths();
|
std::vector<std::string> searchpaths = default_search_paths();
|
||||||
modulepaths.insert(modulepaths.end(), searchpaths.begin(), searchpaths.end());
|
modulepaths.insert(modulepaths.end(), searchpaths.begin(), searchpaths.end());
|
||||||
modulepaths.push_back("");
|
modulepaths.push_back("");
|
||||||
if (modulepath)
|
if (modulepath != nullptr)
|
||||||
{
|
{
|
||||||
modulepaths.push_back(modulepath);
|
modulepaths.push_back(modulepath);
|
||||||
}
|
}
|
||||||
@ -308,7 +308,7 @@ int main(int argc, char *argv[])
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string arg( i ? argv[i] : "--interactive" );
|
std::string arg( i != 0 ? argv[i] : "--interactive" );
|
||||||
|
|
||||||
enum { eInteractive
|
enum { eInteractive
|
||||||
, eCommand
|
, eCommand
|
||||||
@ -319,9 +319,9 @@ int main(int argc, char *argv[])
|
|||||||
if ( (i+1) >= argc ) {
|
if ( (i+1) >= argc ) {
|
||||||
std::cout << "insufficient input following " << arg << '\n';
|
std::cout << "insufficient input following " << arg << '\n';
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} else {
|
|
||||||
arg = argv[++i];
|
|
||||||
}
|
}
|
||||||
|
arg = argv[++i];
|
||||||
|
|
||||||
} else if ( arg == "-" || arg == "--stdin" ) {
|
} else if ( arg == "-" || arg == "--stdin" ) {
|
||||||
arg = "" ;
|
arg = "" ;
|
||||||
std::string line;
|
std::string line;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user