@@ -11,6 +11,10 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1111
1212#include " cpp_typecheck.h"
1313
14+ #ifdef DEBUG
15+ #include < iostream>
16+ #endif
17+
1418#include < util/arith_tools.h>
1519#include < util/base_exceptions.h>
1620#include < util/simplify_expr.h>
@@ -220,6 +224,10 @@ const symbolt &cpp_typecheckt::instantiate_template(
220224 const cpp_template_args_tct &full_template_args,
221225 const typet &specialization)
222226{
227+ #ifdef DEBUG
228+ std::cout << " instantiate_template: " << template_symbol.name << std::endl;
229+ #endif
230+
223231 if (instantiation_stack.size ()==MAX_DEPTH)
224232 {
225233 error ().source_location =source_location;
@@ -233,10 +241,10 @@ const symbolt &cpp_typecheckt::instantiate_template(
233241 instantiation_stack.back ().identifier =template_symbol.name ;
234242 instantiation_stack.back ().full_template_args =full_template_args;
235243
236- # if 0
244+ # ifdef DEBUG
237245 std::cout << " L: " << source_location << ' \n ' ;
238246 std::cout << " I: " << template_symbol.name << ' \n ' ;
239- #endif
247+ #endif
240248
241249 cpp_save_scopet cpp_saved_scope (cpp_scopes);
242250 cpp_saved_template_mapt saved_map (template_map);
@@ -247,7 +255,7 @@ const symbolt &cpp_typecheckt::instantiate_template(
247255 assert (!specialization_template_args.has_unassigned ());
248256 assert (!full_template_args.has_unassigned ());
249257
250- # if 0
258+ # ifdef DEBUG
251259 std::cout << " A: <" ;
252260 forall_expr (it, specialization_template_args.arguments ())
253261 {
@@ -258,8 +266,8 @@ const symbolt &cpp_typecheckt::instantiate_template(
258266 else
259267 std::cout << to_string (*it);
260268 }
261- std::cout << ">\n";
262- #endif
269+ std::cout << " >\n\n " ;
270+ #endif
263271
264272 // do we have arguments?
265273 if (full_template_args.arguments ().empty ())
@@ -377,8 +385,8 @@ const symbolt &cpp_typecheckt::instantiate_template(
377385 instantiated_with.get_sub ().push_back (specialization_template_args);
378386 }
379387
380- #if 0
381- std::cout << "MAP:\n" ;
388+ #ifdef DEBUG
389+ std::cout << " CLASS MAP:" << std::endl ;
382390 template_map.print (std::cout);
383391 #endif
384392
@@ -436,15 +444,29 @@ const symbolt &cpp_typecheckt::instantiate_template(
436444
437445 // mapping from template arguments to values/types
438446 template_map.build (method_type, specialization_template_args);
447+ #ifdef DEBUG
448+ std::cout << " METHOD MAP:" << std::endl;
449+ template_map.print (std::cout);
450+ #endif
439451
440452 method_decl.remove (ID_template_type);
441453 method_decl.remove (ID_is_template);
442454
443455 convert (method_decl);
444456 }
445457
446- const symbolt &new_symb=
447- lookup (new_decl.type ().get (ID_identifier));
458+ const irep_idt& new_symb_id = new_decl.type ().get (ID_identifier);
459+ symbolt &new_symb = symbol_table.get_writeable_ref (new_symb_id);
460+
461+ // add template arguments to type in order to retrieve template map
462+ // when typechecking function body
463+ new_symb.type .set (ID_C_template, template_type);
464+ new_symb.type .set (ID_C_template_arguments, specialization_template_args);
465+
466+ #ifdef DEBUG
467+ std::cout << " instance symbol: " << new_symb.name << std::endl << std::endl;
468+ std::cout << " template type: " << template_type << std::endl << std::endl;
469+ #endif
448470
449471 return new_symb;
450472 }
0 commit comments