q66 pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=211b650c4bf3701e93756fc2babda08a0949f805

commit 211b650c4bf3701e93756fc2babda08a0949f805
Author: Daniel Kolesa <d.kol...@osg.samsung.com>
Date:   Tue May 12 17:04:54 2015 +0100

    eolian: new API eolian_type_enum_field_c_name_get
    
    This API allows you to retrieve the C name of an arbitrary enum field,
    respecting the legacy prefix and properly uppercasing the name.
---
 src/lib/eolian/Eolian.h            | 12 ++++++++++++
 src/lib/eolian/database_type_api.c | 22 ++++++++++++++++++++++
 src/lib/eolian/eo_parser.c         |  1 +
 src/lib/eolian/eolian_database.h   |  1 +
 src/tests/eolian/data/enum.eo      |  1 +
 src/tests/eolian/eolian_parsing.c  | 10 ++++++++++
 6 files changed, 47 insertions(+)

diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index 63ff0cf..795eed6 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -1564,6 +1564,18 @@ EAPI const Eolian_Enum_Type_Field 
*eolian_type_enum_field_get(const Eolian_Type
 EAPI Eina_Stringshare *eolian_type_enum_field_name_get(const 
Eolian_Enum_Type_Field *fl);
 
 /*
+ * @brief Get the C name of a field of an enum type.
+ *
+ * The user of the API is responsible for the resulting stringshare.
+ *
+ * @param[in] fl the field.
+ * @return the name.
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Stringshare *eolian_type_enum_field_c_name_get(const 
Eolian_Enum_Type_Field *fl);
+
+/*
  * @brief Get the description of a field of an enum type.
  *
  * @param[in] fl the field.
diff --git a/src/lib/eolian/database_type_api.c 
b/src/lib/eolian/database_type_api.c
index 8f95590..28ed9e5 100644
--- a/src/lib/eolian/database_type_api.c
+++ b/src/lib/eolian/database_type_api.c
@@ -155,6 +155,28 @@ eolian_type_enum_field_name_get(const 
Eolian_Enum_Type_Field *fl)
 }
 
 EAPI Eina_Stringshare *
+eolian_type_enum_field_c_name_get(const Eolian_Enum_Type_Field *fl)
+{
+   Eina_Stringshare *ret;
+   Eina_Strbuf *buf;
+   char *bufp;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
+   buf = eina_strbuf_new();
+   if (fl->base_enum->legacy)
+     eina_strbuf_append(buf, fl->base_enum->legacy);
+   else
+     eina_strbuf_append(buf, fl->base_enum->full_name);
+   eina_strbuf_append_char(buf, '_');
+   eina_strbuf_append(buf, fl->name);
+   bufp = eina_strbuf_string_steal(buf);
+   eina_strbuf_free(buf);
+   eina_str_toupper(&bufp);
+   ret = eina_stringshare_add(bufp);
+   free(bufp);
+   return ret;
+}
+
+EAPI Eina_Stringshare *
 eolian_type_enum_field_description_get(const Eolian_Enum_Type_Field *fl)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 3a0b80f..e256c7e 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -578,6 +578,7 @@ parse_enum(Eo_Lexer *ls, const char *name, Eina_Bool 
is_extern,
         def->field_list = eina_list_append(def->field_list, fdef);
         eo_lexer_get(ls);
         FILL_BASE(fdef->base, ls, fline, fcol);
+        fdef->base_enum = def;
         fdef->name = eina_stringshare_ref(fname);
         if (ls->t.token != '=')
           {
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index a9ab8d9..0bd9ac8 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -200,6 +200,7 @@ struct _Eolian_Struct_Type_Field
 
 struct _Eolian_Enum_Type_Field
 {
+   Eolian_Type       *base_enum;
    Eina_Stringshare  *name;
    Eolian_Object      base;
    Eolian_Expression *value;
diff --git a/src/tests/eolian/data/enum.eo b/src/tests/eolian/data/enum.eo
index 0f803da..49bc369 100644
--- a/src/tests/eolian/data/enum.eo
+++ b/src/tests/eolian/data/enum.eo
@@ -6,6 +6,7 @@ enum Foo {
 }
 
 enum Bar {
+    legacy: test;
     foo = Foo.baz
 }
 
diff --git a/src/tests/eolian/eolian_parsing.c 
b/src/tests/eolian/eolian_parsing.c
index 58c7973..182272b 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -838,6 +838,7 @@ START_TEST(eolian_enum)
    const Eolian_Type *type = NULL;
    const Eolian_Class *class;
    const Eolian_Expression *exp;
+   Eina_Stringshare *cname;
    const char *name;
    Eolian_Value v;
 
@@ -868,6 +869,7 @@ START_TEST(eolian_enum)
    fail_if(v.value.i != 15);
 
    fail_if(!(type = eolian_type_enum_get_by_name("Bar")));
+   fail_if(strcmp(eolian_type_enum_legacy_prefix_get(type), "test"));
 
    fail_if(!(field = eolian_type_enum_field_get(type, "foo")));
    fail_if(!(exp = eolian_type_enum_field_value_get(field)));
@@ -875,6 +877,10 @@ START_TEST(eolian_enum)
    fail_if(v.type != EOLIAN_EXPR_INT);
    fail_if(v.value.i != 15);
 
+   cname = eolian_type_enum_field_c_name_get(field);
+   fail_if(strcmp(cname, "TEST_FOO"));
+   eina_stringshare_del(cname);
+
    fail_if(!(type = eolian_type_enum_get_by_name("Baz")));
 
    fail_if(!(field = eolian_type_enum_field_get(type, "flag1")));
@@ -889,6 +895,10 @@ START_TEST(eolian_enum)
    fail_if(v.type != EOLIAN_EXPR_INT);
    fail_if(v.value.i != (1 << 1));
 
+   cname = eolian_type_enum_field_c_name_get(field);
+   fail_if(strcmp(cname, "BAZ_FLAG2"));
+   eina_stringshare_del(cname);
+
    fail_if(!(field = eolian_type_enum_field_get(type, "flag3")));
    fail_if(!(exp = eolian_type_enum_field_value_get(field)));
    v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);

-- 


Reply via email to