Class: RLTK::CG::StructType
- Inherits:
-
AggregateType
- Object
- Type
- AggregateType
- RLTK::CG::StructType
- Defined in:
- lib/rltk/cg/type.rb
Overview
A type for representing an arbitrary collection of types.
Instance Attribute Summary
Attributes included from BindingClass
Instance Method Summary collapse
-
#element_types ⇒ Array<Type>
Array of the types in this struct type.
-
#element_types=(el_types, packed = false) ⇒ void
Set the types in the body of this struct type.
-
#initialize(overloaded, name = nil, packed = false, context = nil) ⇒ StructType
constructor
Create a new struct type.
-
#name ⇒ String
Name of the struct type in LLVM IR.
Methods included from AbstractClass
Methods inherited from Type
#allignment, #context, from_ptr, #hash, #kind, #size
Methods included from BindingClass
Constructor Details
#initialize(overloaded, name = nil, packed = false, context = nil) ⇒ StructType
Create a new struct type.
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/rltk/cg/type.rb', line 364 def initialize(overloaded, name = nil, packed = false, context = nil) @ptr = case overloaded when FFI::Pointer overloaded else # Check the types of the elements of the overloaded parameter. @element_types = check_cg_array_type(overloaded, Type, 'overloaded') el_types_ptr = FFI::MemoryPointer.new(:pointer, @element_types.length) el_types_ptr.write_array_of_pointer(@element_types) if name @name = check_type(name, String, 'name') returning Bindings.struct_create_named(Context.global, @name) do |ptr| Bindings.struct_set_body(ptr, el_types_ptr, @element_types.length, packed.to_i) unless @element_types.empty? end elsif context check_type(context, Context, 'context') Bindings.struct_type_in_context(context, el_types_ptr, @element_types.length, is_packed.to_i) else Bindings.struct_type(el_types_ptr, @element_types.length, packed.to_i) end end end |
Instance Method Details
#element_types ⇒ Array<Type>
Returns Array of the types in this struct type.
395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/rltk/cg/type.rb', line 395 def element_types @element_types ||= begin num_elements = Bindings.count_struct_element_types(@ptr) ret_ptr = FFI::MemoryPointer.new(:pointer) Bindings.get_struct_element_types(@ptr, ret_ptr) types_ptr = ret_ptr.get_pointer(0) types_ptr.get_array_of_pointer(0, num_elements).map { |ptr| Type.from_ptr(ptr) } end end |
#element_types=(el_types, packed = false) ⇒ void
This method returns an undefined value.
Set the types in the body of this struct type.
415 416 417 418 419 420 421 422 |
# File 'lib/rltk/cg/type.rb', line 415 def element_types=(el_types, packed = false) @element_types = check_cg_array_type(el_types, Type, 'el_types') el_types_ptr = FFI::MemoryPointer.new(:pointer, @element_types.length) el_types_ptr.write_array_of_pointer(@element_types) Bindings.struct_set_body(@ptr, el_types_ptr, @element_types.length, packed.to_i) end |
#name ⇒ String
Returns Name of the struct type in LLVM IR.
425 426 427 |
# File 'lib/rltk/cg/type.rb', line 425 def name @name ||= Bindings.get_struct_name(@ptr) end |