eolian: new API: eolian_type_alias_find_by_name, remove the old APIs that take an alias name, update tests

This commit is contained in:
Daniel Kolesa 2014-07-21 17:12:35 +01:00
parent 058a3c314c
commit b81e05def5
6 changed files with 34 additions and 60 deletions

View File

@ -761,37 +761,17 @@ EAPI Eina_Bool eolian_class_ctor_enable_get(const Eolian_Class *klass);
EAPI Eina_Bool eolian_class_dtor_enable_get(const Eolian_Class *klass); EAPI Eina_Bool eolian_class_dtor_enable_get(const Eolian_Class *klass);
/* /*
* @brief Find the type for a certain alias * @brief Find the an alias type by name. Supports namespaces.
* *
* @param[in] alias alias of the type definition * @param[in] name the name of the alias
* @return real type of the type definition * @return the alias type or NULL
* *
* @ingroup Eolian * @ingroup Eolian
*/ */
EAPI const Eolian_Type *eolian_type_find_by_alias(const char *alias); EAPI const Eolian_Type *eolian_type_alias_find_by_name(const char *name);
/* /*
* @brief Check if a typedef is extern. * @brief Find a struct by name. Supports namespaces.
*
* @param[in] alias alias of the typedef
* @return EINA_TRUE if it's extern, EINA_FALSE otherwise.
*
* @ingroup Eolian
*/
EAPI Eina_Bool eolian_typedef_is_extern(const char *alias);
/*
* @brief Find the filename for a certain alias
*
* @param[in] alias alias of the type definition
* @return the filename or NULL if @c alias is not found
*
* @ingroup Eolian
*/
EAPI Eina_Stringshare *eolian_typedef_file_get(const char *alias);
/*
* @brief Find a struct by name
* *
* @param[in] name the name of the struct * @param[in] name the name of the struct
* @return the struct or NULL * @return the struct or NULL

View File

@ -3,33 +3,13 @@
#include "eo_definitions.h" #include "eo_definitions.h"
EAPI const Eolian_Type * EAPI const Eolian_Type *
eolian_type_find_by_alias(const char *alias) eolian_type_alias_find_by_name(const char *name)
{ {
if (!_aliases) return NULL; if (!_aliases) return NULL;
Eina_Stringshare *shr = eina_stringshare_add(alias); Eina_Stringshare *shr = eina_stringshare_add(name);
Eolian_Type *def = eina_hash_find(_aliases, shr); Eolian_Type *tp = eina_hash_find(_aliases, shr);
eina_stringshare_del(shr); eina_stringshare_del(shr);
return def ? def->base_type : NULL; return tp;
}
EAPI Eina_Bool
eolian_typedef_is_extern(const char *alias)
{
if (!_aliases) return EINA_FALSE;
Eina_Stringshare *shr = eina_stringshare_add(alias);
Eolian_Type *def = eina_hash_find(_aliases, shr);
eina_stringshare_del(shr);
return def ? def->is_extern : EINA_FALSE;
}
EAPI Eina_Stringshare *
eolian_typedef_file_get(const char *alias)
{
if (!_aliases) return EINA_FALSE;
Eina_Stringshare *shr = eina_stringshare_add(alias);
Eolian_Type *def = eina_hash_find(_aliases, shr);
eina_stringshare_del(shr);
return def ? eina_stringshare_ref(def->file) : NULL;
} }
EAPI const Eolian_Type * EAPI const Eolian_Type *

View File

@ -471,6 +471,7 @@ parse_typedef(Eo_Lexer *ls)
is_extern = EINA_TRUE; is_extern = EINA_TRUE;
eo_lexer_get(ls); eo_lexer_get(ls);
} }
def->type = EOLIAN_TYPE_ALIAS;
def->is_extern = is_extern; def->is_extern = is_extern;
buf = push_strbuf(ls); buf = push_strbuf(ls);
line = ls->line_number; line = ls->line_number;

View File

@ -2,7 +2,7 @@
type Foo: int; type Foo: int;
/* extern type */ /* extern type */
type @extern Evas_Coord: int; type @extern Evas.Coord: int;
/* regular struct */ /* regular struct */
struct X struct X

View File

