Skip to content

C++: use struct tag instead of symbol_type #3060

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 4 commits into from
Oct 5, 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
4 changes: 3 additions & 1 deletion src/cpp/cpp_declarator_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ symbolt &cpp_declarator_convertert::convert(
// adjust type if it's a non-static member function
if(final_type.id()==ID_code)
cpp_typecheck.add_this_to_method_type(
scope->identifier, final_type, method_qualifier);
cpp_typecheck.lookup(scope->identifier),
to_code_type(final_type),
method_qualifier);

get_final_identifier();

Expand Down
8 changes: 8 additions & 0 deletions src/cpp/cpp_exception_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ void cpp_exception_list_rec(
cpp_exception_list_rec(src.subtype(), ns, "_ptr"+suffix, dest);
}
}
else if(src.id() == ID_union_tag)
{
cpp_exception_list_rec(ns.follow_tag(to_union_tag_type(src)), ns, suffix, dest);
}
else if(src.id()==ID_union)
{
// just get tag
dest.push_back("union_"+src.get_string(ID_tag));
}
else if(src.id() == ID_struct_tag)
{
cpp_exception_list_rec(ns.follow_tag(to_struct_tag_type(src)), ns, suffix, dest);
}
else if(src.id()==ID_struct)
{
// just get tag
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/cpp_instantiate_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ std::string cpp_typecheckt::template_suffix(
const typet &type=expr.type();
if(type.id() == ID_symbol_type)
result += id2string(to_symbol_type(type).get_identifier());
else if(type.id() == ID_struct_tag ||
type.id() == ID_union_tag)
result += id2string(to_tag_type(type).get_identifier());
else
result+=cpp_type2name(type);
}
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/cpp_is_pod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ bool cpp_typecheckt::cpp_is_pod(const typet &type) const
DATA_INVARIANT(symb.is_type, "type symbol is a type");
return cpp_is_pod(symb.type);
}
else if(type.id() == ID_struct_tag ||
type.id() == ID_union_tag)
{
const symbolt &symb = lookup(to_tag_type(type));
DATA_INVARIANT(symb.is_type, "tag symbol is a type");
return cpp_is_pod(symb.type);
}

// everything else is POD
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/cpp_typecheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,15 @@ class cpp_typecheckt:public c_typecheck_baset
static bool has_auto(const typet &type);

void typecheck_member_function(
const irep_idt &compound_identifier,
const symbolt &compound_symbol,
struct_typet::componentt &component,
irept &initializers,
const typet &method_qualifier,
exprt &value);

void add_this_to_method_type(
const irep_idt &compound_identifier,
typet &method_type,
const symbolt &compound_symbol,
code_typet &method_type,
const typet &method_qualifier);

// for function overloading
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/cpp_typecheck_bases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void cpp_typecheckt::typecheck_compound_bases(struct_typet &type)
// elaborate any class template instances given as bases
elaborate_class_template(base_symbol_expr.type());

if(base_symbol_expr.type().id() == ID_struct_tag)
base_symbol_expr.type().id(ID_symbol_type);

if(base_symbol_expr.type().id() != ID_symbol_type)
{
error().source_location=name.source_location();
Expand Down
36 changes: 19 additions & 17 deletions src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ void cpp_typecheckt::typecheck_compound_type(
}
else
{
// create type symbol
symbol_typet symbol_type(symbol_name);
qualifiers.write(symbol_type);
type.swap(symbol_type);
// create struct tag
struct_tag_typet tag_type(symbol_name);
qualifiers.write(tag_type);
type.swap(tag_type);
}
}

Expand Down Expand Up @@ -509,7 +509,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
if(!is_virtual)
{
typecheck_member_function(
symbol.name, component, initializers,
symbol, component, initializers,
method_qualifier, value);

if(!value.is_nil() && !is_static)
Expand Down Expand Up @@ -540,7 +540,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
}

typecheck_member_function(
symbol.name,
symbol,
component,
initializers,
method_qualifier,
Expand Down Expand Up @@ -569,7 +569,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
// add a virtual-table pointer
struct_typet::componentt compo(
id2string(symbol.name) + "::@vtable_pointer",
pointer_type(symbol_typet(vt_name)));
pointer_type(struct_tag_typet(vt_name)));
compo.set_base_name("@vtable_pointer");
compo.set_pretty_name(id2string(symbol.base_name) + "@vtable_pointer");
compo.set(ID_is_vtptr, true);
Expand Down Expand Up @@ -1262,7 +1262,7 @@ void cpp_typecheckt::move_member_initializers(
}

