summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2016-09-28 17:41:50 +0200
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2016-10-07 11:54:23 +0200
commit527293557348f6196333ea79bb1ed360312c23b8 (patch)
tree8f0a3b7d0f478bcc4dbf19f73079e5c1009d9acd
parent759f470c29b2f362a87fc37a1abff1fb77f5a74b (diff)
eolian gen2: generation of class initializer func
-rw-r--r--src/bin/eolian2/sources.c128
1 files changed, 124 insertions, 4 deletions
diff --git a/src/bin/eolian2/sources.c b/src/bin/eolian2/sources.c
index f2a297da45..b89c72b9e3 100644
--- a/src/bin/eolian2/sources.c
+++ b/src/bin/eolian2/sources.c
@@ -191,7 +191,7 @@ _gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
191 Eina_Stringshare *rtpn = rtp ? eolian_type_c_type_get(rtp) 191 Eina_Stringshare *rtpn = rtp ? eolian_type_c_type_get(rtp)
192 : eina_stringshare_add("void"); 192 : eina_stringshare_add("void");
193 193
194 char *cnamel, *ocnamel = NULL; 194 char *cnamel = NULL, *ocnamel = NULL;
195 if (!eo_gen_class_names_get(cl, NULL, NULL, &cnamel)) 195 if (!eo_gen_class_names_get(cl, NULL, NULL, &cnamel))
196 goto end; 196 goto end;
197 if (!eo_gen_class_names_get(eolian_implement_class_get(impl), NULL, NULL, &ocnamel)) 197 if (!eo_gen_class_names_get(eolian_implement_class_get(impl), NULL, NULL, &ocnamel))
@@ -241,8 +241,7 @@ _gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
241 /* we need to give the internal function name to Eo, 241 /* we need to give the internal function name to Eo,
242 * use this hash table as indication 242 * use this hash table as indication
243 */ 243 */
244 eina_hash_add(_funcs_params_init, 244 eina_hash_add(_funcs_params_init, &impl, impl);
245 eina_stringshare_add(eolian_function_name_get(fid)), (void *)ftype);
246 /* generation of intermediate __eolian_... */ 245 /* generation of intermediate __eolian_... */
247 eina_strbuf_append(buf, "static "); 246 eina_strbuf_append(buf, "static ");
248 eina_strbuf_append(buf, rtpn); 247 eina_strbuf_append(buf, rtpn);
@@ -402,13 +401,132 @@ end:
402 eina_strbuf_free(params_init); 401 eina_strbuf_free(params_init);
403} 402}
404 403
404static void
405_gen_opfunc(const Eolian_Function *fid, Eolian_Function_Type ftype,
406 Eina_Strbuf *buf, Eina_Bool pinit,
407 const char *cnamel, const char *ocnamel)
408{
409 Eina_Stringshare *fnm = eolian_function_full_c_name_get(fid, ftype, EINA_FALSE);
410 eina_strbuf_append(buf, " EFL_OBJECT_OP_FUNC(");
411 eina_strbuf_append(buf, fnm);
412 eina_strbuf_append(buf, ", ");
413 if (!ocnamel && eolian_function_is_virtual_pure(fid, ftype))
414 eina_strbuf_append(buf, "NULL),\n");
415 else
416 {
417 if (pinit)
418 eina_strbuf_append(buf, "__eolian");
419 eina_strbuf_append_printf(buf, "_%s_", cnamel);
420 if (ocnamel)
421 eina_strbuf_append_printf(buf, "%s_", ocnamel);
422 eina_strbuf_append(buf, eolian_function_name_get(fid));
423 if (ftype == EOLIAN_PROP_GET)
424 eina_strbuf_append(buf, "_get");
425 else if (ftype == EOLIAN_PROP_SET)
426 eina_strbuf_append(buf, "_set");
427 eina_strbuf_append(buf, "),\n");
428 }
429}
430
431static Eina_Bool
432_gen_initializer(const Eolian_Class *cl, Eina_Strbuf *buf)
433{
434 Eina_Iterator *itr = eolian_class_implements_get(cl);
435 const Eolian_Implement *imp;
436 if (!eina_iterator_next(itr, (void **)&imp))
437 {
438 eina_iterator_free(itr);
439 return EINA_FALSE;
440 }
441 eina_iterator_free(itr);
442
443 char *cnamel = NULL;
444 if (!eo_gen_class_names_get(cl, NULL, NULL, &cnamel))
445 return EINA_FALSE;
446
447 eina_strbuf_append(buf, "\nstatic Eina_Bool\n_");
448 eina_strbuf_append(buf, cnamel);
449 eina_strbuf_append(buf, "_class_initializer(Efl_Class *klass)\n{\n");
450
451 Eina_Strbuf *ops = eina_strbuf_new(), *cops = eina_strbuf_new();
452
453 /* start over with clean itearator */
454 itr = eolian_class_implements_get(cl);
455 EINA_ITERATOR_FOREACH(itr, imp)
456 {
457 const Eolian_Class *icl = eolian_implement_class_get(imp);
458 Eolian_Function_Type ftype;
459 const Eolian_Function *fid = eolian_implement_function_get(imp, &ftype);
460
461 Eina_Strbuf *obuf = ops;
462 if (eolian_function_is_class(fid))
463 obuf = cops;
464
465 if (!eina_strbuf_length_get(obuf))
466 eina_strbuf_append_printf(obuf, " EFL_OPS_DEFINE(%s,\n",
467 (obuf == ops) ? "ops" : "cops");
468
469 Eina_Bool found = !!eina_hash_find(_funcs_params_init, &imp);
470 char *ocnamel = NULL;
471 if ((cl != icl) && !eo_gen_class_names_get(cl, NULL, NULL, &ocnamel))
472 return EINA_FALSE;
473
474 switch (ftype)
475 {
476 case EOLIAN_PROP_GET:
477 _gen_opfunc(fid, EOLIAN_PROP_GET, obuf, found, cnamel, ocnamel);
478 break;
479 case EOLIAN_PROP_SET:
480 _gen_opfunc(fid, EOLIAN_PROP_SET, obuf, found, cnamel, ocnamel);
481 break;
482 case EOLIAN_PROPERTY:
483 _gen_opfunc(fid, EOLIAN_PROP_SET, obuf, found, cnamel, ocnamel);
484 _gen_opfunc(fid, EOLIAN_PROP_GET, obuf, found, cnamel, ocnamel);
485 break;
486 default:
487 _gen_opfunc(fid, EOLIAN_METHOD, obuf, found, cnamel, ocnamel);
488 break;
489 }
490
491 free(ocnamel);
492 }
493
494 if (eina_strbuf_length_get(ops))
495 {
496 eina_strbuf_append(ops, " );\n");
497 eina_strbuf_append(buf, eina_strbuf_string_get(ops));
498 }
499 if (eina_strbuf_length_get(cops))
500 {
501 eina_strbuf_append(cops, " );\n");
502 eina_strbuf_append(buf, eina_strbuf_string_get(cops));
503 }
504
505 eina_strbuf_append(buf, " efl_class_functions_set(klass, ");
506 if (eina_strbuf_length_get(ops))
507 eina_strbuf_append(buf, "&ops, ");
508 else
509 eina_strbuf_append(buf, "NULL, ");
510 if (eina_strbuf_length_get(cops))
511 eina_strbuf_append(buf, "&cops);\n");
512 else
513 eina_strbuf_append(buf, "NULL);\n");
514
515 eina_strbuf_free(ops);
516 eina_strbuf_free(cops);
517
518 eina_strbuf_append(buf, "}\n");
519
520 return EINA_TRUE;
521}
522
405void 523void
406eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf) 524eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf)
407{ 525{
408 if (!cl) 526 if (!cl)
409 return; 527 return;
410 528
411 _funcs_params_init = eina_hash_stringshared_new(NULL); 529 _funcs_params_init = eina_hash_pointer_new(NULL);
412 530
413 /* event section, they come first */ 531 /* event section, they come first */
414 { 532 {
@@ -455,5 +573,7 @@ eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf)
455 eina_iterator_free(itr); 573 eina_iterator_free(itr);
456 } 574 }
457 575
576 Eina_Bool has_init = _gen_initializer(cl, buf);
577
458 eina_hash_free(_funcs_params_init); 578 eina_hash_free(_funcs_params_init);
459} 579}