summaryrefslogtreecommitdiff
path: root/src/bin/eolian2/headers.c
blob: cfa4a1e50b323ff1e6e0fec834a4a831a59f6112 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "main.h"

const char *
_cl_type_str_get(const Eolian_Class *cl, Eina_Bool uc)
{
   switch (eolian_class_type_get(cl))
     {
      case EOLIAN_CLASS_REGULAR:
      case EOLIAN_CLASS_ABSTRACT:
        return uc ? "CLASS" : "class";
      case EOLIAN_CLASS_MIXIN:
        return uc ? "MIXIN" : "mixin";
      case EOLIAN_CLASS_INTERFACE:
        return uc ? "INTERFACE" : "interface";
      default:
        return NULL;
     }
}

static void
_gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
          Eolian_Function_Type ftype, Eina_Strbuf *buf)
{
}

void
eo_gen_header_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Bool legacy)
{
   if (!cl)
     return;

   char *cname = NULL, *cnameu = NULL, *cnamel = NULL;

   cname = eo_gen_c_full_name_get(eolian_class_full_name_get(cl));
   if (!cname)
     goto end;

   cnameu = strdup(cname);
   if (!cnameu)
     goto end;
   eina_str_toupper(&cnameu);

   cnamel = strdup(cname);
   if (!cnamel)
     goto end;
   eina_str_tolower(&cnamel);

   /* class definition */

   eina_strbuf_append_printf(buf, "#define %s_%s %s_%s_get()\n\n",
                             cnameu, _cl_type_str_get(cl, EINA_TRUE),
                             cnamel, _cl_type_str_get(cl, EINA_FALSE));

   eina_strbuf_append_printf(buf, "EWAPI const Efl_Class *%s_%s_get(void);\n\n",
                             cnamel, _cl_type_str_get(cl, EINA_FALSE));

   /* method section */
   {
      Eina_Iterator *itr = eolian_class_implements_get(cl);
      if (!itr)
        goto events;

      const Eolian_Implement *imp;
      EINA_ITERATOR_FOREACH(itr, imp)
        {
           if (eolian_implement_class_get(imp) != cl)
             continue;
           Eolian_Function_Type ftype = EOLIAN_UNRESOLVED;
           const Eolian_Function *fid = eolian_implement_function_get(imp, &ftype);
           switch (ftype)
             {
              case EOLIAN_PROP_GET:
              case EOLIAN_PROP_SET:
                _gen_func(cl, fid, ftype, buf);
                break;
              case EOLIAN_PROPERTY:
                _gen_func(cl, fid, EOLIAN_PROP_SET, buf);
                _gen_func(cl, fid, EOLIAN_PROP_GET, buf);
                break;
              default:
                _gen_func(cl, fid, EOLIAN_UNRESOLVED, buf);
             }
        }
      eina_iterator_free(itr);
   }

events:
   /* event section */
   {
      Eina_Iterator *itr = eolian_class_events_get(cl);
      Eolian_Event *ev;
      EINA_ITERATOR_FOREACH(itr, ev)
        {
           Eina_Stringshare *evn = eolian_event_c_name_get(ev);
           Eolian_Object_Scope evs = eolian_event_scope_get(ev);

           if (evs == EOLIAN_SCOPE_PRIVATE)
             continue;

           if (eolian_event_is_beta(ev))
             {
                eina_strbuf_append_printf(buf, "\n#ifndef %s_BETA\n", cnameu);
                eina_strbuf_append_printf(buf, "#define %s_BETA\n", cnameu);
             }
           if (evs == EOLIAN_SCOPE_PROTECTED)
             {
                if (!eolian_event_is_beta(ev))
                  eina_strbuf_append_char(buf, '\n');
                eina_strbuf_append_printf(buf, "#ifndef %s_PROTECTED\n", cnameu);
                eina_strbuf_append_printf(buf, "#define %s_PROTECTED\n", cnameu);
             }

           if (!eolian_event_is_beta(ev) && evs == EOLIAN_SCOPE_PUBLIC)
             eina_strbuf_append_char(buf, '\n');

           eina_strbuf_append_printf(buf, "EOAPI extern const "
                                     "Efl_Event_Description _%s;\n", evn);
           eina_strbuf_append_printf(buf, "#define %s (&(_%s))\n", evn, evn);

           if (evs == EOLIAN_SCOPE_PROTECTED)
             eina_strbuf_append(buf, "#endif\n");
           if (eolian_event_is_beta(ev))
             eina_strbuf_append(buf, "#endif\n");

           eina_stringshare_del(evn);
        }
      eina_iterator_free(itr);
   }

end:
   free(cname);
   free(cnameu);
   free(cnamel);
}