diff options
-rw-r--r-- | server-beta/src/searcher/eachField.lua | 56 | ||||
-rw-r--r-- | server-beta/src/searcher/eachRef.lua | 15 | ||||
-rw-r--r-- | server-beta/src/searcher/getField.lua | 14 | ||||
-rw-r--r-- | server-beta/src/searcher/init.lua | 8 | ||||
-rw-r--r-- | server-beta/test/definition/bug.lua | 5 |
5 files changed, 50 insertions, 48 deletions
diff --git a/server-beta/src/searcher/eachField.lua b/server-beta/src/searcher/eachField.lua index 71968aea..8b987cc2 100644 --- a/server-beta/src/searcher/eachField.lua +++ b/server-beta/src/searcher/eachField.lua @@ -19,14 +19,15 @@ local function ofTabel(searcher, value, callback) end end -local function rawField(searcher, source, callback) +local function ofENV(searcher, source, callback) if source.type == 'getlocal' then local parent = source.parent - local field = searcher:getField(parent) - if field then + if parent.type == 'getfield' + or parent.type == 'getmethod' + or parent.type == 'getindex' then callback { searcher = searcher, - source = field, + source = parent, } end elseif source.type == 'getglobal' @@ -38,37 +39,40 @@ local function rawField(searcher, source, callback) end end +local function ofVar(searcher, source, callback) + local parent = source.parent + if parent then + if parent.type == 'getfield' + or parent.type == 'getmethod' + or parent.type == 'getindex' + or parent.type == 'setfield' + or parent.type == 'setmethod' + or parent.type == 'setindex' then + callback { + searcher = searcher, + source = parent, + } + end + end +end + return function (searcher, source, callback) searcher:eachRef(source, function (info) local src = info.source if src.tag == '_ENV' then if src.ref then for _, ref in ipairs(src.ref) do - rawField(info.searcher, ref, callback) - end - end - elseif src.type == 'getlocal' then - if src.parent then - local field = info.searcher:getField(src.parent) - if field then - callback { - searcher = info.searcher, - source = field, - } - end - end - elseif src.type == 'getglobal' then - if src.parent then - local field = info.searcher:getField(src.parent) - if field then - callback { - searcher = info.searcher, - source = field, - } + ofENV(info.searcher, ref, callback) end end + elseif src.type == 'getlocal' + or src.type == 'getglobal' + or src.type == 'getfield' + or src.type == 'getmethod' + or src.type == 'getindex' then + ofVar(info.searcher, src, callback) elseif src.type == 'table' then - ofTabel(searcher, src, callback) + ofTabel(info.searcher, src, callback) end end) end diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua index fedfdfd6..a08c0751 100644 --- a/server-beta/src/searcher/eachRef.lua +++ b/server-beta/src/searcher/eachRef.lua @@ -121,6 +121,21 @@ local function checkField(key, info, callback) value = src.value elseif stype == 'getglobal' then mode = 'get' + elseif stype == 'setfield' then + mode = 'set' + value = src.value + elseif stype == 'getfield' then + mode = 'get' + elseif stype == 'setmethod' then + mode = 'set' + value = src.value + elseif stype == 'getmethod' then + mode = 'get' + elseif stype == 'setindex' then + mode = 'set' + value = src.value + elseif stype == 'getindex' then + mode = 'get' elseif stype == 'field' then local parent = src.parent if parent.type == 'setfield' then diff --git a/server-beta/src/searcher/getField.lua b/server-beta/src/searcher/getField.lua deleted file mode 100644 index 59ae462c..00000000 --- a/server-beta/src/searcher/getField.lua +++ /dev/null @@ -1,14 +0,0 @@ -return function (searcher, source) - local stype = source.type - if stype == 'getfield' - or stype == 'setfield' then - return source.field - elseif stype == 'getmethod' - or stype == 'setmethod' then - return source.method - elseif stype == 'getindex' - or stype == 'setindex' then - return source.index - end - return nil -end diff --git a/server-beta/src/searcher/init.lua b/server-beta/src/searcher/init.lua index 4796be16..5360a1e2 100644 --- a/server-beta/src/searcher/init.lua +++ b/server-beta/src/searcher/init.lua @@ -1,7 +1,6 @@ local guide = require 'parser.guide' local files = require 'files' local util = require 'utility' -local getField = require 'searcher.getField' local eachRef = require 'searcher.eachRef' local eachField = require 'searcher.eachField' @@ -35,13 +34,6 @@ function mt:lock(tp, source) end) end ---- 获取关联的field ----@param source table ----@return table field -function mt:getField(source) - return getField(self, source) -end - --- 获取所有的引用 function mt:eachRef(source, callback) local lock <close> = self:lock('eachRef', source) diff --git a/server-beta/test/definition/bug.lua b/server-beta/test/definition/bug.lua index 27d4700c..823db46d 100644 --- a/server-beta/test/definition/bug.lua +++ b/server-beta/test/definition/bug.lua @@ -61,6 +61,11 @@ self[self.results.<?labels?>] = lbl ]] TEST [[ +self.results.<!labels!> = {} +self[self.results.<?labels?>] = lbl +]] + +TEST [[ local mt = {} function mt:<!x!>() end |