23std::string render_name(std::string name)
40 j[
"name"] =
dynamic_cast<const method &
>(c).method_name();
46 const auto &f =
dynamic_cast<const function &
>(c);
47 if (f.is_cuda_kernel())
48 j[
"is_cuda_kernel"] =
true;
49 if (f.is_cuda_device())
50 j[
"is_cuda_device"] =
true;
56 j[
"participant_id"] = std::to_string(c.
from().
value());
85 LOG_DBG(
"Skipping empty call from '{}' to '{}'", m.
from(), m.
to());
99 .message_name(render_mode);
101 else if (
config().combine_free_functions_into_file_participants()) {
102 if (to.value().
type_name() ==
"function") {
104 .message_name(render_mode);
106 else if (to.value().
type_name() ==
"function_template") {
108 .message_name(render_mode);
117 msg[
"type"] =
"message";
118 msg[
"from"][
"activity_id"] = std::to_string(from.value().id().value());
119 msg[
"to"][
"activity_id"] = std::to_string(to.value().
id().
value());
120 if (
const auto &cmt = m.
comment(); cmt.has_value())
121 msg[
"comment"] = cmt.value().at(
"comment");
123 if (from.value().type_name() ==
"method") {
124 const auto &class_participant =
127 msg[
"from"][
"participant_id"] =
128 std::to_string(class_participant.class_id().value());
130 else if (from.value().type_name() ==
"function" ||
131 from.value().type_name() ==
"function_template") {
132 if (
config().combine_free_functions_into_file_participants()) {
133 const auto &file_participant =
137 msg[
"from"][
"participant_id"] = std::to_string(
141 msg[
"from"][
"participant_id"] =
142 std::to_string(from.value().id().value());
145 else if (from.value().type_name() ==
"lambda") {
146 msg[
"from"][
"participant_id"] =
147 std::to_string(from.value().id().value());
150 if (to.value().
type_name() ==
"method") {
151 const auto &class_participant =
154 msg[
"to"][
"participant_id"] =
155 std::to_string(class_participant.class_id().value());
157 else if (to.value().
type_name() ==
"function" ||
158 to.value().
type_name() ==
"function_template") {
159 if (
config().combine_free_functions_into_file_participants()) {
160 const auto &file_participant =
164 msg[
"to"][
"participant_id"] = std::to_string(
168 msg[
"to"][
"participant_id"] =
169 std::to_string(to.value().
id().
value());
172 else if (to.value().
type_name() ==
"lambda") {
173 msg[
"to"][
"participant_id"] = std::to_string(to.value().
id().
value());
176 msg[
"source_location"] =
182 parent[
"messages"].push_back(std::move(msg));
190 const activity &a, std::vector<eid_t> &visited)
const
193 for (
const auto &m : a.
messages()) {
195 case message_t::kCall:
201 case message_t::kElseIf:
202 case message_t::kElse:
205 case message_t::kIfEnd:
208 case message_t::kWhile:
211 case message_t::kWhileEnd:
214 case message_t::kFor:
217 case message_t::kForEnd:
223 case message_t::kDoEnd:
226 case message_t::kTry:
229 case message_t::kCatch:
232 case message_t::kTryEnd:
235 case message_t::kSwitch:
238 case message_t::kCase:
241 case message_t::kSwitchEnd:
244 case message_t::kConditional:
247 case message_t::kConditionalElse:
250 case message_t::kConditionalEnd:
253 case message_t::kNone:
254 case message_t::kReturn:;
269 visited.push_back(m.
from());
284 if (
model().sequences().find(m.
to()) !=
model().sequences().end()) {
285 if (std::find(visited.begin(), visited.end(), m.
to()) ==
288 LOG_DBG(
"Creating activity {} --> {} - missing sequence {}",
295 LOG_DBG(
"Skipping activity {} --> {} - missing sequence {}", m.
from(),
303 nlohmann::json while_block;
304 while_block[
"type"] =
"loop";
305 while_block[
"name"] =
"while";
306 while_block[
"activity_id"] = std::to_string(m.
from().
value());
308 while_block[
"condition_text"] = *text;
324 nlohmann::json for_block;
325 for_block[
"type"] =
"loop";
326 for_block[
"name"] =
"for";
327 for_block[
"activity_id"] = std::to_string(m.
from().
value());
329 for_block[
"condition_text"] = *text;
345 nlohmann::json do_block;
346 do_block[
"type"] =
"loop";
347 do_block[
"name"] =
"do";
348 do_block[
"activity_id"] = std::to_string(m.
from().
value());
350 do_block[
"condition_text"] = *text;
366 nlohmann::json try_block;
367 try_block[
"type"] =
"break";
368 try_block[
"name"] =
"try";
369 try_block[
"activity_id"] = std::to_string(m.
from().
value());
376 nlohmann::json branch;
377 branch[
"type"] =
"main";
389 nlohmann::json branch;
390 branch[
"type"] =
"catch";
408 nlohmann::json if_block;
409 if_block[
"type"] =
"alt";
410 if_block[
"name"] =
"switch";
411 if_block[
"activity_id"] = std::to_string(m.
from().
value());
424 nlohmann::json case_block;
425 case_block[
"type"] =
"case";
443 nlohmann::json if_block;
444 if_block[
"type"] =
"alt";
445 if_block[
"name"] =
"conditional";
446 if_block[
"activity_id"] = std::to_string(m.
from().
value());
448 if_block[
"condition_text"] = *text;
455 nlohmann::json branch;
456 branch[
"type"] =
"consequent";
468 nlohmann::json branch;
469 branch[
"type"] =
"alternative";
471 branch[
"condition_text"] = *text;
501 nlohmann::json branch;
502 branch[
"type"] =
"alternative";
511 nlohmann::json if_block;
512 if_block[
"type"] =
"alt";
513 if_block[
"name"] =
"if";
514 if_block[
"activity_id"] = std::to_string(m.
from().
value());
516 if_block[
"condition_text"] = *text;
523 nlohmann::json branch;
524 branch[
"type"] =
"consequent";
532 nlohmann::json &parent,
const std::string &name)
const
534 auto p =
model().get(name);
536 if (!p.has_value()) {
537 LOG_WARN(
"Cannot find participant {} from `participants_order` option",
546 nlohmann::json & ,
eid_t id,
bool force)
const
548 std::optional<eid_t> participant_id{};
551 for (
const auto pid :
model().active_participants()) {
553 participant_id = pid;
561 if (!participant_id.has_value())
562 return participant_id;
565 return participant_id;
567 const auto &participant =
570 const auto participant_type = participant.
type_name();
572 if (participant_type ==
"method") {
573 auto class_participant_id =
579 LOG_DBG(
"Generating JSON method participant: {}",
581 .get_participant<model::method>(*participant_id)
586 const auto &class_participant =
594 json_[
"participants"].push_back(class_participant);
595 json_[
"participants"].back()[
"activities"].push_back(participant);
598 const auto class_participant_full_name =
599 class_participant.full_name(
false);
601 json_[
"participants"].back().at(
"display_name") =
604 return class_participant_id;
608 for (
auto &p :
json_[
"participants"]) {
610 std::to_string(class_participant_id.value())) {
612 p[
"activities"].push_back(participant);
613 return class_participant_id;
618 else if ((participant_type ==
"function" ||
619 participant_type ==
"function_template") &&
620 config().combine_free_functions_into_file_participants()) {
624 const auto &function_participant =
627 const auto file_participant_id =
631 nlohmann::json p = function_participant;
633 const auto file_path =
634 config().make_path_relative(function_participant.file());
637 p[
"name"] = file_path.filename();
640 return participant_id;
642 p[
"id"] = std::to_string(file_participant_id.value());
644 p.erase(
"source_location");
648 p[
"activities"].push_back(participant);
649 json_[
"participants"].push_back(p);
653 return file_participant_id;
657 for (
auto &p :
json_[
"participants"]) {
658 if (p.at(
"id") == std::to_string(file_participant_id.value())) {
660 p[
"activities"].push_back(participant);
665 return file_participant_id;
668 json_[
"participants"].push_back(participant);
673 return participant_id;
687 if (
config().using_namespace)
688 parent[
"using_namespace"] =
config().using_namespace().to_string();
690 if (
config().participants_order.has_value) {
691 for (
const auto &p :
config().participants_order()) {
692 LOG_DBG(
"Pregenerating participant {}", p);
697 for (
const auto &ft :
config().from_to()) {
700 assert(ft.size() == 2);
702 const auto &from_location = ft.front();
703 const auto &to_location = ft.back();
705 auto from_activity_id =
model().get_from_activity_id(from_location);
706 auto to_activity_id =
model().get_to_activity_id(to_location);
708 if (!from_activity_id || !to_activity_id)
711 auto message_chains_unique =
model().get_all_from_to_message_chains(
712 *from_activity_id, *to_activity_id);
714 nlohmann::json sequence;
715 sequence[
"from_to"][
"from"][
"location"] = from_location.location;
716 sequence[
"from_to"][
"from"][
"id"] =
717 std::to_string(from_activity_id.value().value());
718 sequence[
"from_to"][
"to"][
"location"] = to_location.location;
719 sequence[
"from_to"][
"to"][
"id"] =
720 std::to_string(to_activity_id.value().value());
724 sequence[
"message_chains"] = nlohmann::json::array();
726 for (
const auto &mc : message_chains_unique) {
727 nlohmann::json message_chain;
731 for (
const auto &m : mc) {
737 sequence[
"message_chains"].push_back(std::move(message_chain));
742 parent[
"sequences"].push_back(std::move(sequence));
745 for (
const auto &to_location :
config().to()) {
746 auto to_activity_id =
model().get_to_activity_id(to_location);
748 if (!to_activity_id.has_value())
751 auto message_chains_unique =
model().get_all_from_to_message_chains(
754 nlohmann::json sequence;
755 sequence[
"to"][
"location"] = to_location.location;
756 sequence[
"to"][
"id"] = std::to_string(to_activity_id.value().value());
760 sequence[
"message_chains"] = nlohmann::json::array();
762 for (
const auto &mc : message_chains_unique) {
763 nlohmann::json message_chain;
767 for (
const auto &m : mc) {
773 sequence[
"message_chains"].push_back(std::move(message_chain));
778 parent[
"sequences"].push_back(std::move(sequence));
781 for (
const auto &sf :
config().from()) {
782 if (sf.location_type == location_t::function) {
784 std::string start_from_str;
785 for (
const auto &[k, v] :
model().sequences()) {
786 const auto &caller = *
model().participants().at(v.from());
787 std::string vfrom = caller.full_name(
false);
788 if (vfrom == sf.location) {
789 LOG_DBG(
"Found sequence diagram start point: {}", k);
795 if (start_from == 0) {
796 LOG_WARN(
"Failed to find participant with {} for start_from "
803 std::vector<eid_t> visited_participants;
808 if (!from.has_value()) {
809 LOG_WARN(
"Failed to find participant {} for start_from "
820 nlohmann::json sequence;
821 sequence[
"start_from"][
"location"] = sf.location;
822 sequence[
"start_from"][
"id"] = std::to_string(start_from.value());
827 model().get_activity(start_from), visited_participants);
831 if (from.value().type_name() ==
"method" ||
832 config().combine_free_functions_into_file_participants()) {
834 sequence[
"return_type"] =
838 parent[
"sequences"].push_back(std::move(sequence));
847 for (
auto &p :
json_[
"participants"]) {
848 if (p.contains(
"display_name")) {
853 parent[
"participants"] =
json_[
"participants"];
858 auto result =
config().simplify_template_type(full_name);
859 result =
config().using_namespace().relative(result);
861 result = render_name(result);