summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx/grammar/c_type.hpp
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-06 02:54:36 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-06 02:54:36 -0300
commit2a3d7860dbc11458425e162cd69ee399e9025251 (patch)
tree84c5b21b644c4cf8806a8eee07b4ed81922c92b4 /src/lib/eolian_cxx/grammar/c_type.hpp
parent4d1b3191d94fcc70472552b1bb554984a9cb0288 (diff)
eolian-cxx: Rewrite to accomodate new features of the C++ binding
Diffstat (limited to 'src/lib/eolian_cxx/grammar/c_type.hpp')
-rw-r--r--src/lib/eolian_cxx/grammar/c_type.hpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/lib/eolian_cxx/grammar/c_type.hpp b/src/lib/eolian_cxx/grammar/c_type.hpp
new file mode 100644
index 0000000000..b963a77873
--- /dev/null
+++ b/src/lib/eolian_cxx/grammar/c_type.hpp
@@ -0,0 +1,74 @@
1#ifndef EOLIAN_CXX_C_TYPE_HH
2#define EOLIAN_CXX_C_TYPE_HH
3
4#include "grammar/generator.hpp"
5#include "grammar/klass_def.hpp"
6#include "grammar/string.hpp"
7
8namespace efl { namespace eolian { namespace grammar { namespace attributes {
9
10struct c_type_visitor
11{
12 std::string const* c_type;
13 typedef std::string result_type;
14 std::string operator()(attributes::klass_name const& name) const
15 {
16 std::string n;
17 as_generator(" ::" << *(string << "_") << string << string << "*")
18 .generate(std::back_insert_iterator<std::string>(n)
19 , std::make_tuple(name.namespaces, name.eolian_name
20 , std::string{is_const(name.base_qualifier) ? " const" : ""})
21 , context_null {});
22 return n;
23 }
24 template <typename T>
25 std::string operator()(T const&) const
26 {
27 return *c_type;
28 }
29};
30
31inline std::string c_type(parameter_def const& param)
32{
33 switch(param.direction)
34 {
35 case parameter_direction::in:
36 return param.type.original_type.visit(c_type_visitor{&param.c_type});
37 case parameter_direction::out:
38 case parameter_direction::inout:
39 return param.type.original_type.visit(c_type_visitor{&param.c_type}) + "*";
40 default:
41 throw std::runtime_error("Unknown parameter direction");
42 };
43}
44
45}
46
47struct c_type_generator
48{
49 template <typename OutputIterator, typename Context>
50 bool generate(OutputIterator sink, attributes::parameter_def const& attribute, Context const& context) const
51 {
52 return as_generator(attributes::c_type(attribute)).generate(sink, attributes::unused, context);
53 }
54 template <typename OutputIterator, typename Context>
55 bool generate(OutputIterator sink, attributes::type_def const& attribute, Context const& context) const
56 {
57 return as_generator(attribute.original_type.visit(attributes::c_type_visitor{&attribute.c_type}))
58 .generate(sink, attributes::unused, context);
59 }
60};
61
62template <>
63struct is_eager_generator<c_type_generator> : std::true_type {};
64
65namespace type_traits {
66template <>
67struct attributes_needed<c_type_generator> : std::integral_constant<int, 1> {};
68}
69
70c_type_generator const c_type;
71
72} } }
73
74#endif