From c2c9f509581b8c8e78b5745498c782ef1affd51a Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 12 Jul 2010 03:24:54 +0000 Subject: [PATCH] Refactor some for loops to a CYForEach() over CYNext<>. --- Console.cpp | 2 +- ObjectiveC/Output.mm | 4 ++-- ObjectiveC/Replace.cpp | 2 +- Output.cpp | 2 +- Parser.hpp | 5 ++++- Replace.cpp | 6 +++--- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Console.cpp b/Console.cpp index 6ecc251..89cd62e 100644 --- a/Console.cpp +++ b/Console.cpp @@ -313,7 +313,7 @@ static char **Complete(const char *word, int start, int end) { std::string common; bool rest(false); - for (CYElement *element(array->elements_); element != NULL; element = element->next_) { + CYForEach (element, array->elements_) { CYString *string(dynamic_cast(element->value_)); _assert(string != NULL); diff --git a/ObjectiveC/Output.mm b/ObjectiveC/Output.mm index 91696cb..e406493 100644 --- a/ObjectiveC/Output.mm +++ b/ObjectiveC/Output.mm @@ -85,7 +85,7 @@ void CYImport::Output(CYOutput &out, CYFlags flags) const { void CYMessage::Output(CYOutput &out, bool replace) const { out << (instance_ ? '-' : '+'); - for (CYMessageParameter *parameter(parameters_); parameter != NULL; parameter = parameter->next_) + CYForEach (parameter, parameters_) if (parameter->tag_ != NULL) { out << ' ' << *parameter->tag_; if (parameter->name_ != NULL) @@ -113,7 +113,7 @@ void CYSelectorPart::Output(CYOutput &out) const { } void CYSend::Output(CYOutput &out, CYFlags flags) const { - for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_) + CYForEach (argument, arguments_) if (argument->name_ != NULL) { out << ' ' << *argument->name_; if (argument->value_ != NULL) diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 35389b9..9d2d1ab 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -119,7 +119,7 @@ CYExpression *CYSelector::Replace(CYContext &context) { CYString *CYSelectorPart::Replace(CYContext &context) { std::ostringstream str; - for (const CYSelectorPart *part(this); part != NULL; part = part->next_) { + CYForEach (part, this) { if (part->name_ != NULL) str << part->name_->Word(); if (part->value_) diff --git a/Output.cpp b/Output.cpp index 6e70b6b..ee58d06 100644 --- a/Output.cpp +++ b/Output.cpp @@ -607,7 +607,7 @@ void CYRubyProc::Output(CYOutput &out, CYFlags flags) const { void CYStatement::Multiple(CYOutput &out, CYFlags flags) const { bool first(true); - for (const CYStatement *next(this); next != NULL; next = next->next_) { + CYForEach (next, this) { bool last(next->next_ == NULL); CYFlags jacks(first ? last ? flags : CYLeft(flags) : last ? CYRight(flags) : CYCenter(flags)); first = false; diff --git a/Parser.hpp b/Parser.hpp index 5d86018..ebcbb7f 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -57,6 +57,9 @@ struct CYNext { } }; +#define CYForEach(value, list) \ + for (__typeof__(*list) *value(list); value != NULL; value = value->next_) + struct CYThing { virtual ~CYThing() { } @@ -370,7 +373,7 @@ struct CYContext { template void ReplaceAll(Type_ *&values) { Type_ **last(&values); - for (Type_ *next(values); next != NULL; next = next->next_) { + CYForEach (next, values) { Replace(*last); last = &(*last)->next_; } diff --git a/Replace.cpp b/Replace.cpp index 8023bdb..d1f8ab5 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -549,8 +549,8 @@ void CYProgram::Replace(CYContext &context) { IdentifierUsages usages; if (offset < context.rename_.size()) - for (CYIdentifier *i(context.rename_[offset].identifier_); i != NULL; i = i->next_) - usages.insert(i); + CYForEach (i, context.rename_[offset].identifier_) + usages.insert(i); // XXX: totalling the probable occurrences and sorting by them would improve the result for (CYIdentifierUsageVector::const_iterator i(context.rename_.begin()); i != context.rename_.end(); ++i, ++offset) { @@ -582,7 +582,7 @@ void CYProgram::Replace(CYContext &context) { // XXX: at some point, this could become a keyword } - for (CYIdentifier *identifier(i->identifier_); identifier != NULL; identifier = identifier->next_) + CYForEach (identifier, i->identifier_) identifier->Set(name); } } -- 2.45.2