summaryrefslogtreecommitdiff
path: root/server-beta/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-20 11:00:32 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-20 11:00:32 +0800
commit03a56a63e1c943e985b73082be34749a3bd5533b (patch)
tree543dcf81e70b0ff429dcd7415f811ae803f994ab /server-beta/src
parent2c90cf1b7b1fce9095f95bc54ed33680c848bfbe (diff)
downloadlua-language-server-03a56a63e1c943e985b73082be34749a3bd5533b.zip
searcher太难拼了,我们还是叫vm吧
Diffstat (limited to 'server-beta/src')
-rw-r--r--server-beta/src/core/definition.lua4
-rw-r--r--server-beta/src/core/diagnostics/global-in-nil-env.lua1
-rw-r--r--server-beta/src/core/diagnostics/redundant-parameter.lua16
-rw-r--r--server-beta/src/core/diagnostics/undefined-env-child.lua10
-rw-r--r--server-beta/src/core/diagnostics/undefined-global.lua14
-rw-r--r--server-beta/src/core/diagnostics/unused-function.lua14
-rw-r--r--server-beta/src/core/highlight.lua14
-rw-r--r--server-beta/src/core/reference.lua8
-rw-r--r--server-beta/src/core/rename.lua26
-rw-r--r--server-beta/src/files.lua26
-rw-r--r--server-beta/src/searcher/getGlobal.lua6
-rw-r--r--server-beta/src/searcher/init.lua10
-rw-r--r--server-beta/src/service/service.lua14
-rw-r--r--server-beta/src/vm/eachDef.lua (renamed from server-beta/src/searcher/eachDef.lua)10
-rw-r--r--server-beta/src/vm/eachField.lua (renamed from server-beta/src/searcher/eachField.lua)20
-rw-r--r--server-beta/src/vm/eachRef.lua (renamed from server-beta/src/searcher/eachRef.lua)73
-rw-r--r--server-beta/src/vm/getGlobal.lua6
-rw-r--r--server-beta/src/vm/getGlobals.lua (renamed from server-beta/src/searcher/getGlobals.lua)14
-rw-r--r--server-beta/src/vm/getLibrary.lua (renamed from server-beta/src/searcher/getLibrary.lua)20
-rw-r--r--server-beta/src/vm/getLinks.lua (renamed from server-beta/src/searcher/getLinks.lua)12
-rw-r--r--server-beta/src/vm/getValue.lua (renamed from server-beta/src/searcher/getValue.lua)80
-rw-r--r--server-beta/src/vm/init.lua10
-rw-r--r--server-beta/src/vm/special.lua (renamed from server-beta/src/searcher/special.lua)0
-rw-r--r--server-beta/src/vm/vm.lua (renamed from server-beta/src/searcher/searcher.lua)2
24 files changed, 203 insertions, 207 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua
index a7008926..865fc7cb 100644
--- a/server-beta/src/core/definition.lua
+++ b/server-beta/src/core/definition.lua
@@ -1,7 +1,7 @@
local guide = require 'parser.guide'
local workspace = require 'workspace'
local files = require 'files'
-local searcher = require 'searcher'
+local vm = require 'vm'
local function findDef(source, callback)
if source.type ~= 'local'
@@ -17,7 +17,7 @@ local function findDef(source, callback)
and source.type ~= 'goto' then
return
end
- searcher.eachDef(source, function (info)
+ vm.eachDef(source, function (info)
if info.mode == 'declare'
or info.mode == 'set'
or info.mode == 'return' then
diff --git a/server-beta/src/core/diagnostics/global-in-nil-env.lua b/server-beta/src/core/diagnostics/global-in-nil-env.lua
index d8cc0075..9a0d4f35 100644
--- a/server-beta/src/core/diagnostics/global-in-nil-env.lua
+++ b/server-beta/src/core/diagnostics/global-in-nil-env.lua
@@ -1,6 +1,5 @@
local files = require 'files'
local guide = require 'parser.guide'
-local searcher = require 'searcher'
local lang = require 'language'
-- TODO: 检查路径是否可达
diff --git a/server-beta/src/core/diagnostics/redundant-parameter.lua b/server-beta/src/core/diagnostics/redundant-parameter.lua
index a60c8cdb..ec14188e 100644
--- a/server-beta/src/core/diagnostics/redundant-parameter.lua
+++ b/server-beta/src/core/diagnostics/redundant-parameter.lua
@@ -1,12 +1,12 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local searcher = require 'searcher'
-local lang = require 'language'
-local define = require 'proto.define'
-local await = require 'await'
+local files = require 'files'
+local guide = require 'parser.guide'
+local vm = require 'vm'
+local lang = require 'language'
+local define = require 'proto.define'
+local await = require 'await'
local function countLibraryArgs(source)
- local func = searcher.getLibrary(source)
+ local func = vm.getLibrary(source)
if not func then
return nil
end
@@ -66,7 +66,7 @@ return function (uri, callback)
local func = source.node
local funcArgs
- searcher.eachDef(func, function (info)
+ vm.eachDef(func, function (info)
if info.mode == 'value' then
local src = info.source
if src.type == 'function' then
diff --git a/server-beta/src/core/diagnostics/undefined-env-child.lua b/server-beta/src/core/diagnostics/undefined-env-child.lua
index 4169a413..df096cb8 100644
--- a/server-beta/src/core/diagnostics/undefined-env-child.lua
+++ b/server-beta/src/core/diagnostics/undefined-env-child.lua
@@ -1,7 +1,7 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local searcher = require 'searcher'
-local lang = require 'language'
+local files = require 'files'
+local guide = require 'parser.guide'
+local vm = require 'vm'
+local lang = require 'language'
return function (uri, callback)
local ast = files.getAst(uri)
@@ -14,7 +14,7 @@ return function (uri, callback)
if source.node.tag == '_ENV' then
return
end
- local setInENV = searcher.eachRef(source, function (info)
+ local setInENV = vm.eachRef(source, function (info)
if info.mode == 'set' then
return true
end
diff --git a/server-beta/src/core/diagnostics/undefined-global.lua b/server-beta/src/core/diagnostics/undefined-global.lua
index c3fbccbf..ed81ced3 100644
--- a/server-beta/src/core/diagnostics/undefined-global.lua
+++ b/server-beta/src/core/diagnostics/undefined-global.lua
@@ -1,8 +1,8 @@
-local files = require 'files'
-local searcher = require 'searcher'
-local lang = require 'language'
-local library = require 'library'
-local config = require 'config'
+local files = require 'files'
+local vm = require 'vm'
+local lang = require 'language'
+local library = require 'library'
+local config = require 'config'
return function (uri, callback)
local ast = files.getAst(uri)
@@ -13,7 +13,7 @@ return function (uri, callback)
local globalCache = {}
-- 遍历全局变量,检查所有没有 mode['set'] 的全局变量
- local globals = searcher.getGlobals(ast.ast)
+ local globals = vm.getGlobals(ast.ast)
for key, infos in pairs(globals) do
if infos.mode['set'] == true then
goto CONTINUE
@@ -35,7 +35,7 @@ return function (uri, callback)
local uris = files.findGlobals(key)
for i = 1, #uris do
local destAst = files.getAst(uris[i])
- local destGlobals = searcher.getGlobals(destAst.ast)
+ local destGlobals = vm.getGlobals(destAst.ast)
if destGlobals[key] and destGlobals[key].mode['set'] then
globalCache[key] = true
goto CONTINUE
diff --git a/server-beta/src/core/diagnostics/unused-function.lua b/server-beta/src/core/diagnostics/unused-function.lua
index ca3a751d..6c53cdf7 100644
--- a/server-beta/src/core/diagnostics/unused-function.lua
+++ b/server-beta/src/core/diagnostics/unused-function.lua
@@ -1,9 +1,9 @@
-local files = require 'files'
-local guide = require 'parser.guide'
-local searcher = require 'searcher'
-local define = require 'proto.define'
-local lang = require 'language'
-local await = require 'await'
+local files = require 'files'
+local guide = require 'parser.guide'
+local vm = require 'vm'
+local define = require 'proto.define'
+local lang = require 'language'
+local await = require 'await'
return function (uri, callback)
local ast = files.getAst(uri)
@@ -22,7 +22,7 @@ return function (uri, callback)
return
end
local hasSet
- local hasGet = searcher.eachRef(source, function (info)
+ local hasGet = vm.eachRef(source, function (info)
if info.mode == 'get' then
return true
elseif info.mode == 'set'
diff --git a/server-beta/src/core/highlight.lua b/server-beta/src/core/highlight.lua
index 7ae5333a..61e3f91a 100644
--- a/server-beta/src/core/highlight.lua
+++ b/server-beta/src/core/highlight.lua
@@ -1,7 +1,7 @@
-local guide = require 'parser.guide'
-local files = require 'files'
-local searcher = require 'searcher'
-local define = require 'proto.define'
+local guide = require 'parser.guide'
+local files = require 'files'
+local vm = require 'vm'
+local define = require 'proto.define'
local function ofLocal(source, callback)
callback(source)
@@ -21,7 +21,7 @@ local function ofField(source, uri, callback)
if parent.type == 'tableindex'
or parent.type == 'tablefield' then
local tbl = parent.parent
- searcher.eachField(tbl, function (info)
+ vm.eachField(tbl, function (info)
if info.key ~= myKey then
return
end
@@ -32,7 +32,7 @@ local function ofField(source, uri, callback)
callback(info.source)
end)
else
- searcher.eachField(parent.node, function (info)
+ vm.eachField(parent.node, function (info)
if info.key ~= myKey then
return
end
@@ -58,7 +58,7 @@ local function ofIndex(source, uri, callback)
end
local function ofLabel(source, callback)
- searcher.eachRef(source, function (info)
+ vm.eachRef(source, function (info)
callback(info.source)
end)
end
diff --git a/server-beta/src/core/reference.lua b/server-beta/src/core/reference.lua
index 9ffd8fe0..7e265e97 100644
--- a/server-beta/src/core/reference.lua
+++ b/server-beta/src/core/reference.lua
@@ -1,6 +1,6 @@
-local guide = require 'parser.guide'
-local files = require 'files'
-local searcher = require 'searcher'
+local guide = require 'parser.guide'
+local files = require 'files'
+local vm = require 'vm'
local function isFunction(source, offset)
if source.type ~= 'function' then
@@ -27,7 +27,7 @@ local function findRef(source, offset, callback)
and not isFunction(source, offset) then
return
end
- searcher.eachRef(source, function (info)
+ vm.eachRef(source, function (info)
if info.mode == 'declare'
or info.mode == 'set'
or info.mode == 'get'
diff --git a/server-beta/src/core/rename.lua b/server-beta/src/core/rename.lua
index 6f4f26e6..4c67bc9c 100644
--- a/server-beta/src/core/rename.lua
+++ b/server-beta/src/core/rename.lua
@@ -1,9 +1,9 @@
-local files = require 'files'
-local searcher = require 'searcher'
-local guide = require 'parser.guide'
-local proto = require 'proto'
-local define = require 'proto.define'
-local util = require 'utility'
+local files = require 'files'
+local vm = require 'vm'
+local guide = require 'parser.guide'
+local proto = require 'proto'
+local define = require 'proto.define'
+local util = require 'utility'
local Forcing
@@ -127,10 +127,10 @@ local function renameField(source, newname, callback)
if parent.type == 'setfield'
or parent.type == 'getfield' then
local dot = parent.dot
- local newstr = '[' .. util.vieString('"', newname) .. ']'
+ local newstr = '[' .. util.viewString('"', newname) .. ']'
callback(source, dot.start, source.finish, newstr)
elseif parent.type == 'tablefield' then
- local newstr = '[' .. util.vieString('"', newname) .. ']'
+ local newstr = '[' .. util.viewString('"', newname) .. ']'
callback(source, source.start, source.finish, newstr)
elseif parent.type == 'getmethod' then
if not askForcing(newname) then
@@ -144,7 +144,7 @@ local function renameField(source, newname, callback)
-- function mt:name () end --> mt['newname'] = function (self) end
local newstr = string.format('%s[%s] = function '
, text:sub(parent.start, parent.node.finish)
- , util.vieString('"', newname)
+ , util.viewString('"', newname)
)
callback(source, func.start, parent.finish, newstr)
local pl = text:find('(', parent.finish, true)
@@ -164,7 +164,7 @@ local function renameGlobal(source, newname, callback)
callback(source, source.start, source.finish, newname)
return true
end
- local newstr = '_ENV[' .. util.vieString('"', newname) .. ']'
+ local newstr = '_ENV[' .. util.viewString('"', newname) .. ']'
-- function name () end --> _ENV['newname'] = function () end
if source.value and source.value.type == 'function'
and source.value.start < source.start then
@@ -176,7 +176,7 @@ local function renameGlobal(source, newname, callback)
end
local function ofField(source, newname, callback)
- return searcher.eachRef(source, function (info)
+ return vm.eachRef(source, function (info)
local src = info.source
if src.type == 'tablefield'
or src.type == 'getfield'
@@ -192,7 +192,7 @@ local function ofField(source, newname, callback)
end
if src.type == 'string' then
local quo = src[2]
- local text = util.vieString(quo, newname)
+ local text = util.viewString(quo, newname)
callback(src, src.start, src.finish, text)
return
elseif src.type == 'field'
@@ -217,7 +217,7 @@ local function rename(source, newname, callback)
if not isValidName(newname) and not askForcing(newname)then
return false
end
- searcher.eachRef(source, function (info)
+ vm.eachRef(source, function (info)
callback(info.source, info.source.start, info.source.finish, newname)
end)
elseif source.type == 'local' then
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua
index 34c8c2de..34cba439 100644
--- a/server-beta/src/files.lua
+++ b/server-beta/src/files.lua
@@ -1,10 +1,10 @@
-local platform = require 'bee.platform'
-local config = require 'config'
-local glob = require 'glob'
-local furi = require 'file-uri'
-local parser = require 'parser'
-local searcher = require 'searcher.searcher'
-local guide = require 'parser.guide'
+local platform = require 'bee.platform'
+local config = require 'config'
+local glob = require 'glob'
+local furi = require 'file-uri'
+local parser = require 'parser'
+local vm = require 'vm.vm'
+local guide = require 'parser.guide'
local m = {}
@@ -69,13 +69,13 @@ function m.setText(uri, text)
return
end
file.text = text
- file.searcher = nil
+ file.vm = nil
file.lines = nil
file.ast = nil
file.globals = nil
file.links = nil
m.globalVersion = m.globalVersion + 1
- searcher.refreshCache()
+ vm.refreshCache()
local diagnostic = require 'provider.diagnostic'
diagnostic.refresh(originUri)
@@ -123,7 +123,7 @@ function m.remove(uri)
m.fileMap[uri] = nil
m.globalVersion = m.globalVersion + 1
- searcher.refreshCache()
+ vm.refreshCache()
local diagnostic = require 'service.diagnostic'
diagnostic.refresh(file.uri)
@@ -135,7 +135,7 @@ function m.removeAll()
m.fileMap[uri] = nil
end
m.globalVersion = m.globalVersion + 1
- searcher.refreshCache()
+ vm.refreshCache()
end
--- 遍历文件
@@ -225,7 +225,7 @@ function m.findGlobals(name)
file.globals = {}
local ast = m.getAst(uri)
if ast then
- local globals = searcher.getGlobals(ast.ast)
+ local globals = vm.getGlobals(ast.ast)
for name in pairs(globals) do
file.globals[name] = true
end
@@ -248,7 +248,7 @@ function m.findLinkTo(uri)
if file.links == nil then
local ast = m.getAst(file.uri)
if ast then
- file.links = searcher.getLinks(ast.ast)
+ file.links = vm.getLinks(ast.ast)
else
file.links = false
end
diff --git a/server-beta/src/searcher/getGlobal.lua b/server-beta/src/searcher/getGlobal.lua
deleted file mode 100644
index 226f2473..00000000
--- a/server-beta/src/searcher/getGlobal.lua
+++ /dev/null
@@ -1,6 +0,0 @@
-local searcher = require 'searcher.searcher'
-
-function searcher.getGlobal(source)
- searcher.getGlobals(source)
- return searcher.cache.getGlobal[source]
-end
diff --git a/server-beta/src/searcher/init.lua b/server-beta/src/searcher/init.lua
deleted file mode 100644
index 65753ccd..00000000
--- a/server-beta/src/searcher/init.lua
+++ /dev/null
@@ -1,10 +0,0 @@
-local searcher = require 'searcher.searcher'
-require 'searcher.eachField'
-require 'searcher.eachRef'
-require 'searcher.eachDef'
-require 'searcher.getGlobals'
-require 'searcher.getLinks'
-require 'searcher.getGlobal'
-require 'searcher.getLibrary'
-require 'searcher.getValue'
-return searcher
diff --git a/server-beta/src/service/service.lua b/server-beta/src/service/service.lua
index 7b0b8ad5..e1cb604b 100644
--- a/server-beta/src/service/service.lua
+++ b/server-beta/src/service/service.lua
@@ -1,9 +1,9 @@
-local pub = require 'pub'
-local thread = require 'bee.thread'
-local await = require 'await'
-local timer = require 'timer'
-local proto = require 'proto'
-local searcher = require 'searcher'
+local pub = require 'pub'
+local thread = require 'bee.thread'
+local await = require 'await'
+local timer = require 'timer'
+local proto = require 'proto'
+local vm = require 'vm'
local m = {}
m.type = 'service'
@@ -84,7 +84,7 @@ function m.reportCache()
local total = 0
local dead = 0
- for cache in pairs(searcher.cacheTracker) do
+ for cache in pairs(vm.cacheTracker) do
total = total + 1
if cache.dead then
dead = dead + 1
diff --git a/server-beta/src/searcher/eachDef.lua b/server-beta/src/vm/eachDef.lua
index bc9f9e1c..0274cbee 100644
--- a/server-beta/src/searcher/eachDef.lua
+++ b/server-beta/src/vm/eachDef.lua
@@ -1,6 +1,6 @@
-local searcher = require 'searcher.searcher'
-local guide = require 'parser.guide'
-local files = require 'files'
+local vm = require 'vm.vm'
+local guide = require 'parser.guide'
+local files = require 'files'
local function checkPath(source, info)
if source.type == 'goto' then
@@ -17,11 +17,11 @@ local function checkPath(source, info)
return true
end
-function searcher.eachDef(source, callback)
+function vm.eachDef(source, callback)
local results = {}
local valueUris = {}
local sourceUri = guide.getRoot(source).uri
- searcher.eachRef(source, function (info)
+ vm.eachRef(source, function (info)
if info.mode == 'declare'
or info.mode == 'set'
or info.mode == 'return'
diff --git a/server-beta/src/searcher/eachField.lua b/server-beta/src/vm/eachField.lua
index 6245108c..549a7dec 100644
--- a/server-beta/src/searcher/eachField.lua
+++ b/server-beta/src/vm/eachField.lua
@@ -1,5 +1,5 @@
local guide = require 'parser.guide'
-local searcher = require 'searcher.searcher'
+local vm = require 'vm.vm'
local function ofTabel(value, callback)
for _, field in ipairs(value) do
@@ -67,9 +67,9 @@ local function ofSpecialArg(source, callback)
end
elseif name == 'setmetatable' then
if args[1] == source and args[2] then
- searcher.eachField(args[2], function (info)
+ vm.eachField(args[2], function (info)
if info.key == 's|__index' and info.value then
- searcher.eachField(info.value, callback)
+ vm.eachField(info.value, callback)
end
end)
end
@@ -108,7 +108,7 @@ local function ofVar(source, callback)
end
local function eachField(source, callback)
- searcher.eachRef(source, function (info)
+ vm.eachRef(source, function (info)
local src = info.source
if src.tag == '_ENV' then
if src.ref then
@@ -129,20 +129,20 @@ local function eachField(source, callback)
end
--- 获取所有的field
-function searcher.eachField(source, callback)
- local cache = searcher.cache.eachField[source]
+function vm.eachField(source, callback)
+ local cache = vm.cache.eachField[source]
if cache then
for i = 1, #cache do
callback(cache[i])
end
return
end
- local unlock = searcher.lock('eachField', source)
+ local unlock = vm.lock('eachField', source)
if not unlock then
return
end
cache = {}
- searcher.cache.eachField[source] = cache
+ vm.cache.eachField[source] = cache
local mark = {}
eachField(source, function (info)
local src = info.source
@@ -153,9 +153,9 @@ function searcher.eachField(source, callback)
cache[#cache+1] = info
end)
unlock()
- searcher.eachRef(source, function (info)
+ vm.eachRef(source, function (info)
local src = info.source
- searcher.cache.eachField[src] = cache
+ vm.cache.eachField[src] = cache
end)
for i = 1, #cache do
callback(cache[i])
diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/vm/eachRef.lua
index d8e3bd6f..543a0c09 100644
--- a/server-beta/src/searcher/eachRef.lua
+++ b/server-beta/src/vm/eachRef.lua
@@ -1,10 +1,9 @@
-local guide = require 'parser.guide'
-local files = require 'files'
-local workspace = require 'workspace'
-local searcher = require 'searcher.searcher'
+local guide = require 'parser.guide'
+local files = require 'files'
+local vm = require 'vm.vm'
local function ofCall(func, index, callback)
- searcher.eachRef(func, function (info)
+ vm.eachRef(func, function (info)
local src = info.source
local returns
if info.mode == 'main' then
@@ -22,7 +21,7 @@ local function ofCall(func, index, callback)
source = val,
mode = 'return',
}
- searcher.eachRef(val, callback)
+ vm.eachRef(val, callback)
end
end
end
@@ -32,14 +31,14 @@ end
local function ofCallSelect(call, index, callback)
local slc = call.parent
if slc.index == index then
- searcher.eachRef(slc.parent, callback)
+ vm.eachRef(slc.parent, callback)
return
end
if call.extParent then
for i = 1, #call.extParent do
slc = call.extParent[i]
if slc.index == index then
- searcher.eachRef(slc.parent, callback)
+ vm.eachRef(slc.parent, callback)
return
end
end
@@ -53,9 +52,9 @@ local function ofReturn(rtn, index, callback)
end
-- 搜索函数调用的第 index 个接收值
if func.type == 'main' then
- searcher.eachRef(func, callback)
+ vm.eachRef(func, callback)
else
- searcher.eachRef(func, function (info)
+ vm.eachRef(func, function (info)
local source = info.source
local call = source.parent
if not call or call.type ~= 'call' then
@@ -72,14 +71,14 @@ local function ofSpecialCall(call, func, index, callback)
if index == 1 then
local args = call.args
if args[1] then
- searcher.eachRef(args[1], callback)
+ vm.eachRef(args[1], callback)
end
if args[2] then
- searcher.eachField(args[2], function (info)
+ vm.eachField(args[2], function (info)
if info.key == 's|__index' then
- searcher.eachRef(info.source, callback)
+ vm.eachRef(info.source, callback)
if info.value then
- searcher.eachRef(info.value, callback)
+ vm.eachRef(info.value, callback)
end
end
end)
@@ -87,7 +86,7 @@ local function ofSpecialCall(call, func, index, callback)
end
elseif name == 'require' then
if index == 1 then
- local result = searcher.getLinkUris(call)
+ local result = vm.getLinkUris(call)
if result then
local myUri = guide.getRoot(call).uri
for _, uri in ipairs(result) do
@@ -126,7 +125,7 @@ local function ofValue(value, callback)
}
end
- searcher.eachRef(value, callback)
+ vm.eachRef(value, callback)
local parent = value.parent
if parent.type == 'local'
@@ -138,7 +137,7 @@ local function ofValue(value, callback)
or parent.type == 'tablefield'
or parent.type == 'tableindex' then
if parent.value == value then
- searcher.eachRef(parent, callback)
+ vm.eachRef(parent, callback)
end
end
if parent.type == 'return' then
@@ -156,7 +155,7 @@ local function ofSelf(loc, callback)
-- 1. 当前方法定义时的对象(mt)
local method = loc.method
local node = method.node
- searcher.eachRef(node, callback)
+ vm.eachRef(node, callback)
-- 2. 调用该方法时传入的对象
end
@@ -173,7 +172,7 @@ local function asValue(source, callback)
local call = args.parent
local func = call.node
if func.special == 'setmetatable' then
- searcher.eachRef(args[1], callback)
+ vm.eachRef(args[1], callback)
end
end
end
@@ -210,11 +209,11 @@ local function asArg(source, callback)
if name == 'setmetatable' then
if parent[1] == source then
if parent[2] then
- searcher.eachField(parent[2], function (info)
+ vm.eachField(parent[2], function (info)
if info.key == 's|__index' then
- searcher.eachRef(info.source, callback)
+ vm.eachRef(info.source, callback)
if info.value then
- searcher.eachRef(info.value, callback)
+ vm.eachRef(info.value, callback)
end
end
end)
@@ -222,7 +221,7 @@ local function asArg(source, callback)
end
local recvs = getCallRecvs(call)
if recvs and recvs[1] then
- searcher.eachRef(recvs[1], callback)
+ vm.eachRef(recvs[1], callback)
end
end
end
@@ -293,7 +292,7 @@ local function ofGlobal(source, callback)
local uris = files.findGlobals(key)
for _, uri in ipairs(uris) do
local ast = files.getAst(uri)
- local globals = searcher.getGlobals(ast.ast)
+ local globals = vm.getGlobals(ast.ast)
if globals[key] then
for _, info in ipairs(globals[key]) do
callback(info)
@@ -304,7 +303,7 @@ local function ofGlobal(source, callback)
end
end
else
- searcher.eachField(node, function (info)
+ vm.eachField(node, function (info)
if key == info.key then
callback {
source = info.source,
@@ -324,7 +323,7 @@ local function ofField(source, callback)
if parent.type == 'tablefield'
or parent.type == 'tableindex' then
local tbl = parent.parent
- searcher.eachField(tbl, function (info)
+ vm.eachField(tbl, function (info)
if key == info.key then
callback {
source = info.source,
@@ -337,7 +336,7 @@ local function ofField(source, callback)
end)
else
local node = parent.node
- searcher.eachField(node, function (info)
+ vm.eachField(node, function (info)
if key == info.key then
callback {
source = info.source,
@@ -399,7 +398,7 @@ local function ofMain(source, callback)
for _, uri in ipairs(uris) do
local ast = files.getAst(uri)
if ast then
- local links = searcher.getLinks(ast.ast)
+ local links = vm.getLinks(ast.ast)
if links then
for linkUri, calls in pairs(links) do
if files.eq(linkUri, myUri) then
@@ -450,13 +449,13 @@ local function eachRef(source, callback)
end
--- 判断2个对象是否拥有相同的引用
-function searcher.isSameRef(a, b)
- local cache = searcher.cache.eachRef[a]
+function vm.isSameRef(a, b)
+ local cache = vm.cache.eachRef[a]
if cache then
-- 相同引用的source共享同一份cache
- return cache == searcher.cache.eachRef[b]
+ return cache == vm.cache.eachRef[b]
else
- return searcher.eachRef(a, function (info)
+ return vm.eachRef(a, function (info)
if info.source == b then
return true
end
@@ -465,8 +464,8 @@ function searcher.isSameRef(a, b)
end
--- 获取所有的引用
-function searcher.eachRef(source, callback)
- local cache = searcher.cache.eachRef[source]
+function vm.eachRef(source, callback)
+ local cache = vm.cache.eachRef[source]
if cache then
for i = 1, #cache do
local res = callback(cache[i])
@@ -476,12 +475,12 @@ function searcher.eachRef(source, callback)
end
return
end
- local unlock = searcher.lock('eachRef', source)
+ local unlock = vm.lock('eachRef', source)
if not unlock then
return
end
cache = {}
- searcher.cache.eachRef[source] = cache
+ vm.cache.eachRef[source] = cache
local mark = {}
eachRef(source, function (info)
local src = info.source
@@ -494,7 +493,7 @@ function searcher.eachRef(source, callback)
unlock()
for i = 1, #cache do
local src = cache[i].source
- searcher.cache.eachRef[src] = cache
+ vm.cache.eachRef[src] = cache
end
for i = 1, #cache do
local res = callback(cache[i])
diff --git a/server-beta/src/vm/getGlobal.lua b/server-beta/src/vm/getGlobal.lua
new file mode 100644
index 00000000..373c907e
--- /dev/null
+++ b/server-beta/src/vm/getGlobal.lua
@@ -0,0 +1,6 @@
+local vm = require 'vm.vm'
+
+function vm.getGlobal(source)
+ vm.getGlobals(source)
+ return vm.cache.getGlobal[source]
+end
diff --git a/server-beta/src/searcher/getGlobals.lua b/server-beta/src/vm/getGlobals.lua
index 13e69e16..699dd270 100644
--- a/server-beta/src/searcher/getGlobals.lua
+++ b/server-beta/src/vm/getGlobals.lua
@@ -1,11 +1,11 @@
local guide = require 'parser.guide'
-local searcher = require 'searcher.searcher'
+local vm = require 'vm.vm'
local function getGlobals(root)
local env = guide.getENV(root)
local cache = {}
local mark = {}
- searcher.eachField(env, function (info)
+ vm.eachField(env, function (info)
local src = info.source
if mark[src] then
return
@@ -23,23 +23,23 @@ local function getGlobals(root)
end
cache[name][#cache[name]+1] = info
cache[name].mode[info.mode] = true
- searcher.cache.getGlobal[src] = name
+ vm.cache.getGlobal[src] = name
end)
return cache
end
-function searcher.getGlobals(source)
+function vm.getGlobals(source)
source = guide.getRoot(source)
- local cache = searcher.cache.getGlobals[source]
+ local cache = vm.cache.getGlobals[source]
if cache ~= nil then
return cache
end
- local unlock = searcher.lock('getGlobals', source)
+ local unlock = vm.lock('getGlobals', source)
if not unlock then
return nil
end
cache = getGlobals(source) or false
- searcher.cache.getGlobals[source] = cache
+ vm.cache.getGlobals[source] = cache
unlock()
return cache
end
diff --git a/server-beta/src/searcher/getLibrary.lua b/server-beta/src/vm/getLibrary.lua
index a2620295..08f015a6 100644
--- a/server-beta/src/searcher/getLibrary.lua
+++ b/server-beta/src/vm/getLibrary.lua
@@ -1,9 +1,9 @@
-local searcher = require 'searcher.searcher'
-local library = require 'library'
-local guide = require 'parser.guide'
+local vm = require 'vm.vm'
+local library = require 'library'
+local guide = require 'parser.guide'
local function checkStdLibrary(source)
- local globalName = searcher.getGlobal(source)
+ local globalName = vm.getGlobal(source)
if not globalName then
return nil
end
@@ -18,7 +18,7 @@ local function getLibrary(source)
if lib then
return lib
end
- return searcher.eachRef(source, function (info)
+ return vm.eachRef(source, function (info)
local src = info.source
if src.type ~= 'getfield'
and src.type ~= 'getmethod'
@@ -26,7 +26,7 @@ local function getLibrary(source)
return
end
local node = src.node
- local nodeGlobalName = searcher.getGlobal(node)
+ local nodeGlobalName = vm.getGlobal(node)
if not nodeGlobalName then
return
end
@@ -44,17 +44,17 @@ local function getLibrary(source)
end)
end
-function searcher.getLibrary(source)
- local cache = searcher.cache.getLibrary[source]
+function vm.getLibrary(source)
+ local cache = vm.cache.getLibrary[source]
if cache ~= nil then
return cache
end
- local unlock = searcher.lock('getLibrary', source)
+ local unlock = vm.lock('getLibrary', source)
if not unlock then
return
end
cache = getLibrary(source) or false
- searcher.cache.getLibrary[source] = cache
+ vm.cache.getLibrary[source] = cache
unlock()
return cache
end
diff --git a/server-beta/src/searcher/getLinks.lua b/server-beta/src/vm/getLinks.lua
index 3e204e1f..6875771f 100644
--- a/server-beta/src/searcher/getLinks.lua
+++ b/server-beta/src/vm/getLinks.lua
@@ -1,5 +1,5 @@
local guide = require 'parser.guide'
-local searcher = require 'searcher.searcher'
+local vm = require 'vm.vm'
local function getLinks(root)
local cache = {}
@@ -7,7 +7,7 @@ local function getLinks(root)
guide.eachSpecialOf(root, 'require', function (source)
local call = source.parent
if call.type == 'call' then
- local uris = searcher.getLinkUris(call)
+ local uris = vm.getLinkUris(call)
if uris then
ok = true
for i = 1, #uris do
@@ -26,13 +26,13 @@ local function getLinks(root)
return cache
end
-function searcher.getLinks(source)
+function vm.getLinks(source)
source = guide.getRoot(source)
- local cache = searcher.cache.getLinks[source]
+ local cache = vm.cache.getLinks[source]
if cache ~= nil then
return cache
end
- local unlock = searcher.lock('getLinks', source)
+ local unlock = vm.lock('getLinks', source)
if not unlock then
return nil
end
@@ -42,7 +42,7 @@ function searcher.getLinks(source)
if passed > 0.1 then
log.warn(('getLinks takes [%.3f] sec!'):format(passed))
end
- searcher.cache.getLinks[source] = cache
+ vm.cache.getLinks[source] = cache
unlock()
return cache
end
diff --git a/server-beta/src/searcher/getValue.lua b/server-beta/src/vm/getValue.lua
index ae28b212..b13d822d 100644
--- a/server-beta/src/searcher/getValue.lua
+++ b/server-beta/src/vm/getValue.lua
@@ -1,6 +1,4 @@
-local searcher = require 'searcher.searcher'
-local guide = require 'parser.guide'
-local config = require 'config'
+local vm = require 'vm.vm'
local typeSort = {
['boolean'] = 1,
@@ -77,7 +75,7 @@ local function checkUnary(source)
end
local op = source.op
if op.type == 'not' then
- local isTrue = searcher.isTrue(source[1])
+ local isTrue = vm.isTrue(source[1])
local value = nil
if isTrue == true then
value = false
@@ -95,14 +93,14 @@ local function checkUnary(source)
source = source,
}
elseif op.type == '~' then
- local l = searcher.getLiteral(source[1], 'integer')
+ local l = vm.getLiteral(source[1], 'integer')
return {
type = 'integer',
value = l and ~l or nil,
source = source,
}
elseif op.type == '-' then
- local v = searcher.getLiteral(source[1], 'integer')
+ local v = vm.getLiteral(source[1], 'integer')
if v then
return {
type = 'integer',
@@ -110,7 +108,7 @@ local function checkUnary(source)
source = source,
}
end
- v = searcher.getLiteral(source[1], 'number')
+ v = vm.getLiteral(source[1], 'number')
return {
type = 'number',
value = v and -v or nil,
@@ -125,31 +123,31 @@ local function checkBinary(source)
end
local op = source.op
if op.type == 'and' then
- local isTrue = searcher.checkTrue(source[1])
+ local isTrue = vm.checkTrue(source[1])
if isTrue == true then
- return searcher.getValue(source[2])
+ return vm.getValue(source[2])
elseif isTrue == false then
- return searcher.getValue(source[1])
+ return vm.getValue(source[1])
else
return merge(
- searcher.getValue(source[1]),
- searcher.getValue(source[2])
+ vm.getValue(source[1]),
+ vm.getValue(source[2])
)
end
elseif op.type == 'or' then
- local isTrue = searcher.checkTrue(source[1])
+ local isTrue = vm.checkTrue(source[1])
if isTrue == true then
- return searcher.getValue(source[1])
+ return vm.getValue(source[1])
elseif isTrue == false then
- return searcher.getValue(source[2])
+ return vm.getValue(source[2])
else
return merge(
- searcher.getValue(source[1]),
- searcher.getValue(source[2])
+ vm.getValue(source[1]),
+ vm.getValue(source[2])
)
end
elseif op.type == '==' then
- local value = searcher.isSameValue(source[1], source[2])
+ local value = vm.isSameValue(source[1], source[2])
if value ~= nil then
return {
type = 'boolean',
@@ -157,7 +155,7 @@ local function checkBinary(source)
source = source,
}
end
- local isSame = searcher.isSameRef(source[1], source[2])
+ local isSame = vm.isSameRef(source[1], source[2])
if isSame == true then
value = true
else
@@ -169,7 +167,7 @@ local function checkBinary(source)
source = source,
}
elseif op.type == '~=' then
- local value = searcher.isSameValue(source[1], source[2])
+ local value = vm.isSameValue(source[1], source[2])
if value ~= nil then
return {
type = 'boolean',
@@ -177,7 +175,7 @@ local function checkBinary(source)
source = source,
}
end
- local isSame = searcher.isSameRef(source[1], source[2])
+ local isSame = vm.isSameRef(source[1], source[2])
if isSame == true then
value = false
else
@@ -214,8 +212,8 @@ local function checkBinary(source)
or op.type == '*'
or op.type == '%'
or op.type == '//' then
- if hasType('integer', searcher.getValue(source[1]))
- and hasType('integer', searcher.getValue(source[2])) then
+ if hasType('integer', vm.getValue(source[1]))
+ and hasType('integer', vm.getValue(source[2])) then
return 'integer'
else
return 'number'
@@ -225,7 +223,7 @@ end
local function checkValue(source)
if source.value then
- return searcher.getValue(source.value)
+ return vm.getValue(source.value)
end
end
@@ -258,9 +256,9 @@ local function checkNext(result, source)
end
local function checkDef(result, source)
- searcher.eachDef(source, function (info)
+ vm.eachDef(source, function (info)
local src = info.source
- local tp = searcher.getValue(src)
+ local tp = vm.getValue(src)
if tp then
merge(result, tp)
end
@@ -298,8 +296,8 @@ local function getValue(source)
end
end
-function searcher.checkTrue(source)
- local values = searcher.getValue(source)
+function vm.checkTrue(source)
+ local values = vm.getValue(source)
if not values then
return
end
@@ -333,8 +331,8 @@ function searcher.checkTrue(source)
end
--- 拥有某个类型的值
-function searcher.eachValueType(source, type, callback)
- local values = searcher.getValue(source)
+function vm.eachValueType(source, type, callback)
+ local values = vm.getValue(source)
if not values then
return
end
@@ -350,8 +348,8 @@ function searcher.eachValueType(source, type, callback)
end
--- 获取特定类型的字面量值
-function searcher.getLiteral(source, type)
- local values = searcher.getValue(source)
+function vm.getLiteral(source, type)
+ local values = vm.getValue(source)
if not values then
return nil
end
@@ -364,9 +362,9 @@ function searcher.getLiteral(source, type)
return nil
end
-function searcher.isSameValue(a, b)
- local valuesA = searcher.getValue(a)
- local valuesB = searcher.getValue(b)
+function vm.isSameValue(a, b)
+ local valuesA = vm.getValue(a)
+ local valuesB = vm.getValue(b)
if valuesA == valuesB and valuesA ~= nil then
return true
end
@@ -396,8 +394,8 @@ function searcher.isSameValue(a, b)
return true
end
-function searcher.typeInference(source)
- local values = searcher.getValue(source)
+function vm.typeInference(source)
+ local values = vm.getValue(source)
if not values then
return 'any'
end
@@ -435,20 +433,20 @@ function searcher.typeInference(source)
return table.concat(types, '|')
end
-function searcher.getValue(source)
+function vm.getValue(source)
if not source then
return
end
- local cache = searcher.cache.getValue[source]
+ local cache = vm.cache.getValue[source]
if cache ~= nil then
return cache
end
- local unlock = searcher.lock('getValue', source)
+ local unlock = vm.lock('getValue', source)
if not unlock then
return
end
cache = getValue(source) or false
- searcher.cache.getValue[source] = cache
+ vm.cache.getValue[source] = cache
unlock()
return cache
end
diff --git a/server-beta/src/vm/init.lua b/server-beta/src/vm/init.lua
new file mode 100644
index 00000000..bf63db1d
--- /dev/null
+++ b/server-beta/src/vm/init.lua
@@ -0,0 +1,10 @@
+local vm = require 'vm.vm'
+require 'vm.eachField'
+require 'vm.eachRef'
+require 'vm.eachDef'
+require 'vm.getGlobals'
+require 'vm.getLinks'
+require 'vm.getGlobal'
+require 'vm.getLibrary'
+require 'vm.getValue'
+return vm
diff --git a/server-beta/src/searcher/special.lua b/server-beta/src/vm/special.lua
index e69de29b..e69de29b 100644
--- a/server-beta/src/searcher/special.lua
+++ b/server-beta/src/vm/special.lua
diff --git a/server-beta/src/searcher/searcher.lua b/server-beta/src/vm/vm.lua
index e47e8c54..23a691df 100644
--- a/server-beta/src/searcher/searcher.lua
+++ b/server-beta/src/vm/vm.lua
@@ -18,7 +18,7 @@ local specials = {
['loadfile'] = true,
}
----@class searcher
+---@class vm
local m = {}
function m.lock(tp, source)