Code simplifications and spelling fixes found by clion

This commit is contained in:
Jason Turner 2015-04-27 08:09:31 -06:00
parent b2b604e2ad
commit 8889324b2d
12 changed files with 83 additions and 116 deletions

View File

@ -309,16 +309,7 @@ namespace chaiscript
static bool has_guard(const Const_Proxy_Function &t_pf) static bool has_guard(const Const_Proxy_Function &t_pf)
{ {
auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf); auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf) return pf && pf->get_guard();
{
if (pf->get_guard()) {
return true;
} else {
return false;
}
} else {
return false;
}
} }
static Const_Proxy_Function get_guard(const Const_Proxy_Function &t_pf) static Const_Proxy_Function get_guard(const Const_Proxy_Function &t_pf)
@ -372,12 +363,7 @@ namespace chaiscript
static bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf) static bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf)
{ {
const 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()) return pf && pf->get_parse_tree();
{
return true;
} else {
return false;
}
} }
static chaiscript::AST_NodePtr get_parse_tree(const chaiscript::Const_Proxy_Function &t_pf) static chaiscript::AST_NodePtr get_parse_tree(const chaiscript::Const_Proxy_Function &t_pf)

View File

@ -349,15 +349,15 @@ namespace chaiscript
template<typename ContainerType> template<typename ContainerType>
ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = ModulePtr(new Module())) ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = ModulePtr(new Module()))
{ {
typedef typename ContainerType::reference (ContainerType::*frontptr)(); typedef typename ContainerType::reference (ContainerType::*front_ptr)();
typedef typename ContainerType::const_reference (ContainerType::*constfrontptr)() const; typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const;
typedef void (ContainerType::*pushptr)(typename ContainerType::const_reference); typedef void (ContainerType::*push_ptr)(typename ContainerType::const_reference);
typedef void (ContainerType::*popptr)(); typedef void (ContainerType::*pop_ptr)();
m->add(fun(static_cast<frontptr>(&ContainerType::front)), "front"); m->add(fun(static_cast<front_ptr>(&ContainerType::front)), "front");
m->add(fun(static_cast<constfrontptr>(&ContainerType::front)), "front"); m->add(fun(static_cast<const_front_ptr>(&ContainerType::front)), "front");
m->add(fun(static_cast<pushptr>(&ContainerType::push_front)), m->add(fun(static_cast<push_ptr>(&ContainerType::push_front)),
[]()->std::string{ []()->std::string{
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) { if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
return "push_front_ref"; return "push_front_ref";
@ -366,7 +366,7 @@ namespace chaiscript
} }
}()); }());
m->add(fun(static_cast<popptr>(&ContainerType::pop_front)), "pop_front"); m->add(fun(static_cast<pop_ptr>(&ContainerType::pop_front)), "pop_front");
return m; return m;
} }
@ -439,9 +439,9 @@ namespace chaiscript
{ {
m->add(user_type<MapType>(), type); m->add(user_type<MapType>(), type);
typedef typename MapType::mapped_type &(MapType::*elemaccess)(const typename MapType::key_type &); typedef typename MapType::mapped_type &(MapType::*elem_access)(const typename MapType::key_type &);
m->add(fun(static_cast<elemaccess>(&MapType::operator[])), "[]"); m->add(fun(static_cast<elem_access>(&MapType::operator[])), "[]");
container_type<MapType>(type, m); container_type<MapType>(type, m);
default_constructible_type<MapType>(type, m); default_constructible_type<MapType>(type, m);

View File

@ -280,8 +280,8 @@ namespace chaiscript
virtual bool operator==(const dispatch::Proxy_Function_Base &rhs) const CHAISCRIPT_OVERRIDE virtual bool operator==(const dispatch::Proxy_Function_Base &rhs) const CHAISCRIPT_OVERRIDE
{ {
try { try {
const auto &dispatchfun = dynamic_cast<const Dispatch_Function &>(rhs); const auto &dispatch_fun = dynamic_cast<const Dispatch_Function &>(rhs);
return m_funcs == dispatchfun.m_funcs; return m_funcs == dispatch_fun.m_funcs;
} catch (const std::bad_cast &) { } catch (const std::bad_cast &) {
return false; return false;
} }
@ -1138,12 +1138,7 @@ namespace chaiscript
{ {
if (dynamic_lhs->get_guard()) if (dynamic_lhs->get_guard())
{ {
if (dynamic_rhs->get_guard()) return dynamic_rhs->get_guard() ? false : true;
{
return false;
} else {
return true;
}
} else { } else {
return false; return false;
} }

View File

@ -213,12 +213,7 @@ namespace chaiscript
virtual bool operator==(const Proxy_Function_Base &f) const CHAISCRIPT_OVERRIDE virtual bool operator==(const Proxy_Function_Base &f) const CHAISCRIPT_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);
if (dc) return dc && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
{
return dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
} else {
return false;
}
} }
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE

View File

@ -31,8 +31,8 @@ namespace chaiscript
{ {
public: public:
CHAISCRIPT_CONSTEXPR Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void, CHAISCRIPT_CONSTEXPR Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void,
bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bareti) bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bare_ti)
: m_type_info(t_ti), m_bare_type_info(t_bareti), : m_type_info(t_ti), m_bare_type_info(t_bare_ti),
m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer), m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer),
m_is_void(t_is_void), m_is_arithmetic(t_is_arithmetic), m_is_void(t_is_void), m_is_arithmetic(t_is_arithmetic),
m_is_undef(false) m_is_undef(false)

View File

@ -229,8 +229,7 @@ namespace chaiscript
if (f) if (f)
{ {
std::shared_ptr<const dispatch::Dynamic_Proxy_Function> dynfunguard auto dynfunguard = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(f);
= std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(f);
if (dynfunguard) if (dynfunguard)
{ {
retval += " : " + format_guard(dynfunguard->get_parse_tree()); retval += " : " + format_guard(dynfunguard->get_parse_tree());
@ -486,8 +485,8 @@ namespace chaiscript
private: private:
// Copy and assignment explicitly unimplemented // Copy and assignment explicitly unimplemented
AST_Node(const AST_Node &); AST_Node(const AST_Node &) = delete;
AST_Node& operator=(const AST_Node &); AST_Node& operator=(const AST_Node &) = delete;
}; };

View File

@ -166,11 +166,11 @@ namespace chaiscript
static std::string get_error_message(DWORD t_err) static std::string get_error_message(DWORD t_err)
{ {
typedef LPTSTR StringType;
#if defined(_UNICODE) || defined(UNICODE) #if defined(_UNICODE) || defined(UNICODE)
typedef LPWSTR StringType;
std::wstring retval = L"Unknown Error"; std::wstring retval = L"Unknown Error";
#else #else
typedef LPSTR StringType;
std::string retval = "Unknown Error"; std::string retval = "Unknown Error";
#endif #endif
StringType lpMsgBuf = nullptr; StringType lpMsgBuf = nullptr;
@ -182,7 +182,7 @@ namespace chaiscript
NULL, NULL,
t_err, t_err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(StringType)&lpMsgBuf, reinterpret_cast<StringType>(&lpMsgBuf),
0, NULL ) != 0 && lpMsgBuf) 0, NULL ) != 0 && lpMsgBuf)
{ {
retval = lpMsgBuf; retval = lpMsgBuf;
@ -264,8 +264,8 @@ namespace chaiscript
std::map<std::string, detail::Loadable_Module_Ptr> m_loaded_modules; std::map<std::string, detail::Loadable_Module_Ptr> m_loaded_modules;
std::set<std::string> m_active_loaded_modules; std::set<std::string> m_active_loaded_modules;
std::vector<std::string> m_modulepaths; std::vector<std::string> m_module_paths;
std::vector<std::string> m_usepaths; std::vector<std::string> m_use_paths;
chaiscript::detail::Dispatch_Engine m_engine; chaiscript::detail::Dispatch_Engine m_engine;
@ -299,7 +299,7 @@ namespace chaiscript
/// Evaluates the given file and looks in the 'use' paths /// Evaluates the given file and looks in the 'use' paths
const Boxed_Value internal_eval_file(const std::string &t_filename) { const Boxed_Value internal_eval_file(const std::string &t_filename) {
for (const auto &path : m_usepaths) for (const auto &path : m_use_paths)
{ {
try { try {
const auto appendedpath = path + t_filename; const auto appendedpath = path + t_filename;
@ -441,16 +441,16 @@ namespace chaiscript
ChaiScript(const ModulePtr &t_lib, ChaiScript(const ModulePtr &t_lib,
std::vector<std::string> t_modulepaths = std::vector<std::string>(), std::vector<std::string> t_modulepaths = std::vector<std::string>(),
std::vector<std::string> t_usepaths = std::vector<std::string>()) std::vector<std::string> t_usepaths = std::vector<std::string>())
: m_modulepaths(std::move(t_modulepaths)), m_usepaths(std::move(t_usepaths)) : m_module_paths(std::move(t_modulepaths)), m_use_paths(std::move(t_usepaths))
{ {
if (m_modulepaths.empty()) if (m_module_paths.empty())
{ {
m_modulepaths.push_back(""); m_module_paths.push_back("");
} }
if (m_usepaths.empty()) if (m_use_paths.empty())
{ {
m_usepaths.push_back(""); m_use_paths.push_back("");
} }
build_eval_system(t_lib); build_eval_system(t_lib);
@ -465,16 +465,16 @@ namespace chaiscript
/// \param[in] t_usepaths Vector of paths to search when attempting to "use" an included ChaiScript file /// \param[in] t_usepaths Vector of paths to search when attempting to "use" an included ChaiScript file
ChaiScript( std::vector<std::string> t_modulepaths = std::vector<std::string>(), ChaiScript( std::vector<std::string> t_modulepaths = std::vector<std::string>(),
std::vector<std::string> t_usepaths = std::vector<std::string>()) std::vector<std::string> t_usepaths = std::vector<std::string>())
: m_modulepaths(std::move(t_modulepaths)), m_usepaths(std::move(t_usepaths)) : m_module_paths(std::move(t_modulepaths)), m_use_paths(std::move(t_usepaths))
{ {
if (m_modulepaths.empty()) if (m_module_paths.empty())
{ {
m_modulepaths.push_back(""); m_module_paths.push_back("");
} }
if (m_usepaths.empty()) if (m_use_paths.empty())
{ {
m_usepaths.push_back(""); m_use_paths.push_back("");
} }
#if defined(_POSIX_VERSION) && !defined(__CYGWIN__) #if defined(_POSIX_VERSION) && !defined(__CYGWIN__)
@ -507,7 +507,7 @@ namespace chaiscript
dllpath = std::string(&buf.front(), pathlen); dllpath = std::string(&buf.front(), pathlen);
} }
m_modulepaths.insert(m_modulepaths.begin(), dllpath+"/"); m_module_paths.insert(m_module_paths.begin(), dllpath+"/");
} }
#endif #endif
@ -559,7 +559,7 @@ namespace chaiscript
/// \param[in] t_filename Filename to load and evaluate /// \param[in] t_filename Filename to load and evaluate
Boxed_Value use(const std::string &t_filename) Boxed_Value use(const std::string &t_filename)
{ {
for (const auto &path : m_usepaths) for (const auto &path : m_use_paths)
{ {
try { try {
const auto appendedpath = path + t_filename; const auto appendedpath = path + t_filename;
@ -758,7 +758,7 @@ namespace chaiscript
std::vector<std::string> postfixes{".dll", ".so", ".bundle", ""}; std::vector<std::string> postfixes{".dll", ".so", ".bundle", ""};
for (auto & elem : m_modulepaths) for (auto & elem : m_module_paths)
{ {
for (auto & prefix : prefixes) for (auto & prefix : prefixes)
{ {

View File

@ -1330,7 +1330,7 @@ namespace chaiscript
end_point = this->children.size() - 1; end_point = this->children.size() - 1;
} }
for (size_t i = 1; i < end_point; ++i) { for (size_t i = 1; i < end_point; ++i) {
chaiscript::eval::detail::Scope_Push_Pop catchscope(t_ss); chaiscript::eval::detail::Scope_Push_Pop catch_scope(t_ss);
AST_NodePtr catch_block = this->children[i]; AST_NodePtr catch_block = this->children[i];
if (catch_block->children.size() == 1) { if (catch_block->children.size() == 1) {

View File

@ -257,12 +257,12 @@ namespace chaiscript
for (auto &c : p->children) for (auto &c : p->children)
{ {
if (c->identifier == AST_Node_Type::Def && c->children.size() > 0) { if (c->identifier == AST_Node_Type::Def && c->children.size() > 0) {
auto &lastchild = c->children.back(); auto &last_child = c->children.back();
if (lastchild->identifier == AST_Node_Type::Block) { if (last_child->identifier == AST_Node_Type::Block) {
auto &blocklastchild = lastchild->children.back(); auto &block_last_child = last_child->children.back();
if (blocklastchild->identifier == AST_Node_Type::Return) { if (block_last_child->identifier == AST_Node_Type::Return) {
if (blocklastchild->children.size() == 1) { if (block_last_child->children.size() == 1) {
blocklastchild = blocklastchild->children[0]; block_last_child = block_last_child->children[0];
} }
} }
} }
@ -789,30 +789,26 @@ namespace chaiscript
} }
/// Reads (and potentially captures) an identifier from input /// Reads (and potentially captures) an identifier from input
bool Id(const bool t_capture = false) { bool Id() {
SkipWS(); SkipWS();
if (!t_capture) { const auto start = m_input_pos;
return Id_(); const auto prev_col = m_col;
const auto prev_line = m_line;
if (Id_()) {
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>(
[&]()->std::string{
if (*start == '`') {
//Id Literal
return std::string(start+1, m_input_pos-1);
} else {
return std::string(start, m_input_pos);
}
}(),
m_filename, prev_line, prev_col, m_line, m_col));
return true;
} else { } else {
const auto start = m_input_pos; return false;
const auto prev_col = m_col;
const auto prev_line = m_line;
if (Id_()) {
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>(
[&]()->std::string{
if (*start == '`') {
//Id Literal
return std::string(start+1, m_input_pos-1);
} else {
return std::string(start, m_input_pos);
}
}(),
m_filename, prev_line, prev_col, m_line, m_col));
return true;
} else {
return false;
}
} }
} }
@ -821,14 +817,14 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size(); const auto prev_stack_top = m_match_stack.size();
SkipWS(); SkipWS();
if (!Id(true)) { if (!Id()) {
return false; return false;
} }
SkipWS(); SkipWS();
if (t_type_allowed) { if (t_type_allowed) {
Id(true); Id();
} }
build_match(std::make_shared<eval::Arg_AST_Node>(), prev_stack_top); build_match(std::make_shared<eval::Arg_AST_Node>(), prev_stack_top);
@ -1426,7 +1422,7 @@ namespace chaiscript
if (Keyword("def")) { if (Keyword("def")) {
retval = true; retval = true;
if (!Id(true)) { if (!Id()) {
throw exception::eval_error("Missing function name in definition", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Missing function name in definition", File_Position(m_line, m_col), *m_filename);
} }
@ -1436,7 +1432,7 @@ namespace chaiscript
//We're now a method //We're now a method
is_method = true; is_method = true;
if (!Id(true)) { if (!Id()) {
throw exception::eval_error("Missing method name in definition", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Missing method name in definition", File_Position(m_line, m_col), *m_filename);
} }
} }
@ -1609,7 +1605,7 @@ namespace chaiscript
if (Keyword("class")) { if (Keyword("class")) {
retval = true; retval = true;
if (!Id(true)) { if (!Id()) {
throw exception::eval_error("Missing class name in definition", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Missing class name in definition", File_Position(m_line, m_col), *m_filename);
} }
@ -1890,7 +1886,7 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size(); const auto prev_stack_top = m_match_stack.size();
if (Lambda() || Num(true) || Quoted_String(true) || Single_Quoted_String(true) || if (Lambda() || Num(true) || Quoted_String(true) || Single_Quoted_String(true) ||
Paren_Expression() || Inline_Container() || Id(true)) Paren_Expression() || Inline_Container() || Id())
{ {
retval = true; retval = true;
bool has_more = true; bool has_more = true;
@ -1931,7 +1927,7 @@ namespace chaiscript
} }
else if (Symbol(".", true)) { else if (Symbol(".", true)) {
has_more = true; has_more = true;
if (!(Id(true))) { if (!(Id())) {
throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete array access", File_Position(m_line, m_col), *m_filename);
} }
@ -1952,7 +1948,7 @@ namespace chaiscript
if (t_class_context && (Keyword("attr") || Keyword("auto") || Keyword("var"))) { if (t_class_context && (Keyword("attr") || Keyword("auto") || Keyword("var"))) {
retval = true; retval = true;
if (!Id(true)) { if (!Id()) {
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
} }
@ -1960,7 +1956,7 @@ namespace chaiscript
} else if (Keyword("auto") || Keyword("var")) { } else if (Keyword("auto") || Keyword("var")) {
retval = true; retval = true;
if (!(Reference() || Id(true))) { if (!(Reference() || Id())) {
throw exception::eval_error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete variable declaration", File_Position(m_line, m_col), *m_filename);
} }
@ -1968,13 +1964,13 @@ namespace chaiscript
} else if (Keyword("attr")) { } else if (Keyword("attr")) {
retval = true; retval = true;
if (!Id(true)) { if (!Id()) {
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
} }
if (!Symbol("::", false)) { if (!Symbol("::", false)) {
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
} }
if (!Id(true)) { if (!Id()) {
throw exception::eval_error("Missing attribute name in definition", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Missing attribute name in definition", File_Position(m_line, m_col), *m_filename);
} }
@ -2036,7 +2032,7 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size(); const auto prev_stack_top = m_match_stack.size();
if (Symbol("&", false)) { if (Symbol("&", false)) {
if (!Id(true)) { if (!Id()) {
throw exception::eval_error("Incomplete '&' expression", File_Position(m_line, m_col), *m_filename); throw exception::eval_error("Incomplete '&' expression", File_Position(m_line, m_col), *m_filename);
} }
@ -2071,11 +2067,7 @@ namespace chaiscript
/// Parses any of a group of 'value' style ast_node groups from input /// Parses any of a group of 'value' style ast_node groups from input
bool Value() { bool Value() {
if (Var_Decl() || Dot_Fun_Array() || Prefix()) { return Var_Decl() || Dot_Fun_Array() || Prefix();
return true;
} else {
return false;
}
} }
bool Operator_Helper(const size_t t_precedence) { bool Operator_Helper(const size_t t_precedence) {

View File

@ -309,7 +309,7 @@ class Range
/// \brief Moves the front pointer forward one /// \brief Moves the front pointer forward one
/// ///
/// \post front() returne the element at front() + 1; /// \post front() returns the element at front() + 1;
void pop_front(); void pop_front();
}; };
@ -340,7 +340,7 @@ class Const_Range
/// \brief Moves the front pointer forward one /// \brief Moves the front pointer forward one
/// ///
/// \post front() returne the element at front() + 1; /// \post front() returns the element at front() + 1;
void pop_front(); void pop_front();
}; };

View File

@ -38,8 +38,8 @@ namespace chaiscript
/// { {fun(&test::function), "function"}, /// { {fun(&test::function), "function"},
/// {fun(&test::function2), "function2"}, /// {fun(&test::function2), "function2"},
/// {fun(&test::function3), "function3"}, /// {fun(&test::function3), "function3"},
/// {fun(static_cast<std::string(test::*)(double)>(&test::functionoverload)), "functionoverload" }, /// {fun(static_cast<std::string(test::*)(double)>(&test::function_overload)), "function_overload" },
/// {fun(static_cast<std::string(test::*)(int)>(&test::functionoverload)), "functionoverload" }, /// {fun(static_cast<std::string(test::*)(int)>(&test::function_overload)), "function_overload" },
/// {fun(static_cast<test & (test::*)(const test &)>(&test::operator=)), "=" } /// {fun(static_cast<test & (test::*)(const test &)>(&test::operator=)), "=" }
/// } /// }
/// ); /// );

View File

@ -35,7 +35,7 @@ class TestBaseType
std::function<int (int)> func_member; std::function<int (int)> func_member;
private: private:
TestBaseType &operator=(const TestBaseType &); TestBaseType &operator=(const TestBaseType &) = delete;
}; };
class Type2 class Type2
@ -82,7 +82,7 @@ class TestDerivedType : public TestBaseType
int derived_only_func() { return 19; } int derived_only_func() { return 19; }
private: private:
TestDerivedType &operator=(const TestDerivedType &); TestDerivedType &operator=(const TestDerivedType &) = delete;
}; };
class TestMoreDerivedType : public TestDerivedType class TestMoreDerivedType : public TestDerivedType