summaryrefslogtreecommitdiff
path: root/src/lib/eolian_cxx
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/eolian_cxx
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/eolian_cxx')
-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
5 files changed, 73 insertions, 8 deletions
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