summaryrefslogtreecommitdiff
path: root/script/vm/type.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/vm/type.lua')
-rw-r--r--script/vm/type.lua45
1 files changed, 28 insertions, 17 deletions
diff --git a/script/vm/type.lua b/script/vm/type.lua
index 8b80d4f3..4cac9723 100644
--- a/script/vm/type.lua
+++ b/script/vm/type.lua
@@ -1,14 +1,14 @@
local nodeMgr = require 'vm.node'
local compiler = require 'vm.compiler'
local globalMgr = require 'vm.global-manager'
+---@class vm
+local vm = require 'vm.vm'
----@class vm.type-manager
-local m = {}
-
----@param child vm.node
----@param parent vm.node
+---@param child vm.node|string
+---@param parent vm.node|string
+---@param mark? table
---@return boolean
-function m.isSubType(child, parent, mark)
+function vm.isSubType(child, parent, mark)
if type(parent) == 'string' then
parent = globalMgr.getGlobal('type', parent)
end
@@ -16,13 +16,17 @@ function m.isSubType(child, parent, mark)
child = globalMgr.getGlobal('type', child)
end
+ if not child or not parent then
+ return false
+ end
+
if parent.type == 'global' and parent.cate == 'type' and parent.name == 'any' then
return true
end
if child.type == 'doc.type' then
for _, typeUnit in ipairs(child.types) do
- if not m.isSubType(typeUnit, parent) then
+ if not vm.isSubType(typeUnit, parent) then
return false
end
end
@@ -36,7 +40,7 @@ function m.isSubType(child, parent, mark)
if child.type == 'global' and child.cate == 'type' then
if parent.type == 'doc.type' then
for _, typeUnit in ipairs(parent.types) do
- if m.isSubType(child, typeUnit) then
+ if vm.isSubType(child, typeUnit) then
return true
end
end
@@ -58,7 +62,16 @@ function m.isSubType(child, parent, mark)
for _, set in ipairs(child:getSets()) do
if set.type == 'doc.class' and set.extends then
for _, ext in ipairs(set.extends) do
- if m.isSubType(globalMgr.getGlobal('type', ext[1]), parent, mark) then
+ if ext.type == 'doc.extends.name'
+ and vm.isSubType(globalMgr.getGlobal('type', ext[1]), parent, mark) then
+ return true
+ end
+ end
+ end
+ if set.type == 'doc.alias' and set.extends then
+ for _, ext in ipairs(set.extends.types) do
+ if ext.type == 'doc.type.name'
+ and vm.isSubType(globalMgr.getGlobal('type', ext[1]), parent, mark) then
return true
end
end
@@ -72,18 +85,18 @@ end
---@param tnode vm.node
---@param knode vm.node
-function m.getTableValue(tnode, knode)
+function vm.getTableValue(tnode, knode)
local result
for tn in nodeMgr.eachNode(tnode) do
if tn.type == 'doc.type.table' then
for _, field in ipairs(tn.fields) do
- if m.isSubType(field.name, knode) then
+ if vm.isSubType(field.name, knode) then
result = nodeMgr.mergeNode(result, compiler.compileNode(field.extends))
end
end
end
if tn.type == 'doc.type.array' then
- if m.isSubType(globalMgr.getGlobal('type', 'integer'), knode) then
+ if vm.isSubType(globalMgr.getGlobal('type', 'integer'), knode) then
result = nodeMgr.mergeNode(result, compiler.compileNode(tn.node))
end
end
@@ -106,18 +119,18 @@ end
---@param tnode vm.node
---@param vnode vm.node
-function m.getTableKey(tnode, vnode)
+function vm.getTableKey(tnode, vnode)
local result
for tn in nodeMgr.eachNode(tnode) do
if tn.type == 'doc.type.table' then
for _, field in ipairs(tn.fields) do
- if m.isSubType(field.extends, vnode) then
+ if vm.isSubType(field.extends, vnode) then
result = nodeMgr.mergeNode(result, compiler.compileNode(field.name))
end
end
end
if tn.type == 'doc.type.array' then
- if m.isSubType(tn.node, vnode) then
+ if vm.isSubType(tn.node, vnode) then
result = nodeMgr.mergeNode(result, globalMgr.getGlobal('type', 'integer'))
end
end
@@ -137,5 +150,3 @@ function m.getTableKey(tnode, vnode)
end
return result
end
-
-return m