From c3a33653f3c37fb70b0d14625e3ef9a06a83d543 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Tue, 1 Mar 2016 14:55:10 +0000 Subject: [PATCH] eolian: separate type_to_str for decls --- src/lib/eolian/database_type.c | 104 +++++++++++++++++++++---------------- src/lib/eolian/database_type_api.c | 8 ++- src/lib/eolian/eolian_database.h | 1 + 3 files changed, 66 insertions(+), 47 deletions(-) diff --git a/src/lib/eolian/database_type.c b/src/lib/eolian/database_type.c index 2d5b11a..edbf27c 100644 --- a/src/lib/eolian/database_type.c +++ b/src/lib/eolian/database_type.c @@ -131,8 +131,55 @@ database_enum_add(Eolian_Type *tp) database_decl_add(tp->full_name, EOLIAN_DECL_ENUM, tp->base.file, tp->decl); } +void +database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name) +{ + if ((tp->type == EOLIAN_TYPE_REGULAR + || tp->type == EOLIAN_TYPE_COMPLEX + || tp->type == EOLIAN_TYPE_VOID + || tp->type == EOLIAN_TYPE_CLASS) + && tp->is_const) + { + eina_strbuf_append(buf, "const "); + } + if (tp->type == EOLIAN_TYPE_REGULAR + || tp->type == EOLIAN_TYPE_COMPLEX + || tp->type == EOLIAN_TYPE_CLASS) + { + Eina_List *l; + const char *sp; + EINA_LIST_FOREACH(tp->namespaces, l, sp) + { + eina_strbuf_append(buf, sp); + eina_strbuf_append_char(buf, '_'); + } + int kw = eo_lexer_keyword_str_to_id(tp->name); + if (kw && eo_lexer_is_type_keyword(kw)) + eina_strbuf_append(buf, eo_lexer_get_c_type(kw)); + else + eina_strbuf_append(buf, tp->name); + } + else if (tp->type == EOLIAN_TYPE_VOID) + eina_strbuf_append(buf, "void"); + else + { + Eolian_Type *btp = tp->base_type; + database_type_to_str(tp->base_type, buf, NULL); + if (btp->type != EOLIAN_TYPE_POINTER || btp->is_const) + eina_strbuf_append_char(buf, ' '); + eina_strbuf_append_char(buf, '*'); + if (tp->is_const) eina_strbuf_append(buf, " const"); + } + if (name) + { + if (tp->type != EOLIAN_TYPE_POINTER) + eina_strbuf_append_char(buf, ' '); + eina_strbuf_append(buf, name); + } +} + static void -_stype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name) +_stype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf, const char *name) { Eolian_Struct_Type_Field *sf; Eina_List *l; @@ -149,7 +196,7 @@ _stype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name) eina_strbuf_append(buf, tp->name); eina_strbuf_append_char(buf, ' '); } - if (tp->type == EOLIAN_TYPE_STRUCT_OPAQUE) + if (tp->type == EOLIAN_TYPEDECL_STRUCT_OPAQUE) goto append_name; eina_strbuf_append(buf, "{ "); EINA_LIST_FOREACH(tp->field_list, l, sf) @@ -167,7 +214,7 @@ append_name: } static void -_etype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name) +_etype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf, const char *name) { Eolian_Enum_Type_Field *ef; Eina_List *l; @@ -210,7 +257,7 @@ _etype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name) } static void -_atype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf) +_atype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf) { Eina_Strbuf *fulln = eina_strbuf_new(); Eina_List *l; @@ -230,64 +277,29 @@ _atype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf) } void -database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name) +database_typedecl_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf, const char *name) { - if (tp->type == EOLIAN_TYPE_ALIAS) + if (tp->type == EOLIAN_TYPEDECL_ALIAS) { _atype_to_str(tp, buf); return; } - else if (tp->type == EOLIAN_TYPE_STRUCT - || tp->type == EOLIAN_TYPE_STRUCT_OPAQUE) + else if (tp->type == EOLIAN_TYPEDECL_STRUCT + || tp->type == EOLIAN_TYPEDECL_STRUCT_OPAQUE) { _stype_to_str(tp, buf, name); return; } - else if (tp->type == EOLIAN_TYPE_ENUM) + else if (tp->type == EOLIAN_TYPEDECL_ENUM) { _etype_to_str(tp, buf, name); return; } - if ((tp->type == EOLIAN_TYPE_REGULAR - || tp->type == EOLIAN_TYPE_COMPLEX - || tp->type == EOLIAN_TYPE_VOID - || tp->type == EOLIAN_TYPE_CLASS) - && tp->is_const) - { - eina_strbuf_append(buf, "const "); - } - if (tp->type == EOLIAN_TYPE_REGULAR - || tp->type == EOLIAN_TYPE_COMPLEX - || tp->type == EOLIAN_TYPE_CLASS) - { - Eina_List *l; - const char *sp; - EINA_LIST_FOREACH(tp->namespaces, l, sp) - { - eina_strbuf_append(buf, sp); - eina_strbuf_append_char(buf, '_'); - } - int kw = eo_lexer_keyword_str_to_id(tp->name); - if (kw && eo_lexer_is_type_keyword(kw)) - eina_strbuf_append(buf, eo_lexer_get_c_type(kw)); - else - eina_strbuf_append(buf, tp->name); - } - else if (tp->type == EOLIAN_TYPE_VOID) - eina_strbuf_append(buf, "void"); else - { - Eolian_Type *btp = tp->base_type; - database_type_to_str(tp->base_type, buf, NULL); - if (btp->type != EOLIAN_TYPE_POINTER || btp->is_const) - eina_strbuf_append_char(buf, ' '); - eina_strbuf_append_char(buf, '*'); - if (tp->is_const) eina_strbuf_append(buf, " const"); - } + return; if (name) { - if (tp->type != EOLIAN_TYPE_POINTER) - eina_strbuf_append_char(buf, ' '); + eina_strbuf_append_char(buf, ' '); eina_strbuf_append(buf, name); } } diff --git a/src/lib/eolian/database_type_api.c b/src/lib/eolian/database_type_api.c index c64cd78..f167004 100644 --- a/src/lib/eolian/database_type_api.c +++ b/src/lib/eolian/database_type_api.c @@ -340,8 +340,14 @@ eolian_type_c_type_named_get(const Eolian_Type *tp, const char *name) EAPI Eina_Stringshare * eolian_typedecl_c_type_named_get(const Eolian_Typedecl *tp, const char *name) { + Eina_Stringshare *ret; + Eina_Strbuf *buf; EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); - return eolian_type_c_type_named_get(tp->parent, name); + buf = eina_strbuf_new(); + database_typedecl_to_str(tp, buf, name); + ret = eina_stringshare_add(eina_strbuf_string_get(buf)); + eina_strbuf_free(buf); + return ret; } EAPI Eina_Stringshare * diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h index 4919c55..0a14d21 100644 --- a/src/lib/eolian/eolian_database.h +++ b/src/lib/eolian/eolian_database.h @@ -311,6 +311,7 @@ void database_typedef_del(Eolian_Type *tp); void database_typedecl_del(Eolian_Typedecl *tp); void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name); +void database_typedecl_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf, const char *name); /* expressions */ -- 2.7.4