Move to an AST like data structure #76

Merged
Aire-One merged 39 commits from feat/refactor-ast into master 2023-08-03 21:03:16 +02:00
1 changed files with 31 additions and 2 deletions
Showing only changes of commit 6441a6a50b - Show all commits

View File

@ -18,16 +18,45 @@ local function get_all_types_in_node(node: Node): { string }
parameters_types or {})
end
local function replace_in_node_type(node: Node, old_type: string, new_type: string)
if node.parameters then
for _, v in ipairs(node.parameters) do
for i, t in ipairs(v.types) do
if t == old_type then
v.types[i] = new_type
end
end
end
end
if node.types then
for i, t in ipairs(node.types) do
if t == old_type then
node.types[i] = new_type
end
end
end
if node.return_types then
for i, t in ipairs(node.return_types) do
if t == old_type then
node.return_types[i] = new_type
end
end
end
end
local record Module_Dependencies
visit: function(node: Node, mod: Node, d: Dag)
end
function Module_Dependencies.visit(node: Node, mod: Node, d: Dag)
local all_types <const> = get_all_types_in_node(node)
for _, v in ipairs(all_types) do
local dependency = d.modules[v]
for _, type_name in ipairs(all_types) do
local dependency = d.modules[type_name] or d.modules[utils.lowercase(type_name)]
if dependency then
mod.dependencies[dependency.name] = dependency.module_path
replace_in_node_type(node, dependency.module_path, dependency.name)
end
end
end