Class: JavaClass::CodeAttribute

Inherits:
Attribute show all
Defined in:
lib/javaclass/attribute.rb

Overview

コード属性

Instance Attribute Summary collapse

Attributes inherited from Attribute

#java_class, #name_index

Instance Method Summary collapse

Methods inherited from Attribute

#name

Methods included from Base

#==, #===, #dump, #eql?, #hash, #to_byte

Constructor Details

#initialize(java_class, name_index, max_stack = nil, max_locals = nil, codes = [], exception_table = [], attributes = {}) ⇒ CodeAttribute

コンストラクタ

*java_class::属性の所有者であるJavaクラス *name_index::名前を示すconstant_poolのインデックス *max_stack::オペランドスタックの最大深度 *max_locals::ローカル変数の数 *codes::コード *exception_table::例外 *attributes::属性



789
790
791
792
793
794
795
796
797
# File 'lib/javaclass/attribute.rb', line 789

def initialize( java_class, name_index, max_stack=nil, \
  max_locals=nil, codes=[], exception_table=[], attributes={} )
  super( java_class, name_index)
  @max_stack = max_stack
  @max_locals = max_locals
  @codes = codes
  @exception_table = exception_table
  @attributes = attributes
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



830
831
832
# File 'lib/javaclass/attribute.rb', line 830

def attributes
  @attributes
end

#codesObject

Returns the value of attribute codes.



828
829
830
# File 'lib/javaclass/attribute.rb', line 828

def codes
  @codes
end

#exception_tableObject

Returns the value of attribute exception_table.



829
830
831
# File 'lib/javaclass/attribute.rb', line 829

def exception_table
  @exception_table
end

#max_localsObject

Returns the value of attribute max_locals.



827
828
829
# File 'lib/javaclass/attribute.rb', line 827

def max_locals
  @max_locals
end

#max_stackObject

Returns the value of attribute max_stack.



826
827
828
# File 'lib/javaclass/attribute.rb', line 826

def max_stack
  @max_stack
end

Instance Method Details

#to_bytesObject

TODO



801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
# File 'lib/javaclass/attribute.rb', line 801

def to_bytes
  bytes = super

  body = to_byte( @max_stack, 2)
  body += to_byte( @max_locals, 2)
  
  tmp = []
  @codes.each {|c|
    tmp += c.to_bytes
  }
  body += to_byte( tmp.length, 4)
  body += tmp
  
  body += to_byte( @exception_table.length, 2)
  @exception_table.each {|ex|
    body += ex.to_bytes()
  }
  body += to_byte( @attributes.length, 2)
  @attributes.each {|k,a|
    body += a.to_bytes()
  }
  bytes += to_byte( body.length, 4)
  bytes += body
end

#to_sObject



798
799
800
# File 'lib/javaclass/attribute.rb', line 798

def to_s
  # TODO
end