Files
clang-uml/docs/test_cases/t20012.md
2023-06-02 22:02:08 +02:00

561 lines
16 KiB
Markdown

# t20012 - Lambda expression call sequence diagram test case
## Config
```yaml
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
```cpp
#include <algorithm>
#include <functional>
#include <memory>
#include <optional>
#include <utility>
#include <vector>
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
![t20012_sequence](./t20012_sequence.svg "Lambda expression call sequence diagram test case")
## Generated JSON models
```json
{
"diagram_type": "sequence",
"metadata": {
"clang_uml_version": "0.3.6-11-g75d1daa",
"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": 59
},
"type": "function"
},
{
"id": "1160054139240670033",
"name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:67:20)",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 67
},
"type": "class"
},
{
"id": "1798184226128732119",
"name": "clanguml::t20012::A",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 10
},
"type": "class"
},
{
"id": "1893469899260202653",
"name": "clanguml::t20012::B",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 18
},
"type": "class"
},
{
"id": "409124263156368546",
"name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:80:20)",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 80
},
"type": "class"
},
{
"id": "2071958121786360262",
"name": "clanguml::t20012::C",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 28
},
"type": "class"
},
{
"id": "1848989986288721876",
"name": "clanguml::t20012::R<R::(lambda ../../tests/t20012/t20012.cc:86:9)>",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 48
},
"type": "class"
},
{
"id": "235908030444274749",
"name": "clanguml::t20012::tmain()::(lambda ../../tests/t20012/t20012.cc:86:9)",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 86
},
"type": "class"
},
{
"id": "1627226326147373737",
"name": "clanguml::t20012::D",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 36
},
"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": 73
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 68
},
"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": 11
},
"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": 13
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 69
},
"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": 19
},
"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": 21
},
"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": 84
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 81
},
"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": 29
},
"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": 31
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 82
},
"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()",
"return_type": "void",
"scope": "normal",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 88
},
"to": {
"activity_id": "983377906480895496",
"activity_name": "clanguml::t20012::R<R##(lambda ../../tests/t20012/t20012.cc:86:9)>::r()",
"participant_id": "1848989986288721876"
},
"type": "message"
},
{
"from": {
"activity_id": "983377906480895496",
"activity_name": "clanguml::t20012::R<R::(lambda ../../tests/t20012/t20012.cc:86:9)>::r()",
"participant_id": "1848989986288721876"
},
"name": "operator()()",
"return_type": "",
"scope": "normal",
"source_location": {
"file": "../../tests/t20012/t20012.cc",
"line": 54
},
"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": {
"file": "../../tests/t20012/t20012.cc",
"line": 86
},
"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": 94
},
"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"
}
```