From 3036d9d81a5771665e27b1bfe06662d163155b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 25 Sep 2019 17:42:54 +0800 Subject: =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/core/definition.lua | 12 ++++++++++-- server-beta/src/core/engineer.lua | 21 +++++++++++++++++++++ server-beta/src/parser/compile.lua | 12 ++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) (limited to 'server-beta/src') diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua index b15519bd..6724ca89 100644 --- a/server-beta/src/core/definition.lua +++ b/server-beta/src/core/definition.lua @@ -19,18 +19,23 @@ function m.search(state, ast, source) end function m.aslocal(state, ast, source) - engineer(ast):eachLocalRef(source, function (src, mode) + local searcher = engineer(ast) + searcher:eachLocalRef(source, function (src, mode) if mode == 'local' or mode == 'set' then state.callback(src) end end) + searcher:eachClass(source, function (src) + state.callback(src) + end) end m.asgetlocal = m.aslocal m.assetlocal = m.aslocal function m.globals(state, ast, source) - engineer(ast):eachGloablOfName(source[1], function (src, mode) + local searcher = engineer(ast) + searcher:eachGloablOfName(source[1], function (src, mode) if mode == 'set' then state.callback(src) end @@ -47,6 +52,9 @@ return function (ast, text, offset) cache = {}, } function state.callback(target, uri) + if target.start == 0 then + return + end results[#results+1] = { uri = uri or ast.uri, source = state.source, diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua index c82efa6d..a093a90a 100644 --- a/server-beta/src/core/engineer.lua +++ b/server-beta/src/core/engineer.lua @@ -87,6 +87,10 @@ function mt:isGlobal(obj) if obj.type == 'getfield' then return self:call('isGlobalField', obj) end + if obj.type == 'call' then + local d = self:call('asRawGet', obj) + return not not d + end return false end @@ -218,6 +222,23 @@ function mt:eachLocalRef(obj, callback) end end +--- 遍历class +function mt:eachClass(obj, callback) + local root = self.ast.root + if obj.type == 'setlocal' or obj.type == 'getlocal' then + local loc = root[obj.loc] + local setmethod = root[loc.method] + if setmethod then + local node = root[setmethod.node] + self:call('eachLocalRef', node, function (src, mode) + if mode == 'local' or mode == 'set' then + callback(src) + end + end) + end + end +end + return function (ast) local self = setmetatable({ step = 0, diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua index 45fd808b..407b778f 100644 --- a/server-beta/src/parser/compile.lua +++ b/server-beta/src/parser/compile.lua @@ -156,6 +156,14 @@ local vmMap = { if method then obj.method = Compile(method, id) end + value.localself = { + type = 'local', + start = 0, + finish = 0, + method = id, + effect = obj.finish, + [1] = 'self', + } obj.value = Compile(value, id) return id end, @@ -168,6 +176,10 @@ local vmMap = { Block = obj Root[#Root+1] = obj local id = #Root + if obj.localself then + Compile(obj.localself, id) + obj.localself = nil + end local args = obj.args if args then obj.args = Compile(args, id) -- cgit v1.2.3