Class: TypeProf::Scratch::ClassDef
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/typeprof/analyzer.rb |
Overview
or ModuleDef
Class Method Summary
Instance Attribute Summary
- #absolute_path readonly
- #cvars readonly
- #ivars readonly
- #kind readonly
- #klass_obj rw
- #methods readonly
- #modules readonly
- #name rw
- #subclasses readonly
- #superclass readonly
Instance Method Summary
- #add_class_open(name, open_ep)
- #add_constant(name, ty, def_ep)
- #add_method(mid, singleton, mdef)
- #adjust_substitution(singleton, mid, mthd, subst, direct) {|subst, direct| ... }
- #adjust_substitution_for_module(mods, mid, mthd, subst, &blk)
- #check_typed(mid, singleton, klass)
- #check_typed_attr(mid, singleton)
- #check_typed_method(mid, singleton)
- #consts
- #get_constant(name)
- #mix_module(kind, mod, type_args, singleton, absolute_path)
- #search_method(singleton, mid, visited) {|mthds, @klass_obj, singleton| ... }
- #set_method(mid, singleton, mdef)
Constructor Details
.new(kind, name, absolute_path, superclass) ⇒ ClassDef
# File 'lib/typeprof/analyzer.rb', line 348
def initialize(kind, name, absolute_path, superclass) raise unless name.is_a?(Array) @kind = kind @modules = { :before => { true => [], false => [] }, # before = include/extend :after => { true => [], false => [] }, # after = prepend } @name = name @consts = {} @methods = {} @ivars = VarTable.new @cvars = VarTable.new @absolute_path = absolute_path @namespace = nil @superclass = superclass @subclasses = [] end
Instance Attribute Details
#absolute_path (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 366
attr_reader :kind, :modules, :methods, :ivars, :cvars, :absolute_path, :superclass, :subclasses
#cvars (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 366
attr_reader :kind, :modules, :methods, :ivars, :cvars, :absolute_path, :superclass, :subclasses
#ivars (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 366
attr_reader :kind, :modules, :methods, :ivars, :cvars, :absolute_path, :superclass, :subclasses
#kind (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 366
attr_reader :kind, :modules, :methods, :ivars, :cvars, :absolute_path, :superclass, :subclasses
#klass_obj (rw)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 367
attr_accessor :name, :klass_obj
#methods (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 366
attr_reader :kind, :modules, :methods, :ivars, :cvars, :absolute_path, :superclass, :subclasses
#modules (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 366
attr_reader :kind, :modules, :methods, :ivars, :cvars, :absolute_path, :superclass, :subclasses
#name (rw)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 367
attr_accessor :name, :klass_obj
#subclasses (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 366
attr_reader :kind, :modules, :methods, :ivars, :cvars, :absolute_path, :superclass, :subclasses
#superclass (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 366
attr_reader :kind, :modules, :methods, :ivars, :cvars, :absolute_path, :superclass, :subclasses
Instance Method Details
#add_class_open(name, open_ep)
[ GitHub ]#add_constant(name, ty, def_ep)
[ GitHub ]#add_method(mid, singleton, mdef)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 466
def add_method(mid, singleton, mdef) @methods[[singleton, mid]] ||= Utils::MutableSet.new @methods[[singleton, mid]] << mdef # Need to restart...? end
#adjust_substitution(singleton, mid, mthd, subst, direct) {|subst, direct| ... }
# File 'lib/typeprof/analyzer.rb', line 424
def adjust_substitution(singleton, mid, mthd, subst, direct, &blk) adjust_substitution_for_module(@modules[:before][singleton], mid, mthd, subst, &blk) mthds = @methods[[singleton, mid]] yield subst, direct if mthds&.include?(mthd) adjust_substitution_for_module(@modules[:after][singleton], mid, mthd, subst, &blk) end
#adjust_substitution_for_module(mods, mid, mthd, subst, &blk)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 411
def adjust_substitution_for_module(mods, mid, mthd, subst, &blk) mods.each do |mod_def, type_args,| if mod_def.klass_obj.type_params && type_args subst2 = {} mod_def.klass_obj.type_params.zip(type_args) do |(tyvar, *), tyarg| tyvar = Type::Var.new(tyvar) subst2[tyvar] = tyarg.substitute(subst, Config.current. [:type_depth_limit]) end mod_def.adjust_substitution(false, mid, mthd, subst2, false, &blk) end end end
#check_typed(mid, singleton, klass)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 450
def check_typed(mid, singleton, klass) set = @methods[[singleton, mid]] return nil unless set set = set.select {|mdef| mdef.is_a?(klass) } return nil if set.empty? return set end
#check_typed_attr(mid, singleton)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 462
def check_typed_attr(mid, singleton) check_typed(mid, singleton, TypedAttrMethodDef) end
#check_typed_method(mid, singleton)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 458
def check_typed_method(mid, singleton) check_typed(mid, singleton, TypedMethodDef) end
#consts
[ GitHub ]#get_constant(name)
[ GitHub ]#mix_module(kind, mod, type_args, singleton, absolute_path)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 369
def mix_module(kind, mod, type_args, singleton, absolute_path) mod_, module_type_args, absolute_paths = @modules[kind][singleton].find {|m,| m == mod } if mod_ raise "inconsistent #{ kind == :after ? "include/extend" : "prepend" } type args in RBS?" if module_type_args != type_args && type_args != [] && type_args != nil else absolute_paths = Utils::MutableSet.new @modules[kind][singleton].unshift([mod, type_args, absolute_paths]) end absolute_paths << absolute_path end
#search_method(singleton, mid, visited) {|mthds, @klass_obj, singleton| ... }
# File 'lib/typeprof/analyzer.rb', line 433
def search_method(singleton, mid, visited, &blk) # Currently, circular inclusion of modules is allowed return if visited[self] visited[self] = true @modules[:before][singleton].each do |mod_def,| mod_def.search_method(false, mid, visited, &blk) end mthds = @methods[[singleton, mid]] yield mthds, @klass_obj, singleton if mthds @modules[:after][singleton].each do |mod_def,| mod_def.search_method(false, mid, visited, &blk) end end
#set_method(mid, singleton, mdef)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 472
def set_method(mid, singleton, mdef) if mdef @methods[[singleton, mid]] = Utils::MutableSet.new @methods[[singleton, mid]] << mdef else @methods.delete([singleton, mid]) end end