summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/searcher')
-rw-r--r--server-beta/src/searcher/eachRef.lua25
-rw-r--r--server-beta/src/searcher/getValue.lua2
-rw-r--r--server-beta/src/searcher/init.lua98
-rw-r--r--server-beta/src/searcher/special.lua0
4 files changed, 103 insertions, 22 deletions
diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua
index 970334bd..fedfdfd6 100644
--- a/server-beta/src/searcher/eachRef.lua
+++ b/server-beta/src/searcher/eachRef.lua
@@ -81,6 +81,31 @@ local function ofLocal(searcher, loc, callback)
if loc.value then
ofValue(searcher, loc.value, callback)
end
+ if loc.tag == '_ENV' then
+ for _, ref in ipairs(loc.ref) do
+ if ref.type == 'getlocal' then
+ local parent = ref.parent
+ if parent.type == 'getfield'
+ or parent.type == 'getindex' then
+ if guide.getKeyName(parent) == 's|_G' then
+ callback {
+ searcher = searcher,
+ source = parent,
+ mode = 'get',
+ }
+ end
+ end
+ elseif ref.type == 'getglobal' then
+ if guide.getKeyName(ref) == 's|_G' then
+ callback {
+ searcher = searcher,
+ source = ref,
+ mode = 'get',
+ }
+ end
+ end
+ end
+ end
end
local function checkField(key, info, callback)
diff --git a/server-beta/src/searcher/getValue.lua b/server-beta/src/searcher/getValue.lua
deleted file mode 100644
index 70e10bef..00000000
--- a/server-beta/src/searcher/getValue.lua
+++ /dev/null
@@ -1,2 +0,0 @@
-return function (searcher, source)
-end
diff --git a/server-beta/src/searcher/init.lua b/server-beta/src/searcher/init.lua
index 054067d7..4796be16 100644
--- a/server-beta/src/searcher/init.lua
+++ b/server-beta/src/searcher/init.lua
@@ -1,9 +1,8 @@
-local guide = require 'parser.guide'
-local files = require 'files'
-local util = require 'utility'
-local getValue = require 'searcher.getValue'
-local getField = require 'searcher.getField'
-local eachRef = require 'searcher.eachRef'
+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'
local setmetatable = setmetatable
@@ -36,17 +35,6 @@ function mt:lock(tp, source)
end)
end
---- 获取关联的值
----@param source table
----@return value table
-function mt:getValue(source)
- local lock <close> = self:lock('getValue', source)
- if not lock then
- return nil
- end
- return getValue(self, source)
-end
-
--- 获取关联的field
---@param source table
---@return table field
@@ -108,6 +96,75 @@ function mt:eachField(source, callback)
end)
end
+--- 获取特殊对象的名字
+function mt:getSpecialName(source)
+ local spName = self.cache.specialName[source]
+ if spName ~= nil then
+ if spName then
+ return spName
+ end
+ return nil
+ end
+ local function getName(info)
+ local src = info.source
+ if src.type == 'getglobal' then
+ local node = src.node
+ if node.tag ~= '_ENV' then
+ return nil
+ end
+ local name = guide.getKeyName(src)
+ if name:sub(1, 2) ~= 's|' then
+ return nil
+ end
+ spName = name:sub(3)
+ if not specials[spName] then
+ spName = nil
+ end
+ elseif src.type == 'local' then
+ if src.tag == '_ENV' then
+ spName = '_G'
+ end
+ elseif src.type == 'getlocal' then
+ local loc = src.loc
+ if loc.tag == '_ENV' then
+ spName = '_G'
+ end
+ end
+ end
+ self:eachRef(source, getName)
+ self.cache.specialName[source] = spName or false
+ return spName
+end
+
+--- 遍历特殊对象
+---@param callback fun(name:string, source:table)
+function mt:eachSpecial(callback)
+ local cache = self.cache.specials
+ if cache then
+ for i = 1, #cache do
+ callback(cache[i][1], cache[i][2])
+ end
+ return
+ end
+ cache = {}
+ self.cache.specials = cache
+ guide.eachSource(self.ast, function (source)
+ if source.type == 'getlocal'
+ or source.type == 'getglobal'
+ or source.type == 'local'
+ or source.type == 'field'
+ or source.type == 'string' then
+ local name = self:getSpecialName(source)
+ if name then
+ cache[#cache+1] = { name, source }
+ end
+ end
+ end)
+ for i = 1, #cache do
+ callback(cache[i][1], cache[i][2])
+ end
+end
+
---@class engineer
local m = {}
@@ -120,11 +177,12 @@ function m.create(uri)
ast = ast.ast,
uri = uri,
cache = {
- eachRef = {},
- eachField = {},
+ eachRef = {},
+ eachField = {},
+ specialName = {},
+ specials = nil,
},
locked = {
- getValue = {},
eachRef = {},
eachField = {},
}
diff --git a/server-beta/src/searcher/special.lua b/server-beta/src/searcher/special.lua
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/server-beta/src/searcher/special.lua