summaryrefslogtreecommitdiff
path: root/src/lib/eolian/database_implement_api.c
blob: f77500a4d588af72c3d0f2993f1a26f622370d30 (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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <Eina.h>
#include "eolian_database.h"

EAPI Eina_Stringshare *
eolian_implement_full_name_get(const Eolian_Implement *impl)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(impl, NULL);
   return impl->full_name;
}

static Eina_Bool
_fill_class(Eolian_Implement *impl)
{
   const Eolian_Class *class = NULL;
   if (impl->klass)
     return EINA_TRUE;
   if (!database_class_name_validate(impl->full_name, &class) || !class)
     return EINA_FALSE;
   impl->klass = class;
   return EINA_TRUE;
}

EAPI const Eolian_Class *
eolian_implement_class_get(const Eolian_Implement *impl)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(impl, NULL);
   if (!_fill_class((Eolian_Implement*)impl))
     return NULL;
   return impl->klass;
}

EAPI const Eolian_Function *
eolian_implement_function_get(const Eolian_Implement *impl,
                              Eolian_Function_Type   *func_type)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(impl, NULL);

   if (impl->foo_id)
     {
        if (!func_type)
          return impl->foo_id;

        if (impl->is_prop_get)
          *func_type = EOLIAN_PROP_GET;
        else if (impl->is_prop_set)
          *func_type = EOLIAN_PROP_SET;
        else
          *func_type = eolian_function_type_get(impl->foo_id);

        return impl->foo_id;
     }

   const Eolian_Class *klass = eolian_implement_class_get(impl);
   if (!klass)
     return NULL;

   const char *func_name = impl->full_name + strlen(klass->full_name) + 1;

   Eolian_Function_Type tp = EOLIAN_UNRESOLVED;

   if (impl->is_prop_get)
     tp = EOLIAN_PROP_GET;
   else if (impl->is_prop_set)
     tp = EOLIAN_PROP_SET;

   const Eolian_Function *fid = eolian_class_function_get_by_name(klass,
                                                                  func_name,
                                                                  tp);

   if (fid && tp == EOLIAN_UNRESOLVED && (fid->type == EOLIAN_PROP_GET
                                       || fid->type == EOLIAN_PROP_SET))
     {
        eina_log_print(_eolian_log_dom, EINA_LOG_LEVEL_ERR,
            impl->base.file, "", impl->base.line, "both get and set required "
              "for property '%s' at column %d", func_name, impl->base.column);
        return NULL;
     }

   if (func_type)
     {
        if (tp == EOLIAN_UNRESOLVED)
          *func_type = eolian_function_type_get(fid);
        else
          *func_type = tp;
     }

   ((Eolian_Implement*)impl)->foo_id = fid;

   return fid;
}

EAPI Eina_Bool
eolian_implement_is_auto(const Eolian_Implement *impl)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(impl, EINA_FALSE);
   return impl->is_auto;
}

EAPI Eina_Bool
eolian_implement_is_empty(const Eolian_Implement *impl)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(impl, EINA_FALSE);
   return impl->is_empty;
}

EAPI Eina_Bool
eolian_implement_is_virtual(const Eolian_Implement *impl)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(impl, EINA_FALSE);
   return impl->is_virtual;
}

EAPI Eina_Bool
eolian_implement_is_prop_get(const Eolian_Implement *impl)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(impl, EINA_FALSE);
   return impl->is_prop_get;
}

EAPI Eina_Bool
eolian_implement_is_prop_set(const Eolian_Implement *impl)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(impl, EINA_FALSE);
   return impl->is_prop_set;
}