Skip to content

Commit

Permalink
Merge pull request diffblue#1444 from smowton/upstream/restrict-symbo…
Browse files Browse the repository at this point in the history
…l-table

SEC-78 Restrict symbol table interface
  • Loading branch information
smowton authored Oct 5, 2017
2 parents d577d40 + 6794191 commit 22a68fe
Show file tree
Hide file tree
Showing 67 changed files with 526 additions and 492 deletions.
8 changes: 4 additions & 4 deletions src/ansi-c/ansi_c_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void record_function_outputs(
codet output(ID_output);
output.operands().resize(2);

const symbolt &return_symbol=symbol_table.lookup("return'");
const symbolt &return_symbol=*symbol_table.lookup("return'");

output.op0()=
address_of_exprt(
Expand Down Expand Up @@ -212,7 +212,7 @@ bool generate_ansi_c_start_function(
// build call to initialization function

{
symbol_tablet::symbolst::iterator init_it=
symbol_tablet::symbolst::const_iterator init_it=
symbol_table.symbols.find(INITIALIZE_FUNCTION);

if(init_it==symbol_table.symbols.end())
Expand Down Expand Up @@ -478,11 +478,11 @@ bool generate_ansi_c_start_function(
new_symbol.value.swap(init_code);
new_symbol.mode=symbol.mode;

if(symbol_table.move(new_symbol))
if(!symbol_table.insert(std::move(new_symbol)).second)
{
messaget message;
message.set_message_handler(message_handler);
message.error() << "failed to move main symbol" << messaget::eom;
message.error() << "failed to insert main symbol" << messaget::eom;
return true;
}

Expand Down
16 changes: 7 additions & 9 deletions src/ansi-c/c_typecheck_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol)
}

// see if we have it already
symbol_tablet::symbolst::iterator old_it=
symbol_tablet::symbolst::const_iterator old_it=
symbol_table.symbols.find(symbol.name);

if(old_it==symbol_table.symbols.end())
Expand All @@ -121,10 +121,11 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol)
throw 0;
}

symbolt & existing_symbol=*symbol_table.get_writeable(symbol.name);
if(symbol.is_type)
typecheck_redefinition_type(old_it->second, symbol);
typecheck_redefinition_type(existing_symbol, symbol);
else
typecheck_redefinition_non_type(old_it->second, symbol);
typecheck_redefinition_non_type(existing_symbol, symbol);
}
}

Expand Down Expand Up @@ -350,10 +351,10 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
{
const irep_idt &identifier=p_it->get_identifier();

symbol_tablet::symbolst::iterator p_s_it=
symbol_tablet::symbolst::const_iterator p_s_it=
symbol_table.symbols.find(identifier);
if(p_s_it!=symbol_table.symbols.end())
symbol_table.symbols.erase(p_s_it);
symbol_table.erase(p_s_it);
}
}
else
Expand Down Expand Up @@ -732,10 +733,7 @@ void c_typecheck_baset::typecheck_declaration(
// add code contract (if any); we typecheck this after the
// function body done above, so as to have parameter symbols
// available
symbol_tablet::symbolst::iterator s_it=
symbol_table.symbols.find(identifier);
assert(s_it!=symbol_table.symbols.end());
symbolt &new_symbol=s_it->second;
symbolt &new_symbol=*symbol_table.get_writeable(identifier);

typecheck_spec_expr(contract, ID_C_spec_requires);

Expand Down
4 changes: 2 additions & 2 deletions src/ansi-c/c_typecheck_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void c_typecheck_baset::typecheck_decl(codet &code)
irep_idt identifier=d_it->get_name();

// look it up
symbol_tablet::symbolst::iterator s_it=
symbol_tablet::symbolst::const_iterator s_it=
symbol_table.symbols.find(identifier);

if(s_it==symbol_table.symbols.end())
Expand All @@ -298,7 +298,7 @@ void c_typecheck_baset::typecheck_decl(codet &code)
throw 0;
}

symbolt &symbol=s_it->second;
const symbolt &symbol=s_it->second;

// This must not be an incomplete type, unless it's 'extern'
// or a typedef.
Expand Down
6 changes: 3 additions & 3 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void c_typecheck_baset::typecheck_expr_builtin_va_arg(exprt &expr)
symbol.name=ID_gcc_builtin_va_arg;
symbol.type=symbol_type;

symbol_table.move(symbol);
symbol_table.insert(std::move(symbol));
}

void c_typecheck_baset::typecheck_expr_cw_va_arg_typeof(exprt &expr)
Expand Down Expand Up @@ -704,7 +704,7 @@ void c_typecheck_baset::typecheck_expr_operands(exprt &expr)
declaration.declarators().front().get_name();

