Class: TypeProf::Core::StaticRead

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

Direct Known Subclasses

BaseStaticRead, ScopedStaticRead

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ StaticRead

Returns a new instance of StaticRead.



3
4
5
6
7
# File 'lib/typeprof/core/env/static_read.rb', line 3

def initialize(name)
  @name = name
  @followers = Set[]
  @source_modules = Set[]
end

Instance Attribute Details

#followersObject (readonly)

Returns the value of attribute followers.



9
10
11
# File 'lib/typeprof/core/env/static_read.rb', line 9

def followers
  @followers
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/typeprof/core/env/static_read.rb', line 9

def name
  @name
end

Instance Method Details

#destroy(genv) ⇒ Object



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

def destroy(genv)
  @source_modules.each do |mod|
    mod.static_reads[@name].delete(self) || raise
  end
  @source_modules.clear
end

#propagate(genv) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/typeprof/core/env/static_read.rb', line 11

def propagate(genv)
  @followers.each do |follower|
    case follower
    when ModuleEntity
      genv.add_static_eval_queue(:parent_modules_changed, follower)
    when ScopedStaticRead
      follower.on_cbase_updated(genv)
    when Box, IsAFilter
      genv.add_run(follower)
    else
      raise follower.inspect
    end
  end
end

#resolve(genv, cref, break_object) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/typeprof/core/env/static_read.rb', line 33

def resolve(genv, cref, break_object)
  destroy(genv)

  first = true
  while cref
    scope = cref.cpath
    mod = genv.resolve_cpath(scope)
    genv.each_superclass(mod, false) do |mod, _singleton|
      break if mod == genv.mod_object && break_object

      unless @source_modules.include?(mod)
        @source_modules << mod
        (mod.static_reads[@name] ||= Set[]) << self
      end

      return if check_module(genv, mod)

      break unless first
    end
    first = false
    cref = cref.outer
  end
  resolution_failed(genv)
end