forked from enlightenment/efl
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:
parent
058a3c314c
commit
b81e05def5
|
@ -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);
|
||||
|
||||
/*
|
||||
* @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
|
||||
* @return real type of the type definition
|
||||
* @param[in] name the name of the alias
|
||||
* @return the alias type or NULL
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @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
|
||||
* @brief Find a struct by name. Supports namespaces.
|
||||
*
|
||||
* @param[in] name the name of the struct
|
||||
* @return the struct or NULL
|
||||
|
|
|
@ -3,33 +3,13 @@
|
|||
#include "eo_definitions.h"
|
||||
|
||||
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;
|
||||
Eina_Stringshare *shr = eina_stringshare_add(alias);
|
||||
Eolian_Type *def = eina_hash_find(_aliases, shr);
|
||||
Eina_Stringshare *shr = eina_stringshare_add(name);
|
||||
Eolian_Type *tp = eina_hash_find(_aliases, shr);
|
||||
eina_stringshare_del(shr);
|
||||
return def ? def->base_type : NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
return tp;
|
||||
}
|
||||
|
||||
EAPI const Eolian_Type *
|
||||
|
|
|
@ -471,6 +471,7 @@ parse_typedef(Eo_Lexer *ls)
|
|||
is_extern = EINA_TRUE;
|
||||
eo_lexer_get(ls);
|
||||
}
|
||||
def->type = EOLIAN_TYPE_ALIAS;
|
||||
def->is_extern = is_extern;
|
||||
buf = push_strbuf(ls);
|
||||
line = ls->line_number;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
type Foo: int;
|
||||
|
||||
/* extern type */
|
||||
type @extern Evas_Coord: int;
|
||||
type @extern Evas.Coord: int;
|
||||
|
||||
/* regular struct */
|
||||
struct X
|
||||
|
|
|
@ -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 */
|
||||
|
||||
class Dummy {
|
||||
|
|
|
@ -221,7 +221,7 @@ END_TEST
|
|||
|
||||
START_TEST(eolian_typedef)
|
||||
{
|
||||
const Eolian_Type *type = NULL;
|
||||
const Eolian_Type *atype = NULL, *type = NULL;
|
||||
const char *type_name = NULL;
|
||||
Eina_Iterator *iter = NULL;
|
||||
const Eolian_Class *class;
|
||||
|
@ -236,7 +236,12 @@ START_TEST(eolian_typedef)
|
|||
fail_if(!eolian_class_function_find_by_name(class, "foo", EOLIAN_METHOD));
|
||||
|
||||
/* 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(eolian_type_is_own(type));
|
||||
fail_if(eolian_type_is_const(type));
|
||||
|
@ -245,12 +250,16 @@ START_TEST(eolian_typedef)
|
|||
eina_stringshare_del(type_name);
|
||||
|
||||
/* File */
|
||||
fail_if(!(file = eolian_typedef_file_get("Evas_Coord")));
|
||||
fail_if(!(file = eolian_type_file_get(atype)));
|
||||
fail_if(strcmp(file, "typedef.eo"));
|
||||
eina_stringshare_del(file);
|
||||
|
||||
/* 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(!eolian_type_is_own(type));
|
||||
fail_if(strcmp(type_name, "Eina_List *"));
|
||||
|
@ -491,7 +500,7 @@ END_TEST
|
|||
|
||||
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 char *type_name;
|
||||
const char *file;
|
||||
|
@ -541,14 +550,16 @@ START_TEST(eolian_struct)
|
|||
fail_if(eolian_type_type_get(field) != EOLIAN_TYPE_REGULAR_STRUCT);
|
||||
|
||||
/* 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(eolian_type_type_get(type) != EOLIAN_TYPE_STRUCT);
|
||||
fail_if(strcmp(type_name, "_Foo"));
|
||||
eina_stringshare_del(type_name);
|
||||
|
||||
/* 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(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));
|
||||
|
||||
/* 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 */
|
||||
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 */
|
||||
fail_if(!(type = eolian_type_struct_find_by_name("X")));
|
||||
|
|
Loading…
Reference in New Issue