Class: Riml::AST_Rewriter::SplatsToCallFunctionInCallingContext
- Inherits:
-
Riml::AST_Rewriter
- Object
- Riml::AST_Rewriter
- Riml::AST_Rewriter::SplatsToCallFunctionInCallingContext
- Defined in:
- lib/riml/ast_rewriter.rb
Overview
Rewrite constructs like:
let animalObj = s:AnimalConstructor(*a:000)
to:
let animalObj = call('s:AnimalConstructor', a:000)
Basically, mimic Ruby’s approach to expanding lists to their constituent argument parts with ‘*’ in calling context.
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
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
833 834 835 |
# File 'lib/riml/ast_rewriter.rb', line 833 def match?(node) SplatNode === node && CallNode === node.parent end |
#replace(node) ⇒ Object
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 |
# File 'lib/riml/ast_rewriter.rb', line 837 def replace(node) call_node = node.parent is_method_call = call_node.method_call? function_name_expr = if is_method_call && call_node.super_call? BinaryOperatorNode.new('.', [ BinaryOperatorNode.new('.', [ StringNode.new('<SNR>', :s), CallNode.new('s:', 'SID', []) ]), StringNode.new("_s:#{call_node.name.keys.last}", :s) ]) else call_node.scope_modifier = 's:' if call_node.scope_modifier.nil? StringNode.new(call_node.full_name, :s) end call_node.scope_modifier = '' call_node.name = 'call' call_node.arguments = [] call_node.arguments << function_name_expr call_node.arguments << node.expression if is_method_call call_node.arguments << GetVariableNode.new(nil, 'self') end reestablish_parents(call_node) end |