Virtual / override / public cleanups

This commit is contained in:
Jason Turner 2016-03-11 09:24:00 -07:00
parent 11ee71ba27
commit cd1b3f8887
3 changed files with 184 additions and 278 deletions

View File

@ -267,7 +267,7 @@ namespace chaiscript
/// A Proxy_Function implementation that is able to take /// A Proxy_Function implementation that is able to take
/// a vector of Proxy_Functions and perform a dispatch on them. It is /// a vector of Proxy_Functions and perform a dispatch on them. It is
/// used specifically in the case of dealing with Function object variables /// used specifically in the case of dealing with Function object variables
class Dispatch_Function : public dispatch::Proxy_Function_Base class Dispatch_Function final : public dispatch::Proxy_Function_Base
{ {
public: public:
Dispatch_Function(std::vector<Proxy_Function> t_funcs) Dispatch_Function(std::vector<Proxy_Function> t_funcs)
@ -276,7 +276,7 @@ namespace chaiscript
{ {
} }
virtual bool operator==(const dispatch::Proxy_Function_Base &rhs) const override bool operator==(const dispatch::Proxy_Function_Base &rhs) const override
{ {
try { try {
const auto &dispatch_fun = dynamic_cast<const Dispatch_Function &>(rhs); const auto &dispatch_fun = dynamic_cast<const Dispatch_Function &>(rhs);
@ -286,9 +286,7 @@ namespace chaiscript
} }
} }
virtual ~Dispatch_Function() {} std::vector<Const_Proxy_Function> get_contained_functions() const override
virtual std::vector<Const_Proxy_Function> get_contained_functions() const override
{ {
return std::vector<Const_Proxy_Function>(m_funcs.begin(), m_funcs.end()); return std::vector<Const_Proxy_Function>(m_funcs.begin(), m_funcs.end());
} }
@ -314,19 +312,19 @@ namespace chaiscript
return arity; return arity;
} }
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 std::any_of(m_funcs.cbegin(), m_funcs.cend(), return std::any_of(m_funcs.cbegin(), m_funcs.cend(),
[&vals, &t_conversions](const Proxy_Function &f){ return f->call_match(vals, t_conversions); }); [&vals, &t_conversions](const Proxy_Function &f){ return f->call_match(vals, t_conversions); });
} }
virtual std::string annotation() const override std::string annotation() const override
{ {
return "Multiple method dispatch function wrapper."; return "Multiple method dispatch function wrapper.";
} }
protected: protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
{ {
return dispatch::dispatch(m_funcs, params, t_conversions); return dispatch::dispatch(m_funcs, params, t_conversions);
} }

View File