void cpp_typecheckt::typecheck_member_function(
const irep_idt &compound_identifier,
const symbolt &compound_symbol,
struct_typet::componentt &component,
irept &initializers,
const typet &method_qualifier,
Expand All @@ -1283,10 +1283,7 @@ void cpp_typecheckt::typecheck_member_function(
}
else
{
add_this_to_method_type(
compound_identifier,
type,
method_qualifier);
add_this_to_method_type(compound_symbol, type, method_qualifier);
}

if(value.id() == ID_cpp_not_typechecked && value.has_operands())
Expand Down Expand Up @@ -1344,11 +1341,11 @@ void cpp_typecheckt::typecheck_member_function(
}

void cpp_typecheckt::add_this_to_method_type(
const irep_idt &compound_symbol,
typet &type,
const symbolt &compound_symbol,
code_typet &type,
const typet &method_qualifier)
{
code_typet::parameterst &parameters=to_code_type(type).parameters();
code_typet::parameterst &parameters = type.parameters();

parameters.insert(
parameters.begin(), code_typet::parametert());
Expand All @@ -1359,7 +1356,12 @@ void cpp_typecheckt::add_this_to_method_type(
parameter.set_base_name(ID_this);
parameter.set_this();

typet subtype=symbol_typet(compound_symbol);
typet subtype;

if(compound_symbol.type.id() == ID_union)
subtype = union_tag_typet(compound_symbol.name);
else
subtype = struct_tag_typet(compound_symbol.name);

if(has_const(method_qualifier))
subtype.set(ID_C_constant, true);
Expand Down Expand Up @@ -1455,7 +1457,7 @@ void cpp_typecheckt::convert_anon_struct_union_member(
if(struct_union_symbol.type.id() == ID_union)
compound_type = union_tag_typet(struct_union_symbol.name);
else
compound_type = symbol_typet(struct_union_symbol.name);
compound_type = struct_tag_typet(struct_union_symbol.name);

struct_typet::componentt component(identifier, compound_type);
component.set_access(access);
Expand Down
10 changes: 5 additions & 5 deletions src/cpp/cpp_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void cpp_typecheckt::typecheck_expr_main(exprt &expr)
{
// these appear to have type "struct _GUID"
// and they are lvalues!
expr.type()=symbol_typet("tag-_GUID");
expr.type() = struct_tag_typet("tag-_GUID");
follow(expr.type());
expr.set(ID_C_lvalue, true);
}
Expand Down Expand Up @@ -717,7 +717,7 @@ void cpp_typecheckt::typecheck_expr_address_of(exprt &expr)
if(args.size() > 0 && args[0].get(ID_C_base_name)==ID_this)
{
// it's a pointer to member function
const symbol_typet symbol(code_type.get(ID_C_member_name));
const struct_tag_typet symbol(code_type.get(ID_C_member_name));
expr.op0().type().add("to-member")=symbol;

if(code_type.get_bool(ID_C_is_virtual))
Expand Down Expand Up @@ -980,11 +980,11 @@ void cpp_typecheckt::typecheck_expr_explicit_constructor_call(exprt &expr)
{
assert(expr.type().id()==ID_struct);

symbol_typet symb(expr.type().get(ID_name));
symb.add_source_location()=expr.source_location();
struct_tag_typet tag(expr.type().get(ID_name));
tag.add_source_location() = expr.source_location();

exprt e=expr;
new_temporary(e.source_location(), symb, e.operands(), expr);
new_temporary(e.source_location(), tag, e.operands(), expr);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/cpp/cpp_typecheck_resolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ void cpp_typecheck_resolvet::remove_duplicates(
id = to_symbol_expr(old_id).get_identifier();
else if(old_id.id() == ID_type && old_id.type().id() == ID_symbol_type)
id = to_symbol_type(old_id.type()).get_identifier();
else if(old_id.id() == ID_type && old_id.type().id() == ID_struct_tag)
id = to_struct_tag_type(old_id.type()).get_identifier();
else if(old_id.id() == ID_type && old_id.type().id() == ID_union_tag)
id = to_union_tag_type(old_id.type()).get_identifier();

if(id=="")
{
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/cpp_typecheck_virtual_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ void cpp_typecheckt::do_virtual_table(const symbolt &symbol)
vt_symb_var.mode=ID_cpp;
vt_symb_var.module=module;
vt_symb_var.location=vt_symb_type.location;
vt_symb_var.type=symbol_typet(vt_symb_type.name);
vt_symb_var.type = struct_tag_typet(vt_symb_type.name);
vt_symb_var.is_lvalue=true;
vt_symb_var.is_static_lifetime=true;

// do the values
const struct_typet &vt_type=to_struct_type(vt_symb_type.type);

struct_exprt values(symbol_typet(vt_symb_type.name));
struct_exprt values(struct_tag_typet(vt_symb_type.name));

for(const auto &compo : vt_type.components())
{
Expand Down