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

16 KiB

t20020 - If statement sequence diagram test case

Config

compilation_database_dir: ..
output_directory: puml
diagrams:
  t20020_sequence:
    type: sequence
    glob:
      - ../../tests/t20020/t20020.cc
    include:
      namespaces:
        - clanguml::t20020
    using_namespace:
      - clanguml::t20020
    start_from:
      - function: "clanguml::t20020::tmain()"

Source code

File t20020.cc

#include <cmath>
#include <cstdint>

namespace clanguml {
namespace t20020 {
struct A {
    int a1() { return 0; }
    int a2() { return 1; }
    int a3() { return 2; }
    int a4() { return 3; }
};

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 <typename T> struct D {

    T d1(T x, T y) { return x + y; }
};

int tmain()
{
    A a;
    B b;
    C c;
    D<int> d;

    int result{0};

    if (reinterpret_cast<uint64_t>(&a) % 100 == 0ULL) {
        result = a.a1();
    }
    else if (reinterpret_cast<uint64_t>(&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 UML diagrams

t20020_sequence

Generated JSON models

{
  "diagram_type": "sequence",
  "metadata": {
    "clang_uml_version": "0.3.6-11-g75d1daa",
    "llvm_version": "Ubuntu clang version 15.0.6",
    "schema_version": 1
  },
  "name": "t20020_sequence",
  "participants": [
    {
      "id": "432124388562400664",
      "name": "clanguml::t20020::tmain()",
      "source_location": {
        "file": "../../tests/t20020/t20020.cc",
        "line": 39
      },
      "type": "function"
    },
    {
      "id": "208941846648931609",
      "name": "clanguml::t20020::A",
      "source_location": {
        "file": "../../tests/t20020/t20020.cc",
        "line": 6
      },
      "type": "class"
    },
    {
      "id": "1562462306909405383",
      "name": "clanguml::t20020::C",
      "source_location": {
        "file": "../../tests/t20020/t20020.cc",
        "line": 20
      },
      "type": "class"
    },
    {
      "id": "1342563483612170412",
      "name": "clanguml::t20020::B",
      "source_location": {
        "file": "../../tests/t20020/t20020.cc",
        "line": 13
      },
      "type": "class"
    },
    {
      "id": "1605914310746811866",
      "name": "clanguml::t20020::D<int>",
      "source_location": {
        "file": "../../tests/t20020/t20020.cc",
        "line": 34
      },
      "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": {
                    "file": "../../tests/t20020/t20020.cc",
                    "line": 49
                  },
                  "to": {
                    "activity_id": "43928675765534701",
                    "activity_name": "clanguml::t20020::A::a1()",
                    "participant_id": "208941846648931609"
                  },
                  "type": "message"
                }
              ],
              "type": "consequent"
            },
            {
              "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": {
                            "file": "../../tests/t20020/t20020.cc",
                            "line": 52
                          },
                          "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": {
                            "file": "../../tests/t20020/t20020.cc",
                            "line": 52
                          },
                          "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": {
                            "file": "../../tests/t20020/t20020.cc",
                            "line": 53
                          },
                          "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": {
                            "file": "../../tests/t20020/t20020.cc",
                            "line": 54
                          },
                          "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": {
                            "file": "../../tests/t20020/t20020.cc",
                            "line": 55
                          },
                          "to": {
                            "activity_id": "505760236964179187",
                            "activity_name": "clanguml::t20020::B::b2()",
                            "participant_id": "1342563483612170412"
                          },
                          "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": "a4()",
                  "return_type": "int",
                  "scope": "normal",
                  "source_location": {
                    "file": "../../tests/t20020/t20020.cc",
                    "line": 60
                  },
                  "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": {
            "file": "../../tests/t20020/t20020.cc",
            "line": 63
          },
          "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()",
                  "return_type": "void",
                  "scope": "normal",
                  "source_location": {
                    "file": "../../tests/t20020/t20020.cc",
                    "line": 66
                  },
                  "to": {
                    "activity_id": "1962953889020699702",
                    "activity_name": "clanguml::t20020::C::c1()",
                    "participant_id": "1562462306909405383"
                  },
                  "type": "message"
                },
                {
                  "activity_id": "1962953889020699702",
                  "branches": [
                    {
                      "messages": [
                        {
                          "from": {
                            "activity_id": "1962953889020699702",
                            "activity_name": "clanguml::t20020::C::c1()",
                            "participant_id": "1562462306909405383"
                          },
                          "name": "c2()",
                          "return_type": "_Bool",
                          "scope": "condition",
                          "source_location": {
                            "file": "../../tests/t20020/t20020.cc",
                            "line": 25
                          },
                          "to": {
                            "activity_id": "1224151733617799047",
                            "activity_name": "clanguml::t20020::C::c2()",
                            "participant_id": "1562462306909405383"
                          },
                          "type": "message"
                        },
                        {
                          "from": {
                            "activity_id": "1962953889020699702",
                            "activity_name": "clanguml::t20020::C::c1()",
                            "participant_id": "1562462306909405383"
                          },
                          "name": "log()",
                          "return_type": "void",
                          "scope": "normal",
                          "source_location": {
                            "file": "../../tests/t20020/t20020.cc",
                            "line": 26
                          },
                          "to": {
                            "activity_id": "1108114094862697094",
                            "activity_name": "clanguml::t20020::C::log()",
                            "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": {
                    "file": "../../tests/t20020/t20020.cc",
                    "line": 69
                  },
                  "to": {
                    "activity_id": "1780002010052842766",
                    "activity_name": "clanguml::t20020::D<int>::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"
}