Various code cleanups

This commit is contained in:
Jason Turner 2015-01-31 10:10:35 -07:00
parent 76ac7c36fe
commit 722e9ed3d1
5 changed files with 76 additions and 108 deletions

View File

@ -187,9 +187,7 @@ namespace chaiscript
class Bootstrap
{
private:
/**
* Function allowing for assignment of an unknown type to any other value
*/
/// Function allowing for assignment of an unknown type to any other value
static Boxed_Value unknown_assign(Boxed_Value lhs, Boxed_Value rhs)
{
if (lhs.is_undef())
@ -262,7 +260,7 @@ namespace chaiscript
Const_Proxy_Function f = boxed_cast<Const_Proxy_Function>(params[0]);
return Boxed_Value(Const_Proxy_Function(std::make_shared<dispatch::Bound_Function>(f,
return Boxed_Value(Const_Proxy_Function(std::make_shared<dispatch::Bound_Function>(std::move(f),
std::vector<Boxed_Value>(params.begin() + 1, params.end()))));
}
@ -284,15 +282,10 @@ namespace chaiscript
static Const_Proxy_Function get_guard(const Const_Proxy_Function &t_pf)
{
auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf)
const auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf && pf->get_guard())
{
if (pf->get_guard())
{
return pf->get_guard();
} else {
throw std::runtime_error("Function does not have a guard");
}
return pf->get_guard();
} else {
throw std::runtime_error("Function does not have a guard");
}
@ -337,14 +330,10 @@ namespace chaiscript
static bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf)
{
if (auto pf = std::dynamic_pointer_cast<const chaiscript::dispatch::Dynamic_Proxy_Function>(t_pf))
const auto pf = std::dynamic_pointer_cast<const chaiscript::dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf && pf->get_parse_tree())
{
if (pf->get_parse_tree())
{
return true;
} else {
return false;
}
return true;
} else {
return false;
}
@ -352,14 +341,10 @@ namespace chaiscript
static chaiscript::AST_NodePtr get_parse_tree(const chaiscript::Const_Proxy_Function &t_pf)
{
if (auto pf = std::dynamic_pointer_cast<const chaiscript::dispatch::Dynamic_Proxy_Function>(t_pf))
const auto pf = std::dynamic_pointer_cast<const chaiscript::dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf && pf->get_parse_tree())
{
if (pf->get_parse_tree())
{
return pf->get_parse_tree();
} else {
throw std::runtime_error("Function does not have a parse tree");
}
return pf->get_parse_tree();
} else {
throw std::runtime_error("Function does not have a parse tree");
}

View File

@ -228,8 +228,7 @@ namespace chaiscript
std::advance(itr, pos);
container.erase(itr);
}
}
}
template<typename ContainerType>
@ -303,15 +302,15 @@ namespace chaiscript
template<typename ContainerType>
ModulePtr sequence_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
{
std::string insert_name;
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value))
{
insert_name = "insert_ref_at";
} else {
insert_name = "insert_at";
}
m->add(fun(&detail::insert_at<ContainerType>),
[](){
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
return "insert_ref_at";
} else {
return "insert_at";
}
}());
m->add(fun(&detail::insert_at<ContainerType>), insert_name);
m->add(fun(&detail::erase_at<ContainerType>), "erase_at");
return m;
@ -327,16 +326,17 @@ namespace chaiscript
m->add(fun(static_cast<backptr>(&ContainerType::back)), "back");
std::string push_back_name;
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value))
{
push_back_name = "push_back_ref";
} else {
push_back_name = "push_back";
}
typedef void (ContainerType::*push_back)(const typename ContainerType::value_type &);
m->add(fun(static_cast<push_back>(&ContainerType::push_back)), push_back_name);
m->add(fun(static_cast<push_back>(&ContainerType::push_back)),
[](){
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
return "push_back_ref";
} else {
return "push_back";
}
}());
m->add(fun(&ContainerType::pop_back), "pop_back");
return m;
}
@ -356,15 +356,15 @@ namespace chaiscript
m->add(fun(static_cast<frontptr>(&ContainerType::front)), "front");
m->add(fun(static_cast<constfrontptr>(&ContainerType::front)), "front");
std::string push_front_name;
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value))
{
push_front_name = "push_front_ref";
} else {
push_front_name = "push_front";
}
m->add(fun(static_cast<pushptr>(&ContainerType::push_front)),
[](){
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
return "push_front_ref";
} else {
return "push_front";
}
}());
m->add(fun(static_cast<pushptr>(&ContainerType::push_front)), push_front_name);
m->add(fun(static_cast<popptr>(&ContainerType::pop_front)), "pop_front");
return m;
}
@ -417,15 +417,16 @@ namespace chaiscript
m->add(fun(&detail::insert<ContainerType>), "insert");
std::string insert_name;
if (typeid(typename ContainerType::mapped_type) == typeid(Boxed_Value))
{
insert_name = "insert_ref";
} else {
insert_name = "insert";
}
m->add(fun(&detail::insert_ref<ContainerType>),
[](){
if (typeid(typename ContainerType::mapped_type) == typeid(Boxed_Value)) {
return "insert_ref";
} else {
return "insert";
}
}());
m->add(fun(&detail::insert_ref<ContainerType>), insert_name);
return m;
}
@ -536,14 +537,15 @@ namespace chaiscript
input_range_type<String>(type, m);
//Special case: add push_back to string (which doesn't support other back_insertion operations
std::string push_back_name;
if (typeid(typename String::value_type) == typeid(Boxed_Value))
{
push_back_name = "push_back_ref";
} else {
push_back_name = "push_back";
}
m->add(fun(&String::push_back), push_back_name);
m->add(fun(&String::push_back),
[](){
if (typeid(typename String::value_type) == typeid(Boxed_Value)) {
return "push_back_ref";
} else {
return "push_back";
}
}());
typedef std::function<size_t (const String *, const String &, size_t)> find_func;
@ -581,9 +583,6 @@ namespace chaiscript
return m;
}
}
}
}

