From 99da72da61653582d8e98075a7b3a03c36fc1976 Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Sun, 18 Jan 2015 20:19:14 +0800 Subject: Remove evil FOREACH macros --- src/common.hpp | 3 --- src/convert/render.cpp | 12 ++++++------ src/macros.cpp | 7 +++---- 3 files changed, 9 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/common.hpp b/src/common.hpp index 3247ee7a..a6f0717c 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -3,9 +3,6 @@ #ifndef COMMON_HPP_INCLUDED #define COMMON_HPP_INCLUDED -#define FOREACH(basetype, it, src) for(basetype::const_iterator it = src.begin(); it != src.end(); ++ it) -#define FOREACH_M(basetype, it, src) for(basetype::iterator it = src.begin(); it != src.end(); ++ it) - #include #include #include diff --git a/src/convert/render.cpp b/src/convert/render.cpp index bcc0ef68..338fdd06 100644 --- a/src/convert/render.cpp +++ b/src/convert/render.cpp @@ -21,10 +21,10 @@ void Render_Type(::std::ostream& os, const TypeRef& type, const char *name) void Render_CStruct(::std::ostream& os, const AST::CStruct& str) { os << "struct " << str.name() << "{\n"; - FOREACH(item_vec_t, f, str.fields()) + for(auto& f : str.fields()) { os << "\t"; - Render_Type(os, f->second, f->first.c_str()); + Render_Type(os, f.second, f.first.c_str()); os << ";\n"; } os << "}\n"; @@ -33,8 +33,8 @@ void Render_CStruct(::std::ostream& os, const AST::CStruct& str) void Render_Crate(::std::ostream& os, const AST::Flat& crate) { // First off, print forward declarations of all structs + enums - FOREACH(::std::vector, s, crate.structs()) - os << "struct " << s->mangled_name() << ";\n"; + for(const auto& s : crate.structs()) + os << "struct " << s.mangled_name() << ";\n"; for(const auto& item : crate.functions()) { @@ -43,12 +43,12 @@ void Render_Crate(::std::ostream& os, const AST::Flat& crate) Render_Type(os, fcn.rettype(), nullptr); os << " " << name << "("; bool is_first = true; - FOREACH(item_vec_t, f, fcn.args()) + for(const auto& f : fcn.args()) { if( !is_first ) os << ", "; is_first = false; - Render_Type(os, f->second, f->first.c_str()); + Render_Type(os, f.second, f.first.c_str()); } os << ")\n{\n"; // Dump expression AST diff --git a/src/macros.cpp b/src/macros.cpp index 4356a399..fa9ca9ef 100644 --- a/src/macros.cpp +++ b/src/macros.cpp @@ -62,7 +62,7 @@ MacroExpander Macro_Invoke(const char* name, TokenTree input) // 2. Check input token tree against possible variants // 3. Bind names // 4. Return expander - FOREACH(MacroRules, rule_it, rules) + for(const auto& rule : rules) { Token tok; // Create token stream for input tree @@ -73,10 +73,9 @@ MacroExpander Macro_Invoke(const char* name, TokenTree input) ::std::map bound_tts; // Parse according to rules bool fail = false; - FOREACH(::std::vector, pat_it, rule_it->m_pattern) + for(const auto& pat : rule.m_pattern) { TokenTree val; - const MacroPatEnt& pat = *pat_it; try { switch(pat.type) @@ -107,7 +106,7 @@ MacroExpander Macro_Invoke(const char* name, TokenTree input) } if( !fail && lex.getToken().type() == TOK_EOF ) { - return MacroExpander(rule_it->m_contents, bound_tts); + return MacroExpander(rule.m_contents, bound_tts); } } throw ParseError::Todo("Error when macro fails to match"); -- cgit v1.2.3