Class: IDL::AST::BitField

Inherits:
Leaf
  • Object
show all
Defined in:
lib/ridl/node.rb,
lib/ridl/node.rb

Overview

BitSet

Instance Attribute Summary collapse

Attributes inherited from Leaf

#annotations, #enclosure, #intern, #name, #prefix, #scopes

Instance Method Summary collapse

Methods inherited from Leaf

#has_annotations?, #is_local?, #is_template?, #lm_name, #lm_scopes, #replace_prefix, #repository_id, #resolve, #scoped_lm_name, #scoped_name, #set_repo_id, #set_repo_version, #typename, #unescaped_name

Constructor Details

#initialize(_name, _enclosure, params) ⇒ BitField



3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
# File 'lib/ridl/node.rb', line 3129

def initialize(_name, _enclosure, params)
  super(_name, _enclosure)
  @idltype = params[:idltype]
  @bitset = params[:bitset]
  @bits = params[:bits]

  raise "Amount of bits for bitfield #{_name} must <= 64, not #{bits}" if bits > 64

  # When no IDL type has been specified for the bitfield in IDL we need to determine
  # the underlying type based on the number of bits
  if @idltype.nil?
    @idltype = IDL::Type::Boolean.new if bits == 1
    @idltype = IDL::Type::TinyShort.new if bits.between?(2,8)
    @idltype = IDL::Type::Short.new if bits.between?(9,16)
    @idltype = IDL::Type::Long.new if bits.between?(17,32)
    @idltype = IDL::Type::LongLong.new if bits.between?(33,64)
  end
  @bitset.add_bitfield(self)
end

Instance Attribute Details

#bitsObject (readonly)

Returns the value of attribute bits.



3127
3128
3129
# File 'lib/ridl/node.rb', line 3127

def bits
  @bits
end

#bitsetObject (readonly)

Returns the value of attribute bitset.



3127
3128
3129
# File 'lib/ridl/node.rb', line 3127

def bitset
  @bitset
end

#idltypeObject (readonly)

Returns the value of attribute idltype.



3127
3128
3129
# File 'lib/ridl/node.rb', line 3127

def idltype
  @idltype
end

Instance Method Details

#instantiate(instantiation_context, _enclosure) ⇒ Object



3161
3162
3163
3164
3165
3166
3167
# File 'lib/ridl/node.rb', line 3161

def instantiate(instantiation_context, _enclosure)
  # find already instantiated BitSet parent
  _bitmask = _enclosure.resolve(@bitset.name)
  raise "Unable to resolve instantiated BitSet scope for bitfield #{@bitset.name}::#{name} instantiation" unless _bitset

  super(instantiation_context, _enclosure, { bitset: _bitset, bits: @bits })
end

#marshal_dumpObject



3149
3150
3151
# File 'lib/ridl/node.rb', line 3149

def marshal_dump
  super() << @idltype << @bits << @bitset << @value
end

#marshal_load(vars) ⇒ Object



3153
3154
3155
3156
3157
3158
3159
# File 'lib/ridl/node.rb', line 3153

def marshal_load(vars)
  @value = vars.pop
  @bitset = vars.pop
  @bits = vars.pop
  @idltype = vars.pop
  super(vars)
end