[フレーム]

Class: Opal::Rewriters::BinaryOperatorAssignment::ConditionalSendHandler

Inherits:
Opal::Rewriters::BinaryOperatorAssignment show all
Defined in:
opal/lib/opal/rewriters/binary_operator_assignment.rb

Overview

Takes recvr.meth += rhs Produces recvr.nil? ? nil : recvr.meth += rhs NOTE: Later output of this handler gets post-processed by this rewriter again using SendHandler to recvr.nil? ? nil : (recvr.meth = recvr.meth + rhs)

Constant Summary

Constants inherited from Opal::Rewriters::BinaryOperatorAssignment

ASSIGNMENT_STRING_NODE , ClassVariableHandler , ConstantHandler , GET_SET , GlobalVariableHandler , HANDLERS , InstanceVariableHandler , LocalVariableHandler

Constants inherited from Opal::Rewriters::Base

Opal::Rewriters::Base::DUMMY_LOCATION

Instance Attribute Summary

Attributes inherited from Opal::Rewriters::Base

#current_node

Class Method Summary collapse

Methods inherited from Opal::Rewriters::BinaryOperatorAssignment

new_temp , #on_defined? , #on_op_asgn , reset_tmp_counter!

Methods inherited from Opal::Rewriters::Base

#append_to_body , #begin_with_stmts , #dynamic! , #error , #on_top , #prepend_to_body , #process , s , #s , #stmts_of

Class Method Details

.call(node, lhs, operation, rhs) ⇒ Object

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'opal/lib/opal/rewriters/binary_operator_assignment.rb', line 81
def self.call(node, lhs, operation, rhs)
 recvr, meth, *args = *lhs
 recvr_tmp = new_temp
 cache_recvr = s(:lvasgn, recvr_tmp, recvr) # $tmp = recvr
 recvr = s(:js_tmp, recvr_tmp)
 recvr_is_nil = s(:send, recvr, :nil?) # recvr.nil?
 plain_send = lhs.updated(:send, [recvr, meth, *args]) # recvr.meth
 plain_op_asgn = node.updated(:op_asgn, [plain_send, operation, rhs]) # recvr.meth += rhs

 s(:begin,
 cache_recvr,
 s(:if, recvr_is_nil, # if recvr.nil?
 s(:nil), # nil
 # else
 plain_op_asgn # recvr.meth ||= rhs
 ),
 ) # end
end

AltStyle によって変換されたページ (->オリジナル) /