Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TopoSorter: Only allow certain params to be incomplete #392

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions oi/type_graph/TopoSorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,31 @@ namespace {
* Other containers are not required to do this, but might still have this
* behaviour.
*/
bool containerAllowsIncompleteParams(const Container& c) {
bool containerAllowsIncompleteParam(const Container& c, size_t i) {
switch (c.containerInfo_.ctype) {
case SEQ_TYPE:
case LIST_TYPE:
case UNIQ_PTR_TYPE:
case SHRD_PTR_TYPE:
// Also std::forward_list, if we ever support that
// Would be good to have this as an option in the TOML files
return true;
return i == 0;
default:
return false;
}
}
} // namespace

void TopoSorter::visit(Container& c) {
if (!containerAllowsIncompleteParams(c)) {
for (const auto& param : c.templateParams) {
for (size_t i = 0; i < c.templateParams.size(); i++) {
const auto& param = c.templateParams[i];
if (containerAllowsIncompleteParam(c, i)) {
acceptAfter(param.type());
} else {
accept(param.type());
}
}
sortedTypes_.push_back(c);
if (containerAllowsIncompleteParams(c)) {
for (const auto& param : c.templateParams) {
acceptAfter(param.type());
}
}
}

void TopoSorter::visit(Enum& e) {
Expand Down
10 changes: 8 additions & 2 deletions test/test_topo_sorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,30 @@ std::map
}

TEST(TopoSorterTest, ContainersVector) {
// std::vector allows forward declared template parameters
// std::vector allows a forward declared type
auto myparam = Class{1, Class::Kind::Struct, "MyParam", 13};
auto myalloc = Class{1, Class::Kind::Struct, "MyAlloc", 0};
auto mycontainer = getVector();
mycontainer.templateParams.push_back((myparam));
mycontainer.templateParams.push_back((myalloc));

test({mycontainer}, R"(
MyAlloc
std::vector
MyParam
)");
}

TEST(TopoSorterTest, ContainersList) {
// std::list allows forward declared template parameters
// std::list allows a forward declared type
auto myparam = Class{1, Class::Kind::Struct, "MyParam", 13};
auto myalloc = Class{1, Class::Kind::Struct, "MyAlloc", 0};
auto mycontainer = getList();
mycontainer.templateParams.push_back((myparam));
mycontainer.templateParams.push_back((myalloc));

test({mycontainer}, R"(
MyAlloc
std::list
MyParam
)");
Expand Down
Loading