Class: Steep::AST::Types::Name::Applying

Inherits:
Base show all
Includes:
Helper::ChildrenLevel
Defined in:
lib/steep/ast/types/name.rb

Direct Known Subclasses

Alias, Instance, Interface

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods included from Helper::ChildrenLevel

#level_of_children

Constructor Details

#initialize(name:, args:) ⇒ Applying

Returns a new instance of Applying.



30
31
32
33
# File 'lib/steep/ast/types/name.rb', line 30

def initialize(name:, args:)
  super(name: name)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



28
29
30
# File 'lib/steep/ast/types/name.rb', line 28

def args
  @args
end

Instance Method Details

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



35
36
37
38
39
# File 'lib/steep/ast/types/name.rb', line 35

def ==(other)
  other.class == self.class &&
    other.name == name &&
    other.args == args
end

#each_child(&block) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/steep/ast/types/name.rb', line 74

def each_child(&block)
  if block
    args.each(&block)
  else
    args.each
  end
end

#free_variablesObject



66
67
68
69
70
71
72
# File 'lib/steep/ast/types/name.rb', line 66

def free_variables
  @fvs ||= Set.new().tap do |set|
    args.each do |type|
      set.merge(type.free_variables)
    end
  end
end

#hashObject



43
44
45
# File 'lib/steep/ast/types/name.rb', line 43

def hash
  @hash ||= self.class.hash ^ name.hash ^ args.hash
end

#levelObject



84
85
86
# File 'lib/steep/ast/types/name.rb', line 84

def level
  [0] + level_of_children(args)
end

#map_type(&block) ⇒ Object



88
89
90
91
92
# File 'lib/steep/ast/types/name.rb', line 88

def map_type(&block)
  args = self.args.map(&block)

  _ = self.class.new(name: self.name, args: self.args)
end

#subst(s) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/steep/ast/types/name.rb', line 55

def subst(s)
  if free_variables.intersect?(s.domain)
    _ = self.class.new(
      name: name,
      args: args.map {|a| a.subst(s) }
    )
  else
    self
  end
end

#to_sObject



47
48
49
50
51
52
53
# File 'lib/steep/ast/types/name.rb', line 47

def to_s
  if args.empty?
    "#{name}"
  else
    "#{name}[#{args.join(", ")}]"
  end
end