@ -1,4 +1,4 @@
type Evas_Coord: int; /* Simple type definition */ type Evas.Coord: int; /* Simple type definition */
type List_Objects: own(Eina.List*)< Eo *>; /* A little more complex */ type List_Objects: own(Eina.List*)< Eo *>; /* A little more complex */
class Dummy { class Dummy {

View File

@ -221,7 +221,7 @@ END_TEST
START_TEST(eolian_typedef) START_TEST(eolian_typedef)
{ {
const Eolian_Type *type = NULL; const Eolian_Type *atype = NULL, *type = NULL;
const char *type_name = NULL; const char *type_name = NULL;
Eina_Iterator *iter = NULL; Eina_Iterator *iter = NULL;
const Eolian_Class *class; const Eolian_Class *class;
@ -236,7 +236,12 @@ START_TEST(eolian_typedef)
fail_if(!eolian_class_function_find_by_name(class, "foo", EOLIAN_METHOD)); fail_if(!eolian_class_function_find_by_name(class, "foo", EOLIAN_METHOD));
/* Basic type */ /* Basic type */
fail_if(!(type = eolian_type_find_by_alias("Evas_Coord"))); fail_if(!(atype = eolian_type_alias_find_by_name("Evas.Coord")));
fail_if(eolian_type_type_get(atype) != EOLIAN_TYPE_ALIAS);
fail_if(!(type_name = eolian_type_name_get(atype)));
fail_if(strcmp(type_name, "Coord"));
eina_stringshare_del(type_name);
fail_if(!(type = eolian_type_base_type_get(atype)));
fail_if(!(type_name = eolian_type_name_get(type))); fail_if(!(type_name = eolian_type_name_get(type)));
fail_if(eolian_type_is_own(type)); fail_if(eolian_type_is_own(type));
fail_if(eolian_type_is_const(type)); fail_if(eolian_type_is_const(type));
@ -245,12 +250,16 @@ START_TEST(eolian_typedef)
eina_stringshare_del(type_name); eina_stringshare_del(type_name);
/* File */ /* File */
fail_if(!(file = eolian_typedef_file_get("Evas_Coord"))); fail_if(!(file = eolian_type_file_get(atype)));
fail_if(strcmp(file, "typedef.eo")); fail_if(strcmp(file, "typedef.eo"));
eina_stringshare_del(file); eina_stringshare_del(file);
/* Complex type */ /* Complex type */
fail_if(!(type = eolian_type_find_by_alias("List_Objects"))); fail_if(!(atype = eolian_type_alias_find_by_name("List_Objects")));
fail_if(!(type_name = eolian_type_name_get(atype)));
fail_if(strcmp(type_name, "List_Objects"));
eina_stringshare_del(type_name);
fail_if(!(type = eolian_type_base_type_get(atype)));
fail_if(!(type_name = eolian_type_c_type_get(type))); fail_if(!(type_name = eolian_type_c_type_get(type)));
fail_if(!eolian_type_is_own(type)); fail_if(!eolian_type_is_own(type));
fail_if(strcmp(type_name, "Eina_List *")); fail_if(strcmp(type_name, "Eina_List *"));
@ -491,7 +500,7 @@ END_TEST
START_TEST(eolian_struct) START_TEST(eolian_struct)
{ {
const Eolian_Type *type = NULL, *field = NULL; const Eolian_Type *atype = NULL, *type = NULL, *field = NULL;
const Eolian_Class *class; const Eolian_Class *class;
const char *type_name; const char *type_name;
const char *file; const char *file;
@ -541,14 +550,16 @@ START_TEST(eolian_struct)
fail_if(eolian_type_type_get(field) != EOLIAN_TYPE_REGULAR_STRUCT); fail_if(eolian_type_type_get(field) != EOLIAN_TYPE_REGULAR_STRUCT);
/* typedef */ /* typedef */
fail_if(!(type = eolian_type_find_by_alias("Foo"))); fail_if(!(atype = eolian_type_alias_find_by_name("Foo")));
fail_if(!(type = eolian_type_base_type_get(atype)));
fail_if(!(type_name = eolian_type_name_get(type))); fail_if(!(type_name = eolian_type_name_get(type)));
fail_if(eolian_type_type_get(type) != EOLIAN_TYPE_STRUCT); fail_if(eolian_type_type_get(type) != EOLIAN_TYPE_STRUCT);
fail_if(strcmp(type_name, "_Foo")); fail_if(strcmp(type_name, "_Foo"));
eina_stringshare_del(type_name); eina_stringshare_del(type_name);
/* typedef - anon */ /* typedef - anon */
fail_if(!(type = eolian_type_find_by_alias("Bar"))); fail_if(!(atype = eolian_type_alias_find_by_name("Bar")));
fail_if(!(type = eolian_type_base_type_get(atype)));
fail_if(!!(type_name = eolian_type_name_get(type))); fail_if(!!(type_name = eolian_type_name_get(type)));
fail_if(eolian_type_type_get(type) != EOLIAN_TYPE_STRUCT); fail_if(eolian_type_type_get(type) != EOLIAN_TYPE_STRUCT);
@ -571,10 +582,12 @@ START_TEST(eolian_extern)
fail_if(!eolian_class_function_find_by_name(class, "foo", EOLIAN_METHOD)); fail_if(!eolian_class_function_find_by_name(class, "foo", EOLIAN_METHOD));
/* regular type */ /* regular type */
fail_if(eolian_typedef_is_extern("Foo")); fail_if(!(type = eolian_type_alias_find_by_name("Foo")));
fail_if(eolian_type_is_extern(type));
/* extern type */ /* extern type */
fail_if(!eolian_typedef_is_extern("Evas_Coord")); fail_if(!(type = eolian_type_alias_find_by_name("Evas.Coord")));
fail_if(!eolian_type_is_extern(type));
/* regular struct */ /* regular struct */
fail_if(!(type = eolian_type_struct_find_by_name("X"))); fail_if(!(type = eolian_type_struct_find_by_name("X")));