summaryrefslogtreecommitdiff
path: root/server-beta/src
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src')
-rw-r--r--server-beta/src/core/definition.lua8
-rw-r--r--server-beta/src/files.lua4
-rw-r--r--server-beta/src/seacher/methods.lua26
-rw-r--r--server-beta/src/seacher/setmetatable.lua48
-rw-r--r--server-beta/src/searcher/boolean.lua (renamed from server-beta/src/seacher/boolean.lua)17
-rw-r--r--server-beta/src/searcher/field.lua (renamed from server-beta/src/seacher/field.lua)14
-rw-r--r--server-beta/src/searcher/getfield.lua (renamed from server-beta/src/seacher/getfield.lua)31
-rw-r--r--server-beta/src/searcher/getglobal.lua (renamed from server-beta/src/seacher/getglobal.lua)82
-rw-r--r--server-beta/src/searcher/getlocal.lua (renamed from server-beta/src/seacher/getlocal.lua)0
-rw-r--r--server-beta/src/searcher/goto.lua (renamed from server-beta/src/seacher/goto.lua)5
-rw-r--r--server-beta/src/searcher/index.lua (renamed from server-beta/src/seacher/index.lua)0
-rw-r--r--server-beta/src/searcher/init.lua (renamed from server-beta/src/seacher/init.lua)68
-rw-r--r--server-beta/src/searcher/label.lua (renamed from server-beta/src/seacher/label.lua)0
-rw-r--r--server-beta/src/searcher/local.lua (renamed from server-beta/src/seacher/local.lua)81
-rw-r--r--server-beta/src/searcher/method.lua (renamed from server-beta/src/seacher/method.lua)12
-rw-r--r--server-beta/src/searcher/methods.lua26
-rw-r--r--server-beta/src/searcher/number.lua (renamed from server-beta/src/seacher/number.lua)17
-rw-r--r--server-beta/src/searcher/select.lua (renamed from server-beta/src/seacher/select.lua)6
-rw-r--r--server-beta/src/searcher/setmetatable.lua63
-rw-r--r--server-beta/src/searcher/string.lua (renamed from server-beta/src/seacher/string.lua)17
-rw-r--r--server-beta/src/searcher/table.lua (renamed from server-beta/src/seacher/table.lua)17
-rw-r--r--server-beta/src/searcher/tablefield.lua (renamed from server-beta/src/seacher/tablefield.lua)0
22 files changed, 344 insertions, 198 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua
index 01f2586b..91d8f499 100644
--- a/server-beta/src/core/definition.lua
+++ b/server-beta/src/core/definition.lua
@@ -3,7 +3,9 @@ local workspace = require 'workspace'
local files = require 'files'
local function findDef(searcher, source, callback)
- searcher:eachDef(source, function (src, uri)
+ searcher:eachDef(source, function (info)
+ local src = info.source
+ local uri = info.uri
if src.type == 'setfield'
or src.type == 'getfield'
or src.type == 'tablefield' then
@@ -70,11 +72,11 @@ return function (uri, offset)
}
}
end)
- findDef(searcher, source, function (src, uri)
+ findDef(searcher, source, function (target, uri)
results[#results+1] = {
+ target = target,
uri = uri,
source = source,
- target = src,
}
end)
end)
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua
index 67a13aa8..4a6c920f 100644
--- a/server-beta/src/files.lua
+++ b/server-beta/src/files.lua
@@ -150,8 +150,8 @@ function m.getSearcher(uri)
return nil
end
if not file.searcher then
- local seacher = require 'seacher'
- file.searcher = seacher.create(uri)
+ local searcher = require 'searcher'
+ file.searcher = searcher.create(uri)
end
return file.searcher
end
diff --git a/server-beta/src/seacher/methods.lua b/server-beta/src/seacher/methods.lua
deleted file mode 100644
index a23350bf..00000000
--- a/server-beta/src/seacher/methods.lua
+++ /dev/null
@@ -1,26 +0,0 @@
-local methods = {}
-
-methods['local'] = require 'seacher.local'
-methods['getlocal'] = require 'seacher.getlocal'
-methods['setlocal'] = methods['getlocal']
-methods['getglobal'] = require 'seacher.getglobal'
-methods['setglobal'] = methods['getglobal']
-methods['getfield'] = require 'seacher.getfield'
-methods['setfield'] = methods['getfield']
-methods['tablefield'] = require 'seacher.tablefield'
-methods['getmethod'] = methods['getfield']
-methods['setmethod'] = methods['getfield']
-methods['getindex'] = methods['getfield']
-methods['setindex'] = methods['getfield']
-methods['field'] = require 'seacher.field'
-methods['method'] = require 'seacher.method'
-methods['index'] = require 'seacher.index'
-methods['number'] = require 'seacher.number'
-methods['boolean'] = require 'seacher.boolean'
-methods['string'] = require 'seacher.string'
-methods['table'] = require 'seacher.table'
-methods['select'] = require 'seacher.select'
-methods['goto'] = require 'seacher.goto'
-methods['label'] = require 'seacher.label'
-
-return methods
diff --git a/server-beta/src/seacher/setmetatable.lua b/server-beta/src/seacher/setmetatable.lua
deleted file mode 100644
index 978d165c..00000000
--- a/server-beta/src/seacher/setmetatable.lua
+++ /dev/null
@@ -1,48 +0,0 @@
-local guide = require 'parser.guide'
-
-return function (self, key, used, found, callback)
- self:eachSpecial(function (name, src)
- local call = src.parent
- if name == 'rawset' then
- local t, k = self:callArgOf(call)
- if used[t] and guide.getKeyName(k) == key then
- callback(call, 'set')
- end
- elseif name == 'rawget' then
- local t, k, v = self:callArgOf(call)
- if used[t] and guide.getKeyName(k) == key then
- callback(call, 'get')
- self:eachField(v, key, callback)
- end
- elseif name == 'setmetatable' and not found then
- -- 如果已经找到值,则不检查meta表
- local t, mt = self:callArgOf(call)
- if mt then
- self:eachField(mt, 's|__index', function (src, mode)
- if mode == 'set' then
- -- t.field -> mt.__index.field
- if used[t] then
- self:eachValue(src, function (mtvalue)
- self:eachField(mtvalue, key, callback)
- end)
- end
- -- mt.__index.field -> t.field
- self:eachValue(src, function (src)
- if used[src] then
- self:eachValue(t, function (mtvalue)
- self:eachField(mtvalue, key, callback)
- end)
- local obj = self:callReturnOf(call)
- if obj then
- self:eachValue(obj, function (mtvalue)
- self:eachField(mtvalue, key, callback)
- end)
- end
- end
- end)
- end
- end)
- end
- end
- end)
-end
diff --git a/server-beta/src/seacher/boolean.lua b/server-beta/src/searcher/boolean.lua
index 3f36ee59..782b37ff 100644
--- a/server-beta/src/seacher/boolean.lua
+++ b/server-beta/src/searcher/boolean.lua
@@ -12,9 +12,9 @@ function m:eachDef(source, callback)
end
local node = parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, function (src, mode)
- if mode == 'set' then
- callback(src, mode)
+ self:eachField(node, key, function (info)
+ if info.mode == 'set' then
+ callback(info)
end
end)
end
@@ -29,15 +29,18 @@ function m:eachRef(source, callback)
end
local node = parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, function (src, mode)
- if mode == 'set' or mode == 'get' then
- callback(src, mode)
+ self:eachField(node, key, function (info)
+ if info.mode == 'set' or info.mode == 'get' then
+ callback(info)
end
end)
end
function m:eachValue(source, callback)
- callback(source)
+ callback {
+ uri = self.uri,
+ source = source,
+ }
end
return m
diff --git a/server-beta/src/seacher/field.lua b/server-beta/src/searcher/field.lua
index 72e8ab59..a9b01d25 100644
--- a/server-beta/src/seacher/field.lua
+++ b/server-beta/src/searcher/field.lua
@@ -1,14 +1,14 @@
local guide = require 'parser.guide'
-local checkSMT = require 'seacher.setmetatable'
+local checkSMT = require 'searcher.setmetatable'
local m = {}
function m:eachDef(source, callback)
local parent = source.parent
local key = guide.getKeyName(source)
- self:eachField(parent, key, function (src, mode)
- if mode == 'set' then
- callback(src, mode)
+ self:eachField(parent, key, function (info)
+ if info.mode == 'set' then
+ callback(info)
end
end)
end
@@ -16,9 +16,9 @@ end
function m:eachRef(source, callback)
local parent = source.parent
local key = guide.getKeyName(source)
- self:eachField(parent, key, function (src, mode)
- if mode == 'set' or mode == 'set' then
- callback(src, mode)
+ self:eachField(parent, key, function (info)
+ if info.mode == 'set' or info.mode == 'set' then
+ callback(info)
end
end)
end
diff --git a/server-beta/src/seacher/getfield.lua b/server-beta/src/searcher/getfield.lua
index 7b9ac263..f3c3df16 100644
--- a/server-beta/src/seacher/getfield.lua
+++ b/server-beta/src/searcher/getfield.lua
@@ -1,5 +1,5 @@
local guide = require 'parser.guide'
-local checkSMT = require 'seacher.setmetatable'
+local checkSMT = require 'searcher.setmetatable'
local m = {}
@@ -12,9 +12,9 @@ function m:eachRef(source, callback)
or node.type == 'setindex'
or node.type == 'getindex' then
local key = guide.getKeyName(node)
- self:eachField(node.node, key, function (src, mode)
- if mode == 'set' or mode == 'get' then
- callback(src, mode)
+ self:eachField(node.node, key, function (info)
+ if info.mode == 'set' or info.mode == 'get' then
+ callback(info)
end
end)
else
@@ -27,30 +27,39 @@ function m:eachField(source, key, callback)
local found = false
used[source] = true
- self:eachRef(source, function (src)
+ self:eachRef(source, function (info)
+ local src = info.source
used[src] = true
local child, mode, value = self:childMode(src)
if child then
if key == guide.getKeyName(child) then
- callback(child, mode)
+ callback {
+ uri = self.uri,
+ source = child,
+ mode = mode,
+ }
end
if value then
- self:eachField(value, key, callback)
+ info.searcher:eachField(value, key, callback)
end
return
end
if src.type == 'getglobal' then
local parent = src.parent
- child, mode = self:childMode(parent)
+ child, mode = info.searcher:childMode(parent)
if child then
if key == guide.getKeyName(child) then
- callback(child, mode)
+ callback {
+ uri = self.uri,
+ source = child,
+ mode = mode,
+ }
end
end
elseif src.type == 'setglobal' then
- self:eachField(src.value, key, callback)
+ info.searcher:eachField(src.value, key, callback)
else
- self:eachField(src, key, callback)
+ info.searcher:eachField(src, key, callback)
end
end)
diff --git a/server-beta/src/seacher/getglobal.lua b/server-beta/src/searcher/getglobal.lua
index a6bee129..c4fd10f1 100644
--- a/server-beta/src/seacher/getglobal.lua
+++ b/server-beta/src/searcher/getglobal.lua
@@ -1,27 +1,35 @@
local guide = require 'parser.guide'
-local checkSMT = require 'seacher.setmetatable'
+local checkSMT = require 'searcher.setmetatable'
local m = {}
function m:eachDef(source, callback)
-- _ENV
local key = guide.getKeyName(source)
- self:eachField(source.node, key, function (src, mode)
- if mode == 'set' then
- callback(src, mode)
+ self:eachField(source.node, key, function (info)
+ if info.mode == 'set' then
+ callback(info)
end
end)
self:eachSpecial(function (name, src)
if name == '_G' then
local parent = src.parent
if guide.getKeyName(parent) == key then
- callback(parent, 'set')
+ callback {
+ source = parent,
+ uri = self.uri,
+ mode = 'set',
+ }
end
elseif name == 'rawset' then
local t, k = self:callArgOf(src.parent)
if self:getSpecialName(t) == '_G'
and guide.getKeyName(k) == key then
- callback(src.parent, 'set')
+ callback {
+ source = src.parent,
+ uri = self.uri,
+ mode = 'set',
+ }
end
end
end)
@@ -30,9 +38,9 @@ end
function m:eachRef(source, callback)
-- _ENV
local key = guide.getKeyName(source)
- self:eachField(source.node, key, function (src, mode)
- if mode == 'set' or mode == 'get' then
- callback(src, mode)
+ self:eachField(source.node, key, function (info)
+ if info.mode == 'set' or info.mode == 'get' then
+ callback(info)
end
end)
self:eachSpecial(function (name, src)
@@ -40,22 +48,38 @@ function m:eachRef(source, callback)
local parent = src.parent
if guide.getKeyName(parent) == key then
if parent.type:sub(1, 3) == 'set' then
- callback(parent, 'set')
+ callback {
+ source = parent,
+ uri = self.uri,
+ mode = 'set',
+ }
else
- callback(parent, 'get')
+ callback {
+ source = parent,
+ uri = self.uri,
+ mode = 'get',
+ }
end
end
elseif name == 'rawset' then
local t, k = self:callArgOf(src.parent)
if self:getSpecialName(t) == '_G'
and guide.getKeyName(k) == key then
- callback(src.parent, 'set')
+ callback {
+ source = src.parent,
+ uri = self.uri,
+ mode = 'set',
+ }
end
elseif name == 'rawget' then
local t, k = self:callArgOf(src.parent)
if self:getSpecialName(t) == '_G'
and guide.getKeyName(k) == key then
- callback(src.parent, 'get')
+ callback {
+ source = src.parent,
+ uri = self.uri,
+ mode = 'set',
+ }
end
end
end)
@@ -66,33 +90,42 @@ function m:eachField(source, key, callback)
local found = false
used[source] = true
- self:eachRef(source, function (src)
+ self:eachRef(source, function (info)
+ local src = info.source
used[src] = true
- local child, mode, value = self:childMode(src)
+ local child, mode, value = info.searcher:childMode(src)
if child then
if key == guide.getKeyName(child) then
- callback(child, mode)
+ callback {
+ source = child,
+ uri = info.uri,
+ mode = mode,
+ }
end
if value then
- self:eachField(value, key, callback)
+ info.searcher:eachField(value, key, callback)
end
return
end
if src.type == 'getglobal' then
local parent = src.parent
- child, mode, value = self:childMode(parent)
+ child, mode, value = info.searcher:childMode(parent)
if child then
if key == guide.getKeyName(child) then
- callback(child, mode)
+ callback {
+ source = child,
+ uri = info.uri,
+ mode = mode,
+ }
end
if value then
- self:eachField(value, key, callback)
+ info.searcher:eachField(value, key, callback)
end
end
elseif src.type == 'setglobal' then
- self:eachField(src.value, key, callback)
+ info.searcher:eachField(src.value, key, callback)
else
- self:eachField(src, key, callback)
+ info.searcher:eachField(src, key, callback)
end
end)
@@ -100,7 +133,10 @@ function m:eachField(source, key, callback)
end
function m:eachValue(source, callback)
- callback(source)
+ callback {
+ source = source,
+ uri = self.uri,
+ }
if source.value then
self:eachValue(source.value, callback)
end
diff --git a/server-beta/src/seacher/getlocal.lua b/server-beta/src/searcher/getlocal.lua
index ca4e58c3..ca4e58c3 100644
--- a/server-beta/src/seacher/getlocal.lua
+++ b/server-beta/src/searcher/getlocal.lua
diff --git a/server-beta/src/seacher/goto.lua b/server-beta/src/searcher/goto.lua
index 36f373d2..8698eef1 100644
--- a/server-beta/src/seacher/goto.lua
+++ b/server-beta/src/searcher/goto.lua
@@ -6,7 +6,10 @@ function m:eachDef(source, callback)
local name = source[1]
local label = guide.getLabel(source, name)
if label then
- callback(label)
+ callback {
+ source = label,
+ uri = self.uri,
+ }
end
end
diff --git a/server-beta/src/seacher/index.lua b/server-beta/src/searcher/index.lua
index f96c2dcf..f96c2dcf 100644
--- a/server-beta/src/seacher/index.lua
+++ b/server-beta/src/searcher/index.lua
diff --git a/server-beta/src/seacher/init.lua b/server-beta/src/searcher/init.lua
index 5584c83f..a56d9a22 100644
--- a/server-beta/src/seacher/init.lua
+++ b/server-beta/src/searcher/init.lua
@@ -1,9 +1,10 @@
local guide = require 'parser.guide'
local files = require 'files'
-local methods = require 'seacher.methods'
+local methods = require 'searcher.methods'
local tableUnpack = table.unpack
local error = error
local setmetatable = setmetatable
+local assert = assert
_ENV = nil
local specials = {
@@ -16,10 +17,10 @@ local specials = {
['loadfile'] = true,
}
----@class seacher
+---@class searcher
local mt = {}
mt.__index = mt
-mt.__name = 'seacher'
+mt.__name = 'searcher'
--- 获取特殊对象的名字
function mt:getSpecialName(source)
@@ -30,7 +31,8 @@ function mt:getSpecialName(source)
end
return nil
end
- local function getName(src)
+ local function getName(info)
+ local src = info.source
if src.type == 'getglobal' then
local node = src.node
if node.tag ~= '_ENV' then
@@ -92,12 +94,12 @@ end
--- 遍历元素
---@param source table
---@param key string
----@param callback fun(field:table, mode:string)
+---@param callback fun(info:table)
function mt:eachField(source, key, callback)
local cache = self.cache.field[source]
if cache and cache[key] then
for i = 1, #cache[key] do
- callback(tableUnpack(cache[key][i]))
+ callback(cache[key][i])
end
return
end
@@ -121,27 +123,31 @@ function mt:eachField(source, key, callback)
self.cache.field[source] = cache
end
cache[key] = {}
- f(self, source, key, function (src, ...)
+ f(self, source, key, function (info)
+ local src = info.source
+ local uri = info.uri
+ assert(src and uri)
if mark[src] then
return
end
mark[src] = true
- cache[key][#cache[key]+1] = { src, ... }
+ info.searcher = files.getSearcher(uri)
+ cache[key][#cache[key]+1] = info
end)
for i = 1, #cache[key] do
- callback(tableUnpack(cache[key][i]))
+ callback(cache[key][i])
end
self.step = self.step - 1
end
--- 遍历引用
---@param source table
----@param callback fun(def:table, mode:string)
+---@param callback fun(info:table)
function mt:eachRef(source, callback)
local cache = self.cache.ref[source]
if cache then
for i = 1, #cache do
- callback(tableUnpack(cache[i]))
+ callback(cache[i])
end
return
end
@@ -162,27 +168,31 @@ function mt:eachRef(source, callback)
cache = {}
self.cache.ref[source] = cache
local mark = {}
- f(self, source, function (src, ...)
+ f(self, source, function (info)
+ local src = info.source
+ local uri = info.uri
+ assert(src and uri)
if mark[src] then
return
end
mark[src] = true
- cache[#cache+1] = {src, ...}
+ info.searcher = files.getSearcher(uri)
+ cache[#cache+1] = info
end)
for i = 1, #cache do
- callback(tableUnpack(cache[i]))
+ callback(cache[i])
end
self.step = self.step - 1
end
--- 遍历定义
---@param source table
----@param callback fun(def:table, mode:string)
+---@param callback fun(info:table)
function mt:eachDef(source, callback)
local cache = self.cache.def[source]
if cache then
for i = 1, #cache do
- callback(tableUnpack(cache[i]))
+ callback(cache[i])
end
return
end
@@ -203,27 +213,31 @@ function mt:eachDef(source, callback)
cache = {}
self.cache.def[source] = cache
local mark = {}
- f(self, source, function (src, ...)
+ f(self, source, function (info)
+ local src = info.source
+ local uri = info.uri
+ assert(src and uri)
if mark[src] then
return
end
mark[src] = true
- cache[#cache+1] = {src, ...}
+ info.searcher = files.getSearcher(uri)
+ cache[#cache+1] = info
end)
for i = 1, #cache do
- callback(tableUnpack(cache[i]))
+ callback(cache[i])
end
self.step = self.step - 1
end
--- 遍历value
---@param source table
----@param callback fun(value:table)
+---@param callback fun(info:table)
function mt:eachValue(source, callback)
local cache = self.cache.value[source]
if cache then
for i = 1, #cache do
- callback(tableUnpack(cache[i]))
+ callback(cache[i])
end
return
end
@@ -244,15 +258,19 @@ function mt:eachValue(source, callback)
cache = {}
self.cache.value[source] = cache
local mark = {}
- f(self, source, function (src, ...)
+ f(self, source, function (info)
+ local src = info.source
+ local uri = info.uri
+ assert(src and uri)
if mark[src] then
return
end
mark[src] = true
- cache[#cache+1] = {src, ...}
+ info.searcher = files.getSearcher(uri)
+ cache[#cache+1] = info
end)
for i = 1, #cache do
- callback(tableUnpack(cache[i]))
+ callback(cache[i])
end
self.step = self.step - 1
end
@@ -324,7 +342,7 @@ local m = {}
--- 新建搜索器
---@param uri string
----@return seacher
+---@return searcher
function m.create(uri)
local ast = files.getAst(uri)
local searcher = setmetatable({
diff --git a/server-beta/src/seacher/label.lua b/server-beta/src/searcher/label.lua
index f05a57e6..f05a57e6 100644
--- a/server-beta/src/seacher/label.lua
+++ b/server-beta/src/searcher/label.lua
diff --git a/server-beta/src/seacher/local.lua b/server-beta/src/searcher/local.lua
index 302d49da..398a9387 100644
--- a/server-beta/src/seacher/local.lua
+++ b/server-beta/src/searcher/local.lua
@@ -1,16 +1,24 @@
local guide = require 'parser.guide'
-local checkSMT = require 'seacher.setmetatable'
+local checkSMT = require 'searcher.setmetatable'
local m = {}
function m:eachDef(source, callback)
if source.tag ~= 'self' then
- callback(source, 'local')
+ callback {
+ source = source,
+ uri = self.uri,
+ mode = 'local',
+ }
end
if source.ref then
for _, ref in ipairs(source.ref) do
if ref.type == 'setlocal' then
- callback(ref, 'set')
+ callback {
+ source = ref,
+ uri = self.uri,
+ mode = 'set',
+ }
end
end
end
@@ -23,14 +31,26 @@ end
function m:eachRef(source, callback)
if source.tag ~= 'self' then
- callback(source, 'local')
+ callback {
+ source = source,
+ uri = self.uri,
+ mode = 'local',
+ }
end
if source.ref then
for _, ref in ipairs(source.ref) do
if ref.type == 'setlocal' then
- callback(ref, 'set')
+ callback {
+ source = ref,
+ uri = self.uri,
+ mode = 'set',
+ }
elseif ref.type == 'getlocal' then
- callback(ref, 'get')
+ callback {
+ source = ref,
+ uri = self.uri,
+ mode = 'get',
+ }
end
end
end
@@ -54,23 +74,39 @@ function m:eachField(source, key, callback)
local parent = ref.parent
if key == guide.getKeyName(parent) then
if parent.type:sub(1, 3) == 'set' then
- callback(parent, 'set')
+ callback {
+ source = parent,
+ uri = self.uri,
+ mode = 'set',
+ }
found = true
else
- callback(parent, 'get')
+ callback {
+ source = parent,
+ uri = self.uri,
+ mode = 'get',
+ }
end
end
elseif ref.type == 'getglobal' then
used[ref] = true
if key == guide.getKeyName(ref) then
-- _ENV.XXX
- callback(ref, 'get')
+ callback {
+ source = ref,
+ uri = self.uri,
+ mode = 'get',
+ }
end
elseif ref.type == 'setglobal' then
used[ref] = true
-- _ENV.XXX = XXX
if key == guide.getKeyName(ref) then
- callback(ref, 'set')
+ callback {
+ source = ref,
+ uri = self.uri,
+ mode = 'set',
+ }
found = true
end
end
@@ -79,18 +115,19 @@ function m:eachField(source, key, callback)
if source.tag == 'self' then
local method = source.method
local node = method.node
- self:eachField(node, key, function (src, mode)
- callback(src, mode)
- if mode == 'set' then
+ self:eachField(node, key, function (info)
+ callback(info)
+ if info.mode == 'set' then
found = true
end
end)
end
- self:eachValue(source, function (src)
+ self:eachValue(source, function (info)
+ local src = info.source
if source ~= src then
- self:eachField(src, key, function (src, mode)
- callback(src, mode)
- if mode == 'set' then
+ info.searcher:eachField(src, key, function (info)
+ callback(info)
+ if info.mode == 'set' then
found = true
end
end)
@@ -100,7 +137,10 @@ function m:eachField(source, key, callback)
end
function m:eachValue(source, callback)
- callback(source)
+ callback {
+ source = source,
+ uri = self.uri,
+ }
local refs = source.ref
if refs then
for i = 1, #refs do
@@ -112,7 +152,10 @@ function m:eachValue(source, callback)
if parent.type == 'setmethod' then
local func = parent.value
if func and func.locals then
- callback(func.locals[1])
+ callback {
+ source = func.locals[1],
+ uri = self.uri,
+ }
end
end
end
diff --git a/server-beta/src/seacher/method.lua b/server-beta/src/searcher/method.lua
index 52c00358..cc7736a3 100644
--- a/server-beta/src/seacher/method.lua
+++ b/server-beta/src/searcher/method.lua
@@ -5,9 +5,9 @@ local m = {}
function m:eachDef(source, callback)
local node = source.parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, function (src, mode)
- if mode == 'set' then
- callback(src, mode)
+ self:eachField(node, key, function (info)
+ if info.mode == 'set' then
+ callback(info)
end
end)
end
@@ -15,9 +15,9 @@ end
function m:eachRef(source, callback)
local node = source.parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, function (src, mode)
- if mode == 'set' or mode == 'get' then
- callback(src, mode)
+ self:eachField(node, key, function (info)
+ if info.mode == 'set' or info.mode == 'get' then
+ callback(info)
end
end)
end
diff --git a/server-beta/src/searcher/methods.lua b/server-beta/src/searcher/methods.lua
new file mode 100644
index 00000000..498978dd
--- /dev/null
+++ b/server-beta/src/searcher/methods.lua
@@ -0,0 +1,26 @@
+local methods = {}
+
+methods['local'] = require 'searcher.local'
+methods['getlocal'] = require 'searcher.getlocal'
+methods['setlocal'] = methods['getlocal']
+methods['getglobal'] = require 'searcher.getglobal'
+methods['setglobal'] = methods['getglobal']
+methods['getfield'] = require 'searcher.getfield'
+methods['setfield'] = methods['getfield']
+methods['tablefield'] = require 'searcher.tablefield'
+methods['getmethod'] = methods['getfield']
+methods['setmethod'] = methods['getfield']
+methods['getindex'] = methods['getfield']
+methods['setindex'] = methods['getfield']
+methods['field'] = require 'searcher.field'
+methods['method'] = require 'searcher.method'
+methods['index'] = require 'searcher.index'
+methods['number'] = require 'searcher.number'
+methods['boolean'] = require 'searcher.boolean'
+methods['string'] = require 'searcher.string'
+methods['table'] = require 'searcher.table'
+methods['select'] = require 'searcher.select'
+methods['goto'] = require 'searcher.goto'
+methods['label'] = require 'searcher.label'
+
+return methods
diff --git a/server-beta/src/seacher/number.lua b/server-beta/src/searcher/number.lua
index 3f36ee59..43f838f6 100644
--- a/server-beta/src/seacher/number.lua
+++ b/server-beta/src/searcher/number.lua
@@ -12,9 +12,9 @@ function m:eachDef(source, callback)
end
local node = parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, function (src, mode)
- if mode == 'set' then
- callback(src, mode)
+ self:eachField(node, key, function (info)
+ if info.mode == 'set' then
+ callback(info)
end
end)
end
@@ -29,15 +29,18 @@ function m:eachRef(source, callback)
end
local node = parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, function (src, mode)
- if mode == 'set' or mode == 'get' then
- callback(src, mode)
+ self:eachField(node, key, function (info)
+ if info.mode == 'set' or info.mode == 'get' then
+ callback(info)
end
end)
end
function m:eachValue(source, callback)
- callback(source)
+ callback {
+ source = source,
+ uri = self.uri,
+ }
end
return m
diff --git a/server-beta/src/seacher/select.lua b/server-beta/src/searcher/select.lua
index bbdf1234..77480dc7 100644
--- a/server-beta/src/seacher/select.lua
+++ b/server-beta/src/searcher/select.lua
@@ -9,9 +9,9 @@ function m:eachValue(source, callback)
if self:getSpecialName(func) == 'setmetatable' then
local t, mt = self:callArgOf(vararg)
self:eachValue(t, callback)
- self:eachField(mt, 's|__index', function (src, mode)
- if mode == 'set' then
- self:eachValue(src, callback)
+ self:eachField(mt, 's|__index', function (info)
+ if info.mode == 'set' then
+ info.searcher:eachValue(info.source, callback)
end
end)
end
diff --git a/server-beta/src/searcher/setmetatable.lua b/server-beta/src/searcher/setmetatable.lua
new file mode 100644
index 00000000..7489bf6f
--- /dev/null
+++ b/server-beta/src/searcher/setmetatable.lua
@@ -0,0 +1,63 @@
+local guide = require 'parser.guide'
+
+local function checkIndex(info, key, t, used, call, callback)
+ if info.mode ~= 'set' then
+ return
+ end
+ local src = info.source
+ -- t.field -> mt.__index.field
+ if used[t] then
+ info.searcher:eachValue(src, function (info)
+ info.searcher:eachField(info.source, key, callback)
+ end)
+ end
+ -- mt.__index.field -> t.field
+ info.searcher:eachValue(src, function (info)
+ local value = info.source
+ if used[value] then
+ info.searcher:eachValue(t, function (info)
+ info.searcher:eachField(info.source, key, callback)
+ end)
+ local obj = info.searcher:callReturnOf(call)
+ if obj then
+ info.searcher:eachValue(obj, function (info)
+ info.searcher:eachField(info.source, key, callback)
+ end)
+ end
+ end
+ end)
+end
+
+return function (self, key, used, found, callback)
+ self:eachSpecial(function (name, src)
+ local call = src.parent
+ if name == 'rawset' then
+ local t, k = self:callArgOf(call)
+ if used[t] and guide.getKeyName(k) == key then
+ callback {
+ source = call,
+ uri = self.uri,
+ mode = 'set',
+ }
+ end
+ elseif name == 'rawget' then
+ local t, k, v = self:callArgOf(call)
+ if used[t] and guide.getKeyName(k) == key then
+ callback {
+ source = call,
+ uri = self.uri,
+ mode = 'get',
+ }
+ self:eachField(v, key, callback)
+ end
+ elseif name == 'setmetatable' and not found then
+ -- 如果已经找到值,则不检查meta表
+ local t, mt = self:callArgOf(call)
+ if mt then
+ self:eachField(mt, 's|__index', function (info)
+ checkIndex(info, key, t, used, call, callback)
+ end)
+ end
+ end
+ end)
+end
diff --git a/server-beta/src/seacher/string.lua b/server-beta/src/searcher/string.lua
index 3f36ee59..43f838f6 100644
--- a/server-beta/src/seacher/string.lua
+++ b/server-beta/src/searcher/string.lua
@@ -12,9 +12,9 @@ function m:eachDef(source, callback)
end
local node = parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, function (src, mode)
- if mode == 'set' then
- callback(src, mode)
+ self:eachField(node, key, function (info)
+ if info.mode == 'set' then
+ callback(info)
end
end)
end
@@ -29,15 +29,18 @@ function m:eachRef(source, callback)
end
local node = parent.node
local key = guide.getKeyName(source)
- self:eachField(node, key, function (src, mode)
- if mode == 'set' or mode == 'get' then
- callback(src, mode)
+ self:eachField(node, key, function (info)
+ if info.mode == 'set' or info.mode == 'get' then
+ callback(info)
end
end)
end
function m:eachValue(source, callback)
- callback(source)
+ callback {
+ source = source,
+ uri = self.uri,
+ }
end
return m
diff --git a/server-beta/src/seacher/table.lua b/server-beta/src/searcher/table.lua
index 851ee791..26c499ed 100644
--- a/server-beta/src/seacher/table.lua
+++ b/server-beta/src/searcher/table.lua
@@ -7,16 +7,27 @@ function m:eachField(source, key, callback)
local src = source[i]
if key == guide.getKeyName(src) then
if src.type == 'tablefield' then
- callback(src, 'set')
+ callback {
+ source = src,
+ uri = self.uri,
+ mode = 'set',
+ }
elseif src.type == 'tableindex' then
- callback(src, 'set')
+ callback {
+ source = src,
+ uri = self.uri,
+ mode = 'set',
+ }
end
end
end
end
function m:eachValue(source, callback)
- callback(source)
+ callback {
+ source = source,
+ uri = self.uri,
+ }
end
return m
diff --git a/server-beta/src/seacher/tablefield.lua b/server-beta/src/searcher/tablefield.lua
index 219828d4..219828d4 100644
--- a/server-beta/src/seacher/tablefield.lua
+++ b/server-beta/src/searcher/tablefield.lua