From e63ccd8fec249fdcade372f1c664733dacdc131e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 1 Nov 2022 13:31:30 +0800 Subject: cleanup --- script/vm/sign.lua | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'script/vm/sign.lua') diff --git a/script/vm/sign.lua b/script/vm/sign.lua index 21044a28..3791ca4f 100644 --- a/script/vm/sign.lua +++ b/script/vm/sign.lua @@ -260,3 +260,72 @@ function vm.createSign() }, mt) return genericMgr end + +---@class parser.object +---@field package _sign vm.sign|false|nil + +---@param source parser.object +---@param sign vm.sign +function vm.setSign(source, sign) + source._sign = sign +end + +---@param source parser.object +---@return vm.sign? +function vm.getSign(source) + if source._sign ~= nil then + return source._sign or nil + end + source._sign = false + if source.type == 'function' then + if not source.bindDocs then + return nil + end + for _, doc in ipairs(source.bindDocs) do + if doc.type == 'doc.generic' then + if not source._sign then + source._sign = vm.createSign() + break + end + end + end + if not source._sign then + return nil + end + if source.args then + for _, arg in ipairs(source.args) do + local argNode = vm.compileNode(arg) + if arg.optional then + argNode:addOptional() + end + source._sign:addSign(argNode) + end + end + end + if source.type == 'doc.type.function' + or source.type == 'doc.type.table' + or source.type == 'doc.type.array' then + local hasGeneric + guide.eachSourceType(source, 'doc.generic.name', function () + hasGeneric = true + end) + if not hasGeneric then + return nil + end + source._sign = vm.createSign() + if source.type == 'doc.type.function' then + for _, arg in ipairs(source.args) do + if arg.extends then + local argNode = vm.compileNode(arg.extends) + if arg.optional then + argNode:addOptional() + end + source._sign:addSign(argNode) + else + source._sign:addSign(vm.createNode()) + end + end + end + end + return source._sign or nil +end -- cgit v1.2.3