Class: Riml::AST_Rewriter::ClassDefinitionToFunctions::DefNodeToPrivateFunction

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

Constant Summary

Constants included from Constants

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

Instance Attribute Summary

Attributes inherited from Riml::AST_Rewriter

#ast, #classes, #rewritten_included_and_sourced_files

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, #recursive?, #rewrite, #rewrite_included_and_sourced_files!, #rewrite_on_match

Constructor Details

This class inherits a constructor from Riml::AST_Rewriter

Instance Method Details

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


261
262
263
264
# File 'lib/ast_rewriter.rb', line 261

def match?(node)
  return unless node.instance_of?(DefNode) && node.name != 'initialize'
  node.private_function = true
end

#replace(node) ⇒ Object



266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/ast_rewriter.rb', line 266

def replace(node)
  class_node = ast
  class_name = class_node.name
  node.scope_modifier = 's:'
  node.name = "#{class_name}_#{node.name}"
  node.sid = nil
  node.keywords -= ['dict']
  node.parameters.unshift(class_node.constructor_obj_name)
  # rewrite `self` in function body to a:#{class_name}Obj
  self_to_obj_argument = SelfToObjArgumentInPrivateFunction.new(node, classes, class_node)
  self_to_obj_argument.rewrite_on_match
  reestablish_parents(node)
end