Class: Riml::Compiler::CallNodeVisitor

Inherits:
ScopedVisitor show all
Defined in:
lib/compiler.rb

Instance Method Summary collapse

Methods inherited from Visitor

#initialize, #visit

Constructor Details

This class inherits a constructor from Riml::Compiler::Visitor

Instance Method Details

#compile(node) ⇒ Object



534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/compiler.rb', line 534

def compile(node)
  set_modifier(node) if node.name && !node.builtin_function?
  node.compiled_output =
    if node.name.respond_to?(:variable)
      node.name.accept(visitor_for_node(node.name))
      node.scope_modifier + node.name.compiled_output
    elsif DictGetDotNode === node.name
      node.name.accept(visitor_for_node(node.name))
      node.name.compiled_output
    else
      node.full_name
    end
  compile_arguments(node)
  node.compiled_output
end

#compile_arguments(node) ⇒ Object



550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/compiler.rb', line 550

def compile_arguments(node)
  node.compiled_output << if node.builtin_command?
    if node.arguments.any? then ' ' else '' end
  else
    '('
  end
  node.arguments.each_with_index do |arg, i|
    arg.parent_node = node
    arg_visitor = visitor_for_node(arg)
    arg.accept(arg_visitor)
    node.compiled_output << ", " unless last_arg?(node.arguments, i)
  end
  node.compiled_output << ")" unless node.builtin_command?
  unless node.descendant_of_control_structure? ||
         node.descendant_of_call_node? ||
         node.descendant_of_object_instantiation_node? ||
         node.descendant_of_list_node? ||
         node.descendant_of_list_or_dict_get_node? ||
         node.descendant_of_operator_node? ||
         node.descendant_of_wrap_in_parens_node? ||
         node.descendant_of_sublist_node? ||
         node.descendant_of_dict_get_dot_node? ||
         node.descendant_of_dictionary_node? ||
         node.descendant_of_curly_brace_part?
    node.force_newline = true
  end
end