Class: Riml::AST_Rewriter::ObjectInstantiationToCall

Inherits:
Riml::AST_Rewriter show all
Defined in:
lib/riml/ast_rewriter.rb

Constant Summary

Constants included from Constants

Constants::BUILTIN_COMMANDS, Constants::BUILTIN_FUNCTIONS, Constants::COMPARISON_OPERATORS, Constants::COMPILED_STRING_LOCATION, Constants::DEFINE_KEYWORDS, Constants::END_KEYWORDS, Constants::IGNORECASE_CAPABLE_OPERATORS, Constants::KEYWORDS, Constants::REGISTERS, Constants::RIML_CLASS_COMMANDS, Constants::RIML_COMMANDS, Constants::RIML_END_KEYWORDS, Constants::RIML_FILE_COMMANDS, Constants::RIML_KEYWORDS, Constants::SPECIAL_VARIABLE_PREFIXES, Constants::SPLAT_LITERAL, Constants::UNKNOWN_LOCATION_INFO, Constants::VIML_COMMANDS, Constants::VIML_END_KEYWORDS, Constants::VIML_KEYWORDS

Instance Attribute Summary

Attributes inherited from Riml::AST_Rewriter

#ast, #classes, #options

Instance Method Summary collapse

Methods inherited from Riml::AST_Rewriter

#add_SID_function!, #add_SID_function?, #do_establish_parents, #do_rewrite_on_match, #establish_parents, #initialize, #max_recursion_lvl, #reorder_includes_based_on_class_dependencies!, #resolve_class_dependencies!, #resolve_class_dependencies?, #rewrite, #rewrite_included_and_sourced_files!, #rewrite_on_match, #watch_for_class_pickup

Constructor Details

This class inherits a constructor from Riml::AST_Rewriter

Instance Method Details

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


865
866
867
# File 'lib/riml/ast_rewriter.rb', line 865

def match?(node)
  ObjectInstantiationNode === node
end

#replace(node) ⇒ Object



869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
# File 'lib/riml/ast_rewriter.rb', line 869

def replace(node)
  constructor_name = (node.call_node.scope_modifier ||
                      ClassDefinitionNode::DEFAULT_SCOPE_MODIFIER) +
                      node.call_node.name
  class_node = classes[constructor_name]
  call_node = node.call_node
  call_node.name = class_node.constructor_name
  call_node.scope_modifier = class_node.constructor.scope_modifier
  # FIXME: `replace_with` doesn't take into account this scenario!
  if CallNode === node.parent && node.parent.arguments.include?(node)
    idx = node.parent.arguments.index(node)
    node.parent.arguments[idx] = call_node
  else
    node.replace_with(call_node)
  end
end