vitorsousa pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=378ba8ebd1c2e3a049cff0bad9b23b2000d7c939

commit 378ba8ebd1c2e3a049cff0bad9b23b2000d7c939
Author: Vitor Sousa <[email protected]>
Date:   Fri Mar 22 18:37:50 2019 -0300

    eolian_csharp: add indentation context
    
    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       | 16 ++++++------
 src/bin/eolian_mono/eolian/mono/events.hh          |  6 ++---
 .../eolian_mono/eolian/mono/function_definition.hh |  2 +-
 .../eolian_mono/eolian/mono/function_pointer.hh    |  2 +-
 .../eolian_mono/eolian/mono/generation_contexts.hh | 30 ++++++++++++++++++++++
 src/bin/eolian_mono/eolian/mono/helpers.hh         |  2 +-
 src/bin/eolian_mono/eolian/mono/name_helpers.hh    |  4 +--
 src/bin/eolian_mono/eolian/mono/parameter.hh       |  4 +--
 .../eolian_mono/eolian/mono/variable_definition.hh |  2 +-
 src/bin/eolian_mono/eolian_mono.cc                 | 19 +++++++-------
 10 files changed, 59 insertions(+), 28 deletions(-)

diff --git a/src/bin/eolian_mono/eolian/mono/blacklist.hh 
b/src/bin/eolian_mono/eolian/mono/blacklist.hh
index 77be1c0da8..df94b6acb6 100644
--- a/src/bin/eolian_mono/eolian/mono/blacklist.hh
+++ b/src/bin/eolian_mono/eolian/mono/blacklist.hh
@@ -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);
 
diff --git a/src/bin/eolian_mono/eolian/mono/events.hh 
b/src/bin/eolian_mono/eolian/mono/events.hh
index f4f6987950..1a3aca17aa 100644
--- a/src/bin/eolian_mono/eolian/mono/events.hh
+++ b/src/bin/eolian_mono/eolian/mono/events.hh
@@ -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;
diff --git a/src/bin/eolian_mono/eolian/mono/function_definition.hh 
b/src/bin/eolian_mono/eolian/mono/function_definition.hh
index fe349effab..0d6eff628e 100644
--- a/src/bin/eolian_mono/eolian/mono/function_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_definition.hh
@@ -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;
diff --git a/src/bin/eolian_mono/eolian/mono/function_pointer.hh 
b/src/bin/eolian_mono/eolian/mono/function_pointer.hh
index d616f1da2a..aa99601c8c 100644
--- a/src/bin/eolian_mono/eolian/mono/function_pointer.hh
+++ b/src/bin/eolian_mono/eolian/mono/function_pointer.hh
@@ -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);
 
diff --git a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh 
b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
index 5cc57ef902..25ac3098fb 100644
--- a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
+++ b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
@@ -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;
diff --git a/src/bin/eolian_mono/eolian/mono/helpers.hh 
b/src/bin/eolian_mono/eolian/mono/helpers.hh
index a4bb169593..dffb38b820 100644
--- a/src/bin/eolian_mono/eolian/mono/helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/helpers.hh
@@ -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;
diff --git a/src/bin/eolian_mono/eolian/mono/name_helpers.hh 
b/src/bin/eolian_mono/eolian/mono/name_helpers.hh
index 698976446e..2ff2b47e1d 100644
--- a/src/bin/eolian_mono/eolian/mono/name_helpers.hh
+++ b/src/bin/eolian_mono/eolian/mono/name_helpers.hh
@@ -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);
diff --git a/src/bin/eolian_mono/eolian/mono/parameter.hh 
b/src/bin/eolian_mono/eolian/mono/parameter.hh
index 1314c125cb..730fa66ee7 100644
--- a/src/bin/eolian_mono/eolian/mono/parameter.hh
+++ b/src/bin/eolian_mono/eolian/mono/parameter.hh
@@ -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(
diff --git a/src/bin/eolian_mono/eolian/mono/variable_definition.hh 
b/src/bin/eolian_mono/eolian/mono/variable_definition.hh
index d143d7e138..f13efdecc2 100644
--- a/src/bin/eolian_mono/eolian/mono/variable_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/variable_definition.hh
@@ -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))
diff --git a/src/bin/eolian_mono/eolian_mono.cc 
b/src/bin/eolian_mono/eolian_mono.cc
index e3cbe5fcad..0699c774e7 100644
--- a/src/bin/eolian_mono/eolian_mono.cc
+++ b/src/bin/eolian_mono/eolian_mono.cc
@@ -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)
      {

-- 


Reply via email to