Class: Riml::AST_Rewriter::ClassDefinitionToFunctions::ExtendObjectWithMethods
- Inherits:
-
Riml::AST_Rewriter
- Object
- Riml::AST_Rewriter
- Riml::AST_Rewriter::ClassDefinitionToFunctions::ExtendObjectWithMethods
- 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
-
#extend_obj_with_methods(def_node) ⇒ Object
Ex: ‘let dogObj.bark = function(’<SNR>‘ . s:SID() . ’_s:Dog_bark’)‘.
- #match?(node) ⇒ Boolean
- #replace(node) ⇒ Object
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
#extend_obj_with_methods(def_node) ⇒ Object
Ex: ‘let dogObj.bark = function(’<SNR>‘ . s:SID() . ’_s:Dog_bark’)‘
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/ast_rewriter.rb', line 328 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
308 309 310 |
# File 'lib/ast_rewriter.rb', line 308 def match?(node) DefMethodNode === node end |
#replace(node) ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/ast_rewriter.rb', line 312 def replace(node) def_node = node.to_def_node class_expressions = ast.expressions class_expressions.insert_after(class_expressions.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 |