diff --git a/src/cpp/cpp_declarator_converter.cpp b/src/cpp/cpp_declarator_converter.cpp index 456547e3d05..632d56e70b6 100644 --- a/src/cpp/cpp_declarator_converter.cpp +++ b/src/cpp/cpp_declarator_converter.cpp @@ -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(); diff --git a/src/cpp/cpp_exception_id.cpp b/src/cpp/cpp_exception_id.cpp index 7899d03f999..74ade5396fd 100644 --- a/src/cpp/cpp_exception_id.cpp +++ b/src/cpp/cpp_exception_id.cpp @@ -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 diff --git a/src/cpp/cpp_instantiate_template.cpp b/src/cpp/cpp_instantiate_template.cpp index cfaf97d7a98..2fdbe6331ee 100644 --- a/src/cpp/cpp_instantiate_template.cpp +++ b/src/cpp/cpp_instantiate_template.cpp @@ -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); } diff --git a/src/cpp/cpp_is_pod.cpp b/src/cpp/cpp_is_pod.cpp index 7d17a77c9e5..c3f68e0af0a 100644 --- a/src/cpp/cpp_is_pod.cpp +++ b/src/cpp/cpp_is_pod.cpp @@ -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; diff --git a/src/cpp/cpp_typecheck.h b/src/cpp/cpp_typecheck.h index 9fbd7268dbf..51b19790245 100644 --- a/src/cpp/cpp_typecheck.h +++ b/src/cpp/cpp_typecheck.h @@ -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 diff --git a/src/cpp/cpp_typecheck_bases.cpp b/src/cpp/cpp_typecheck_bases.cpp index 4ad96ef08b8..bf282416127 100644 --- a/src/cpp/cpp_typecheck_bases.cpp +++ b/src/cpp/cpp_typecheck_bases.cpp @@ -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(); diff --git a/src/cpp/cpp_typecheck_compound_type.cpp b/src/cpp/cpp_typecheck_compound_type.cpp index 4d29ce97ba9..e082571be98 100644 --- a/src/cpp/cpp_typecheck_compound_type.cpp +++ b/src/cpp/cpp_typecheck_compound_type.cpp @@ -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); } } @@ -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) @@ -540,7 +540,7 @@ void cpp_typecheckt::typecheck_compound_declarator( } typecheck_member_function( - symbol.name, + symbol, component, initializers, method_qualifier, @@ -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); @@ -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, @@ -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()) @@ -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 ¶meters=to_code_type(type).parameters(); + code_typet::parameterst ¶meters = type.parameters(); parameters.insert( parameters.begin(), code_typet::parametert()); @@ -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); @@ -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); diff --git a/src/cpp/cpp_typecheck_expr.cpp b/src/cpp/cpp_typecheck_expr.cpp index 4b921d77c9d..3e171162d4a 100644 --- a/src/cpp/cpp_typecheck_expr.cpp +++ b/src/cpp/cpp_typecheck_expr.cpp @@ -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); } @@ -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)) @@ -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); } } diff --git a/src/cpp/cpp_typecheck_resolve.cpp b/src/cpp/cpp_typecheck_resolve.cpp index a78d0c09357..9ac4d8756f7 100644 --- a/src/cpp/cpp_typecheck_resolve.cpp +++ b/src/cpp/cpp_typecheck_resolve.cpp @@ -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=="") { diff --git a/src/cpp/cpp_typecheck_virtual_table.cpp b/src/cpp/cpp_typecheck_virtual_table.cpp index 78b3effc5cf..d47276ff323 100644 --- a/src/cpp/cpp_typecheck_virtual_table.cpp +++ b/src/cpp/cpp_typecheck_virtual_table.cpp @@ -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()) {