Skip to content

Use cpp_namet's and namet's constructors #3025

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
Sep 24, 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
8 changes: 2 additions & 6 deletions src/cpp/cpp_constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,10 @@ optionalt<codet> cpp_typecheckt::cpp_constructor(
// there is always a constructor for non-PODs
assert(constructor_name!="");

irept cpp_name(ID_cpp_name);
cpp_name.get_sub().push_back(irept(ID_name));
cpp_name.get_sub().back().set(ID_identifier, constructor_name);
cpp_name.get_sub().back().set(ID_C_source_location, source_location);

side_effect_expr_function_callt function_call;
function_call.add_source_location()=source_location;
function_call.function().swap(static_cast<exprt&>(cpp_name));
function_call.function() =
cpp_namet(constructor_name, source_location).as_expr();
function_call.arguments().reserve(operands_tc.size());

for(exprt::operandst::iterator
Expand Down
3 changes: 1 addition & 2 deletions src/cpp/cpp_declarator_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ symbolt &cpp_declarator_convertert::convert(
type.swap(declarator.name().get_sub().back());
declarator.type().subtype()=type;
cpp_typecheck.typecheck_type(type);
irept name(ID_name);
name.set(ID_identifier, "("+cpp_type2name(type)+")");
cpp_namet::namet name("(" + cpp_type2name(type) + ")");
declarator.name().get_sub().back().swap(name);
}

Expand Down
5 changes: 1 addition & 4 deletions src/cpp/cpp_destructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ optionalt<codet> cpp_typecheckt::cpp_destructor(
// there is always a destructor for non-PODs
assert(dtor_name!="");

irept cpp_name(ID_cpp_name);
cpp_name.get_sub().push_back(irept(ID_name));
cpp_name.get_sub().back().set(ID_identifier, dtor_name);
cpp_name.get_sub().back().set(ID_C_source_location, source_location);
cpp_namet cpp_name(dtor_name, source_location);

exprt member(ID_member);
member.add(ID_component_cpp_name) = cpp_name;
Expand Down
3 changes: 1 addition & 2 deletions src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ void cpp_typecheckt::typecheck_compound_declarator(
typet type=static_cast<typet &>(declarator.name().get_sub()[1]);
declarator.type().subtype()=type;

irept name(ID_name);
name.set(ID_identifier, "("+cpp_type2name(type)+")");
cpp_namet::namet name("(" + cpp_type2name(type) + ")");
declarator.name().get_sub().back().swap(name);
}

Expand Down
112 changes: 18 additions & 94 deletions src/cpp/cpp_typecheck_constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,8 @@ void cpp_typecheckt::default_ctor(
const irep_idt &base_name,
cpp_declarationt &ctor) const
{
exprt name(ID_name);
name.set(ID_identifier, base_name);
name.add_source_location()=source_location;

cpp_declaratort decl;
decl.name().id(ID_cpp_name);
decl.name().move_to_sub(name);
decl.name() = cpp_namet(base_name, source_location);
decl.type()=typet(ID_function_type);
decl.type().subtype().make_nil();
decl.add_source_location()=source_location;
Expand Down Expand Up @@ -204,20 +199,10 @@ void cpp_typecheckt::default_cpctor(
std::string param_identifier("ref");

// Compound name
irept comp_name(ID_name);
comp_name.set(ID_identifier, symbol.base_name);
comp_name.set(ID_C_source_location, source_location);

cpp_namet cppcomp;
cppcomp.move_to_sub(comp_name);
const cpp_namet cppcomp(symbol.base_name, source_location);

// Parameter name
exprt param_name(ID_name);
param_name.add_source_location()=source_location;
param_name.set(ID_identifier, param_identifier);

cpp_namet cpp_parameter;
cpp_parameter.move_to_sub(param_name);
const cpp_namet cpp_parameter(param_identifier, source_location);

// Parameter declarator
cpp_declaratort parameter_tor;
Expand All @@ -230,8 +215,7 @@ void cpp_typecheckt::default_cpctor(
cpp_declarationt parameter_decl;
parameter_decl.set(ID_type, ID_merged_type);
auto &sub = to_type_with_subtypes(parameter_decl.type()).subtypes();
sub.push_back(
static_cast<const typet &>(static_cast<const irept &>(cppcomp)));
sub.push_back(cppcomp.as_type());
irept constnd(ID_const);
sub.push_back(static_cast<const typet &>(constnd));
parameter_decl.move_to_operands(parameter_tor);
Expand Down Expand Up @@ -264,18 +248,12 @@ void cpp_typecheckt::default_cpctor(
irep_idt ctor_name=parsymb.base_name;

// Call the parent default copy constructor
exprt name(ID_name);
name.set(ID_identifier, ctor_name);
name.add_source_location()=source_location;

cpp_namet cppname;
cppname.move_to_sub(name);
const cpp_namet cppname(ctor_name, source_location);

codet mem_init(ID_member_initializer);
mem_init.add_source_location()=source_location;
mem_init.set(ID_member, cppname);
mem_init.copy_to_operands(
static_cast<const exprt &>(static_cast<const irept &>(cpp_parameter)));
mem_init.copy_to_operands(cpp_parameter.as_expr());
initializers.move_to_sub(mem_init);
}
}
Expand All @@ -289,12 +267,7 @@ void cpp_typecheckt::default_cpctor(
// Take care of virtual tables
if(mem_c.get_bool(ID_is_vtptr))
{
exprt name(ID_name);
name.set(ID_identifier, mem_c.get_base_name());
name.add_source_location()=source_location;

cpp_namet cppname;
cppname.move_to_sub(name);
const cpp_namet cppname(mem_c.get_base_name(), source_location);

const symbolt &virtual_table_symbol_type =
lookup(mem_c.type().subtype().get(ID_identifier));
Expand Down Expand Up @@ -327,21 +300,15 @@ void cpp_typecheckt::default_cpctor(

const irep_idt &mem_name = mem_c.get_base_name();

exprt name(ID_name);
name.set(ID_identifier, mem_name);
name.add_source_location()=source_location;

cpp_namet cppname;
cppname.move_to_sub(name);
const cpp_namet cppname(mem_name, source_location);

codet mem_init(ID_member_initializer);
mem_init.set(ID_member, cppname);
mem_init.add_source_location()=source_location;

exprt memberexpr(ID_member);
memberexpr.set(ID_component_cpp_name, cppname);
memberexpr.copy_to_operands(
static_cast<const exprt &>(static_cast<const irept &>(cpp_parameter)));
memberexpr.copy_to_operands(cpp_parameter.as_expr());
memberexpr.add_source_location()=source_location;

if(mem_c.type().id() == ID_array)
Expand Down Expand Up @@ -400,12 +367,8 @@ void cpp_typecheckt::default_assignop(
auto &args_decl_type_sub = to_type_with_subtypes(args_decl.type()).subtypes();

args_decl.type().id(ID_merged_type);
args_decl_type_sub.push_back(typet(ID_cpp_name));
args_decl_type_sub.back().get_sub().push_back(irept(ID_name));
args_decl_type_sub.back().get_sub().back().set(
ID_identifier, symbol.base_name);
args_decl_type_sub.back().get_sub().back().set(
ID_C_source_location, source_location);
args_decl_type_sub.push_back(
cpp_namet(symbol.base_name, source_location).as_type());

args_decl_type_sub.push_back(typet(ID_const));
args_decl.operands().push_back(exprt(ID_cpp_declarator));
Expand All @@ -414,9 +377,7 @@ void cpp_typecheckt::default_assignop(
cpp_declaratort &args_decl_declor=
static_cast<cpp_declaratort&>(args_decl.operands().back());

args_decl_declor.name().id(ID_cpp_name);
args_decl_declor.name().get_sub().push_back(irept(ID_name));
args_decl_declor.name().get_sub().back().add(ID_identifier).id(arg_name);
args_decl_declor.name() = cpp_namet(arg_name, source_location);
args_decl_declor.add_source_location()=source_location;

args_decl_declor.type()=pointer_type(typet(ID_nil));
Expand Down Expand Up @@ -522,8 +483,6 @@ void cpp_typecheckt::check_member_initializers(
const irept &initializer=*init_it;
assert(initializer.is_not_nil());

assert(initializer.get(ID_member)==ID_cpp_name);

const cpp_namet &member_name=
to_cpp_name(initializer.find(ID_member));

Expand Down Expand Up @@ -666,15 +625,7 @@ void cpp_typecheckt::full_member_initialization(
// ifthenelse only gets to have two operands (instead of three)
codet cond(ID_ifthenelse);

{
cpp_namet most_derived;
most_derived.get_sub().push_back(irept(ID_name));
most_derived.get_sub().back().set(ID_identifier, "@most_derived");

exprt tmp;
tmp.swap(most_derived);
cond.move_to_operands(tmp);
}
cond.copy_to_operands(cpp_namet("@most_derived").as_expr());

code_blockt block;

Expand All @@ -684,11 +635,7 @@ void cpp_typecheckt::full_member_initialization(
if(!cpp_is_pod(symb.type))
{
// default initializer
irept name(ID_name);
name.set(ID_identifier, symb.base_name);

cpp_namet cppname;
cppname.move_to_sub(name);
const cpp_namet cppname(symb.base_name);

codet mem_init(ID_member_initializer);
mem_init.set(ID_member, cppname);
Expand Down Expand Up @@ -724,8 +671,6 @@ void cpp_typecheckt::full_member_initialization(
{
irept initializer=*m_it;

assert(initializer.get(ID_member)==ID_cpp_name);

const cpp_namet &member_name=
to_cpp_name(initializer.find(ID_member));

Expand Down Expand Up @@ -773,11 +718,7 @@ void cpp_typecheckt::full_member_initialization(
// Call the parent default constructor
if(!found)
{
irept name(ID_name);
name.set(ID_identifier, ctor_name);

cpp_namet cppname;
cppname.move_to_sub(name);
const cpp_namet cppname(ctor_name);

codet mem_init(ID_member_initializer);
mem_init.set(ID_member, cppname);
Expand All @@ -790,15 +731,7 @@ void cpp_typecheckt::full_member_initialization(
// ifthenelse only gets to have two operands (instead of three)
codet cond(ID_ifthenelse);

{
cpp_namet most_derived;
most_derived.get_sub().push_back(irept(ID_name));
most_derived.get_sub().back().set(ID_identifier, "@most_derived");

exprt tmp;
tmp.swap(most_derived);
cond.move_to_operands(tmp);
}
cond.copy_to_operands(cpp_namet("@most_derived").as_expr());

{
codet tmp(ID_member_initializer);
Expand All @@ -816,12 +749,7 @@ void cpp_typecheckt::full_member_initialization(
// Take care of virtual tables
if(c.get_bool(ID_is_vtptr))
{
exprt name(ID_name);
name.set(ID_identifier, c.get_base_name());
name.add_source_location() = c.source_location();

cpp_namet cppname;
cppname.move_to_sub(name);
const cpp_namet cppname(c.get_base_name(), c.source_location());

const symbolt &virtual_table_symbol_type =
lookup(c.type().subtype().get(ID_identifier));
Expand Down Expand Up @@ -893,11 +821,7 @@ void cpp_typecheckt::full_member_initialization(
// then its default constructor is called.
if(!found && !cpp_is_pod((const typet &)(c.find(ID_type))))
{
irept name(ID_name);
name.set(ID_identifier, mem_name);

cpp_namet cppname;
cppname.move_to_sub(name);
cpp_namet cppname(mem_name);

codet mem_init(ID_member_initializer);
mem_init.set(ID_member, cppname);
Expand Down
10 changes: 2 additions & 8 deletions src/cpp/cpp_typecheck_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,10 +1087,7 @@ bool cpp_typecheckt::user_defined_conversion_sequence(
{
// To take care of the possible virtual case,
// we build the function as a member expression.
irept func_name(ID_name);
func_name.set(ID_identifier, component.get_base_name());
cpp_namet cpp_func_name;
cpp_func_name.get_sub().push_back(func_name);
const cpp_namet cpp_func_name(component.get_base_name());

exprt member_func(ID_member);
member_func.add(ID_component_cpp_name)=cpp_func_name;
Expand Down Expand Up @@ -1318,10 +1315,7 @@ bool cpp_typecheckt::reference_binding(
{
// To take care of the possible virtual case,
// we build the function as a member expression.
irept func_name(ID_name);
func_name.set(ID_identifier, component.get_base_name());
cpp_namet cpp_func_name;
cpp_func_name.get_sub().push_back(func_name);
const cpp_namet cpp_func_name(component.get_base_name());

exprt member_func(ID_member);
member_func.add(ID_component_cpp_name)=cpp_func_name;
Expand Down
7 changes: 1 addition & 6 deletions src/cpp/cpp_typecheck_declaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ void cpp_typecheckt::convert_anonymous_union(
// unnamed object
std::string identifier="#anon_union"+std::to_string(anon_counter++);

irept name(ID_name);
name.set(ID_identifier, identifier);
name.set(ID_C_source_location, declaration.source_location());

cpp_namet cpp_name;
cpp_name.move_to_sub(name);
const cpp_namet cpp_name(identifier, declaration.source_location());
cpp_declaratort declarator;
declarator.name()=cpp_name;

Expand Down
21 changes: 3 additions & 18 deletions src/cpp/cpp_typecheck_destructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ void cpp_typecheckt::default_dtor(
assert(symbol.type.id()==ID_struct ||
symbol.type.id()==ID_union);

irept name;
name.id(ID_name);
name.set(ID_identifier, "~"+id2string(symbol.base_name));
name.set(ID_C_source_location, symbol.location);

cpp_declaratort decl;
decl.name().id(ID_cpp_name);
decl.name().move_to_sub(name);
decl.name() = cpp_namet("~" + id2string(symbol.base_name), symbol.location);
decl.type().id(ID_function_type);
decl.type().subtype().make_nil();

Expand Down Expand Up @@ -78,11 +72,7 @@ codet cpp_typecheckt::dtor(const symbolt &symbol)
{
if(c.get_bool(ID_is_vtptr))
{
exprt name(ID_name);
name.set(ID_identifier, c.get_base_name());

cpp_namet cppname;
cppname.move_to_sub(name);
const cpp_namet cppname(c.get_base_name());

const symbolt &virtual_table_symbol_type =
lookup(c.type().subtype().get(ID_identifier));
Expand Down Expand Up @@ -123,12 +113,7 @@ codet cpp_typecheckt::dtor(const symbolt &symbol)
cpp_is_pod(type))
continue;

irept name(ID_name);
name.set(ID_identifier, cit->get_base_name());
name.set(ID_C_source_location, source_location);

cpp_namet cppname;
cppname.get_sub().push_back(name);
const cpp_namet cppname(cit->get_base_name(), source_location);

exprt member(ID_ptrmember, type);
member.set(ID_component_cpp_name, cppname);
Expand Down
Loading