Commit 84235207 authored by Kenton Varda's avatar Kenton Varda

Handle TODO(soon)s.

parent a499aceb
......@@ -937,7 +937,7 @@ template <typename T>
inline T ListBuilder::getDataElement(ElementCount index) {
return reinterpret_cast<WireValue<T>*>(ptr + index * step / BITS_PER_BYTE)->get();
// TODO(soon): Benchmark this alternate implementation, which I suspect may make better use of
// TODO(perf): Benchmark this alternate implementation, which I suspect may make better use of
// the x86 SIB byte. Also use it for all the other getData/setData implementations below, and
// the various non-inline methods that look up pointers.
// Also if using this, consider changing ptr back to void* instead of byte*.
......
......@@ -393,12 +393,6 @@ void copyToUnchecked(Reader&& reader, kj::ArrayPtr<word> uncheckedBuffer) {
builder.requireFilled();
}
template <typename Type>
static typename Type::Reader defaultValue() {
// TODO(soon): Correctly handle lists. Maybe primitives too?
return typename Type::Reader(_::StructReader());
}
} // namespace capnp
#endif // CAPNP_MESSAGE_H_
......@@ -486,45 +486,6 @@ TEST(CommonParsers, References) {
}
}
TEST(CommonParsers, AcceptIfParser) {
auto parser = acceptIf(
oneOf(transform(exactly('a'), []() -> uint { return 123; }),
transform(exactly('b'), []() -> uint { return 456; }),
transform(exactly('c'), []() -> uint { return 789; })),
[](uint i) {return i > 200;});
{
StringPtr text = "a";
Input input(text.begin(), text.end());
Maybe<uint> result = parser(input);
EXPECT_TRUE(result == nullptr);
}
{
StringPtr text = "b";
Input input(text.begin(), text.end());
Maybe<uint> result = parser(input);
KJ_IF_MAYBE(value, result) {
EXPECT_EQ(456u, *value);
} else {
ADD_FAILURE() << "Expected parse result, got null.";
}
EXPECT_TRUE(input.atEnd());
}
{
StringPtr text = "c";
Input input(text.begin(), text.end());
Maybe<uint> result = parser(input);
KJ_IF_MAYBE(value, result) {
EXPECT_EQ(789u, *value);
} else {
ADD_FAILURE() << "Expected parse result, got null.";
}
EXPECT_TRUE(input.atEnd());
}
}
TEST(CommonParsers, NotLookingAt) {
auto parser = notLookingAt(exactly('a'));
......
......@@ -722,46 +722,6 @@ constexpr TransformWithLocation_<SubParser, TransformFunc> transformWithLocation
kj::fwd<SubParser>(subParser), kj::fwd<TransformFunc>(functor));
}
// -------------------------------------------------------------------
// acceptIf()
// Output = Same as SubParser
template <typename SubParser, typename Condition>
class AcceptIf_ {
public:
explicit constexpr AcceptIf_(SubParser&& subParser, Condition&& condition)
: subParser(kj::fwd<SubParser>(subParser)), condition(kj::fwd<Condition>(condition)) {}
template <typename Input>
Maybe<OutputType<SubParser, Input>> operator()(Input& input) const {
KJ_IF_MAYBE(subResult, subParser(input)) {
if (condition(*subResult)) {
return kj::mv(*subResult);
} else {
return nullptr;
}
} else {
return nullptr;
}
}
private:
SubParser subParser;
Condition condition;
};
template <typename SubParser, typename Condition>
constexpr AcceptIf_<SubParser, Condition> acceptIf(SubParser&& subParser, Condition&& condition) {
// Constructs a parser which executes some other parser and then invokes the functor
// `condition` on the result to check if it is valid. Typically, `condition` is a lambda
// returning true or false. Like with `transform()`, `condition` is invoked using `kj::apply`
// to unpack tuples.
//
// TODO(soon): Remove in favor of transformOrReject()?
return AcceptIf_<SubParser, Condition>(
kj::fwd<SubParser>(subParser), kj::fwd<Condition>(condition));
}
// -------------------------------------------------------------------
// notLookingAt()
// Fails if the given parser succeeds at the current location.
......
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