summaryrefslogtreecommitdiff
path: root/src/lib/eolian/database_type.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/eolian/database_type.c')
-rw-r--r--src/lib/eolian/database_type.c52
1 files changed, 44 insertions, 8 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