eolian: include terminatable checks in ownable check

This commit is contained in:
Daniel Kolesa 2017-09-14 00:28:32 +02:00
parent 8ff2bf35fe
commit 59347d4c4b
3 changed files with 8 additions and 19 deletions

View File

@ -80,13 +80,16 @@ static const Eina_Bool _ownable_types[] = {
};
Eina_Bool
database_type_is_ownable(const Eolian_Type *tp)
database_type_is_ownable(const Eolian_Type *tp, Eina_Bool term)
{
if (tp->is_ptr)
return EINA_TRUE;
if (tp->type == EOLIAN_TYPE_REGULAR)
{
int kwid = eo_lexer_keyword_str_to_id(tp->name);
/* don't include bool, it only has 2 values so it's useless */
if (term && (kwid >= KW_byte && kwid < KW_bool))
return EINA_TRUE;
const char *ct = eo_lexer_get_c_type(kwid);
if (!ct)
return EINA_FALSE;
@ -117,7 +120,7 @@ database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name,
if ((tp->type == EOLIAN_TYPE_REGULAR
|| tp->type == EOLIAN_TYPE_VOID)
&& tp->is_const
&& ((ctype != EOLIAN_C_TYPE_RETURN) || database_type_is_ownable(tp)))
&& ((ctype != EOLIAN_C_TYPE_RETURN) || database_type_is_ownable(tp, EINA_FALSE)))
{
eina_strbuf_append(buf, "const ");
}

View File

@ -131,26 +131,12 @@ _validate_typedecl(Eolian_Typedecl *tp)
return EINA_TRUE;
}
static Eina_Bool
_type_is_terminatable(const Eolian_Type *tp)
{
if (database_type_is_ownable(tp))
return EINA_TRUE;
if (tp->type == EOLIAN_TYPE_REGULAR)
{
int kwid = eo_lexer_keyword_str_to_id(tp->name);
/* don't include bool, it only has 2 values so it's useless */
return (kwid >= KW_byte && kwid < KW_bool);
}
return EINA_FALSE;
}
static Eina_Bool
_validate_type(Eolian_Type *tp)
{
char buf[256];
if ((tp->is_own || tp->freefunc) && !database_type_is_ownable(tp))
if ((tp->is_own || tp->freefunc) && !database_type_is_ownable(tp, EINA_FALSE))
{
snprintf(buf, sizeof(buf), "type '%s' is not ownable", tp->full_name);
return _type_error(tp, buf);
@ -183,7 +169,7 @@ _validate_type(Eolian_Type *tp)
return EINA_TRUE;
}
case EOLIAN_TYPE_TERMINATED_ARRAY:
if (!_type_is_terminatable(tp->base_type))
if (!database_type_is_ownable(tp->base_type, EINA_TRUE))
{
snprintf(buf, sizeof(buf),
"invalid base type '%s' for terminated array",

View File

@ -314,7 +314,7 @@ void database_typedecl_del(Eolian_Typedecl *tp);
void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype);
void database_typedecl_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp, Eina_Strbuf *buf);
Eina_Bool database_type_is_ownable(const Eolian_Type *tp);
Eina_Bool database_type_is_ownable(const Eolian_Type *tp, Eina_Bool term);
/* expressions */