Class: Opal::Rewriters::BinaryOperatorAssignment
- Inherits:
- 
      Base
      
        - Object
- Parser::AST::Processor
- Base
- Opal::Rewriters::BinaryOperatorAssignment
 
- Defined in:
- opal/lib/opal/rewriters/binary_operator_assignment.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ConditionalSendHandler, SendHandler
Constant Summary
- GET_SET =
- ->(get_type, set_type) { ->(lhs, operation, rhs) { get_node = lhs.updated(get_type) # lhs set_node = s(:send, get_node, operation, rhs) # lhs + rhs lhs.updated(set_type, [*lhs, set_node]) # lhs = lhs + rhs } } 
- LocalVariableHandler =
        Takes lhs += rhsProduceslhs = lhs + rhs
- GET_SET[:lvar, :lvasgn] 
- InstanceVariableHandler =
        Takes @lhs += rhsProduces@lhs = @lhs + rhs
- GET_SET[:ivar, :ivasgn] 
- ConstantHandler =
        Takes LHS += rhsProducesLHS = LHS + rhs
- GET_SET[:const, :casgn] 
- GlobalVariableHandler =
        Takes $lhs += rhsProduces$lhs = $lhs + rhs
- GET_SET[:gvar, :gvasgn] 
- ClassVariableHandler =
        Takes @@lhs += rhsProduces@@lhs = @@lhs + rhs
- GET_SET[:cvar, :cvasgn] 
- HANDLERS =
- { lvasgn: LocalVariableHandler, ivasgn: InstanceVariableHandler, casgn: ConstantHandler, gvasgn: GlobalVariableHandler, cvasgn: ClassVariableHandler, send: SendHandler, csend: ConditionalSendHandler }.freeze 
- ASSIGNMENT_STRING_NODE =
- s(:str, 'assignment') 
Constants inherited from Base
Opal::Rewriters::Base::DUMMY_LOCATION
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- 
  
    
      #on_defined?(node)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Rewrites any or_asgn and and_asgn node like defined?(a ||= 1)anddefined?(a &&= 1)to a static "assignment" string node.
- 
  
    
      #on_op_asgn(node)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    lhs += rhs. 
Methods inherited from Base
#append_to_body, #begin_with_stmts, #error, #prepend_to_body, #process, #s, s, #stmts_of
Class Method Details
.new_temp ⇒ Object
| 12 13 14 15 16 | # File 'opal/lib/opal/rewriters/binary_operator_assignment.rb', line 12 def self.new_temp @@counter ||= 0 @@counter += 1 :$binary_op_recvr_tmp_#{@@counter}" end | 
.reset_tmp_counter! ⇒ Object
| 8 9 10 | # File 'opal/lib/opal/rewriters/binary_operator_assignment.rb', line 8 def self.reset_tmp_counter! @@counter = 0 end | 
Instance Method Details
#on_defined?(node) ⇒ Boolean
Rewrites any or_asgn and and_asgn node like
  defined?(a ||= 1)
and
  defined?(a &&= 1)
to a static "assignment" string node
| 131 132 133 134 135 136 137 138 | # File 'opal/lib/opal/rewriters/binary_operator_assignment.rb', line 131 def on_defined?(node) inner, _ = *node if inner.type == :op_asgn ASSIGNMENT_STRING_NODE else super(node) end end | 
#on_op_asgn(node) ⇒ Object
lhs += rhs
| 114 115 116 117 118 119 120 121 122 | # File 'opal/lib/opal/rewriters/binary_operator_assignment.rb', line 114 def on_op_asgn(node) lhs, op, rhs = *node result = HANDLERS .fetch(lhs.type) { error "cannot handle LHS type: #{lhs.type}" } .call(lhs, op, rhs) process(result) end |