# t20020 - If statement sequence diagram test case ## Config ```yaml compilation_database_dir: .. output_directory: diagrams diagrams: t20020_sequence: type: sequence glob: - ../../tests/t20020/t20020.cc include: namespaces: - clanguml::t20020 using_namespace: - clanguml::t20020 from: - function: "clanguml::t20020::tmain()" ``` ## Source code File t20020.cc ```cpp #include #include namespace clanguml { namespace t20020 { struct A { int a1() { return 0; } int a2() { return 1; } int a3() { return 2; } int a4() { return 3; } int a5() { return 4; } }; struct B { void log() { } int b1() { return 3; } int b2() { return 4; } }; struct C { void log() const { } void c1() const { if (c2()) log(); } bool c2() const { return true; } int c3(int x) { return x * 2; } }; template struct D { T d1(T x, T y) { return x + y; } }; int tmain() { A a; B b; C c; D d; int result{0}; if (reinterpret_cast(&a) % 100 == 0ULL) { result = a.a1(); } else if (reinterpret_cast(&a) % 100 == 42ULL) { result = a.a5(); } else if (reinterpret_cast(&a) % 64 == 0ULL) { if (c.c3(a.a2()) > 2) result = b.b1(); else if (a.a3() % 2) result = b.b2(); else result = 0; } else { result = a.a4(); } b.log(); if (true) c.c1(); if (true) d.d1(1, 1); // This if/else should not be included in the diagram at all // as the calls to std will be excluded by the diagram filters if (result != 2) { result = std::exp(result); } else if (result == 3) { result = 4; } else { result = std::exp(result + 1); } return result; } } } ``` ## Generated PlantUML diagrams ![t20020_sequence](./t20020_sequence.svg "If statement sequence diagram test case") ## Generated Mermaid diagrams ![t20020_sequence](./t20020_sequence_mermaid.svg "If statement sequence diagram test case") ## Generated JSON models ```json { "diagram_type": "sequence", "metadata": { "clang_uml_version": "0.4.0", "llvm_version": "Ubuntu clang version 16.0.1 (++20230328073357+42d1b276f779-1~exp1~20230328073502.65)", "schema_version": 1 }, "name": "t20020_sequence", "participants": [ { "id": "432124388562400664", "name": "clanguml::t20020::tmain()", "source_location": { "column": 5, "file": "../../tests/t20020/t20020.cc", "line": 40, "translation_unit": "../../tests/t20020/t20020.cc" }, "type": "function" }, { "id": "208941846648931609", "name": "clanguml::t20020::A", "source_location": { "column": 8, "file": "../../tests/t20020/t20020.cc", "line": 6, "translation_unit": "../../tests/t20020/t20020.cc" }, "type": "class" }, { "id": "1562462306909405383", "name": "clanguml::t20020::C", "source_location": { "column": 8, "file": "../../tests/t20020/t20020.cc", "line": 21, "translation_unit": "../../tests/t20020/t20020.cc" }, "type": "class" }, { "id": "1342563483612170412", "name": "clanguml::t20020::B", "source_location": { "column": 8, "file": "../../tests/t20020/t20020.cc", "line": 14, "translation_unit": "../../tests/t20020/t20020.cc" }, "type": "class" }, { "id": "1605914310746811866", "name": "clanguml::t20020::D", "source_location": { "column": 30, "file": "../../tests/t20020/t20020.cc", "line": 35, "translation_unit": "../../tests/t20020/t20020.cc" }, "type": "class" } ], "sequences": [ { "messages": [ { "activity_id": "432124388562400664", "branches": [ { "messages": [ { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "a1()", "return_type": "int", "scope": "normal", "source_location": { "column": 18, "file": "../../tests/t20020/t20020.cc", "line": 50, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "43928675765534701", "activity_name": "clanguml::t20020::A::a1()", "participant_id": "208941846648931609" }, "type": "message" } ], "type": "consequent" }, { "messages": [ { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "a5()", "return_type": "int", "scope": "normal", "source_location": { "column": 18, "file": "../../tests/t20020/t20020.cc", "line": 53, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "1613457246223182826", "activity_name": "clanguml::t20020::A::a5()", "participant_id": "208941846648931609" }, "type": "message" } ], "type": "alternative" }, { "messages": [ { "activity_id": "432124388562400664", "branches": [ { "messages": [ { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "a2()", "return_type": "int", "scope": "condition", "source_location": { "column": 18, "file": "../../tests/t20020/t20020.cc", "line": 56, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "1289745252290688140", "activity_name": "clanguml::t20020::A::a2()", "participant_id": "208941846648931609" }, "type": "message" }, { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "c3(int)", "return_type": "int", "scope": "condition", "source_location": { "column": 13, "file": "../../tests/t20020/t20020.cc", "line": 56, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "1303438784842196201", "activity_name": "clanguml::t20020::C::c3(int)", "participant_id": "1562462306909405383" }, "type": "message" }, { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "b1()", "return_type": "int", "scope": "normal", "source_location": { "column": 22, "file": "../../tests/t20020/t20020.cc", "line": 57, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "542196582335607343", "activity_name": "clanguml::t20020::B::b1()", "participant_id": "1342563483612170412" }, "type": "message" } ], "type": "consequent" }, { "messages": [ { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "a3()", "return_type": "int", "scope": "condition", "source_location": { "column": 18, "file": "../../tests/t20020/t20020.cc", "line": 58, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "1983660679554669898", "activity_name": "clanguml::t20020::A::a3()", "participant_id": "208941846648931609" }, "type": "message" }, { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "b2()", "return_type": "int", "scope": "normal", "source_location": { "column": 22, "file": "../../tests/t20020/t20020.cc", "line": 59, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "505760236964179187", "activity_name": "clanguml::t20020::B::b2()", "participant_id": "1342563483612170412" }, "type": "message" } ], "type": "alternative" } ], "name": "if", "type": "alt" } ], "type": "alternative" }, { "messages": [ { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "a4()", "return_type": "int", "scope": "normal", "source_location": { "column": 18, "file": "../../tests/t20020/t20020.cc", "line": 64, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "20573198999978866", "activity_name": "clanguml::t20020::A::a4()", "participant_id": "208941846648931609" }, "type": "message" } ], "type": "alternative" } ], "name": "if", "type": "alt" }, { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "log()", "return_type": "void", "scope": "normal", "source_location": { "column": 5, "file": "../../tests/t20020/t20020.cc", "line": 67, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "1436250788704205026", "activity_name": "clanguml::t20020::B::log()", "participant_id": "1342563483612170412" }, "type": "message" }, { "activity_id": "432124388562400664", "branches": [ { "messages": [ { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "c1() const", "return_type": "void", "scope": "normal", "source_location": { "column": 9, "file": "../../tests/t20020/t20020.cc", "line": 70, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "1473521613404783653", "activity_name": "clanguml::t20020::C::c1() const", "participant_id": "1562462306909405383" }, "type": "message" }, { "activity_id": "1473521613404783653", "branches": [ { "messages": [ { "from": { "activity_id": "1473521613404783653", "activity_name": "clanguml::t20020::C::c1() const", "participant_id": "1562462306909405383" }, "name": "c2() const", "return_type": "bool", "scope": "condition", "source_location": { "column": 13, "file": "../../tests/t20020/t20020.cc", "line": 26, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "1789116382725485914", "activity_name": "clanguml::t20020::C::c2() const", "participant_id": "1562462306909405383" }, "type": "message" }, { "from": { "activity_id": "1473521613404783653", "activity_name": "clanguml::t20020::C::c1() const", "participant_id": "1562462306909405383" }, "name": "log() const", "return_type": "void", "scope": "normal", "source_location": { "column": 13, "file": "../../tests/t20020/t20020.cc", "line": 27, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "635780525021572670", "activity_name": "clanguml::t20020::C::log() const", "participant_id": "1562462306909405383" }, "type": "message" } ], "type": "consequent" } ], "name": "if", "type": "alt" } ], "type": "consequent" } ], "name": "if", "type": "alt" }, { "activity_id": "432124388562400664", "branches": [ { "messages": [ { "from": { "activity_id": "432124388562400664", "activity_name": "clanguml::t20020::tmain()", "participant_id": "432124388562400664", "participant_name": "clanguml::t20020::tmain()" }, "name": "d1(int,int)", "return_type": "int", "scope": "normal", "source_location": { "column": 9, "file": "../../tests/t20020/t20020.cc", "line": 73, "translation_unit": "../../tests/t20020/t20020.cc" }, "to": { "activity_id": "1780002010052842766", "activity_name": "clanguml::t20020::D::d1(int,int)", "participant_id": "1605914310746811866" }, "type": "message" } ], "type": "consequent" } ], "name": "if", "type": "alt" } ], "start_from": { "id": 432124388562400664, "location": "clanguml::t20020::tmain()" } } ], "using_namespace": "clanguml::t20020" } ```