# t20012 - Lambda expression call sequence diagram test case ## Config ```yaml compilation_database_dir: .. output_directory: diagrams diagrams: t20012_sequence: type: sequence glob: - ../../tests/t20012/t20012.cc include: namespaces: - clanguml::t20012 using_namespace: - clanguml::t20012 from: - function: "clanguml::t20012::tmain()" ``` ## Source code File t20012.cc ```cpp #include #include #include #include #include #include namespace clanguml { namespace t20012 { struct A { void a() { aa(); } void aa() { aaa(); } void aaa() { } }; struct B { void b() { bb(); } void bb() { bbb(); } void bbb() { } void eb() { } }; struct C { void c() { cc(); } void cc() { ccc(); } void ccc() { } }; struct D { int add5(int arg) const { return arg + 5; } }; class E { std::optional> maybe_b; std::shared_ptr a; public: template void setup(F &&f) { f(maybe_b); } }; template struct R { R(F &&f) : f_{std::move(f)} { } void r() { f_(); } F f_; }; void tmain() { A a; B b; C c; // The activity shouldn't be marked at the lambda definition, but // wherever it is actually called... auto alambda = [&a, &b]() { a.a(); b.b(); }; // ...like here alambda(); // There should be no call to B in the sequence diagram as the blambda // is never called [[maybe_unused]] auto blambda = [&b]() { b.b(); }; // Nested lambdas should also work auto clambda = [alambda, &c]() { c.c(); alambda(); }; clambda(); R r{[&c]() { c.c(); }}; r.r(); D d; std::vector ints{0, 1, 2, 3, 4}; std::transform(ints.begin(), ints.end(), ints.begin(), [&d](auto i) { return d.add5(i); }); // TODO: Fix naming function call arguments which are lambdas // E e; // // e.setup([](auto &&arg) mutable { // // We cannot know here what 'arg' might be // arg.value()->eb(); // }); } } } ``` ## Generated PlantUML diagrams ![t20012_sequence](./t20012_sequence.svg "Lambda expression call sequence diagram test case") ## Generated Mermaid diagrams ![t20012_sequence](./t20012_sequence_mermaid.svg "Lambda expression call sequence diagram test case") ## Generated JSON models ```json { "diagram_type": "sequence", "metadata": { "clang_uml_version": "0.4.1-11-g39d3e1f", "llvm_version": "Ubuntu clang version 16.0.6 (++20230710042027+7cbf1a259152-1~exp1~20230710162048.105)", "schema_version": 1 }, "name": "t20012_sequence", "participants": [ { "id": "893699278278125827", "name": "clanguml::t20012::tmain()", "source_location": { "column": 6, "file": "../../tests/t20012/t20012.cc", "line": 59, "translation_unit": "../../tests/t20012/t20012.cc" }, "type": "function" }, { "id": "1160054139240670033", "name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:67:20)", "source_location": { "column": 20, "file": "../../tests/t20012/t20012.cc", "line": 67, "translation_unit": "../../tests/t20012/t20012.cc" }, "type": "class" }, { "id": "1798184226128732119", "name": "clanguml::t20012::A", "source_location": { "column": 8, "file": "../../tests/t20012/t20012.cc", "line": 10, "translation_unit": "../../tests/t20012/t20012.cc" }, "type": "class" }, { "id": "1893469899260202653", "name": "clanguml::t20012::B", "source_location": { "column": 8, "file": "../../tests/t20012/t20012.cc", "line": 18, "translation_unit": "../../tests/t20012/t20012.cc" }, "type": "class" }, { "id": "409124263156368546", "name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:80:20)", "source_location": { "column": 20, "file": "../../tests/t20012/t20012.cc", "line": 80, "translation_unit": "../../tests/t20012/t20012.cc" }, "type": "class" }, { "id": "2071958121786360262", "name": "clanguml::t20012::C", "source_location": { "column": 8, "file": "../../tests/t20012/t20012.cc", "line": 28, "translation_unit": "../../tests/t20012/t20012.cc" }, "type": "class" }, { "id": "1848989986288721876", "name": "clanguml::t20012::R", "source_location": { "column": 30, "file": "../../tests/t20012/t20012.cc", "line": 48, "translation_unit": "../../tests/t20012/t20012.cc" }, "type": "class" }, { "id": "235908030444274749", "name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:86:9)", "source_location": { "column": 9, "file": "../../tests/t20012/t20012.cc", "line": 86, "translation_unit": "../../tests/t20012/t20012.cc" }, "type": "class" } ], "sequences": [ { "messages": [ { "from": { "activity_id": "893699278278125827", "activity_name": "clanguml::t20012::tmain()", "participant_id": "893699278278125827", "participant_name": "clanguml::t20012::tmain()" }, "name": "operator()()", "return_type": "", "scope": "normal", "source_location": { "column": 5, "file": "../../tests/t20012/t20012.cc", "line": 73, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "2097044932440760306", "activity_name": "clanguml::t20012::tmain()##(lambda ../../tests/t20012/t20012.cc:67:20)::operator()()", "participant_id": "1160054139240670033" }, "type": "message" }, { "from": { "activity_id": "2097044932440760306", "activity_name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:67:20)::operator()()", "participant_id": "1160054139240670033" }, "name": "a()", "return_type": "void", "scope": "normal", "source_location": { "column": 9, "file": "../../tests/t20012/t20012.cc", "line": 68, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "1871432932744498976", "activity_name": "clanguml::t20012::A::a()", "participant_id": "1798184226128732119" }, "type": "message" }, { "from": { "activity_id": "1871432932744498976", "activity_name": "clanguml::t20012::A::a()", "participant_id": "1798184226128732119" }, "name": "aa()", "return_type": "void", "scope": "normal", "source_location": { "column": 16, "file": "../../tests/t20012/t20012.cc", "line": 11, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "1100933039353876539", "activity_name": "clanguml::t20012::A::aa()", "participant_id": "1798184226128732119" }, "type": "message" }, { "from": { "activity_id": "1100933039353876539", "activity_name": "clanguml::t20012::A::aa()", "participant_id": "1798184226128732119" }, "name": "aaa()", "return_type": "void", "scope": "normal", "source_location": { "column": 17, "file": "../../tests/t20012/t20012.cc", "line": 13, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "941636185823691898", "activity_name": "clanguml::t20012::A::aaa()", "participant_id": "1798184226128732119" }, "type": "message" }, { "from": { "activity_id": "2097044932440760306", "activity_name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:67:20)::operator()()", "participant_id": "1160054139240670033" }, "name": "b()", "return_type": "void", "scope": "normal", "source_location": { "column": 9, "file": "../../tests/t20012/t20012.cc", "line": 69, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "2142697410385270633", "activity_name": "clanguml::t20012::B::b()", "participant_id": "1893469899260202653" }, "type": "message" }, { "from": { "activity_id": "2142697410385270633", "activity_name": "clanguml::t20012::B::b()", "participant_id": "1893469899260202653" }, "name": "bb()", "return_type": "void", "scope": "normal", "source_location": { "column": 16, "file": "../../tests/t20012/t20012.cc", "line": 19, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "973718340784931313", "activity_name": "clanguml::t20012::B::bb()", "participant_id": "1893469899260202653" }, "type": "message" }, { "from": { "activity_id": "973718340784931313", "activity_name": "clanguml::t20012::B::bb()", "participant_id": "1893469899260202653" }, "name": "bbb()", "return_type": "void", "scope": "normal", "source_location": { "column": 17, "file": "../../tests/t20012/t20012.cc", "line": 21, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "195788529004378403", "activity_name": "clanguml::t20012::B::bbb()", "participant_id": "1893469899260202653" }, "type": "message" }, { "from": { "activity_id": "893699278278125827", "activity_name": "clanguml::t20012::tmain()", "participant_id": "893699278278125827", "participant_name": "clanguml::t20012::tmain()" }, "name": "operator()()", "return_type": "", "scope": "normal", "source_location": { "column": 5, "file": "../../tests/t20012/t20012.cc", "line": 84, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "3346531080036149", "activity_name": "clanguml::t20012::tmain()##(lambda ../../tests/t20012/t20012.cc:80:20)::operator()()", "participant_id": "409124263156368546" }, "type": "message" }, { "from": { "activity_id": "3346531080036149", "activity_name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:80:20)::operator()()", "participant_id": "409124263156368546" }, "name": "c()", "return_type": "void", "scope": "normal", "source_location": { "column": 9, "file": "../../tests/t20012/t20012.cc", "line": 81, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "675369415318225607", "activity_name": "clanguml::t20012::C::c()", "participant_id": "2071958121786360262" }, "type": "message" }, { "from": { "activity_id": "675369415318225607", "activity_name": "clanguml::t20012::C::c()", "participant_id": "2071958121786360262" }, "name": "cc()", "return_type": "void", "scope": "normal", "source_location": { "column": 16, "file": "../../tests/t20012/t20012.cc", "line": 29, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "1451821704315336057", "activity_name": "clanguml::t20012::C::cc()", "participant_id": "2071958121786360262" }, "type": "message" }, { "from": { "activity_id": "1451821704315336057", "activity_name": "clanguml::t20012::C::cc()", "participant_id": "2071958121786360262" }, "name": "ccc()", "return_type": "void", "scope": "normal", "source_location": { "column": 17, "file": "../../tests/t20012/t20012.cc", "line": 31, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "1956141408799600460", "activity_name": "clanguml::t20012::C::ccc()", "participant_id": "2071958121786360262" }, "type": "message" }, { "from": { "activity_id": "3346531080036149", "activity_name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:80:20)::operator()()", "participant_id": "409124263156368546" }, "name": "operator()()", "return_type": "", "scope": "normal", "source_location": { "column": 9, "file": "../../tests/t20012/t20012.cc", "line": 82, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "2097044932440760306", "activity_name": "clanguml::t20012::tmain()##(lambda ../../tests/t20012/t20012.cc:67:20)::operator()()", "participant_id": "1160054139240670033" }, "type": "message" }, { "from": { "activity_id": "893699278278125827", "activity_name": "clanguml::t20012::tmain()", "participant_id": "893699278278125827", "participant_name": "clanguml::t20012::tmain()" }, "name": "R((lambda at /home/bartek/devel/clang-uml/tests/t20012/t20012.cc:86:9) &&)", "return_type": "void", "scope": "normal", "source_location": { "column": 7, "file": "../../tests/t20012/t20012.cc", "line": 86, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "1163275626544717212", "activity_name": "clanguml::t20012::R::R((lambda at /home/bartek/devel/clang-uml/tests/t20012/t20012.cc:86:9) &&)", "participant_id": "1848989986288721876" }, "type": "message" }, { "from": { "activity_id": "893699278278125827", "activity_name": "clanguml::t20012::tmain()", "participant_id": "893699278278125827", "participant_name": "clanguml::t20012::tmain()" }, "name": "r()", "return_type": "void", "scope": "normal", "source_location": { "column": 5, "file": "../../tests/t20012/t20012.cc", "line": 88, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "983377906480895496", "activity_name": "clanguml::t20012::R::r()", "participant_id": "1848989986288721876" }, "type": "message" }, { "from": { "activity_id": "983377906480895496", "activity_name": "clanguml::t20012::R::r()", "participant_id": "1848989986288721876" }, "name": "operator()()", "return_type": "", "scope": "normal", "source_location": { "column": 16, "file": "../../tests/t20012/t20012.cc", "line": 54, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "2085809056446194400", "activity_name": "clanguml::t20012::tmain()##(lambda ../../tests/t20012/t20012.cc:86:9)::operator()()", "participant_id": "235908030444274749" }, "type": "message" }, { "from": { "activity_id": "2085809056446194400", "activity_name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:86:9)::operator()()", "participant_id": "235908030444274749" }, "name": "c()", "return_type": "void", "scope": "normal", "source_location": { "column": 18, "file": "../../tests/t20012/t20012.cc", "line": 86, "translation_unit": "../../tests/t20012/t20012.cc" }, "to": { "activity_id": "675369415318225607", "activity_name": "clanguml::t20012::C::c()", "participant_id": "2071958121786360262" }, "type": "message" } ], "start_from": { "id": 893699278278125827, "location": "clanguml::t20012::tmain()" } } ], "using_namespace": "clanguml::t20012" } ```