diff options
-rw-r--r-- | src/lib/eolian_cxx/grammar/address_of.hpp | 9 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/base_class_definition.hpp | 7 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/c_type.hpp | 1 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/class_declaration.hpp | 10 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/class_definition.hpp | 53 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/class_implementation.hpp | 4 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/cxx_class_name.hpp | 37 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/function_definition.hpp | 3 | ||||
-rw-r--r-- | src/lib/eolian_cxx/grammar/type_impl.hpp | 3 |
9 files changed, 85 insertions, 42 deletions
diff --git a/src/lib/eolian_cxx/grammar/address_of.hpp b/src/lib/eolian_cxx/grammar/address_of.hpp index 6c6b977ca3..cdedf8a3f5 100644 --- a/src/lib/eolian_cxx/grammar/address_of.hpp +++ b/src/lib/eolian_cxx/grammar/address_of.hpp @@ -11,6 +11,7 @@ #include "grammar/parameter.hpp" #include "grammar/function_declaration.hpp" #include "grammar/case.hpp" +#include "grammar/cxx_class_name.hpp" namespace efl { namespace eolian { namespace grammar { @@ -23,12 +24,12 @@ struct address_of_generator if(!as_generator ( - scope_tab << " ::efl::eolian::address_of_operator<" << string + scope_tab << " ::efl::eolian::address_of_operator<" << cxx_class_name ).generate(sink, cls.cxx_name, context)) return false; for(auto&& i : cls.inherits) { - if(!as_generator(", " << *("::" << lower_case[string]) << "::" << string) + if(!as_generator(", " << *("::" << lower_case[string]) << "::" << cxx_class_name) .generate(sink, std::make_tuple(attributes::cpp_namespaces(i.namespaces), i.eolian_name), context)) return false; } @@ -40,12 +41,12 @@ struct address_of_generator if(!as_generator ( - scope_tab << " ::efl::eolian::address_of_operator<" << string << " const " + scope_tab << " ::efl::eolian::address_of_operator<" << cxx_class_name << " const " ).generate(sink, cls.cxx_name, context)) return false; for(auto&& i : cls.inherits) { - if(!as_generator(", " << *("::" << lower_case[string]) << "::" << string << " const ") + if(!as_generator(", " << *("::" << lower_case[string]) << "::" << cxx_class_name << " const ") .generate(sink, std::make_tuple(attributes::cpp_namespaces(i.namespaces), i.eolian_name), context)) return false; } diff --git a/src/lib/eolian_cxx/grammar/base_class_definition.hpp b/src/lib/eolian_cxx/grammar/base_class_definition.hpp index f8a704d4fd..233cc03a5d 100644 --- a/src/lib/eolian_cxx/grammar/base_class_definition.hpp +++ b/src/lib/eolian_cxx/grammar/base_class_definition.hpp @@ -15,6 +15,7 @@ #include "grammar/address_of.hpp" #include "grammar/attribute_reorder.hpp" #include "grammar/part_declaration.hpp" +#include "grammar/cxx_class_name.hpp" namespace efl { namespace eolian { namespace grammar { @@ -31,7 +32,7 @@ struct base_class_definition_generator if(!as_generator ( - "struct " << string << " {\n" + "struct " << cxx_class_name << " {\n" ).generate(sink, cls.cxx_name, context)) return false; if(!as_generator(*(function_declaration(get_klass_name(cls)))) @@ -70,14 +71,14 @@ struct base_class_definition_generator if(!as_generator( scope_tab << "Eo* _eo_ptr() const { return *(reinterpret_cast<Eo **>" - << "(const_cast<" << string << " *>(this))); }\n" + << "(const_cast<" << cxx_class_name << " *>(this))); }\n" ).generate(sink, cls.cxx_name, context)) return false; // operator ::ns::Class_Name() const; // operator ::ns::Class_Name&(); // operator ::ns::Class_Name const&() const; - auto class_name = *(lit("::") << lower_case[string]) << "::" << string; + auto class_name = *(lit("::") << lower_case[string]) << "::" << cxx_class_name; if(!as_generator ( attribute_reorder<0, 1, 0, 1, 0, 1, 0, 1> diff --git a/src/lib/eolian_cxx/grammar/c_type.hpp b/src/lib/eolian_cxx/grammar/c_type.hpp index e680b38835..8ff3779f18 100644 --- a/src/lib/eolian_cxx/grammar/c_type.hpp +++ b/src/lib/eolian_cxx/grammar/c_type.hpp @@ -4,6 +4,7 @@ #include "grammar/generator.hpp" #include "grammar/klass_def.hpp" #include "grammar/string.hpp" +#include "grammar/cxx_class_name.hpp" namespace efl { namespace eolian { namespace grammar { namespace attributes { diff --git a/src/lib/eolian_cxx/grammar/class_declaration.hpp b/src/lib/eolian_cxx/grammar/class_declaration.hpp index de9c4a69d6..172c07b787 100644 --- a/src/lib/eolian_cxx/grammar/class_declaration.hpp +++ b/src/lib/eolian_cxx/grammar/class_declaration.hpp @@ -39,7 +39,7 @@ struct class_declaration_generator if(!as_generator ( - "struct " << string << ";\n" + "struct " << cxx_class_name << ";\n" ).generate(sink, cls.cxx_name, context)) return false; auto close_namespace = *(lit("} ")) << "\n"; @@ -49,13 +49,13 @@ struct class_declaration_generator if(!as_generator ( "namespace efl { namespace eo { template<> struct is_eolian_object< " - "::" << *(lower_case[string] << "::") << string << "> : ::std::true_type {}; } }\n" + "::" << *(lower_case[string] << "::") << cxx_class_name << "> : ::std::true_type {}; } }\n" "namespace efl { namespace eo { template<> struct is_eolian_object< " - "::" << *(lower_case[string] << "::") << string << "&> : ::std::true_type {}; } }\n" + "::" << *(lower_case[string] << "::") << cxx_class_name << "&> : ::std::true_type {}; } }\n" "namespace efl { namespace eo { template<> struct is_eolian_object< " - "::" << *(lower_case[string] << "::") << string << " const> : ::std::true_type {}; } }\n" + "::" << *(lower_case[string] << "::") << cxx_class_name << " const> : ::std::true_type {}; } }\n" "namespace efl { namespace eo { template<> struct is_eolian_object< " - "::" << *(lower_case[string] << "::") << string << " const&> : ::std::true_type {}; } }\n" + "::" << *(lower_case[string] << "::") << cxx_class_name << " const&> : ::std::true_type {}; } }\n" ).generate(sink, std::make_tuple ( cpp_namespaces, cls.cxx_name, cpp_namespaces, cls.cxx_name diff --git a/src/lib/eolian_cxx/grammar/class_definition.hpp b/src/lib/eolian_cxx/grammar/class_definition.hpp index 89455eda16..75ea06e8cb 100644 --- a/src/lib/eolian_cxx/grammar/class_definition.hpp +++ b/src/lib/eolian_cxx/grammar/class_definition.hpp @@ -16,6 +16,7 @@ #include "grammar/attribute_conditional.hpp" #include "grammar/attribute_replace.hpp" #include "grammar/part_declaration.hpp" +#include "grammar/cxx_class_name.hpp" namespace efl { namespace eolian { namespace grammar { @@ -29,20 +30,20 @@ struct class_definition_generator if(!as_generator(open_namespace).generate(sink, cpp_namespaces, add_lower_case_context(context))) return false; #ifdef USE_EOCXX_INHERIT_ONLY - if(!as_generator("struct " << string << " : private ::efl::eo::concrete\n" + if(!as_generator("struct " << cxx_class_name << " : private ::efl::eo::concrete\n" << scope_tab << ", ::eo_cxx" - << *("::" << lower_case[string]) << "::" << string) + << *("::" << lower_case[string]) << "::" << cxx_class_name) .generate(sink, std::make_tuple(cls.cxx_name, attributes::cpp_namespaces(cls.namespaces), cls.cxx_name), context)) return false; #else - if(!as_generator("struct " << string << " : private ::efl::eo::concrete") + if(!as_generator("struct " << cxx_class_name << " : private ::efl::eo::concrete") .generate(sink, cls.cxx_name, context)) return false; #endif for(auto&& i : cls.inherits) { - if(!as_generator("\n" << scope_tab << ", EO_CXX_INHERIT(" << *("::" << lower_case[string]) << "::" << string << ")") + if(!as_generator("\n" << scope_tab << ", EO_CXX_INHERIT(" << *("::" << lower_case[string]) << "::" << cxx_class_name << ")") .generate(sink, std::make_tuple(attributes::cpp_namespaces(i.namespaces), i.eolian_name), context)) return false; } @@ -50,39 +51,39 @@ struct class_definition_generator // constructors if(!as_generator( - scope_tab << "explicit " << string << "( ::Eo* eo)\n" + scope_tab << "explicit " << cxx_class_name << "( ::Eo* eo)\n" << scope_tab << scope_tab << ": ::efl::eo::concrete(eo) {}\n" - << scope_tab << string << "(std::nullptr_t)\n" + << scope_tab << cxx_class_name << "(std::nullptr_t)\n" << scope_tab << scope_tab << ": ::efl::eo::concrete(nullptr) {}\n" - << scope_tab << "explicit " << string << "() = default;\n" - << scope_tab << string << "(" << string << " const&) = default;\n" - << scope_tab << string << "(" << string << "&&) = default;\n" - << scope_tab << string << "& operator=(" << string << " const&) = default;\n" - << scope_tab << string << "& operator=(" << string << "&&) = default;\n" + << scope_tab << "explicit " << cxx_class_name << "() = default;\n" + << scope_tab << cxx_class_name << "(" << cxx_class_name << " const&) = default;\n" + << scope_tab << cxx_class_name << "(" << cxx_class_name << "&&) = default;\n" + << scope_tab << cxx_class_name << "& operator=(" << cxx_class_name << " const&) = default;\n" + << scope_tab << cxx_class_name << "& operator=(" << cxx_class_name << "&&) = default;\n" << scope_tab << "template <typename Derived>\n" - << scope_tab << string << "(Derived&& derived\n" + << scope_tab << cxx_class_name << "(Derived&& derived\n" << scope_tab << scope_tab << ", typename std::enable_if<\n" << scope_tab << scope_tab << scope_tab << "::efl::eo::is_eolian_object<Derived>::value\n" - << scope_tab << scope_tab << scope_tab << " && std::is_base_of< " << string << ", Derived>::value>::type* = 0)\n" + << scope_tab << scope_tab << scope_tab << " && std::is_base_of< " << cxx_class_name << ", Derived>::value>::type* = 0)\n" << scope_tab << scope_tab << scope_tab << ": ::efl::eo::concrete(derived._eo_ptr()) {}\n\n" ).generate(sink, attributes::make_infinite_tuple(cls.cxx_name), context)) return false; if((cls.type == attributes::class_type::regular) && !as_generator( - scope_tab << string << "( ::efl::eo::instantiate_t)\n" + scope_tab << cxx_class_name << "( ::efl::eo::instantiate_t)\n" << scope_tab << "{\n" << scope_tab << scope_tab << "::efl::eolian::do_eo_add( ::efl::eo::concrete::_eo_raw, ::efl::eo::concrete{nullptr}, _eo_class());\n" << scope_tab << "}\n" << scope_tab << "template <typename T>\n" - << scope_tab << "explicit " << string << "( ::efl::eo::instantiate_t, T&& parent, typename std::enable_if< ::efl::eo::is_eolian_object<T>::value>::type* = 0)\n" + << scope_tab << "explicit " << cxx_class_name << "( ::efl::eo::instantiate_t, T&& parent, typename std::enable_if< ::efl::eo::is_eolian_object<T>::value>::type* = 0)\n" << scope_tab << "{\n" << scope_tab << scope_tab << "::efl::eolian::do_eo_add( ::efl::eo::concrete::_eo_raw, parent, _eo_class());\n" << scope_tab << "}\n" - << scope_tab << "template <typename F> " << string << "( ::efl::eo::instantiate_t, F&& f, typename ::std::enable_if< ::efl::eolian::is_constructor_lambda<F, " << string << " >::value>::type* = 0)\n" + << scope_tab << "template <typename F> " << cxx_class_name << "( ::efl::eo::instantiate_t, F&& f, typename ::std::enable_if< ::efl::eolian::is_constructor_lambda<F, " << cxx_class_name << " >::value>::type* = 0)\n" << scope_tab << "{\n" << scope_tab << scope_tab << "::efl::eolian::do_eo_add( ::efl::eo::concrete::_eo_raw, ::efl::eo::concrete{nullptr}, _eo_class(), *this, std::forward<F>(f));\n" << scope_tab << "}\n" - << scope_tab << "template <typename T, typename F> " << string << "( ::efl::eo::instantiate_t, T&& parent, F&& f, typename ::std::enable_if< ::efl::eolian::is_constructor_lambda<F, " << string << " >::value && ::efl::eo::is_eolian_object<T>::value>::type* = 0)\n" + << scope_tab << "template <typename T, typename F> " << cxx_class_name << "( ::efl::eo::instantiate_t, T&& parent, F&& f, typename ::std::enable_if< ::efl::eolian::is_constructor_lambda<F, " << cxx_class_name << " >::value && ::efl::eo::is_eolian_object<T>::value>::type* = 0)\n" << scope_tab << "{\n" << scope_tab << scope_tab << "::efl::eolian::do_eo_add( ::efl::eo::concrete::_eo_raw, parent, _eo_class(), *this, std::forward<F>(f));\n" << scope_tab << "}\n\n" @@ -131,7 +132,7 @@ struct class_definition_generator if(!as_generator( scope_tab << "Eo* _eo_ptr() const { return *(reinterpret_cast<Eo **>" - << "(const_cast<" << string << " *>(this))); }\n" + << "(const_cast<" << cxx_class_name << " *>(this))); }\n" ).generate(sink, cls.cxx_name, context)) return false; @@ -216,8 +217,8 @@ struct class_definition_generator if(!as_generator("#endif \n").generate(sink, attributes::unused, context)) return false; } - if(!as_generator( scope_tab << "::efl::eo::wref<" << string << "> _get_wref() const { " - "return ::efl::eo::wref<" << string << ">(*this); }\n" + if(!as_generator( scope_tab << "::efl::eo::wref<" << cxx_class_name << "> _get_wref() const { " + "return ::efl::eo::wref<" << cxx_class_name << ">(*this); }\n" ).generate(sink, std::make_tuple(cls.cxx_name, cls.cxx_name), context)) return false; // eo_concrete @@ -235,25 +236,25 @@ struct class_definition_generator // EXPERIMENTAL: wref and implicit conversion to Eo* if(!as_generator("#ifdef EFL_CXXPERIMENTAL\n").generate(sink, attributes::unused, context)) return false; // For easy wref, operator-> in wref needs to also return a pointer type - if(!as_generator( scope_tab << "const " << string << "* operator->() const { return this; }\n" + if(!as_generator( scope_tab << "const " << cxx_class_name << "* operator->() const { return this; }\n" ).generate(sink, std::make_tuple(cls.cxx_name, cls.cxx_name), context)) return false; - if(!as_generator( scope_tab << string << "* operator->() { return this; }\n" + if(!as_generator( scope_tab << cxx_class_name << "* operator->() { return this; }\n" ).generate(sink, std::make_tuple(cls.cxx_name, cls.cxx_name), context)) return false; // For easy interfacing with C: no need to use _eo_ptr() if(!as_generator( scope_tab << "operator Eo*() const { return _eo_ptr(); }\n" ).generate(sink, attributes::unused, context)) return false; if(!as_generator("#endif \n").generate(sink, attributes::unused, context)) return false; - if(!as_generator( scope_tab << "friend bool operator==(" << string << " const& lhs, " << string << " const& rhs)\n" + if(!as_generator( scope_tab << "friend bool operator==(" << cxx_class_name << " const& lhs, " << cxx_class_name << " const& rhs)\n" << scope_tab << "{ return lhs._get_concrete() == rhs._get_concrete(); }\n" - << scope_tab << "friend bool operator!=(" << string << " const& lhs, " << string << " const& rhs)\n" + << scope_tab << "friend bool operator!=(" << cxx_class_name << " const& lhs, " << cxx_class_name << " const& rhs)\n" << scope_tab << "{ return !(lhs == rhs); }\n" << "};\n").generate(sink, attributes::make_infinite_tuple(cls.cxx_name), context)) return false; // static asserts - if(!as_generator("static_assert(sizeof(" << string << ") == sizeof(Eo*), \"\");\n") + if(!as_generator("static_assert(sizeof(" << cxx_class_name << ") == sizeof(Eo*), \"\");\n") .generate(sink, cls.cxx_name, context)) return false; - if(!as_generator("static_assert(std::is_standard_layout<" << string << ">::value, \"\");\n") + if(!as_generator("static_assert(std::is_standard_layout<" << cxx_class_name << ">::value, \"\");\n") .generate(sink, cls.cxx_name, context)) return false; auto close_namespace = *(lit("} ")) << "\n"; diff --git a/src/lib/eolian_cxx/grammar/class_implementation.hpp b/src/lib/eolian_cxx/grammar/class_implementation.hpp index 615ee6022e..f5f2f31ffb 100644 --- a/src/lib/eolian_cxx/grammar/class_implementation.hpp +++ b/src/lib/eolian_cxx/grammar/class_implementation.hpp @@ -24,8 +24,8 @@ struct class_implementation_generator bool generate(OutputIterator sink, attributes::klass_def const& cls, Context const& ctx) const { std::vector<std::string> cpp_namespaces = attributes::cpp_namespaces(cls.namespaces); - auto base_class_name = *(lower_case[string] << "::") << string; - auto class_name = *(lit("::") << lower_case[string]) << "::" << string; + auto base_class_name = *(lower_case[string] << "::") << lower_case[string]; + auto class_name = *(lit("::") << lower_case[string]) << "::" << lower_case[string]; std::string guard_symbol; if(!as_generator(*(string << "_") << string << "_IMPL_HH") diff --git a/src/lib/eolian_cxx/grammar/cxx_class_name.hpp b/src/lib/eolian_cxx/grammar/cxx_class_name.hpp new file mode 100644 index 0000000000..ab7a81281c --- /dev/null +++ b/src/lib/eolian_cxx/grammar/cxx_class_name.hpp @@ -0,0 +1,37 @@ +#ifndef EOLIAN_CXX_CLASS_NAME_HH +#define EOLIAN_CXX_CLASS_NAME_HH + +#include "grammar/case.hpp" +#include "grammar/string.hpp" + +namespace efl { namespace eolian { namespace grammar { + +struct cxx_class_name_generator +{ + template <typename OutputIterator, typename Context> + bool generate(OutputIterator sink, std::string name, Context const& context) const + { + if(name == "Class") + { + name = "efl_class"; + } + + return as_generator(lower_case[string]).generate(sink, name, context); + } +}; + +cxx_class_name_generator const cxx_class_name{}; + +template <> +struct is_eager_generator<cxx_class_name_generator> : std::true_type {}; +template <> +struct is_generator<cxx_class_name_generator> : std::true_type {}; + +namespace type_traits { +template <> +struct attributes_needed<cxx_class_name_generator> : std::integral_constant<int, 1> {}; +} + +} } } + +#endif diff --git a/src/lib/eolian_cxx/grammar/function_definition.hpp b/src/lib/eolian_cxx/grammar/function_definition.hpp index 9b646efc9c..14413d1631 100644 --- a/src/lib/eolian_cxx/grammar/function_definition.hpp +++ b/src/lib/eolian_cxx/grammar/function_definition.hpp @@ -18,6 +18,7 @@ #include "grammar/attribute_reorder.hpp" #include "grammar/type_impl.hpp" #include "grammar/eps.hpp" +#include "grammar/cxx_class_name.hpp" namespace efl { namespace eolian { namespace grammar { @@ -71,7 +72,7 @@ struct function_definition_generator if (!f.is_static) const_flag = " const"; if(!as_generator - ("inline ::efl::eolian::return_traits<" << grammar::type(true) << ">::type " << string << "::" + ("inline ::efl::eolian::return_traits<" << grammar::type(true) << ">::type " << cxx_class_name << "::" << string << "(" << (parameter % ", ") << ")" << string << "\n{\n") .generate(sink, std::make_tuple(f.return_type, _klass_name.eolian_name, escape_keyword(f.name), f.parameters, const_flag), ctx)) diff --git a/src/lib/eolian_cxx/grammar/type_impl.hpp b/src/lib/eolian_cxx/grammar/type_impl.hpp index ebe738abed..f9a158fc4c 100644 --- a/src/lib/eolian_cxx/grammar/type_impl.hpp +++ b/src/lib/eolian_cxx/grammar/type_impl.hpp @@ -6,6 +6,7 @@ #include "grammar/case.hpp" #include "grammar/container.hpp" #include "grammar/type.hpp" +#include "grammar/cxx_class_name.hpp" namespace efl { namespace eolian { namespace grammar { @@ -263,7 +264,7 @@ struct visitor_generate bool operator()(attributes::klass_name klass) const { return - as_generator(" " << *("::" << lower_case[string]) << "::" << string) + as_generator(" " << *("::" << lower_case[string]) << "::" << cxx_class_name) .generate(sink, std::make_tuple(attributes::cpp_namespaces(klass.namespaces), klass.eolian_name), *context) && (!(klass.base_qualifier & qualifier_info::is_ref) || as_generator("&").generate(sink, attributes::unused, *context)); |