Skip to content
Snippets Groups Projects
Commit 8f5bc53c authored by 最萌小汐's avatar 最萌小汐
Browse files

更新引用实现

parent d0e4afaa
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ local fs = require 'bee.filesystem'
ROOT = fs.path(rootPath)
LANG = LANG or 'en-US'
--collectgarbage 'generational'
collectgarbage 'generational'
log = require 'log'
log.init(ROOT, ROOT / 'log' / 'service.log')
......
......@@ -10,6 +10,7 @@ local function findDef(source, callback)
and source.type ~= 'setglobal'
and source.type ~= 'getglobal'
and source.type ~= 'field'
and source.type ~= 'tablefield'
and source.type ~= 'method'
and source.type ~= 'string'
and source.type ~= 'number'
......
......@@ -423,7 +423,10 @@ local function compileGoTo(obj)
}
return
end
label.ref = obj
if not label.ref then
label.ref = {}
end
label.ref[#label.ref+1] = obj
-- 如果有局部变量在 goto 与 label 之间声明,
-- 并在 label 之后使用,则算作语法错误
......
......@@ -271,8 +271,22 @@ end
local function ofField(source, callback)
local parent = source.parent
local node = parent.node
local key = guide.getKeyName(source)
if parent.type == 'tablefield' then
local tbl = parent.parent
searcher.eachField(tbl, function (info)
if key == info.key then
callback {
source = info.source,
mode = info.mode,
}
if info.value then
ofValue(info.value, callback)
end
end
end)
else
local node = parent.node
searcher.eachField(node, function (info)
if key == info.key then
callback {
......@@ -285,6 +299,7 @@ local function ofField(source, callback)
end
end)
end
end
local function ofLiteral(source, callback)
local parent = source.parent
......@@ -297,25 +312,28 @@ local function ofLiteral(source, callback)
end
end
local function ofGoTo(source, callback)
local name = source[1]
local label = guide.getLabel(source, name)
if label then
local function ofLabel(source, callback)
callback {
source = label,
source = source,
mode = 'set',
}
end
end
local function ofLabel(source, callback)
if source.ref then
for _, ref in ipairs(source.ref) do
callback {
source = source.ref,
source = ref,
mode = 'get',
}
end
end
end
local function ofGoTo(source, callback)
local name = source[1]
local label = guide.getLabel(source, name)
if label then
ofLabel(label, callback)
end
end
local function ofMain(source, callback)
if source.returns then
......@@ -347,7 +365,8 @@ local function eachRef(source, callback)
or stype == 'index' then
ofField(source, callback)
elseif stype == 'setfield'
or stype == 'getfield' then
or stype == 'getfield'
or stype == 'tablefield' then
ofField(source.field, callback)
elseif stype == 'setmethod'
or stype == 'getmethod' then
......
......@@ -38,7 +38,7 @@ local function main()
test 'definition'
test 'diagnostics'
--test 'references'
test 'references'
--test 'highlight'
--test 'rename'
--test 'type_inference'
......
......@@ -65,6 +65,9 @@ t.<!a!> = t.<!a!>
TEST [[
:: <!LABEL!> ::
goto <?LABEL?>
if true then
goto <!LABEL!>
end
]]
TEST [[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment