16 KiB
16 KiB
t20012 - Lambda expression call sequence diagram test case
Config
compilation_database_dir: ..
output_directory: puml
diagrams:
t20012_sequence:
type: sequence
glob:
- ../../tests/t20012/t20012.cc
include:
namespaces:
- clanguml::t20012
using_namespace:
- clanguml::t20012
start_from:
- function: "clanguml::t20012::tmain()"
Source code
File t20012.cc
#include <algorithm>
#include <functional>
#include <memory>
#include <optional>
#include <utility>
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<std::shared_ptr<B>> maybe_b;
std::shared_ptr<A> a;
public:
template <typename F> void setup(F &&f) { f(maybe_b); }
};
template <typename F> 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<int> 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 UML diagrams
Generated JSON models
{
"diagram_type": "sequence",
"metadata": {
"clang_uml_version": "0.3.4-28-g3eb1c47",
"llvm_version": "Ubuntu clang version 15.0.6",
"schema_version": 1
},
"name": "t20012_sequence",
"participants": [
{
"id": "893699278278125827",
"name": "clanguml::t20012::tmain()",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 58
},
"type": "function"
},
{
"id": "871571755123349249",
"name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:66:20)",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 66
},
"type": "class"
},
{
"id": "1798184226128732119",
"name": "clanguml::t20012::A",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 9
},
"type": "class"
},
{
"id": "1893469899260202653",
"name": "clanguml::t20012::B",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 17
},
"type": "class"
},
{
"id": "516948909715002916",
"name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:79:20)",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 79
},
"type": "class"
},
{
"id": "2071958121786360262",
"name": "clanguml::t20012::C",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 27
},
"type": "class"
},
{
"id": "1639905845562724067",
"name": "clanguml::t20012::R<R::(lambda ../../tests/t20012/t20012.cc:85:9)>",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 47
},
"type": "class"
},
{
"id": "105322683015690128",
"name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:85:9)",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 85
},
"type": "class"
},
{
"id": "1627226326147373737",
"name": "clanguml::t20012::D",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 35
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 72
},
"to": {
"activity_id": "601151241333493101",
"activity_name": "clanguml::t20012::tmain()##(lambda ../../tests/t20012/t20012.cc:66:20)::operator()()",
"participant_id": "871571755123349249"
},
"type": "message"
},
{
"from": {
"activity_id": "601151241333493101",
"activity_name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:66:20)::operator()()",
"participant_id": "871571755123349249"
},
"name": "a()",
"return_type": "void",
"scope": "normal",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 67
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 10
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 12
},
"to": {
"activity_id": "941636185823691898",
"activity_name": "clanguml::t20012::A::aaa()",
"participant_id": "1798184226128732119"
},
"type": "message"
},
{
"from": {
"activity_id": "601151241333493101",
"activity_name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:66:20)::operator()()",
"participant_id": "871571755123349249"
},
"name": "b()",
"return_type": "void",
"scope": "normal",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 68
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 18
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 20
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 83
},
"to": {
"activity_id": "435249756897748529",
"activity_name": "clanguml::t20012::tmain()##(lambda ../../tests/t20012/t20012.cc:79:20)::operator()()",
"participant_id": "516948909715002916"
},
"type": "message"
},
{
"from": {
"activity_id": "435249756897748529",
"activity_name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:79:20)::operator()()",
"participant_id": "516948909715002916"
},
"name": "c()",
"return_type": "void",
"scope": "normal",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 80
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 28
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 30
},
"to": {
"activity_id": "1956141408799600460",
"activity_name": "clanguml::t20012::C::ccc()",
"participant_id": "2071958121786360262"
},
"type": "message"
},
{
"from": {
"activity_id": "435249756897748529",
"activity_name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:79:20)::operator()()",
"participant_id": "516948909715002916"
},
"name": "operator()()",
"return_type": "",
"scope": "normal",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 81
},
"to": {
"activity_id": "601151241333493101",
"activity_name": "clanguml::t20012::tmain()##(lambda ../../tests/t20012/t20012.cc:66:20)::operator()()",
"participant_id": "871571755123349249"
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 87
},
"to": {
"activity_id": "1003931867044486762",
"activity_name": "clanguml::t20012::R<R##(lambda ../../tests/t20012/t20012.cc:85:9)>::r()",
"participant_id": "1639905845562724067"
},
"type": "message"
},
{
"from": {
"activity_id": "1003931867044486762",
"activity_name": "clanguml::t20012::R<R::(lambda ../../tests/t20012/t20012.cc:85:9)>::r()",
"participant_id": "1639905845562724067"
},
"name": "operator()()",
"return_type": "",
"scope": "normal",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 53
},
"to": {
"activity_id": "31472345599504206",
"activity_name": "clanguml::t20012::tmain()##(lambda ../../tests/t20012/t20012.cc:85:9)::operator()()",
"participant_id": "105322683015690128"
},
"type": "message"
},
{
"from": {
"activity_id": "31472345599504206",
"activity_name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:85:9)::operator()()",
"participant_id": "105322683015690128"
},
"name": "c()",
"return_type": "void",
"scope": "normal",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 85
},
"to": {
"activity_id": "675369415318225607",
"activity_name": "clanguml::t20012::C::c()",
"participant_id": "2071958121786360262"
},
"type": "message"
},
{
"from": {
"activity_id": "893699278278125827",
"activity_name": "clanguml::t20012::tmain()",
"participant_id": "893699278278125827",
"participant_name": "clanguml::t20012::tmain()"
},
"name": "add5(int)",
"return_type": "",
"scope": "normal",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 93
},
"to": {
"activity_id": "1355013132527568474",
"activity_name": "clanguml::t20012::D::add5(int)",
"participant_id": "1627226326147373737"
},
"type": "message"
}
],
"start_from": {
"id": 893699278278125827,
"location": "clanguml::t20012::tmain()"
}
}
],
"using_namespace": "clanguml::t20012"
}