summaryrefslogtreecommitdiff
path: root/src/bin/eolian/types_generator.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/eolian/types_generator.c')
-rw-r--r--src/bin/eolian/types_generator.c90
1 files changed, 82 insertions, 8 deletions
diff --git a/src/bin/eolian/types_generator.c b/src/bin/eolian/types_generator.c
index e770fe3cb8..9da055816f 100644
--- a/src/bin/eolian/types_generator.c
+++ b/src/bin/eolian/types_generator.c
@@ -37,7 +37,7 @@ _desc_generate(const char *desc, Eina_Strbuf *buf)
37} 37}
38 38
39static Eina_Strbuf * 39static Eina_Strbuf *
40_type_generate(const Eolian_Type *tp) 40_type_generate(const Eolian_Type *tp, Eina_Bool in_typedef)
41{ 41{
42 Eina_Strbuf *buf = eina_strbuf_new(); 42 Eina_Strbuf *buf = eina_strbuf_new();
43 _desc_generate(eolian_type_description_get(tp), buf); 43 _desc_generate(eolian_type_description_get(tp), buf);
@@ -48,10 +48,10 @@ _type_generate(const Eolian_Type *tp)
48 { 48 {
49 const Eolian_Type *base_tp = eolian_type_base_type_get(tp); 49 const Eolian_Type *base_tp = eolian_type_base_type_get(tp);
50 Eolian_Type_Type base_tp_type = eolian_type_type_get(base_tp); 50 Eolian_Type_Type base_tp_type = eolian_type_type_get(base_tp);
51 if (base_tp_type == EOLIAN_TYPE_STRUCT) 51 if (base_tp_type == EOLIAN_TYPE_STRUCT || base_tp_type == EOLIAN_TYPE_ENUM)
52 { 52 {
53 const char *name = eolian_type_name_get(tp); 53 const char *name = eolian_type_name_get(tp);
54 Eina_Strbuf *struct_buf = _type_generate(base_tp); 54 Eina_Strbuf *struct_buf = _type_generate(base_tp, EINA_TRUE);
55 eina_strbuf_append_printf(buf, "typedef %s%s%s", 55 eina_strbuf_append_printf(buf, "typedef %s%s%s",
56 eina_strbuf_string_get(struct_buf), 56 eina_strbuf_string_get(struct_buf),
57 name?" ":"", name?name:""); 57 name?" ":"", name?name:"");
@@ -72,6 +72,12 @@ _type_generate(const Eolian_Type *tp)
72 { 72 {
73 const char *member_name; 73 const char *member_name;
74 char *name = _concat_name(tp); 74 char *name = _concat_name(tp);
75 if (in_typedef && name)
76 {
77 eina_strbuf_append_printf(buf, "struct %s", name);
78 free(name);
79 break;
80 }
75 eina_strbuf_append_printf(buf, "struct%s%s {\n", name?" ":"", name?name:""); 81 eina_strbuf_append_printf(buf, "struct%s%s {\n", name?" ":"", name?name:"");
76 free(name); 82 free(name);
77 Eina_Iterator *members = eolian_type_struct_field_names_get(tp); 83 Eina_Iterator *members = eolian_type_struct_field_names_get(tp);
@@ -90,6 +96,62 @@ _type_generate(const Eolian_Type *tp)
90 eina_strbuf_append(buf, "}"); 96 eina_strbuf_append(buf, "}");
91 break; 97 break;
92 } 98 }
99 case EOLIAN_TYPE_ENUM:
100 {
101 const char *member_name;
102 char *name = _concat_name(tp);
103 if (in_typedef)
104 {
105 eina_strbuf_append_printf(buf, "enum %s", name);
106 free(name);
107 break;
108 }
109 char *pre = NULL;
110 eina_strbuf_append_printf(buf, "enum %s {\n", name);
111 if (eolian_type_enum_legacy_prefix_get(tp))
112 {
113 pre = strdup(eolian_type_enum_legacy_prefix_get(tp));
114 free(name);
115 }
116 else
117 pre = name;
118 eina_str_toupper(&pre);
119 Eina_Iterator *members = eolian_type_enum_field_names_get(tp);
120 Eina_Bool next = eina_iterator_next(members, (void**)&member_name);
121 Eina_Strbuf *membuf = eina_strbuf_new();
122 while (next)
123 {
124 const char *desc = eolian_type_enum_field_description_get(tp, member_name);
125 const Eolian_Expression *member = eolian_type_enum_field_get(tp, member_name);
126 char *memb_u = strdup(member_name);
127 eina_str_toupper(&memb_u);
128 eina_strbuf_reset(membuf);
129 eina_strbuf_append(membuf, pre);
130 eina_strbuf_append_char(membuf, '_');
131 eina_strbuf_append(membuf, memb_u);
132 free(memb_u);
133 if (!member)
134 eina_strbuf_append_printf(buf, " %s", eina_strbuf_string_get(membuf));
135 else
136 {
137 Eina_Value *v = NULL;
138 Eolian_Expression_Type et = eolian_expression_eval(member, EOLIAN_MASK_INT, &v);
139 const char *lit = eolian_expression_value_to_literal(v, et);
140 eina_strbuf_append_printf(buf, " %s = %s", eina_strbuf_string_get(membuf), lit);
141 eina_stringshare_del(lit);
142 }
143 next = eina_iterator_next(members, (void**)&member_name);
144 if (next)
145 eina_strbuf_append(buf, ",");
146 if (desc) eina_strbuf_append_printf(buf, " /** %s */", desc);
147 eina_strbuf_append(buf, "\n");
148 }
149 eina_strbuf_free(membuf);
150 free(pre);
151 eina_iterator_free(members);
152 eina_strbuf_append(buf, "}");
153 break;
154 }
93 default: 155 default:
94 { 156 {
95 eina_strbuf_reset(buf); 157 eina_strbuf_reset(buf);
@@ -107,10 +169,7 @@ types_header_generate(const char *eo_filename, Eina_Strbuf *buf)
107 Eina_Iterator *itr = eolian_type_aliases_get_by_file(eo_filename); 169 Eina_Iterator *itr = eolian_type_aliases_get_by_file(eo_filename);
108 EINA_ITERATOR_FOREACH(itr, tp) 170 EINA_ITERATOR_FOREACH(itr, tp)
109 { 171 {
110 /* avoid for the time being */ 172 Eina_Strbuf *type_buf = _type_generate(tp, EINA_TRUE);
111 if (eolian_type_type_get(eolian_type_base_type_get(tp)) == EOLIAN_TYPE_ENUM)
112 continue;
113 Eina_Strbuf *type_buf = _type_generate(tp);
114 if (type_buf) 173 if (type_buf)
115 { 174 {
116 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf)); 175 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf));
@@ -124,7 +183,21 @@ types_header_generate(const char *eo_filename, Eina_Strbuf *buf)
124 itr = eolian_type_structs_get_by_file(eo_filename); 183 itr = eolian_type_structs_get_by_file(eo_filename);
125 EINA_ITERATOR_FOREACH(itr, tp) 184 EINA_ITERATOR_FOREACH(itr, tp)
126 { 185 {
127 Eina_Strbuf *type_buf = _type_generate(tp); 186 Eina_Strbuf *type_buf = _type_generate(tp, EINA_FALSE);
187 if (type_buf)
188 {
189 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf));
190 eina_strbuf_append(buf, ";\n\n");
191 eina_strbuf_free(type_buf);
192 }
193 }
194 eina_iterator_free(itr);
195
196 /* Generation of enums */
197 itr = eolian_type_enums_get_by_file(eo_filename);
198 EINA_ITERATOR_FOREACH(itr, tp)
199 {
200 Eina_Strbuf *type_buf = _type_generate(tp, EINA_FALSE);
128 if (type_buf) 201 if (type_buf)
129 { 202 {
130 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf)); 203 eina_strbuf_append(buf, eina_strbuf_string_get(type_buf));
@@ -133,6 +206,7 @@ types_header_generate(const char *eo_filename, Eina_Strbuf *buf)
133 } 206 }
134 } 207 }
135 eina_iterator_free(itr); 208 eina_iterator_free(itr);
209
136 return EINA_TRUE; 210 return EINA_TRUE;
137} 211}
138 212