From 4c4fbfae0bfb739fd0d87d452022d7026d0645f9 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Tue, 1 Mar 2016 13:40:24 +0000 Subject: [PATCH] eolian: remove most of the old type APIs --- src/lib/eolian/Eolian.h | 3 -- src/lib/eolian/database_expr_api.c | 13 +++--- src/lib/eolian/database_type_api.c | 64 ++++-------------------------- src/lib/eolian/database_validate.c | 60 +++++++++++++++++----------- 4 files changed, 50 insertions(+), 90 deletions(-) diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index 39c486ff03..da3a212786 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -1487,7 +1487,6 @@ EAPI const Eolian_Expression *eolian_typedecl_enum_field_value_get(const Eolian_ * * @ingroup Eolian */ -EAPI Eina_Stringshare *eolian_type_enum_legacy_prefix_get(const Eolian_Type *tp); EAPI Eina_Stringshare *eolian_typedecl_enum_legacy_prefix_get(const Eolian_Typedecl *tp); /* @@ -1499,7 +1498,6 @@ EAPI Eina_Stringshare *eolian_typedecl_enum_legacy_prefix_get(const Eolian_Typed * * @ingroup Eolian */ -EAPI const Eolian_Documentation *eolian_type_documentation_get(const Eolian_Type *tp); EAPI const Eolian_Documentation *eolian_typedecl_documentation_get(const Eolian_Typedecl *tp); /* @@ -1586,7 +1584,6 @@ EAPI Eina_Bool eolian_type_is_const(const Eolian_Type *tp); * * @ingroup Eolian */ -EAPI Eina_Bool eolian_type_is_extern(const Eolian_Type *tp); EAPI Eina_Bool eolian_typedecl_is_extern(const Eolian_Typedecl *tp); /* diff --git a/src/lib/eolian/database_expr_api.c b/src/lib/eolian/database_expr_api.c index eb0d119d68..81d4200a31 100644 --- a/src/lib/eolian/database_expr_api.c +++ b/src/lib/eolian/database_expr_api.c @@ -23,8 +23,6 @@ _eval_type(const Eolian_Expression *expr, const Eolian_Type *type) return err; switch (type->type) { - case EOLIAN_TYPE_ALIAS: - return _eval_type(expr, eolian_type_base_type_get(type)); case EOLIAN_TYPE_POINTER: { int mask = EOLIAN_MASK_NULL; @@ -36,15 +34,18 @@ _eval_type(const Eolian_Expression *expr, const Eolian_Type *type) } case EOLIAN_TYPE_CLASS: return database_expr_eval(expr, EOLIAN_MASK_NULL); - case EOLIAN_TYPE_ENUM: - return database_expr_eval(expr, EOLIAN_MASK_INT); case EOLIAN_TYPE_REGULAR: { int kw = eo_lexer_keyword_str_to_id(type->name); if (!kw || kw < KW_byte || kw >= KW_void) { - const Eolian_Type *base = eolian_type_base_type_get(type); - if (base) return _eval_type(expr, base); + const Eolian_Typedecl *base = eolian_type_typedecl_get(type); + if (!base) + return err; + if (base->type == EOLIAN_TYPEDECL_ALIAS) + return _eval_type(expr, eolian_typedecl_base_type_get(base)); + else if (base->type == EOLIAN_TYPEDECL_ENUM) + return database_expr_eval(expr, EOLIAN_MASK_INT); return err; } switch (kw) diff --git a/src/lib/eolian/database_type_api.c b/src/lib/eolian/database_type_api.c index ffbde9088c..c64cd78911 100644 --- a/src/lib/eolian/database_type_api.c +++ b/src/lib/eolian/database_type_api.c @@ -207,15 +207,6 @@ eolian_typedecl_enum_field_value_get(const Eolian_Enum_Type_Field *fl, Eina_Bool return fl->value; } -EAPI Eina_Stringshare * -eolian_type_enum_legacy_prefix_get(const Eolian_Type *tp) -{ - EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); - if (tp->type != EOLIAN_TYPE_ENUM) - return NULL; - return tp->legacy; -} - EAPI Eina_Stringshare * eolian_typedecl_enum_legacy_prefix_get(const Eolian_Typedecl *tp) { @@ -225,13 +216,6 @@ eolian_typedecl_enum_legacy_prefix_get(const Eolian_Typedecl *tp) return tp->legacy; } -EAPI const Eolian_Documentation * -eolian_type_documentation_get(const Eolian_Type *tp) -{ - EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); - return tp->doc; -} - EAPI const Eolian_Documentation * eolian_typedecl_documentation_get(const Eolian_Typedecl *tp) { @@ -256,28 +240,9 @@ eolian_typedecl_file_get(const Eolian_Typedecl *tp) EAPI const Eolian_Type * eolian_type_base_type_get(const Eolian_Type *tp) { - Eolian_Type_Type tpt; EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); - tpt = eolian_type_type_get(tp); - if ((tpt != EOLIAN_TYPE_POINTER) && (tpt != EOLIAN_TYPE_ALIAS) && - (tpt != EOLIAN_TYPE_REGULAR)) + if (tp->type != EOLIAN_TYPE_POINTER) return NULL; - if (tpt == EOLIAN_TYPE_REGULAR) - { - /* for regular types, try looking up if it belongs to a struct, - * enum or an alias... otherwise return NULL - * but first check for builtins - */ - int kw = eo_lexer_keyword_str_to_id(tp->full_name); - if (!kw || kw < KW_byte || kw >= KW_true) - { - Eolian_Declaration *decl = eina_hash_find(_decls, tp->full_name); - if (decl && decl->type != EOLIAN_DECL_CLASS - && decl->type != EOLIAN_DECL_VAR) - return ((const Eolian_Typedecl *)decl->data)->parent; - } - return NULL; - } return tp->base_type; } @@ -304,10 +269,8 @@ eolian_type_typedecl_get(const Eolian_Type *tp) EAPI const Eolian_Type * eolian_typedecl_base_type_get(const Eolian_Typedecl *tp) { - Eolian_Typedecl_Type tpt; EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); - tpt = eolian_typedecl_type_get(tp); - if (tpt != EOLIAN_TYPEDECL_ALIAS) + if (tp->type != EOLIAN_TYPEDECL_ALIAS) return NULL; return tp->base_type; } @@ -315,18 +278,12 @@ eolian_typedecl_base_type_get(const Eolian_Typedecl *tp) EAPI const Eolian_Type * eolian_type_aliased_base_get(const Eolian_Type *tp) { - if (!tp) - return NULL; - if (eolian_type_type_get(tp) == EOLIAN_TYPE_REGULAR) - { - const Eolian_Type *btp = eolian_type_base_type_get(tp); - if (btp && (eolian_type_type_get(btp) == EOLIAN_TYPE_ALIAS)) - return eolian_type_aliased_base_get(btp); - return tp; - } - else if (eolian_type_type_get(tp) != EOLIAN_TYPE_ALIAS) + if (!tp || tp->type != EOLIAN_TYPE_REGULAR) return tp; - return eolian_type_aliased_base_get(tp->base_type); + const Eolian_Typedecl *btp = eolian_type_typedecl_get(tp); + if (btp && (btp->type == EOLIAN_TYPEDECL_ALIAS)) + return eolian_typedecl_aliased_base_get(btp); + return tp; } EAPI const Eolian_Type * @@ -360,13 +317,6 @@ eolian_type_is_const(const Eolian_Type *tp) return tp->is_const; } -EAPI Eina_Bool -eolian_type_is_extern(const Eolian_Type *tp) -{ - EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EINA_FALSE); - return tp->is_extern; -} - EAPI Eina_Bool eolian_typedecl_is_extern(const Eolian_Typedecl *tp) { diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c index d72b213d4d..63e1f3728a 100644 --- a/src/lib/eolian/database_validate.c +++ b/src/lib/eolian/database_validate.c @@ -189,11 +189,42 @@ _type_error(const Validator *vs, const Eolian_Type *tp, const char *msg) } static Eina_Bool -_validate_type(const Validator *vs, const Eolian_Type *tp) +_validate_typedecl(const Validator *vs, const Eolian_Typedecl *tp) { if (!_validate_doc(vs, tp->doc)) return EINA_FALSE; + switch (tp->type) + { + case EOLIAN_TYPEDECL_ALIAS: + return _validate_type(vs, tp->base_type); + case EOLIAN_TYPEDECL_STRUCT: + { + Val_Success succ; + succ.vs = vs; + succ.success = EINA_TRUE; + eina_hash_foreach(tp->fields, (Eina_Hash_Foreach)_sf_map_cb, &succ); + return succ.success; + } + case EOLIAN_TYPEDECL_STRUCT_OPAQUE: + return EINA_TRUE; + case EOLIAN_TYPEDECL_ENUM: + { + Val_Success succ; + succ.vs = vs; + succ.success = EINA_TRUE; + eina_hash_foreach(tp->fields, (Eina_Hash_Foreach)_ef_map_cb, &succ); + return succ.success; + } + default: + return EINA_FALSE; + } + return EINA_TRUE; +} + +static Eina_Bool +_validate_type(const Validator *vs, const Eolian_Type *tp) +{ switch (tp->type) { case EOLIAN_TYPE_VOID: @@ -202,42 +233,23 @@ _validate_type(const Validator *vs, const Eolian_Type *tp) return EINA_TRUE; case EOLIAN_TYPE_REGULAR: { - const Eolian_Type *tpp; + const Eolian_Typedecl *tpp; /* builtins */ int id = eo_lexer_keyword_str_to_id(tp->full_name); if (id) return eo_lexer_is_type_keyword(id); /* user defined */ - tpp = eolian_type_base_type_get(tp); + tpp = eolian_type_typedecl_get(tp); if (!tpp) { char buf[256]; snprintf(buf, sizeof(buf), "undefined type %s", tp->full_name); return _type_error(vs, tp, buf); } - return _validate_type(vs, tpp); + return _validate_typedecl(vs, tpp); } case EOLIAN_TYPE_POINTER: - case EOLIAN_TYPE_ALIAS: return _validate_type(vs, tp->base_type); - case EOLIAN_TYPE_STRUCT: - { - Val_Success succ; - succ.vs = vs; - succ.success = EINA_TRUE; - eina_hash_foreach(tp->fields, (Eina_Hash_Foreach)_sf_map_cb, &succ); - return succ.success; - } - case EOLIAN_TYPE_STRUCT_OPAQUE: - return EINA_TRUE; - case EOLIAN_TYPE_ENUM: - { - Val_Success succ; - succ.vs = vs; - succ.success = EINA_TRUE; - eina_hash_foreach(tp->fields, (Eina_Hash_Foreach)_ef_map_cb, &succ); - return succ.success; - } case EOLIAN_TYPE_CLASS: { if (!eolian_type_class_get(tp)) @@ -391,7 +403,7 @@ static Eina_Bool _type_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, const Eolian_Type *tp, Val_Success *sc) { - sc->success = _validate_type(sc->vs, tp); + sc->success = _validate_typedecl(sc->vs, tp->decl); return sc->success; }