eolian: refactor the struct/enum field APIs
This commit is contained in:
parent
894c9a42db
commit
b75014a024
|
@ -69,7 +69,7 @@ _type_generate(const Eolian_Type *tp, Eina_Bool in_typedef)
|
|||
case EOLIAN_TYPE_STRUCT:
|
||||
case EOLIAN_TYPE_STRUCT_OPAQUE:
|
||||
{
|
||||
const char *member_name;
|
||||
const Eolian_Struct_Type_Field *member;
|
||||
char *name = _concat_name(tp);
|
||||
if ((in_typedef && name) || tp_type == EOLIAN_TYPE_STRUCT_OPAQUE)
|
||||
{
|
||||
|
@ -79,15 +79,15 @@ _type_generate(const Eolian_Type *tp, Eina_Bool in_typedef)
|
|||
}
|
||||
eina_strbuf_append_printf(buf, "struct%s%s {\n", name?" ":"", name?name:"");
|
||||
free(name);
|
||||
Eina_Iterator *members = eolian_type_struct_field_names_get(tp);
|
||||
EINA_ITERATOR_FOREACH(members, member_name)
|
||||
Eina_Iterator *members = eolian_type_struct_fields_get(tp);
|
||||
EINA_ITERATOR_FOREACH(members, member)
|
||||
{
|
||||
const char *desc = eolian_type_struct_field_description_get(tp, member_name);
|
||||
const Eolian_Type *member = eolian_type_struct_field_get(tp, member_name);
|
||||
Eina_Stringshare *c_type = eolian_type_c_type_get(member);
|
||||
const char *desc = eolian_type_struct_field_description_get(member);
|
||||
const Eolian_Type *type = eolian_type_struct_field_type_get(member);
|
||||
Eina_Stringshare *c_type = eolian_type_c_type_get(type);
|
||||
eina_strbuf_append_printf(buf, " %s%s%s;",
|
||||
c_type, strchr(c_type, '*')?"":" ",
|
||||
member_name);
|
||||
eolian_type_struct_field_name_get(member));
|
||||
if (desc) eina_strbuf_append_printf(buf, " /** %s */", desc);
|
||||
eina_strbuf_append(buf, "\n");
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ _type_generate(const Eolian_Type *tp, Eina_Bool in_typedef)
|
|||
}
|
||||
case EOLIAN_TYPE_ENUM:
|
||||
{
|
||||
const char *member_name;
|
||||
const Eolian_Enum_Type_Field *member;
|
||||
char *name = _concat_name(tp);
|
||||
if (in_typedef)
|
||||
{
|
||||
|
@ -115,28 +115,28 @@ _type_generate(const Eolian_Type *tp, Eina_Bool in_typedef)
|
|||
else
|
||||
pre = name;
|
||||
eina_str_toupper(&pre);
|
||||
Eina_Iterator *members = eolian_type_enum_field_names_get(tp);
|
||||
Eina_Bool next = eina_iterator_next(members, (void**)&member_name);
|
||||
Eina_Iterator *members = eolian_type_enum_fields_get(tp);
|
||||
Eina_Bool next = eina_iterator_next(members, (void**)&member);
|
||||
Eina_Strbuf *membuf = eina_strbuf_new();
|
||||
while (next)
|
||||
{
|
||||
const char *desc = eolian_type_enum_field_description_get(tp, member_name);
|
||||
const Eolian_Expression *member = eolian_type_enum_field_get(tp, member_name);
|
||||
char *memb_u = strdup(member_name);
|
||||
const char *desc = eolian_type_enum_field_description_get(member);
|
||||
const Eolian_Expression *value = eolian_type_enum_field_value_get(member);
|
||||
char *memb_u = strdup(eolian_type_enum_field_name_get(member));
|
||||
eina_str_toupper(&memb_u);
|
||||
eina_strbuf_reset(membuf);
|
||||
eina_strbuf_append(membuf, pre);
|
||||
eina_strbuf_append_char(membuf, '_');
|
||||
eina_strbuf_append(membuf, memb_u);
|
||||
free(memb_u);
|
||||
if (!member)
|
||||
if (!value)
|
||||
eina_strbuf_append_printf(buf, " %s", eina_strbuf_string_get(membuf));
|
||||
else
|
||||
{
|
||||
Eolian_Value val = eolian_expression_eval(member, EOLIAN_MASK_INT);
|
||||
Eolian_Value val = eolian_expression_eval(value, EOLIAN_MASK_INT);
|
||||
const char *lit = eolian_expression_value_to_literal(&val);
|
||||
eina_strbuf_append_printf(buf, " %s = %s", eina_strbuf_string_get(membuf), lit);
|
||||
const char *exp = eolian_expression_serialize(member);
|
||||
const char *exp = eolian_expression_serialize(value);
|
||||
if (exp && strcmp(lit, exp))
|
||||
{
|
||||
eina_strbuf_append_printf(buf, " /* %s */", exp);
|
||||
|
@ -144,7 +144,7 @@ _type_generate(const Eolian_Type *tp, Eina_Bool in_typedef)
|
|||
}
|
||||
eina_stringshare_del(lit);
|
||||
}
|
||||
next = eina_iterator_next(members, (void**)&member_name);
|
||||
next = eina_iterator_next(members, (void**)&member);
|
||||
if (next)
|
||||
eina_strbuf_append(buf, ",");
|
||||
if (desc) eina_strbuf_append_printf(buf, " /** %s */", desc);
|
||||
|
|
|
@ -86,6 +86,18 @@ typedef struct _Eolian_Expression Eolian_Expression;
|
|||
*/
|
||||
typedef struct _Eolian_Variable Eolian_Variable;
|
||||
|
||||
/* Struct field information
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
typedef struct _Eolian_Struct_Type_Field Eolian_Struct_Type_Field;
|
||||
|
||||
/* Enum field information
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
typedef struct _Eolian_Enum_Type_Field Eolian_Enum_Type_Field;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EOLIAN_UNRESOLVED,
|
||||
|
@ -1094,14 +1106,14 @@ EAPI Eina_Iterator *eolian_type_arguments_get(const Eolian_Type *tp);
|
|||
EAPI Eina_Iterator *eolian_type_subtypes_get(const Eolian_Type *tp);
|
||||
|
||||
/*
|
||||
* @brief Get an iterator to all field names of a struct type.
|
||||
* @brief Get an iterator to all fields of a struct type.
|
||||
*
|
||||
* @param[in] tp the type.
|
||||
* @return the iterator when @c tp is EOLIAN_TYPE_STRUCT, NULL otherwise.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eina_Iterator *eolian_type_struct_field_names_get(const Eolian_Type *tp);
|
||||
EAPI Eina_Iterator *eolian_type_struct_fields_get(const Eolian_Type *tp);
|
||||
|
||||
/*
|
||||
* @brief Get a field of a struct type.
|
||||
|
@ -1113,40 +1125,47 @@ EAPI Eina_Iterator *eolian_type_struct_field_names_get(const Eolian_Type *tp);
|
|||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI const Eolian_Type *eolian_type_struct_field_get(const Eolian_Type *tp, const char *field);
|
||||
EAPI const Eolian_Struct_Type_Field *eolian_type_struct_field_get(const Eolian_Type *tp, const char *field);
|
||||
|
||||
/*
|
||||
* @brief Get the name of a field of a struct type.
|
||||
*
|
||||
* @param[in] fl the field.
|
||||
* @return the name.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eina_Stringshare *eolian_type_struct_field_name_get(const Eolian_Struct_Type_Field *fl);
|
||||
|
||||
/*
|
||||
* @brief Get the description of a field of a struct type.
|
||||
*
|
||||
* @param[in] tp the type.
|
||||
* @param[in] field the field name.
|
||||
* @return the description when @c tp is EOLIAN_TYPE_STRUCT, @c field is not NULL
|
||||
* and the field exists, NULL otherwise.
|
||||
* @param[in] fl the field.
|
||||
* @return the description.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eina_Stringshare *eolian_type_struct_field_description_get(const Eolian_Type *tp, const char *field);
|
||||
EAPI Eina_Stringshare *eolian_type_struct_field_description_get(const Eolian_Struct_Type_Field *fl);
|
||||
|
||||
/*
|
||||
* @brief Get an iterator to all field names of an enum type.
|
||||
* @brief Get the type of a field of a struct type.
|
||||
*
|
||||
* @param[in] fl the field.
|
||||
* @return the type.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI const Eolian_Type *eolian_type_struct_field_type_get(const Eolian_Struct_Type_Field *fl);
|
||||
|
||||
/*
|
||||
* @brief Get an iterator to all fields of an enum type.
|
||||
*
|
||||
* @param[in] tp the type.
|
||||
* @return the iterator when @c tp is EOLIAN_TYPE_ENUM, NULL otherwise.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eina_Iterator *eolian_type_enum_field_names_get(const Eolian_Type *tp);
|
||||
|
||||
/*
|
||||
* @brief Get whether an enum field exists.
|
||||
*
|
||||
* @param[in] tp the type.
|
||||
* @param[in] field the field name.
|
||||
* @return EINA_TRUE when the field exists, EINA_FALSE otherwise.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eina_Bool eolian_type_enum_field_exists(const Eolian_Type *tp, const char *field);
|
||||
EAPI Eina_Iterator *eolian_type_enum_fields_get(const Eolian_Type *tp);
|
||||
|
||||
/*
|
||||
* @brief Get a field of an enum type.
|
||||
|
@ -1161,19 +1180,37 @@ EAPI Eina_Bool eolian_type_enum_field_exists(const Eolian_Type *tp, const char *
|
|||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI const Eolian_Expression *eolian_type_enum_field_get(const Eolian_Type *tp, const char *field);
|
||||
EAPI const Eolian_Enum_Type_Field *eolian_type_enum_field_get(const Eolian_Type *tp, const char *field);
|
||||
|
||||
/*
|
||||
* @brief Get the name of a field of an enum type.
|
||||
*
|
||||
* @param[in] fl the field.
|
||||
* @return the name.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eina_Stringshare *eolian_type_enum_field_name_get(const Eolian_Enum_Type_Field *fl);
|
||||
|
||||
/*
|
||||
* @brief Get the description of a field of an enum type.
|
||||
*
|
||||
* @param[in] tp the type.
|
||||
* @param[in] field the field name.
|
||||
* @return the description when @c tp is EOLIAN_TYPE_ENUM, @c field is not NULL
|
||||
* and the field exists, NULL otherwise.
|
||||
* @param[in] fl the field.
|
||||
* @return the description.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI Eina_Stringshare *eolian_type_enum_field_description_get(const Eolian_Type *tp, const char *field);
|
||||
EAPI Eina_Stringshare *eolian_type_enum_field_description_get(const Eolian_Enum_Type_Field *fl);
|
||||
|
||||
/*
|
||||
* @brief Get the value of a field of an enum type.
|
||||
*
|
||||
* @param[in] fl the field.
|
||||
* @return the description.
|
||||
*
|
||||
* @ingroup Eolian
|
||||
*/
|
||||
EAPI const Eolian_Expression *eolian_type_enum_field_value_get(const Eolian_Enum_Type_Field *fl);
|
||||
|
||||
/*
|
||||
* @brief Get the legacy prefix of enum field names. When not specified,
|
||||
|
|
|
@ -495,6 +495,7 @@ eval_exp(const Eolian_Expression *expr, Eolian_Expression_Mask mask,
|
|||
if (!var)
|
||||
{
|
||||
const Eolian_Type *etp;
|
||||
const Eolian_Enum_Type_Field *fl;
|
||||
|
||||
/* try aliases, hoping it'll be enum */
|
||||
char *fulln = NULL, *memb = NULL;
|
||||
|
@ -527,7 +528,8 @@ eval_exp(const Eolian_Expression *expr, Eolian_Expression_Mask mask,
|
|||
return expr_error(expr, "undefined variable");
|
||||
}
|
||||
|
||||
exp = eolian_type_enum_field_get(etp, memb);
|
||||
fl = eolian_type_enum_field_get(etp, memb);
|
||||
if (fl) exp = eolian_type_enum_field_value_get(fl);
|
||||
free(fulln);
|
||||
|
||||
if (!exp)
|
||||
|
@ -545,6 +547,7 @@ eval_exp(const Eolian_Expression *expr, Eolian_Expression_Mask mask,
|
|||
{
|
||||
const Eolian_Type *etp;
|
||||
const Eolian_Expression *exp;
|
||||
const Eolian_Enum_Type_Field *fl;
|
||||
|
||||
char *fulln = NULL, *memb = NULL;
|
||||
if (!split_enum_name(expr->value.s, &fulln, &memb))
|
||||
|
@ -562,7 +565,8 @@ eval_exp(const Eolian_Expression *expr, Eolian_Expression_Mask mask,
|
|||
return expr_error(expr, "invalid enum");
|
||||
}
|
||||
|
||||
exp = eolian_type_enum_field_get(etp, memb);
|
||||
fl = eolian_type_enum_field_get(etp, memb);
|
||||
if (fl) exp = eolian_type_enum_field_value_get(fl);
|
||||
free(fulln);
|
||||
|
||||
if (!exp)
|
||||
|
|
|
@ -115,7 +115,7 @@ _stype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name)
|
|||
eina_strbuf_append(buf, "{ ");
|
||||
EINA_LIST_FOREACH(tp->field_list, l, fname)
|
||||
{
|
||||
Eolian_Struct_Field *sf = eina_hash_find(tp->fields, fname);
|
||||
Eolian_Struct_Type_Field *sf = eina_hash_find(tp->fields, fname);
|
||||
database_type_to_str(sf->type, buf, fname);
|
||||
eina_strbuf_append(buf, "; ");
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ _etype_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name)
|
|||
eina_strbuf_append(buf, "{ ");
|
||||
EINA_LIST_FOREACH(tp->field_list, l, fname)
|
||||
{
|
||||
Eolian_Enum_Field *ef = eina_hash_find(tp->fields, fname);
|
||||
Eolian_Enum_Type_Field *ef = eina_hash_find(tp->fields, fname);
|
||||
eina_strbuf_append(buf, fname);
|
||||
if (ef->value)
|
||||
{
|
||||
|
@ -341,7 +341,7 @@ database_type_print(Eolian_Type *tp)
|
|||
printf("{ ");
|
||||
EINA_LIST_FOREACH(tp->field_list, m, fname)
|
||||
{
|
||||
Eolian_Struct_Field *sf = eina_hash_find(tp->fields, fname);
|
||||
Eolian_Struct_Type_Field *sf = eina_hash_find(tp->fields, fname);
|
||||
printf("%s: ", fname);
|
||||
database_type_print(sf->type);
|
||||
printf("; ");
|
||||
|
@ -356,7 +356,7 @@ database_type_print(Eolian_Type *tp)
|
|||
printf("{ ");
|
||||
EINA_LIST_FOREACH(tp->field_list, m, fname)
|
||||
{
|
||||
Eolian_Enum_Field *ef = eina_hash_find(tp->fields, fname);
|
||||
Eolian_Enum_Type_Field *ef = eina_hash_find(tp->fields, fname);
|
||||
printf("%s", fname);
|
||||
if (ef->value)
|
||||
{
|
||||
|
|
|
@ -97,79 +97,85 @@ eolian_type_subtypes_get(const Eolian_Type *tp)
|
|||
}
|
||||
|
||||
EAPI Eina_Iterator *
|
||||
eolian_type_struct_field_names_get(const Eolian_Type *tp)
|
||||
eolian_type_struct_fields_get(const Eolian_Type *tp)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
|
||||
EINA_SAFETY_ON_FALSE_RETURN_VAL(tp->type == EOLIAN_TYPE_STRUCT, NULL);
|
||||
return eina_list_iterator_new(tp->field_list);
|
||||
}
|
||||
|
||||
EAPI const Eolian_Struct_Type_Field *
|
||||
eolian_type_struct_field_get(const Eolian_Type *tp, const char *field)
|
||||
{
|
||||
Eolian_Struct_Type_Field *sf = NULL;
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(field, NULL);
|
||||
EINA_SAFETY_ON_FALSE_RETURN_VAL(tp->type == EOLIAN_TYPE_STRUCT, NULL);
|
||||
sf = eina_hash_find(tp->fields, field);
|
||||
if (!sf) return NULL;
|
||||
return sf;
|
||||
}
|
||||
|
||||
EAPI Eina_Stringshare *
|
||||
eolian_type_struct_field_name_get(const Eolian_Struct_Type_Field *fl)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
|
||||
return fl->name;
|
||||
}
|
||||
|
||||
EAPI Eina_Stringshare *
|
||||
eolian_type_struct_field_description_get(const Eolian_Struct_Type_Field *fl)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
|
||||
return fl->comment;
|
||||
}
|
||||
|
||||
EAPI const Eolian_Type *
|
||||
eolian_type_struct_field_get(const Eolian_Type *tp, const char *field)
|
||||
eolian_type_struct_field_type_get(const Eolian_Struct_Type_Field *fl)
|
||||
{
|
||||
Eolian_Struct_Field *sf = NULL;
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(field, NULL);
|
||||
EINA_SAFETY_ON_FALSE_RETURN_VAL(tp->type == EOLIAN_TYPE_STRUCT, NULL);
|
||||
sf = eina_hash_find(tp->fields, field);
|
||||
if (!sf) return NULL;
|
||||
return sf->type;
|
||||
}
|
||||
|
||||
EAPI Eina_Stringshare *
|
||||
eolian_type_struct_field_description_get(const Eolian_Type *tp, const char *field)
|
||||
{
|
||||
Eolian_Struct_Field *sf = NULL;
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(field, NULL);
|
||||
EINA_SAFETY_ON_FALSE_RETURN_VAL(tp->type == EOLIAN_TYPE_STRUCT, NULL);
|
||||
sf = eina_hash_find(tp->fields, field);
|
||||
if (!sf) return NULL;
|
||||
return sf->comment;
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
|
||||
return fl->type;
|
||||
}
|
||||
|
||||
EAPI Eina_Iterator *
|
||||
eolian_type_enum_field_names_get(const Eolian_Type *tp)
|
||||
eolian_type_enum_fields_get(const Eolian_Type *tp)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
|
||||
EINA_SAFETY_ON_FALSE_RETURN_VAL(tp->type == EOLIAN_TYPE_ENUM, NULL);
|
||||
return eina_list_iterator_new(tp->field_list);
|
||||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
eolian_type_enum_field_exists(const Eolian_Type *tp, const char *field)
|
||||
{
|
||||
Eolian_Enum_Field *ef = NULL;
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EINA_FALSE);
|
||||
EINA_SAFETY_ON_FALSE_RETURN_VAL(tp->type == EOLIAN_TYPE_ENUM, EINA_FALSE);
|
||||
ef = eina_hash_find(tp->fields, field);
|
||||
if (!ef)
|
||||
return EINA_FALSE;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EAPI const Eolian_Expression *
|
||||
EAPI const Eolian_Enum_Type_Field *
|
||||
eolian_type_enum_field_get(const Eolian_Type *tp, const char *field)
|
||||
{
|
||||
Eolian_Enum_Field *ef = NULL;
|
||||
Eolian_Enum_Type_Field *ef = NULL;
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(field, NULL);
|
||||
EINA_SAFETY_ON_FALSE_RETURN_VAL(tp->type == EOLIAN_TYPE_ENUM, NULL);
|
||||
ef = eina_hash_find(tp->fields, field);
|
||||
if (!ef) return NULL;
|
||||
return ef->value;
|
||||
return ef;
|
||||
}
|
||||
|
||||
EAPI Eina_Stringshare *
|
||||
eolian_type_enum_field_description_get(const Eolian_Type *tp, const char *field)
|
||||
eolian_type_enum_field_name_get(const Eolian_Enum_Type_Field *fl)
|
||||
{
|
||||
Eolian_Enum_Field *ef = NULL;
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(field, NULL);
|
||||
EINA_SAFETY_ON_FALSE_RETURN_VAL(tp->type == EOLIAN_TYPE_ENUM, NULL);
|
||||
ef = eina_hash_find(tp->fields, field);
|
||||
if (!ef) return NULL;
|
||||
return ef->comment;
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
|
||||
return fl->name;
|
||||
}
|
||||
|
||||
EAPI Eina_Stringshare *
|
||||
eolian_type_enum_field_description_get(const Eolian_Enum_Type_Field *fl)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
|
||||
return fl->comment;
|
||||
}
|
||||
|
||||
EAPI const Eolian_Expression *
|
||||
eolian_type_enum_field_value_get(const Eolian_Enum_Type_Field *fl)
|
||||
{
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
|
||||
return fl->value;
|
||||
}
|
||||
|
||||
EAPI Eina_Stringshare *
|
||||
|
|
|
@ -7,7 +7,7 @@ static Eina_Bool _validate_expr(const Eolian_Expression *expr,
|
|||
|
||||
static Eina_Bool
|
||||
_sf_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED,
|
||||
const Eolian_Struct_Field *sf, Eina_Bool *success)
|
||||
const Eolian_Struct_Type_Field *sf, Eina_Bool *success)
|
||||
{
|
||||
*success = _validate_type(sf->type);
|
||||
return *success;
|
||||
|
@ -15,7 +15,7 @@ _sf_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED,
|
|||
|
||||
static Eina_Bool
|
||||
_ef_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED,
|
||||
const Eolian_Enum_Field *ef, Eina_Bool *success)
|
||||
const Eolian_Enum_Type_Field *ef, Eina_Bool *success)
|
||||
{
|
||||
*success = _validate_expr(ef->value, NULL, EOLIAN_MASK_INT);
|
||||
return *success;
|
||||
|
|
|
@ -568,9 +568,10 @@ parse_function_type(Eo_Lexer *ls)
|
|||
}
|
||||
|
||||
static void
|
||||
_struct_field_free(Eolian_Struct_Field *def)
|
||||
_struct_field_free(Eolian_Struct_Type_Field *def)
|
||||
{
|
||||
if (def->base.file) eina_stringshare_del(def->base.file);
|
||||
if (def->name) eina_stringshare_del(def->name);
|
||||
database_type_del(def->type);
|
||||
if (def->comment) eina_stringshare_del(def->comment);
|
||||
free(def);
|
||||
|
@ -597,16 +598,16 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
|
|||
while (ls->t.token != '}')
|
||||
{
|
||||
const char *fname;
|
||||
Eolian_Struct_Field *fdef;
|
||||
Eolian_Struct_Type_Field *fdef;
|
||||
Eolian_Type *tp;
|
||||
int fline = ls->line_number, fcol = ls->column;
|
||||
check(ls, TOK_VALUE);
|
||||
if (eina_hash_find(def->fields, ls->t.value.s))
|
||||
eo_lexer_syntax_error(ls, "double field definition");
|
||||
fdef = calloc(1, sizeof(Eolian_Struct_Field));
|
||||
fdef = calloc(1, sizeof(Eolian_Struct_Type_Field));
|
||||
fname = eina_stringshare_ref(ls->t.value.s);
|
||||
eina_hash_add(def->fields, fname, fdef);
|
||||
def->field_list = eina_list_append(def->field_list, fname);
|
||||
def->field_list = eina_list_append(def->field_list, fdef);
|
||||
eo_lexer_get(ls);
|
||||
check_next(ls, ':');
|
||||
tp = parse_type(ls);
|
||||
|
@ -614,6 +615,7 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
|
|||
fdef->base.line = fline;
|
||||
fdef->base.column = fcol;
|
||||
fdef->type = tp;
|
||||
fdef->name = eina_stringshare_ref(fname);
|
||||
pop_type(ls);
|
||||
check_next(ls, ';');
|
||||
if (ls->t.token == TOK_COMMENT)
|
||||
|
@ -631,9 +633,10 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
|
|||
}
|
||||
|
||||
static void
|
||||
_enum_field_free(Eolian_Enum_Field *def)
|
||||
_enum_field_free(Eolian_Enum_Type_Field *def)
|
||||
{
|
||||
if (def->base.file) eina_stringshare_del(def->base.file);
|
||||
if (def->name) eina_stringshare_del(def->name);
|
||||
database_expr_del(def->value);
|
||||
if (def->comment) eina_stringshare_del(def->comment);
|
||||
free(def);
|
||||
|
@ -673,19 +676,20 @@ parse_enum(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
|
|||
for (;;)
|
||||
{
|
||||
const char *fname;
|
||||
Eolian_Enum_Field *fdef;
|
||||
Eolian_Enum_Type_Field *fdef;
|
||||
int fline = ls->line_number, fcol = ls->column;
|
||||
check(ls, TOK_VALUE);
|
||||
if (eina_hash_find(def->fields, ls->t.value.s))
|
||||
eo_lexer_syntax_error(ls, "double field definition");
|
||||
fdef = calloc(1, sizeof(Eolian_Enum_Field));
|
||||
fdef = calloc(1, sizeof(Eolian_Enum_Type_Field));
|
||||
fname = eina_stringshare_ref(ls->t.value.s);
|
||||
eina_hash_add(def->fields, fname, fdef);
|
||||
def->field_list = eina_list_append(def->field_list, fname);
|
||||
def->field_list = eina_list_append(def->field_list, fdef);
|
||||
eo_lexer_get(ls);
|
||||
fdef->base.file = eina_stringshare_ref(ls->filename);
|
||||
fdef->base.line = fline;
|
||||
fdef->base.column = fcol;
|
||||
fdef->name = eina_stringshare_ref(fname);
|
||||
if (ls->t.token != '=')
|
||||
{
|
||||
if (!prev_exp)
|
||||
|
|
|
@ -161,19 +161,21 @@ struct _Eolian_Event
|
|||
int scope;
|
||||
};
|
||||
|
||||
typedef struct _Eolian_Struct_Field
|
||||
struct _Eolian_Struct_Type_Field
|
||||
{
|
||||
Eina_Stringshare *name;
|
||||
Eolian_Object base;
|
||||
Eolian_Type *type;
|
||||
Eina_Stringshare *comment;
|
||||
} Eolian_Struct_Field;
|
||||
};
|
||||
|
||||
typedef struct _Eolian_Enum_Field
|
||||
struct _Eolian_Enum_Type_Field
|
||||
{
|
||||
Eina_Stringshare *name;
|
||||
Eolian_Object base;
|
||||
Eolian_Expression *value;
|
||||
Eina_Stringshare *comment;
|
||||
} Eolian_Enum_Field;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
|
|
@ -548,7 +548,8 @@ END_TEST
|
|||
|
||||
START_TEST(eolian_struct)
|
||||
{
|
||||
const Eolian_Type *atype = NULL, *type = NULL, *field = NULL;
|
||||
const Eolian_Struct_Type_Field *field = NULL;
|
||||
const Eolian_Type *atype = NULL, *type = NULL, *ftype = NULL;
|
||||
const Eolian_Class *class;
|
||||
const char *type_name;
|
||||
const char *file;
|
||||
|
@ -572,10 +573,12 @@ START_TEST(eolian_struct)
|
|||
fail_if(strcmp(type_name, "Named"));
|
||||
fail_if(strcmp(file, "struct.eo"));
|
||||
fail_if(!(field = eolian_type_struct_field_get(type, "field")));
|
||||
fail_if(!(type_name = eolian_type_name_get(field)));
|
||||
fail_if(!(ftype = eolian_type_struct_field_type_get(field)));
|
||||
fail_if(!(type_name = eolian_type_name_get(ftype)));
|
||||
fail_if(strcmp(type_name, "int"));
|
||||
fail_if(!(field = eolian_type_struct_field_get(type, "something")));
|
||||
fail_if(!(type_name = eolian_type_c_type_get(field)));
|
||||
fail_if(!(ftype = eolian_type_struct_field_type_get(field)));
|
||||
fail_if(!(type_name = eolian_type_c_type_get(ftype)));
|
||||
fail_if(strcmp(type_name, "const char *"));
|
||||
eina_stringshare_del(type_name);
|
||||
|
||||
|
@ -587,9 +590,10 @@ START_TEST(eolian_struct)
|
|||
fail_if(strcmp(type_name, "Another"));
|
||||
fail_if(strcmp(file, "struct.eo"));
|
||||
fail_if(!(field = eolian_type_struct_field_get(type, "field")));
|
||||
fail_if(!(type_name = eolian_type_name_get(field)));
|
||||
fail_if(!(ftype = eolian_type_struct_field_type_get(field)));
|
||||
fail_if(!(type_name = eolian_type_name_get(ftype)));
|
||||
fail_if(strcmp(type_name, "Named"));
|
||||
fail_if(eolian_type_type_get(field) != EOLIAN_TYPE_REGULAR_STRUCT);
|
||||
fail_if(eolian_type_type_get(ftype) != EOLIAN_TYPE_REGULAR_STRUCT);
|
||||
|
||||
/* typedef */
|
||||
fail_if(!(atype = eolian_type_alias_get_by_name("Foo")));
|
||||
|
@ -712,6 +716,7 @@ END_TEST
|
|||
|
||||
START_TEST(eolian_enum)
|
||||
{
|
||||
const Eolian_Enum_Type_Field *field = NULL;
|
||||
const Eolian_Variable *var = NULL;
|
||||
const Eolian_Type *type = NULL;
|
||||
const Eolian_Class *class;
|
||||
|
@ -730,25 +735,25 @@ START_TEST(eolian_enum)
|
|||
|
||||
fail_if(!(type = eolian_type_enum_get_by_name("Foo")));
|
||||
|
||||
fail_if(!(eolian_type_enum_field_exists(type, "first")));
|
||||
fail_if(!(exp = eolian_type_enum_field_get(type, "first")));
|
||||
fail_if(!(field = eolian_type_enum_field_get(type, "first")));
|
||||
fail_if(!(exp = eolian_type_enum_field_value_get(field)));
|
||||
v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
|
||||
fail_if(v.type != EOLIAN_EXPR_INT);
|
||||
fail_if(v.value.i != 0);
|
||||
|
||||
fail_if(!(eolian_type_enum_field_exists(type, "bar")));
|
||||
fail_if(eolian_type_enum_field_get(type, "bar"));
|
||||
fail_if(!(field = eolian_type_enum_field_get(type, "bar")));
|
||||
fail_if(eolian_type_enum_field_value_get(field));
|
||||
|
||||
fail_if(!(eolian_type_enum_field_exists(type, "baz")));
|
||||
fail_if(!(exp = eolian_type_enum_field_get(type, "baz")));
|
||||
fail_if(!(field = eolian_type_enum_field_get(type, "baz")));
|
||||
fail_if(!(exp = eolian_type_enum_field_value_get(field)));
|
||||
v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
|
||||
fail_if(v.type != EOLIAN_EXPR_INT);
|
||||
fail_if(v.value.i != 15);
|
||||
|
||||
fail_if(!(type = eolian_type_enum_get_by_name("Bar")));
|
||||
|
||||
fail_if(!(eolian_type_enum_field_exists(type, "foo")));
|
||||
fail_if(!(exp = eolian_type_enum_field_get(type, "foo")));
|
||||
fail_if(!(field = eolian_type_enum_field_get(type, "foo")));
|
||||
fail_if(!(exp = eolian_type_enum_field_value_get(field)));
|
||||
v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
|
||||
fail_if(v.type != EOLIAN_EXPR_INT);
|
||||
fail_if(v.value.i != 15);
|
||||
|
@ -756,20 +761,20 @@ START_TEST(eolian_enum)
|
|||
fail_if(!(type = eolian_type_alias_get_by_name("Baz")));
|
||||
fail_if(!(type = eolian_type_base_type_get(type)));
|
||||
|
||||
fail_if(!(eolian_type_enum_field_exists(type, "flag1")));
|
||||
fail_if(!(exp = eolian_type_enum_field_get(type, "flag1")));
|
||||
fail_if(!(field = eolian_type_enum_field_get(type, "flag1")));
|
||||
fail_if(!(exp = eolian_type_enum_field_value_get(field)));
|
||||
v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
|
||||
fail_if(v.type != EOLIAN_EXPR_INT);
|
||||
fail_if(v.value.i != (1 << 0));
|
||||
|
||||
fail_if(!(eolian_type_enum_field_exists(type, "flag2")));
|
||||
fail_if(!(exp = eolian_type_enum_field_get(type, "flag2")));
|
||||
fail_if(!(field = eolian_type_enum_field_get(type, "flag2")));
|
||||
fail_if(!(exp = eolian_type_enum_field_value_get(field)));
|
||||
v = eolian_expression_eval(exp, EOLIAN_MASK_ALL);
|
||||
fail_if(v.type != EOLIAN_EXPR_INT);
|
||||
fail_if(v.value.i != (1 << 1));
|
||||
|
||||
fail_if(!(eolian_type_enum_field_exists(type, "flag3")));
|
||||
fail_if(!(exp = eolian_type_enum_field_get(type, "flag3")));
|
||||
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);
|
||||
fail_if(v.type != EOLIAN_EXPR_INT);
|
||||
fail_if(v.value.i != (1 << 2));
|
||||
|
|
Loading…
Reference in New Issue