@ -145,7 +145,7 @@ namespace chaiscript
class Proxy_Function_Base class Proxy_Function_Base
{ {
public: public:
virtual ~Proxy_Function_Base() {} virtual ~Proxy_Function_Base() = default;
Boxed_Value operator()(const std::vector<Boxed_Value> &params, const chaiscript::Type_Conversions_State &t_conversions) const Boxed_Value operator()(const std::vector<Boxed_Value> &params, const chaiscript::Type_Conversions_State &t_conversions) const
{ {
@ -248,7 +248,8 @@ namespace chaiscript
} }
static bool compare_types(const std::vector<Type_Info> &tis, const std::vector<Boxed_Value> &bvs, const Type_Conversions_State &t_conversions) static bool compare_types(const std::vector<Type_Info> &tis, const std::vector<Boxed_Value> &bvs,
const Type_Conversions_State &t_conversions)
{ {
if (tis.size() - 1 != bvs.size()) if (tis.size() - 1 != bvs.size())
{ {
@ -288,8 +289,7 @@ namespace chaiscript
guard_error(const guard_error &) = default; guard_error(const guard_error &) = default;
virtual ~guard_error() noexcept virtual ~guard_error() noexcept = default;
{ }
}; };
} }
@ -314,7 +314,6 @@ namespace chaiscript
{ {
} }
virtual ~Dynamic_Proxy_Function() {}
virtual bool operator==(const Proxy_Function_Base &rhs) const override virtual bool operator==(const Proxy_Function_Base &rhs) const override
{ {
@ -394,7 +393,7 @@ namespace chaiscript
template<typename Callable> template<typename Callable>
class Dynamic_Proxy_Function_Impl : public Dynamic_Proxy_Function class Dynamic_Proxy_Function_Impl final : public Dynamic_Proxy_Function
{ {
public: public:
Dynamic_Proxy_Function_Impl( Dynamic_Proxy_Function_Impl(
@ -415,11 +414,9 @@ namespace chaiscript
{ {
} }
virtual ~Dynamic_Proxy_Function_Impl() {}
protected: protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
{ {
if (call_match(params, t_conversions) && test_guard(params, t_conversions)) if (call_match(params, t_conversions) && test_guard(params, t_conversions))
{ {
@ -430,7 +427,6 @@ namespace chaiscript
} }
private: private:
Callable m_f; Callable m_f;
}; };
@ -451,7 +447,7 @@ namespace chaiscript
/// and substitutes bound parameters into the parameter list /// and substitutes bound parameters into the parameter list
/// at runtime, when call() is executed. /// at runtime, when call() is executed.
/// it is used for bind(function, param1, _, param2) style calls /// it is used for bind(function, param1, _, param2) style calls
class Bound_Function : public Proxy_Function_Base class Bound_Function final : public Proxy_Function_Base
{ {
public: public:
Bound_Function(const Const_Proxy_Function &t_f, Bound_Function(const Const_Proxy_Function &t_f,
@ -462,19 +458,18 @@ namespace chaiscript
assert(m_f->get_arity() < 0 || m_f->get_arity() == static_cast<int>(m_args.size())); assert(m_f->get_arity() < 0 || m_f->get_arity() == static_cast<int>(m_args.size()));
} }
virtual bool operator==(const Proxy_Function_Base &t_f) const override bool operator==(const Proxy_Function_Base &t_f) const override
{ {
return &t_f == this; return &t_f == this;
} }
virtual ~Bound_Function() {}
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_f->call_match(build_param_list(vals), t_conversions); return m_f->call_match(build_param_list(vals), t_conversions);
} }
virtual std::vector<Const_Proxy_Function> get_contained_functions() const override std::vector<Const_Proxy_Function> get_contained_functions() const override
{ {
return std::vector<Const_Proxy_Function>{m_f}; return std::vector<Const_Proxy_Function>{m_f};
} }
@ -524,7 +519,7 @@ namespace chaiscript
if (t_f->get_arity() < 0) { return std::vector<Type_Info>(); } if (t_f->get_arity() < 0) { return std::vector<Type_Info>(); }
std::vector<Type_Info> types = t_f->get_param_types(); const auto types = t_f->get_param_types();
assert(types.size() == t_args.size() + 1); assert(types.size() == t_args.size() + 1);
// this analysis warning is invalid in MSVC12 and doesn't exist in MSVC14 // this analysis warning is invalid in MSVC12 and doesn't exist in MSVC14
@ -559,16 +554,15 @@ namespace chaiscript
{ {
} }
virtual ~Proxy_Function_Impl_Base() {} std::string annotation() const override
virtual std::string annotation() const override
{ {
return ""; return "";
} }
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 static_cast<int>(vals.size()) == get_arity() && (compare_types(m_types, vals, t_conversions) && compare_types_with_cast(vals, t_conversions)); return static_cast<int>(vals.size()) == get_arity()
&& (compare_types(m_types, vals, t_conversions) && compare_types_with_cast(vals, t_conversions));
} }
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const = 0; virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const = 0;
@ -578,7 +572,7 @@ namespace chaiscript
/// For any callable object /// For any callable object
template<typename Func, typename Callable> template<typename Func, typename Callable>
class Proxy_Function_Callable_Impl : public Proxy_Function_Impl_Base class Proxy_Function_Callable_Impl final : public Proxy_Function_Impl_Base
{ {
public: public:
Proxy_Function_Callable_Impl(Callable f) Proxy_Function_Callable_Impl(Callable f)
@ -587,21 +581,19 @@ namespace chaiscript
{ {
} }
virtual ~Proxy_Function_Callable_Impl() {} bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
{ {
return detail::compare_types_cast(static_cast<Func *>(nullptr), vals, t_conversions); return detail::compare_types_cast(static_cast<Func *>(nullptr), vals, t_conversions);
} }
virtual bool operator==(const Proxy_Function_Base &t_func) const override bool operator==(const Proxy_Function_Base &t_func) const override
{ {
return dynamic_cast<const Proxy_Function_Callable_Impl<Func, Callable> *>(&t_func) != nullptr; return dynamic_cast<const Proxy_Function_Callable_Impl<Func, Callable> *>(&t_func) != nullptr;
} }
protected: protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
{ {
typedef typename detail::Function_Signature<Func>::Return_Type Return_Type; typedef typename detail::Function_Signature<Func>::Return_Type Return_Type;
return detail::Do_Call<Return_Type>::template go<Func>(m_f, params, t_conversions); return detail::Do_Call<Return_Type>::template go<Func>(m_f, params, t_conversions);
@ -620,16 +612,11 @@ namespace chaiscript
{ {
} }
virtual ~Assignable_Proxy_Function() {}
virtual void assign(const std::shared_ptr<const Proxy_Function_Base> &t_rhs) = 0; virtual void assign(const std::shared_ptr<const Proxy_Function_Base> &t_rhs) = 0;
}; };
template<typename Func> template<typename Func>
class Assignable_Proxy_Function_Impl : public Assignable_Proxy_Function class Assignable_Proxy_Function_Impl final : public Assignable_Proxy_Function
{ {
public: public:
Assignable_Proxy_Function_Impl(std::reference_wrapper<std::function<Func>> t_f, std::shared_ptr<std::function<Func>> t_ptr) Assignable_Proxy_Function_Impl(std::reference_wrapper<std::function<Func>> t_f, std::shared_ptr<std::function<Func>> t_ptr)
@ -639,14 +626,12 @@ namespace chaiscript
assert(!m_shared_ptr_holder || m_shared_ptr_holder.get() == &m_f.get()); assert(!m_shared_ptr_holder || m_shared_ptr_holder.get() == &m_f.get());
} }
virtual ~Assignable_Proxy_Function_Impl() {} bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
{ {
return detail::compare_types_cast(static_cast<Func *>(nullptr), vals, t_conversions); return detail::compare_types_cast(static_cast<Func *>(nullptr), vals, t_conversions);
} }
virtual bool operator==(const Proxy_Function_Base &t_func) const override bool operator==(const Proxy_Function_Base &t_func) const override
{ {
return dynamic_cast<const Assignable_Proxy_Function_Impl<Func> *>(&t_func) != nullptr; return dynamic_cast<const Assignable_Proxy_Function_Impl<Func> *>(&t_func) != nullptr;
} }
@ -656,12 +641,12 @@ namespace chaiscript
return m_f.get(); return m_f.get();
} }
virtual void assign(const std::shared_ptr<const Proxy_Function_Base> &t_rhs) override { void assign(const std::shared_ptr<const Proxy_Function_Base> &t_rhs) override {
m_f.get() = dispatch::functor<Func>(t_rhs, nullptr); m_f.get() = dispatch::functor<Func>(t_rhs, nullptr);
} }
protected: protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
{ {
return detail::Do_Call<typename std::function<Func>::result_type>::template go<Func>(m_f.get(), params, t_conversions); return detail::Do_Call<typename std::function<Func>::result_type>::template go<Func>(m_f.get(), params, t_conversions);
} }
@ -671,9 +656,11 @@ namespace chaiscript
std::reference_wrapper<std::function<Func>> m_f; std::reference_wrapper<std::function<Func>> m_f;
std::shared_ptr<std::function<Func>> m_shared_ptr_holder; std::shared_ptr<std::function<Func>> m_shared_ptr_holder;
}; };
/// Attribute getter Proxy_Function implementation /// Attribute getter Proxy_Function implementation
template<typename T, typename Class> template<typename T, typename Class>
class Attribute_Access : public Proxy_Function_Base class Attribute_Access final : public Proxy_Function_Base
{ {
public: public:
Attribute_Access(T Class::* t_attr) Attribute_Access(T Class::* t_attr)
@ -682,11 +669,9 @@ namespace chaiscript
{ {
} }
virtual ~Attribute_Access() {} bool is_attribute_function() const override { return true; }
virtual bool is_attribute_function() const override { return true; } bool operator==(const Proxy_Function_Base &t_func) const override
virtual bool operator==(const Proxy_Function_Base &t_func) const override
{ {
const Attribute_Access<T, Class> * aa const Attribute_Access<T, Class> * aa
= dynamic_cast<const Attribute_Access<T, Class> *>(&t_func); = dynamic_cast<const Attribute_Access<T, Class> *>(&t_func);
@ -698,7 +683,7 @@ namespace chaiscript
} }
} }
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &) const override bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &) const override
{ {
if (vals.size() != 1) if (vals.size() != 1)
{ {
@ -708,13 +693,13 @@ namespace chaiscript
return vals[0].get_type_info().bare_equal(user_type<Class>()); return vals[0].get_type_info().bare_equal(user_type<Class>());
} }
virtual std::string annotation() const override std::string annotation() const override
{ {
return ""; return "";
} }
protected: protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
{ {
const Boxed_Value &bv = params[0]; const Boxed_Value &bv = params[0];
if (bv.is_const()) if (bv.is_const())
@ -762,7 +747,7 @@ namespace chaiscript
dispatch_error(const dispatch_error &) = default; dispatch_error(const dispatch_error &) = default;
virtual ~dispatch_error() noexcept {} virtual ~dispatch_error() noexcept = default;
std::vector<Boxed_Value> parameters; std::vector<Boxed_Value> parameters;
std::vector<Const_Proxy_Function> functions; std::vector<Const_Proxy_Function> functions;

View File

@ -82,20 +82,18 @@ namespace chaiscript
} }
struct Binary_Operator_AST_Node : AST_Node { struct Binary_Operator_AST_Node : AST_Node {
public:
Binary_Operator_AST_Node(const std::string &t_oper, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Binary_Operator_AST_Node(const std::string &t_oper, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(t_oper, AST_Node_Type::Binary, std::move(t_loc), std::move(t_children)), AST_Node(t_oper, AST_Node_Type::Binary, std::move(t_loc), std::move(t_children)),
m_oper(Operators::to_operator(t_oper)) m_oper(Operators::to_operator(t_oper))
{ } { }
virtual ~Binary_Operator_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
auto lhs = this->children[0]->eval(t_ss); auto lhs = this->children[0]->eval(t_ss);
auto rhs = this->children[1]->eval(t_ss); auto rhs = this->children[1]->eval(t_ss);
return do_oper(t_ss, m_oper, text, lhs, rhs); return do_oper(t_ss, m_oper, text, lhs, rhs);
} }
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
return "(" + this->children[0]->pretty_print() + " " + text + " " + this->children[1]->pretty_print() + ")"; return "(" + this->children[0]->pretty_print() + " " + text + " " + this->children[1]->pretty_print() + ")";
} }
@ -131,28 +129,25 @@ namespace chaiscript
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc;
}; };
struct Int_AST_Node : public AST_Node { struct Int_AST_Node final : AST_Node {
public:
Int_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, Boxed_Value t_bv) : Int_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, Boxed_Value t_bv) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Int, std::move(t_loc)), AST_Node(std::move(t_ast_node_text), AST_Node_Type::Int, std::move(t_loc)),
m_value(std::move(t_bv)) { assert(text != ""); } m_value(std::move(t_bv)) { assert(text != ""); }
virtual ~Int_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override {
return m_value; return m_value;
} }
private: private:
Boxed_Value m_value; Boxed_Value m_value;
}; };
struct Float_AST_Node : public AST_Node { struct Float_AST_Node final : AST_Node {
public:
Float_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, Boxed_Value t_bv) : Float_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, Boxed_Value t_bv) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Float, std::move(t_loc)), AST_Node(std::move(t_ast_node_text), AST_Node_Type::Float, std::move(t_loc)),
m_value(std::move(t_bv)) { } m_value(std::move(t_bv)) { }
virtual ~Float_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override {
return m_value; return m_value;
} }
@ -161,15 +156,13 @@ namespace chaiscript
}; };
struct Id_AST_Node : public AST_Node { struct Id_AST_Node final : AST_Node {
public:
Id_AST_Node(const std::string &t_ast_node_text, Parse_Location t_loc) : Id_AST_Node(const std::string &t_ast_node_text, Parse_Location t_loc) :
AST_Node(t_ast_node_text, AST_Node_Type::Id, std::move(t_loc)), AST_Node(t_ast_node_text, AST_Node_Type::Id, std::move(t_loc)),
m_value(get_value(t_ast_node_text)), m_loc(0) m_value(get_value(t_ast_node_text)), m_loc(0)
{ } { }
virtual ~Id_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
if (!m_value.is_undef()) if (!m_value.is_undef())
{ {
return m_value; return m_value;
@ -206,39 +199,33 @@ namespace chaiscript
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc;
}; };
struct Char_AST_Node : public AST_Node { struct Char_AST_Node final : AST_Node {
public:
Char_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) : Char_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Char, std::move(t_loc)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Char, std::move(t_loc)) { }
virtual ~Char_AST_Node() {}
}; };
struct Str_AST_Node : public AST_Node { struct Str_AST_Node final : AST_Node {
public:
Str_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) : Str_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Str, std::move(t_loc)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Str, std::move(t_loc)) { }
virtual ~Str_AST_Node() {}
}; };
struct Eol_AST_Node : public AST_Node { struct Eol_AST_Node final : AST_Node {
public:
Eol_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) : Eol_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Eol, std::move(t_loc)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Eol, std::move(t_loc)) { }
virtual ~Eol_AST_Node() {}
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
return "\n"; return "\n";
} }
}; };
struct Fun_Call_AST_Node : public AST_Node { struct Fun_Call_AST_Node final : AST_Node {
public:
Fun_Call_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Fun_Call_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Fun_Call, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Fun_Call, std::move(t_loc), std::move(t_children)) { }
virtual ~Fun_Call_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override
{
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss); chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
std::vector<Boxed_Value> params; std::vector<Boxed_Value> params;
@ -278,7 +265,7 @@ namespace chaiscript
} }
} }
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
std::ostringstream oss; std::ostringstream oss;
@ -302,13 +289,11 @@ namespace chaiscript
struct Arg_AST_Node : public AST_Node { struct Arg_AST_Node final : AST_Node {
public:
Arg_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Arg_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Arg_List, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Arg_List, std::move(t_loc), std::move(t_children)) { }
virtual ~Arg_AST_Node() {}
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
std::ostringstream oss; std::ostringstream oss;
for (size_t j = 0; j < this->children.size(); ++j) { for (size_t j = 0; j < this->children.size(); ++j) {
@ -324,13 +309,11 @@ namespace chaiscript
} }
}; };
struct Arg_List_AST_Node : public AST_Node { struct Arg_List_AST_Node final : AST_Node {
public:
Arg_List_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Arg_List_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Arg_List, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Arg_List, std::move(t_loc), std::move(t_children)) { }
virtual ~Arg_List_AST_Node() {}
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
std::ostringstream oss; std::ostringstream oss;
for (size_t j = 0; j < this->children.size(); ++j) { for (size_t j = 0; j < this->children.size(); ++j) {
@ -371,9 +354,9 @@ namespace chaiscript
{ {
if (t_node->children.size() < 2) if (t_node->children.size() < 2)
{ {
return std::pair<std::string, Type_Info>(); return {};
} else { } else {
return std::pair<std::string, Type_Info>(t_node->children[0]->text, t_ss->get_type(t_node->children[0]->text, false)); return {t_node->children[0]->text, t_ss->get_type(t_node->children[0]->text, false)};
} }
} }
@ -389,19 +372,14 @@ namespace chaiscript
} }
}; };
struct Equation_AST_Node : public AST_Node { struct Equation_AST_Node final : AST_Node {
public:
Equation_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Equation_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Equation, std::move(t_loc), std::move(t_children)), AST_Node(std::move(t_ast_node_text), AST_Node_Type::Equation, std::move(t_loc), std::move(t_children)),
m_oper(Operators::to_operator(children[1]->text)) m_oper(Operators::to_operator(children[1]->text))
{ assert(children.size() == 3); } { assert(children.size() == 3); }
Operators::Opers m_oper;
mutable std::atomic_uint_fast32_t m_loc;
mutable std::atomic_uint_fast32_t m_clone_loc;
virtual ~Equation_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss); chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
Boxed_Value rhs = this->children[2]->eval(t_ss); Boxed_Value rhs = this->children[2]->eval(t_ss);
Boxed_Value lhs = this->children[0]->eval(t_ss); Boxed_Value lhs = this->children[0]->eval(t_ss);
@ -469,17 +447,20 @@ namespace chaiscript
return rhs; return rhs;
} }
private:
Operators::Opers m_oper;
mutable std::atomic_uint_fast32_t m_loc;
mutable std::atomic_uint_fast32_t m_clone_loc;
}; };
struct Global_Decl_AST_Node : public AST_Node { struct Global_Decl_AST_Node final : AST_Node {
public:
Global_Decl_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Global_Decl_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Global_Decl, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Global_Decl, std::move(t_loc), std::move(t_children)) { }
virtual ~Global_Decl_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
const std::string &idname = const std::string &idname =
[&]()->const std::string &{ [&]()->const std::string & {
if (children[0]->identifier == AST_Node_Type::Reference) { if (children[0]->identifier == AST_Node_Type::Reference) {
return children[0]->children[0]->text; return children[0]->children[0]->text;
} else { } else {
@ -498,12 +479,11 @@ namespace chaiscript
}; };
struct Var_Decl_AST_Node : public AST_Node { struct Var_Decl_AST_Node final : AST_Node {
public:
Var_Decl_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Var_Decl_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Var_Decl, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Var_Decl, std::move(t_loc), std::move(t_children)) { }
virtual ~Var_Decl_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
if (this->children[0]->identifier == AST_Node_Type::Reference) if (this->children[0]->identifier == AST_Node_Type::Reference)
{ {
return this->children[0]->eval(t_ss); return this->children[0]->eval(t_ss);
@ -524,7 +504,7 @@ namespace chaiscript
} }
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
return "var " + this->children[0]->text; return "var " + this->children[0]->text;
} }
@ -532,15 +512,14 @@ namespace chaiscript
}; };
struct Array_Call_AST_Node : public AST_Node { struct Array_Call_AST_Node final : AST_Node {
public:
Array_Call_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Array_Call_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Array_Call, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Array_Call, std::move(t_loc), std::move(t_children)) { }
virtual ~Array_Call_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss); chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
std::vector<Boxed_Value> params{children[0]->eval(t_ss), children[1]->eval(t_ss)}; const std::vector<Boxed_Value> params{children[0]->eval(t_ss), children[1]->eval(t_ss)};
try { try {
fpp.save_params(params); fpp.save_params(params);
@ -549,10 +528,9 @@ namespace chaiscript
catch(const exception::dispatch_error &e){ catch(const exception::dispatch_error &e){
throw exception::eval_error("Can not find appropriate array lookup operator '[]'.", e.parameters, e.functions, false, *t_ss ); throw exception::eval_error("Can not find appropriate array lookup operator '[]'.", e.parameters, e.functions, false, *t_ss );
} }
} }
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
std::ostringstream oss; std::ostringstream oss;
oss << this->children[0]->pretty_print(); oss << this->children[0]->pretty_print();
@ -567,19 +545,18 @@ namespace chaiscript
return oss.str(); return oss.str();
} }
private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc;
}; };
struct Dot_Access_AST_Node : public AST_Node { struct Dot_Access_AST_Node final : AST_Node {
public:
Dot_Access_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Dot_Access_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Dot_Access, std::move(t_loc), std::move(t_children)), AST_Node(std::move(t_ast_node_text), AST_Node_Type::Dot_Access, std::move(t_loc), std::move(t_children)),
m_fun_name( m_fun_name(
((children[2]->identifier == AST_Node_Type::Fun_Call) || (children[2]->identifier == AST_Node_Type::Array_Call))? ((children[2]->identifier == AST_Node_Type::Fun_Call) || (children[2]->identifier == AST_Node_Type::Array_Call))?
children[2]->children[0]->text:children[2]->text) { } children[2]->children[0]->text:children[2]->text) { }
virtual ~Dot_Access_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss); chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
@ -626,42 +603,37 @@ namespace chaiscript
private: private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc;
mutable std::atomic_uint_fast32_t m_array_loc; mutable std::atomic_uint_fast32_t m_array_loc;
std::string m_fun_name; const std::string m_fun_name;
}; };
struct Quoted_String_AST_Node : public AST_Node { struct Quoted_String_AST_Node final : AST_Node {
public:
Quoted_String_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) : Quoted_String_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Quoted_String, std::move(t_loc)), AST_Node(std::move(t_ast_node_text), AST_Node_Type::Quoted_String, std::move(t_loc)),
m_value(const_var(text)) { } m_value(const_var(text)) { }
virtual ~Quoted_String_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override {
return m_value; return m_value;
} }
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
return "\"" + text + "\""; return "\"" + text + "\"";
} }
private: private:
Boxed_Value m_value; Boxed_Value m_value;
}; };
struct Single_Quoted_String_AST_Node : public AST_Node { struct Single_Quoted_String_AST_Node final : AST_Node {
public:
Single_Quoted_String_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) : Single_Quoted_String_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Single_Quoted_String, std::move(t_loc)), AST_Node(std::move(t_ast_node_text), AST_Node_Type::Single_Quoted_String, std::move(t_loc)),
m_value(const_var(char(text.at(0)))) { } m_value(const_var(char(text.at(0)))) { }
virtual ~Single_Quoted_String_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override{
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override{
return m_value; return m_value;
} }
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
return "'" + text + "'"; return "'" + text + "'";
} }
@ -670,15 +642,12 @@ namespace chaiscript
Boxed_Value m_value; Boxed_Value m_value;
}; };
struct Lambda_AST_Node : public AST_Node { struct Lambda_AST_Node final : AST_Node {
public:
Lambda_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Lambda_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(t_ast_node_text, AST_Node_Type::Lambda, std::move(t_loc), std::move(t_children)), AST_Node(t_ast_node_text, AST_Node_Type::Lambda, std::move(t_loc), std::move(t_children)),
m_param_names(Arg_List_AST_Node::get_arg_names(children[1])) { } m_param_names(Arg_List_AST_Node::get_arg_names(children[1])) { }
virtual ~Lambda_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
const auto captures = [&]()->std::map<std::string, Boxed_Value>{ const auto captures = [&]()->std::map<std::string, Boxed_Value>{
std::map<std::string, Boxed_Value> named_captures; std::map<std::string, Boxed_Value> named_captures;
@ -689,7 +658,6 @@ namespace chaiscript
}(); }();
const auto numparams = this->children[1]->children.size(); const auto numparams = this->children[1]->children.size();
const auto param_names = m_param_names;
const auto param_types = Arg_List_AST_Node::get_arg_types(this->children[1], t_ss); const auto param_types = Arg_List_AST_Node::get_arg_types(this->children[1], t_ss);
const auto &lambda_node = this->children.back(); const auto &lambda_node = this->children.back();
@ -697,7 +665,7 @@ namespace chaiscript
return Boxed_Value( return Boxed_Value(
dispatch::make_dynamic_proxy_function( dispatch::make_dynamic_proxy_function(
[engine, lambda_node, param_names, captures](const std::vector<Boxed_Value> &t_params) [engine, lambda_node, param_names = this->m_param_names, captures](const std::vector<Boxed_Value> &t_params)
{ {
return detail::eval_function(engine, lambda_node, param_names, t_params, &captures); return detail::eval_function(engine, lambda_node, param_names, t_params, &captures);
}, },
@ -707,17 +675,15 @@ namespace chaiscript
} }
private: private:
std::vector<std::string> m_param_names; const std::vector<std::string> m_param_names;
}; };
struct Block_AST_Node : public AST_Node { struct Block_AST_Node final : AST_Node {
public:
Block_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Block_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Block, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Block, std::move(t_loc), std::move(t_children)) { }
virtual ~Block_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
const auto num_children = children.size(); const auto num_children = children.size();
@ -725,17 +691,14 @@ namespace chaiscript
children[i]->eval(t_ss); children[i]->eval(t_ss);
} }
return children.back()->eval(t_ss); return children.back()->eval(t_ss);
} }
}; };
struct Def_AST_Node : public AST_Node { struct Def_AST_Node final : AST_Node {
public:
Def_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Def_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Def, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Def, std::move(t_loc), std::move(t_children)) { }
virtual ~Def_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
std::vector<std::string> t_param_names; std::vector<std::string> t_param_names;
size_t numparams = 0; size_t numparams = 0;
AST_NodePtr guardnode; AST_NodePtr guardnode;
@ -794,12 +757,11 @@ namespace chaiscript
}; };
struct While_AST_Node : public AST_Node { struct While_AST_Node final : AST_Node {
public:
While_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : While_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::While, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::While, std::move(t_loc), std::move(t_children)) { }
virtual ~While_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
try { try {
@ -820,12 +782,11 @@ namespace chaiscript
} }
}; };
struct Class_AST_Node : public AST_Node { struct Class_AST_Node final : AST_Node {
public:
Class_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Class_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Class, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Class, std::move(t_loc), std::move(t_children)) { }
virtual ~Class_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
/// \todo do this better /// \todo do this better
@ -838,29 +799,26 @@ namespace chaiscript
} }
}; };
struct Ternary_Cond_AST_Node : public AST_Node { struct Ternary_Cond_AST_Node final : AST_Node {
public:
Ternary_Cond_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Ternary_Cond_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::If, std::move(t_loc), std::move(t_children)) AST_Node(std::move(t_ast_node_text), AST_Node_Type::If, std::move(t_loc), std::move(t_children))
{ assert(children.size() == 3); } { assert(children.size() == 3); }
virtual ~Ternary_Cond_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
if (get_bool_condition(children[0]->eval(t_ss))) { if (get_bool_condition(children[0]->eval(t_ss))) {
return children[1]->eval(t_ss); return children[1]->eval(t_ss);
} } else {
else {
return children[2]->eval(t_ss); return children[2]->eval(t_ss);
} }
} }
}; };
struct If_AST_Node : public AST_Node { struct If_AST_Node final : AST_Node {
public:
If_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : If_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::If, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::If, std::move(t_loc), std::move(t_children)) { }
virtual ~If_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
if (get_bool_condition(children[0]->eval(t_ss))) { if (get_bool_condition(children[0]->eval(t_ss))) {
return children[1]->eval(t_ss); return children[1]->eval(t_ss);
@ -886,14 +844,12 @@ namespace chaiscript
}; };
struct For_AST_Node : public AST_Node { struct For_AST_Node final : AST_Node {
public:
For_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : For_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::For, std::move(t_loc), std::move(t_children)) AST_Node(std::move(t_ast_node_text), AST_Node_Type::For, std::move(t_loc), std::move(t_children))
{ assert(children.size() == 4); } { assert(children.size() == 4); }
virtual ~For_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
try { try {
@ -920,12 +876,11 @@ namespace chaiscript
}; };
struct Switch_AST_Node : public AST_Node { struct Switch_AST_Node final : AST_Node {
public:
Switch_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Switch_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Switch, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Switch, std::move(t_loc), std::move(t_children)) { }
virtual ~Switch_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
bool breaking = false; bool breaking = false;
size_t currentCase = 1; size_t currentCase = 1;
bool hasMatched = false; bool hasMatched = false;
@ -964,14 +919,12 @@ namespace chaiscript
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc;
}; };
struct Case_AST_Node : public AST_Node { struct Case_AST_Node final : AST_Node {
public:
Case_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Case_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Case, std::move(t_loc), std::move(t_children)) AST_Node(std::move(t_ast_node_text), AST_Node_Type::Case, std::move(t_loc), std::move(t_children))
{ assert(children.size() == 2); /* how many children does it have? */ } { assert(children.size() == 2); /* how many children does it have? */ }
virtual ~Case_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
children[1]->eval(t_ss); children[1]->eval(t_ss);
@ -980,13 +933,12 @@ namespace chaiscript
} }
}; };
struct Default_AST_Node : public AST_Node { struct Default_AST_Node final : AST_Node {
public:
Default_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Default_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Default, std::move(t_loc), std::move(t_children)) AST_Node(std::move(t_ast_node_text), AST_Node_Type::Default, std::move(t_loc), std::move(t_children))
{ assert(children.size() == 1); } { assert(children.size() == 1); }
virtual ~Default_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
children[0]->eval(t_ss); children[0]->eval(t_ss);
@ -996,12 +948,11 @@ namespace chaiscript
}; };
struct Inline_Array_AST_Node : public AST_Node { struct Inline_Array_AST_Node final : AST_Node {
public:
Inline_Array_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Inline_Array_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Array, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Array, std::move(t_loc), std::move(t_children)) { }
virtual ~Inline_Array_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
try { try {
std::vector<Boxed_Value> vec; std::vector<Boxed_Value> vec;
if (!children.empty()) { if (!children.empty()) {
@ -1022,20 +973,20 @@ namespace chaiscript
} }
} }
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
return "[" + AST_Node::pretty_print() + "]"; return "[" + AST_Node::pretty_print() + "]";
} }
private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc;
}; };
struct Inline_Map_AST_Node : public AST_Node { struct Inline_Map_AST_Node final : AST_Node {
public:
Inline_Map_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Inline_Map_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Map, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Map, std::move(t_loc), std::move(t_children)) { }
virtual ~Inline_Map_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
try { try {
std::map<std::string, Boxed_Value> retval; std::map<std::string, Boxed_Value> retval;
@ -1055,15 +1006,15 @@ namespace chaiscript
} }
} }
private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc;
}; };
struct Return_AST_Node : public AST_Node { struct Return_AST_Node final : AST_Node {
public:
Return_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Return_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Return, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Return, std::move(t_loc), std::move(t_children)) { }
virtual ~Return_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
if (!this->children.empty()) { if (!this->children.empty()) {
throw detail::Return_Value(children[0]->eval(t_ss)); throw detail::Return_Value(children[0]->eval(t_ss));
} }
@ -1071,15 +1022,13 @@ namespace chaiscript
throw detail::Return_Value(Boxed_Value()); throw detail::Return_Value(Boxed_Value());
} }
} }
}; };
struct File_AST_Node : public AST_Node { struct File_AST_Node final : AST_Node {
public:
File_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : File_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::File, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::File, std::move(t_loc), std::move(t_children)) { }
virtual ~File_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
try { try {
const auto num_children = children.size(); const auto num_children = children.size();
@ -1099,13 +1048,12 @@ namespace chaiscript
} }
}; };
struct Reference_AST_Node : public AST_Node { struct Reference_AST_Node final : AST_Node {
public:
Reference_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Reference_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Reference, std::move(t_loc), std::move(t_children)) AST_Node(std::move(t_ast_node_text), AST_Node_Type::Reference, std::move(t_loc), std::move(t_children))
{ assert(children.size() == 1); } { assert(children.size() == 1); }
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
try { try {
Boxed_Value bv; Boxed_Value bv;
t_ss.add_object(this->children[0]->text, bv); t_ss.add_object(this->children[0]->text, bv);
@ -1115,19 +1063,15 @@ namespace chaiscript
throw exception::eval_error("Reserved word used as variable '" + this->children[0]->text + "'"); throw exception::eval_error("Reserved word used as variable '" + this->children[0]->text + "'");
} }
} }
virtual ~Reference_AST_Node() {}
}; };
struct Prefix_AST_Node : public AST_Node { struct Prefix_AST_Node final : AST_Node {
public:
Prefix_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Prefix_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Prefix, std::move(t_loc), std::move(t_children)), AST_Node(std::move(t_ast_node_text), AST_Node_Type::Prefix, std::move(t_loc), std::move(t_children)),
m_oper(Operators::to_operator(children[0]->text, true)) m_oper(Operators::to_operator(children[0]->text, true))
{ } { }
virtual ~Prefix_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
Boxed_Value bv(children[1]->eval(t_ss)); Boxed_Value bv(children[1]->eval(t_ss));
try { try {
@ -1150,63 +1094,51 @@ namespace chaiscript
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc;
}; };
struct Break_AST_Node : public AST_Node { struct Break_AST_Node final : AST_Node {
public:
Break_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Break_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Break, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Break, std::move(t_loc), std::move(t_children)) { }
virtual ~Break_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override{
throw detail::Break_Loop(); throw detail::Break_Loop();
} }
}; };
struct Continue_AST_Node : public AST_Node { struct Continue_AST_Node final : AST_Node {
public:
Continue_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Continue_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Continue, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Continue, std::move(t_loc), std::move(t_children)) { }
virtual ~Continue_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override{
throw detail::Continue_Loop(); throw detail::Continue_Loop();
} }
}; };
struct Noop_AST_Node : public AST_Node { struct Noop_AST_Node final : public AST_Node {
public:
Noop_AST_Node() : Noop_AST_Node() :
AST_Node("", AST_Node_Type::Noop, Parse_Location()), AST_Node("", AST_Node_Type::Noop, Parse_Location())
m_value(const_var(true))
{ } { }
virtual ~Noop_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override{
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &) const override{
// It's a no-op, that evaluates to "true" // It's a no-op, that evaluates to "true"
return m_value; // the magic-static version of const_var(true) helps us here
return const_var(true);
} }
private:
Boxed_Value m_value;
}; };
struct Map_Pair_AST_Node : public AST_Node { struct Map_Pair_AST_Node final : AST_Node {
public:
Map_Pair_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Map_Pair_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Map_Pair, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Map_Pair, std::move(t_loc), std::move(t_children)) { }
virtual ~Map_Pair_AST_Node() {}
}; };
struct Value_Range_AST_Node : public AST_Node { struct Value_Range_AST_Node final : AST_Node {
public:
Value_Range_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Value_Range_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Value_Range, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Value_Range, std::move(t_loc), std::move(t_children)) { }
virtual ~Value_Range_AST_Node() {}
}; };
struct Inline_Range_AST_Node : public AST_Node { struct Inline_Range_AST_Node final : AST_Node {
public:
Inline_Range_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Inline_Range_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Range, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Inline_Range, std::move(t_loc), std::move(t_children)) { }
virtual ~Inline_Range_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
try { try {
auto oper1 = children[0]->children[0]->children[0]->eval(t_ss); auto oper1 = children[0]->children[0]->children[0]->eval(t_ss);
auto oper2 = children[0]->children[0]->children[1]->eval(t_ss); auto oper2 = children[0]->children[0]->children[1]->eval(t_ss);
@ -1217,21 +1149,18 @@ namespace chaiscript
} }
} }
private:
mutable std::atomic_uint_fast32_t m_loc; mutable std::atomic_uint_fast32_t m_loc;
}; };
struct Annotation_AST_Node : public AST_Node { struct Annotation_AST_Node final : AST_Node {
public:
Annotation_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) : Annotation_AST_Node(std::string t_ast_node_text, Parse_Location t_loc) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Annotation, std::move(t_loc)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Annotation, std::move(t_loc)) { }
virtual ~Annotation_AST_Node() {}
}; };
struct Try_AST_Node : public AST_Node { struct Try_AST_Node final : AST_Node {
public:
Try_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Try_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Try, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Try, std::move(t_loc), std::move(t_children)) { }
virtual ~Try_AST_Node() {}
Boxed_Value handle_exception(const chaiscript::detail::Dispatch_State &t_ss, const Boxed_Value &t_except) const Boxed_Value handle_exception(const chaiscript::detail::Dispatch_State &t_ss, const Boxed_Value &t_except) const
{ {
@ -1294,7 +1223,7 @@ namespace chaiscript
return retval; return retval;
} }
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
Boxed_Value retval; Boxed_Value retval;
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
@ -1338,26 +1267,21 @@ namespace chaiscript
}; };
struct Catch_AST_Node : public AST_Node { struct Catch_AST_Node final : AST_Node {
public:
Catch_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Catch_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Catch, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Catch, std::move(t_loc), std::move(t_children)) { }
virtual ~Catch_AST_Node() {}
}; };
struct Finally_AST_Node : public AST_Node { struct Finally_AST_Node final : AST_Node {
public:
Finally_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Finally_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Finally, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Finally, std::move(t_loc), std::move(t_children)) { }
virtual ~Finally_AST_Node() {}
}; };
struct Method_AST_Node : public AST_Node { struct Method_AST_Node final : AST_Node {
public:
Method_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Method_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Method, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Method, std::move(t_loc), std::move(t_children)) { }
virtual ~Method_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
AST_NodePtr guardnode; AST_NodePtr guardnode;
@ -1443,12 +1367,11 @@ namespace chaiscript
}; };
struct Attr_Decl_AST_Node : public AST_Node { struct Attr_Decl_AST_Node final : AST_Node {
public:
Attr_Decl_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Attr_Decl_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Attr_Decl, std::move(t_loc), std::move(t_children)) { } AST_Node(std::move(t_ast_node_text), AST_Node_Type::Attr_Decl, std::move(t_loc), std::move(t_children)) { }
virtual ~Attr_Decl_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override
{ {
const auto &d = t_ss->get_parent_locals(); const auto &d = t_ss->get_parent_locals();
const auto itr = d.find("_current_class_name"); const auto itr = d.find("_current_class_name");
@ -1480,36 +1403,35 @@ namespace chaiscript
}; };
struct Logical_And_AST_Node : public AST_Node { struct Logical_And_AST_Node final : AST_Node {
public:
Logical_And_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Logical_And_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Logical_And, std::move(t_loc), std::move(t_children)) AST_Node(std::move(t_ast_node_text), AST_Node_Type::Logical_And, std::move(t_loc), std::move(t_children))
{ assert(children.size() == 3); } { assert(children.size() == 3); }
virtual ~Logical_And_AST_Node() {} Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ {
return const_var(get_bool_condition(children[0]->eval(t_ss)) return const_var(get_bool_condition(children[0]->eval(t_ss))
&& get_bool_condition(children[2]->eval(t_ss))); && get_bool_condition(children[2]->eval(t_ss)));
} }
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
return "(" + AST_Node::pretty_print() + ")"; return "(" + AST_Node::pretty_print() + ")";
} }
}; };
struct Logical_Or_AST_Node : public AST_Node { struct Logical_Or_AST_Node final : AST_Node {
public:
Logical_Or_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) : Logical_Or_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_NodePtr> t_children) :
AST_Node(std::move(t_ast_node_text), AST_Node_Type::Logical_Or, std::move(t_loc), std::move(t_children)) AST_Node(std::move(t_ast_node_text), AST_Node_Type::Logical_Or, std::move(t_loc), std::move(t_children))
{ assert(children.size() == 3); } { assert(children.size() == 3); }
virtual ~Logical_Or_AST_Node() {}
virtual Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override
{
return const_var(get_bool_condition(children[0]->eval(t_ss)) return const_var(get_bool_condition(children[0]->eval(t_ss))
|| get_bool_condition(children[2]->eval(t_ss))); || get_bool_condition(children[2]->eval(t_ss)));
} }
virtual std::string pretty_print() const override std::string pretty_print() const override
{ {
return "(" + AST_Node::pretty_print() + ")"; return "(" + AST_Node::pretty_print() + ")";
} }
@ -1520,3 +1442,4 @@ namespace chaiscript
} }
#endif /* CHAISCRIPT_EVAL_HPP_ */ #endif /* CHAISCRIPT_EVAL_HPP_ */