summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/part_implementation.hpp
blob: d88ae05b921a277f984f72e61f7491593c4fa191 (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
#ifndef EOLIAN_CXX_PART_IMPLEMENTATION_HH
#define EOLIAN_CXX_PART_IMPLEMENTATION_HH

#include "grammar/generator.hpp"

#include "grammar/string.hpp"
#include "grammar/indentation.hpp"
#include "grammar/list.hpp"
#include "grammar/alternative.hpp"
#include "grammar/type.hpp"
#include "grammar/parameter.hpp"
#include "grammar/keyword.hpp"

namespace efl { namespace eolian { namespace grammar {

struct part_implementation_generator
{
   part_implementation_generator(std::string const& _klass_name)
      : klass_name(_klass_name) {}

   template <typename OutputIterator, typename Context>
   bool generate(OutputIterator sink, attributes::part_def const& part, Context const& ctx) const
   {
      if(!as_generator("#ifdef EFL_CXXPERIMENTAL\n").generate(sink, attributes::unused, ctx))
        return false;

      if(!as_generator("::efl::eolian::return_traits<::" << *(string << "::"))
            .generate(sink, part.klass.namespaces, add_lower_case_context(ctx)))
        return false;
      // FIXME: part_def can't depend on klass_def so C type is not known :(
      if(!as_generator(string << ">::type "<< string << "::" << string << "() const\n{\n"
                       << scope_tab << "::Eo *__return_value = ::efl_part"
                       << "(this->_eo_ptr(), \"" << string << "\");\n"
                       << scope_tab << "::___efl_auto_unref_set(__return_value, false);\n")
            .generate(sink, std::make_tuple(part.klass.eolian_name, klass_name, part.name, part.name), ctx))
        return false;
      if(!as_generator(scope_tab << "return ::" << *(string << "::"))
            .generate(sink, part.klass.namespaces, add_lower_case_context(ctx)))
        return false;
      if(!as_generator(string << "{__return_value};\n}\n")
            .generate(sink, part.klass.eolian_name, ctx))
        return false;

      if(!as_generator("#endif\n").generate(sink, attributes::unused, ctx))
        return false;

      return true;
   }

private:
   std::string klass_name;
};

template <>
struct is_eager_generator<part_implementation_generator> : std::true_type {};
template <>
struct is_generator<part_implementation_generator> : std::true_type {};
namespace type_traits {
template <>
struct attributes_needed<part_implementation_generator> : std::integral_constant<int, 1> {};
}

struct part_implementation_terminal
{
  part_implementation_generator operator()(std::string klass_name) const
  {
    return part_implementation_generator{klass_name};
  }
} const part_implementation = {};

} } }

#endif