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.



1292
1293
1294
# File 'lib/t_ruby/ir.rb', line 1292

def initialize
  super("type_annotation_cleanup")
end

Instance Method Details

#transform(node) ⇒ Object



1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
# File 'lib/t_ruby/ir.rb', line 1296

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