eolian: new APIs
authorDaniel Kolesa <d.kolesa@samsung.com>
Tue, 12 Aug 2014 14:26:48 +0000 (15:26 +0100)
committerDaniel Kolesa <d.kolesa@samsung.com>
Thu, 21 Aug 2014 08:26:04 +0000 (09:26 +0100)
This adds eolian_show_enum, eolian_show_global, eolian_show_constant.

src/lib/eolian/Eolian.h
src/lib/eolian/database_print.c
src/lib/eolian/database_type.c
src/lib/eolian/eolian_database.h

index 080ca45c3a2942b841bed4b7135cffb462f4f2db..ff2166516fee040436fa39632bd9c1cacfb573d9 100644 (file)
@@ -288,6 +288,9 @@ EAPI Eina_Bool eolian_all_eot_files_parse();
  *
  * @see eolian_show_typedef
  * @see eolian_show_struct
+ * @see eolian_show_enum
+ * @see eolian_show_global
+ * @see eolian_show_constant
  * @see eolian_show_all
  *
  * @ingroup Eolian
@@ -307,6 +310,9 @@ EAPI Eina_Bool eolian_show_class(const Eolian_Class *klass);
  *
  * @see eolian_show_class
  * @see eolian_show_struct
+ * @see eolian_show_enum
+ * @see eolian_show_global
+ * @see eolian_show_constant
  * @see eolian_show_all
  *
  * @ingroup Eolian
@@ -326,12 +332,81 @@ EAPI Eina_Bool eolian_show_typedef(const char *alias);
  *
  * @see eolian_show_class
  * @see eolian_show_typedef
+ * @see eolian_show_enum
+ * @see eolian_show_global
+ * @see eolian_show_constant
  * @see eolian_show_all
  *
  * @ingroup Eolian
  */
 EAPI Eina_Bool eolian_show_struct(const char *name);
 
+/*
+ * @brief Show information about a given enum.
+ *
+ * If @c name is NULL, this function will print information of
+ * all the enums.
+ *
+ * @param[in] name the enum to show.
+ *
+ * @return EINA_TRUE on success, EINA_FALSE otherwise (when enum is not
+ * found).
+ *
+ * @see eolian_show_class
+ * @see eolian_show_typedef
+ * @see eolian_show_struct
+ * @see eolian_show_global
+ * @see eolian_show_constant
+ * @see eolian_show_all
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Bool eolian_show_enum(const char *name);
+
+/*
+ * @brief Show information about a given global.
+ *
+ * If @c name is NULL, this function will print information of
+ * all the globals.
+ *
+ * @param[in] name the global to show.
+ *
+ * @return EINA_TRUE on success, EINA_FALSE otherwise (when global is not
+ * found).
+ *
+ * @see eolian_show_class
+ * @see eolian_show_typedef
+ * @see eolian_show_struct
+ * @see eolian_show_enum
+ * @see eolian_show_constant
+ * @see eolian_show_all
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Bool eolian_show_global(const char *name);
+
+/*
+ * @brief Show information about a given constant.
+ *
+ * If @c name is NULL, this function will print information of
+ * all the constants.
+ *
+ * @param[in] name the constant to show.
+ *
+ * @return EINA_TRUE on success, EINA_FALSE otherwise (when constant is not
+ * found).
+ *
+ * @see eolian_show_class
+ * @see eolian_show_typedef
+ * @see eolian_show_struct
+ * @see eolian_show_enum
+ * @see eolian_show_global
+ * @see eolian_show_all
+ *
+ * @ingroup Eolian
+ */
+EAPI Eina_Bool eolian_show_constant(const char *name);
+
 /*
  * @brief Show information about everything.
  *
@@ -341,6 +416,7 @@ EAPI Eina_Bool eolian_show_struct(const char *name);
  * @see eolian_show_class
  * @see eolian_show_typedef
  * @see eolian_show_struct
+ * @see eolian_show_enum
  *
  * @ingroup Eolian
  */
index f2773d3551b5832708a95742b1b989a4c0eaad87..7b110d8e65f253f6d4d7444dc738fd5ae9a9202b 100644 (file)
@@ -294,7 +294,7 @@ eolian_show_typedef(const char *alias)
 
 static Eina_Bool
 _struct_cb(Eina_Hash *hash EINA_UNUSED, const char *name,
-            const Eolian_Type *tp, const void *fdata EINA_UNUSED)
+           const Eolian_Type *tp, const void *fdata EINA_UNUSED)
 {
    printf("Struct: %s\n", name);
    printf("  type: <");
@@ -319,6 +319,79 @@ eolian_show_struct(const char *name)
    return EINA_TRUE;
 }
 
