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