summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/diagnostics/duplicate-index.lua3
-rw-r--r--script-beta/core/highlight.lua2
-rw-r--r--script-beta/core/rename.lua2
-rw-r--r--script-beta/vm/eachDef.lua8
-rw-r--r--script-beta/vm/eachField.lua15
-rw-r--r--script-beta/vm/eachRef.lua12
-rw-r--r--script-beta/vm/getGlobals.lua2
-rw-r--r--script-beta/vm/vm.lua60
8 files changed, 74 insertions, 30 deletions
diff --git a/script-beta/core/diagnostics/duplicate-index.lua b/script-beta/core/diagnostics/duplicate-index.lua
index 76b1c958..dabe1b3c 100644
--- a/script-beta/core/diagnostics/duplicate-index.lua
+++ b/script-beta/core/diagnostics/duplicate-index.lua
@@ -2,6 +2,7 @@ local files = require 'files'
local guide = require 'parser.guide'
local lang = require 'language'
local define = require 'proto.define'
+local vm = require 'vm'
return function (uri, callback)
local ast = files.getAst(uri)
@@ -14,7 +15,7 @@ return function (uri, callback)
for _, obj in ipairs(source) do
if obj.type == 'tablefield'
or obj.type == 'tableindex' then
- local name = guide.getKeyName(obj)
+ local name = vm.getKeyName(obj)
if name then
if not mark[name] then
mark[name] = {}
diff --git a/script-beta/core/highlight.lua b/script-beta/core/highlight.lua
index 61e3f91a..48f2ea9f 100644
--- a/script-beta/core/highlight.lua
+++ b/script-beta/core/highlight.lua
@@ -17,7 +17,7 @@ local function ofField(source, uri, callback)
if not parent then
return
end
- local myKey = guide.getKeyName(source)
+ local myKey = vm.getKeyName(source)
if parent.type == 'tableindex'
or parent.type == 'tablefield' then
local tbl = parent.parent
diff --git a/script-beta/core/rename.lua b/script-beta/core/rename.lua
index 4beb3bbb..f65bd71b 100644
--- a/script-beta/core/rename.lua
+++ b/script-beta/core/rename.lua
@@ -227,7 +227,7 @@ local function ofLocal(source, newname, callback)
end
local function ofField(source, newname, callback)
- local key = guide.getKeyName(source)
+ local key = vm.getKeyName(source)
local tbl
if source.type == 'tablefield'
or source.type == 'tableindex' then
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
index 19b0c0ed..6d389d18 100644
--- a/script-beta/vm/eachDef.lua
+++ b/script-beta/vm/eachDef.lua
@@ -37,7 +37,7 @@ local function ofLocal(loc, callback)
end
local function ofGlobal(source, callback)
- local key = guide.getKeyName(source)
+ local key = vm.getKeyName(source)
local node = source.node
if node.tag == '_ENV' then
local uris = files.findGlobals(key)
@@ -55,7 +55,7 @@ local function ofGlobal(source, callback)
else
vm.eachField(node, function (src)
if vm.isSet(src)
- and key == guide.getKeyName(src) then
+ and key == vm.getKeyName(src) then
callback(src)
end
end)
@@ -68,7 +68,7 @@ end
local function ofField(source, callback)
local parent = source.parent
- local key = guide.getKeyName(source)
+ local key = vm.getKeyName(source)
if parent.type == 'tablefield'
or parent.type == 'tableindex' then
ofTableField(parent, callback)
@@ -76,7 +76,7 @@ local function ofField(source, callback)
local node = parent.node
vm.eachField(node, function (src)
if vm.isSet(src)
- and key == guide.getKeyName(src) then
+ and key == vm.getKeyName(src) then
callback(src)
end
end)
diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua
index 4a9e3eef..89df0e2f 100644
--- a/script-beta/vm/eachField.lua
+++ b/script-beta/vm/eachField.lua
@@ -30,20 +30,19 @@ local function ofENV(source, callback)
end
for i = 1, #refs do
local ref = refs[i]
- if ref.type == 'getglobal' then
+ if ref.type == 'getglobal'
+ or ref.type == 'setglobal' then
callback(ref)
if guide.getName(ref) == '_G' then
local nextSrc = checkNext(ref)
if nextSrc then
callback(nextSrc)
end
- end
- elseif ref.type == 'setglobal' then
- callback(ref)
- if guide.getName(ref) == '_G' then
- local nextSrc = checkNext(ref)
- if nextSrc then
- callback(nextSrc)
+ local call, index = vm.getArgInfo(ref)
+ local special = vm.getSpecial(call)
+ if (special == 'rawset' or special == 'rawget')
+ and index == 1 then
+ callback(call.next)
end
end
elseif ref.type == 'getlocal' then
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index 91aed10e..b8a2bce5 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -21,7 +21,7 @@ local function ofLocal(loc, callback)
end
local function ofGlobal(source, callback)
- local key = guide.getKeyName(source)
+ local key = vm.getKeyName(source)
local node = source.node
if node.tag == '_ENV' then
local uris = files.findGlobals(key)
@@ -36,7 +36,7 @@ local function ofGlobal(source, callback)
end
else
vm.eachField(node, function (src)
- if key == guide.getKeyName(src) then
+ if key == vm.getKeyName(src) then
callback(src)
end
end)
@@ -49,9 +49,9 @@ local function ofTableField(source, callback)
if not src then
return
end
- local key = guide.getKeyName(source)
+ local key = vm.getKeyName(source)
vm.eachField(src, function (src)
- if key == guide.getKeyName(src) then
+ if key == vm.getKeyName(src) then
callback(src)
end
end)
@@ -59,14 +59,14 @@ end
local function ofField(source, callback)
local parent = source.parent
- local key = guide.getKeyName(source)
+ local key = vm.getKeyName(source)
if parent.type == 'tablefield'
or parent.type == 'tableindex' then
ofTableField(parent, callback)
else
local node = parent.node
vm.eachField(node, function (src)
- if key == guide.getKeyName(src) then
+ if key == vm.getKeyName(src) then
callback(src)
end
end)
diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua
index b64d63ff..2760fea4 100644
--- a/script-beta/vm/getGlobals.lua
+++ b/script-beta/vm/getGlobals.lua
@@ -13,7 +13,7 @@ local function getGlobals(root)
return
end
mark[src] = true
- local name = guide.getKeyName(src)
+ local name = vm.getKeyName(src)
if not name then
return
end
diff --git a/script-beta/vm/vm.lua b/script-beta/vm/vm.lua
index 863686d8..6c8af6e7 100644
--- a/script-beta/vm/vm.lua
+++ b/script-beta/vm/vm.lua
@@ -61,14 +61,58 @@ end
function m.isSet(src)
local tp = src.type
- return tp == 'setglobal'
- or tp == 'local'
- or tp == 'setlocal'
- or tp == 'setfield'
- or tp == 'setmethod'
- or tp == 'setindex'
- or tp == 'tablefield'
- or tp == 'tableindex'
+ if tp == 'setglobal'
+ or tp == 'local'
+ or tp == 'setlocal'
+ or tp == 'setfield'
+ or tp == 'setmethod'
+ or tp == 'setindex'
+ or tp == 'tablefield'
+ or tp == 'tableindex' then
+ return true
+ end
+ if tp == 'call' then
+ local special = m.getSpecial(src.node)
+ if special == 'rawset' then
+ return true
+ end
+ end
+ return false
+end
+
+function m.getArgInfo(source)
+ local callargs = source.parent
+ if not callargs or callargs.type ~= 'callargs' then
+ return nil
+ end
+ local call = callargs.parent
+ if not call or call.type ~= 'call' then
+ return nil
+ end
+ for i = 1, #callargs do
+ if callargs[i] == source then
+ return call.node, i
+ end
+ end
+ return nil
+end
+
+function m.getSpecial(source)
+ if not source then
+ return nil
+ end
+ return source.special
+end
+
+function m.getKeyName(source)
+ if source.type == 'call' then
+ local special = m.getSpecial(source.node)
+ if special == 'rawset'
+ or special == 'rawget' then
+ return guide.getKeyName(source.args[2])
+ end
+ end
+ return guide.getKeyName(source)
end
m.cacheTracker = setmetatable({}, { __mode = 'kv' })