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)
{
auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf)
{
if (pf->get_guard()) {
return true;
} else {
return false;
}
} else {
return false;
}
return pf && pf->get_guard();
}
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)
{
const auto pf = std::dynamic_pointer_cast<const chaiscript::dispatch::Dynamic_Proxy_Function>(t_pf);
if (pf && pf->get_parse_tree())
{
return true;
} else {
return false;
}
return pf && pf->get_parse_tree();
}
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>
ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = ModulePtr(new Module()))
{
typedef typename ContainerType::reference (ContainerType::*frontptr)();
typedef typename ContainerType::const_reference (ContainerType::*constfrontptr)() const;
typedef void (ContainerType::*pushptr)(typename ContainerType::const_reference);
typedef void (ContainerType::*popptr)();
typedef typename ContainerType::reference (ContainerType::*front_ptr)();
typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const;
typedef void (ContainerType::*push_ptr)(typename ContainerType::const_reference);
typedef void (ContainerType::*pop_ptr)();
m->add(fun(static_cast<frontptr>(&ContainerType::front)), "front");
m->add(fun(static_cast<constfrontptr>(&ContainerType::front)), "front");
m->add(fun(static_cast<front_ptr>(&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{
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
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;
}
@ -439,9 +439,9 @@ namespace chaiscript
{
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);
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
{
try {
const auto &dispatchfun = dynamic_cast<const Dispatch_Function &>(rhs);
return m_funcs == dispatchfun.m_funcs;
const auto &dispatch_fun = dynamic_cast<const Dispatch_Function &>(rhs);
return m_funcs == dispatch_fun.m_funcs;
} catch (const std::bad_cast &) {
return false;
}
@ -1138,12 +1138,7 @@ namespace chaiscript
{
if (dynamic_lhs->get_guard())
{
if (dynamic_rhs->get_guard())
{
return false;
} else {
return true;
}
return dynamic_rhs->get_guard() ? false : true;
} else {
return false;
}

View File

@ -213,12 +213,7 @@ namespace chaiscript
virtual bool operator==(const Proxy_Function_Base &f) const CHAISCRIPT_OVERRIDE
{
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
if (dc)
{
return dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
} else {
return false;
}
return dc && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
}
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:
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)
: m_type_info(t_ti), m_bare_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_bare_ti),
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_undef(false)

View File

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

View File

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

View File

@ -1330,7 +1330,7 @@ namespace chaiscript
end_point = this->children.size() - 1;
}
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];
if (catch_block->children.size() == 1) {

View File

@ -257,12 +257,12 @@ namespace chaiscript
for (auto &c : p->children)
{
if (c->identifier == AST_Node_Type::Def && c->children.size() > 0) {
auto &lastchild = c->children.back();
if (lastchild->identifier == AST_Node_Type::Block) {
auto &blocklastchild = lastchild->children.back();
if (blocklastchild->identifier == AST_Node_Type::Return) {
if (blocklastchild->children.size() == 1) {
blocklastchild = blocklastchild->children[0];
auto &last_child = c->children.back();
if (last_child->identifier == AST_Node_Type::Block) {
auto &block_last_child = last_child->children.back();
if (block_last_child->identifier == AST_Node_Type::Return) {
if (block_last_child->children.size() == 1) {
block_last_child = block_last_child->children[0];
}
}
}
@ -789,30 +789,26 @@ namespace chaiscript
}
/// Reads (and potentially captures) an identifier from input
bool Id(const bool t_capture = false) {
bool Id() {
SkipWS();
if (!t_capture) {
return Id_();
const auto start = m_input_pos;
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 {
const auto start = m_input_pos;
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;
}
return false;
}
}
@ -821,14 +817,14 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size();
SkipWS();
if (!Id(true)) {
if (!Id()) {
return false;
}
SkipWS();
if (t_type_allowed) {
Id(true);
Id();
}
build_match(std::make_shared<eval::Arg_AST_Node>(), prev_stack_top);
@ -1426,7 +1422,7 @@ namespace chaiscript
if (Keyword("def")) {
retval = true;
if (!Id(true)) {
if (!Id()) {
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
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);
}
}
@ -1609,7 +1605,7 @@ namespace chaiscript
if (Keyword("class")) {
retval = true;
if (!Id(true)) {
if (!Id()) {
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();
if (Lambda() || Num(true) || Quoted_String(true) || Single_Quoted_String(true) ||
Paren_Expression() || Inline_Container() || Id(true))
Paren_Expression() || Inline_Container() || Id())
{
retval = true;
bool has_more = true;
@ -1931,7 +1927,7 @@ namespace chaiscript
}
else if (Symbol(".", true)) {
has_more = true;
if (!(Id(true))) {
if (!(Id())) {
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"))) {
retval = true;
if (!Id(true)) {
if (!Id()) {
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")) {
retval = true;
if (!(Reference() || Id(true))) {
if (!(Reference() || Id())) {
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")) {
retval = true;
if (!Id(true)) {
if (!Id()) {
throw exception::eval_error("Incomplete attribute declaration", File_Position(m_line, m_col), *m_filename);
}
if (!Symbol("::", false)) {
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);
}
@ -2036,7 +2032,7 @@ namespace chaiscript
const auto prev_stack_top = m_match_stack.size();
if (Symbol("&", false)) {
if (!Id(true)) {
if (!Id()) {
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
bool Value() {
if (Var_Decl() || Dot_Fun_Array() || Prefix()) {
return true;
} else {
return false;
}
return Var_Decl() || Dot_Fun_Array() || Prefix();
}
bool Operator_Helper(const size_t t_precedence) {

View File

@ -309,7 +309,7 @@ class Range
/// \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();
};
@ -340,7 +340,7 @@ class Const_Range
/// \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();
};

View File

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

View File

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