Skip to content

Commit 8889324

Browse files
committed
Code simplifications and spelling fixes found by clion
1 parent b2b604e commit 8889324

12 files changed

Lines changed: 83 additions & 116 deletions

include/chaiscript/dispatchkit/bootstrap.hpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,7 @@ namespace chaiscript
309309
static bool has_guard(const Const_Proxy_Function &t_pf)
310310
{
311311
auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
312-
if (pf)
313-
{
314-
if (pf->get_guard()) {
315-
return true;
316-
} else {
317-
return false;
318-
}
319-
} else {
320-
return false;
321-
}
312+
return pf && pf->get_guard();
322313
}
323314

324315
static Const_Proxy_Function get_guard(const Const_Proxy_Function &t_pf)
@@ -372,12 +363,7 @@ namespace chaiscript
372363
static bool has_parse_tree(const chaiscript::Const_Proxy_Function &t_pf)
373364
{
374365
const auto pf = std::dynamic_pointer_cast<const chaiscript::dispatch::Dynamic_Proxy_Function>(t_pf);
375-
if (pf && pf->get_parse_tree())
376-
{
377-
return true;
378-
} else {
379-
return false;
380-
}
366+
return pf && pf->get_parse_tree();
381367
}
382368

383369
static chaiscript::AST_NodePtr get_parse_tree(const chaiscript::Const_Proxy_Function &t_pf)

include/chaiscript/dispatchkit/bootstrap_stl.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,15 @@ namespace chaiscript
349349
template<typename ContainerType>
350350
ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = ModulePtr(new Module()))
351351
{
352-
typedef typename ContainerType::reference (ContainerType::*frontptr)();
353-
typedef typename ContainerType::const_reference (ContainerType::*constfrontptr)() const;
354-
typedef void (ContainerType::*pushptr)(typename ContainerType::const_reference);
355-
typedef void (ContainerType::*popptr)();
352+
typedef typename ContainerType::reference (ContainerType::*front_ptr)();
353+
typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const;
354+
typedef void (ContainerType::*push_ptr)(typename ContainerType::const_reference);
355+
typedef void (ContainerType::*pop_ptr)();
356356

357-
m->add(fun(static_cast<frontptr>(&ContainerType::front)), "front");
358-
m->add(fun(static_cast<constfrontptr>(&ContainerType::front)), "front");
357+
m->add(fun(static_cast<front_ptr>(&ContainerType::front)), "front");
358+
m->add(fun(static_cast<const_front_ptr>(&ContainerType::front)), "front");
359359

360-
m->add(fun(static_cast<pushptr>(&ContainerType::push_front)),
360+
m->add(fun(static_cast<push_ptr>(&ContainerType::push_front)),
361361
[]()->std::string{
362362
if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
363363
return "push_front_ref";
@@ -366,7 +366,7 @@ namespace chaiscript
366366
}
367367
}());
368368

369-
m->add(fun(static_cast<popptr>(&ContainerType::pop_front)), "pop_front");
369+
m->add(fun(static_cast<pop_ptr>(&ContainerType::pop_front)), "pop_front");
370370
return m;
371371
}
372372

