aboutsummaryrefslogtreecommitdiffstats
path: root/utils/eolian_extras.lua
blob: 35be202299315bd1750b58845f030b404037582c (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
local eolian = require("eolian")

local M = {}

-- check for pre-state eolian api
local legacy = not eolian.new

-- wrapper for legacy eolian api to mimic modern
local legacy_eos = {
    directory_add = function(self, dir)
        eolian.directory_scan(dir)
    end,

    system_directory_add = function(self)
        eolian.system_directory_scan()
    end,

    all_eo_files_parse = function(self)
        assert(eolian.all_eo_files_parse())
        assert(eolian.database_validate())
    end,

    all_eot_files_parse = function(self)
        assert(eolian.all_eot_files_parse())
        assert(eolian.database_validate())
    end,

    classes_get = function(self)
        return eolian.all_classes_get(nil)
    end,

    aliases_get = function(self)
        return eolian.typedecl_all_aliases_get(nil)
    end,

    structs_get = function(self)
        return eolian.typedecl_all_structs_get(nil)
    end,

    enums_get = function(self)
        return eolian.typedecl_all_enums_get(nil)
    end,

    globals_get = function(self)
        return eolian.variable_all_globals_get(nil)
    end,

    constants_get = function(self)
        return eolian.variable_all_constants_get(nil)
    end
}

M.new = function()
    if legacy then
        return legacy_eos
    end
    return eolian.new()
end

M.get_c_functions = function(eos)
    local ret = {}
    for cl in eos:classes_get() do
        local fntp = eolian.function_type
        for fn in cl:functions_get(fntp.METHOD) do
            ret[#ret + 1] = fn:full_c_name_get(fntp.METHOD, false)
        end
        for fn in cl:functions_get(fntp.PROPERTY) do
            local tp = fn:type_get()
            if tp == fntp.PROPERTY then
                ret[#ret + 1] = fn:full_c_name_get(fntp.PROP_GET, false)
                ret[#ret + 1] = fn:full_c_name_get(fntp.PROP_SET, false)
            else
                ret[#ret + 1] = fn:full_c_name_get(tp, false)
            end
        end
    end
    return ret
end

M.get_c_events = function(eos)
    local ret = {}
    for cl in eos:classes_get() do
        for ev in cl:events_get() do
            ret[#ret + 1] = ev:c_name_get()
        end
    end
    return ret
end

local full_name_get = function(obj)
    if legacy then
        return obj:full_name_get()
    end
    return obj:name_get()
end

M.get_c_function_pointers = function(eos)
    if legacy then
        -- no function pointer support in pre-state api
        return {}
    end
    local ret = {}
    for tp in eos:aliases_get() do
        if tp:type_get() == eolian.typedecl_type.FUNCTION_POINTER then
            ret[#ret + 1] = full_name_get(tp):gsub("%.", "_")
        end
    end
    return ret
end

M.get_c_aliases = function(eos)
    local ret = {}
    for tp in eos:aliases_get() do
        if tp:type_get() ~= eolian.typedecl_type.FUNCTION_POINTER then
            ret[#ret + 1] = full_name_get(tp):gsub("%.", "_")
        end
    end
    return ret
end

M.get_c_structs = function(eos)
    local ret = {}
    for tp in eos:structs_get() do
        ret[#ret + 1] = full_name_get(tp):gsub("%.", "_")
    end
    return ret
end

M.get_c_enums = function(eos)
    local ret = {}
    for tp in eos:enums_get() do
        ret[#ret + 1] = full_name_get(tp):gsub("%.", "_")
    end
    return ret
end

M.get_c_globals = function(eos)
    local ret = {}
    for v in eos:globals_get() do
        ret[#ret + 1] = full_name_get(v):gsub("%.", "_"):upper()
    end
    return ret
end

M.get_c_constants = function(eos)
    local ret = {}
    for v in eos:constants_get() do
        ret[#ret + 1] = full_name_get(v):gsub("%.", "_"):upper()
    end
    return ret
end

return M