Class: Internal::ByteDecoder::Expression::Infix

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, op, lhs, rhs) ⇒ Infix

Returns a new instance of Infix.



103
104
105
106
107
108
# File 'lib/decompiler/vm/bytedecoder.rb', line 103

def initialize(pc, op, lhs, rhs)
  super(pc)
  @op = op
  @lhs = lhs
  @rhs = rhs
end

Instance Attribute Details

#lhsObject (readonly)

Returns the value of attribute lhs.



100
101
102
# File 'lib/decompiler/vm/bytedecoder.rb', line 100

def lhs
  @lhs
end

#opObject (readonly)

Returns the value of attribute op.



99
100
101
# File 'lib/decompiler/vm/bytedecoder.rb', line 99

def op
  @op
end

#rhsObject (readonly)

Returns the value of attribute rhs.



101
102
103
# File 'lib/decompiler/vm/bytedecoder.rb', line 101

def rhs
  @rhs
end

Instance Method Details

#precedenceObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/decompiler/vm/bytedecoder.rb', line 114

def precedence
  case @op
  when :*, :/, :%
    return 2
  when '+'.intern, '-'.intern
    return 3
  when :<<, :>>
    return 4
  when :>, :>=, :<, :<=, :==, :===, :!=
    return 5
  when :undef
    return 6
  else
    raise ArgumentError, "Unknown op: #{@op}"
  end
end

#to_sObject



110
111
112
# File 'lib/decompiler/vm/bytedecoder.rb', line 110

def to_s
  return "#{fmt(@lhs)} #{@op} #{fmt(@rhs)}"
end