+ context.scope_ = scope.parent_;
+ scope.Scope(context, statements_);
+
+ size_t offset(0);
+
+ CYCStringSet external;
+ for (CYIdentifierValueSet::const_iterator i(scope.identifiers_.begin()); i != scope.identifiers_.end(); ++i)
+ external.insert((*i)->Word());
+
+ IdentifierUsages usages;
+
+ if (offset < context.rename_.size())
+ for (CYIdentifier *i(context.rename_[offset].identifier_); i != NULL; i = i->next_)
+ 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) {
+ //std::cout << *i << ":" << (*i)->offset_ << std::endl;
+
+ const char *name;
+
+ if (context.options_.verbose_)
+ name = apr_psprintf(context.pool_, "$%"APR_SIZE_T_FMT"", offset);
+ else {
+ char id[8];
+ id[7] = '\0';
+
+ id:
+ unsigned position(7), local(offset + 1);
+
+ do {
+ unsigned index(local % (sizeof(MappingSet) - 1));
+ local /= sizeof(MappingSet) - 1;
+ id[--position] = MappingSet[index];
+ } while (local != 0);
+
+ if (external.find(id + position) != external.end()) {
+ ++offset;
+ goto id;
+ }
+
+ name = apr_pstrmemdup(context.pool_, id + position, 7 - position);
+ // XXX: at some point, this could become a keyword
+ }
+
+ for (CYIdentifier *identifier(i->identifier_); identifier != NULL; identifier = identifier->next_)
+ identifier->Set(name);
+ }