Skip to content

Test has_subtype on recursive data types #2084

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

Merged
merged 1 commit into from
Apr 18, 2018
Merged
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
32 changes: 30 additions & 2 deletions unit/util/has_subtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ static std::function<bool(const typet &)> is_type(const typet &t1)
return f;
}

SCENARIO("has_subtype", "[core][solvers][refinement][string_refinement]")
SCENARIO("has_subtype", "[core][utils][has_subtype]")
{
const symbol_tablet symbol_table;
symbol_tablet symbol_table;
const namespacet ns(symbol_table);

const typet char_type = java_char_type();
Expand Down Expand Up @@ -63,4 +63,32 @@ SCENARIO("has_subtype", "[core][solvers][refinement][string_refinement]")
REQUIRE_FALSE(has_subtype(ptr_type, is_type(int_type), ns));
}
}

GIVEN("a recursive struct definition")
{
symbol_typet symbol_type("A-struct");
struct_typet::componentt comp("ptr", pointer_type(symbol_type));
struct_typet struct_type;
struct_type.components().push_back(comp);

symbolt s;
s.type = struct_type;
s.name = "A-struct";
s.is_type = true;
symbol_table.add(s);

THEN("has_subtype terminates")
{
REQUIRE_FALSE(
has_subtype(struct_type, [&](const typet &t) { return false; }, ns));
}
THEN("symbol type is a subtype")
{
REQUIRE(has_subtype(struct_type, is_type(pointer_type(symbol_type)), ns));
}
THEN("struct type is a subtype")
{
REQUIRE(has_subtype(struct_type, is_type(struct_type), ns));
}
}
}