@@ -439,9 +439,9 @@ namespace chaiscript
439439
{
440440
m->add(user_type<MapType>(), type);
441441

442-
typedef typename MapType::mapped_type &(MapType::*elemaccess)(const typename MapType::key_type &);
442+
typedef typename MapType::mapped_type &(MapType::*elem_access)(const typename MapType::key_type &);
443443

444-
m->add(fun(static_cast<elemaccess>(&MapType::operator[])), "[]");
444+
m->add(fun(static_cast<elem_access>(&MapType::operator[])), "[]");
445445

446446
container_type<MapType>(type, m);
447447
default_constructible_type<MapType>(type, m);

include/chaiscript/dispatchkit/dispatchkit.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ namespace chaiscript
280280
virtual bool operator==(const dispatch::Proxy_Function_Base &rhs) const CHAISCRIPT_OVERRIDE
281281
{
282282
try {
283-
const auto &dispatchfun = dynamic_cast<const Dispatch_Function &>(rhs);
284-
return m_funcs == dispatchfun.m_funcs;
283+
const auto &dispatch_fun = dynamic_cast<const Dispatch_Function &>(rhs);
284+
return m_funcs == dispatch_fun.m_funcs;
285285
} catch (const std::bad_cast &) {
286286
return false;
287287
}
@@ -1138,12 +1138,7 @@ namespace chaiscript
11381138
{
11391139
if (dynamic_lhs->get_guard())
11401140
{
1141-
if (dynamic_rhs->get_guard())
1142-
{
1143-
return false;
1144-
} else {
1145-
return true;
1146-
}
1141+
return dynamic_rhs->get_guard() ? false : true;
11471142
} else {
11481143
return false;
11491144
}

include/chaiscript/dispatchkit/dynamic_object_detail.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,7 @@ namespace chaiscript
213213
virtual bool operator==(const Proxy_Function_Base &f) const CHAISCRIPT_OVERRIDE
214214
{
215215
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
216-
if (dc)
217-
{
218-
return dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
219-
} else {
220-
return false;
221-
}
216+
return dc && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
222217
}
223218

224219
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE

include/chaiscript/dispatchkit/type_info.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ namespace chaiscript
3131
{
3232
public:
3333
CHAISCRIPT_CONSTEXPR Type_Info(bool t_is_const, bool t_is_reference, bool t_is_pointer, bool t_is_void,
34-
bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bareti)
35-
: m_type_info(t_ti), m_bare_type_info(t_bareti),
34+
bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bare_ti)
35+
: m_type_info(t_ti), m_bare_type_info(t_bare_ti),
3636
m_is_const(t_is_const), m_is_reference(t_is_reference), m_is_pointer(t_is_pointer),
3737
m_is_void(t_is_void), m_is_arithmetic(t_is_arithmetic),
3838
m_is_undef(false)

include/chaiscript/language/chaiscript_common.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ namespace chaiscript
229229

230230
if (f)
231231
{
232-
std::shared_ptr<const dispatch::Dynamic_Proxy_Function> dynfunguard
233-
= std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(f);
232+
auto dynfunguard = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(f);
234233
if (dynfunguard)
235234
{
236235
retval += " : " + format_guard(dynfunguard->get_parse_tree());
@@ -486,8 +485,8 @@ namespace chaiscript
486485

487486
private:
488487
// Copy and assignment explicitly unimplemented
489-
AST_Node(const AST_Node &);
490-
AST_Node& operator=(const AST_Node &);
488+
AST_Node(const AST_Node &) = delete;
489+
AST_Node& operator=(const AST_Node &) = delete;
491490
};
492491

493492

include/chaiscript/language/chaiscript_engine.hpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ namespace chaiscript
166166

167167
static std::string get_error_message(DWORD t_err)
168168
{
169+
typedef LPTSTR StringType;
170+
169171
#if defined(_UNICODE) || defined(UNICODE)
170-
typedef LPWSTR StringType;
171172
std::wstring retval = L"Unknown Error";
172173
#else
173-
typedef LPSTR StringType;
174174
std::string retval = "Unknown Error";
175175
#endif
176176
StringType lpMsgBuf = nullptr;
@@ -182,7 +182,7 @@ namespace chaiscript
182182
NULL,
183183
t_err,
184184
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
185-
(StringType)&lpMsgBuf,
185+
reinterpret_cast<StringType>(&lpMsgBuf),
186186
0, NULL ) != 0 && lpMsgBuf)
187187
{
188188
retval = lpMsgBuf;
@@ -264,8 +264,8 @@ namespace chaiscript
264264
std::map<std::string, detail::Loadable_Module_Ptr> m_loaded_modules;
265265
std::set<std::string> m_active_loaded_modules;
266266

267-
std::vector<std::string> m_modulepaths;
268-
std::vector<std::string> m_usepaths;
267+
std::vector<std::string> m_module_paths;
268+
std::vector<std::string> m_use_paths;
269269

270270
chaiscript::detail::Dispatch_Engine m_engine;
271271

@@ -299,7 +299,7 @@ namespace chaiscript
299299

300300
/// Evaluates the given file and looks in the 'use' paths
301301
const Boxed_Value internal_eval_file(const std::string &t_filename) {
302-
for (const auto &path : m_usepaths)
302+
for (const auto &path : m_use_paths)
303303
{
304304
try {
305305
const auto appendedpath = path + t_filename;
@@ -441,16 +441,16 @@ namespace chaiscript
441441
ChaiScript(const ModulePtr &t_lib,
442442
std::vector<std::string> t_modulepaths = std::vector<std::string>(),
443443
std::vector<std::string> t_usepaths = std::vector<std::string>())
444-
: m_modulepaths(std::move(t_modulepaths)), m_usepaths(std::move(t_usepaths))
444+
: m_module_paths(std::move(t_modulepaths)), m_use_paths(std::move(t_usepaths))
445445
{
446-
if (m_modulepaths.empty())
446+
if (m_module_paths.empty())
447447
{
448-
m_modulepaths.push_back("");
448+
m_module_paths.push_back("");
449449
}
450450

451-
if (m_usepaths.empty())
451+
if (m_use_paths.empty())
452452
{
453-
m_usepaths.push_back("");
453+
m_use_paths.push_back("");
454454
}
455455

456456
build_eval_system(t_lib);
@@ -465,16 +465,16 @@ namespace chaiscript
465465
/// \param[in] t_usepaths Vector of paths to search when attempting to "use" an included ChaiScript file
466466
ChaiScript( std::vector<std::string> t_modulepaths = std::vector<std::string>(),
467467
std::vector<std::string> t_usepaths = std::vector<std::string>())
468-
: m_modulepaths(std::move(t_modulepaths)), m_usepaths(std::move(t_usepaths))
468+
: m_module_paths(std::move(t_modulepaths)), m_use_paths(std::move(t_usepaths))
469469
{
470-
if (m_modulepaths.empty())
470+
if (m_module_paths.empty())
471471
{
472-
m_modulepaths.push_back("");
472+
m_module_paths.push_back("");
473473
}
474474

475-
if (m_usepaths.empty())
475+
if (m_use_paths.empty())
476476
{
477-
m_usepaths.push_back("");
477+
m_use_paths.push_back("");
478478
}
479479

480480
#if defined(_POSIX_VERSION) && !defined(__CYGWIN__)
@@ -507,7 +507,7 @@ namespace chaiscript
507507
dllpath = std::string(&buf.front(), pathlen);
508508
}
509509

510-
m_modulepaths.insert(m_modulepaths.begin(), dllpath+"/");
510+
m_module_paths.insert(m_module_paths.begin(), dllpath+"/");
511511
}
512512
#endif
513513

@@ -559,7 +559,7 @@ namespace chaiscript
559559
/// \param[in] t_filename Filename to load and evaluate
560560
Boxed_Value use(const std::string &t_filename)
561561
{
562-
for (const auto &path : m_usepaths)
562+
for (const auto &path : m_use_paths)
563563
{
564564
try {
565565
const auto appendedpath = path + t_filename;
@@ -758,7 +758,7 @@ namespace chaiscript
758758

759759
std::vector<std::string> postfixes{".dll", ".so", ".bundle", ""};
760760

761-
for (auto & elem : m_modulepaths)
761+
for (auto & elem : m_module_paths)
762762
{
763763
for (auto & prefix : prefixes)
764764
{

include/chaiscript/language/chaiscript_eval.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ namespace chaiscript
13301330
end_point = this->children.size() - 1;
13311331
}
13321332
for (size_t i = 1; i < end_point; ++i) {
1333-
chaiscript::eval::detail::Scope_Push_Pop catchscope(t_ss);
1333+
chaiscript::eval::detail::Scope_Push_Pop catch_scope(t_ss);
13341334
AST_NodePtr catch_block = this->children[i];
13351335

13361336
if (catch_block->children.size() == 1) {

0 commit comments

Comments
 (0)