From 2a86ea3fc9114ca5e269dab1270d86b1fec98119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 28 Aug 2020 18:25:39 +0800 Subject: =?UTF-8?q?=E6=95=B4=E7=90=86library?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/library.lua | 21 ++++++++++++--------- script-beta/parser/guide.lua | 29 +++++++++++++++++++++++++++++ script-beta/vm/guideInterface.lua | 13 ++++++++++++- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/script-beta/library.lua b/script-beta/library.lua index 038e19fa..a1416fb4 100644 --- a/script-beta/library.lua +++ b/script-beta/library.lua @@ -258,10 +258,13 @@ end local function markLibrary(library) for _, lib in pairs(library) do lib.library = true - lib.start = 0 - lib.finish = 0 + lib.fields = {} if lib.child then - markLibrary(lib.child) + for _, child in util.sortPairs(lib.child) do + table.insert(lib.fields, child) + child.library = true + child.parent = library + end end end end @@ -269,11 +272,11 @@ end local function init() local lang = require 'language' local id = lang.id - m.global = util.container() - m.library = util.container() - m.object = util.container() - m.other = util.container() - m.custom = util.container() + m.global = {} + m.library = {} + m.object = {} + m.other = {} + m.custom = {} for libPath in (ROOT / 'libs'):list_directory() do local libName = libPath:filename():string() @@ -281,7 +284,7 @@ local function init() local libs local buf = util.loadFile(path:string()) if buf then - libs = util.container() + libs = {} xpcall(lni, log.error, buf, path:string(), {libs}) fix(libs) end diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 5fdb1e25..b16e7dcf 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -597,6 +597,9 @@ function m.getKeyName(obj) end function m.getSimpleName(obj) + if obj.library then + return ('s|%s'):format(obj.name) + end if obj.type == 'call' then local key = obj.args[2] return m.getKeyName(key) @@ -604,6 +607,8 @@ function m.getSimpleName(obj) return ('t|%p'):format(obj) elseif obj.type == 'select' then return ('v|%p'):format(obj) + elseif obj.type == 'string' then + return ('z|%p'):format(obj) end return m.getKeyName(obj) end @@ -870,6 +875,9 @@ local function buildSimpleList(obj, max) if i == limit then return nil end + while cur.type == 'paren' do + cur = cur.exp + end if cur.type == 'setfield' or cur.type == 'getfield' or cur.type == 'setmethod' @@ -898,6 +906,9 @@ local function buildSimpleList(obj, max) elseif cur.type == 'select' then list[i] = cur break + elseif cur.type == 'string' then + list[i] = cur + break elseif cur.type == 'function' or cur.type == 'main' then break @@ -1142,6 +1153,22 @@ function m.checkSameSimpleInValueOfCallMetaTable(status, call, start, queue) end end +function m.checkSameSimpleInSpecialBranch(status, obj, start, queue) + if not status.interface.index then + return + end + local results = status.interface.index(obj) + if not results then + return + end + for _, res in ipairs(results) do + queue[#queue+1] = { + obj = res, + start = start + 1, + } + end +end + function m.checkSameSimpleInArg1OfSetMetaTable(status, obj, start, queue) local args = obj.parent if not args or args.type ~= 'callargs' then @@ -1610,6 +1637,8 @@ function m.checkSameSimple(status, simple, data, mode, results, queue) m.checkSameSimpleInArg1OfSetMetaTable(status, ref, i, queue) -- 检查自己作为 setmetatable 调用的情况 m.checkSameSimpleInValueOfCallMetaTable(status, ref, i, queue) + -- 检查自己是特殊分支的情况 + m.checkSameSimpleInSpecialBranch(status, ref, i, queue) if cmode ~= 'def' then -- 检查形如 { a = f } 的情况 m.checkSameSimpleAsTableField(status, ref, i, queue) diff --git a/script-beta/vm/guideInterface.lua b/script-beta/vm/guideInterface.lua index 3ddb86ea..b21aee79 100644 --- a/script-beta/vm/guideInterface.lua +++ b/script-beta/vm/guideInterface.lua @@ -3,6 +3,7 @@ local files = require 'files' local ws = require 'workspace' local guide = require 'parser.guide' local await = require 'await' +local library = require 'library' local m = {} @@ -65,11 +66,12 @@ vm.interface = {} vm.interface.searchLevel = 0 function vm.interface.call(func, args, index) - await.delay() if func.special == 'require' and index == 1 then + await.delay() return m.require(args, index) end if func.special == 'dofile' then + await.delay() return m.dofile(args, index) end end @@ -84,6 +86,15 @@ function vm.interface.link(uri) return vm.getLinksTo(uri) end +function vm.interface.index(obj) + local tp = obj.type + local lib = library.object[tp] + if not lib then + return nil + end + return lib.fields +end + function vm.interface.cache(source, mode) await.delay() local cache = vm.getCache('cache') -- cgit v1.2.3