std::string common;
bool rest(false);
- for (CYElement *element(array->elements_); element != NULL; element = element->next_) {
+ CYForEach (element, array->elements_) {
CYString *string(dynamic_cast<CYString *>(element->value_));
_assert(string != NULL);
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)
}
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)
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_)
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;
}
};
+#define CYForEach(value, list) \
+ for (__typeof__(*list) *value(list); value != NULL; value = value->next_)
+
struct CYThing {
virtual ~CYThing() {
}
template <typename Type_>
void ReplaceAll(Type_ *&values) {
Type_ **last(&values);
- for (Type_ *next(values); next != NULL; next = next->next_) {
+ CYForEach (next, values) {
Replace(*last);
last = &(*last)->next_;
}
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) {
// 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);
}
}