diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-12-05 17:52:03 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-12-05 17:52:03 +0800 |
commit | 14f38cf2671ce044dd2ee752b3d66dbbaf7b83aa (patch) | |
tree | f56f2d7c1d86557a6be502aa3118e00697b73dc1 /script-beta/vm | |
parent | 51185264ab76b43571689dd717b3e685d4ff9c73 (diff) | |
download | lua-language-server-14f38cf2671ce044dd2ee752b3d66dbbaf7b83aa.zip |
更新hover
Diffstat (limited to 'script-beta/vm')
-rw-r--r-- | script-beta/vm/getValue.lua | 89 |
1 files changed, 20 insertions, 69 deletions
diff --git a/script-beta/vm/getValue.lua b/script-beta/vm/getValue.lua index f4b1ff68..f6b3ff53 100644 --- a/script-beta/vm/getValue.lua +++ b/script-beta/vm/getValue.lua @@ -168,6 +168,16 @@ local function checkUnary(source) end end +local function mathCheck(a, b) + local v1 = vm.getLiteral(a, 'integer') or vm.getLiteral(a, 'number') + local v2 = vm.getLiteral(b, 'integer') or vm.getLiteral(a, 'number') + local int = vm.hasType(a, 'integer') + and vm.hasType(b, 'integer') + and not vm.hasType(a, 'number') + and not vm.hasType(b, 'number') + return int and 'integer' or 'number', v1, v2 +end + local function checkBinary(source) if source.type ~= 'binary' then return @@ -383,87 +393,37 @@ local function checkBinary(source) } -- 其他数学运算根据2侧的值决定,当2侧的值均为整数时返回整数 elseif op.type == '+' then - local v1 = vm.getLiteral(source[1], 'integer') - local v2 = vm.getLiteral(source[2], 'integer') - if v1 and v2 then - return alloc { - type = 'integer', - value = v1 + v2, - source = source, - } - end - v1 = v1 or vm.getLiteral(source[1], 'number') - v2 = v2 or vm.getLiteral(source[1], 'number') + local int, v1, v2 = mathCheck(source[1], source[2]) return alloc { - type = 'number', + type = int, value = (v1 and v2) and (v1 + v2) or nil, source = source, } elseif op.type == '-' then - local v1 = vm.getLiteral(source[1], 'integer') - local v2 = vm.getLiteral(source[2], 'integer') - if v1 and v2 then - return alloc { - type = 'integer', - value = v1 - v2, - source = source, - } - end - v1 = v1 or vm.getLiteral(source[1], 'number') - v2 = v2 or vm.getLiteral(source[1], 'number') + local int, v1, v2 = mathCheck(source[1], source[2]) return alloc { - type = 'number', + type = int, value = (v1 and v2) and (v1 - v2) or nil, source = source, } elseif op.type == '*' then - local v1 = vm.getLiteral(source[1], 'integer') - local v2 = vm.getLiteral(source[2], 'integer') - if v1 and v2 then - return alloc { - type = 'integer', - value = v1 * v2, - source = source, - } - end - v1 = v1 or vm.getLiteral(source[1], 'number') - v2 = v2 or vm.getLiteral(source[1], 'number') + local int, v1, v2 = mathCheck(source[1], source[2]) return alloc { - type = 'number', + type = int, value = (v1 and v2) and (v1 * v2) or nil, source = source, } elseif op.type == '%' then - local v1 = vm.getLiteral(source[1], 'integer') - local v2 = vm.getLiteral(source[2], 'integer') - if v1 and v2 then - return alloc { - type = 'integer', - value = v1 % v2, - source = source, - } - end - v1 = v1 or vm.getLiteral(source[1], 'number') - v2 = v2 or vm.getLiteral(source[1], 'number') + local int, v1, v2 = mathCheck(source[1], source[2]) return alloc { - type = 'number', + type = int, value = (v1 and v2) and (v1 % v2) or nil, source = source, } elseif op.type == '//' then - local v1 = vm.getLiteral(source[1], 'integer') - local v2 = vm.getLiteral(source[2], 'integer') - if v1 and v2 then - return alloc { - type = 'integer', - value = v1 // v2, - source = source, - } - end - v1 = v1 or vm.getLiteral(source[1], 'number') - v2 = v2 or vm.getLiteral(source[1], 'number') + local int, v1, v2 = mathCheck(source[1], source[2]) return alloc { - type = 'number', + type = int, value = (v1 and v2) and (v1 // v2) or nil, source = source, } @@ -479,15 +439,6 @@ local function checkValue(source) end end -local function hasTypeInResults(results, type) - for i = 1, #results do - if results[i].type == type then - return true - end - end - return false -end - local function inferByCall(results, source) if #results ~= 0 then return |