aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-01-11 02:46:25 -0200
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-01-11 02:46:25 -0200
commit99729cb536cf16f7d15140fdac528fe70b3d6e8b (patch)
treeb92acba048f113cb9576e83a3f19d482ead1c2fd
parentefl-csharp: Temporarily blacklist forwarder function. (diff)
downloadefl-devs/lauromoura/csharp_constants.tar.gz
efl-csharp - WIP Constants workdevs/lauromoura/csharp_constants
TODO - Open the constants namespaces - Declare the class that will hold the constants Maybe we'll need to group the constants - Add expression value definition to eolian_cxx
-rw-r--r--src/bin/eolian_mono/eolian/mono/generation_contexts.hh1
-rw-r--r--src/bin/eolian_mono/eolian_mono.cc18
-rw-r--r--src/lib/eolian_cxx/grammar/klass_def.hpp49
3 files changed, 68 insertions, 0 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
index ca1ca9e678..9c5eaf1289 100644
--- a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
+++ b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
@@ -14,6 +14,7 @@ struct class_context
enums,
function_ptr,
alias,
+ variables,
};
wrapper_kind current_wrapper_kind;
};
diff --git a/src/bin/eolian_mono/eolian_mono.cc b/src/bin/eolian_mono/eolian_mono.cc
index db888816a2..015e81b49d 100644
--- a/src/bin/eolian_mono/eolian_mono.cc
+++ b/src/bin/eolian_mono/eolian_mono.cc
@@ -33,6 +33,7 @@
#include <eolian/mono/marshall_annotation.hh>
#include <eolian/mono/function_pointer.hh>
#include <eolian/mono/alias_definition.hh>
+#include <eolian/mono/variable_definition.hh>
namespace eolian_mono {
@@ -165,6 +166,22 @@ run(options_type const& opts)
}
}
+ // Constants
+ auto current_unit = ::eolian_state_unit_by_file_get(opts.state, basename_input.c_str());
+ if (!current_unit)
+ throw std::runtime_error("Failed to get unit for current file.");
+
+ for (efl::eina::iterator<const Eolian_Variable> var_iterator( ::eolian_unit_constants_get(current_unit))
+ , var_last; var_iterator != var_last; ++var_iterator)
+ {
+ efl::eolian::grammar::attributes::variable_def var(&*var_iterator, opts.unit);
+ auto var_cxt = context_add_tag(class_context{class_context::variables}, context);
+ if (!eolian_mono::constant_definition.generate(iterator, var, var_cxt))
+ {
+ throw std::runtime_error("Failed to generate enum");
+ }
+ }
+
if (klass)
{
efl::eolian::grammar::attributes::klass_def klass_def(klass, opts.unit);
@@ -200,6 +217,7 @@ run(options_type const& opts)
throw std::runtime_error("Failed to generate struct");
}
}
+
}
static void
diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp
index f69fca29d3..850ea4a044 100644
--- a/src/lib/eolian_cxx/grammar/klass_def.hpp
+++ b/src/lib/eolian_cxx/grammar/klass_def.hpp
@@ -91,6 +91,14 @@ inline typedecl_type typedecl_type_get(Eolian_Typedecl const* decl)
}
}
+enum class variable_type
+{
+ unknown,
+ constant,
+ global
+};
+
+
struct type_def;
bool operator==(type_def const& rhs, type_def const& lhs);
bool operator!=(type_def const& rhs, type_def const& lhs);
@@ -857,6 +865,47 @@ struct property_def
}
};
+struct variable_def
+{
+ std::string name;
+ std::string full_name;
+ type_def base_type;
+ documentation_def documentation;
+ variable_type type;
+ std::vector<std::string> namespaces;
+ bool is_extern;
+ // FIXME What about the expression value?
+
+ friend inline bool operator==(variable_def const& lhs, variable_def const& rhs)
+ {
+ return lhs.name == rhs.name
+ && lhs.full_name == rhs.full_name
+ && lhs.base_type == rhs.base_type
+ && lhs.documentation == rhs.documentation
+ && lhs.type == rhs.type
+ && lhs.namespaces == rhs.namespaces
+ && lhs.is_extern == rhs.is_extern;
+ }
+
+ friend inline bool operator!=(variable_def const& lhs, variable_def const& rhs)
+ {
+ return !(lhs == rhs);
+ }
+
+ variable_def() = default;
+ variable_def(Eolian_Variable const* variable, Eolian_Unit const* unit)
+ : name(::eolian_variable_short_name_get(variable))
+ , full_name(::eolian_variable_name_get(variable))
+ , base_type(::eolian_variable_base_type_get(variable), unit, ::EOLIAN_C_TYPE_DEFAULT)
+ {
+ for(efl::eina::iterator<const char> namespace_iterator( ::eolian_variable_namespaces_get(variable))
+ , namespace_last; namespace_iterator != namespace_last; ++namespace_iterator)
+ {
+ this->namespaces.push_back((&*namespace_iterator));
+ }
+ }
+};
+
// template <int N>
// struct tuple_element<N, function_def const> : tuple_element<N, function_def> {};