Skip to content

cpp_scopet::lookup methods now return an id set #3063

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 29, 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
12 changes: 4 additions & 8 deletions src/cpp/cpp_declarator_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,8 @@ symbolt &cpp_declarator_convertert::convert(

if(symbol.type.id()=="cpp-template-type")
{
cpp_scopet::id_sett id_set;

scope->lookup_identifier(
symbol.name, cpp_idt::id_classt::TEMPLATE_PARAMETER, id_set);
const auto id_set = scope->lookup_identifier(
symbol.name, cpp_idt::id_classt::TEMPLATE_PARAMETER);

if(id_set.empty())
{
Expand Down Expand Up @@ -496,10 +494,8 @@ symbolt &cpp_declarator_convertert::convert_new_symbol(

if(!is_code)
{
cpp_scopest::id_sett id_set;

cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name, cpp_scopet::SCOPE_ONLY, id_set);
const auto id_set = cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name, cpp_scopet::SCOPE_ONLY);

for(cpp_scopest::id_sett::const_iterator
id_it=id_set.begin();
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/cpp_instantiate_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ const symbolt &cpp_typecheckt::instantiate_template(
{
cpp_scopet &scope=cpp_scopes.get_scope(subscope_name);

cpp_scopet::id_sett id_set;
scope.lookup(template_symbol.base_name, cpp_scopet::SCOPE_ONLY, id_set);
const auto id_set =
scope.lookup(template_symbol.base_name, cpp_scopet::SCOPE_ONLY);

if(id_set.size()==1)
{
Expand Down
31 changes: 16 additions & 15 deletions src/cpp/cpp_scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std::ostream &operator << (std::ostream &out, cpp_scopet::lookup_kindt kind)
return out;
}

void cpp_scopet::lookup(
void cpp_scopet::lookup_rec(
const irep_idt &base_name,
lookup_kindt kind,
id_sett &id_set)
Expand Down Expand Up @@ -60,7 +60,7 @@ void cpp_scopet::lookup(

// Recursive call.
// Note the different kind!
other_scope.lookup(base_name, QUALIFIED, id_set);
other_scope.lookup_rec(base_name, QUALIFIED, id_set);
}

if(!id_set.empty())
Expand All @@ -76,20 +76,21 @@ void cpp_scopet::lookup(

// Recursive call.
// Note the different kind!
other_scope.lookup(base_name, QUALIFIED, id_set);
other_scope.lookup_rec(base_name, QUALIFIED, id_set);
}

if(kind==QUALIFIED)
return; // done

if(!id_set.empty())
return; // done

// ask parent, recursive call
if(!is_root_scope())
get_parent().lookup(base_name, kind, id_set);
get_parent().lookup_rec(base_name, kind, id_set);
}

void cpp_scopet::lookup(
void cpp_scopet::lookup_rec(
const irep_idt &base_name,
lookup_kindt kind,
cpp_idt::id_classt id_class,
Expand Down Expand Up @@ -139,7 +140,7 @@ void cpp_scopet::lookup(

// Recursive call.
// Note the different kind!
other_scope.lookup(base_name, QUALIFIED, id_class, id_set);
other_scope.lookup_rec(base_name, QUALIFIED, id_class, id_set);
}

if(!id_set.empty() && id_class != id_classt::TEMPLATE)
Expand All @@ -155,7 +156,7 @@ void cpp_scopet::lookup(

// Recursive call.
// Note the different kind!
other_scope.lookup(base_name, QUALIFIED, id_class, id_set);
other_scope.lookup_rec(base_name, QUALIFIED, id_class, id_set);
}

if(kind==QUALIFIED)
Expand All @@ -166,14 +167,15 @@ void cpp_scopet::lookup(

// ask parent, recursive call
if(!is_root_scope())
get_parent().lookup(base_name, kind, id_class, id_set);
get_parent().lookup_rec(base_name, kind, id_class, id_set);
}

void cpp_scopet::lookup_identifier(
cpp_scopet::id_sett cpp_scopet::lookup_identifier(
const irep_idt &identifier,
cpp_idt::id_classt id_class,
id_sett &id_set)
cpp_idt::id_classt id_class)
{
id_sett id_set;

for(cpp_id_mapt::iterator n_it=sub.begin();
n_it!=sub.end(); n_it++)
{
Expand All @@ -195,6 +197,8 @@ void cpp_scopet::lookup_identifier(
id_set.insert(&parent);
}
#endif

return id_set;
}

cpp_scopet &cpp_scopet::new_scope(const irep_idt &new_scope_name)
Expand All @@ -208,10 +212,7 @@ cpp_scopet &cpp_scopet::new_scope(const irep_idt &new_scope_name)
return (cpp_scopet &)id;
}


bool cpp_scopet::contains(const irep_idt &base_name)
{
id_sett id_set;
lookup(base_name, SCOPE_ONLY, id_set);
return !id_set.empty();
return !lookup(base_name, SCOPE_ONLY).empty();
}
35 changes: 24 additions & 11 deletions src/cpp/cpp_scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,25 @@ class cpp_scopet:public cpp_idt

enum lookup_kindt { SCOPE_ONLY, QUALIFIED, RECURSIVE };

void lookup(
const irep_idt &base_name,
lookup_kindt kind,
id_sett &id_set);
id_sett lookup(const irep_idt &base_name, lookup_kindt kind)
{
id_sett result;
lookup_rec(base_name, kind, result);
return result;
}

void lookup(
id_sett lookup(
const irep_idt &base_name,
lookup_kindt kind,
cpp_idt::id_classt id_class,
id_sett &id_set);
cpp_idt::id_classt id_class)
{
id_sett result;
lookup_rec(base_name, kind, id_class, result);
return result;
}

void lookup_identifier(
const irep_idt &identifier,
cpp_idt::id_classt id_class,
id_sett &id_set);
id_sett
lookup_identifier(const irep_idt &identifier, cpp_idt::id_classt id_class);

cpp_idt &insert(const irep_idt &_base_name)
{
Expand Down Expand Up @@ -114,6 +118,15 @@ class cpp_scopet:public cpp_idt
}

class cpp_scopet &new_scope(const irep_idt &new_scope_name);

protected:
void lookup_rec(const irep_idt &base_name, lookup_kindt kind, id_sett &);

void lookup_rec(
const irep_idt &base_name,
lookup_kindt kind,
cpp_idt::id_classt id_class,
id_sett &);
};

class cpp_root_scopet:public cpp_scopet
Expand Down
10 changes: 4 additions & 6 deletions src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ cpp_scopet &cpp_typecheckt::tag_scope(
// Check if we have it already. If so, take it.

// we should only look for tags, but we don't
cpp_scopet::id_sett id_set;
cpp_scopes.current_scope().lookup(base_name, cpp_scopet::RECURSIVE, id_set);
const auto id_set =
cpp_scopes.current_scope().lookup(base_name, cpp_scopet::RECURSIVE);

for(const auto &id : id_set)
if(id->is_class())
Expand Down Expand Up @@ -816,10 +816,8 @@ void cpp_typecheckt::put_compound_into_scope(
else
{
// check if it's already there
cpp_scopest::id_sett id_set;

cpp_scopes.current_scope().lookup(
base_name, cpp_scopet::SCOPE_ONLY, id_set);
const auto id_set =
cpp_scopes.current_scope().lookup(base_name, cpp_scopet::SCOPE_ONLY);

for(const auto &id_it : id_set)
{
Expand Down
43 changes: 16 additions & 27 deletions src/cpp/cpp_typecheck_resolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,15 +914,12 @@ cpp_scopet &cpp_typecheck_resolvet::resolve_scope(
template_args=to_cpp_template_args_non_tc(*pos);
else if(pos->id()=="::")
{
cpp_scopest::id_sett id_set;

if(template_args.is_not_nil())
{
cpp_typecheck.cpp_scopes.current_scope().lookup(
const auto id_set = cpp_typecheck.cpp_scopes.current_scope().lookup(
final_base_name,
recursive?cpp_scopet::RECURSIVE:cpp_scopet::QUALIFIED,
cpp_idt::id_classt::TEMPLATE,
id_set);
recursive ? cpp_scopet::RECURSIVE : cpp_scopet::QUALIFIED,
cpp_idt::id_classt::TEMPLATE);

#ifdef DEBUG
std::cout << "S: "
Expand All @@ -946,10 +943,9 @@ cpp_scopet &cpp_typecheck_resolvet::resolve_scope(
}
else
{
cpp_typecheck.cpp_scopes.current_scope().lookup(
auto id_set = cpp_typecheck.cpp_scopes.current_scope().lookup(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

final_base_name,
recursive?cpp_scopet::RECURSIVE:cpp_scopet::QUALIFIED,
id_set);
recursive ? cpp_scopet::RECURSIVE : cpp_scopet::QUALIFIED);

filter_for_named_scopes(id_set);

Expand Down Expand Up @@ -1259,12 +1255,8 @@ cpp_scopet &cpp_typecheck_resolvet::resolve_namespace(
const source_locationt &source_location=cpp_name.source_location();
bool qualified=cpp_name.is_qualified();

cpp_scopest::id_sett id_set;

cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name,
qualified?cpp_scopet::QUALIFIED:cpp_scopet::RECURSIVE,
id_set);
auto id_set = cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name, qualified ? cpp_scopet::QUALIFIED : cpp_scopet::RECURSIVE);

filter_for_namespaces(id_set);

Expand Down Expand Up @@ -1442,8 +1434,8 @@ exprt cpp_typecheck_resolvet::resolve(

if(template_args.is_nil())
{
cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name, lookup_kind, id_set);
id_set =
cpp_typecheck.cpp_scopes.current_scope().lookup(base_name, lookup_kind);

if(id_set.empty() && !cpp_typecheck.builtin_factory(base_name))
{
Expand All @@ -1456,8 +1448,8 @@ exprt cpp_typecheck_resolvet::resolve(
}
}
else
cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name, lookup_kind, cpp_idt::id_classt::TEMPLATE, id_set);
id_set = cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name, lookup_kind, cpp_idt::id_classt::TEMPLATE);

// Argument-dependent name lookup
#if 0
Expand Down Expand Up @@ -1765,9 +1757,8 @@ void cpp_typecheck_resolvet::guess_template_args(
irep_idt base_name;
resolve_scope(cpp_name, base_name, template_args);

cpp_scopest::id_sett id_set;
cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name, cpp_scopet::RECURSIVE, id_set);
const auto id_set = cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name, cpp_scopet::RECURSIVE);

// alright, rummage through these
for(cpp_scopest::id_sett::const_iterator it=id_set.begin();
Expand Down Expand Up @@ -1855,9 +1846,8 @@ void cpp_typecheck_resolvet::guess_template_args(
cpp_template_args_non_tct template_args;
resolve_scope(cpp_name, base_name, template_args);

cpp_scopest::id_sett id_set;
cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name, cpp_scopet::RECURSIVE, id_set);
const auto id_set = cpp_typecheck.cpp_scopes.current_scope().lookup(
base_name, cpp_scopet::RECURSIVE);

// alright, rummage through these
for(cpp_scopest::id_sett::const_iterator
Expand Down Expand Up @@ -2412,10 +2402,9 @@ void cpp_typecheck_resolvet::resolve_with_arguments(
if(final_type.id()!=ID_struct && final_type.id()!=ID_union)
continue;

cpp_scopest::id_sett tmp_set;
cpp_scopet &scope=
cpp_typecheck.cpp_scopes.get_scope(final_type.get(ID_name));
scope.lookup(base_name, cpp_scopet::SCOPE_ONLY, tmp_set);
const auto tmp_set = scope.lookup(base_name, cpp_scopet::SCOPE_ONLY);
id_set.insert(tmp_set.begin(), tmp_set.end());
}
}
30 changes: 12 additions & 18 deletions src/cpp/cpp_typecheck_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ void cpp_typecheckt::typecheck_class_template(
// Check if the name is already used by a different template
// in the same scope.
{
cpp_scopet::id_sett id_set;
cpp_scopes.current_scope().lookup(
base_name,
cpp_scopet::SCOPE_ONLY,
cpp_scopet::TEMPLATE,
id_set);
const auto id_set=
cpp_scopes.current_scope().lookup(
base_name,
cpp_scopet::SCOPE_ONLY,
cpp_scopet::TEMPLATE);

if(!id_set.empty())
{
Expand Down Expand Up @@ -345,13 +344,10 @@ void cpp_typecheckt::typecheck_class_template_member(
}

// let's find the class template this function template belongs to.
cpp_scopet::id_sett id_set;

cpp_scopes.current_scope().lookup(
const auto id_set = cpp_scopes.current_scope().lookup(
cpp_name.get_sub().front().get(ID_identifier),
cpp_scopet::SCOPE_ONLY, // look only in current scope
cpp_scopet::id_classt::TEMPLATE, // must be template
id_set);
cpp_scopet::SCOPE_ONLY, // look only in current scope
cpp_scopet::id_classt::TEMPLATE); // must be template

if(id_set.empty())
{
Expand Down Expand Up @@ -539,9 +535,8 @@ void cpp_typecheckt::convert_class_template_specialization(

// get the template symbol

cpp_scopest::id_sett id_set;
cpp_scopes.current_scope().lookup(
base_name, cpp_scopet::SCOPE_ONLY, cpp_idt::id_classt::TEMPLATE, id_set);
auto id_set = cpp_scopes.current_scope().lookup(
base_name, cpp_scopet::SCOPE_ONLY, cpp_idt::id_classt::TEMPLATE);

// remove any specializations
for(cpp_scopest::id_sett::iterator
Expand Down Expand Up @@ -656,9 +651,8 @@ void cpp_typecheckt::convert_template_function_or_member_specialization(
std::string base_name=
cpp_name.get_sub()[0].get(ID_identifier).c_str();

cpp_scopest::id_sett id_set;
cpp_scopes.current_scope().lookup(
base_name, cpp_scopet::SCOPE_ONLY, id_set);
const auto id_set =
cpp_scopes.current_scope().lookup(base_name, cpp_scopet::SCOPE_ONLY);

if(id_set.empty())
{
Expand Down
5 changes: 2 additions & 3 deletions src/cpp/cpp_typecheck_using.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ void cpp_typecheckt::convert(cpp_usingt &cpp_using)
resolver.resolve_scope(cpp_using.name(), base_name, template_args);

bool qualified=cpp_using.name().is_qualified();
cpp_scopest::id_sett id_set;

cpp_scopes.current_scope().lookup(
base_name, qualified?cpp_scopet::QUALIFIED:cpp_scopet::RECURSIVE, id_set);
const auto id_set = cpp_scopes.current_scope().lookup(
base_name, qualified ? cpp_scopet::QUALIFIED : cpp_scopet::RECURSIVE);

bool using_directive=cpp_using.get_namespace();

Expand Down