Class: Idl::StructType

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

Constant Summary

Constants inherited from Type

Type::KINDS, Type::QUALIFIERS, Type::TYPE_FROM_KIND

Instance Attribute Summary collapse

Attributes inherited from Type

#kind, #max_width, #qualifiers, #width_ast

Instance Method Summary collapse

Methods inherited from Type

#==, #ary?, #ary_type, #comparable_to?, #const?, #convertable_to?, #enum_class, #equal_to?, from_json_schema, from_typename, #global?, #integral?, #known?, #make_const, #make_const!, #make_global, #make_known, #make_signed, #mutable?, #qualify, #signed?, #sub_type, #to_idl, #to_s, #tuple_types, #width

Constructor Details

#initialize(type_name, member_types, member_names) ⇒ StructType

Returns a new instance of StructType.



617
618
619
620
621
622
# File 'lib/idlc/type.rb', line 617

def initialize(type_name, member_types, member_names)
  super(:struct)
  @type_name = type_name
  @member_types = member_types
  @member_names = member_names
end

Instance Attribute Details

#type_nameObject (readonly)

Returns the value of attribute type_name.



614
615
616
# File 'lib/idlc/type.rb', line 614

def type_name
  @type_name
end

Instance Method Details

#cloneObject



627
628
629
# File 'lib/idlc/type.rb', line 627

def clone
  StructType.new(@type_name, @member_types, @member_names)
end

#defaultObject



631
632
633
634
635
636
637
# File 'lib/idlc/type.rb', line 631

def default
  hsh = {}
  @member_types.size.times do |i|
    hsh[@member_names.fetch(i)] = @member_types.fetch(i).default
  end
  hsh
end

#member?(name) ⇒ Boolean

Returns:

  • (Boolean)


639
# File 'lib/idlc/type.rb', line 639

def member?(name) = @member_names.include?(name)

#member_type(member_name) ⇒ Object



641
642
643
644
645
646
# File 'lib/idlc/type.rb', line 641

def member_type(member_name)
  idx = @member_names.index(member_name)
  raise "No member named '#{member_name}'" if idx.nil?

  @member_types[idx]
end

#nameObject



625
# File 'lib/idlc/type.rb', line 625

def name = @type_name

#runtime?Boolean

does this struct have any members whose type depends on a runtime parameter?

Returns:

  • (Boolean)


649
650
651
# File 'lib/idlc/type.rb', line 649

def runtime?
  @member_types.any?(&:runtime?)
end