Class: Carbon::Concrete::Item::Struct Private
- Inherits:
-
Object
- Object
- Carbon::Concrete::Item::Struct
- Includes:
- Data
- Defined in:
- lib/carbon/concrete/item/struct.rb,
lib/carbon/concrete/item/struct/element.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class is frozen upon initialization. This means that any attempt to modify it will result in an error. In most cases, the attributes on this class will also be frozen, as well.
A struct data type. This is normally a sequence of elements that are stored sequentially in memory. Each element has a name, to reference which position, and a type.
Defined Under Namespace
Classes: Element
Instance Attribute Summary
Attributes included from Data
Attributes included from Base
#dependencies, #generics, #name, #type
Class Method Summary collapse
-
.from(type) ⇒ {::Symbol => ::Object}
private
Creates a hash from a given Type that can be used to intialize an instance of this object.
Instance Method Summary collapse
-
#call(build, generics) ⇒ void
private
Performs compilation for the item.
-
#initialize(data) ⇒ Struct
constructor
private
Initialize the struct with the given data.
Methods included from Base
#==, #corrected_dependencies, #define, #hash
Constructor Details
#initialize(data) ⇒ Struct
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the struct with the given data.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/carbon/concrete/item/struct.rb', line 34 def initialize(data) @type = data.fetch(:type) @generics = @type.generics @name = @type.to_s @extern = data[:extern] @implements = Set.new(data.fetch(:implements)) @dependencies = Set.new derive_elements(data.fetch(:elements)) derive_dependencies deep_freeze! end |
Class Method Details
.from(type) ⇒ {::Symbol => ::Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a hash from a given Type that can be used to intialize an instance of this object. This is mostly used for Carbon::Concrete::Index#define and shouldn't be used anywhere else.
22 23 24 |
# File 'lib/carbon/concrete/item/struct.rb', line 22 def self.from(type) { type: type, implements: [], elements: [] } end |
Instance Method Details
#call(build, generics) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Performs compilation for the item. This converts the item into an
LLVM-based value or type, to be used for compiling. If
unimplemented, it raises a NotImplementedError
.
49 50 51 52 53 54 55 56 |
# File 'lib/carbon/concrete/item/struct.rb', line 49 def call(build, generics) full = @type.sub(generics) elements = @elements.map(&:type).map { |t| t.sub(generics) } .map { |t| build.fetch(t).last } name = @extern || full.to_s build.items[full] = [self, ::LLVM::Type.struct(elements, false, name)] end |