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
|
local m = {}
function m:def(source, callback)
if source.tag ~= 'self' then
callback(source, 'local')
end
if source.ref then
for _, ref in ipairs(source.ref) do
if ref.type == 'setlocal' then
callback(ref, 'set')
end
end
end
if source.tag == 'self' then
local method = source.method
local node = method.node
self:eachRef(node, 'def', callback)
end
end
function m:ref(source, callback)
if source.tag ~= 'self' then
callback(source, 'local')
end
if source.ref then
for _, ref in ipairs(source.ref) do
if ref.type == 'setlocal' then
callback(ref, 'set')
elseif ref.type == 'getlocal' then
callback(ref, 'get')
end
end
end
if source.tag == 'self' then
local method = source.method
local node = method.node
self:eachRef(node, 'ref', callback)
end
end
function m:field(source, key, callback)
if source.ref then
for _, ref in ipairs(source.ref) do
if ref.type == 'getlocal' then
local parent = ref.parent
local tp = parent.type
if tp == 'setfield'
or tp == 'setmethod'
or tp == 'setindex' then
callback(parent, 'set')
elseif tp == 'getfield'
or tp == 'getmethod'
or tp == 'getindex' then
callback(parent, 'get')
end
elseif ref.type == 'setlocal' then
self:eachRef(ref.value, 'field', callback)
elseif ref.type == 'getglobal' then
-- _ENV.XXX
callback(ref, 'get')
elseif ref.type == 'setglobal' then
-- _ENV.XXX = XXX
callback(ref, 'set')
end
end
end
if source.tag == 'self' then
local method = source.method
local node = method.node
self:eachRef(node, 'field', callback)
end
if source.value then
self:eachField(source.value, nil, 'ref', callback)
end
end
return m
|