@@ -172,6 +172,45 @@ SymbolMap kore_definition::get_overloads() const {
172
172
return transitive_closure (overloads);
173
173
}
174
174
175
+ static void process_sort_ordinal (
176
+ kore_sort *sort,
177
+ std::unordered_map<kore_composite_sort, uint32_t , hash_sort> &sorts,
178
+ std::vector<kore_composite_sort *> &all_sorts, uint32_t &next_sort) {
179
+ // We use a work list to ensure that parametric sorts get ordinals
180
+ // that are greater than the ordinals of any of their parameters.
181
+ // This invariant is usefull for serialization purposes, and given
182
+ // that all parametric sorts are statically known, it is sound to
183
+ // assign ordinals to them in such a topological order.
184
+ std::stack<std::pair<kore_composite_sort *, bool >> worklist;
185
+ auto *ctr = dynamic_cast <kore_composite_sort *>(sort);
186
+ worklist.push (std::make_pair (ctr, false ));
187
+
188
+ while (!worklist.empty ()) {
189
+ auto *sort_to_process = worklist.top ().first ;
190
+ bool params_processed = worklist.top ().second ;
191
+ worklist.pop ();
192
+
193
+ if (!sorts.contains (*sort_to_process)) {
194
+ if (!params_processed) {
195
+ // Defer processing this sort until its parameter sorts have
196
+ // been processed.
197
+ worklist.push (std::make_pair (sort_to_process, true ));
198
+ for (auto const ¶m_sort : sort_to_process->get_arguments ()) {
199
+ auto *param_ctr
200
+ = dynamic_cast <kore_composite_sort *>(param_sort.get ());
201
+ worklist.push (std::make_pair (param_ctr, false ));
202
+ }
203
+ continue ;
204
+ }
205
+
206
+ sorts.emplace (*sort_to_process, next_sort++);
207
+ all_sorts.push_back (sort_to_process);
208
+ }
209
+
210
+ sort_to_process->set_ordinal (sorts[*sort_to_process]);
211
+ }
212
+ }
213
+
175
214
// NOLINTNEXTLINE(*-function-cognitive-complexity)
176
215
void kore_definition::preprocess () {
177
216
get_subsorts ();
@@ -286,40 +325,11 @@ void kore_definition::preprocess() {
286
325
for (auto *symbol : entry.second ) {
287
326
if (symbol->is_concrete ()) {
288
327
for (auto const &sort : symbol->get_arguments ()) {
289
- // We use a work list to ensure that parametric sorts get ordinals
290
- // that are greater than the ordinals of any of their parameters.
291
- // This invariant is usefull for serialization purposes, and given
292
- // that all parametric sorts are statically known, it is sound to
293
- // assign ordinals to them in such a topological order.
294
- std::stack<std::pair<kore_composite_sort *, bool >> worklist;
295
- auto *ctr = dynamic_cast <kore_composite_sort *>(sort.get ());
296
- worklist.push (std::make_pair (ctr, false ));
297
-
298
- while (!worklist.empty ()) {
299
- auto *sort_to_process = worklist.top ().first ;
300
- bool params_processed = worklist.top ().second ;
301
- worklist.pop ();
302
-
303
- if (!sorts.contains (*sort_to_process)) {
304
- if (!params_processed) {
305
- // Defer processing this sort until its parameter sorts have
306
- // been processed.
307
- worklist.push (std::make_pair (sort_to_process, true ));
308
- for (auto const ¶m_sort :
309
- sort_to_process->get_arguments ()) {
310
- auto *param_ctr
311
- = dynamic_cast <kore_composite_sort *>(param_sort.get ());
312
- worklist.push (std::make_pair (param_ctr, false ));
313
- }
314
- continue ;
315
- }
316
-
317
- sorts.emplace (*sort_to_process, next_sort++);
318
- all_sorts_.push_back (sort_to_process);
319
- }
320
-
321
- sort_to_process->set_ordinal (sorts[*sort_to_process]);
322
- }
328
+ process_sort_ordinal (sort.get (), sorts, all_sorts_, next_sort);
329
+ }
330
+ if (symbol->get_sort ()->is_concrete ()) {
331
+ process_sort_ordinal (
332
+ symbol->get_sort ().get (), sorts, all_sorts_, next_sort);
323
333
}
324
334
if (!instantiations.contains (*symbol)) {
325
335
instantiations.emplace (*symbol, next_symbol++);
0 commit comments