summaryrefslogtreecommitdiff
path: root/src/scripts/testgen/ekeys.py
blob: eeff4c4503dd3f8fe3a4691da5a7d32d1151e27b (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
#!/usr/bin/env python3
# encoding: utf-8

class Function_List_Type:
    INHERITIS = 1
    INHERITIS_FULL = 2
    CLASS_IMPLEMENTS = 3
    CLASS_ONLY = 4

class EKeys:
    def __init__(self, ext):
        self.ext = ext
        self.dicttypes = {}
        self.keywords = []
        self.verbs = []
        self.blacklist = []
        self.keyloads = ["init", "shutdown", "custom"]
        self.funclist = Function_List_Type.CLASS_IMPLEMENTS

    def type_convert(self, eotype):
        return eotype.name

    def print_arg(self, eoarg):
        return "arg_{}".format(eoarg.name)


class EMonoKeys(EKeys):
    def __init__(self, ext):
        super().__init__(ext)
        self.dicttypes = {
            "byte": "sbyte",
            "llong": "long",
            "int8": "sbyte",
            "int16": "short",
            "int32": "int",
            "int64": "long",
            "ssize": "long",
            "ubyte": "byte",
            "ullong": "ulong",
            "uint8": "byte",
            "uint16": "ushort",
            "uint32": "uint",
            "uint64": "ulong",
            "size": "ulong",
            "ptrdiff": "long",
            "intptr": "System.IntPtr",
            "uintptr": "System.IntPtr",
            "void_ptr": "System.IntPtr",
            "void": "System.IntPtr",  # only if is out/inout
            "Error": "eina.Error",
            "string": "System.String",
            "mstring": "System.String",
            "stringshare": "System.String",
            "any_value": "eina.Value",
            "any_value_ptr": "eina.Value"
            # complex Types
            ,
            "list": "eina.List",
            "inlist": "eina.Inlist",
            "array": "eina.Array",
            "inarray": "eina.Inarray",
            "hash": "eina.Hash",
            "promise": "int",
            "future": "int",
            "iterator": "eina.Iterator",
            "accessor": "int",
        }

        self.keywords = [
            "delete",
            "do",
            "lock",
            "event",
            "in",
            "object",
            "interface",
            "string",
            "internal",
            "fixed",
            "base",
        ]

        self.verbs = [
            "add",
            "get",
            "is",
            "del",
            "thaw",
            "freeze",
            "save",
            "wait",
            "eject",
            "raise",
            "lower",
            "load",
            "dup",
            "reset",
            "unload",
            "close",
            "set",
            "interpolate",
            "has",
            "grab",
            "check",
            "find",
            "ungrab",
            "unset",
            "clear",
            "pop",
            "new",
            "peek",
            "push",
            "update",
            "show",
            "move",
            "hide",
            "calculate",
            "resize",
            "attach",
            "pack",
            "unpack",
            "emit",
            "call",
            "append",
        ]

        self.blacklist = [
            "efl_event_callback_array_priority_add",
            "efl_player_position_get",
            "efl_text_font_source",
            "efl_ui_focus_manager_focus_get",
            "efl_ui_widget_focus",
            "efl_ui_text_password",
            "elm_interface_scrollable_repeat_events",
            "elm_wdg_item_del",
            "elm_wdg_item_focus",
            "elm_interface_scrollable_mirrored_set",
            "evas_obj_table_mirrored",
            "edje_obj_load_error_get",
            "efl_ui_focus_user_parent_get",
            "efl_canvas_object_scale",  # duplicated signature
            "efl_access_parent_get",
            "efl_access_name",
            "efl_access_root_get",
            "efl_access_type_get",
            "efl_access_role_get",
            "efl_access_action_description",
            "efl_access_image_description",
            "efl_access_component_layer_get",  # duplicated signature
            "efl_access_component_alpha_get",
            "efl_access_component_size_get",
            "efl_ui_spin_button_loop_get",
            "efl_ui_list_model_size_get",
            "efl_ui_list_relayout_layout_do",
        ]

    def escape_keyword(self, key):
        return "kw_{}".format(key) if key in self.keywords else key

    def direction_get(self, name):
        if name == "INOUT":
            return "ref "
        elif name == "OUT":
            return "out "
        return None

    def klass_name(self, eotype):
        *namespaces, name = eotype.name.split(".")
        namespaces = [self.escape_keyword(x.lower()) for x in namespaces]
        is_interface = eotype.type == eotype.type.CLASS
        k_name = ('I' if is_interface else '') + name
        return ".".join(namespaces + [k_name])

    def type_convert(self, eotype):
        if eotype.type == eotype.type.VOID:
            return "System.IntPtr"

        new_type = self.dicttypes.get(eotype.name, self.klass_name(eotype))
        if new_type != "int" and eotype.base_type:
            new_type = "{}<{}>".format(
                new_type,
                self.dicttypes.get(
                    eotype.base_type.name, self.klass_name(eotype.base_type)
                ),
            )

        return new_type

    def print_arg(self, eoarg):
        r = super().print_arg(eoarg)
        prefix = self.direction_get(eoarg.direction.name) or None

        if prefix == "out" and (eoarg.type.name in ("Eina.Slice", "Eina.Rw_Slice")):
            prefix = "ref"

        if (not prefix
                and eoarg.type.is_ptr
                and eoarg.type.type == eoarg.type.type.REGULAR
                and eoarg.type.typedecl
                and eoarg.type.typedecl.type == eoarg.type.typedecl.type.STRUCT):
            prefix = "ref"

        return " ".join([prefix, r]) if prefix else r


def GetKey(ext):
    if ext == ".cs":
        return EMonoKeys(ext)
    return EKeys(ext)