summaryrefslogtreecommitdiff
path: root/cli/inline.cxx
blob: 37c4a4692591c947385413fa56bec88baa3034e7 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// file      : cli/inline.cxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
// license   : MIT; see accompanying LICENSE file

#include <cli/inline.hxx>

namespace
{
  //
  //
  struct option: traversal::option, context
  {
    option (context& c) : context (c) {}

    virtual void
    traverse (type& o)
    {
      string name (ename (o));
      string type (o.type ().name ());
      string scope (escape (o.scope ().name ()));

      os << inl << "const " << type << "& " << scope << "::" << endl
         << name << " () const"
         << "{"
         << "return this->" << emember (o) << ";"
         << "}";

      if (modifier)
      {
        os << inl << type << "& " << scope << "::" << endl
           << name << " ()"
           << "{"
           << "return this->" << emember (o) << ";"
           << "}";

        os << inl << "void " << scope << "::" << endl
           << name << "(const " << type << "& x)"
           << "{"
           << "this->" << emember (o) << " = x;"
           << "}";
      }

      if (specifier && type != "bool")
      {
        string spec (especifier (o));

        os << inl << "bool " << scope << "::" << endl
           << spec << " () const"
           << "{"
           << "return this->" << especifier_member (o) << ";"
           << "}";

        if (modifier)
          os << inl << "void " << scope << "::" << endl
             << spec << "(bool x)"
             << "{"
             << "this->" << especifier_member (o) << " = x;"
             << "}";
      }
    }
  };

  //
  //
  struct class_: traversal::class_, context
  {
    class_ (context& c)
        : context (c), option_ (c)
    {
      names_option_ >> option_;
    }

    virtual void
    traverse (type& c)
    {
      string name (escape (c.name ()));

      os << "// " << name << endl
         << "//" << endl
         << endl;

      names (c, names_option_);
    }

  private:
    option option_;
    traversal::names names_option_;
  };
}

void
generate_inline (context& ctx)
{
  traversal::cli_unit unit;
  traversal::names unit_names;
  namespace_ ns (ctx);
  class_ cl (ctx);

  unit >> unit_names >> ns;
  unit_names >> cl;

  traversal::names ns_names;

  ns >> ns_names >> ns;
  ns_names >> cl;

  unit.dispatch (ctx.unit);
}