summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-02-28 11:09:38 -0300
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-02-28 12:05:36 -0300
commitf78be36dfea490e62943a751dfee6347f3212a97 (patch)
treeba8863150008ec928573c4c3403fc151a373746d /src/bin/eolian_mono
parenta25c0d713754a7fc153ff83c89212489d72ab4c0 (diff)
efl_csharp: add constant variable generation to C# binding (constants)
Reviewers: lauromoura, q66, bu5hm4n, zmike, cedric, felipealmeida, segfaultxavi Reviewed By: segfaultxavi Subscribers: segfaultxavi, cedric, #reviewers, #committers Tags: #efl_language_bindings Differential Revision: https://phab.enlightenment.org/D8048
Diffstat (limited to 'src/bin/eolian_mono')
-rw-r--r--src/bin/eolian_mono/eolian/mono/generation_contexts.hh1
-rw-r--r--src/bin/eolian_mono/eolian/mono/variable_definition.hh93
-rw-r--r--src/bin/eolian_mono/eolian_mono.cc15
3 files changed, 109 insertions, 0 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
index 9a1493a..5cc57ef 100644
--- a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
+++ b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
@@ -14,6 +14,7 @@ struct class_context
14 enums, 14 enums,
15 function_ptr, 15 function_ptr,
16 alias, 16 alias,
17 variables,
17 }; 18 };
18 wrapper_kind current_wrapper_kind; 19 wrapper_kind current_wrapper_kind;
19}; 20};
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
diff --git a/src/bin/eolian_mono/eolian_mono.cc b/src/bin/eolian_mono/eolian_mono.cc
index 235f250..58c725c 100644
--- a/src/bin/eolian_mono/eolian_mono.cc
+++ b/src/bin/eolian_mono/eolian_mono.cc
@@ -33,6 +33,7 @@
33#include <eolian/mono/marshall_annotation.hh> 33#include <eolian/mono/marshall_annotation.hh>
34#include <eolian/mono/function_pointer.hh> 34#include <eolian/mono/function_pointer.hh>
35#include <eolian/mono/alias_definition.hh> 35#include <eolian/mono/alias_definition.hh>
36#include <eolian/mono/variable_definition.hh>
36 37
37namespace eolian_mono { 38namespace eolian_mono {
38 39
@@ -168,6 +169,20 @@ run(options_type const& opts)
168 } 169 }
169 } 170 }
170 171
172 // Constants
173 {
174 auto var_cxt = context_add_tag(class_context{class_context::variables}, context);
175 for (efl::eina::iterator<const Eolian_Variable> var_iterator( ::eolian_state_constants_by_file_get(opts.state, basename_input.c_str()))
176 , var_last; var_iterator != var_last; ++var_iterator)
177 {
178 efl::eolian::grammar::attributes::variable_def var(&*var_iterator, opts.unit);
179 if (!eolian_mono::constant_definition.generate(iterator, var, var_cxt))
180 {
181 throw std::runtime_error("Failed to generate enum");
182 }
183 }
184 }
185
171 if (klass) 186 if (klass)
172 { 187 {
173 efl::eolian::grammar::attributes::klass_def klass_def(klass, opts.unit); 188 efl::eolian::grammar::attributes::klass_def klass_def(klass, opts.unit);