Commit f651e5cf authored by Kenton Varda's avatar Kenton Varda

Reverse order of KJ_MAP to be consistent with e.g. KJ_IF_MAYBE.

parent e65d5d0f
This diff is collapsed.
......@@ -296,7 +296,7 @@ private:
}
kj::StringTree genAnnotations(List<schema::Annotation>::Reader list, Schema scope) {
return kj::strTree(KJ_MAP(list, ann) { return genAnnotation(ann, scope); });
return kj::strTree(KJ_MAP(ann, list) { return genAnnotation(ann, scope); });
}
kj::StringTree genAnnotations(Schema schema) {
auto proto = schema.getProto();
......@@ -326,7 +326,7 @@ private:
template <typename MemberList>
kj::Array<decltype(kj::instance<MemberList>()[0])> sortByCodeOrder(MemberList&& list) {
auto sorted = KJ_MAP(list, item) { return item; };
auto sorted = KJ_MAP(item, list) { return item; };
std::sort(sorted.begin(), sorted.end(), OrderByCodeOrder());
return kj::mv(sorted);
}
......@@ -338,7 +338,7 @@ private:
// subsequent fields.
bool seenUnion = false;
return KJ_MAP(sortByCodeOrder(schema.getFields()), field) {
return KJ_MAP(field, sortByCodeOrder(schema.getFields())) {
if (field.getProto().hasDiscriminantValue()) {
if (seenUnion) {
return kj::strTree();
......@@ -350,7 +350,7 @@ private:
auto unionFields = sortByCodeOrder(schema.getUnionFields());
return kj::strTree(
indent, "union { # tag bits [", offset * 16, ", ", offset * 16 + 16, ")\n",
KJ_MAP(unionFields, uField) {
KJ_MAP(uField, unionFields) {
return genStructField(uField.getProto(), schema, indent.next());
},
indent, "}\n");
......@@ -424,7 +424,7 @@ private:
case schema::Node::ENUM: {
return kj::strTree(
indent, "enum ", name, " @0x", kj::hex(proto.getId()), genAnnotations(schema), " {\n",
KJ_MAP(sortByCodeOrder(schema.asEnum().getEnumerants()), enumerant) {
KJ_MAP(enumerant, sortByCodeOrder(schema.asEnum().getEnumerants())) {
return kj::strTree(indent.next(), enumerant.getProto().getName(), " @",
enumerant.getIndex(),
genAnnotations(enumerant.getProto().getAnnotations(), schema),
......@@ -437,12 +437,12 @@ private:
return kj::strTree(
indent, "interface ", name, " @0x", kj::hex(proto.getId()),
genAnnotations(schema), " {\n",
KJ_MAP(sortByCodeOrder(schema.asInterface().getMethods()), method) {
KJ_MAP(method, sortByCodeOrder(schema.asInterface().getMethods())) {
int i = 0;
auto methodProto = method.getProto();
return kj::strTree(
indent.next(), methodProto.getName(), " @", method.getIndex(), "(",
KJ_MAP(methodProto.getParams(), param) {
KJ_MAP(param, methodProto.getParams()) {
bool hasDefault = i >= methodProto.getRequiredParamCount() ||
!isEmptyValue(param.getDefaultValue());
return kj::strTree(
......@@ -504,7 +504,7 @@ private:
kj::StringTree genNestedDecls(Schema schema, Indent indent) {
uint64_t id = schema.getProto().getId();
return kj::strTree(KJ_MAP(schema.getProto().getNestedNodes(), nested) {
return kj::strTree(KJ_MAP(nested, schema.getProto().getNestedNodes()) {
return genDecl(schemaLoader.get(nested.getId()), nested.getName(), id, indent);
});
}
......@@ -516,7 +516,7 @@ private:
return kj::strTree(
"# ", proto.getDisplayName(), "\n",
"@0x", kj::hex(proto.getId()), ";\n",
KJ_MAP(proto.getAnnotations(), ann) { return genAnnotation(ann, file, "", ";\n"); },
KJ_MAP(ann, proto.getAnnotations()) { return genAnnotation(ann, file, "", ";\n"); },
genNestedDecls(file, Indent(0)));
}
......
......@@ -523,7 +523,7 @@ const Compiler::Node::Content& Compiler::Node::getContent(Content::State minimum
// Create the final schema.
KJ_IF_MAYBE(exception, kj::runCatchingExceptions([&](){
auto nodeSet = locked->translator->finish();
locked->auxSchemas = KJ_MAP(nodeSet.auxNodes, auxNode) {
locked->auxSchemas = KJ_MAP(auxNode, nodeSet.auxNodes) {
return module->getCompiler().getFinalLoader().loadOnce(auxNode);
};
locked->finalSchema = module->getCompiler().getFinalLoader().loadOnce(nodeSet.node);
......
......@@ -536,7 +536,7 @@ NodeTranslator::NodeTranslator(
NodeTranslator::NodeSet NodeTranslator::getBootstrapNode() {
return NodeSet {
wipNode.getReader(),
KJ_MAP(groups, g) { return g.getReader(); }
KJ_MAP(g, groups) { return g.getReader(); }
};
}
......
......@@ -173,7 +173,7 @@ static kj::StringTree print(const DynamicValue::Reader& value,
case DynamicValue::LIST: {
auto listValue = value.as<DynamicList>();
auto which = listValue.getSchema().whichElementType();
kj::Array<kj::StringTree> elements = KJ_MAP(listValue, element) {
kj::Array<kj::StringTree> elements = KJ_MAP(element, listValue) {
return print(element, which, indent.next(), BARE);
};
return kj::strTree('[', indent.delimit(kj::mv(elements), mode), ']');
......
......@@ -331,7 +331,7 @@ TEST(Array, OwnConst) {
TEST(Array, Map) {
StringPtr foo = "abcd";
Array<char> bar = KJ_MAP(foo, c) -> char { return c + 1; };
Array<char> bar = KJ_MAP(c, foo) -> char { return c + 1; };
EXPECT_STREQ("bcde", str(bar).cStr());
}
......
......@@ -466,15 +466,15 @@ private:
};
// =======================================================================================
// KJ_MAP_ARRAY
// KJ_MAP
#define KJ_MAP(array, elementName) \
#define KJ_MAP(elementName, array) \
::kj::_::Mapper<KJ_DECLTYPE_REF(array)>(array) * [&](decltype(*(array).begin()) elementName)
// Applies some function to every element of an array, returning an Array of the results, with
// nice syntax. Example:
//
// StringPtr foo = "abcd";
// Array<char> bar = KJ_MAP(foo, c) -> char { return c + 1; };
// Array<char> bar = KJ_MAP(c, foo) -> char { return c + 1; };
// KJ_ASSERT(str(bar) == "bcde");
namespace _ { // private
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment