cxx: Implement support for @class static functions
authorJean-Philippe Andre <jp.andre@samsung.com>
Tue, 28 Nov 2017 05:17:51 +0000 (14:17 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Tue, 5 Dec 2017 01:17:02 +0000 (10:17 +0900)
src/lib/eolian_cxx/grammar/function_declaration.hpp
src/lib/eolian_cxx/grammar/function_definition.hpp
src/lib/eolian_cxx/grammar/klass_def.hpp

index 04694fa..fe3ad73 100644 (file)
@@ -24,7 +24,7 @@ struct function_declaration_generator
    template <typename OutputIterator, typename Context>
    bool generate(OutputIterator sink, attributes::function_def const& f, Context const& ctx) const
    {
-      std::string suffix;
+      std::string suffix, static_flag, const_flag;
       switch(_klass_name.type)
         {
         case attributes::class_type::regular:
@@ -50,8 +50,12 @@ struct function_declaration_generator
           .generate(sink, attributes::unused, ctx))
         return false;
 
+      if (f.is_static) static_flag = "static ";
+      else const_flag = " const";
+
       if(!as_generator
-            (scope_tab << "::efl::eolian::return_traits<" << grammar::type(true) << ">::type " << string << "(" << (parameter % ", ") << ") const;\n")
+            (scope_tab << static_flag << "::efl::eolian::return_traits<" << grammar::type(true) << ">::type "
+             << string << "(" << (parameter % ", ") << ")" << const_flag << ";\n")
             .generate(sink, std::make_tuple(f.return_type, escape_keyword(f.name), f.parameters), ctx))
         return false;
       if(f.is_beta &&
index 55f5621..1ffbed4 100644 (file)
@@ -60,9 +60,14 @@ struct function_definition_generator
           .generate(sink, attributes::unused, ctx))
         return false;
 
+      std::string const_flag;
+      if (!f.is_static) const_flag = " const";
+
       if(!as_generator
-         ("inline ::efl::eolian::return_traits<" << grammar::type(true) << ">::type " << string << "::" << string << "(" << (parameter % ", ") << ") const\n{\n")
-         .generate(sink, std::make_tuple(f.return_type, _klass_name.eolian_name, escape_keyword(f.name), f.parameters), ctx))
+         ("inline ::efl::eolian::return_traits<" << grammar::type(true) << ">::type " << string << "::"
+          << 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))
         return false;
 
       std::vector<std::string> opening_statements(f.opening_statements());
@@ -104,10 +109,13 @@ struct function_definition_generator
          && !as_generator(attributes::c_type({attributes::parameter_direction::in, f.return_type, ""})
                           << " __return_value = "
                           ).generate(sink, attributes::unused, ctx)) return false;
-      
+
+      std::string object_flag;
+      if (f.is_static) object_flag = "_eo_class()";
+      else object_flag = "_eo_ptr()";
+
       if(!as_generator
-         (" ::" << string << "(this->_eo_ptr()"
-          <<
+         (" ::" << string << "(" << string <<
           *(
             "\n" << scope_tab << scope_tab << ", "
             <<
@@ -119,7 +127,7 @@ struct function_definition_generator
             )
           )
           << ");\n"
-         ).generate(sink, std::make_tuple(f.c_name, f.parameters), ctx))
+         ).generate(sink, std::make_tuple(f.c_name, object_flag, f.parameters), ctx))
         return false;
 
       auto out_assignments =
index fc6d62d..b2aae1b 100644 (file)
@@ -439,6 +439,7 @@ struct function_def
   bool is_beta;
   bool is_protected;
   bool is_function_pointer;
+  bool is_static;
 
   friend inline bool operator==(function_def const& lhs, function_def const& rhs)
   {
@@ -449,7 +450,8 @@ struct function_def
       && lhs.filename == rhs.filename
       && lhs.is_beta == rhs.is_beta
       && lhs.is_protected == rhs.is_protected
-      && lhs.is_function_pointer == rhs.is_function_pointer;
+      && lhs.is_function_pointer == rhs.is_function_pointer
+      && lhs.is_static == rhs.is_static;
   }
   friend inline bool operator!=(function_def const& lhs, function_def const& rhs)
   {
@@ -531,7 +533,7 @@ struct function_def
        }
      is_beta = eolian_function_is_beta(function);
      is_protected = eolian_function_scope_get(function, type) == EOLIAN_SCOPE_PROTECTED;
-     is_protected = eolian_function_scope_get(function, type) == EOLIAN_SCOPE_PROTECTED;
+     is_static = eolian_function_is_class(function);
   }
 
   std::string template_statement() const