From 18ad48ed3c4b1dcafb1f66d28dc5231b4aa9a00a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 9 Oct 2019 16:31:03 +0800 Subject: =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/core/engineer.lua | 94 ++++++++++++++++++++++------------ server-beta/test/definition/method.lua | 10 ---- 2 files changed, 61 insertions(+), 43 deletions(-) diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua index be64a66c..192de506 100644 --- a/server-beta/src/core/engineer.lua +++ b/server-beta/src/core/engineer.lua @@ -153,32 +153,15 @@ mt['getglobal'] = function (self, source, mode, callback) end end mt['setglobal'] = mt['getglobal'] -mt['eachfield'] = function (self, node, key, mode, callback) - self:eachRef(node, 'field', function (src) - if key == guide.getKeyName(src) then - if mode == 'def' then - if src.type == 'setfield' - or src.type == 'tablefield' then - callback(src.field, 'set') - elseif src.type == 'setindex' - or src.type == 'tableindex' then - callback(src.index, 'set') - elseif src.type == 'setmethod' then - callback(src.method, 'set') - end - end - end - end) -end mt['field'] = function (self, source, mode, callback) local node = source.parent.node local key = guide.getKeyName(source) - mt['eachfield'](self, node, key, mode, callback) + self:eachField(node, key, mode, callback) end mt['method'] = function (self, source, mode, callback) local node = source.parent.node local key = guide.getKeyName(source) - mt['eachfield'](self, node, key, mode, callback) + self:eachField(node, key, mode, callback) end mt['special'] = function (self, source, mode, callback) local name = self:getSpecial(source) @@ -193,22 +176,14 @@ mt['special'] = function (self, source, mode, callback) end end end -mt['asindex'] = function (self, source, mode, callback) - local parent = source.parent - if not parent then - return - end - if parent.type ~= 'setindex' and parent.type ~= 'getindex' then - return - end - local node = parent.node - local key = guide.getKeyName(source) - mt['eachfield'](self, node, key, mode, callback) +mt['number'] = function (self, source, mode, callback) + self:asindex(source, mode, callback) +end +mt['boolean'] = function (self, source, mode, callback) + self:asindex(source, mode, callback) end -mt['number'] = mt['asindex'] -mt['boolean'] = mt['asindex'] mt['string'] = function (self, source, mode, callback) - mt['asindex'](self, source, mode, callback) + self:asindex(source, mode, callback) end mt['table'] = function (self, source, mode, callback) if mode == 'field' then @@ -221,6 +196,41 @@ mt['table'] = function (self, source, mode, callback) end end end +mt['select'] = function (self, source, mode, callback) + local vararg = source.vararg + if vararg.type == 'call' then + local func = vararg.node + self:specialreturn(func, source.index, mode, callback) + end +end + +function mt:specialreturn(source, index, mode, callback) + local name = self:getSpecial(source) + if not name then + return + end + local call = source.parent + if name == 's|setmetatable' then + if index ~= 1 then + return + end + self:eachField(call.args[2], 's|__index', 'def', callback) + return + end +end + +function mt:asindex(source, mode, callback) + local parent = source.parent + if not parent then + return + end + if parent.type ~= 'setindex' and parent.type ~= 'getindex' then + return + end + local node = parent.node + local key = guide.getKeyName(source) + self:eachField(node, key, mode, callback) +end function mt:getSpecial(source) local node = source.node @@ -239,6 +249,24 @@ function mt:search(source, method, mode, callback) f(self, source, mode, callback) end +function mt:eachField(node, key, mode, callback) + self:eachRef(node, 'field', function (src) + if key == guide.getKeyName(src) then + if mode == 'def' then + if src.type == 'setfield' + or src.type == 'tablefield' then + callback(src.field, 'set') + elseif src.type == 'setindex' + or src.type == 'tableindex' then + callback(src.index, 'set') + elseif src.type == 'setmethod' then + callback(src.method, 'set') + end + end + end + end) +end + function mt:eachRef(source, mode, callback) local tp = source.type self:search(source, tp, mode, callback) diff --git a/server-beta/test/definition/method.lua b/server-beta/test/definition/method.lua index 08b56f61..58785fe1 100644 --- a/server-beta/test/definition/method.lua +++ b/server-beta/test/definition/method.lua @@ -40,16 +40,6 @@ local obj = setmetatable({}, mt) obj:() ]] -TEST [[ -local mt -mt.__index = mt -function mt:() -end - -local obj = setmetatable({}, mt) -obj:() -]] - TEST [[ local mt function mt:() -- cgit v1.2.3