+static Eina_Bool
+_enum_cb(Eina_Hash *hash EINA_UNUSED, const char *name,
+         const Eolian_Type *tp, const void *fdata EINA_UNUSED)
+{
+   printf("Enum: %s\n", name);
+   printf("  type: <");
+   database_type_print((Eolian_Type*)tp);
+   printf(">\n");
+   return EINA_TRUE;
+}
+
+EAPI Eina_Bool
+eolian_show_enum(const char *name)
+{
+   if (!name)
+     eina_hash_foreach(_enums, (Eina_Hash_Foreach)_enum_cb, NULL);
+   else
+     {
+        Eina_Stringshare *shr = eina_stringshare_add(name);
+        Eolian_Type *tp = eina_hash_find(_enums, shr);
+        eina_stringshare_del(shr);
+        if (!tp) return EINA_FALSE;
+        _enum_cb(NULL, name, tp, NULL);
+     }
+   return EINA_TRUE;
+}
+
+static Eina_Bool
+_var_cb(Eina_Hash *hash EINA_UNUSED, const char *name,
+        const Eolian_Variable *var, const void *fdata EINA_UNUSED)
+{
+   if (var->type == EOLIAN_VAR_CONSTANT)
+     printf("Constant: %s\n", name);
+   else
+     printf("Global: %s\n", name);
+   printf("  value: <");
+   database_expr_print(var->value);
+   printf(">\n");
+   return EINA_TRUE;
+}
+
+EAPI Eina_Bool
+eolian_show_global(const char *name)
+{
+   if (!name)
+     eina_hash_foreach(_globals, (Eina_Hash_Foreach)_var_cb, NULL);
+   else
+     {
+        Eina_Stringshare *shr = eina_stringshare_add(name);
+        Eolian_Variable *var = eina_hash_find(_globals, shr);
+        eina_stringshare_del(shr);
+        if (!var) return EINA_FALSE;
+        _var_cb(NULL, name, var, NULL);
+     }
+   return EINA_TRUE;
+}
+
+EAPI Eina_Bool
+eolian_show_constant(const char *name)
+{
+   if (!name)
+     eina_hash_foreach(_constants, (Eina_Hash_Foreach)_var_cb, NULL);
+   else
+     {
+        Eina_Stringshare *shr = eina_stringshare_add(name);
+        Eolian_Variable *var = eina_hash_find(_constants, shr);
+        eina_stringshare_del(shr);
+        if (!var) return EINA_FALSE;
+        _var_cb(NULL, name, var, NULL);
+     }
+   return EINA_TRUE;
+}
+
 EAPI void
 eolian_show_all()
 {
index a47a2f02cea14088cf668a4fb87d16ece54320ce..14d37a6a4b37f8fa854608f9984aa649c6e8f2ed 100644 (file)
@@ -267,6 +267,17 @@ _typedef_print(Eolian_Type *tp)
    database_type_print(tp->base_type);
 }
 
+void
+database_expr_print(Eolian_Expression *exp)
+{
+   Eina_Value *val = NULL;
+   Eolian_Expression_Type et = eolian_expression_eval(exp, EOLIAN_MASK_ALL,
+       &val);
+   const char *ret = eolian_expression_value_to_literal(val, et);
+   printf("%s", ret);
+   eina_stringshare_del(ret);
+}
+
 void
 database_type_print(Eolian_Type *tp)
 {
@@ -342,14 +353,8 @@ database_type_print(Eolian_Type *tp)
              printf("%s", fname);
              if (ef->value)
                {
-                  Eina_Value *val = NULL;
-                  Eolian_Expression_Type et = eolian_expression_eval(ef->value,
-                      EOLIAN_MASK_INT, &val);
-                  const char *ret;
                   printf(" = ");
-                  ret = eolian_expression_value_to_literal(val, et);
-                  printf("%s", ret);
-                  eina_stringshare_del(ret);
+                  database_expr_print(ef->value);
                }
              if (l != eina_list_last(tp->field_names))
                printf(", ");
index 58b2a30ccbf3afd77c881c0b6a564dd9c40af44e..58dadd7b168e9b57b319cb9aec81ab134b1d9f01 100644 (file)
@@ -274,6 +274,7 @@ void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *n
 
 Eolian_Expression_Type database_expr_eval(const Eolian_Expression *expr, Eolian_Expression_Mask mask, Eina_Value **out);
 void database_expr_del(Eolian_Expression *expr);
+void database_expr_print(Eolian_Expression *expr);
 
 /* variables */