From 4bae2a7385626e649b635dc4577a193a7d49e8e5 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 22 Sep 2017 17:46:02 +0200 Subject: [PATCH] eolian: merge REGULAR and COMPLEX types --- src/bindings/luajit/eolian.lua | 10 ++--- src/lib/eolian/Eolian.h | 14 +++---- src/lib/eolian/database_expr_api.c | 5 +-- src/lib/eolian/database_type.c | 10 +---- src/lib/eolian/database_validate.c | 16 ++++---- src/lib/eolian/eo_lexer.c | 5 ++- src/lib/eolian/eo_parser.c | 1 - src/lib/eolian_cxx/grammar/klass_def.hpp | 67 ++++++++++++++++---------------- src/scripts/elua/apps/docgen/doctree.lua | 18 ++++----- 9 files changed, 69 insertions(+), 77 deletions(-) diff --git a/src/bindings/luajit/eolian.lua b/src/bindings/luajit/eolian.lua index 9c6a281..7deca59 100644 --- a/src/bindings/luajit/eolian.lua +++ b/src/bindings/luajit/eolian.lua @@ -79,7 +79,6 @@ ffi.cdef [[ EOLIAN_TYPE_UNKNOWN_TYPE = 0, EOLIAN_TYPE_VOID, EOLIAN_TYPE_REGULAR, - EOLIAN_TYPE_COMPLEX, EOLIAN_TYPE_CLASS, EOLIAN_TYPE_STATIC_ARRAY, EOLIAN_TYPE_TERMINATED_ARRAY, @@ -504,11 +503,10 @@ M.type_type = { UNKNOWN = 0, VOID = 1, REGULAR = 2, - COMPLEX = 3, - CLASS = 4, - STATIC_ARRAY = 5, - TERMINATED_ARRAY = 6, - UNDEFINED = 7 + CLASS = 3, + STATIC_ARRAY = 4, + TERMINATED_ARRAY = 5, + UNDEFINED = 6 } M.typedecl_type = { diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index fdf14b9..5ec4abb 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -227,7 +227,6 @@ typedef enum EOLIAN_TYPE_UNKNOWN_TYPE = 0, EOLIAN_TYPE_VOID, EOLIAN_TYPE_REGULAR, - EOLIAN_TYPE_COMPLEX, EOLIAN_TYPE_CLASS, EOLIAN_TYPE_STATIC_ARRAY, EOLIAN_TYPE_TERMINATED_ARRAY, @@ -1761,8 +1760,8 @@ EAPI Eina_Stringshare *eolian_type_file_get(const Eolian_Type *tp); /* * @brief Get the base type of a type. * - * For pointers, this is the type before the star and for complex types, - * this is the first inner type. + * Only applies to "complex" ordinary types, i.e. this is the first inner + * type in <>. * * @param[in] tp the type. * @return the base type or NULL. @@ -1883,8 +1882,8 @@ EAPI Eina_Bool eolian_type_is_ptr(const Eolian_Type *tp); EAPI Eina_Stringshare *eolian_type_c_type_get(const Eolian_Type *tp, Eolian_C_Type_Type ctype); /* - * @brief Get the name of the given type. For regular or complex types, this - * is for example "int". For EOLIAN_TYPE_CLASS, this can be "Button". Keep in + * @brief Get the name of the given type. For regular types, this is for + * example "int". For EOLIAN_TYPE_CLASS, this can be "Button". Keep in * mind that the name doesn't include namespaces. * * @param[in] tp the type. @@ -1920,8 +1919,9 @@ EAPI Eina_Iterator *eolian_type_namespaces_get(const Eolian_Type *tp); * @param[in] tp the type. * @return the free func name. * - * For pointer, class and complex types, this returns name of the func used - * to free the pointer. For other types, this returns NULL. + * For types that translate to C pointers, this is the function used to + * free them. For other types, this is the function to free a pointer to + * those types. * * @ingroup Eolian */ diff --git a/src/lib/eolian/database_expr_api.c b/src/lib/eolian/database_expr_api.c index ab6d98e..50a0afa 100644 --- a/src/lib/eolian/database_expr_api.c +++ b/src/lib/eolian/database_expr_api.c @@ -26,13 +26,12 @@ _eval_type(const Eolian_Unit *unit, const Eolian_Expression *expr, switch (type->type) { case EOLIAN_TYPE_CLASS: - case EOLIAN_TYPE_COMPLEX: return database_expr_eval(unit, expr, EOLIAN_MASK_NULL); case EOLIAN_TYPE_REGULAR: { - int kw = eo_lexer_keyword_str_to_id(type->name); - if (type->is_ptr) + if (database_type_is_ownable(type, EINA_FALSE)) return database_expr_eval(unit, expr, EOLIAN_MASK_NULL); + int kw = eo_lexer_keyword_str_to_id(type->name); if (!kw || kw < KW_byte || kw >= KW_void) { const Eolian_Typedecl *base = eolian_type_typedecl_get(type); diff --git a/src/lib/eolian/database_type.c b/src/lib/eolian/database_type.c index a05fa25..dda298f 100644 --- a/src/lib/eolian/database_type.c +++ b/src/lib/eolian/database_type.c @@ -120,13 +120,8 @@ void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype) { - if ((tp->type == EOLIAN_TYPE_COMPLEX - || tp->type == EOLIAN_TYPE_CLASS) - && tp->is_const) - { - eina_strbuf_append(buf, "const "); - } if ((tp->type == EOLIAN_TYPE_REGULAR + || tp->type == EOLIAN_TYPE_CLASS || tp->type == EOLIAN_TYPE_VOID) && tp->is_const && ((ctype != EOLIAN_C_TYPE_RETURN) || database_type_is_ownable(tp, EINA_FALSE))) @@ -134,7 +129,6 @@ database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, eina_strbuf_append(buf, "const "); } if (tp->type == EOLIAN_TYPE_REGULAR - || tp->type == EOLIAN_TYPE_COMPLEX || tp->type == EOLIAN_TYPE_CLASS) { Eina_List *l; @@ -162,7 +156,7 @@ database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, if (tp->is_const && (ctype != EOLIAN_C_TYPE_RETURN)) eina_strbuf_append(buf, " const"); } - if (tp->type == EOLIAN_TYPE_COMPLEX || tp->type == EOLIAN_TYPE_CLASS) + if (tp->type == EOLIAN_TYPE_CLASS) _buf_add_suffix(buf, "*"); if (tp->is_ptr) _buf_add_suffix(buf, "*"); diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c index b2df691..980ec62 100644 --- a/src/lib/eolian/database_validate.c +++ b/src/lib/eolian/database_validate.c @@ -160,15 +160,17 @@ _validate_type(Eolian_Type *tp) case EOLIAN_TYPE_VOID: case EOLIAN_TYPE_UNDEFINED: return EINA_TRUE; - case EOLIAN_TYPE_COMPLEX: - if (!tp->freefunc) - { - tp->freefunc = eina_stringshare_add(eo_complex_frees[ - eo_lexer_keyword_str_to_id(tp->full_name) - KW_accessor]); - } - return EINA_TRUE; case EOLIAN_TYPE_REGULAR: { + if (tp->base_type) + { + if (!tp->freefunc) + { + tp->freefunc = eina_stringshare_add(eo_complex_frees[ + eo_lexer_keyword_str_to_id(tp->full_name) - KW_accessor]); + } + return EINA_TRUE; + } Eolian_Typedecl *tpp; /* builtins */ int id = eo_lexer_keyword_str_to_id(tp->full_name); diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c index dc5d01f..9318186 100644 --- a/src/lib/eolian/eo_lexer.c +++ b/src/lib/eolian/eo_lexer.c @@ -73,8 +73,9 @@ static const char * const ctypes[] = NULL, NULL, /* array types */ - "Eina_Accessor", "Eina_Array", "Eina_Iterator", "Eina_Hash", "Eina_List", - "Efl_Future", + "Eina_Accessor *", "Eina_Array *", "Eina_Iterator *", "Eina_Hash *", + "Eina_List *", + "Efl_Future *", "Eina_Value", "char *", "const char *", "Eina_Stringshare *", "void *", diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c index a523d88..3095864 100644 --- a/src/lib/eolian/eo_parser.c +++ b/src/lib/eolian/eo_parser.c @@ -806,7 +806,6 @@ parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ref, Eina_Bool allow_sarray) if (tpid >= KW_accessor && tpid <= KW_future) { int bline = ls->line_number, bcol = ls->column; - def->type = EOLIAN_TYPE_COMPLEX; check_next(ls, '<'); if (tpid == KW_future) def->base_type = parse_type_void(ls, EINA_FALSE, EINA_FALSE); diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp index 8bcbfc6..3de453e 100644 --- a/src/lib/eolian_cxx/grammar/klass_def.hpp +++ b/src/lib/eolian_cxx/grammar/klass_def.hpp @@ -253,33 +253,45 @@ inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* uni { c_type = ::eolian_type_c_type_get(eolian_type, ctype); // ::eina_stringshare_del(stringshare); // this crashes + Eolian_Type const* stp = eolian_type_base_type_get(eolian_type); switch( ::eolian_type_type_get(eolian_type)) { case EOLIAN_TYPE_VOID: original_type = attributes::regular_type_def{"void", {qualifiers(eolian_type), {}}, {}}; break; case EOLIAN_TYPE_REGULAR: - { - bool is_undefined = false; - Eolian_Typedecl const* decl = eolian_type_typedecl_get(eolian_type); - bool is_function_ptr = decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_FUNCTION_POINTER; - if(decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_ALIAS) - { - Eolian_Type const* aliased = eolian_typedecl_base_type_get(decl); - if(aliased && eolian_type_type_get(aliased) == EOLIAN_TYPE_UNDEFINED) - { - is_undefined = true; - } - } - - if(c_type == "va_list *") - throw std::runtime_error(""); - std::vector namespaces; - for(efl::eina::iterator namespace_iterator( ::eolian_type_namespaces_get(eolian_type)) - , namespace_last; namespace_iterator != namespace_last; ++namespace_iterator) - namespaces.push_back(&*namespace_iterator); - original_type = {regular_type_def{ ::eolian_type_name_get(eolian_type), {qualifiers(eolian_type), {}}, namespaces, is_undefined, is_function_ptr}}; - } + if (!stp) + { + bool is_undefined = false; + Eolian_Typedecl const* decl = eolian_type_typedecl_get(eolian_type); + bool is_function_ptr = decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_FUNCTION_POINTER; + if(decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_ALIAS) + { + Eolian_Type const* aliased = eolian_typedecl_base_type_get(decl); + if(aliased && eolian_type_type_get(aliased) == EOLIAN_TYPE_UNDEFINED) + { + is_undefined = true; + } + } + if(c_type == "va_list *") + throw std::runtime_error(""); + std::vector namespaces; + for(efl::eina::iterator namespace_iterator( ::eolian_type_namespaces_get(eolian_type)) + , namespace_last; namespace_iterator != namespace_last; ++namespace_iterator) + namespaces.push_back(&*namespace_iterator); + original_type = {regular_type_def{ ::eolian_type_name_get(eolian_type), {qualifiers(eolian_type), {}}, namespaces, is_undefined, is_function_ptr}}; + } + else + { + complex_type_def complex + {{::eolian_type_name_get(eolian_type), {qualifiers(eolian_type), {}}, {}}, {}}; + while (stp) + { + complex.subtypes.push_back({stp, unit, EOLIAN_C_TYPE_DEFAULT}); + stp = eolian_type_next_type_get(stp); + } + original_type = complex; + } break; case EOLIAN_TYPE_CLASS: { @@ -287,19 +299,6 @@ inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* uni original_type = klass_name(klass, {qualifiers(eolian_type), {}}); } break; - case EOLIAN_TYPE_COMPLEX: - { - complex_type_def complex - {{::eolian_type_name_get(eolian_type), {qualifiers(eolian_type), {}}, {}}, {}}; - Eolian_Type const* stp = eolian_type_base_type_get(eolian_type); - while (stp) - { - complex.subtypes.push_back({stp, unit, EOLIAN_C_TYPE_DEFAULT}); - stp = eolian_type_next_type_get(stp); - } - original_type = complex; - } - break; default: throw std::runtime_error("Type not supported"); break; diff --git a/src/scripts/elua/apps/docgen/doctree.lua b/src/scripts/elua/apps/docgen/doctree.lua index 5ff9d34..f387682 100644 --- a/src/scripts/elua/apps/docgen/doctree.lua +++ b/src/scripts/elua/apps/docgen/doctree.lua @@ -666,7 +666,6 @@ M.Type = Node:clone { UNKNOWN = eolian.type_type.UNKNOWN, VOID = eolian.type_type.VOID, REGULAR = eolian.type_type.REGULAR, - COMPLEX = eolian.type_type.COMPLEX, CLASS = eolian.type_type.CLASS, STATIC_ARRAY = eolian.type_type.STATIC_ARRAY, TERMINATED_ARRAY = eolian.type_type.TERMINATED_ARRAY, @@ -769,16 +768,17 @@ M.Type = Node:clone { elseif tpt == self.UNDEFINED then return wrap_type_attrs(self, "__undefined_type") elseif tpt == self.REGULAR or tpt == self.CLASS then - return wrap_type_attrs(self, self:full_name_get()) - elseif tpt == self.COMPLEX then - local stypes = {} local stp = self:base_type_get() - while stp do - stypes[#stypes + 1] = stp:serialize() - stp = stp:next_type_get() + if stp then + local stypes = {} + while stp do + stypes[#stypes + 1] = stp:serialize() + stp = stp:next_type_get() + end + return wrap_type_attrs(self, self:full_name_get() .. "<" + .. table.concat(stypes, ", ") .. ">") end - return wrap_type_attrs(self, self:full_name_get() .. "<" - .. table.concat(stypes, ", ") .. ">") + return wrap_type_attrs(self, self:full_name_get()) elseif tpt == self.STATIC_ARRAY then return wrap_type_attrs(self, "static_array<" .. self:base_type_get():serialize() .. ", " -- 2.7.4