@@ -181,69 +181,80 @@ static void output_single_property_plain(
181
181
<< messaget::eom;
182
182
}
183
183
184
+ using propertyt = std::pair<irep_idt, property_infot>;
185
+ // / Compare two properties according to the following sort:
186
+ // / 1. alphabetical ordering of file name
187
+ // / 2. alphabetical ordering of function name
188
+ // / 3. numerical ordering of line number
189
+ // / 4. alphabetical ordering of goal ID
190
+ // / 5. number ordering of the goal ID number
191
+ // / \param property1: The first property.
192
+ // / \param property2: The second propery.
193
+ // / \return True if the first property is less than the second property
194
+ static bool
195
+ is_property_less_than (const propertyt &property1, const propertyt &property2)
196
+ {
197
+ const auto &p1 = property1.second .pc ->source_location ;
198
+ const auto &p2 = property2.second .pc ->source_location ;
199
+ if (p1.get_file () != p2.get_file ())
200
+ return id2string (p1.get_file ()) < id2string (p2.get_file ());
201
+ if (p1.get_function () != p2.get_function ())
202
+ return id2string (p1.get_function ()) < id2string (p2.get_function ());
203
+ else if (
204
+ !p1.get_line ().empty () && !p2.get_line ().empty () &&
205
+ p1.get_line () != p2.get_line ())
206
+ return std::stoul (id2string (p1.get_line ())) <
207
+ std::stoul (id2string (p2.get_line ()));
208
+
209
+ const auto split_property_id =
210
+ [](const irep_idt &property_id) -> std::pair<std::string, std::size_t > {
211
+ const auto property_string = id2string (property_id);
212
+ const auto last_dot = property_string.rfind (' .' );
213
+ std::string property_name;
214
+ std::string property_number;
215
+ if (last_dot == std::string::npos)
216
+ {
217
+ property_name = " " ;
218
+ property_number = property_string;
219
+ }
220
+ else
221
+ {
222
+ property_name = property_string.substr (0 , last_dot);
223
+ property_number = property_string.substr (last_dot + 1 );
224
+ }
225
+ const auto maybe_number = string2optional_size_t (property_number);
226
+ if (maybe_number.has_value ())
227
+ return std::make_pair (property_name, *maybe_number);
228
+ else
229
+ return std::make_pair (property_name, 0 );
230
+ };
231
+
232
+ const auto left_split = split_property_id (property1.first );
233
+ const auto left_id_name = left_split.first ;
234
+ const auto left_id_number = left_split.second ;
235
+
236
+ const auto right_split = split_property_id (property2.first );
237
+ const auto right_id_name = right_split.first ;
238
+ const auto right_id_number = right_split.second ;
239
+
240
+ if (left_id_name != right_id_name)
241
+ return left_id_name < right_id_name;
242
+ else
243
+ return left_id_number < right_id_number;
244
+ }
245
+
184
246
static std::vector<propertiest::const_iterator>
185
247
get_sorted_properties (const propertiest &properties)
186
248
{
187
249
std::vector<propertiest::const_iterator> sorted_properties;
188
250
for (auto p_it = properties.begin (); p_it != properties.end (); p_it++)
189
251
sorted_properties.push_back (p_it);
190
- // now determine an ordering for those goals:
191
- // 1. alphabetical ordering of file name
192
- // 2. alphabetical ordering of function name
193
- // 3. numerical ordering of line number
194
- // 4. alphabetical ordering of goal ID
195
- // 5. number ordering of the goal ID number
252
+
196
253
std::sort (
197
254
sorted_properties.begin (),
198
255
sorted_properties.end (),
199
256
[](propertiest::const_iterator pit1, propertiest::const_iterator pit2) {
200
- const auto &p1 = pit1->second .pc ->source_location ;
201
- const auto &p2 = pit2->second .pc ->source_location ;
202
- if (p1.get_file () != p2.get_file ())
203
- return id2string (p1.get_file ()) < id2string (p2.get_file ());
204
- if (p1.get_function () != p2.get_function ())
205
- return id2string (p1.get_function ()) < id2string (p2.get_function ());
206
- else if (
207
- !p1.get_line ().empty () && !p2.get_line ().empty () &&
208
- p1.get_line () != p2.get_line ())
209
- return std::stoul (id2string (p1.get_line ())) <
210
- std::stoul (id2string (p2.get_line ()));
211
-
212
- const auto split_property_id =
213
- [](const irep_idt &property_id) -> std::pair<std::string, std::size_t > {
214
- const auto property_string = id2string (property_id);
215
- const auto last_dot = property_string.rfind (' .' );
216
- std::string property_name;
217
- std::string property_number;
218
- if (last_dot == std::string::npos)
219
- {
220
- property_name = " " ;
221
- property_number = property_string;
222
- }
223
- else
224
- {
225
- property_name = property_string.substr (0 , last_dot);
226
- property_number = property_string.substr (last_dot + 1 );
227
- }
228
- const auto maybe_number = string2optional_size_t (property_number);
229
- if (maybe_number.has_value ())
230
- return std::make_pair (property_name, *maybe_number);
231
- else
232
- return std::make_pair (property_name, 0 );
233
- };
234
-
235
- const auto left_split = split_property_id (pit1->first );
236
- const auto left_id_name = left_split.first ;
237
- const auto left_id_number = left_split.second ;
238
-
239
- const auto right_split = split_property_id (pit2->first );
240
- const auto right_id_name = left_split.first ;
241
- const auto right_id_number = left_split.second ;
242
-
243
- if (left_id_name != right_id_name)
244
- return left_id_name < right_id_name;
245
- else
246
- return left_id_number < right_id_number;
257
+ return is_property_less_than (*pit1, *pit2);
247
258
});
248
259
return sorted_properties;
249
260
}
0 commit comments