eolian_csharp: add indentation context
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>
Fri, 22 Mar 2019 21:37:50 +0000 (18:37 -0300)
committerYeongjong Lee <yj34.lee@samsung.com>
Tue, 2 Apr 2019 03:45:17 +0000 (12:45 +0900)
Summary:
Also, use new context class for cleaner constructs.

Also, make functions receive context objects by reference to avoid
unnecessary object copies (since context objects are bigger now).

This commit contains preparation structures for a future overhaul of
white space generation.

Depends on D8467

Test Plan: ninja test

Reviewers: felipealmeida, lauromoura

Reviewed By: lauromoura

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D8468

src/bin/eolian_mono/eolian/mono/blacklist.hh
src/bin/eolian_mono/eolian/mono/events.hh
src/bin/eolian_mono/eolian/mono/function_definition.hh
src/bin/eolian_mono/eolian/mono/function_pointer.hh
src/bin/eolian_mono/eolian/mono/generation_contexts.hh
src/bin/eolian_mono/eolian/mono/helpers.hh
src/bin/eolian_mono/eolian/mono/name_helpers.hh
src/bin/eolian_mono/eolian/mono/parameter.hh
src/bin/eolian_mono/eolian/mono/variable_definition.hh
src/bin/eolian_mono/eolian_mono.cc

index 77be1c0..df94b6a 100644 (file)
@@ -52,7 +52,7 @@ inline bool is_function_blacklisted(std::string const& c_name)
 }
 
 template<typename Context>
-inline bool is_function_blacklisted(attributes::function_def const& func, Context context)
+inline bool is_function_blacklisted(attributes::function_def const& func, Context const& context)
 {
   auto options = efl::eolian::grammar::context_find_tag<options_context>(context);
   auto c_name = func.c_name;
@@ -80,7 +80,7 @@ inline bool is_struct_blacklisted(std::string const& full_name)
 }
 
 template <typename Context>
