Module: Carbon::Concrete::Item::Base

Included in:
Data, Function, Trait
Defined in:
lib/carbon/concrete/item/base.rb

Overview

A "base" for other items. This just has some common methods that all items need to share to be compatible with the index. This module is the bases of the build system in the Carbon::Concrete module.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dependenciesSet<Request> (readonly)

The dependencies that this item is based on. These are requests because we request the item from the index as a dependency. Requests contain the module name that it builds and the generics it requires.

Examples:

item.dependencies # => Set[#<Carbon::Concrete::Request T>]

Returns:

  • (Set<Request>)


51
52
53
# File 'lib/carbon/concrete/item/base.rb', line 51

def dependencies
  @dependencies
end

#generics<Type::Generic> (readonly)

Returns the generic information associated with this item. This is used internally for generic substitution later on.

Examples:

item.generics # => [#<Carbon::Concrcete::Type::Generic T>]

Returns:



40
41
42
# File 'lib/carbon/concrete/item/base.rb', line 40

def generics
  @generics
end

#name::String (readonly)

Returns the full name of the item. This can include generic information.

Examples:

item.name # => "Carbon::Pointer<T>"

Returns:

  • (::String)


31
32
33
# File 'lib/carbon/concrete/item/base.rb', line 31

def name
  @name
end

#typeConcrete::Type (readonly)

Returns the type of the item. This is the full Type.

Examples:

For a module.

item.name # => "Carbon::Pointer<T>"
item.type # => #<Carbon::Type Carbon::Pointer<T>>

For a function.

item.name
  # => "Carbon::Pointer<T>.+(Carbon::Pointer<T>, Carbon::Int32)"
item.intern
  # => #<Carbon::Type Carbon::Pointer.+(Carbon::Pointer, Carbon::Int32)>

Returns:



23
24
25
# File 'lib/carbon/concrete/item/base.rb', line 23

def type
  @type
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.

Parameters:

Returns:

  • ({::Symbol => ::Object})


60
61
62
# File 'lib/carbon/concrete/item/base.rb', line 60

def self.from(type)
  { type: type }
end

Instance Method Details

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

Compares this item to another object. If the other object is this item, then it returns true; otherwise, it returns false.

Examples:

first.type # => "Carbon::Pointer<T>"
second.type # => "Carbon::Pointer<T>"
first == first # => true
first == second # => true
second == second # => true
second == first # => true

Parameters:

  • other (Base, ::Object)

    The object to compare.

Returns:

  • (::Boolean)

    The result of comparison.



77
78
79
# File 'lib/carbon/concrete/item/base.rb', line 77

def ==(other)
  equal?(other)
end

#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.

Parameters:

Raises:

  • (NotImplementedError)

    If it is not implemented.



103
104
105
# File 'lib/carbon/concrete/item/base.rb', line 103

def call(build, generics)
  fail NotImplementedError, "Could not build #{self.class}"
end

#corrected_dependencies(request) {|dep| ... } ⇒ ::Enumerable, 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.

Modifies the dependencies of this item so that they conform to the given request. This should resolve all of our dependencies so that they no longer hold any sort of generic class.

Parameters:

  • request (Request)

    The request.

Yields:

  • (dep)

    The corrected dependencies.

Yield Parameters:

  • dep (Request)

    The corrected dependency.

Returns:

  • (::Enumerable)

    An enumerator of the corrected dependencies, if no block was given.

  • (void)

    If a block was given.



129
130
131
132
133
134
# File 'lib/carbon/concrete/item/base.rb', line 129

def corrected_dependencies(request, &block)
  return to_enum(:corrected_dependencies, request) unless block_given?
  return dependencies.each(&block) if generics.empty?

  forced_corrected_dependencies(request, &block)
end

#define(index) ⇒ Concrete::Item::Base

Performs modification to the item. This is done after all items are loaded into the index, so that an item can load outside information if need be.

Parameters:

Returns:



114
115
116
# File 'lib/carbon/concrete/item/base.rb', line 114

def define(index)
  self
end

#hashNumeric

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 of the item. This is used mostly in the Hash class.

Returns:

  • (Numeric)


87
88
89
# File 'lib/carbon/concrete/item/base.rb', line 87

def hash
  type.hash
end