Class: TRuby::IR::Passes::TypeAnnotationCleanup

Inherits:
Pass
  • Object
show all
Defined in:
lib/t_ruby/ir.rb

Overview

Type annotation cleanup

Instance Attribute Summary

Attributes inherited from Pass

#changes_made, #name

Instance Method Summary collapse

Methods inherited from Pass

#run

Constructor Details

#initializeTypeAnnotationCleanup

Returns a new instance of TypeAnnotationCleanup.



1153
1154
1155
# File 'lib/t_ruby/ir.rb', line 1153

def initialize
  super("type_annotation_cleanup")
end

Instance Method Details

#transform(node) ⇒ Object



1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
# File 'lib/t_ruby/ir.rb', line 1157

def transform(node)
  case node
  when Program
    node.declarations.each { |d| transform(d) }
  when MethodDef
    # Remove redundant type annotations
    node.params.each do |param|
      if param.type_annotation && redundant_annotation?(param)
        param.type_annotation = nil
        @changes_made += 1
      end
    end
  end

  node
end