summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/variable_definition.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/variable_definition.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/variable_definition.hh93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/variable_definition.hh b/src/bin/eolian_mono/eolian/mono/variable_definition.hh
new file mode 100644
index 0000000..2a0eac3
--- /dev/null
+++ b/src/bin/eolian_mono/eolian/mono/variable_definition.hh
@@ -0,0 +1,93 @@
1#ifndef EOLIAN_MONO_VARIABLE_DEFINITION_HH
2#define EOLIAN_MONO_VARIABLE_DEFINITION_HH
3
4#include <Eina.hh>
5
6#include "grammar/generator.hpp"
7#include "grammar/klass_def.hpp"
8
9#include "grammar/indentation.hpp"
10#include "grammar/list.hpp"
11#include "grammar/alternative.hpp"
12#include "grammar/attribute_reorder.hpp"
13#include "logging.hh"
14#include "type.hh"
15#include "name_helpers.hh"
16#include "helpers.hh"
17#include "function_helpers.hh"
18#include "marshall_type.hh"
19#include "parameter.hh"
20#include "documentation.hh"
21#include "using_decl.hh"
22#include "generation_contexts.hh"
23#include "blacklist.hh"
24
25namespace eolian_mono {
26
27
28struct constant_definition_generator
29{
30 template<typename OutputIterator, typename Context>
31 bool generate(OutputIterator sink, attributes::variable_def constant, Context context) const
32 {
33 // Open partial class
34 if (!name_helpers::open_namespaces(sink, constant.namespaces, context))
35 return false;
36
37 if (!as_generator("public partial class Constants {\n").generate(sink, attributes::unused, context))
38 return false;
39
40 std::string literal;
41 if (constant.expression_value.type == EOLIAN_EXPR_NULL)
42 literal = "null";
43 else if (constant.expression_value.type == EOLIAN_EXPR_BOOL)
44 literal = (constant.expression_value.value.b ? "true" : "false");
45 else
46 {
47 auto lit = ::eolian_expression_value_to_literal(&constant.expression_value);
48 if (!lit)
49 return false;
50 literal = lit;
51 ::eina_stringshare_del(lit);
52 }
53
54 // declare variable
55 if (!as_generator(scope_tab(1)
56 << "public static readonly " << type
57 << " " << utils::remove_all(constant.name, '_')
58 << " = " << literal << ";\n")
59 .generate(sink, constant.base_type, context))
60 return false;
61
62 // FIXME missing documentation generator
63
64 // Close partial class
65 if (!as_generator("}\n").generate(sink, attributes::unused, context))
66 return false;
67
68 if (!name_helpers::close_namespaces(sink, constant.namespaces, context))
69 return false;
70
71 return true;
72
73
74 }
75} const constant_definition;
76
77}
78
79namespace efl { namespace eolian { namespace grammar {
80
81template <>
82struct is_eager_generator< ::eolian_mono::constant_definition_generator> : std::true_type {};
83template <>
84struct is_generator< ::eolian_mono::constant_definition_generator> : std::true_type {};
85
86namespace type_traits {
87template <>
88struct attributes_needed< ::eolian_mono::constant_definition_generator> : std::integral_constant<int, 1> {};
89}
90
91} } }
92
93#endif