// look it up
symbol_tablet::symbolst::iterator s_it=
symbol_tablet::symbolst::const_iterator s_it=
symbol_table.symbols.find(identifier);

if(s_it==symbol_table.symbols.end())
Expand All @@ -715,7 +715,7 @@ void c_typecheck_baset::typecheck_expr_operands(exprt &expr)
throw 0;
}

symbolt &symbol=s_it->second;
const symbolt &symbol=s_it->second;

if(symbol.is_type || symbol.is_extern || symbol.is_static_lifetime ||
!is_complete_type(symbol.type) || symbol.type.id()==ID_code)
Expand Down
17 changes: 6 additions & 11 deletions src/ansi-c/c_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,7 @@ void c_typecheck_baset::typecheck_type(typet &type)
{
const irep_idt &tag_name=
to_c_enum_tag_type(type.subtype()).get_identifier();

symbol_tablet::symbolst::iterator entry=
symbol_table.symbols.find(tag_name);
assert(entry!=symbol_table.symbols.end());

entry->second.type.subtype()=result;
symbol_table.get_writeable(tag_name)->get().type.subtype()=result;
}

type=result;
Expand Down Expand Up @@ -736,7 +731,7 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
identifier=type.find(ID_tag).get(ID_identifier);

// does it exist already?
symbol_tablet::symbolst::iterator s_it=
symbol_tablet::symbolst::const_iterator s_it=
symbol_table.symbols.find(identifier);

if(s_it==symbol_table.symbols.end())
Expand Down Expand Up @@ -787,7 +782,7 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
type.set(ID_tag, base_name);

typecheck_compound_body(type);
s_it->second.type.swap(type);
symbol_table.get_writeable(s_it->first)->get().type.swap(type);
}
}
else if(have_body)
Expand Down Expand Up @@ -1213,19 +1208,19 @@ void c_typecheck_baset::typecheck_c_enum_type(typet &type)
enum_tag_symbol.type.subtype()=underlying_type;

// is it in the symbol table already?
symbol_tablet::symbolst::iterator s_it=
symbol_tablet::symbolst::const_iterator s_it=
symbol_table.symbols.find(identifier);

