Class: Idl::BitfieldType

Inherits:
Type
  • Object
show all
Defined in:
lib/idl/type.rb

Instance Method Summary collapse

Constructor Details

#initialize(type_name, width, field_names, field_ranges) ⇒ BitfieldType

Returns a new instance of BitfieldType.



577
578
579
580
581
582
583
584
# File 'lib/idl/type.rb', line 577

def initialize(type_name, width, field_names, field_ranges)
  super(:bitfield, name: type_name, width:)

  @field_names = field_names
  @field_ranges = field_ranges
  raise "unexpected" unless field_names.is_a?(Array)
  raise "unexpected" unless field_ranges.is_a?(Array) && field_names.length == field_ranges.length
end

Instance Method Details

#cloneObject



597
598
599
600
601
602
603
604
# File 'lib/idl/type.rb', line 597

def clone
  BitfieldType.new(
    name,
    width,
    field_names,
    @field_ranges
  )
end

#field_namesObject



593
594
595
# File 'lib/idl/type.rb', line 593

def field_names
  @field_names
end

#range(field_name) ⇒ Object



586
587
588
589
590
591
# File 'lib/idl/type.rb', line 586

def range(field_name)
  i = @field_names.index(field_name)
  raise "Could not find #{field_name} in #{@name}" if i.nil?

  @field_ranges[i]
end