Class: Riml::AST_Rewriter::ClassDefinitionToFunctions::PrivateFunctionCallToPassObjExplicitly

Inherits:
Riml::AST_Rewriter
  • Object
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)


498
499
500
501
502
503
504
# File 'lib/riml/ast_rewriter.rb', line 498

def match?(node)
  CallNode === node && node.name.instance_of?(DictGetDotNode) &&
    !node.name.dict.is_a?(ListOrDictGetNode) &&
    node.name.dict.scope_modifier.nil? &&
    node.name.dict.name == 'self' &&
    (node.name.keys & ast.private_function_names).size == 1
end

#replace(node) ⇒ Object



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/riml/ast_rewriter.rb', line 506

def replace(node)
  node.scope_modifier = 's:'
  # find function that I'm in
  n = node
  until n.instance_of?(DefNode)
    n = n.parent
  end
  if n.original_name == 'initialize'
    node.arguments.unshift(GetVariableNode.new(nil, ast.constructor_obj_name))
  elsif n.private_function
    node.arguments.unshift(GetVariableNode.new('a:', ast.constructor_obj_name))
  else
    node.arguments.unshift(GetVariableNode.new(nil, 'self'))
  end
  func_name = node.name.keys.first
  node.name = "#{ast.name}_#{func_name}"
  reestablish_parents(node)
end