Class: MilkTea::Types::Struct

Inherits:
Base
  • Object
show all
Defined in:
lib/milk_tea/core/types/types.rb

Direct Known Subclasses

StructInstance, Union, VariantArmPayload

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#accept, #bitwise?, #boolean?, #float?, #integer?, #numeric?, #sendable?, #void?

Constructor Details

#initialize(name, module_name: nil, external: false, packed: false, alignment: nil, linkage_name: nil, lifetime_params: []) ⇒ Struct

Returns a new instance of Struct.



908
909
910
911
912
913
914
915
916
917
918
919
920
# File 'lib/milk_tea/core/types/types.rb', line 908

def initialize(name, module_name: nil, external: false, packed: false, alignment: nil, linkage_name: nil, lifetime_params: [])
  @name = name
  @module_name = module_name
  @external = external
  @packed = packed
  @alignment = alignment
  @linkage_name = linkage_name
  @lifetime_params = lifetime_params.freeze
  @fields = {}
  @events = {}
  @nested_types = {}
  @ast_declaration = nil
end

Instance Attribute Details

#alignmentObject (readonly)

Returns the value of attribute alignment.



905
906
907
# File 'lib/milk_tea/core/types/types.rb', line 905

def alignment
  @alignment
end

#ast_declarationObject

Returns the value of attribute ast_declaration.



906
907
908
# File 'lib/milk_tea/core/types/types.rb', line 906

def ast_declaration
  @ast_declaration
end

#externalObject (readonly)

Returns the value of attribute external.



905
906
907
# File 'lib/milk_tea/core/types/types.rb', line 905

def external
  @external
end

#lifetime_paramsObject (readonly)

Returns the value of attribute lifetime_params.



905
906
907
# File 'lib/milk_tea/core/types/types.rb', line 905

def lifetime_params
  @lifetime_params
end

#linkage_nameObject (readonly)

Returns the value of attribute linkage_name.



905
906
907
# File 'lib/milk_tea/core/types/types.rb', line 905

def linkage_name
  @linkage_name
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



905
906
907
# File 'lib/milk_tea/core/types/types.rb', line 905

def module_name
  @module_name
end

#nameObject (readonly)

Returns the value of attribute name.



905
906
907
# File 'lib/milk_tea/core/types/types.rb', line 905

def name
  @name
end

#nested_typesObject (readonly)

Returns the value of attribute nested_types.



905
906
907
# File 'lib/milk_tea/core/types/types.rb', line 905

def nested_types
  @nested_types
end

#packedObject (readonly)

Returns the value of attribute packed.



905
906
907
# File 'lib/milk_tea/core/types/types.rb', line 905

def packed
  @packed
end

Instance Method Details

#childrenObject



990
991
992
# File 'lib/milk_tea/core/types/types.rb', line 990

def children
  fields.values
end

#define_events(events) ⇒ Object



927
928
929
930
# File 'lib/milk_tea/core/types/types.rb', line 927

def define_events(events)
  @events = events.freeze
  self
end

#define_fields(fields) ⇒ Object



922
923
924
925
# File 'lib/milk_tea/core/types/types.rb', line 922

def define_fields(fields)
  @fields = fields.freeze
  self
end

#define_nested_types(nested) ⇒ Object



932
933
934
935
# File 'lib/milk_tea/core/types/types.rb', line 932

def define_nested_types(nested)
  @nested_types = nested.freeze
  self
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


970
971
972
973
974
975
976
977
978
# File 'lib/milk_tea/core/types/types.rb', line 970

def eql?(other)
  other.class == self.class &&
    other.name == name &&
    other.module_name == module_name &&
    other.external == external &&
    other.packed == packed &&
    other.alignment == alignment &&
    other.linkage_name == linkage_name
end

#event(name) ⇒ Object



955
956
957
# File 'lib/milk_tea/core/types/types.rb', line 955

def event(name)
  @events[name]
end

#eventsObject



951
952
953
# File 'lib/milk_tea/core/types/types.rb', line 951

def events
  @events
end

#field(name) ⇒ Object



947
948
949
# File 'lib/milk_tea/core/types/types.rb', line 947

def field(name)
  @fields[name]
end

#field_c_name(name) ⇒ Object



963
964
965
966
967
968
# File 'lib/milk_tea/core/types/types.rb', line 963

def field_c_name(name)
  stripped = name.delete_suffix("_")
  return stripped if stripped != name && MilkTea::KEYWORDS.key?(stripped)

  name
end

#fieldsObject



943
944
945
# File 'lib/milk_tea/core/types/types.rb', line 943

def fields
  @fields
end

#has_events?Boolean

Returns:

  • (Boolean)


959
960
961
# File 'lib/milk_tea/core/types/types.rb', line 959

def has_events?
  !@events.empty?
end

#hashObject



982
983
984
# File 'lib/milk_tea/core/types/types.rb', line 982

def hash
  [self.class, name, module_name, external, packed, alignment, linkage_name].hash
end

#set_layout(packed:, alignment:) ⇒ Object



937
938
939
940
941
# File 'lib/milk_tea/core/types/types.rb', line 937

def set_layout(packed:, alignment:)
  @packed = packed
  @alignment = alignment
  self
end

#to_sObject



986
987
988
# File 'lib/milk_tea/core/types/types.rb', line 986

def to_s
  module_name ? "#{module_name}.#{name}" : name
end