Class: JvmBytecode::Attributes::Attribute
- Inherits:
-
Object
- Object
- JvmBytecode::Attributes::Attribute
- Defined in:
- lib/jvm_bytecode/attributes/attribute.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.attr_name ⇒ Object
readonly
Returns the value of attribute attr_name.
-
.locations ⇒ Object
readonly
Returns the value of attribute locations.
Instance Attribute Summary collapse
-
#cp ⇒ Object
readonly
Returns the value of attribute cp.
Class Method Summary collapse
- .decode_serial(cp, io) ⇒ Object
- .define(name: nil, location:) ⇒ Object
- .fetch(attr_name) ⇒ Object
- .locatable_at(loc) ⇒ Object
Instance Method Summary collapse
- #additional_bytecode ⇒ Object
- #bytecode ⇒ Object
-
#initialize(cp) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(cp) ⇒ Attribute
Returns a new instance of Attribute.
36 37 38 |
# File 'lib/jvm_bytecode/attributes/attribute.rb', line 36 def initialize(cp) @cp = cp end |
Class Attribute Details
.attr_name ⇒ Object (readonly)
Returns the value of attribute attr_name.
7 8 9 |
# File 'lib/jvm_bytecode/attributes/attribute.rb', line 7 def attr_name @attr_name end |
.locations ⇒ Object (readonly)
Returns the value of attribute locations.
7 8 9 |
# File 'lib/jvm_bytecode/attributes/attribute.rb', line 7 def locations @locations end |
Instance Attribute Details
#cp ⇒ Object (readonly)
Returns the value of attribute cp.
34 35 36 |
# File 'lib/jvm_bytecode/attributes/attribute.rb', line 34 def cp @cp end |
Class Method Details
.decode_serial(cp, io) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/jvm_bytecode/attributes/attribute.rb', line 25 def decode_serial(cp, io) n = io.read(2).unpack('S>').first Array.new(n) do name_index = io.read(2).unpack('S>').first fetch(cp.constant(name_index).to_s).new(cp).tap { |a| a.decode(io) } end end |
.define(name: nil, location:) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/jvm_bytecode/attributes/attribute.rb', line 9 def define(name: nil, location:) @attr_name = name || shortname.encode('UTF-8') @locations = location @@attributes ||= {} @@attributes[@attr_name] = self end |
.fetch(attr_name) ⇒ Object
17 18 19 |
# File 'lib/jvm_bytecode/attributes/attribute.rb', line 17 def fetch(attr_name) @@attributes[attr_name] || raise(Errors::AttributeError, "#{attr_name} is not implemented") end |
.locatable_at(loc) ⇒ Object
21 22 23 |
# File 'lib/jvm_bytecode/attributes/attribute.rb', line 21 def locatable_at(loc) @@attributes.select { |_, v| v.locations.include?(loc) } end |
Instance Method Details
#additional_bytecode ⇒ Object
40 41 42 |
# File 'lib/jvm_bytecode/attributes/attribute.rb', line 40 def additional_bytecode raise NotImplementedError, "#{self.class}##{__method__} is not implemented!" end |
#bytecode ⇒ Object
44 45 46 47 |
# File 'lib/jvm_bytecode/attributes/attribute.rb', line 44 def bytecode bc = additional_bytecode [cp.utf8(self.class.attr_name), bc.length].pack('S>I>') + bc end |