Class: TypeProf::Core::ActualArguments

Inherits:
Object
  • Object
show all
Defined in:
lib/typeprof/core/env/method.rb

Direct Known Subclasses

ForwardingActualArguments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(positionals, splat_flags, keywords, block) ⇒ ActualArguments

Returns a new instance of ActualArguments.



27
28
29
30
31
32
# File 'lib/typeprof/core/env/method.rb', line 27

def initialize(positionals, splat_flags, keywords, block)
  @positionals = positionals
  @splat_flags = splat_flags
  @keywords = keywords
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



34
35
36
# File 'lib/typeprof/core/env/method.rb', line 34

def block
  @block
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



34
35
36
# File 'lib/typeprof/core/env/method.rb', line 34

def keywords
  @keywords
end

#positionalsObject (readonly)

Returns the value of attribute positionals.



34
35
36
# File 'lib/typeprof/core/env/method.rb', line 34

def positionals
  @positionals
end

#splat_flagsObject (readonly)

Returns the value of attribute splat_flags.



34
35
36
# File 'lib/typeprof/core/env/method.rb', line 34

def splat_flags
  @splat_flags
end

Instance Method Details

#add_box_edges(genv, box) ⇒ Object



69
70
71
72
# File 'lib/typeprof/core/env/method.rb', line 69

def add_box_edges(genv, box)
  @keywords.add_edge(genv, box) if @keywords
  @block.add_edge(genv, box) if @block
end

#get_keyword_arg(genv, changes, name) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/typeprof/core/env/method.rb', line 100

def get_keyword_arg(genv, changes, name)
  vtx = Vertex.new(self)
  @keywords.each_type do |ty|
    case ty
    when Type::Hash
      changes.add_edge(genv, ty.get_value(name), vtx)
    when Type::Record
      field_vtx = ty.get_value(name)
      changes.add_edge(genv, field_vtx, vtx) if field_vtx
    when Type::Instance
      if ty.mod == genv.mod_hash
        changes.add_edge(genv, ty.args[1], vtx)
      end
    else
      # what to do?
    end
  end
  vtx
end

#get_rest_args(genv, changes, start_rest, end_rest) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/typeprof/core/env/method.rb', line 78

def get_rest_args(genv, changes, start_rest, end_rest)
  vtxs = []

  start_rest.upto(end_rest - 1) do |i|
    a_arg = @positionals[i]
    if @splat_flags[i]
      a_arg.each_type do |ty|
        ty = ty.base_type(genv)
        if ty.is_a?(Type::Instance) && ty.mod == genv.mod_ary && ty.args[0]
          vtxs << changes.new_vertex(genv, self, ty.args[0])
        else
          "???"
        end
      end
    else
      vtxs << a_arg
    end
  end

  vtxs.uniq
end

#new_vertexes(genv, node) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/typeprof/core/env/method.rb', line 36

def new_vertexes(genv, node)
  positionals = @positionals.map {|arg| arg.new_vertex(genv, node) }
  splat_flags = @splat_flags
  keywords = @keywords ? @keywords.new_vertex(genv, node) : nil
  block = @block ? @block.new_vertex(genv, node) : nil
  ActualArguments.new(positionals, splat_flags, keywords, block)
end

#normalize_for_method_call(_genv) ⇒ Object



74
75
76
# File 'lib/typeprof/core/env/method.rb', line 74

def normalize_for_method_call(_genv)
  self
end

#prepend_positionals(positionals, splat_flags) ⇒ Object



55
56
57
58
59
# File 'lib/typeprof/core/env/method.rb', line 55

def prepend_positionals(positionals, splat_flags)
  return self if positionals.empty?

  ActualArguments.new(positionals + @positionals, splat_flags + @splat_flags, @keywords, @block)
end

#with_block(block, omittable: false) ⇒ Object



65
66
67
# File 'lib/typeprof/core/env/method.rb', line 65

def with_block(block, omittable: false)
  ActualArguments.new(@positionals, @splat_flags, @keywords, block)
end

#with_keywords(keywords) ⇒ Object



61
62
63
# File 'lib/typeprof/core/env/method.rb', line 61

def with_keywords(keywords)
  ActualArguments.new(@positionals, @splat_flags, keywords, @block)
end

#with_keywords_as_last_positional_hashObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/typeprof/core/env/method.rb', line 44

def with_keywords_as_last_positional_hash
  return self unless @keywords

  ActualArguments.new(
    @positionals + [@keywords],
    @splat_flags + [false],
    nil,
    @block,
  )
end