53 LOG_DBG(
"Skipping empty call from '{}' to '{}'", m.
from(), m.
to());
66 const auto &f =
dynamic_cast<const model::method &
>(to.value());
67 const std::string_view style = f.
is_static() ?
"__" :
"";
69 fmt::format(
"{}{}{}", style, f.message_name(render_mode), style);
71 else if (
config().combine_free_functions_into_file_participants()) {
72 if (to.value().
type_name() ==
"function") {
76 if (f.is_cuda_kernel())
78 else if (f.is_cuda_device())
81 else if (to.value().
type_name() ==
"function_template") {
85 if (f.is_cuda_kernel())
87 else if (f.is_cuda_device())
101 ostr << from_alias <<
" "
106 if (
config().generate_links) {
137 if (to.has_value() && !to.value().is_void()) {
142 ostr << to_alias <<
" "
144 <<
" " << from_alias;
146 if (
config().generate_return_types()) {
155 const activity &a, std::ostream &ostr, std::vector<eid_t> &visited)
const
157 for (
const auto &m : a.
messages()) {
158 if (m.in_static_declaration_context()) {
165 if (m.type() == message_t::kCall) {
169 visited.push_back(m.from());
171 LOG_DBG(
"Generating message [{}] --> [{}]", m.from(), m.to());
177 ostr <<
"activate " << to_alias <<
'\n';
179 if (
model().sequences().find(m.to()) !=
model().sequences().end()) {
180 if (std::find(visited.begin(), visited.end(), m.to()) ==
183 LOG_DBG(
"Creating activity {} --> {} - missing sequence {}",
184 m.from(), m.to(), m.to());
186 model().get_activity(m.to()), ostr, visited);
190 LOG_DBG(
"Skipping activity {} --> {} - missing sequence {}",
191 m.from(), m.to(), m.to());
195 ostr <<
"deactivate " << to_alias <<
'\n';
199 else if (m.type() == message_t::kIf) {
203 if (
const auto &text = m.condition_text(); text.has_value())
204 ostr <<
" " << text.value();
207 else if (m.type() == message_t::kElseIf) {
210 if (
const auto &text = m.condition_text(); text.has_value())
211 ostr <<
" " << text.value();
214 else if (m.type() == message_t::kElse) {
218 else if (m.type() == message_t::kIfEnd) {
221 else if (m.type() == message_t::kWhile) {
225 if (
const auto &text = m.condition_text(); text.has_value())
226 ostr <<
" " << text.value();
229 else if (m.type() == message_t::kWhileEnd) {
232 else if (m.type() == message_t::kFor) {
236 if (
const auto &text = m.condition_text(); text.has_value())
237 ostr <<
" " << text.value();
240 else if (m.type() == message_t::kForEnd) {
243 else if (m.type() == message_t::kDo) {
247 if (
const auto &text = m.condition_text(); text.has_value())
248 ostr <<
" " << text.value();
251 else if (m.type() == message_t::kDoEnd) {
254 else if (m.type() == message_t::kTry) {
257 ostr <<
"group try\n";
259 else if (m.type() == message_t::kCatch) {
261 ostr <<
"else " << m.message_name() <<
'\n';
263 else if (m.type() == message_t::kTryEnd) {
267 else if (m.type() == message_t::kSwitch) {
270 ostr <<
"group switch\n";
272 else if (m.type() == message_t::kCase) {
274 ostr <<
"else " << m.message_name() <<
'\n';
276 else if (m.type() == message_t::kSwitchEnd) {
279 else if (m.type() == message_t::kConditional) {
283 if (
const auto &text = m.condition_text(); text.has_value())
284 ostr <<
" " << text.value();
287 else if (m.type() == message_t::kConditionalElse) {
291 else if (m.type() == message_t::kConditionalEnd) {
305 bool comment_generated_from_note_decorators{
false};
306 for (
const auto &decorator : m.
decorators()) {
307 auto note = std::dynamic_pointer_cast<decorators::note>(decorator);
308 if (note && note->applies_to_diagram(
config().name)) {
309 comment_generated_from_note_decorators =
true;
314 note->text,
config().message_comment_width())
317 ostr <<
"end note" <<
'\n';
321 if (comment_generated_from_note_decorators)
324 if (!
config().generate_message_comments())
328 if (
const auto &comment = m.
comment(); comment &&
334 config().message_comment_width())
337 ostr <<
"end note" <<
'\n';
342 std::ostream &ostr,
const std::string &name)
const
344 auto p =
model().get(name);
346 if (!p.has_value()) {
347 LOG_WARN(
"Cannot find participant {} from `participants_order` "
357 std::ostream &ostr,
eid_t id,
bool force)
const
359 eid_t participant_id{};
362 for (
const auto pid :
model().active_participants()) {
364 participant_id = pid;
372 if (participant_id == 0)
378 const auto &participant =
381 if (participant.type_name() ==
"method") {
382 const auto class_id =
391 const auto &class_participant =
396 auto participant_name =
397 config().simplify_template_type(class_participant.full_name(
false));
399 config().using_namespace().relative(participant_name);
403 ostr <<
"participant \"" <<
render_name(participant_name) <<
"\" as "
404 << class_participant.alias();
406 if (
config().generate_links) {
408 ostr, class_participant);
415 else if ((participant.type_name() ==
"function" ||
416 participant.type_name() ==
"function_template") &&
417 config().combine_free_functions_into_file_participants()) {
420 const auto &file_path =
426 assert(!file_path.empty());
434 std::filesystem::path{file_path},
config().root_directory())
437 ostr <<
"participant \"" <<
render_name(participant_name) <<
"\" as "
438 << fmt::format(
"C_{:022}", file_id.value());
447 auto participant_name =
config().using_namespace().relative(
448 config().simplify_template_type(participant.full_name(
false)));
451 ostr <<
"participant \"" <<
render_name(participant_name) <<
"\" as "
452 << participant.alias();
454 if (
const auto *function_ptr =
457 if (function_ptr->is_cuda_kernel())
458 ostr <<
" << CUDA Kernel >>";
459 else if (function_ptr->is_cuda_device())
460 ostr <<
" << CUDA Device >>";
463 if (
config().generate_links) {
484 if ((participant.
type_name() ==
"function" ||
485 participant.
type_name() ==
"function_template") &&
486 config().combine_free_functions_into_file_participants()) {
489 return fmt::format(
"C_{:022}", file_id.value());
492 return participant.
alias();
499 if (
config().participants_order.has_value) {
500 for (
const auto &p :
config().participants_order()) {
501 LOG_DBG(
"Pregenerating participant {}", p);
506 for (
const auto &ft :
config().from_to()) {
509 assert(ft.size() == 2);
511 const auto &from_location = ft.front();
512 const auto &to_location = ft.back();
514 auto from_activity_id =
model().get_from_activity_id(from_location);
515 auto to_activity_id =
model().get_to_activity_id(to_location);
517 if (!from_activity_id || !to_activity_id)
520 if (
model().participants().count(*from_activity_id) == 0)
523 if (
model().participants().count(*to_activity_id) == 0)
526 auto message_chains_unique =
model().get_all_from_to_message_chains(
527 *from_activity_id, *to_activity_id);
529 bool first_separator_skipped{
false};
530 for (
const auto &mc : message_chains_unique) {
531 if (!first_separator_skipped)
532 first_separator_skipped =
true;
539 if (from.value().type_name() ==
"method" ||
540 config().combine_free_functions_into_file_participants()) {
544 << from.value().message_name(
549 for (
const auto &m : mc) {
555 for (
const auto &to_location :
config().to()) {
556 auto to_activity_id =
model().get_to_activity_id(to_location);
561 auto message_chains_unique =
562 model().get_all_from_to_message_chains(
eid_t{}, *to_activity_id);
564 bool first_separator_skipped{
false};
565 for (
const auto &mc : message_chains_unique) {
566 if (!first_separator_skipped)
567 first_separator_skipped =
true;
571 const auto from_activity_id = mc.front().from();
573 if (
model().participants().count(from_activity_id) == 0)
579 if (from.value().type_name() ==
"method" ||
580 config().combine_free_functions_into_file_participants()) {
584 << from.value().message_name(
589 for (
const auto &m : mc) {
595 for (
const auto &sf :
config().from()) {
596 if (sf.location_type == location_t::function) {
598 for (
const auto &[k, v] :
model().sequences()) {
599 if (
model().participants().count(v.from()) == 0)
602 const auto &caller = *
model().participants().at(v.from());
603 std::string vfrom = caller.full_name(
false);
604 if (vfrom == sf.location) {
605 LOG_DBG(
"Found sequence diagram start point: {}", k);
611 if (start_from == 0) {
612 LOG_WARN(
"Failed to find participant with {} for start_from "
618 if (
model().participants().count(start_from) == 0)
622 std::vector<eid_t> visited_participants;
627 if (!from.has_value()) {
628 LOG_WARN(
"Failed to find participant {} for start_from "
645 if (from.value().type_name() ==
"method" ||
646 config().combine_free_functions_into_file_participants()) {
648 <<
" " << from_alias <<
" : "
649 << from.value().message_name(render_mode) <<
'\n';
652 ostr <<
"activate " << from_alias <<
'\n';
655 model().get_activity(start_from), ostr, visited_participants);
657 if (from.value().type_name() ==
"method" ||
658 config().combine_free_functions_into_file_participants()) {
660 if (!from.value().is_void()) {
662 <<
" " << from_alias;
664 if (
config().generate_return_types())
665 ostr <<
" : //" << from.value().return_type() <<
"//";
671 ostr <<
"deactivate " << from_alias <<
'\n';
683 if (
config().generate_method_arguments() ==