t-ruby 0.0.35 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/t_ruby/ir.rb CHANGED
@@ -314,7 +314,7 @@ module TRuby
314
314
  attr_accessor :kind, :condition, :body
315
315
 
316
316
  # kind: :while, :until, :loop
317
- def initialize(kind:, condition: nil, body:, **opts)
317
+ def initialize(kind:, body:, condition: nil, **opts)
318
318
  super(**opts)
319
319
  @kind = kind
320
320
  @condition = condition
@@ -424,7 +424,7 @@ module TRuby
424
424
  class Lambda < Node
425
425
  attr_accessor :params, :body, :return_type
426
426
 
427
- def initialize(params: [], body:, return_type: nil, **opts)
427
+ def initialize(body:, params: [], return_type: nil, **opts)
428
428
  super(**opts)
429
429
  @params = params
430
430
  @body = body
@@ -457,7 +457,7 @@ module TRuby
457
457
  class RescueClause < Node
458
458
  attr_accessor :exception_types, :variable, :body
459
459
 
460
- def initialize(exception_types: [], variable: nil, body:, **opts)
460
+ def initialize(body:, exception_types: [], variable: nil, **opts)
461
461
  super(**opts)
462
462
  @exception_types = exception_types
463
463
  @variable = variable
@@ -523,11 +523,11 @@ module TRuby
523
523
  end
524
524
 
525
525
  def to_rbs
526
- "#{@base}[#{@type_args.map(&:to_rbs).join(', ')}]"
526
+ "#{@base}[#{@type_args.map(&:to_rbs).join(", ")}]"
527
527
  end
528
528
 
529
529
  def to_trb
530
- "#{@base}<#{@type_args.map(&:to_trb).join(', ')}>"
530
+ "#{@base}<#{@type_args.map(&:to_trb).join(", ")}>"
531
531
  end
532
532
  end
533
533
 
@@ -571,7 +571,7 @@ module TRuby
571
571
  class FunctionType < TypeNode
572
572
  attr_accessor :param_types, :return_type
573
573
 
574
- def initialize(param_types: [], return_type:, **opts)
574
+ def initialize(return_type:, param_types: [], **opts)
575
575
  super(**opts)
576
576
  @param_types = param_types
577
577
  @return_type = return_type
@@ -598,11 +598,11 @@ module TRuby
598
598
  end
599
599
 
600
600
  def to_rbs
601
- "[#{@element_types.map(&:to_rbs).join(', ')}]"
601
+ "[#{@element_types.map(&:to_rbs).join(", ")}]"
602
602
  end
603
603
 
604
604
  def to_trb
605
- "[#{@element_types.map(&:to_trb).join(', ')}]"
605
+ "[#{@element_types.map(&:to_trb).join(", ")}]"
606
606
  end
607
607
  end
608
608
 
@@ -648,7 +648,7 @@ module TRuby
648
648
 
649
649
  class Visitor
650
650
  def visit(node)
651
- method_name = "visit_#{node.class.name.split('::').last.gsub(/([A-Z])/, '_\1').downcase.sub(/^_/, '')}"
651
+ method_name = "visit_#{node.class.name.split("::").last.gsub(/([A-Z])/, '_\1').downcase.sub(/^_/, "")}"
652
652
  if respond_to?(method_name)
653
653
  send(method_name, node)
654
654
  else
@@ -676,11 +676,9 @@ module TRuby
676
676
 
677
677
  # Build IR from parser output
678
678
  def build(parse_result, source: nil)
679
- declarations = []
680
-
681
679
  # Build type aliases
682
- (parse_result[:type_aliases] || []).each do |alias_info|
683
- declarations << build_type_alias(alias_info)
680
+ declarations = (parse_result[:type_aliases] || []).map do |alias_info|
681
+ build_type_alias(alias_info)
684
682
  end
685
683
 
686
684
  # Build interfaces
@@ -802,7 +800,7 @@ module TRuby
802
800
  depth -= 1
803
801
  current += char
804
802
  when ","
805
- if depth == 0
803
+ if depth.zero?
806
804
  args << parse_type(current.strip)
807
805
  current = ""
808
806
  else
@@ -912,7 +910,7 @@ module TRuby
912
910
  private
913
911
 
914
912
  def emit(text)
915
- @output << (" " * @indent + text)
913
+ @output << ((" " * @indent) + text)
916
914
  end
917
915
 
918
916
  def emit_comment(text)
@@ -1008,7 +1006,7 @@ module TRuby
1008
1006
  private
1009
1007
 
1010
1008
  def emit(text)
1011
- @output << (" " * @indent + text)
1009
+ @output << ((" " * @indent) + text)
1012
1010
  end
1013
1011
  end
1014
1012
 
@@ -1141,12 +1139,11 @@ module TRuby
1141
1139
  when "+" then left + right
1142
1140
  when "-" then left - right
1143
1141
  when "*" then left * right
1144
- when "/" then right != 0 ? left / right : nil
1145
- when "%" then right != 0 ? left % right : nil
1146
- when "**" then left ** right
1147
- else nil
1142
+ when "/" then right.zero? ? nil : left / right
1143
+ when "%" then right.zero? ? nil : left % right
1144
+ when "**" then left**right
1148
1145
  end
1149
- rescue
1146
+ rescue StandardError
1150
1147
  nil
1151
1148
  end
1152
1149
  end
@@ -1176,7 +1173,7 @@ module TRuby
1176
1173
 
1177
1174
  private
1178
1175
 
1179
- def redundant_annotation?(param)
1176
+ def redundant_annotation?(_param)
1180
1177
  # Consider annotation redundant if it matches the default/inferred type
1181
1178
  false
1182
1179
  end
@@ -1264,7 +1261,7 @@ module TRuby
1264
1261
  Passes::DeadCodeElimination,
1265
1262
  Passes::ConstantFolding,
1266
1263
  Passes::TypeAnnotationCleanup,
1267
- Passes::UnusedDeclarationRemoval
1264
+ Passes::UnusedDeclarationRemoval,
1268
1265
  ].freeze
1269
1266
 
1270
1267
  attr_reader :passes, :stats
@@ -1291,7 +1288,7 @@ module TRuby
1291
1288
  end
1292
1289
 
1293
1290
  @stats[:total_changes] += changes_this_iteration
1294
- break if changes_this_iteration == 0
1291
+ break if changes_this_iteration.zero?
1295
1292
  end
1296
1293
 
1297
1294
  { program: program, stats: @stats }