@@ -110,6 +110,40 @@ void cpp_typecheckt::show_instantiation_stack(std::ostream &out)
110
110
}
111
111
}
112
112
113
+ // / Set up a scope as subscope of the template scope
114
+ cpp_scopet &cpp_typecheckt::sub_scope_for_instantiation (
115
+ cpp_scopet &template_scope,
116
+ const std::string &suffix)
117
+ {
118
+ cpp_scopet::id_sett id_set;
119
+ template_scope.lookup (suffix, cpp_scopet::SCOPE_ONLY, id_set);
120
+
121
+ CHECK_RETURN (id_set.size () <= 1 );
122
+
123
+ if (id_set.size () == 1 )
124
+ {
125
+ cpp_idt &cpp_id = **id_set.begin ();
126
+ CHECK_RETURN (cpp_id.is_template_scope ());
127
+
128
+ return static_cast <cpp_scopet &>(cpp_id);
129
+ }
130
+ else
131
+ {
132
+ cpp_scopet &sub_scope = template_scope.new_scope (suffix);
133
+ sub_scope.id_class = cpp_idt::id_classt::TEMPLATE_SCOPE;
134
+ sub_scope.prefix = template_scope.get_parent ().prefix ;
135
+ sub_scope.suffix = suffix;
136
+ sub_scope.add_using_scope (template_scope.get_parent ());
137
+
138
+ const std::string subscope_name =
139
+ id2string (template_scope.identifier ) + suffix;
140
+ cpp_scopes.id_map .insert (
141
+ cpp_scopest::id_mapt::value_type (subscope_name, &sub_scope));
142
+
143
+ return sub_scope;
144
+ }
145
+ }
146
+
113
147
const symbolt &cpp_typecheckt::class_template_symbol (
114
148
const source_locationt &source_location,
115
149
const symbolt &template_symbol,
@@ -173,7 +207,8 @@ const symbolt &cpp_typecheckt::class_template_symbol(
173
207
symbol_table.move (new_symbol, s_ptr);
174
208
175
209
// put into template scope
176
- cpp_idt &id=cpp_scopes.put_into_scope (*s_ptr, *template_scope);
210
+ cpp_scopet &sub_scope = sub_scope_for_instantiation (*template_scope, suffix);
211
+ cpp_idt &id = cpp_scopes.put_into_scope (*s_ptr, sub_scope);
177
212
178
213
id.id_class =cpp_idt::id_classt::CLASS;
179
214
id.is_scope =true ;
@@ -325,18 +360,12 @@ const symbolt &cpp_typecheckt::instantiate_template(
325
360
class_name=cpp_scopes.current_scope ().get_parent ().identifier ;
326
361
327
362
// sub-scope for fixing the prefix
328
- std::string subscope_name= id2string ( template_scope-> identifier )+ suffix;
363
+ cpp_scopet &sub_scope = sub_scope_for_instantiation (* template_scope, suffix) ;
329
364
330
365
// let's see if we have the instance already
331
- cpp_scopest::id_mapt::iterator scope_it=
332
- cpp_scopes.id_map .find (subscope_name);
333
-
334
- if (scope_it!=cpp_scopes.id_map .end ())
335
366
{
336
- cpp_scopet &scope=cpp_scopes.get_scope (subscope_name);
337
-
338
367
cpp_scopet::id_sett id_set;
339
- scope .lookup (template_symbol.base_name , cpp_scopet::SCOPE_ONLY, id_set);
368
+ sub_scope .lookup (template_symbol.base_name , cpp_scopet::SCOPE_ONLY, id_set);
340
369
341
370
if (id_set.size ()==1 )
342
371
{
@@ -356,20 +385,7 @@ const symbolt &cpp_typecheckt::instantiate_template(
356
385
return symb;
357
386
}
358
387
359
- cpp_scopes.go_to (scope);
360
- }
361
- else
362
- {
363
- // set up a scope as subscope of the template scope
364
- cpp_scopet &sub_scope=
365
- cpp_scopes.current_scope ().new_scope (subscope_name);
366
- sub_scope.id_class =cpp_idt::id_classt::TEMPLATE_SCOPE;
367
- sub_scope.prefix =template_scope->get_parent ().prefix ;
368
- sub_scope.suffix =suffix;
369
- sub_scope.add_using_scope (template_scope->get_parent ());
370
388
cpp_scopes.go_to (sub_scope);
371
- cpp_scopes.id_map .insert (
372
- cpp_scopest::id_mapt::value_type (subscope_name, &sub_scope));
373
389
}
374
390
375
391
// store the information that the template has
0 commit comments