View File

@ -147,8 +147,7 @@ namespace chaiscript
Boxed_Value operator()(const std::vector<Boxed_Value> &params, const chaiscript::Type_Conversions &t_conversions) const
{
Boxed_Value bv = do_call(params, t_conversions);
return bv;
return do_call(params, t_conversions);
}
/// Returns a vector containing all of the types of the parameters the function returns/takes
@ -177,7 +176,7 @@ namespace chaiscript
if (m_arity < 0)
{
return true;
} else if (size_t(m_arity) == vals.size()) {
} else if (static_cast<size_t>(m_arity) == vals.size()) {
if (m_arity == 0)
{
return true;
@ -234,16 +233,14 @@ namespace chaiscript
virtual bool compare_first_type(const Boxed_Value &bv, const Type_Conversions &t_conversions) const
{
const std::vector<Type_Info> &types = get_param_types();
const auto &types = get_param_types();
if (types.size() < 2)
{
return true;
}
const Type_Info &ti = types[1];
return compare_type_to_param(ti, bv, t_conversions);
return compare_type_to_param(types[1], bv, t_conversions);
}
static bool compare_types(const std::vector<Type_Info> &tis, const std::vector<Boxed_Value> &bvs)
@ -252,7 +249,7 @@ namespace chaiscript
{
return false;
} else {
size_t size = bvs.size();
const size_t size = bvs.size();
for (size_t i = 0; i < size; ++i)
{
if (!(tis[i+1].bare_equal(bvs[i].get_type_info()) && tis[i+1].is_const() >= bvs[i].get_type_info().is_const() ))
@ -412,20 +409,16 @@ namespace chaiscript
std::function<Boxed_Value (const std::vector<Boxed_Value> &)> m_f;
};
/**
* An object used by Bound_Function to represent "_" parameters
* of a binding. This allows for unbound parameters during bind.
*/
/// An object used by Bound_Function to represent "_" parameters
/// of a binding. This allows for unbound parameters during bind.
struct Placeholder_Object
{
};
/**
* An implementation of Proxy_Function that takes a Proxy_Function
* and substitutes bound parameters into the parameter list
* at runtime, when call() is executed.
* it is used for bind(function, param1, _, param2) style calls
*/
/// An implementation of Proxy_Function that takes a Proxy_Function
/// and substitutes bound parameters into the parameter list
/// at runtime, when call() is executed.
/// it is used for bind(function, param1, _, param2) style calls
class Bound_Function : public Proxy_Function_Base
{
public:
@ -451,9 +444,7 @@ namespace chaiscript
virtual std::vector<Const_Proxy_Function> get_contained_functions() const CHAISCRIPT_OVERRIDE
{
std::vector<Const_Proxy_Function> fs;
fs.push_back(m_f);
return fs;
return std::vector<Const_Proxy_Function>{m_f};
}
@ -504,8 +495,7 @@ namespace chaiscript
std::vector<Type_Info> types = t_f->get_param_types();
assert(types.size() == t_args.size() + 1);
std::vector<Type_Info> retval;
retval.push_back(types[0]);
std::vector<Type_Info> retval{types[0]};
for (size_t i = 0; i < types.size()-1; ++i)
{
if (t_args[i].get_type_info() == chaiscript::detail::Get_Type_Info<Placeholder_Object>::get())
@ -544,7 +534,7 @@ namespace chaiscript
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE
{
if (int(vals.size()) != get_arity())
if (static_cast<int>(vals.size()) != get_arity())
{
return false;
}
@ -555,11 +545,9 @@ namespace chaiscript
virtual bool compare_types_with_cast(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const = 0;
};
/**
* The standard typesafe function call implementation of Proxy_Function
* It takes a std::function<> object and performs runtime
* type checking of Boxed_Value parameters, in a type safe manner
*/
/// The standard typesafe function call implementation of Proxy_Function
/// It takes a std::function<> object and performs runtime
/// type checking of Boxed_Value parameters, in a type safe manner
template<typename Func>
class Proxy_Function_Impl : public Proxy_Function_Impl_Base
{
@ -598,9 +586,7 @@ namespace chaiscript
Func *m_dummy_func;
};
/**
* Attribute getter Proxy_Function implementation
*/
/// Attribute getter Proxy_Function implementation
template<typename T, typename Class>
class Attribute_Access : public Proxy_Function_Base
{

View File

@ -62,7 +62,7 @@ namespace chaiscript
/// \todo is it possible to reduce the number of templates generated here?
return Proxy_Function(
new Proxy_Function_Impl<typename FunctionSignature<decltype(to_function(t)) >::Signature>(to_function(t)));
}
}
};
template<>
@ -171,7 +171,7 @@ namespace chaiscript
{
return fun(detail::bind_first(detail::bind_first(t, q), r));
}
}

View File

@ -129,9 +129,7 @@ namespace chaiscript
namespace detail
{
/**
* Helper used to create a Type_Info object
*/
/// Helper used to create a Type_Info object
template<typename T>
struct Get_Type_Info
{