diff options
Diffstat (limited to 'server-beta/src/core')
-rw-r--r-- | server-beta/src/core/_G.lua | 34 | ||||
-rw-r--r-- | server-beta/src/core/boolean.lua | 11 | ||||
-rw-r--r-- | server-beta/src/core/engineer.lua | 256 | ||||
-rw-r--r-- | server-beta/src/core/field.lua | 23 | ||||
-rw-r--r-- | server-beta/src/core/getglobal.lua | 49 | ||||
-rw-r--r-- | server-beta/src/core/getlocal.lua | 15 | ||||
-rw-r--r-- | server-beta/src/core/local.lua | 70 | ||||
-rw-r--r-- | server-beta/src/core/method.lua | 23 | ||||
-rw-r--r-- | server-beta/src/core/number.lua | 11 | ||||
-rw-r--r-- | server-beta/src/core/string.lua | 11 | ||||
-rw-r--r-- | server-beta/src/core/table.lua | 13 |
11 files changed, 312 insertions, 204 deletions
diff --git a/server-beta/src/core/_G.lua b/server-beta/src/core/_G.lua new file mode 100644 index 00000000..3a28c7ac --- /dev/null +++ b/server-beta/src/core/_G.lua @@ -0,0 +1,34 @@ +local m = {} + +function m:def(source, callback) + local parent = source.parent + if parent.type == 'setfield' + or parent.type == 'setindex' + or parent.type == 'setmethod' then + callback(parent, 'set') + elseif parent.type == 'getfield' + or parent.type == 'getindex' then + self:search(parent, 'special', 'def', callback) + elseif parent.type == 'callargs' then + self:search(parent.parent, 'special', 'def', callback) + end +end + +function m:ref(source, callback) + local parent = source.parent + if parent.type == 'setfield' + or parent.type == 'setindex' + or parent.type == 'setmethod' then + callback(parent, 'set') + elseif parent.type == 'getfield' + or parent.type == 'getindex' + or parent.type == 'getmethod' then + callback(parent, 'get') + elseif parent.type == 'getfield' then + self:search(parent, 'special', 'ref', callback) + elseif parent.type == 'callargs' then + self:search(parent.parent, 'special', 'ref', callback) + end +end + +return m diff --git a/server-beta/src/core/boolean.lua b/server-beta/src/core/boolean.lua new file mode 100644 index 00000000..acc4436e --- /dev/null +++ b/server-beta/src/core/boolean.lua @@ -0,0 +1,11 @@ +local m = {} + +function m:def(source, callback) + self:asindex(source, 'def', callback) +end + +function m:ref(source, callback) + self:asindex(source, 'ref', callback) +end + +return m diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua index 9fc771b2..76a360cc 100644 --- a/server-beta/src/core/engineer.lua +++ b/server-beta/src/core/engineer.lua @@ -1,217 +1,57 @@ -local guide = require 'parser.guide' -local config = require 'config' +local guide = require 'parser.guide' +local require = require -local type = type local setmetatable = setmetatable local ipairs = ipairs _ENV = nil - ---@class engineer local mt = {} mt.__index = mt mt.type = 'engineer' -mt['local'] = function (self, source, mode, callback) - if mode == 'def' then - if source.tag ~= 'self' then - callback(source, 'local') - end - if source.ref then - for _, ref in ipairs(source.ref) do - if ref.type == 'setlocal' then - callback(ref, 'set') - end - end - end - if source.tag == 'self' then - local method = source.method - local node = method.node - self:eachRef(node, mode, callback) - end - elseif mode == 'ref' then - if source.tag ~= 'self' then - callback(source, 'local') - end - if source.ref then - for _, ref in ipairs(source.ref) do - if ref.type == 'setlocal' then - callback(ref, 'set') - elseif ref.type == 'getlocal' then - callback(ref, 'get') - end - end - end - if source.tag == 'self' then - local method = source.method - local node = method.node - self:eachRef(node, mode, callback) - end - elseif mode == 'field' then - if source.ref then - for _, ref in ipairs(source.ref) do - if ref.type == 'getlocal' then - local parent = ref.parent - local tp = parent.type - if tp == 'setfield' - or tp == 'getfield' - or tp == 'setmethod' - or tp == 'getmethod' - or tp == 'setindex' - or tp == 'getindex' then - callback(parent) - end - elseif ref.type == 'setlocal' then - self:eachRef(ref.value, 'field', callback) - end - end - end - if source.tag == 'self' then - local method = source.method - local node = method.node - self:eachRef(node, 'field', callback) - end - if source.value then - self:eachField(source.value, nil, 'ref', callback) - end - end -end -mt['getlocal'] = function (self, source, mode, callback) - self:search(source.loc, 'local', mode, callback) -end -mt['setlocal'] = mt['getlocal'] -mt['_G'] = function (self, source, mode, callback) - if mode == 'def' then - local parent = source.parent - if parent.type == 'setfield' - or parent.type == 'setindex' - or parent.type == 'setmethod' then - callback(parent, 'set') - elseif parent.type == 'getfield' - or parent.type == 'getindex' then - self:search(parent, 'special', mode, callback) - elseif parent.type == 'callargs' then - self:search(parent.parent, 'special', mode, callback) - end - elseif mode == 'ref' then - local parent = source.parent - if parent.type == 'setfield' - or parent.type == 'setindex' - or parent.type == 'setmethod' then - callback(parent, 'set') - elseif parent.type == 'getfield' - or parent.type == 'getindex' - or parent.type == 'getmethod' then - callback(parent, 'get') - elseif parent.type == 'getfield' then - self:search(parent, 'special', mode, callback) - elseif parent.type == 'callargs' then - self:search(parent.parent, 'special', mode, callback) - end - end -end -mt['getglobal'] = function (self, source, mode, callback) - local env = source.node - if mode == 'def' then - if env.ref then - for _, ref in ipairs(env.ref) do - if ref.type == 'setglobal' then - callback(ref, 'set') - elseif ref.type == 'getglobal' then - self:search(ref, 'special', mode, callback) - elseif ref.type == 'getlocal' then - self:search(ref, '_G', mode, callback) - end - end - end - elseif mode == 'ref' then - if env.ref then - for _, ref in ipairs(env.ref) do - if ref.type == 'setglobal' then - callback(ref, 'set') - elseif ref.type == 'getglobal' then - callback(ref, 'get') - self:search(ref, 'special', mode, callback) - elseif ref.type == 'getlocal' then - self:search(ref, '_G', mode, callback) - end - end - end - elseif mode == 'field' then - self:search(source, 'getglobal', 'ref', function (src) - local parent = src.parent - local tp = parent.type - if tp == 'setfield' - or tp == 'getfield' - or tp == 'setmethod' - or tp == 'getmethod' - or tp == 'setindex' - or tp == 'getindex' then - callback(parent) - end - end) - end -end +mt['local'] = require 'core.local' +mt['getlocal'] = require 'core.getlocal' +mt['setlocal'] = mt['getlocal'] +mt['_G'] = require 'core._G' +mt['getglobal'] = require 'core.getglobal' mt['setglobal'] = mt['getglobal'] -mt['field'] = function (self, source, mode, callback) - local node = source.parent.node - local key = guide.getKeyName(source) - self:eachField(node, key, mode, callback) -end -mt['method'] = function (self, source, mode, callback) - local node = source.parent.node - local key = guide.getKeyName(source) - self:eachField(node, key, mode, callback) -end -mt['special'] = function (self, source, mode, callback) - local name = self:getSpecial(source) - if not name then - return - end - if mode == 'def' then - if name == 's|_G' then - self:search(source, '_G', mode, callback) - elseif name == 's|rawset' then - callback(source.parent, 'set') - end - end -end -mt['number'] = function (self, source, mode, callback) - self:asindex(source, mode, callback) -end -mt['boolean'] = function (self, source, mode, callback) - self:asindex(source, mode, callback) -end -mt['string'] = function (self, source, mode, callback) - self:asindex(source, mode, callback) -end -mt['table'] = function (self, source, mode, callback) - if mode == 'field' then - for i = 1, #source do - local src = source[i] - if src.type == 'tablefield' - or src.type == 'tableindex' then - callback(src) - end - end - end -end -mt['call'] = function (self, source, mode, callback) - local name = self:getSpecial(source) - if not name then - return - end - local parent = source.parent - if name == 's|setmetatable' then - if parent.index ~= 1 then - return - end - self:eachField(source.args[2], 's|__index', 'def', function (src) - self:eachField(src, nil, 'ref', callback) - end) - return - end -end +mt['field'] = require 'core.field' +mt['method'] = require 'core.method' +mt['number'] = require 'core.number' +mt['boolean'] = require 'core.boolean' +mt['string'] = require 'core.string' +mt['table'] = require 'core.table' + +--mt['special'] = function (self, source, mode, callback) +-- local name = self:getSpecial(source) +-- if not name then +-- return +-- end +-- if mode == 'def' then +-- if name == 's|_G' then +-- self:search(source, '_G', mode, callback) +-- elseif name == 's|rawset' then +-- callback(source.parent, 'set') +-- end +-- end +--end +--mt['call'] = function (self, source, mode, callback) +-- local name = self:getSpecial(source) +-- if not name then +-- return +-- end +-- local parent = source.parent +-- if name == 's|setmetatable' then +-- if parent.index ~= 1 then +-- return +-- end +-- self:eachField(source.args[2], 's|__index', 'def', function (src) +-- self:eachField(src, nil, 'ref', callback) +-- end) +-- return +-- end +--end function mt:asindex(source, mode, callback) local parent = source.parent @@ -279,7 +119,15 @@ end function mt:eachRef(source, mode, callback) local tp = source.type - self:search(source, tp, mode, callback) + local d = mt[tp] + if not d then + return + end + local f = d[mode] + if not f then + return + end + f(self, source, callback) end return function (ast) diff --git a/server-beta/src/core/field.lua b/server-beta/src/core/field.lua new file mode 100644 index 00000000..1304eeab --- /dev/null +++ b/server-beta/src/core/field.lua @@ -0,0 +1,23 @@ +local guide = require 'parser.guide' + +local m = {} + +function m:def(source, callback) + local node = source.parent.node + local key = guide.getKeyName(source) + self:eachField(node, key, 'def', callback) +end + +function m:ref(source, callback) + local node = source.parent.node + local key = guide.getKeyName(source) + self:eachField(node, key, 'ref', callback) +end + +function m:field(source, callback) + local node = source.parent.node + local key = guide.getKeyName(source) + self:eachField(node, key, 'field', callback) +end + +return m diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua new file mode 100644 index 00000000..ffa35176 --- /dev/null +++ b/server-beta/src/core/getglobal.lua @@ -0,0 +1,49 @@ +local m = {} + +function m:def(source, callback) + local env = source.node + if env.ref then + for _, ref in ipairs(env.ref) do + if ref.type == 'setglobal' then + callback(ref, 'set') + elseif ref.type == 'getglobal' then + self:search(ref, 'special', 'def', callback) + elseif ref.type == 'getlocal' then + self:search(ref, '_G', 'def', callback) + end + end + end +end + +function m:ref(source, callback) + local env = source.node + if env.ref then + for _, ref in ipairs(env.ref) do + if ref.type == 'setglobal' then + callback(ref, 'set') + elseif ref.type == 'getglobal' then + callback(ref, 'get') + self:search(ref, 'special', 'ref', callback) + elseif ref.type == 'getlocal' then + self:search(ref, '_G', 'ref', callback) + end + end + end +end + +function m:field(source, callback) + self:search(source, 'getglobal', 'ref', function (src) + local parent = src.parent + local tp = parent.type + if tp == 'setfield' + or tp == 'getfield' + or tp == 'setmethod' + or tp == 'getmethod' + or tp == 'setindex' + or tp == 'getindex' then + callback(parent) + end + end) +end + +return m diff --git a/server-beta/src/core/getlocal.lua b/server-beta/src/core/getlocal.lua new file mode 100644 index 00000000..89a35c30 --- /dev/null +++ b/server-beta/src/core/getlocal.lua @@ -0,0 +1,15 @@ +local m = {} + +function m:def(source, callback) + self:search(source.loc, 'local', 'def', callback) +end + +function m:ref(source, callback) + self:search(source.loc, 'local', 'ref', callback) +end + +function m:field(source, callback) + self:search(source.loc, 'local', 'field', callback) +end + +return m diff --git a/server-beta/src/core/local.lua b/server-beta/src/core/local.lua new file mode 100644 index 00000000..d3a391ad --- /dev/null +++ b/server-beta/src/core/local.lua @@ -0,0 +1,70 @@ +local m = {} + +function m:def(source, callback) + if source.tag ~= 'self' then + callback(source, 'local') + end + if source.ref then + for _, ref in ipairs(source.ref) do + if ref.type == 'setlocal' then + callback(ref, 'set') + end + end + end + if source.tag == 'self' then + local method = source.method + local node = method.node + self:eachRef(node, 'def', callback) + end +end + +function m:ref(source, callback) + if source.tag ~= 'self' then + callback(source, 'local') + end + if source.ref then + for _, ref in ipairs(source.ref) do + if ref.type == 'setlocal' then + callback(ref, 'set') + elseif ref.type == 'getlocal' then + callback(ref, 'get') + end + end + end + if source.tag == 'self' then + local method = source.method + local node = method.node + self:eachRef(node, 'ref', callback) + end +end + +function m:field(source, callback) + if source.ref then + for _, ref in ipairs(source.ref) do + if ref.type == 'getlocal' then + local parent = ref.parent + local tp = parent.type + if tp == 'setfield' + or tp == 'getfield' + or tp == 'setmethod' + or tp == 'getmethod' + or tp == 'setindex' + or tp == 'getindex' then + callback(parent) + end + elseif ref.type == 'setlocal' then + self:eachRef(ref.value, 'field', callback) + end + end + end + if source.tag == 'self' then + local method = source.method + local node = method.node + self:eachRef(node, 'field', callback) + end + if source.value then + self:eachField(source.value, nil, 'ref', callback) + end +end + +return m diff --git a/server-beta/src/core/method.lua b/server-beta/src/core/method.lua new file mode 100644 index 00000000..9217c4a3 --- /dev/null +++ b/server-beta/src/core/method.lua @@ -0,0 +1,23 @@ +local guide = require 'parser.guide' + +local m = {} + +function m:def(source, callback) + local node = source.parent.node + local key = guide.getKeyName(source) + self:eachField(node, key, 'def', callback) +end + +function m:ref(source, callback) + local node = source.parent.node + local key = guide.getKeyName(source) + self:eachField(node, key, 'ref', callback) +end + +function m:field(source, callback) + local node = source.parent.node + local key = guide.getKeyName(source) + self:eachField(node, key, 'field', callback) +end + +return m diff --git a/server-beta/src/core/number.lua b/server-beta/src/core/number.lua new file mode 100644 index 00000000..acc4436e --- /dev/null +++ b/server-beta/src/core/number.lua @@ -0,0 +1,11 @@ +local m = {} + +function m:def(source, callback) + self:asindex(source, 'def', callback) +end + +function m:ref(source, callback) + self:asindex(source, 'ref', callback) +end + +return m diff --git a/server-beta/src/core/string.lua b/server-beta/src/core/string.lua new file mode 100644 index 00000000..acc4436e --- /dev/null +++ b/server-beta/src/core/string.lua @@ -0,0 +1,11 @@ +local m = {} + +function m:def(source, callback) + self:asindex(source, 'def', callback) +end + +function m:ref(source, callback) + self:asindex(source, 'ref', callback) +end + +return m diff --git a/server-beta/src/core/table.lua b/server-beta/src/core/table.lua new file mode 100644 index 00000000..1f6c45c4 --- /dev/null +++ b/server-beta/src/core/table.lua @@ -0,0 +1,13 @@ +local m = {} + +function m:field(source, callback) + for i = 1, #source do + local src = source[i] + if src.type == 'tablefield' + or src.type == 'tableindex' then + callback(src) + end + end +end + +return m |