summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-01-18 22:25:02 -0200
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-01-18 22:47:04 -0200
commita1f2db255b22052050baf0c04bb72146b22a6e99 (patch)
tree8499c057a7a0054f75fe3ab4719b2cc3659949d5 /src/lib
parent7f148feea8275d4ae3a366e5aead8170498089a6 (diff)
cxx: Modify how to generate C++ headers and allow cyclic dependencies
Allow cyclic dependencies in generated C++ headers by changing order of includes and creating forward declarations.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/.gitignore13
-rw-r--r--src/lib/edje/Edje.hh9
-rw-r--r--src/lib/efl/.gitignore1
-rw-r--r--src/lib/efl/Efl.hh11
-rw-r--r--src/lib/eio/Eio.hh9
-rw-r--r--src/lib/elementary/.gitignore1
-rw-r--r--src/lib/elementary/Elementary.hh26
-rw-r--r--src/lib/eolian_cxx/grammar/class_declaration.hpp16
-rw-r--r--src/lib/eolian_cxx/grammar/header.hpp3
-rw-r--r--src/lib/eolian_cxx/grammar/implementation_include_directive.hpp6
-rw-r--r--src/lib/eolian_cxx/grammar/keyword.hpp2
-rw-r--r--src/lib/eolian_cxx/grammar/klass_def.hpp54
-rw-r--r--src/lib/evas/Evas.hh9
13 files changed, 144 insertions, 16 deletions
diff --git a/src/lib/.gitignore b/src/lib/.gitignore
index 190a85e1d6..aaec4c069e 100644
--- a/src/lib/.gitignore
+++ b/src/lib/.gitignore
@@ -1,11 +1,12 @@
1/ecore_x/ecore_x_version.h 1/ecore_x/ecore_x_version.h
2/efl/Efl_Config.h 2/efl/Efl_Config.h
3/efl/Efl.hh
4/eina/eina_config.h 3/eina/eina_config.h
5/ecore_audio/Ecore_Audio.hh
6/ecore/Ecore.eo.hh 4/ecore/Ecore.eo.hh
7/evas/Evas.hh
8/edje/Edje.hh
9/edje/Edje.eo.hh 5/edje/Edje.eo.hh
10/eio/Eio.hh 6/eio/Eio.eo.hh
11/eldbus/Eldbus_Model.hh 7/elementary/Elementary.eo.hh
8/evas/Evas.eo.hh
9/efl/Efl.eo.hh
10/eldbus/Eldbus_Model.eo.hh
11
12
diff --git a/src/lib/edje/Edje.hh b/src/lib/edje/Edje.hh
new file mode 100644
index 0000000000..4550181ac8
--- /dev/null
+++ b/src/lib/edje/Edje.hh
@@ -0,0 +1,9 @@
1#ifndef EFL_CXX_EDJE_HH
2#define EFL_CXX_EDJE_HH
3
4#ifdef EFL_BETA_API_SUPPORT
5
6#include <Edje.eo.hh>
7
8#endif
9#endif
diff --git a/src/lib/efl/.gitignore b/src/lib/efl/.gitignore
index 3732c0ce33..e69de29bb2 100644
--- a/src/lib/efl/.gitignore
+++ b/src/lib/efl/.gitignore
@@ -1 +0,0 @@
1Efl.hh
diff --git a/src/lib/efl/Efl.hh b/src/lib/efl/Efl.hh
new file mode 100644
index 0000000000..20dfc1a90d
--- /dev/null
+++ b/src/lib/efl/Efl.hh
@@ -0,0 +1,11 @@
1#ifndef EFL_EFL_HH
2#define EFL_EFL_HH
3
4#ifdef EFL_BETA_API_SUPPORT
5
6#include <Efl.eo.hh>
7
8#endif
9#endif
10
11
diff --git a/src/lib/eio/Eio.hh b/src/lib/eio/Eio.hh
new file mode 100644
index 0000000000..78c0f391d8
--- /dev/null
+++ b/src/lib/eio/Eio.hh
@@ -0,0 +1,9 @@
1#ifndef EFL_CXX_EIO_HH
2#define EFL_CXX_EIO_HH
3#ifdef EFL_BETA_API_SUPPORT
4
5#include "Eio.eo.hh"
6
7#endif
8#endif
9
diff --git a/src/lib/elementary/.gitignore b/src/lib/elementary/.gitignore
index 089c32dd72..9076648525 100644
--- a/src/lib/elementary/.gitignore
+++ b/src/lib/elementary/.gitignore
@@ -1,4 +1,3 @@
1/Elementary.hh
2/Elementary_Options.h 1/Elementary_Options.h
3/elm_intro.h 2/elm_intro.h
4/*.eo.c 3/*.eo.c
diff --git a/src/lib/elementary/Elementary.hh b/src/lib/elementary/Elementary.hh
new file mode 100644
index 0000000000..215632bb10
--- /dev/null
+++ b/src/lib/elementary/Elementary.hh
@@ -0,0 +1,26 @@
1#ifndef EFL_CXX_ELEMENTARY_HH
2#define EFL_CXX_ELEMENTARY_HH
3#if defined(ELEMENTARY_H) || defined(ELM_WIDGET_H)
4#error "Do not include Elm C API headers before including Elementary.hh"
5#endif
6
7#ifndef EFL_BETA_API_SUPPORT
8#define EFL_BETA_API_SUPPORT
9#endif
10#ifndef EFL_EO_API_SUPPORT
11#define EFL_EO_API_SUPPORT
12#endif
13#ifndef ELM_INTERNAL_API_ARGESFSDFEFC
14#define ELM_INTERNAL_API_ARGESFSDFEFC
15#endif
16
17#include <Efl.hh>
18
19extern "C" {
20#include "Elementary.h"
21#include "elm_widget.h"
22}
23
24#include "Elementary.eo.hh"
25
26#endif
diff --git a/src/lib/eolian_cxx/grammar/class_declaration.hpp b/src/lib/eolian_cxx/grammar/class_declaration.hpp
index 6f23641e4d..bed1a5696f 100644
--- a/src/lib/eolian_cxx/grammar/class_declaration.hpp
+++ b/src/lib/eolian_cxx/grammar/class_declaration.hpp
@@ -15,6 +15,8 @@ namespace efl { namespace eolian { namespace grammar {
15 15
16struct class_declaration_generator 16struct class_declaration_generator
17{ 17{
18 bool type_traits;
19
18 template <typename OutputIterator, typename Context> 20 template <typename OutputIterator, typename Context>
19 bool generate(OutputIterator sink, attributes::klass_def const& cls, Context const& context) const 21 bool generate(OutputIterator sink, attributes::klass_def const& cls, Context const& context) const
20 { 22 {
@@ -30,11 +32,12 @@ struct class_declaration_generator
30 auto close_namespace = *(lit("} ")) << "\n"; 32 auto close_namespace = *(lit("} ")) << "\n";
31 if(!as_generator(close_namespace).generate(sink, cpp_namespaces, context)) return false; 33 if(!as_generator(close_namespace).generate(sink, cpp_namespaces, context)) return false;
32 34
33 if(!as_generator 35 if(type_traits)
34 ( 36 if(!as_generator
35 "namespace efl { namespace eo { template<> struct is_eolian_object< " 37 (
36 "::" << *(lower_case[string] << "::") << string << "> : ::std::true_type {}; } }\n" 38 "namespace efl { namespace eo { template<> struct is_eolian_object< "
37 ).generate(sink, std::make_tuple(cpp_namespaces, cls.cxx_name), context)) return false; 39 "::" << *(lower_case[string] << "::") << string << "> : ::std::true_type {}; } }\n"
40 ).generate(sink, std::make_tuple(cpp_namespaces, cls.cxx_name), context)) return false;
38 41
39 42
40 return true; 43 return true;
@@ -49,7 +52,8 @@ template <>
49struct attributes_needed<class_declaration_generator> : std::integral_constant<int, 1> {}; 52struct attributes_needed<class_declaration_generator> : std::integral_constant<int, 1> {};
50} 53}
51 54
52class_declaration_generator const class_declaration = {}; 55class_declaration_generator const class_declaration = {true};
56class_declaration_generator const class_forward_declaration = {false};
53 57
54} } } 58} } }
55 59
diff --git a/src/lib/eolian_cxx/grammar/header.hpp b/src/lib/eolian_cxx/grammar/header.hpp
index 96e123593c..63a6095949 100644
--- a/src/lib/eolian_cxx/grammar/header.hpp
+++ b/src/lib/eolian_cxx/grammar/header.hpp
@@ -25,11 +25,12 @@ auto class_header =
25 "#include <Eo.hh>\n" 25 "#include <Eo.hh>\n"
26 << *header_include_directive // sequence<string> 26 << *header_include_directive // sequence<string>
27 << *class_declaration // sequence<class> | class 27 << *class_declaration // sequence<class> | class
28 << *class_forward_declaration // sequence<class> | class
28 << "\nnamespace eo_cxx {\n" 29 << "\nnamespace eo_cxx {\n"
29 << *base_class_definition // sequence<class> | class 30 << *base_class_definition // sequence<class> | class
30 << "}\n" 31 << "}\n"
31 << *class_definition // sequence<class> | class 32 << *class_definition // sequence<class> | class
32 << *implementation_include_directive 33 // << *implementation_include_directive
33 ] 34 ]
34 ; 35 ;
35 36
diff --git a/src/lib/eolian_cxx/grammar/implementation_include_directive.hpp b/src/lib/eolian_cxx/grammar/implementation_include_directive.hpp
index dab1e0a7e9..6c2631ab80 100644
--- a/src/lib/eolian_cxx/grammar/implementation_include_directive.hpp
+++ b/src/lib/eolian_cxx/grammar/implementation_include_directive.hpp
@@ -22,6 +22,12 @@ struct implementation_include_directive_generator
22 return as_generator("#include \"" << string << ".impl.hh\"\n") 22 return as_generator("#include \"" << string << ".impl.hh\"\n")
23 .generate(sink, std::string(eolian_class_file_get(get_klass(get_klass_name(cls)))), add_lower_case_context(ctx)); 23 .generate(sink, std::string(eolian_class_file_get(get_klass(get_klass_name(cls)))), add_lower_case_context(ctx));
24 } 24 }
25 template <typename OutputIterator, typename Context>
26 bool generate(OutputIterator sink, std::string const& cls, Context const& ctx) const
27 {
28 return as_generator("#include \"" << string << ".impl.hh\"\n")
29 .generate(sink, cls, add_lower_case_context(ctx));
30 }
25}; 31};
26 32
27template <> 33template <>
diff --git a/src/lib/eolian_cxx/grammar/keyword.hpp b/src/lib/eolian_cxx/grammar/keyword.hpp
index 9359892f9c..b64201eac3 100644
--- a/src/lib/eolian_cxx/grammar/keyword.hpp
+++ b/src/lib/eolian_cxx/grammar/keyword.hpp
@@ -5,7 +5,7 @@ namespace efl { namespace eolian { namespace grammar {
5 5
6inline std::string escape_keyword(std::string const& name) 6inline std::string escape_keyword(std::string const& name)
7{ 7{
8 if(name == "delete" || name == "register") 8 if(name == "delete" || name == "register" || name == "do")
9 return "cxx_" + name; 9 return "cxx_" + name;
10 return name; 10 return name;
11} 11}
diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp
index 4b9bc48205..c663f289b8 100644
--- a/src/lib/eolian_cxx/grammar/klass_def.hpp
+++ b/src/lib/eolian_cxx/grammar/klass_def.hpp
@@ -315,6 +315,18 @@ struct parameter_def
315 std::string param_name; 315 std::string param_name;
316 std::string c_type; 316 std::string c_type;
317 317
318 friend inline bool operator==(parameter_def const& lhs, parameter_def const& rhs)
319 {
320 return lhs.direction == rhs.direction
321 && lhs.type == rhs.type
322 && lhs.param_name == rhs.param_name
323 && lhs.c_type == rhs.c_type;
324 }
325 friend inline bool operator!=(parameter_def const& lhs, parameter_def const& rhs)
326 {
327 return !(lhs == rhs);
328 }
329
318 parameter_def(parameter_direction direction, type_def type, std::string param_name, std::string c_type) 330 parameter_def(parameter_direction direction, type_def type, std::string param_name, std::string c_type)
319 : direction(std::move(direction)), type(std::move(type)), param_name(std::move(param_name)), c_type(std::move(c_type)) {} 331 : direction(std::move(direction)), type(std::move(type)), param_name(std::move(param_name)), c_type(std::move(c_type)) {}
320 parameter_def(Eolian_Function_Parameter const* param) 332 parameter_def(Eolian_Function_Parameter const* param)
@@ -384,6 +396,20 @@ struct function_def
384 bool is_beta; 396 bool is_beta;
385 bool is_protected; 397 bool is_protected;
386 398
399 friend inline bool operator==(function_def const& lhs, function_def const& rhs)
400 {
401 return lhs.return_type == rhs.return_type
402 && lhs.name == rhs.name
403 && lhs.parameters == rhs.parameters
404 && lhs.c_name == rhs.c_name
405 && lhs.is_beta == rhs.is_beta
406 && lhs.is_protected == rhs.is_protected;
407 }
408 friend inline bool operator!=(function_def const& lhs, function_def const& rhs)
409 {
410 return !(lhs == rhs);
411 }
412
387 function_def(type_def return_type, std::string name, std::vector<parameter_def> parameters 413 function_def(type_def return_type, std::string name, std::vector<parameter_def> parameters
388 , std::string c_name, bool is_beta) 414 , std::string c_name, bool is_beta)
389 : return_type(return_type), name(name), parameters(parameters), c_name(c_name), is_beta(is_beta) {} 415 : return_type(return_type), name(name), parameters(parameters), c_name(c_name), is_beta(is_beta) {}
@@ -504,6 +530,19 @@ struct event_def
504 std::string name, c_name; 530 std::string name, c_name;
505 bool beta, protect; 531 bool beta, protect;
506 532
533 friend inline bool operator==(event_def const& lhs, event_def const& rhs)
534 {
535 return lhs.type == rhs.type
536 && lhs.name == rhs.name
537 && lhs.c_name == rhs.c_name
538 && lhs.beta == rhs.beta
539 && lhs.protect == rhs.protect;
540 }
541 friend inline bool operator!=(event_def const& lhs, event_def const& rhs)
542 {
543 return !(lhs == rhs);
544 }
545
507 event_def(type_def type, std::string name, std::string c_name, bool beta, bool protect) 546 event_def(type_def type, std::string name, std::string c_name, bool beta, bool protect)
508 : type(type), name(name), c_name(c_name), beta(beta), protect(protect) {} 547 : type(type), name(name), c_name(c_name), beta(beta), protect(protect) {}
509 event_def(Eolian_Event const* event) 548 event_def(Eolian_Event const* event)
@@ -558,6 +597,21 @@ struct klass_def
558 class_type type; 597 class_type type;
559 std::vector<event_def> events; 598 std::vector<event_def> events;
560 599
600 friend inline bool operator==(klass_def const& lhs, klass_def const& rhs)
601 {
602 return lhs.eolian_name == rhs.eolian_name
603 && lhs.cxx_name == rhs.cxx_name
604 && lhs.namespaces == rhs.namespaces
605 && lhs.functions == rhs.functions
606 && lhs.inherits == rhs.inherits
607 && lhs.type == rhs.type
608 && lhs.events == rhs.events;
609 }
610 friend inline bool operator!=(klass_def const& lhs, klass_def const& rhs)
611 {
612 return !(lhs == rhs);
613 }
614
561 klass_def(std::string eolian_name, std::string cxx_name 615 klass_def(std::string eolian_name, std::string cxx_name
562 , std::vector<std::string> namespaces 616 , std::vector<std::string> namespaces
563 , std::vector<function_def> functions 617 , std::vector<function_def> functions
diff --git a/src/lib/evas/Evas.hh b/src/lib/evas/Evas.hh
new file mode 100644
index 0000000000..4bef41958f
--- /dev/null
+++ b/src/lib/evas/Evas.hh
@@ -0,0 +1,9 @@
1#ifndef EFL_EVAS_HH
2#define EFL_EVAS_HH
3#ifdef EFL_BETA_API_SUPPORT
4
5#include "Evas.eo.hh"
6
7#endif
8#endif
9