Skip to content

Commit 6718725

Browse files
author
kroening
committed
more template fixes
git-svn-id: svn+ssh://svn.cprover.org/srv/svn/cbmc/trunk@116 6afb6bc1-c8e4-404c-8f48-9ae832c5b171
1 parent 52b9d78 commit 6718725

File tree

3 files changed

+182
-148
lines changed

3 files changed

+182
-148
lines changed

src/cpp/cpp_typecheck.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,16 @@ class cpp_typecheckt:public c_typecheck_baset
151151

152152
void typecheck_template_class(cpp_declarationt &declaration);
153153

154-
void typecheck_template_function(cpp_declarationt &declaration);
154+
void typecheck_function_template(cpp_declarationt &declaration);
155+
156+
void typecheck_template_member_function(cpp_declarationt &declaration);
155157

156158
std::string template_class_identifier(
157159
const irep_idt &base_name,
158160
const template_typet &template_type,
159161
const cpp_template_args_non_tct &partial_specialization_args);
160162

161-
std::string template_function_identifier(
163+
std::string function_template_identifier(
162164
const irep_idt &base_name,
163165
const template_typet &template_type,
164166
const typet &function_type);

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,10 @@ void cpp_typecheck_resolvet::resolve_scope(
987987
recursive?cpp_scopet::RECURSIVE:cpp_scopet::QUALIFIED,
988988
cpp_idt::TEMPLATE,
989989
id_set);
990+
991+
// std::cout << "S: " << cpp_typecheck.cpp_scopes.current_scope().identifier << std::endl;
992+
// cpp_typecheck.cpp_scopes.current_scope().print(std::cout);
993+
// std::cout << "X: " << id_set.size() <<std::endl;
990994

991995
const symbolt &symb_tmpl=
992996
disambiguate_template_classes(base_name, id_set, template_args);
@@ -1002,7 +1006,7 @@ void cpp_typecheck_resolvet::resolve_scope(
10021006
base_name,
10031007
recursive?cpp_scopet::RECURSIVE:cpp_scopet::QUALIFIED,
10041008
id_set);
1005-
1009+
10061010
filter_for_named_scopes(id_set);
10071011

10081012
if(id_set.empty())
@@ -1081,7 +1085,8 @@ const symbolt &cpp_typecheck_resolvet::disambiguate_template_classes(
10811085
{
10821086
cpp_typecheck.show_instantiation_stack(cpp_typecheck.str);
10831087
cpp_typecheck.err_location(location);
1084-
cpp_typecheck.str << "template scope `" << base_name << "' not found";
1088+
cpp_typecheck.str << "template scope `"
1089+
<< base_name << "' not found";
10851090
throw 0;
10861091
}
10871092

@@ -2444,22 +2449,30 @@ void cpp_typecheck_resolvet::filter_for_named_scopes(
24442449
}
24452450
else if(id.id_class==cpp_scopet::TEMPLATE_ARGUMENT)
24462451
{
2447-
// maybe it is a scope
2448-
exprt e = cpp_typecheck.template_map.lookup(id.identifier);
2449-
2450-
if(e.id() != ID_type)
2451-
continue; // it's definitively not a scope
2452+
// a template argument may be a scope: it could
2453+
// be instantiated with a class/struct
2454+
exprt e=cpp_typecheck.template_map.lookup(id.identifier);
2455+
2456+
if(e.id()!=ID_type)
2457+
continue; // expressions are definitively not a scope
24522458

2453-
if(e.type().id() == ID_symbol)
2459+
if(e.type().id()==ID_symbol)
24542460
{
2455-
irep_idt identifier=e.type().get(ID_identifier);
2461+
symbol_typet type=to_symbol_type(e.type());
24562462

24572463
while(true)
24582464
{
2465+
irep_idt identifier=type.get_identifier();
2466+
24592467
const symbolt &symbol=cpp_typecheck.lookup(identifier);
24602468
assert(symbol.is_type);
2461-
2462-
if(symbol.type.id()==ID_struct)
2469+
2470+
if(symbol.type.id()==ID_symbol)
2471+
type=to_symbol_type(symbol.type);
2472+
else if(symbol.type.id()==ID_struct ||
2473+
symbol.type.id()==ID_incomplete_struct ||
2474+
symbol.type.id()==ID_union ||
2475+
symbol.type.id()==ID_incomplete_union)
24632476
{
24642477
// this is a scope, too!
24652478
cpp_idt &class_id=
@@ -2469,9 +2482,7 @@ void cpp_typecheck_resolvet::filter_for_named_scopes(
24692482
new_set.insert(&class_id);
24702483
break;
24712484
}
2472-
else if(symbol.type.id()==ID_symbol)
2473-
identifier=symbol.type.get(ID_identifier);
2474-
else
2485+
else // give up
24752486
break;
24762487
}
24772488
}

0 commit comments

Comments
 (0)