Skip to content

Introduce union tag type #2697

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 2 commits into from
Sep 7, 2018
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
23 changes: 19 additions & 4 deletions src/ansi-c/c_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ void c_typecheck_baset::typecheck_type(typet &type)
typecheck_symbol_type(to_symbol_type(type));
else if(type.id() == ID_typedef_type)
typecheck_typedef_type(type);
else if(type.id() == ID_struct_tag ||
type.id() == ID_union_tag)
{
// nothing to do, these stay as is
}
else if(type.id()==ID_vector)
typecheck_vector_type(to_vector_type(type));
else if(type.id()==ID_custom_unsignedbv ||
Expand Down Expand Up @@ -815,11 +820,21 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
}
}

symbol_typet symbol_type(identifier);
symbol_type.add_source_location()=type.source_location();

c_qualifierst original_qualifiers(type);
type.swap(symbol_type);

if(type.id() == ID_union)
{
union_tag_typet tag_type(identifier);
tag_type.add_source_location() = type.source_location();
type.swap(tag_type);
}
else
{
symbol_typet symbol_type(identifier);
symbol_type.add_source_location() = type.source_location();
type.swap(symbol_type);
}

original_qualifiers.write(type);
}

Expand Down
19 changes: 15 additions & 4 deletions src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ void cpp_typecheckt::typecheck_compound_type(
cpp_scopet *dest_scope=nullptr;
bool has_body=type.find(ID_body).is_not_nil();
bool tag_only_declaration=type.get_bool(ID_C_tag_only_declaration);
bool is_union = type.id() == ID_union;

if(!has_tag)
{
Expand Down Expand Up @@ -263,10 +264,20 @@ void cpp_typecheckt::typecheck_compound_type(
}
}

// create type symbol
symbol_typet symbol_type(symbol_name);
qualifiers.write(symbol_type);
type.swap(symbol_type);
if(is_union)
{
// create union tag
union_tag_typet tag_type(symbol_name);
qualifiers.write(tag_type);
type.swap(tag_type);
}
else
{
// create type symbol
symbol_typet symbol_type(symbol_name);
qualifiers.write(symbol_type);
type.swap(symbol_type);
}
}

void cpp_typecheckt::typecheck_compound_declarator(
Expand Down
6 changes: 6 additions & 0 deletions src/cpp/cpp_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ void cpp_typecheckt::typecheck_type(typet &type)
else if(type.id() == ID_symbol_type)
{
}
else if(type.id() == ID_struct_tag)
{
}
else if(type.id() == ID_union_tag)
{
}
else if(type.id()==ID_constructor ||
type.id()==ID_destructor)
{
Expand Down
20 changes: 17 additions & 3 deletions src/goto-symex/goto_symex_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,10 @@ void goto_symex_statet::rename_address(

// type might not have been renamed in case of nesting of
// structs and pointers/arrays
if(member_expr.struct_op().type().id() != ID_symbol_type)
if(
member_expr.struct_op().type().id() != ID_symbol_type &&
member_expr.struct_op().type().id() != ID_struct_tag &&
member_expr.struct_op().type().id() != ID_union_tag)
{
const struct_union_typet &su_type=
to_struct_union_type(member_expr.struct_op().type());
Expand Down Expand Up @@ -845,8 +848,19 @@ void goto_symex_statet::rename(
}
else if(type.id() == ID_symbol_type)
{
const symbolt &symbol=
ns.lookup(to_symbol_type(type).get_identifier());
const symbolt &symbol = ns.lookup(to_symbol_type(type));
type = symbol.type;
rename(type, l1_identifier, ns, level);
}
else if(type.id() == ID_union_tag)
{
const symbolt &symbol = ns.lookup(to_union_tag_type(type));
type = symbol.type;
rename(type, l1_identifier, ns, level);
}
else if(type.id() == ID_struct_tag)
{
const symbolt &symbol = ns.lookup(to_struct_tag_type(type));
type=symbol.type;
rename(type, l1_identifier, ns, level);
}
Expand Down