From 580da8919f56ca2ca4e7ba52274e1e8b8b9d19c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 13 May 2021 11:37:31 +0800 Subject: stash --- script/core/infer.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'script/core') diff --git a/script/core/infer.lua b/script/core/infer.lua index 716fbcf9..14ec6be2 100644 --- a/script/core/infer.lua +++ b/script/core/infer.lua @@ -1,5 +1,6 @@ local searcher = require 'core.searcher' local config = require 'config' +local linker = require 'core.linker' local BE_LEN = {'#'} local CLASS = {'CLASS'} @@ -260,10 +261,43 @@ local function searchInfer(source, infers) infers['any'] = true return end - -- # XX -> string | table - if source.parent.type == 'unary' - and source.parent.op.type == '#' then - infers[BE_LEN] = true + if source.parent.type == 'unary' then + local op = source.parent.op.type + -- # XX -> string | table + if op == '#' then + infers[BE_LEN] = true + return + end + if op == '-' then + infers['number'] = true + return + end + if op == '~' then + infers['integer'] = true + return + end + return + end + if source.parent.type == 'binary' then + local op = source.parent.op.type + if op == '+' + or op == '-' + or op == '*' + or op == '/' + or op == '//' + or op == '^' + or op == '%' then + infers['number'] = true + return + end + if op == '<<' + or op == '>>' + or op == '~' + or op == '|' + or op == '&' then + infers['integer'] = true + return + end return end end @@ -289,6 +323,15 @@ function m.searchInfers(source) for _, def in ipairs(defs) do searchInfer(def, infers) end + local id = linker.getID(source) + if id then + local link = linker.getLinkByID(source, id) + if link and link.sources then + for _, src in ipairs(link.sources) do + searchInfer(src, infers) + end + end + end cleanInfers(infers) return infers end -- cgit v1.2.3