-inline bool is_struct_blacklisted(attributes::struct_def const& struct_, Context context)
+inline bool is_struct_blacklisted(attributes::struct_def const& struct_, Context const& context)
 {
    auto options = efl::eolian::grammar::context_find_tag<options_context>(context);
    if (struct_.is_beta && !options.want_beta)
@@ -91,7 +91,7 @@ inline bool is_struct_blacklisted(attributes::struct_def const& struct_, Context
 
 // Struct as type_def is for places where the struct is used as a struct field or parameter/return.
 template <typename Context>
-inline bool is_struct_blacklisted(attributes::type_def const& struct_, Context context)
+inline bool is_struct_blacklisted(attributes::type_def const& struct_, Context const& context)
 {
    auto options = efl::eolian::grammar::context_find_tag<options_context>(context);
    if (struct_.is_beta && !options.want_beta)
@@ -119,7 +119,7 @@ inline bool is_property_blacklisted(std::string const& name)
 }
 
 template<typename Context>
-inline bool is_property_blacklisted(attributes::property_def const& property, Context context)
+inline bool is_property_blacklisted(attributes::property_def const& property, Context const& context)
 {
     auto name = name_helpers::klass_full_concrete_or_interface_name(property.klass) + "." + name_helpers::property_managed_name(property);
 
@@ -135,7 +135,7 @@ inline bool is_property_blacklisted(attributes::property_def const& property, Co
 template<typename Context>
 inline bool is_property_blacklisted(attributes::property_def const& property,
                                     attributes::klass_def const& implementing_class,
-                                    Context context)
+                                    Context const& context)
 {
    std::string property_name = name_helpers::property_managed_name(property);
    std::string klass_name = name_helpers::klass_concrete_or_interface_name(implementing_class);
@@ -149,7 +149,7 @@ inline bool is_property_blacklisted(attributes::property_def const& property,
 }
 
 template<typename Context>
-inline bool is_class_blacklisted(attributes::klass_def const& cls, Context context)
+inline bool is_class_blacklisted(attributes::klass_def const& cls, Context const& context)
 {
    auto options = efl::eolian::grammar::context_find_tag<options_context>(context);
 
@@ -157,7 +157,7 @@ inline bool is_class_blacklisted(attributes::klass_def const& cls, Context conte
 }
 
 template<typename Context>
-inline bool is_class_blacklisted(attributes::klass_name const& cls, Context context)
+inline bool is_class_blacklisted(attributes::klass_name const& cls, Context const& context)
 {
    auto options = efl::eolian::grammar::context_find_tag<options_context>(context);
 
@@ -166,7 +166,7 @@ inline bool is_class_blacklisted(attributes::klass_name const& cls, Context cont
 
 
 template<typename Context>
-inline bool is_event_blacklisted(attributes::event_def const& evt, Context context)
+inline bool is_event_blacklisted(attributes::event_def const& evt, Context const& context)
 {
    auto options = efl::eolian::grammar::context_find_tag<options_context>(context);
 
index f4f6987..1a3aca1 100644 (file)
@@ -179,7 +179,7 @@ struct event_definition_generator
    bool is_inherited_event;
 
    template<typename OutputIterator, typename Context>
-   bool generate(OutputIterator sink, attributes::event_def const& evt, Context context) const
+   bool generate(OutputIterator sink, attributes::event_def const& evt, Context const& context) const
    {
       if (blacklist::is_event_blacklisted(evt, context))
         return true;
@@ -291,7 +291,7 @@ struct event_definition_generator
                               , std::string const& event_name
                               , std::string const& event_args_type
                               , std::string const& event_template_args
-                              , Context context) const
+                              , Context const& context) const
    {
       auto delegate_type = "EventHandler" + event_template_args;
       if (!as_generator(
@@ -311,7 +311,7 @@ struct event_definition_generator
    }
 
    template<typename OutputIterator, typename Context>
-   bool generate_event_add_remove(OutputIterator sink, attributes::event_def const &evt, const std::string& event_name, Context context) const
+   bool generate_event_add_remove(OutputIterator sink, attributes::event_def const &evt, const std::string& event_name, Context const& context) const
    {
       std::string upper_c_name = utils::to_uppercase(evt.c_name);
       auto unit = (const Eolian_Unit*) context_find_tag<eolian_state_context>(context).state;
index fe349ef..0d6eff6 100644 (file)
@@ -217,7 +217,7 @@ struct native_function_definition_parameterized
 struct property_wrapper_definition_generator
 {
    template<typename OutputIterator, typename Context>
-   bool generate(OutputIterator sink, attributes::property_def const& property, Context context) const
+   bool generate(OutputIterator sink, attributes::property_def const& property, Context const& context) const
    {
       if (blacklist::is_property_blacklisted(property, *implementing_klass, context))
         return true;
index d616f1d..aa99601 100644 (file)
@@ -15,7 +15,7 @@ namespace eolian_mono {
 
 // Blacklist structs that require some kind of manual binding.
 template <typename Context>
-static bool is_function_ptr_blacklisted(attributes::function_def const& func, Context context)
+static bool is_function_ptr_blacklisted(attributes::function_def const& func, Context const& context)
 {
   std::string name = name_helpers::function_ptr_full_eolian_name(func);
 
index 5cc57ef..25ac309 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef EOLIAN_MONO_GENERATION_CONTEXTS_HH
 #define EOLIAN_MONO_GENERATION_CONTEXTS_HH
 
+#include "grammar/context.hpp"
+#include "grammar/indentation.hpp"
+
 namespace eolian_mono {
 
 struct class_context
@@ -19,6 +22,33 @@ struct class_context
     wrapper_kind current_wrapper_kind;
 };
 
+struct indentation_context
+{
+  constexpr indentation_context(indentation_context const& other) = default;
+  constexpr indentation_context(efl::eolian::grammar::scope_tab_generator indent)
+    : indent(indent)
+  {}
+  constexpr indentation_context(int n)
+    : indent(n)
+  {}
+  constexpr indentation_context(int n, int m)
+    : indent(n, m)
+  {}
+  efl::eolian::grammar::scope_tab_generator indent;
+};
+
+template <typename Context>
+inline constexpr efl::eolian::grammar::scope_tab_generator const& current_indentation(Context const& context)
+{
+  return efl::eolian::grammar::context_find_tag<indentation_context>(context).indent;
+}
+
+template <typename Context>
+inline constexpr Context change_indentation(efl::eolian::grammar::scope_tab_generator const& indent, Context const& context)
+{
+  return efl::eolian::grammar::context_replace_tag(indentation_context(indent), context);
+}
+
 struct library_context
 {
   std::string library_name;
index a4bb169..dffb38b 100644 (file)
@@ -103,7 +103,7 @@ std::set<attributes::klass_name, attributes::compare_klass_name_by_name> interfa
 // Returns the set of interfaces implemented by this type that haven't been implemented
 // by a regular parent class.
 template<typename Context>
-std::set<attributes::klass_name, attributes::compare_klass_name_by_name> non_implemented_interfaces(attributes::klass_def const& cls, Context context)
+std::set<attributes::klass_name, attributes::compare_klass_name_by_name> non_implemented_interfaces(attributes::klass_def const& cls, Context const& context)
 {
    auto options = efl::eolian::grammar::context_find_tag<options_context>(context);
    std::set<attributes::klass_name, attributes::compare_klass_name_by_name> implemented_interfaces;
index 6989764..2ff2b47 100644 (file)
@@ -442,7 +442,7 @@ inline std::string translate_inherited_event_name(const attributes::event_def &e
 
 // Open/close namespaces
 template<typename OutputIterator, typename Context>
-bool open_namespaces(OutputIterator sink, std::vector<std::string> namespaces, Context context)
+bool open_namespaces(OutputIterator sink, std::vector<std::string> namespaces, Context const& context)
 {
   std::transform(namespaces.begin(), namespaces.end(), namespaces.begin(), managed_namespace);
 
@@ -451,7 +451,7 @@ bool open_namespaces(OutputIterator sink, std::vector<std::string> namespaces, C
 }
 
 template<typename OutputIterator, typename Context>
-bool close_namespaces(OutputIterator sink, std::vector<std::string> const& namespaces, Context context)
+bool close_namespaces(OutputIterator sink, std::vector<std::string> const& namespaces, Context const& context)
 {
      auto close_namespace = *(lit("} ")) << "\n";
      return as_generator(close_namespace).generate(sink, namespaces, context);
index 1314c12..730fa66 100644 (file)
@@ -1452,7 +1452,7 @@ struct constructor_parameter_name_parameterized
 struct constructor_param_generator
 {
   template<typename OutputIterator, typename Context>
-  bool generate(OutputIterator sink, attributes::constructor_def const& ctor, Context context) const
+  bool generate(OutputIterator sink, attributes::constructor_def const& ctor, Context const& context) const
   {
      auto params = ctor.function.parameters;
 
@@ -1471,7 +1471,7 @@ struct constructor_param_generator
 struct constructor_invocation_generator
 {
   template<typename OutputIterator, typename Context>
-  bool generate(OutputIterator sink, attributes::constructor_def const& ctor, Context context) const
+  bool generate(OutputIterator sink, attributes::constructor_def const& ctor, Context const& context) const
   {
      auto params = ctor.function.parameters;
      if (!as_generator(
index d143d7e..f13efde 100644 (file)
@@ -28,7 +28,7 @@ namespace eolian_mono {
 struct constant_definition_generator
 {
   template<typename OutputIterator, typename Context>
-  bool generate(OutputIterator sink, attributes::variable_def constant, Context context) const
+  bool generate(OutputIterator sink, attributes::variable_def constant, Context const& context) const
   {
     // Open partial class
     if (!name_helpers::open_namespaces(sink, constant.namespaces, context))
index e3cbe5f..0699c77 100644 (file)
@@ -140,15 +140,16 @@ run(options_type const& opts)
         throw std::runtime_error("Failed to generate file preamble");
      }
 
-   auto lib_context = efl::eolian::grammar::context_add_tag(eolian_mono::library_context{opts.dllimport,
-                                                                                     opts.v_major,
-                                                                                     opts.v_minor,
-                                                                                     opts.references_map},
-                                                        efl::eolian::grammar::context_null());
-
-   auto options_context = efl::eolian::grammar::context_add_tag(eolian_mono::options_context{opts.want_beta}, lib_context);
-
-   auto context = efl::eolian::grammar::context_add_tag(eolian_mono::eolian_state_context{opts.state}, options_context);
+   using efl::eolian::grammar::context_add_tag;
+
+   auto context = context_add_tag(eolian_mono::indentation_context{0},
+                  context_add_tag(eolian_mono::eolian_state_context{opts.state},
+                  context_add_tag(eolian_mono::options_context{opts.want_beta},
+                  context_add_tag(eolian_mono::library_context{opts.dllimport,
+                                                               opts.v_major,
+                                                               opts.v_minor,
+                                                               opts.references_map},
+                                  efl::eolian::grammar::context_null()))));
 
    EINA_ITERATOR_FOREACH(aliases, tp)
      {