Class: Internal::ByteDecoder::Expression::Send

Inherits:
Internal::ByteDecoder::Expression show all
Defined in:
lib/decompiler/vm/bytedecoder.rb

Instance Attribute Summary collapse

Attributes inherited from Internal::ByteDecoder::Expression

#pc

Instance Method Summary collapse

Methods inherited from Internal::ByteDecoder::Expression

#<=>, #fmt

Constructor Details

#initialize(pc, id, has_receiver, has_parens, receiver, block, splat_last, *args) ⇒ Send

Returns a new instance of Send.



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/decompiler/vm/bytedecoder.rb', line 159

def initialize(pc, id, has_receiver, has_parens, receiver, block, splat_last, *args)
  super(pc)
  @id = id
  @is_assignment = id.to_s[-1] == ?=
  @has_receiver = has_receiver
  @has_parens = has_parens
  @receiver = receiver
  @block = block
  @splat_last = splat_last
  @args = args
end

Instance Attribute Details

#is_assignmentObject (readonly)

Returns the value of attribute is_assignment.



157
158
159
# File 'lib/decompiler/vm/bytedecoder.rb', line 157

def is_assignment
  @is_assignment
end

Instance Method Details

#precedenceObject



206
207
208
209
210
211
212
213
# File 'lib/decompiler/vm/bytedecoder.rb', line 206

def precedence
  if @has_receiver then
    if @receiver.respond_to?(:precedence) then
      return @receiver.precedence
    end
  end
  return 1
end

#to_sObject



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/decompiler/vm/bytedecoder.rb', line 171

def to_s
  s = ''
  receiver_str = @has_receiver \
    ? "#{@receiver}." \
    : nil
  args = @args.map { |x| x.to_s }
  if @splat_last then
    args[-1] = "*#{@args[-1]}"
  end
  if @is_assignment and args.size == 1 then
    s = "#{receiver_str}#{@id.to_s[0..-2]} = #{args[0]}"
  else
    open = @has_parens ? '(' : ''
    close = @has_parens ? ')' : ''
    s = "#{receiver_str}#{@id}#{open}#{args.join(', ')}#{close}"
  end
  if @block then
    # TODO: this code is duplicated elsewhere
    # TODO: handle block args
    env = Environment.new(@block.local_table)
    @block.bytedecode(env)
    expressions = env.expressions + env.stack
    expressions.sort!
    expressions.map! { |x| x.to_s }
    if expressions.length == 1 and
       expressions[0].is_a?(Literal) and
       expressions[0].value == nil then
      # empty
    else
      s << " { #{expressions.join('; ')} }"
    end
  end
  return s
end