summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/enum_definition.hh
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2017-11-23 21:50:16 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2017-12-04 15:47:50 -0300
commitd93e9ff286ce1961f530d56b5536881f47104ebd (patch)
treed9fd8cd25a64b9ab6b23ae34b92c342dc8e6b543 /src/bin/eolian_mono/eolian/mono/enum_definition.hh
parent9391407319424c503a78479b407737ccead945b7 (diff)
eolian_mono: Added code for eolian_mono generator
Based on the eolian_cxx library generators. Buildsystem files will come in a future commmit.
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/enum_definition.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/enum_definition.hh74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/enum_definition.hh b/src/bin/eolian_mono/eolian/mono/enum_definition.hh
new file mode 100644
index 0000000000..ae9775e71f
--- /dev/null
+++ b/src/bin/eolian_mono/eolian/mono/enum_definition.hh
@@ -0,0 +1,74 @@
1#ifndef EOLIAN_MONO_ENUM_DEFINITION_HH
2#define EOLIAN_MONO_ENUM_DEFINITION_HH
3
4#include "grammar/generator.hpp"
5#include "grammar/klass_def.hpp"
6#include "grammar/indentation.hpp"
7#include "grammar/list.hpp"
8#include "grammar/alternative.hpp"
9#include "type.hh"
10#include "keyword.hh"
11#include "using_decl.hh"
12
13namespace eolian_mono {
14
15struct enum_definition_generator
16{
17 template <typename OutputIterator, typename Context>
18 bool generate(OutputIterator sink, attributes::enum_def const& enum_, Context const& context) const
19 {
20 std::vector<std::string> cpp_namespaces = escape_namespace(attributes::cpp_namespaces(enum_.namespaces));
21
22 auto open_namespace = *("namespace " << string << " { ") << "\n";
23 if(!as_generator(open_namespace).generate(sink, cpp_namespaces, add_lower_case_context(context))) return false;
24
25 if(!as_generator
26 (
27 "public enum " << string << "\n{\n"
28 )
29 .generate(sink, enum_.cxx_name, context))
30 return false;
31
32 // iterate enum fiels
33 for(auto first = std::begin(enum_.fields)
34 , last = std::end(enum_.fields); first != last; ++first)
35 {
36 auto name = (*first).name;
37 auto literal = (*first).value.literal;
38 name[0] = std::toupper(name[0]); // Hack to allow 'static' as a field name
39 if (!as_generator
40 (
41 string << " = " << string << ",\n"
42 )
43 .generate(sink, std::make_tuple(name, literal), context))
44 return false;
45 }
46
47 if(!as_generator("}\n").generate(sink, attributes::unused, context)) return false;
48
49 auto close_namespace = *(lit("} ")) << "\n";
50 if(!as_generator(close_namespace).generate(sink, cpp_namespaces, context)) return false;
51
52 return true;
53 }
54};
55
56enum_definition_generator const enum_definition = {};
57
58}
59
60namespace efl { namespace eolian { namespace grammar {
61
62template <>
63struct is_eager_generator< ::eolian_mono::enum_definition_generator> : std::true_type {};
64template <>
65struct is_generator< ::eolian_mono::enum_definition_generator> : std::true_type {};
66
67namespace type_traits {
68template <>
69struct attributes_needed< ::eolian_mono::enum_definition_generator> : std::integral_constant<int, 1> {};
70}
71
72} } }
73
74#endif