Class: IDL::AST::BitSet

Inherits:
Node show all
Defined in:
lib/ridl/node.rb,
lib/ridl/node.rb

Overview

BitValue

Constant Summary collapse

DEFINABLE =
[IDL::AST::BitField]

Instance Attribute Summary collapse

Attributes inherited from Leaf

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

Instance Method Summary collapse

Methods inherited from Node

#introduce, #is_definable?, #match_members, #redefine, #replace_prefix, #resolve, #select_members, #undo_introduction, #walk_members

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) ⇒ BitSet

Returns a new instance of BitSet.



3038
3039
3040
3041
3042
3043
3044
# File 'lib/ridl/node.rb', line 3038

def initialize(_name, enclosure, params)
  super(_name, enclosure)
  @bitfields = []
  @bitset_bits = 0
  @idltype = IDL::Type::BitSet.new(self)
  @base = set_base(params[:inherits])
end

Instance Attribute Details

#idltypeObject (readonly)

Returns the value of attribute idltype.



3036
3037
3038
# File 'lib/ridl/node.rb', line 3036

def idltype
  @idltype
end

Instance Method Details

#add_bitfield(n) ⇒ Object



3115
3116
3117
3118
3119
# File 'lib/ridl/node.rb', line 3115

def add_bitfield(n)
  @bitfields << n
  @bitset_bits += n.bits
  raise "Bitset size #{bitset_bits} must be between 1 and 64" unless bitset_bits.between?(1, 64)
end

#baseObject



3056
3057
3058
# File 'lib/ridl/node.rb', line 3056

def base
  @base
end

#bitfieldsObject



3111
3112
3113
# File 'lib/ridl/node.rb', line 3111

def bitfields
  @bitfields
end

#bitset_bitsObject

Total number of bits in this bitset including the optional base



3098
3099
3100
# File 'lib/ridl/node.rb', line 3098

def bitset_bits
  base.nil? ? @bitset_bits : @bitset_bits + base.bitset_bits
end

#define(_type, _name, params = {}) ⇒ Object

Override from Node base to handle anonymous bitfields



3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
# File 'lib/ridl/node.rb', line 3061

def define(_type, _name, params = {})
  unless is_definable?(_type)
    raise "#{_type} is not definable in #{self.typename}."
  end

  # All IDL definables have a name except a bitfield, that has an optional name and can
  # be anonymous
  node = search_self(_name) unless _name.nil?
  if node.nil?
    node = _type.new(_name, self, params)
    node.annotations.concat(params[:annotations])
    node.prefix = @prefix
    introduce(node) unless _name.nil? # If there is no name don't introduce it in our scope
    @children << node
  else
    if _type != node.class
      raise "#{_name} is already defined as a type of #{node.typename}"
    end

    node = redefine(node, params)
  end
  node
end

#instantiate(instantiation_context, _enclosure) ⇒ Object



3121
3122
3123
# File 'lib/ridl/node.rb', line 3121

def instantiate(instantiation_context, _enclosure)
  super(instantiation_context, _enclosure, {})
end

#marshal_dumpObject



3085
3086
3087
# File 'lib/ridl/node.rb', line 3085

def marshal_dump
  super() << @idltype << @bitset_bits << @bitfields << @base
end

#marshal_load(vars) ⇒ Object



3089
3090
3091
3092
3093
3094
3095
# File 'lib/ridl/node.rb', line 3089

def marshal_load(vars)
  @base = vars.pop
  @bitfields = vars.pop
  @bitset_bits = vars.pop
  @idltype = vars.pop
  super(vars)
end

#set_base(inherits) ⇒ Object



3046
3047
3048
3049
3050
3051
3052
3053
3054
# File 'lib/ridl/node.rb', line 3046

def set_base(inherits)
  unless inherits.nil?
    rtc = inherits.resolved_type
    unless rtc.node.is_a?(IDL::AST::BitSet)
      raise "#{typename} #{scoped_lm_name} cannot inherit from non bitset #{rtc.node.typename} #{rtc.node.scoped_lm_name}"
    end
    inherits.node
  end
end

#underlying_typeObject

Underlying type which is large enough to contain the full bitset including its base



3104
3105
3106
3107
3108
3109
# File 'lib/ridl/node.rb', line 3104

def underlying_type
  return IDL::Type::UTinyShort.new if bitset_bits.between?(1,8)
  return IDL::Type::UShort.new if bitset_bits.between?(9,16)
  return IDL::Type::ULong.new if bitset_bits.between?(17,32)
  return IDL::Type::ULongLong.new if bitset_bits.between?(33,64)
end