summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/eolian/database_type.c52
-rw-r--r--src/lib/eolian/database_type_api.c4
-rw-r--r--src/lib/eolian/eo_parser.c34
-rw-r--r--src/lib/eolian/eolian_database.h4
4 files changed, 52 insertions, 42 deletions
diff --git a/src/lib/eolian/database_type.c b/src/lib/eolian/database_type.c
index 0b2202383a..ddff419fae 100644
--- a/src/lib/eolian/database_type.c
+++ b/src/lib/eolian/database_type.c
@@ -67,6 +67,34 @@ database_enum_add(Eolian_Typedecl *tp)
67 database_decl_add(tp->full_name, EOLIAN_DECL_ENUM, tp->base.file, tp); 67 database_decl_add(tp->full_name, EOLIAN_DECL_ENUM, tp->base.file, tp);
68} 68}
69 69
70static const Eina_Bool _ownable_types[] = {
71 EINA_FALSE, /* unknown */
72 EINA_FALSE, /* void */
73 EINA_FALSE, /* regular */
74 EINA_TRUE, /* complex */
75 EINA_TRUE, /* pointer */
76 EINA_TRUE, /* class */
77 EINA_TRUE, /* static array */
78 EINA_TRUE, /* terminated array */
79 EINA_FALSE /* undefined */
80};
81
82Eina_Bool
83database_type_is_ownable(const Eolian_Type *tp)
84{
85 if (tp->is_ptr)
86 return EINA_TRUE;
87 if (tp->type == EOLIAN_TYPE_REGULAR)
88 {
89 int kwid = eo_lexer_keyword_str_to_id(tp->name);
90 const char *ct = eo_lexer_get_c_type(kwid);
91 if (!ct)
92 return EINA_FALSE;
93 return (ct[strlen(ct) - 1] == '*');
94 }
95 return _ownable_types[tp->type];
96}
97
70static void 98static void
71_buf_add_suffix(Eina_Strbuf *buf, const char *suffix) 99_buf_add_suffix(Eina_Strbuf *buf, const char *suffix)
72{ 100{
@@ -77,16 +105,22 @@ _buf_add_suffix(Eina_Strbuf *buf, const char *suffix)
77} 105}
78 106
79void 107void
80database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name) 108database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name,
109 Eolian_C_Type_Type ctype)
81{ 110{
82 if ((tp->type == EOLIAN_TYPE_REGULAR 111 if ((tp->type == EOLIAN_TYPE_COMPLEX
83 || tp->type == EOLIAN_TYPE_COMPLEX
84 || tp->type == EOLIAN_TYPE_VOID
85 || tp->type == EOLIAN_TYPE_CLASS) 112 || tp->type == EOLIAN_TYPE_CLASS)
86 && tp->is_const) 113 && tp->is_const)
87 { 114 {
88 eina_strbuf_append(buf, "const "); 115 eina_strbuf_append(buf, "const ");
89 } 116 }
117 if ((tp->type == EOLIAN_TYPE_REGULAR
118 || tp->type == EOLIAN_TYPE_VOID)
119 && tp->is_const
120 && ((ctype != EOLIAN_C_TYPE_RETURN) || database_type_is_ownable(tp)))
121 {
122 eina_strbuf_append(buf, "const ");
123 }
90 if (tp->type == EOLIAN_TYPE_REGULAR 124 if (tp->type == EOLIAN_TYPE_REGULAR
91 || tp->type == EOLIAN_TYPE_COMPLEX 125 || tp->type == EOLIAN_TYPE_COMPLEX
92 || tp->type == EOLIAN_TYPE_CLASS) 126 || tp->type == EOLIAN_TYPE_CLASS)
@@ -111,9 +145,10 @@ database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name)
111 else 145 else
112 { 146 {
113 /* handles arrays and pointers as they all serialize to pointers */ 147 /* handles arrays and pointers as they all serialize to pointers */
114 database_type_to_str(tp->base_type, buf, NULL); 148 database_type_to_str(tp->base_type, buf, NULL, EOLIAN_C_TYPE_DEFAULT);
115 _buf_add_suffix(buf, "*"); 149 _buf_add_suffix(buf, "*");
116 if (tp->is_const) eina_strbuf_append(buf, " const"); 150 if (tp->is_const && (ctype != EOLIAN_C_TYPE_RETURN))
151 eina_strbuf_append(buf, " const");
117 } 152 }
118 if (tp->type == EOLIAN_TYPE_COMPLEX || tp->type == EOLIAN_TYPE_CLASS) 153 if (tp->type == EOLIAN_TYPE_COMPLEX || tp->type == EOLIAN_TYPE_CLASS)
119 _buf_add_suffix(buf, "*"); 154 _buf_add_suffix(buf, "*");
@@ -140,7 +175,7 @@ _stype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
140 eina_strbuf_append(buf, " { "); 175 eina_strbuf_append(buf, " { ");
141 EINA_LIST_FOREACH(tp->field_list, l, sf) 176 EINA_LIST_FOREACH(tp->field_list, l, sf)
142 { 177 {
143 database_type_to_str(sf->type, buf, sf->name); 178 database_type_to_str(sf->type, buf, sf->name, EOLIAN_C_TYPE_DEFAULT);
144 eina_strbuf_append(buf, "; "); 179 eina_strbuf_append(buf, "; ");
145 } 180 }
146 eina_strbuf_append(buf, "}"); 181 eina_strbuf_append(buf, "}");
@@ -212,7 +247,8 @@ _atype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
212 247
213 Eina_Strbuf *fulln = eina_strbuf_new(); 248 Eina_Strbuf *fulln = eina_strbuf_new();
214 _append_name(tp, fulln); 249 _append_name(tp, fulln);
215 database_type_to_str(tp->base_type, buf, eina_strbuf_string_get(fulln)); 250 database_type_to_str(tp->base_type, buf, eina_strbuf_string_get(fulln),
251 EOLIAN_C_TYPE_DEFAULT);
216 eina_strbuf_free(fulln); 252 eina_strbuf_free(fulln);
217} 253}
218 254
diff --git a/src/lib/eolian/database_type_api.c b/src/lib/eolian/database_type_api.c
index 47d994e584..e986611fe6 100644
--- a/src/lib/eolian/database_type_api.c
+++ b/src/lib/eolian/database_type_api.c
@@ -355,13 +355,13 @@ eolian_typedecl_is_extern(const Eolian_Typedecl *tp)
355} 355}
356 356
357EAPI Eina_Stringshare * 357EAPI Eina_Stringshare *
358eolian_type_c_type_get(const Eolian_Type *tp, Eolian_C_Type_Type ctype EINA_UNUSED) 358eolian_type_c_type_get(const Eolian_Type *tp, Eolian_C_Type_Type ctype)
359{ 359{
360 Eina_Stringshare *ret; 360 Eina_Stringshare *ret;
361 Eina_Strbuf *buf; 361 Eina_Strbuf *buf;
362 EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); 362 EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
363 buf = eina_strbuf_new(); 363 buf = eina_strbuf_new();
364 database_type_to_str(tp, buf, NULL); 364 database_type_to_str(tp, buf, NULL, ctype);
365 ret = eina_stringshare_add(eina_strbuf_string_get(buf)); 365 ret = eina_stringshare_add(eina_strbuf_string_get(buf));
366 eina_strbuf_free(buf); 366 eina_strbuf_free(buf);
367 return ret; 367 return ret;
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index f4bcb83724..ddb49f30c1 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -684,38 +684,10 @@ _parse_dep(Eo_Lexer *ls, const char *fname, const char *name)
684 } 684 }
685} 685}
686 686
687static const Eina_Bool _ownable_types[] = {
688 EINA_FALSE, /* unknown */
689 EINA_FALSE, /* void */
690 EINA_FALSE, /* regular */
691 EINA_TRUE, /* complex */
692 EINA_TRUE, /* pointer */
693 EINA_TRUE, /* class */
694 EINA_TRUE, /* static array */
695 EINA_TRUE, /* terminated array */
696 EINA_FALSE /* undefined */
697};
698
699static Eina_Bool
700_type_is_ownable(Eolian_Type *tp)
701{
702 if (tp->is_ptr)
703 return EINA_TRUE;
704 if (tp->type == EOLIAN_TYPE_REGULAR)
705 {
706 int kwid = eo_lexer_keyword_str_to_id(tp->name);
707 const char *ct = eo_lexer_get_c_type(kwid);
708 if (!ct)
709 return EINA_FALSE;
710 return (ct[strlen(ct) - 1] == '*');
711 }
712 return _ownable_types[tp->type];
713}
714
715static Eina_Bool 687static Eina_Bool
716_type_is_terminatable(Eolian_Type *tp) 688_type_is_terminatable(Eolian_Type *tp)
717{ 689{
718 if (_type_is_ownable(tp)) 690 if (database_type_is_ownable(tp))
719 return EINA_TRUE; 691 return EINA_TRUE;
720 if (tp->type == EOLIAN_TYPE_REGULAR) 692 if (tp->type == EOLIAN_TYPE_REGULAR)
721 { 693 {
@@ -769,7 +741,7 @@ parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ref, Eina_Bool allow_sarray)
769 check_next(ls, '('); 741 check_next(ls, '(');
770 eo_lexer_context_push(ls); 742 eo_lexer_context_push(ls);
771 def = parse_type_void(ls, allow_ref, EINA_FALSE); 743 def = parse_type_void(ls, allow_ref, EINA_FALSE);
772 if (!_type_is_ownable(def)) 744 if (!database_type_is_ownable(def))
773 { 745 {
774 eo_lexer_context_restore(ls); 746 eo_lexer_context_restore(ls);
775 eo_lexer_syntax_error(ls, "ownable type expected"); 747 eo_lexer_syntax_error(ls, "ownable type expected");
@@ -789,7 +761,7 @@ parse_type_void(Eo_Lexer *ls, Eina_Bool allow_ref, Eina_Bool allow_sarray)
789 check_next(ls, '('); 761 check_next(ls, '(');
790 eo_lexer_context_push(ls); 762 eo_lexer_context_push(ls);
791 def = parse_type_void(ls, allow_ref, EINA_FALSE); 763 def = parse_type_void(ls, allow_ref, EINA_FALSE);
792 if (!_type_is_ownable(def)) 764 if (!database_type_is_ownable(def))
793 { 765 {
794 eo_lexer_context_restore(ls); 766 eo_lexer_context_restore(ls);
795 eo_lexer_syntax_error(ls, "freeable type expected"); 767 eo_lexer_syntax_error(ls, "freeable type expected");
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index c088412898..bb7f5ba348 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -312,9 +312,11 @@ void database_enum_add(Eolian_Typedecl *tp);
312void database_type_del(Eolian_Type *tp); 312void database_type_del(Eolian_Type *tp);
313void database_typedecl_del(Eolian_Typedecl *tp); 313void database_typedecl_del(Eolian_Typedecl *tp);
314 314
315void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name); 315void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype);
316void database_typedecl_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp, Eina_Strbuf *buf); 316void database_typedecl_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp, Eina_Strbuf *buf);
317 317
318Eina_Bool database_type_is_ownable(const Eolian_Type *tp);
319
318/* expressions */ 320/* expressions */
319 321
320Eolian_Value database_expr_eval(const Eolian_Unit *unit, const Eolian_Expression *expr, Eolian_Expression_Mask mask); 322Eolian_Value database_expr_eval(const Eolian_Unit *unit, const Eolian_Expression *expr, Eolian_Expression_Mask mask);