11
11
12
12
#include " cpp_typecheck.h"
13
13
14
+ #ifdef DEBUG
15
+ #include < iostream>
16
+ #endif
17
+
14
18
#include < util/arith_tools.h>
15
19
#include < util/base_exceptions.h>
16
20
#include < util/simplify_expr.h>
@@ -220,6 +224,10 @@ const symbolt &cpp_typecheckt::instantiate_template(
220
224
const cpp_template_args_tct &full_template_args,
221
225
const typet &specialization)
222
226
{
227
+ #ifdef DEBUG
228
+ std::cout << " instantiate_template: " << template_symbol.name << std::endl;
229
+ #endif
230
+
223
231
if (instantiation_stack.size ()==MAX_DEPTH)
224
232
{
225
233
error ().source_location =source_location;
@@ -233,10 +241,10 @@ const symbolt &cpp_typecheckt::instantiate_template(
233
241
instantiation_stack.back ().identifier =template_symbol.name ;
234
242
instantiation_stack.back ().full_template_args =full_template_args;
235
243
236
- # if 0
244
+ # ifdef DEBUG
237
245
std::cout << " L: " << source_location << ' \n ' ;
238
246
std::cout << " I: " << template_symbol.name << ' \n ' ;
239
- #endif
247
+ #endif
240
248
241
249
cpp_save_scopet cpp_saved_scope (cpp_scopes);
242
250
cpp_saved_template_mapt saved_map (template_map);
@@ -247,7 +255,7 @@ const symbolt &cpp_typecheckt::instantiate_template(
247
255
assert (!specialization_template_args.has_unassigned ());
248
256
assert (!full_template_args.has_unassigned ());
249
257
250
- # if 0
258
+ # ifdef DEBUG
251
259
std::cout << " A: <" ;
252
260
forall_expr (it, specialization_template_args.arguments ())
253
261
{
@@ -258,8 +266,8 @@ const symbolt &cpp_typecheckt::instantiate_template(
258
266
else
259
267
std::cout << to_string (*it);
260
268
}
261
- std::cout << ">\n";
262
- #endif
269
+ std::cout << " >\n\n " ;
270
+ #endif
263
271
264
272
// do we have arguments?
265
273
if (full_template_args.arguments ().empty ())
@@ -377,8 +385,8 @@ const symbolt &cpp_typecheckt::instantiate_template(
377
385
instantiated_with.get_sub ().push_back (specialization_template_args);
378
386
}
379
387
380
- #if 0
381
- std::cout << "MAP:\n" ;
388
+ #ifdef DEBUG
389
+ std::cout << " CLASS MAP:" << std::endl ;
382
390
template_map.print (std::cout);
383
391
#endif
384
392
@@ -436,15 +444,29 @@ const symbolt &cpp_typecheckt::instantiate_template(
436
444
437
445
// mapping from template arguments to values/types
438
446
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
439
451
440
452
method_decl.remove (ID_template_type);
441
453
method_decl.remove (ID_is_template);
442
454
443
455
convert (method_decl);
444
456
}
445
457
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
448
470
449
471
return new_symb;
450
472
}
0 commit comments