1 module('operators', package
.seeall
)
3 local operatorTrans
= {
20 local function is_helper_function(name
)
21 local s1
= name
:sub(1,1)
22 local s2
= name
:sub(2,2)
23 return s1
== 'q' and s2
== s2
:upper()
26 function fix_operators(index
)
27 for f
in pairs(index
) do
28 if f
.label
== "Function" then
29 if f
.xarg
.name
:match("^operator") and f
.xarg
.friend
then
30 if f
[1].xarg
.type_base
== f
.xarg
.member_of
then
31 -- overloaded friend operator - its first argument is 'this',
32 -- needs to be removed
34 table.remove(f
.arguments
, 1)
35 if f
.xarg
.name
== 'operator-' and #f
.arguments
== 0 then
36 -- use '_' as a marker for unary minus
37 f
.xarg
.name
= 'operator_'
40 -- operator in form: number OP class - do not bind these
43 elseif is_helper_function(f
.xarg
.name
) then
51 local op
= operators
.get_operator(f
.xarg
.name
)
52 if op
== "*" and #f
.arguments
== 0 then
53 ignore(f
.xarg
.fullname
, "pointer dereference operator", f
.xarg
.member_of_class
)
57 return '- *self', false
58 elseif op
== '++' or op
== '--' then
59 -- the ++ and -- operators don't line () at the end, like: *self ++()
60 if f
.arguments
[1] then
62 return op
..' *self', false
64 return '*self '..op
, false
67 return '*self '..op
..'(', true
71 function get_operator(name
)
72 return name
:match('^operator(.+)$')
75 function is_operator(name
)
76 return name
:match('^operator.') and operatorTrans
[get_operator(name
)]
79 function rename_operator(name
)
80 local trans
= operatorTrans
[get_operator(name
)]
81 if is_operator(name
) and trans
then