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



1254
1255
1256
# File 'lib/t_ruby/ir.rb', line 1254

def initialize
  super("type_annotation_cleanup")
end

Instance Method Details

#transform(node) ⇒ Object



1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
# File 'lib/t_ruby/ir.rb', line 1258

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