Skip to content

Commit

Permalink
Refactor crystal tool expand
Browse files Browse the repository at this point in the history
  - Remove `process_toplevel`, and enhance `process_type` instead
  - Use `each_value` instead of `values.each`
  • Loading branch information
makenowjust committed Feb 4, 2017
1 parent dd4958c commit 3caf689
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions src/compiler/crystal/tools/expand.cr
Expand Up @@ -76,33 +76,19 @@ module Crystal
@message = "no expansion found"
end

def process_toplevel(toplevel)
return unless toplevel

toplevel.def_instances.each_value do |typed_def|
typed_def.accept(self)
end

toplevel.types?.try &.values.each do |type|
process_type type
end
end

def process_type(type)
if type.is_a?(NamedType)
type.types?.try &.values.each do |inner_type|
return unless type

if type.is_a?(NamedType) || type.is_a?(Program) || type.is_a?(FileModule)
type.types?.try &.each_value do |inner_type|
process_type(inner_type)
end
end

process_type type.metaclass if type.metaclass != type

if type.is_a?(DefInstanceContainer)
type.def_instances.values.try do |typed_defs|
typed_defs.each do |typed_def|
typed_def.accept(self)
end
end
type.def_instances.each_value &.accept(self)
end

if type.is_a?(GenericType)
Expand All @@ -114,8 +100,8 @@ module Crystal

def process(result : Compiler::Result)
@in_defs = true
process_toplevel result.program
process_toplevel result.program.file_module?(@target_location.original_filename)
process_type result.program
process_type result.program.file_module?(@target_location.original_filename)
@in_defs = false

result.node.accept(self)
Expand Down

0 comments on commit 3caf689

Please sign in to comment.