summaryrefslogtreecommitdiff
path: root/src/lib/eolian/eolian_database.h
blob: edef41e94c9e1ee9a5e678329a3d4d5036bda4d4 (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#ifndef __EOLIAN_DATABASE_H
#define __EOLIAN_DATABASE_H

#include <Eolian.h>

extern int _eolian_log_dom;
extern Eina_Prefix *_eolian_prefix;

#ifdef CRI
#undef CRI
#endif
#define CRI(...) EINA_LOG_DOM_CRIT(_eolian_log_dom, __VA_ARGS__)

#ifdef ERR
#undef ERR
#endif
#define ERR(...) EINA_LOG_DOM_ERR(_eolian_log_dom, __VA_ARGS__)

#ifdef WRN
#undef WRN
#endif
#define WRN(...) EINA_LOG_DOM_WARN(_eolian_log_dom, __VA_ARGS__)

#ifdef INF
#undef INF
#endif
#define INF(...) EINA_LOG_DOM_INFO(_eolian_log_dom, __VA_ARGS__)

#ifdef DBG
#undef DBG
#endif
#define DBG(...) EINA_LOG_DOM_DBG(_eolian_log_dom, __VA_ARGS__)

struct _Eolian_Unit
{
   Eolian        *state;
   Eina_Hash     *children;
   Eina_Hash     *classes;
   Eina_Hash     *globals;
   Eina_Hash     *constants;
   Eina_Hash     *aliases;
   Eina_Hash     *structs;
   Eina_Hash     *enums;
   Eina_Hash     *decls;
};

struct _Eolian
{
   Eolian_Unit unit;

   Eina_Hash *filenames_eo; /* filename to full path mapping */
   Eina_Hash *filenames_eot;

   Eina_Hash *parsing;
   Eina_Hash *parsed;
   Eina_Hash *defer;

   Eina_Hash *units;

   Eina_Hash *classes_f;
   Eina_Hash *aliases_f;
   Eina_Hash *structs_f;
   Eina_Hash *enums_f;
   Eina_Hash *globals_f;
   Eina_Hash *constants_f;
   Eina_Hash *decls_f;
};

typedef struct _Eolian_Object
{
   const char *file;
   int line;
   int column;
   int refcount;
   Eina_Bool validated;
} Eolian_Object;

static inline void
eolian_object_ref(Eolian_Object *obj)
{
   ++obj->refcount;
}

static inline Eina_Bool
eolian_object_unref(Eolian_Object *obj)
{
   return (--obj->refcount > 0);
}

struct _Eolian_Documentation
{
   Eolian_Object base;
   Eina_Stringshare *summary;
   Eina_Stringshare *description;
   Eina_Stringshare *since;
};

struct _Eolian_Declaration
{
   Eolian_Declaration_Type type;
   Eina_Stringshare *name;
   void *data;
};

struct _Eolian_Class
{
   Eolian_Object base;
   Eina_Stringshare *full_name;
   Eina_List *namespaces; /* List Eina_Stringshare * */
   Eina_Stringshare *name;
   Eolian_Class_Type type;
   Eolian_Documentation *doc;
   Eina_Stringshare *legacy_prefix;
   Eina_Stringshare *eo_prefix;
   Eina_Stringshare *ev_prefix;
   Eina_Stringshare *data_type;
   Eina_List *inherits; /* Eolian_Class */
   Eina_List *properties; /* Eolian_Function */
   Eina_List *methods; /* Eolian_Function */
   Eina_List *implements; /* Eolian_Implement */
   Eina_List *constructors; /* Eolian_Constructor */
   Eina_List *events; /* Eolian_Event */
   Eina_List *parts; /* Eolian_Part */
   Eina_Bool class_ctor_enable:1;
   Eina_Bool class_dtor_enable:1;
   Eina_Bool toplevel:1;
};

struct _Eolian_Function
{
   Eolian_Object base;
   Eolian_Object set_base;
   Eina_Stringshare *name;
   union { /* lists of Eolian_Function_Parameter */
       Eina_List *params;
       struct {
           Eina_List *prop_values;
           Eina_List *prop_values_get;
           Eina_List *prop_values_set;
           Eina_List *prop_keys;
           Eina_List *prop_keys_get;
           Eina_List *prop_keys_set;
       };
   };
   Eolian_Function_Type type;
   Eolian_Object_Scope get_scope;
   Eolian_Object_Scope set_scope;
   Eolian_Type *get_ret_type;
   Eolian_Type *set_ret_type;
   Eolian_Expression *get_ret_val;
   Eolian_Expression *set_ret_val;
   Eolian_Implement *impl;
   Eina_Stringshare *get_legacy;
   Eina_Stringshare *set_legacy;
   Eolian_Documentation *get_return_doc;
   Eolian_Documentation *set_return_doc;
   Eina_Bool obj_is_const :1; /* True if the object has to be const. Useful for a few methods. */
   Eina_Bool get_return_warn_unused :1; /* also used for methods */
   Eina_Bool set_return_warn_unused :1;
   Eina_Bool get_only_legacy: 1;
   Eina_Bool set_only_legacy: 1;
   Eina_Bool is_class :1;
   Eina_Bool is_beta :1;
   Eina_List *ctor_of;
   Eolian_Class *klass;
};

struct _Eolian_Part
{
   Eolian_Object base;
   Eina_Stringshare *name;
   Eolian_Class *klass;
   Eolian_Documentation *doc;
};

struct _Eolian_Function_Parameter
{
   Eolian_Object base;
   Eina_Stringshare *name;
   Eolian_Type *type;
   Eolian_Expression *value;
   Eolian_Documentation *doc;
   Eolian_Parameter_Dir param_dir;
   Eina_Bool nonull :1; /* True if this argument cannot be NULL - deprecated */
   Eina_Bool nullable :1; /* True if this argument is nullable */
   Eina_Bool optional :1; /* True if this argument is optional */
};

struct _Eolian_Type
{
   Eolian_Object base;
   Eolian_Type_Type type;
   Eolian_Type_Builtin_Type btype;
   Eolian_Type *base_type;
   Eolian_Type *next_type;
   Eina_Stringshare *name;
   Eina_Stringshare *full_name;
   Eina_List        *namespaces;
   Eina_Stringshare *freefunc;
   Eina_Bool is_const  :1;
   Eina_Bool is_ptr    :1;
   Eina_Bool owned     :1;
   Eina_Bool legacy    :1;
};

struct _Eolian_Typedecl
{
   Eolian_Object base;
   Eolian_Typedecl_Type type;
   Eolian_Type      *base_type;
   Eina_Stringshare *name;
   Eina_Stringshare *full_name;
   Eina_List        *namespaces;
   Eina_Hash        *fields;
   Eina_List        *field_list;
   Eolian_Function *function_pointer;
   Eolian_Documentation *doc;
   Eina_Stringshare *legacy;
   Eina_Stringshare *freefunc;
   Eina_Bool is_extern :1;
};

struct _Eolian_Implement
{
   Eolian_Object base;
   const Eolian_Class *klass;
   const Eolian_Function *foo_id;
   Eina_Stringshare *full_name;
   Eolian_Documentation *common_doc;
   Eolian_Documentation *get_doc;
   Eolian_Documentation *set_doc;
   Eina_Bool is_prop_get :1;
   Eina_Bool is_prop_set :1;
   Eina_Bool get_pure_virtual :1;
   Eina_Bool set_pure_virtual :1;
   Eina_Bool get_auto: 1;
   Eina_Bool set_auto: 1;
   Eina_Bool get_empty: 1;
   Eina_Bool set_empty: 1;
};

struct _Eolian_Constructor
{
   Eolian_Object base;
   const Eolian_Class *klass;
   Eina_Stringshare *full_name;
   Eina_Bool is_optional: 1;
};

struct _Eolian_Event
{
   Eolian_Object base;
   Eina_Stringshare *name;
   Eolian_Documentation *doc;
   Eolian_Type *type;
   Eolian_Class *klass;
   Eolian_Object_Scope scope;
   Eina_Bool is_beta :1;
   Eina_Bool is_hot  :1;
   Eina_Bool is_restart :1;
};

struct _Eolian_Struct_Type_Field
{
   Eolian_Object     base;
   Eina_Stringshare *name;
   Eolian_Type      *type;
   Eolian_Documentation *doc;
};

struct _Eolian_Enum_Type_Field
{
   Eolian_Object      base;
   Eolian_Typedecl   *base_enum;
   Eina_Stringshare  *name;
   Eolian_Expression *value;
   Eolian_Documentation *doc;
   Eina_Bool is_public_value :1;
};

struct _Eolian_Expression
{
   Eolian_Object base;
   Eolian_Expression_Type type;
   union
   {
      struct
      {
         Eolian_Binary_Operator binop;
         Eolian_Expression *lhs;
         Eolian_Expression *rhs;
      };
      struct
      {
         Eolian_Unary_Operator unop;
         Eolian_Expression *expr;
      };
      Eolian_Value_Union value;
   };
   Eina_Bool weak_lhs :1;
   Eina_Bool weak_rhs :1;
};

struct _Eolian_Variable
{
   Eolian_Object         base;
   Eolian_Variable_Type  type;
   Eina_Stringshare     *name;
   Eina_Stringshare     *full_name;
   Eina_List            *namespaces;
   Eolian_Type          *base_type;
   Eolian_Expression    *value;
   Eolian_Documentation *doc;
   Eina_Bool is_extern :1;
};

int database_init(void);
int database_shutdown(void);

char *database_class_to_filename(const char *cname);
Eina_Bool database_validate(Eolian *state, const Eolian_Unit *src);

void database_decl_add(Eolian *state, Eina_Stringshare *name,
                       Eolian_Declaration_Type type,
                       Eina_Stringshare *file, void *ptr);

void database_doc_del(Eolian_Documentation *doc);

void database_unit_init(Eolian *state, Eolian_Unit *unit);
void database_unit_del(Eolian_Unit *unit);

/* types */

void database_type_add(Eolian *state, Eolian_Typedecl *def);
void database_struct_add(Eolian *state, Eolian_Typedecl *tp);
void database_enum_add(Eolian *state, Eolian_Typedecl *tp);
void database_type_del(Eolian_Type *tp);
void database_typedecl_del(Eolian_Typedecl *tp);

void database_type_to_str(const Eolian_Unit *src, const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype);
void database_typedecl_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp, Eina_Strbuf *buf);

Eina_Bool database_type_is_ownable(const Eolian_Unit *unit, const Eolian_Type *tp);

/* expressions */

Eolian_Value database_expr_eval(const Eolian_Unit *unit, const Eolian_Expression *expr, Eolian_Expression_Mask mask);
void database_expr_del(Eolian_Expression *expr);
void database_expr_print(Eolian_Expression *expr);

/* variables */

void database_var_del(Eolian_Variable *var);
void database_var_add(Eolian *state, Eolian_Variable *var);

/* classes */
void database_class_del(Eolian_Class *cl);

/* functions */
void database_function_del(Eolian_Function *fid);
void database_function_constructor_add(Eolian_Function *func, const Eolian_Class *klass);
Eina_Bool database_function_is_type(Eolian_Function *fid, Eolian_Function_Type ftype);

/* func parameters */
void database_parameter_del(Eolian_Function_Parameter *pdesc);

/* implements */
void database_implement_del(Eolian_Implement *impl);

/* constructors */
void database_constructor_del(Eolian_Constructor *ctor);

/* events */
void database_event_del(Eolian_Event *event);

/* parts */
void database_part_del(Eolian_Part *part);

#endif