Skip to content

Commit 6eab8dd

Browse files
committedMay 10, 2014
Apply changes applied from clang-modernize
Needed 1-2 cleanups by hand. 99% was automatic. * The version that ships with ubuntu 14.04 seems to not work. I had to build from scratch * Use cmake to generate the build commands that clang-modernize wants ```sh cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:bool=true ../ChaiScript/ ``` * Use the clang-modernize tool. Note that you have to be pretty explicit about the include paths if you want it to also update your include files ```sh ../llvm-build/bin/clang-modernize ../ChaiScript/src/*.cpp -for-compilers=gcc-4.8 -include /home/jason/ChaiScript/include,/hjason/ChaiScript/include/chaiscript,/home/jason/ChaiScript/include/chaiscript/dispatchkit,/home/jason/ChaiScript/include/chaiscript/language -p compile_commands.json ``` * In my case, it left some unused `typedef`s behind, which I cleaned up.
1 parent 5f27968 commit 6eab8dd

19 files changed

+207
-217
lines changed
 

‎include/chaiscript/dispatchkit/any.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef CHAISCRIPT_ANY_HPP_
88
#define CHAISCRIPT_ANY_HPP_
99

10+
#include <utility>
11+
1012
namespace chaiscript {
1113
namespace detail {
1214
namespace exception
@@ -27,7 +29,7 @@ namespace chaiscript {
2729
virtual ~bad_any_cast() CHAISCRIPT_NOEXCEPT {}
2830

2931
/// \brief Description of what error occured
30-
virtual const char * what() const CHAISCRIPT_NOEXCEPT
32+
virtual const char * what() const CHAISCRIPT_NOEXCEPT override
3133
{
3234
return m_what.c_str();
3335
}
@@ -51,25 +53,25 @@ namespace chaiscript {
5153
template<typename T>
5254
struct Data_Impl : Data
5355
{
54-
Data_Impl(const T &t_type)
56+
Data_Impl(T t_type)
5557
: m_type(typeid(T)),
56-
m_data(t_type)
58+
m_data(std::move(t_type))
5759
{
5860
}
5961

6062
virtual ~Data_Impl() {}
6163

62-
virtual void *data()
64+
virtual void *data() override
6365
{
6466
return &m_data;
6567
}
6668

67-
const std::type_info &type() const
69+
const std::type_info &type() const override
6870
{
6971
return m_type;
7072
}
7173

72-
std::shared_ptr<Data> clone() const
74+
std::shared_ptr<Data> clone() const override
7375
{
7476
return std::shared_ptr<Data>(new Data_Impl<T>(m_data));
7577
}

‎include/chaiscript/dispatchkit/bad_boxed_cast.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ namespace chaiscript
2222
{
2323
public:
2424
bad_boxed_cast(const Type_Info &t_from, const std::type_info &t_to,
25-
const std::string &t_what) CHAISCRIPT_NOEXCEPT
26-
: from(t_from), to(&t_to), m_what(t_what)
25+
std::string t_what) CHAISCRIPT_NOEXCEPT
26+
: from(t_from), to(&t_to), m_what(std::move(t_what))
2727
{
2828
}
2929

@@ -32,15 +32,15 @@ namespace chaiscript
3232
{
3333
}
3434

35-
bad_boxed_cast(const std::string &t_what) CHAISCRIPT_NOEXCEPT
36-
: to(0), m_what(t_what)
35+
bad_boxed_cast(std::string t_what) CHAISCRIPT_NOEXCEPT
36+
: to(nullptr), m_what(std::move(t_what))
3737
{
3838
}
3939

4040
virtual ~bad_boxed_cast() CHAISCRIPT_NOEXCEPT {}
4141

4242
/// \brief Description of what error occured
43-
virtual const char * what() const CHAISCRIPT_NOEXCEPT
43+
virtual const char * what() const CHAISCRIPT_NOEXCEPT override
4444
{
4545
return m_what.c_str();
4646
}

‎include/chaiscript/dispatchkit/bootstrap_stl.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ namespace chaiscript
189189
template<typename Type>
190190
void insert_at(Type &container, int pos, const typename Type::value_type &v)
191191
{
192-
typename Type::iterator itr = container.begin();
193-
typename Type::iterator end = container.end();
192+
auto itr = container.begin();
193+
auto end = container.end();
194194

195195
if (pos < 0 || std::distance(itr, end) < pos)
196196
{
@@ -206,8 +206,8 @@ namespace chaiscript
206206
template<typename Type>
207207
void erase_at(Type &container, int pos)
208208
{
209-
typename Type::iterator itr = container.begin();
210-
typename Type::iterator end = container.end();
209+
auto itr = container.begin();
210+
auto end = container.end();
211211

212212
if (pos < 0 || std::distance(itr, end) < (pos-1))
213213
{

‎include/chaiscript/dispatchkit/boxed_value.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace chaiscript
3636
const chaiscript::detail::Any &to,
3737
bool tr,
3838
const void *t_void_ptr)
39-
: m_type_info(ti), m_obj(to), m_data_ptr(ti.is_const()?0:const_cast<void *>(t_void_ptr)), m_const_data_ptr(t_void_ptr),
39+
: m_type_info(ti), m_obj(to), m_data_ptr(ti.is_const()?nullptr:const_cast<void *>(t_void_ptr)), m_const_data_ptr(t_void_ptr),
4040
m_is_ref(tr)
4141
{
4242
}
@@ -201,7 +201,7 @@ namespace chaiscript
201201

202202
bool is_null() const
203203
{
204-
return (m_data->m_data_ptr == 0 && m_data->m_const_data_ptr == 0);
204+
return (m_data->m_data_ptr == nullptr && m_data->m_const_data_ptr == nullptr);
205205
}
206206

207207
const chaiscript::detail::Any & get() const

‎include/chaiscript/dispatchkit/dispatchkit.hpp

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ namespace chaiscript
252252
{
253253
}
254254

255-
virtual bool operator==(const dispatch::Proxy_Function_Base &rhs) const
255+
virtual bool operator==(const dispatch::Proxy_Function_Base &rhs) const override
256256
{
257257
try {
258258
const Dispatch_Function &dispatchfun = dynamic_cast<const Dispatch_Function &>(rhs);
@@ -264,17 +264,17 @@ namespace chaiscript
264264

265265
virtual ~Dispatch_Function() {}
266266

267-
virtual std::vector<Const_Proxy_Function> get_contained_functions() const
267+
virtual std::vector<Const_Proxy_Function> get_contained_functions() const override
268268
{
269269
return std::vector<Const_Proxy_Function>(m_funcs.begin(), m_funcs.end());
270270
}
271271

272272

273-
virtual int get_arity() const
273+
virtual int get_arity() const override
274274
{
275275
typedef std::vector<Proxy_Function> function_vec;
276276

277-
function_vec::const_iterator begin = m_funcs.begin();
277+
auto begin = m_funcs.begin();
278278
const function_vec::const_iterator end = m_funcs.end();
279279

280280
if (begin != end)
@@ -300,12 +300,10 @@ namespace chaiscript
300300
return -1; // unknown arity
301301
}
302302

303-
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Dynamic_Cast_Conversions &t_conversions) const
303+
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Dynamic_Cast_Conversions &t_conversions) const override
304304
{
305-
typedef std::vector<Proxy_Function> function_vec;
306-
307-
function_vec::const_iterator begin = m_funcs.begin();
308-
function_vec::const_iterator end = m_funcs.end();
305+
auto begin = m_funcs.begin();
306+
auto end = m_funcs.end();
309307

310308
while (begin != end)
311309
{
@@ -320,13 +318,13 @@ namespace chaiscript
320318
return false;
321319
}
322320

323-
virtual std::string annotation() const
321+
virtual std::string annotation() const override
324322
{
325323
return "Multiple method dispatch function wrapper.";
326324
}
327325

328326
protected:
329-
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Dynamic_Cast_Conversions &t_conversions) const
327+
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Dynamic_Cast_Conversions &t_conversions) const override
330328
{
331329
return dispatch::dispatch(m_funcs.begin(), m_funcs.end(), params, t_conversions);
332330
}
@@ -338,7 +336,7 @@ namespace chaiscript
338336
{
339337
typedef std::vector<Proxy_Function> function_vec;
340338

341-
function_vec::const_iterator begin = t_funcs.begin();
339+
auto begin = t_funcs.begin();
342340
const function_vec::const_iterator end = t_funcs.end();
343341

344342
if (begin != end)
@@ -477,7 +475,7 @@ namespace chaiscript
477475
validate_object_name(name);
478476

479477
Scope &scope = stack.back();
480-
Scope::iterator itr = scope.find(name);
478+
auto itr = scope.find(name);
481479
if (itr != stack.back().end())
482480
{
483481
throw chaiscript::exception::name_conflict_error(name);
@@ -598,7 +596,7 @@ namespace chaiscript
598596
{
599597
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_global_object_mutex);
600598

601-
std::map<std::string, Boxed_Value>::const_iterator itr = m_state.m_global_objects.find(name);
599+
auto itr = m_state.m_global_objects.find(name);
602600
if (itr != m_state.m_global_objects.end())
603601
{
604602
return itr->second;
@@ -628,7 +626,7 @@ namespace chaiscript
628626
{
629627
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
630628

631-
Type_Name_Map::const_iterator itr = m_state.m_types.find(name);
629+
auto itr = m_state.m_types.find(name);
632630

633631
if (itr != m_state.m_types.end())
634632
{
@@ -647,13 +645,11 @@ namespace chaiscript
647645
{
648646
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
649647

650-
for (Type_Name_Map::const_iterator itr = m_state.m_types.begin();
651-
itr != m_state.m_types.end();
652-
++itr)
648+
for (const auto & elem : m_state.m_types)
653649
{
654-
if (itr->second.bare_equal(ti))
650+
if (elem.second.bare_equal(ti))
655651
{
656-
return itr->first;
652+
return elem.first;
657653
}
658654
}
659655

@@ -680,7 +676,7 @@ namespace chaiscript
680676

681677
const std::map<std::string, std::vector<Proxy_Function> > &funs = get_functions_int();
682678

683-
std::map<std::string, std::vector<Proxy_Function> >::const_iterator itr
679+
auto itr
684680
= funs.find(t_name);
685681

686682
if (itr != funs.end())
@@ -699,7 +695,7 @@ namespace chaiscript
699695

700696
const std::map<std::string, Proxy_Function> &funs = get_function_objects_int();
701697

702-
std::map<std::string, Proxy_Function>::const_iterator itr = funs.find(t_name);
698+
auto itr = funs.find(t_name);
703699

704700
if (itr != funs.end())
705701
{
@@ -756,7 +752,7 @@ namespace chaiscript
756752

757753
// note: map insert doesn't overwrite existing values, which is why this works
758754

759-
for (StackData::reverse_iterator itr = stack.rbegin(); itr != stack.rend(); ++itr)
755+
for (auto itr = stack.rbegin(); itr != stack.rend(); ++itr)
760756
{
761757
retval.insert(itr->begin(), itr->end());
762758
}
@@ -783,11 +779,9 @@ namespace chaiscript
783779

784780
std::map<std::string, Boxed_Value> objs;
785781

786-
for (std::map<std::string, Proxy_Function>::const_iterator itr = funs.begin();
787-
itr != funs.end();
788-
++itr)
782+
for (const auto & fun : funs)
789783
{
790-
objs.insert(std::make_pair(itr->first, const_var(itr->second)));
784+
objs.insert(std::make_pair(fun.first, const_var(fun.second)));
791785
}
792786

793787
return objs;
@@ -805,15 +799,11 @@ namespace chaiscript
805799

806800
const std::map<std::string, std::vector<Proxy_Function> > &functions = get_functions_int();
807801

808-
for (std::map<std::string, std::vector<Proxy_Function> >::const_iterator itr = functions.begin();
809-
itr != functions.end();
810-
++itr)
802+
for (const auto & function : functions)
811803
{
812-
for (std::vector<Proxy_Function>::const_iterator itr2 = itr->second.begin();
813-
itr2 != itr->second.end();
814-
++itr2)
804+
for (const auto & internal_func : function.second)
815805
{
816-
rets.push_back(std::make_pair(itr->first, *itr2));
806+
rets.push_back(std::make_pair(function.first, internal_func));
817807
}
818808
}
819809

@@ -1171,7 +1161,7 @@ namespace chaiscript
11711161

11721162
std::map<std::string, std::vector<Proxy_Function> > &funcs = get_functions_int();
11731163

1174-
std::map<std::string, std::vector<Proxy_Function> >::iterator itr
1164+
auto itr
11751165
= funcs.find(t_name);
11761166

11771167
std::map<std::string, Proxy_Function> &func_objs = get_function_objects_int();

‎include/chaiscript/dispatchkit/dynamic_cast_conversion.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ namespace chaiscript
109109
// Pull the reference out of the contained boxed value, which we know is the type we want
110110
if (t_from.is_const())
111111
{
112-
const From &d = detail::Cast_Helper<const From &>::cast(t_from, 0);
112+
const From &d = detail::Cast_Helper<const From &>::cast(t_from, nullptr);
113113
const To &data = dynamic_cast<const To &>(d);
114114
return Boxed_Value(std::cref(data));
115115
} else {
116-
From &d = detail::Cast_Helper<From &>::cast(t_from, 0);
116+
From &d = detail::Cast_Helper<From &>::cast(t_from, nullptr);
117117
To &data = dynamic_cast<To &>(d);
118118
return Boxed_Value(std::ref(data));
119119
}
@@ -133,12 +133,12 @@ namespace chaiscript
133133
{
134134
}
135135

136-
virtual Boxed_Value convert_down(const Boxed_Value &t_base) const
136+
virtual Boxed_Value convert_down(const Boxed_Value &t_base) const override
137137
{
138138
return Dynamic_Caster<Base, Derived>::cast(t_base);
139139
}
140140

141-
virtual Boxed_Value convert(const Boxed_Value &t_derived) const
141+
virtual Boxed_Value convert(const Boxed_Value &t_derived) const override
142142
{
143143
return Dynamic_Caster<Derived, Base>::cast(t_derived);
144144
}
@@ -209,7 +209,7 @@ namespace chaiscript
209209
{
210210
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
211211

212-
std::set<std::shared_ptr<detail::Dynamic_Conversion> >::const_iterator itr =
212+
auto itr =
213213
find(base, derived);
214214

215215
if (itr != m_conversions.end())
@@ -224,7 +224,7 @@ namespace chaiscript
224224
std::set<std::shared_ptr<detail::Dynamic_Conversion> >::const_iterator find(
225225
const Type_Info &base, const Type_Info &derived) const
226226
{
227-
for (std::set<std::shared_ptr<detail::Dynamic_Conversion> >::const_iterator itr = m_conversions.begin();
227+
for (auto itr = m_conversions.begin();
228228
itr != m_conversions.end();
229229
++itr)
230230
{

1 commit comments

Comments
 (1)

lefticus commented on May 10, 2014

@lefticus
MemberAuthor

@jonathandturner @axelstudios

The results from clang-modernize. Note that I had to build it from scratch to get it to work, which wasn't terribly painful. The cmake llvm build system seems to be working fine. You just have to clone llvm, then llvm/tools, then llvm/tools/clang/tools.

Please sign in to comment.