if(s_it!=symbol_table.symbols.end())
{
// Yes.
symbolt &symbol=s_it->second;
const symbolt &symbol=s_it->second;

if(symbol.type.id()==ID_incomplete_c_enum)
{
// Ok, overwrite the type in the symbol table.
// This gives us the members and the subtype.
symbol.type=enum_tag_symbol.type;
symbol_table.get_writeable(symbol.name)->get().type=enum_tag_symbol.type;
}
else if(symbol.type.id()==ID_c_enum)
{
Expand Down
25 changes: 10 additions & 15 deletions src/cpp/cpp_declarator_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ symbolt &cpp_declarator_convertert::convert(
}

// try static first
symbol_tablet::symbolst::iterator c_it=
cpp_typecheck.symbol_table.symbols.find(final_identifier);
symbol_tablet::opt_symbol_reft maybe_symbol=
cpp_typecheck.symbol_table.get_writeable(final_identifier);

if(c_it==cpp_typecheck.symbol_table.symbols.end())
if(!maybe_symbol)
{
// adjust type if it's a non-static member function
if(final_type.id()==ID_code)
Expand All @@ -111,9 +111,8 @@ symbolt &cpp_declarator_convertert::convert(
get_final_identifier();

// try again
c_it=cpp_typecheck.symbol_table.symbols.find(final_identifier);

if(c_it==cpp_typecheck.symbol_table.symbols.end())
maybe_symbol=cpp_typecheck.symbol_table.get_writeable(final_identifier);
if(!maybe_symbol)
{
cpp_typecheck.error().source_location=
declarator.name().source_location();
Expand All @@ -125,9 +124,7 @@ symbolt &cpp_declarator_convertert::convert(
}
}

assert(c_it!=cpp_typecheck.symbol_table.symbols.end());

symbolt &symbol=c_it->second;
symbolt &symbol=*maybe_symbol;

combine_types(declarator.name().source_location(), final_type, symbol);
enforce_rules(symbol);
Expand Down Expand Up @@ -194,13 +191,11 @@ symbolt &cpp_declarator_convertert::convert(
}

// already there?
symbol_tablet::symbolst::iterator c_it=
cpp_typecheck.symbol_table.symbols.find(final_identifier);

if(c_it==cpp_typecheck.symbol_table.symbols.end())
symbol_tablet::opt_symbol_reft maybe_symbol=
cpp_typecheck.symbol_table.get_writeable(final_identifier);
if(!maybe_symbol)
return convert_new_symbol(storage_spec, member_spec, declarator);

symbolt &symbol=c_it->second;
symbolt &symbol=*maybe_symbol;

if(!storage_spec.is_extern())
symbol.is_extern = false;
Expand Down
9 changes: 2 additions & 7 deletions src/cpp/cpp_instantiate_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ const symbolt &cpp_typecheckt::instantiate_template(
// been instantiated using these arguments
{
// need non-const handle on template symbol
symbolt &s=symbol_table.symbols.find(template_symbol.name)->second;
symbolt &s=*symbol_table.get_writeable(template_symbol.name);
irept &instantiated_with=s.value.add("instantiated_with");
instantiated_with.get_sub().push_back(specialization_template_args);
}
Expand Down Expand Up @@ -451,12 +451,7 @@ const symbolt &cpp_typecheckt::instantiate_template(

if(is_template_method)
{
symbol_tablet::symbolst::iterator it =
symbol_table.symbols.find(class_name);

assert(it!=symbol_table.symbols.end());

symbolt &symb = it->second;
symbolt &symb=*symbol_table.get_writeable(class_name);

assert(new_decl.declarators().size() == 1);

Expand Down
32 changes: 16 additions & 16 deletions src/cpp/cpp_typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ void cpp_typecheckt::static_and_dynamic_initialization()

disable_access_control = true;

for(const auto &d_it : dynamic_initializations)
for(const irep_idt &d_it : dynamic_initializations)
{
symbolt &symbol=symbol_table.symbols.find(d_it)->second;
const symbolt &symbol=*symbol_table.lookup(d_it);

if(symbol.is_extern)
continue;
Expand All @@ -178,7 +178,7 @@ void cpp_typecheckt::static_and_dynamic_initialization()

// Make it nil to get zero initialization by
// __CPROVER_initialize
symbol.value.make_nil();
symbol_table.get_writeable(d_it)->get().value.make_nil();
}
else
{
Expand Down Expand Up @@ -210,7 +210,7 @@ void cpp_typecheckt::static_and_dynamic_initialization()
init_symbol.is_type=false;
init_symbol.is_macro=false;

symbol_table.move(init_symbol);
symbol_table.insert(std::move(init_symbol));

disable_access_control=false;
}
Expand All @@ -223,14 +223,15 @@ void cpp_typecheckt::do_not_typechecked()
{
cont = false;

Forall_symbols(s_it, symbol_table.symbols)
for(const auto &named_symbol : symbol_table.symbols)
{
symbolt &symbol=s_it->second;
const symbolt &symbol=named_symbol.second;

if(symbol.value.id()=="cpp_not_typechecked" &&
symbol.value.get_bool("is_used"))
{
assert(symbol.type.id()==ID_code);
symbolt &symbol=*symbol_table.get_writeable(named_symbol.first);

if(symbol.base_name=="operator=")
{
Expand All @@ -256,37 +257,36 @@ void cpp_typecheckt::do_not_typechecked()
}
while(cont);

Forall_symbols(s_it, symbol_table.symbols)
for(const auto &named_symbol : symbol_table.symbols)
{
symbolt &symbol=s_it->second;
if(symbol.value.id()=="cpp_not_typechecked")
symbol.value.make_nil();
if(named_symbol.second.value.id()=="cpp_not_typechecked")
symbol_table.get_writeable(named_symbol.first)->get().value.make_nil();
}
}

void cpp_typecheckt::clean_up()
{
symbol_tablet::symbolst::iterator it=symbol_table.symbols.begin();
symbol_tablet::symbolst::const_iterator it=symbol_table.symbols.begin();

while(it!=symbol_table.symbols.end())
{
symbol_tablet::symbolst::iterator cur_it = it;
symbol_tablet::symbolst::const_iterator cur_it = it;
it++;

symbolt &symbol = cur_it->second;
const symbolt &symbol=cur_it->second;

// erase templates
if(symbol.type.get_bool(ID_is_template))
{
symbol_table.symbols.erase(cur_it);
symbol_table.erase(cur_it);
continue;
}
else if(symbol.type.id()==ID_struct ||
symbol.type.id()==ID_union)
{
// remove methods from 'components'
struct_union_typet &struct_union_type=
to_struct_union_type(symbol.type);
struct_union_typet &struct_union_type=to_struct_union_type(
symbol_table.get_writeable(cur_it->first)->get().type);

const struct_union_typet::componentst &components=
struct_union_type.components();
Expand Down
Loading

0 comments on commit 22a68fe

Please sign in to comment.