diff options
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/type.hh')
-rw-r--r-- | src/bin/eolian_mono/eolian/mono/type.hh | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/type.hh b/src/bin/eolian_mono/eolian/mono/type.hh new file mode 100644 index 0000000000..b0e14516ce --- /dev/null +++ b/src/bin/eolian_mono/eolian/mono/type.hh | |||
@@ -0,0 +1,68 @@ | |||
1 | #ifndef EOLIAN_MONO_TYPE_HH | ||
2 | #define EOLIAN_MONO_TYPE_HH | ||
3 | |||
4 | #include "grammar/generator.hpp" | ||
5 | #include "grammar/klass_def.hpp" | ||
6 | #include "grammar/case.hpp" | ||
7 | |||
8 | namespace eolian_mono { | ||
9 | |||
10 | namespace attributes = efl::eolian::grammar::attributes; | ||
11 | |||
12 | template <typename OutputIterator, typename Context> | ||
13 | struct visitor_generate; | ||
14 | |||
15 | struct type_generator | ||
16 | { | ||
17 | type_generator(bool is_return = false) | ||
18 | : is_return(is_return) {} | ||
19 | |||
20 | template <typename OutputIterator, typename Context> | ||
21 | bool generate(OutputIterator sink, attributes::type_def const& type, Context const& context) const | ||
22 | { | ||
23 | return type.original_type.visit(visitor_generate<OutputIterator, Context>{sink, &context, type.c_type, false, is_return}); | ||
24 | } | ||
25 | template <typename OutputIterator, typename Context> | ||
26 | bool generate(OutputIterator sink, attributes::parameter_def const& param, Context const& context) const | ||
27 | { | ||
28 | return param.type.original_type.visit(visitor_generate<OutputIterator, Context>{sink, &context, param.type.c_type | ||
29 | , param.direction != attributes::parameter_direction::in, false}); | ||
30 | } | ||
31 | |||
32 | bool is_return; | ||
33 | }; | ||
34 | |||
35 | struct type_terminal | ||
36 | { | ||
37 | type_generator const operator()(bool is_return) const | ||
38 | { | ||
39 | return type_generator(is_return); | ||
40 | } | ||
41 | } const type = {}; | ||
42 | |||
43 | type_generator const as_generator(type_terminal) | ||
44 | { | ||
45 | return type_generator{}; | ||
46 | } | ||
47 | |||
48 | } | ||
49 | |||
50 | namespace efl { namespace eolian { namespace grammar { | ||
51 | |||
52 | template <> | ||
53 | struct is_eager_generator< ::eolian_mono::type_generator> : std::true_type {}; | ||
54 | template <> | ||
55 | struct is_generator< ::eolian_mono::type_generator> : std::true_type {}; | ||
56 | template <> | ||
57 | struct is_generator< ::eolian_mono::type_terminal> : std::true_type {}; | ||
58 | |||
59 | namespace type_traits { | ||
60 | template <> | ||
61 | struct attributes_needed< ::eolian_mono::type_generator> : std::integral_constant<int, 1> {}; | ||
62 | template <> | ||
63 | struct attributes_needed< ::eolian_mono::type_terminal> : std::integral_constant<int, 1> {}; | ||
64 | } | ||
65 | |||
66 | } } } | ||
67 | |||
68 | #endif | ||