summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/address_of.hpp
blob: 41a027667c30e777e246637420007c7772164836 (plain) (blame)
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
#ifndef EOLIAN_CXX_ADDRESS_OF_HH
#define EOLIAN_CXX_ADDRESS_OF_HH

#include "grammar/generator.hpp"
#include "grammar/klass_def.hpp"

#include "grammar/indentation.hpp"
#include "grammar/list.hpp"
#include "grammar/alternative.hpp"
#include "grammar/type.hpp"
#include "grammar/parameter.hpp"
#include "grammar/function_declaration.hpp"
#include "grammar/case.hpp"

namespace efl { namespace eolian { namespace grammar {

struct address_of_generator
{
   template <typename OutputIterator, typename Context>
   bool generate(OutputIterator sink, attributes::klass_def const& cls, Context const& context) const
   {
     std::vector<std::string> cpp_namespaces = attributes::cpp_namespaces(cls.namespaces);

     if(!as_generator
        (
         scope_tab << " ::efl::eolian::address_of_operator<" << string
        ).generate(sink, cls.cxx_name, context)) return false;

     for(auto&& i : cls.inherits)
       {
         if(!as_generator(",  " << *("::" << lower_case[string]) << "::" << string)
            .generate(sink, std::make_tuple(attributes::cpp_namespaces(i.namespaces), i.eolian_name), context))
           return false;
       }

      if(!as_generator
         (
           "> operator&() { return {this}; }\n"
         ).generate(sink, attributes::unused, context)) return false;

     if(!as_generator
        (
         scope_tab << " ::efl::eolian::address_of_operator<" << string << " const "
        ).generate(sink, cls.cxx_name, context)) return false;

     for(auto&& i : cls.inherits)
       {
         if(!as_generator(",  " << *("::" << lower_case[string]) << "::" << string << " const ")
            .generate(sink, std::make_tuple(attributes::cpp_namespaces(i.namespaces), i.eolian_name), context))
           return false;
       }

      if(!as_generator
         (
           "> operator&() const { return {this}; }\n"
         ).generate(sink, attributes::unused, context)) return false;
      
      return true;
   }
};

template <>
struct is_eager_generator<address_of_generator> : std::true_type {};

namespace type_traits {
template <>
struct attributes_needed<address_of_generator> : std::integral_constant<int, 1> {};
}
      
address_of_generator const address_of;
      
} } }

#endif