class Riml::AST_Rewriter::SplatsToCallFunctionInCallingContext

Rewrite constructs like:

let animalObj = s:AnimalConstructor(*a:000)

to:

let animalObj = call('s:AnimalConstructor', a:000)

Basically, mimic Ruby’s approach to expanding lists to their constituent argument parts with ‘*’ in calling context.

Public Instance Methods

match?(node) click to toggle source
# File lib/riml/ast_rewriter.rb, line 833
def match?(node)
  SplatNode === node && CallNode === node.parent
end
replace(node) click to toggle source
# File lib/riml/ast_rewriter.rb, line 837
def replace(node)
  call_node = node.parent
  is_method_call = call_node.method_call?
  function_name_expr = if is_method_call && call_node.super_call?
    BinaryOperatorNode.new('.', [
      BinaryOperatorNode.new('.', [
        StringNode.new('<SNR>', :s), CallNode.new('s:', 'SID', [])
      ]),
      StringNode.new("_s:#{call_node.name.keys.last}", :s)
    ])
  else
    call_node.scope_modifier = 's:' if call_node.scope_modifier.nil?
    StringNode.new(call_node.full_name, :s)
  end
  call_node.scope_modifier = ''
  call_node.name = 'call'
  call_node.arguments = []
  call_node.arguments << function_name_expr
  call_node.arguments << node.expression
  if is_method_call
    call_node.arguments << GetVariableNode.new(nil, 'self')
  end
  reestablish_parents(call_node)
end