From cf54024379f6e6cad0adba57aeb9809d13744c72 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Thu, 22 Feb 2018 18:05:15 +0100 Subject: [PATCH] fix derivation of propagation direction from connect stage --- core/src/container.cpp | 24 ++++++++++++++++-------- core/test/test_container.cpp | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/core/src/container.cpp b/core/src/container.cpp index bb25060f..ce2455b9 100644 --- a/core/src/container.cpp +++ b/core/src/container.cpp @@ -480,23 +480,31 @@ void SerialContainerPrivate::pruneInterfaces(container_type::const_iterator firs // determine accepted interface from available push interfaces InterfaceFlags accepted; - // if previous stage pushes forward, we accept forward propagation + // if first stage ... if (first != children().begin()) { auto prev = first; --prev; // pointer to previous stage + // ... pushes forward, we accept forward propagation if ((*prev)->pimpl()->requiredInterface() & WRITES_NEXT_START) - accepted |= WRITES_NEXT_START; + accepted |= PROPAGATE_FORWARDS; + // ... pulls backward, we accept backward propagation + if ((*prev)->pimpl()->requiredInterface() & READS_END) + accepted |= PROPAGATE_BACKWARDS; } // else: for first child we cannot determine the interface yet - // if end stage pushes backward, we accept backward propagation + // if end stage ... if (end != children().end()) { + // ... pushes backward, we accept backward propagation if ((*end)->pimpl()->requiredInterface() & WRITES_PREV_END) - accepted |= WRITES_PREV_END; + accepted |= PROPAGATE_BACKWARDS; + // ... pulls forward, we accept forward propagation + if ((*end)->pimpl()->requiredInterface() & READS_START) + accepted |= PROPAGATE_FORWARDS; } // else: for last child we cannot determine the interface yet // nothing to do if: // - accepted == 0: interface still unknown // - accepted == PROPAGATE_FORWARDS | PROPAGATE_BACKWARDS: no change - if (accepted != 0 && accepted != InterfaceFlags({PROPAGATE_FORWARDS, PROPAGATE_BACKWARDS})) + if (accepted != UNKNOWN && accepted != InterfaceFlags({PROPAGATE_FORWARDS, PROPAGATE_BACKWARDS})) pruneInterfaces(first, end, accepted); } @@ -509,13 +517,13 @@ void SerialContainerPrivate::pruneInterfaces(container_type::const_iterator firs for (auto it = first; it != end; ++it) { StagePrivate* impl = (*it)->pimpl(); // range should only contain stages with unknown required interface - assert(impl->requiredInterface() == PropagatingEitherWay::AUTO); + assert(impl->requiredInterface() == UNKNOWN); // remove push interfaces - if (!(accepted & WRITES_PREV_END)) + if (!(accepted & PROPAGATE_BACKWARDS)) impl->setPrevEnds(InterfacePtr()); - if (!(accepted & WRITES_NEXT_START)) + if (!(accepted & PROPAGATE_FORWARDS)) impl->setNextStarts(InterfacePtr()); } // 2nd sweep: recursively prune children diff --git a/core/test/test_container.cpp b/core/test/test_container.cpp index 678e5efb..fc7e77f3 100644 --- a/core/test/test_container.cpp +++ b/core/test/test_container.cpp @@ -292,6 +292,26 @@ TEST_F(SerialTest, interface_detection) { EXPECT_EQ((*++it)->pimpl()->interfaceFlags(), InterfaceFlags(PROPAGATE_FORWARDS)); EXPECT_EQ(serial.pimpl()->interfaceFlags(), InterfaceFlags(GENERATE)); + EXPECT_INIT_SUCCESS(true, true, GEN, ANY); + EXPECT_EQ(serial.pimpl()->interfaceFlags(), InterfaceFlags(GENERATE)); + + EXPECT_INIT_SUCCESS(true, true, ANY, GEN); + EXPECT_EQ(serial.pimpl()->interfaceFlags(), InterfaceFlags(GENERATE)); + + // derive propagation direction from inner connector + EXPECT_INIT_SUCCESS(false, false, ANY, CONN, ANY); // -> -- <- + it = serial.pimpl()->children().begin(); + EXPECT_EQ( (*it)->pimpl()->interfaceFlags(), InterfaceFlags(PROPAGATE_FORWARDS)); + EXPECT_EQ((*++it)->pimpl()->interfaceFlags(), InterfaceFlags(CONNECT)); + EXPECT_EQ((*++it)->pimpl()->interfaceFlags(), InterfaceFlags(PROPAGATE_BACKWARDS)); + EXPECT_EQ(serial.pimpl()->interfaceFlags(), InterfaceFlags(CONNECT)); + + EXPECT_INIT_SUCCESS(false, false, CONN, ANY); + EXPECT_EQ(serial.pimpl()->interfaceFlags(), InterfaceFlags(CONNECT)); + + EXPECT_INIT_SUCCESS(false, false, ANY, CONN); + EXPECT_EQ(serial.pimpl()->interfaceFlags(), InterfaceFlags(CONNECT)); + // derive propagation direction from outer interface EXPECT_INIT_SUCCESS(false, true, ANY, ANY); // -> -> it = serial.pimpl()->children().begin();