Class: MethodSig::YarvOptionalArgument

Inherits:
OptionalArgument show all
Defined in:
lib/decompiler/method/signature/argument.rb

Instance Attribute Summary collapse

Attributes inherited from Argument

#name

Instance Method Summary collapse

Methods inherited from OptionalArgument

#optional?

Methods inherited from Argument

#block?, #optional?, #required?, #rest?, #to_s

Constructor Details

#initialize(name, iseq, pc_start, local_idx, is_rest, is_block) ⇒ YarvOptionalArgument

Returns a new instance of YarvOptionalArgument.



69
70
71
72
73
74
75
# File 'lib/decompiler/method/signature/argument.rb', line 69

def initialize(name, iseq, pc_start, local_idx, is_rest, is_block)
  super(name, is_rest, is_block)
  @iseq = iseq
  @pc_start = pc_start
  @local_idx = local_idx
  @default = nil
end

Instance Attribute Details

#iseqObject (readonly)

Returns the value of attribute iseq.



65
66
67
# File 'lib/decompiler/method/signature/argument.rb', line 65

def iseq
  @iseq
end

#local_idxObject (readonly)

Returns the value of attribute local_idx.



67
68
69
# File 'lib/decompiler/method/signature/argument.rb', line 67

def local_idx
  @local_idx
end

#pc_startObject (readonly)

Returns the value of attribute pc_start.



66
67
68
# File 'lib/decompiler/method/signature/argument.rb', line 66

def pc_start
  @pc_start
end

Instance Method Details

#defaultObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/decompiler/method/signature/argument.rb', line 82

def default
  return @default if @default

  env = Internal::ByteDecoder::Environment.new(@iseq.local_table())
  local_table_idx = local_table_idx()
  @iseq.bytedecode(env, @pc_start) do |instr|
    RubyVM::Instruction::SETLOCAL === instr &&
    instr.operands[0] == local_table_idx
  end
  expressions = env.expressions + env.stack

  @default = expressions[0].rhs.to_s
  return @default
end

#inspectObject



77
78
79
80
# File 'lib/decompiler/method/signature/argument.rb', line 77

def inspect
  default()
  super
end

#local_table_idxObject



97
98
99
# File 'lib/decompiler/method/signature/argument.rb', line 97

def local_table_idx
  return @iseq.local_table.size - @local_idx + 1
end