Class: Riml::AST_Rewriter::ClassDefinitionToFunctions::ExtendObjectWithMethods

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, #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

#extend_obj_with_methods(def_node) ⇒ Object

Ex: ‘let dogObj.bark = function(’<SNR>‘ . s:SID() . ’_s:Dog_bark’)‘



547
548
549
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
# File 'lib/riml/ast_rewriter.rb', line 547

def extend_obj_with_methods(def_node)
  constructor = ast.constructor
  extension =
    AssignNode.new('=',
      DictGetDotNode.new(
        GetVariableNode.new(nil, ast.constructor_obj_name),
        [def_node.original_name]
      ),
      CallNode.new(
        nil, 'function', [
          BinaryOperatorNode.new(
            '.',
            [
              BinaryOperatorNode.new(
                '.',
                [
                  StringNode.new('<SNR>', :s),
                  CallNode.new('s:', 'SID', []),
                ]
              ),
              StringNode.new("_s:#{def_node.name}", :s)
            ]
          )
        ]
      )
    )
  constructor.expressions << extension
  extension.parent = constructor.expressions
end

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


527
528
529
# File 'lib/riml/ast_rewriter.rb', line 527

def match?(node)
  node.instance_of?(DefMethodNode)
end

#max_recursion_lvlObject



577
578
579
# File 'lib/riml/ast_rewriter.rb', line 577

def max_recursion_lvl
  2
end

#replace(node) ⇒ Object



531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/riml/ast_rewriter.rb', line 531

def replace(node)
  def_node = node.to_def_node
  class_expressions = ast.expressions
  class_expressions.insert_after(class_expressions.nodes.last, def_node)
  def_node.parent = class_expressions
  # to remove it
  node.parent = class_expressions
  node.remove
  def_node.original_name = def_node.name.dup
  def_node.name.insert(0, "#{ast.name}_")
  def_node.sid = SIDNode.new
  reestablish_parents(def_node)
  extend_obj_with_methods(def_node)
end