aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/cc/utility.ixx
blob: 46a4d0de1251a3cd509891d7bc261ac8a03f6157 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// file      : libbuild2/cc/utility.ixx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

namespace build2
{
  namespace cc
  {
    inline otype
    compile_type (const target_type& t, optional<unit_type> u)
    {
      using namespace bin;

      auto test = [&t, u] (const auto& h, const auto& i, const auto& o)
      {
        return (u
                ? t.is_a (*u == unit_type::module_header ? h :
                          *u == unit_type::module_iface  ? i : o)
                : t.is_a (h) || t.is_a (i) || t.is_a (o));
      };

      return
        test (hbmie::static_type, bmie::static_type, obje::static_type) ? otype::e :
        test (hbmis::static_type, bmis::static_type, objs::static_type) ? otype::s :
        test (hbmia::static_type, bmia::static_type, obja::static_type) ? otype::a :
        static_cast<otype> (0xFF);
    }

    inline compile_target_types
    compile_types (otype t)
    {
      using namespace bin;

      const target_type* o (nullptr);
      const target_type* i (nullptr);
      const target_type* h (nullptr);

      switch (t)
      {
      case otype::e:
        o = &obje::static_type;
        i = &bmie::static_type;
        h = &hbmie::static_type;
        break;
      case otype::a:
        o = &obja::static_type;
        i = &bmia::static_type;
        h = &hbmia::static_type;
        break;
      case otype::s:
        o = &objs::static_type;
        i = &bmis::static_type;
        h = &hbmis::static_type;
        break;
      }

      return compile_target_types {*o, *i, *h};
    }
  }
}