Class: Carbon::Compiler::Node::EType

Inherits:
Base
  • Object
show all
Defined in:
lib/carbon/compiler/node/etype.rb,
lib/carbon/compiler/node/etype/star.rb,
lib/carbon/compiler/node/etype/option.rb

Defined Under Namespace

Classes: Option, Star

Instance Attribute Summary

Attributes inherited from Base

#children, #location

Instance Method Summary collapse

Methods inherited from Base

#[], #accept, #attributes!, #behavior?, #data, #data?, #each, #identity?, #initialize, #map!, mapping, #merge!, #type!, #update!

Constructor Details

This class inherits a constructor from Carbon::Compiler::Node::Base

Instance Method Details

#clean?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/carbon/compiler/node/etype.rb', line 29

def clean?
  children.none? { |c| c.is_a?(Base) }
end

#expand(file, typify = true) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/carbon/compiler/node/etype.rb', line 11

def expand(file, typify = true)
  catch(:invalid) { check_valid_parts(file) } or return {}
  return blank_mapping if clean?

  # now we know that children[0..-2] are all parts and children[-1] is
  # an option... we just have to expand the option now.
  children[-1].expand(file).map do |key, value|
    value = children[0..-2].concat(value)

    if typify
      { Concrete::Type.new(Concrete::Type::Name.new([key], nil)) =>
        Concrete::Type.new(Concrete::Type::Name.new(value, nil)) }
    else
      { key => value }
    end
  end.inject(:merge)
end

#to_typeObject



33
34
35
36
37
# File 'lib/carbon/compiler/node/etype.rb', line 33

def to_type
  return unless clean?
  Concrete::Type.new(Concrete::Type::Name.new(children, nil),
    location: location)
end