Files
clang-uml/docs/test_cases/t20028.md
2023-08-05 19:34:03 +02:00

6.2 KiB

t20028 - Conditional (ternary) '?:' operator test case

Config

compilation_database_dir: ..
output_directory: puml
diagrams:
  t20028_sequence:
    type: sequence
    glob:
      - ../../tests/t20028/t20028.cc
    include:
      namespaces:
        - clanguml::t20028
    exclude:
      namespaces:
        - clanguml::t20028::detail
    using_namespace:
      - clanguml::t20028
    start_from:
      - function: "clanguml::t20028::tmain()"

Source code

File t20028.cc

namespace clanguml {
namespace t20028 {

struct A {
    int a() { return 0; }
    int b() { return 1; }
    int c() { return 2; }
    int d() { return 3; }
};

namespace detail {
struct B {
    int e() { return 4; }
};
} // namespace detail

int tmain()
{
    A a;
    detail::B b;

    int result{};

    result = b.e() ? b.e() : 12;

    result += a.a() ? a.b() + a.c() : a.d();

    return result;
}
}
}

Generated UML diagrams

t20028_sequence

Generated JSON models

{
  "diagram_type": "sequence",
  "metadata": {
    "clang_uml_version": "0.3.8-13-g2e1013c",
    "llvm_version": "Ubuntu clang version 15.0.7",
    "schema_version": 1
  },
  "name": "t20028_sequence",
  "participants": [
    {
      "id": "1347206662193933194",
      "name": "clanguml::t20028::tmain()",
      "source_location": {
        "column": 5,
        "file": "../../tests/t20028/t20028.cc",
        "line": 17,
        "translation_unit": "../../tests/t20028/t20028.cc"
      },
      "type": "function"
    },
    {
      "id": "2073479923903128898",
      "name": "clanguml::t20028::A",
      "source_location": {
        "column": 8,
        "file": "../../tests/t20028/t20028.cc",
        "line": 4,
        "translation_unit": "../../tests/t20028/t20028.cc"
      },
      "type": "class"
    }
  ],
  "sequences": [
    {
      "messages": [
        {
          "activity_id": "1347206662193933194",
          "branches": [
            {
              "messages": [
                {
                  "from": {
                    "activity_id": "1347206662193933194",
                    "activity_name": "clanguml::t20028::tmain()",
                    "participant_id": "1347206662193933194",
                    "participant_name": "clanguml::t20028::tmain()"
                  },
                  "name": "a()",
                  "return_type": "int",
                  "scope": "condition",
                  "source_location": {
                    "column": 15,
                    "file": "../../tests/t20028/t20028.cc",
                    "line": 26,
                    "translation_unit": "../../tests/t20028/t20028.cc"
                  },
                  "to": {
                    "activity_id": "666210834901940781",
                    "activity_name": "clanguml::t20028::A::a()",
                    "participant_id": "2073479923903128898"
                  },
                  "type": "message"
                },
                {
                  "from": {
                    "activity_id": "1347206662193933194",
                    "activity_name": "clanguml::t20028::tmain()",
                    "participant_id": "1347206662193933194",
                    "participant_name": "clanguml::t20028::tmain()"
                  },
                  "name": "b()",
                  "return_type": "int",
                  "scope": "normal",
                  "source_location": {
                    "column": 23,
                    "file": "../../tests/t20028/t20028.cc",
                    "line": 26,
                    "translation_unit": "../../tests/t20028/t20028.cc"
                  },
                  "to": {
                    "activity_id": "793793464184037795",
                    "activity_name": "clanguml::t20028::A::b()",
                    "participant_id": "2073479923903128898"
                  },
                  "type": "message"
                },
                {
                  "from": {
                    "activity_id": "1347206662193933194",
                    "activity_name": "clanguml::t20028::tmain()",
                    "participant_id": "1347206662193933194",
                    "participant_name": "clanguml::t20028::tmain()"
                  },
                  "name": "c()",
                  "return_type": "int",
                  "scope": "normal",
                  "source_location": {
                    "column": 31,
                    "file": "../../tests/t20028/t20028.cc",
                    "line": 26,
                    "translation_unit": "../../tests/t20028/t20028.cc"
                  },
                  "to": {
                    "activity_id": "1582152567698110078",
                    "activity_name": "clanguml::t20028::A::c()",
                    "participant_id": "2073479923903128898"
                  },
                  "type": "message"
                }
              ],
              "type": "consequent"
            },
            {
              "messages": [
                {
                  "from": {
                    "activity_id": "1347206662193933194",
                    "activity_name": "clanguml::t20028::tmain()",
                    "participant_id": "1347206662193933194",
                    "participant_name": "clanguml::t20028::tmain()"
                  },
                  "name": "d()",
                  "return_type": "int",
                  "scope": "normal",
                  "source_location": {
                    "column": 39,
                    "file": "../../tests/t20028/t20028.cc",
                    "line": 26,
                    "translation_unit": "../../tests/t20028/t20028.cc"
                  },
                  "to": {
                    "activity_id": "1178268687951492696",
                    "activity_name": "clanguml::t20028::A::d()",
                    "participant_id": "2073479923903128898"
                  },
                  "type": "message"
                }
              ],
              "type": "alternative"
            }
          ],
          "name": "conditional",
          "type": "alt"
        }
      ],
      "start_from": {
        "id": 1347206662193933194,
        "location": "clanguml::t20028::tmain()"
      }
    }
  ],
  "using_namespace": "clanguml::t20028"
}