diff options
author | John Hodge (sonata) <tpg@mutabah.net> | 2015-01-18 20:19:14 +0800 |
---|---|---|
committer | John Hodge (sonata) <tpg@mutabah.net> | 2015-01-18 20:19:14 +0800 |
commit | 99da72da61653582d8e98075a7b3a03c36fc1976 (patch) | |
tree | c88032e1ef0eeed1a0b17727b6eab1d7cd8bf4cb | |
parent | 26a027caaf751cde502b6044ad91b208bbfdc8ca (diff) | |
download | mrust-99da72da61653582d8e98075a7b3a03c36fc1976.tar.gz |
Remove evil FOREACH macros
-rw-r--r-- | src/common.hpp | 3 | ||||
-rw-r--r-- | src/convert/render.cpp | 12 | ||||
-rw-r--r-- | src/macros.cpp | 7 |
3 files changed, 9 insertions, 13 deletions
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 <iostream> #include <vector> #include <cassert> 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<AST::CStruct>, 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<const char*,TokenTree,cmp_str> bound_tts;
// Parse according to rules
bool fail = false;
- FOREACH(::std::vector<MacroPatEnt>, 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");
|