Class: TypeProf::Core::ModuleEntity
- Inherits:
-
Object
- Object
- TypeProf::Core::ModuleEntity
- Defined in:
- lib/typeprof/core/env/module_entity.rb
Instance Attribute Summary collapse
-
#alias_decls ⇒ Object
readonly
Returns the value of attribute alias_decls.
-
#alias_target ⇒ Object
readonly
Returns the value of attribute alias_target.
-
#child_modules ⇒ Object
readonly
Returns the value of attribute child_modules.
-
#consts ⇒ Object
readonly
Returns the value of attribute consts.
-
#cpath ⇒ Object
readonly
Returns the value of attribute cpath.
-
#cvar_reads ⇒ Object
readonly
Returns the value of attribute cvar_reads.
-
#cvars ⇒ Object
readonly
Returns the value of attribute cvars.
-
#extended_modules ⇒ Object
readonly
Returns the value of attribute extended_modules.
-
#included_modules ⇒ Object
readonly
Returns the value of attribute included_modules.
-
#inner_modules ⇒ Object
readonly
Returns the value of attribute inner_modules.
-
#ivar_reads ⇒ Object
readonly
Returns the value of attribute ivar_reads.
-
#ivars ⇒ Object
readonly
Returns the value of attribute ivars.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#module_decls ⇒ Object
readonly
Returns the value of attribute module_decls.
-
#module_defs ⇒ Object
readonly
Returns the value of attribute module_defs.
-
#outer_module ⇒ Object
readonly
Returns the value of attribute outer_module.
-
#prepended_modules ⇒ Object
readonly
Returns the value of attribute prepended_modules.
-
#self_types ⇒ Object
readonly
Returns the value of attribute self_types.
-
#static_reads ⇒ Object
readonly
Returns the value of attribute static_reads.
-
#subclass_checks ⇒ Object
readonly
Returns the value of attribute subclass_checks.
-
#superclass ⇒ Object
readonly
Returns the value of attribute superclass.
-
#superclass_type_args ⇒ Object
readonly
Returns the value of attribute superclass_type_args.
-
#type_aliases ⇒ Object
readonly
Returns the value of attribute type_aliases.
-
#type_params ⇒ Object
readonly
Returns the value of attribute type_params.
Instance Method Summary collapse
- #add_alias_decl(genv, decl, target_mod) ⇒ Object
- #add_extend_decl(genv, node) ⇒ Object
- #add_extend_def(genv, node) ⇒ Object
- #add_include_decl(genv, node) ⇒ Object
- #add_include_def(genv, node) ⇒ Object
- #add_ivar_decl(genv, singleton, name, decl) ⇒ Object
- #add_module_decl(genv, decl) ⇒ Object
- #add_module_def(genv, node) ⇒ Object
- #add_prepend_decl(genv, node) ⇒ Object
- #add_prepend_def(genv, node) ⇒ Object
- #each_descendant(base_mod = nil) {|_self| ... } ⇒ Object
- #exist? ⇒ Boolean
- #find_superclass_const_read ⇒ Object
- #get_cname ⇒ Object
- #get_const(cname) ⇒ Object
- #get_cvar(name) ⇒ Object
- #get_ivar(singleton, name) ⇒ Object
- #get_method(singleton, mid) ⇒ Object
- #get_type_alias(name) ⇒ Object
- #get_vertexes(vtxs) ⇒ Object
-
#initialize(cpath, outer_module = self) ⇒ ModuleEntity
constructor
A new instance of ModuleEntity.
- #interface? ⇒ Boolean
- #module? ⇒ Boolean
- #on_ancestors_updated(genv, base_mod) ⇒ Object
- #on_inner_modules_changed(genv, changed_cname) ⇒ Object
- #on_module_added(genv) ⇒ Object
- #on_module_removed(genv) ⇒ Object
- #on_parent_modules_changed(genv) ⇒ Object
- #pretty_print(q) ⇒ Object
- #remove_alias_decl(genv, decl) ⇒ Object
- #remove_extend_decl(genv, node) ⇒ Object
- #remove_extend_def(genv, node) ⇒ Object
- #remove_include_decl(genv, node) ⇒ Object
- #remove_include_def(genv, node) ⇒ Object
- #remove_ivar_decl(genv, singleton, name, decl) ⇒ Object
- #remove_module_decl(genv, decl) ⇒ Object
- #remove_module_def(genv, node) ⇒ Object
- #remove_prepend_decl(genv, node) ⇒ Object
- #remove_prepend_def(genv, node) ⇒ Object
- #show_cpath ⇒ Object
- #update_parent(genv, origin, old_parent, new_parent_cpath) ⇒ Object
- #update_type_params ⇒ Object
Constructor Details
#initialize(cpath, outer_module = self) ⇒ ModuleEntity
Returns a new instance of ModuleEntity.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/typeprof/core/env/module_entity.rb', line 3 def initialize(cpath, outer_module = self) @cpath = cpath @module_decls = Set.empty @module_defs = Set.empty @include_decls = Set.empty @include_defs = Set.empty @prepend_decls = [] @prepend_defs = [] @extend_decls = Set.empty @extend_defs = Set.empty # `class Foo = Bar` / `module Foo = Bar` declarations attached to this entity. # Maps an alias decl to the target ModuleEntity at the time of registration. @alias_decls = {} @alias_target = nil @inner_modules = {} @outer_module = outer_module # parent modules (superclass and all modules that I include) @superclass = nil @self_types = {} @included_modules = {} @prepended_modules = {} @extended_modules = {} @basic_object = @cpath == [:BasicObject] # child modules (subclasses and all modules that include me) @child_modules = {} # class Foo[X, Y, Z] < Bar[A, B, C] @superclass_type_args = nil # A, B, C @type_params = {} # X, Y, Z @consts = {} @methods = { true => {}, false => {} } @ivars = { true => {}, false => {} } @cvars = {} @type_aliases = {} @static_reads = {} @subclass_checks = Set.empty @ivar_reads = Set.empty # should be handled in @ivars ?? @cvar_reads = Set.empty end |
Instance Attribute Details
#alias_decls ⇒ Object (readonly)
Returns the value of attribute alias_decls.
53 54 55 |
# File 'lib/typeprof/core/env/module_entity.rb', line 53 def alias_decls @alias_decls end |
#alias_target ⇒ Object (readonly)
Returns the value of attribute alias_target.
54 55 56 |
# File 'lib/typeprof/core/env/module_entity.rb', line 54 def alias_target @alias_target end |
#child_modules ⇒ Object (readonly)
Returns the value of attribute child_modules.
64 65 66 |
# File 'lib/typeprof/core/env/module_entity.rb', line 64 def child_modules @child_modules end |
#consts ⇒ Object (readonly)
Returns the value of attribute consts.
69 70 71 |
# File 'lib/typeprof/core/env/module_entity.rb', line 69 def consts @consts end |
#cpath ⇒ Object (readonly)
Returns the value of attribute cpath.
50 51 52 |
# File 'lib/typeprof/core/env/module_entity.rb', line 50 def cpath @cpath end |
#cvar_reads ⇒ Object (readonly)
Returns the value of attribute cvar_reads.
78 79 80 |
# File 'lib/typeprof/core/env/module_entity.rb', line 78 def cvar_reads @cvar_reads end |
#cvars ⇒ Object (readonly)
Returns the value of attribute cvars.
72 73 74 |
# File 'lib/typeprof/core/env/module_entity.rb', line 72 def cvars @cvars end |
#extended_modules ⇒ Object (readonly)
Returns the value of attribute extended_modules.
63 64 65 |
# File 'lib/typeprof/core/env/module_entity.rb', line 63 def extended_modules @extended_modules end |
#included_modules ⇒ Object (readonly)
Returns the value of attribute included_modules.
61 62 63 |
# File 'lib/typeprof/core/env/module_entity.rb', line 61 def included_modules @included_modules end |
#inner_modules ⇒ Object (readonly)
Returns the value of attribute inner_modules.
56 57 58 |
# File 'lib/typeprof/core/env/module_entity.rb', line 56 def inner_modules @inner_modules end |
#ivar_reads ⇒ Object (readonly)
Returns the value of attribute ivar_reads.
77 78 79 |
# File 'lib/typeprof/core/env/module_entity.rb', line 77 def ivar_reads @ivar_reads end |
#ivars ⇒ Object (readonly)
Returns the value of attribute ivars.
71 72 73 |
# File 'lib/typeprof/core/env/module_entity.rb', line 71 def ivars @ivars end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
70 71 72 |
# File 'lib/typeprof/core/env/module_entity.rb', line 70 def methods @methods end |
#module_decls ⇒ Object (readonly)
Returns the value of attribute module_decls.
51 52 53 |
# File 'lib/typeprof/core/env/module_entity.rb', line 51 def module_decls @module_decls end |
#module_defs ⇒ Object (readonly)
Returns the value of attribute module_defs.
52 53 54 |
# File 'lib/typeprof/core/env/module_entity.rb', line 52 def module_defs @module_defs end |
#outer_module ⇒ Object (readonly)
Returns the value of attribute outer_module.
57 58 59 |
# File 'lib/typeprof/core/env/module_entity.rb', line 57 def outer_module @outer_module end |
#prepended_modules ⇒ Object (readonly)
Returns the value of attribute prepended_modules.
62 63 64 |
# File 'lib/typeprof/core/env/module_entity.rb', line 62 def prepended_modules @prepended_modules end |
#self_types ⇒ Object (readonly)
Returns the value of attribute self_types.
60 61 62 |
# File 'lib/typeprof/core/env/module_entity.rb', line 60 def self_types @self_types end |
#static_reads ⇒ Object (readonly)
Returns the value of attribute static_reads.
75 76 77 |
# File 'lib/typeprof/core/env/module_entity.rb', line 75 def static_reads @static_reads end |
#subclass_checks ⇒ Object (readonly)
Returns the value of attribute subclass_checks.
76 77 78 |
# File 'lib/typeprof/core/env/module_entity.rb', line 76 def subclass_checks @subclass_checks end |
#superclass ⇒ Object (readonly)
Returns the value of attribute superclass.
59 60 61 |
# File 'lib/typeprof/core/env/module_entity.rb', line 59 def superclass @superclass end |
#superclass_type_args ⇒ Object (readonly)
Returns the value of attribute superclass_type_args.
66 67 68 |
# File 'lib/typeprof/core/env/module_entity.rb', line 66 def superclass_type_args @superclass_type_args end |
#type_aliases ⇒ Object (readonly)
Returns the value of attribute type_aliases.
73 74 75 |
# File 'lib/typeprof/core/env/module_entity.rb', line 73 def type_aliases @type_aliases end |
#type_params ⇒ Object (readonly)
Returns the value of attribute type_params.
67 68 69 |
# File 'lib/typeprof/core/env/module_entity.rb', line 67 def type_params @type_params end |
Instance Method Details
#add_alias_decl(genv, decl, target_mod) ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'lib/typeprof/core/env/module_entity.rb', line 190 def add_alias_decl(genv, decl, target_mod) on_module_added(genv) @alias_decls[decl] = target_mod @alias_target = @alias_decls.values.first ce = @outer_module.get_const(get_cname) ce.add_decl(decl) ce end |
#add_extend_decl(genv, node) ⇒ Object
226 227 228 229 |
# File 'lib/typeprof/core/env/module_entity.rb', line 226 def add_extend_decl(genv, node) @extend_decls << node genv.add_static_eval_queue(:parent_modules_changed, self) end |
#add_extend_def(genv, node) ⇒ Object
236 237 238 239 |
# File 'lib/typeprof/core/env/module_entity.rb', line 236 def add_extend_def(genv, node) @extend_defs << node genv.add_static_eval_queue(:parent_modules_changed, self) end |
#add_include_decl(genv, node) ⇒ Object
206 207 208 209 |
# File 'lib/typeprof/core/env/module_entity.rb', line 206 def add_include_decl(genv, node) @include_decls << node genv.add_static_eval_queue(:parent_modules_changed, self) end |
#add_include_def(genv, node) ⇒ Object
216 217 218 219 |
# File 'lib/typeprof/core/env/module_entity.rb', line 216 def add_include_def(genv, node) @include_defs << node genv.add_static_eval_queue(:parent_modules_changed, self) end |
#add_ivar_decl(genv, singleton, name, decl) ⇒ Object
524 525 526 527 528 529 |
# File 'lib/typeprof/core/env/module_entity.rb', line 524 def add_ivar_decl(genv, singleton, name, decl) ive = get_ivar(singleton, name) ive.add_decl(decl) ive.on_decl_changed(genv) ive end |
#add_module_decl(genv, decl) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/typeprof/core/env/module_entity.rb', line 123 def add_module_decl(genv, decl) on_module_added(genv) @module_decls << decl if @type_params update_type_params else @type_params = {} decl.params.zip(decl.params_default_types) {|name, default_type| @type_params[name] = default_type } end if decl.is_a?(AST::SigClassNode) && !@superclass_type_args @superclass_type_args = decl.superclass_args end ce = @outer_module.get_const(get_cname) ce.add_decl(decl) ce end |
#add_module_def(genv, node) ⇒ Object
176 177 178 179 180 181 182 |
# File 'lib/typeprof/core/env/module_entity.rb', line 176 def add_module_def(genv, node) on_module_added(genv) @module_defs << node ce = @outer_module.get_const(get_cname) ce.add_def(node) ce end |
#add_prepend_decl(genv, node) ⇒ Object
246 247 248 249 |
# File 'lib/typeprof/core/env/module_entity.rb', line 246 def add_prepend_decl(genv, node) @prepend_decls << node genv.add_static_eval_queue(:parent_modules_changed, self) end |
#add_prepend_def(genv, node) ⇒ Object
256 257 258 259 |
# File 'lib/typeprof/core/env/module_entity.rb', line 256 def add_prepend_def(genv, node) @prepend_defs << node genv.add_static_eval_queue(:parent_modules_changed, self) end |
#each_descendant(base_mod = nil) {|_self| ... } ⇒ Object
504 505 506 507 508 509 510 |
# File 'lib/typeprof/core/env/module_entity.rb', line 504 def each_descendant(base_mod = nil, &blk) return if base_mod == self yield self @child_modules.each_key do |child_mod| child_mod.each_descendant(base_mod || self, &blk) end end |
#exist? ⇒ Boolean
92 93 94 |
# File 'lib/typeprof/core/env/module_entity.rb', line 92 def exist? !@module_decls.empty? || !@module_defs.empty? || !@alias_decls.empty? end |
#find_superclass_const_read ⇒ Object
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/typeprof/core/env/module_entity.rb', line 296 def find_superclass_const_read return nil if @basic_object if @module_decls.empty? @module_defs.each do |mdef| case mdef when AST::ClassNode if mdef.superclass_cpath const_read = mdef.superclass_cpath.static_ret return const_read ? const_read.cpath : [] end when AST::SingletonClassNode next when AST::ModuleNode return nil when AST::StructNewNode base_cpath = mdef.struct_base_cpath return base_cpath == @cpath ? [] : base_cpath else raise end end else @module_decls.each do |mdecl| case mdecl when AST::SigClassNode if mdecl.superclass_cpath const_read = mdecl.static_ret[:superclass_cpath].last return const_read ? const_read.cpath : [] end when AST::SigModuleNode, AST::SigInterfaceNode return nil end end end return [] end |
#get_cname ⇒ Object
88 89 90 |
# File 'lib/typeprof/core/env/module_entity.rb', line 88 def get_cname @cpath.empty? ? :Object : @cpath.last end |
#get_const(cname) ⇒ Object
512 513 514 |
# File 'lib/typeprof/core/env/module_entity.rb', line 512 def get_const(cname) @consts[cname] ||= ValueEntity.new end |
#get_cvar(name) ⇒ Object
537 538 539 |
# File 'lib/typeprof/core/env/module_entity.rb', line 537 def get_cvar(name) @cvars[name] ||= ValueEntity.new end |
#get_ivar(singleton, name) ⇒ Object
520 521 522 |
# File 'lib/typeprof/core/env/module_entity.rb', line 520 def get_ivar(singleton, name) @ivars[singleton][name] ||= ValueEntity.new end |
#get_method(singleton, mid) ⇒ Object
516 517 518 |
# File 'lib/typeprof/core/env/module_entity.rb', line 516 def get_method(singleton, mid) @methods[singleton][mid] ||= MethodEntity.new end |
#get_type_alias(name) ⇒ Object
541 542 543 |
# File 'lib/typeprof/core/env/module_entity.rb', line 541 def get_type_alias(name) @type_aliases[name] ||= TypeAliasEntity.new end |
#get_vertexes(vtxs) ⇒ Object
545 546 547 548 549 550 551 552 553 |
# File 'lib/typeprof/core/env/module_entity.rb', line 545 def get_vertexes(vtxs) @inner_modules.each_value do |mod| next if self.equal?(mod) # for Object mod.get_vertexes(vtxs) end @consts.each_value do |cdef| vtxs << cdef.vtx end end |
#interface? ⇒ Boolean
84 85 86 |
# File 'lib/typeprof/core/env/module_entity.rb', line 84 def interface? @cpath.last && @cpath.last.start_with?("_") end |
#module? ⇒ Boolean
80 81 82 |
# File 'lib/typeprof/core/env/module_entity.rb', line 80 def module? !@superclass && !@basic_object end |
#on_ancestors_updated(genv, base_mod) ⇒ Object
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/typeprof/core/env/module_entity.rb', line 484 def on_ancestors_updated(genv, base_mod) # `include` and `extend` can form a cycle in valid Ruby return if base_mod == self @child_modules.each_key {|child_mod| child_mod.on_ancestors_updated(genv, base_mod || self) } @static_reads.each_value do |static_reads| static_reads.each do |static_read| genv.add_static_eval_queue(:static_read_changed, static_read) end end @methods.each do |_, methods| methods.each_value do |me| me.method_call_boxes.each do |box| genv.add_run(box) end end end @ivar_reads.each {|ivar_read| genv.add_run(ivar_read) } @cvar_reads.each {|cvar_read| genv.add_run(cvar_read) } end |
#on_inner_modules_changed(genv, changed_cname) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/typeprof/core/env/module_entity.rb', line 96 def on_inner_modules_changed(genv, changed_cname) @child_modules.each_key do |child_mod| child_mod.on_inner_modules_changed(genv, changed_cname) end if @static_reads[changed_cname] @static_reads[changed_cname].each do |static_read| genv.add_static_eval_queue(:static_read_changed, static_read) end end end |
#on_module_added(genv) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/typeprof/core/env/module_entity.rb', line 107 def on_module_added(genv) return if @cpath.empty? unless exist? genv.add_static_eval_queue(:inner_modules_changed, [@outer_module, get_cname]) end genv.add_static_eval_queue(:parent_modules_changed, self) end |
#on_module_removed(genv) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/typeprof/core/env/module_entity.rb', line 115 def on_module_removed(genv) return if @cpath.empty? genv.add_static_eval_queue(:parent_modules_changed, self) unless exist? genv.add_static_eval_queue(:inner_modules_changed, [@outer_module, get_cname]) end end |
#on_parent_modules_changed(genv) ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/typeprof/core/env/module_entity.rb', line 335 def on_parent_modules_changed(genv) any_updated = false unless @basic_object new_superclass_cpath = find_superclass_const_read new_superclass, updated = update_parent(genv, :superclass, @superclass, new_superclass_cpath) if updated @superclass = new_superclass any_updated = true end end @module_decls.each do |mdecl| case mdecl when AST::SigModuleNode mdecl.static_ret[:self_types].each_with_index do |const_reads, i| key = [mdecl, i] new_parent_cpath = const_reads.last.cpath new_self_type, updated = update_parent(genv, key, @self_types[key], new_parent_cpath) if updated if new_self_type @self_types[key] = new_self_type else @self_types.delete(key) || raise end any_updated = true end end end end @self_types.delete_if do |(origin_mdecl, origin_idx), old_mod| if @module_decls.include?(origin_mdecl) false else _new_self_type, updated = update_parent(genv, [origin_mdecl, origin_idx], old_mod, nil) any_updated ||= updated true end end @include_decls.each do |idecl| new_parent_cpath = idecl.static_ret.last.cpath new_parent, updated = update_parent(genv, idecl, @included_modules[idecl], new_parent_cpath) if updated if new_parent @included_modules[idecl] = new_parent else @included_modules.delete(idecl) || raise end any_updated = true end end @include_defs.each do |idef| new_parent_cpath = idef.static_ret ? idef.static_ret.cpath : nil new_parent, updated = update_parent(genv, idef, @included_modules[idef], new_parent_cpath) if updated if new_parent @included_modules[idef] = new_parent else @included_modules.delete(idef) || raise end any_updated = true end end @prepend_decls.each do |pdecl| new_parent_cpath = pdecl.static_ret.last.cpath new_parent, updated = update_parent(genv, pdecl, @prepended_modules[pdecl], new_parent_cpath) if updated if new_parent @prepended_modules[pdecl] = new_parent else @prepended_modules.delete(pdecl) || raise end any_updated = true end end @prepend_defs.each do |pdef| new_parent_cpath = pdef.static_ret ? pdef.static_ret.cpath : nil new_parent, updated = update_parent(genv, pdef, @prepended_modules[pdef], new_parent_cpath) if updated if new_parent @prepended_modules[pdef] = new_parent else @prepended_modules.delete(pdef) || raise end any_updated = true end end @extend_decls.each do |edecl| new_parent_cpath = edecl.static_ret.last.cpath new_parent, updated = update_parent(genv, edecl, @extended_modules[edecl], new_parent_cpath) if updated if new_parent @extended_modules[edecl] = new_parent else @extended_modules.delete(edecl) || raise end any_updated = true end end @extend_defs.each do |edef| new_parent_cpath = edef.static_ret ? edef.static_ret.cpath : nil new_parent, updated = update_parent(genv, edef, @extended_modules[edef], new_parent_cpath) if updated if new_parent @extended_modules[edef] = new_parent else @extended_modules.delete(edef) || raise end any_updated = true end end @included_modules.delete_if do |origin, old_mod| if @include_decls.include?(origin) || @include_defs.include?(origin) false else _new_parent, updated = update_parent(genv, origin, old_mod, nil) any_updated ||= updated true end end @prepended_modules.delete_if do |origin, old_mod| if @prepend_decls.include?(origin) || @prepend_defs.include?(origin) false else _new_parent, updated = update_parent(genv, origin, old_mod, nil) any_updated ||= updated true end end @extended_modules.delete_if do |origin, old_mod| if @extend_decls.include?(origin) || @extend_defs.include?(origin) false else _new_parent, updated = update_parent(genv, origin, old_mod, nil) any_updated ||= updated true end end if any_updated @subclass_checks.each do |mcall_box| genv.add_run(mcall_box) end on_ancestors_updated(genv, nil) end end |
#pretty_print(q) ⇒ Object
559 560 561 |
# File 'lib/typeprof/core/env/module_entity.rb', line 559 def pretty_print(q) q.text "#<ModuleEntity[::#{ @cpath.empty? ? "Object" : @cpath.join("::") }]>" end |
#remove_alias_decl(genv, decl) ⇒ Object
199 200 201 202 203 204 |
# File 'lib/typeprof/core/env/module_entity.rb', line 199 def remove_alias_decl(genv, decl) @outer_module.get_const(get_cname).remove_decl(decl) @alias_decls.delete(decl) || raise @alias_target = @alias_decls.values.first on_module_removed(genv) end |
#remove_extend_decl(genv, node) ⇒ Object
231 232 233 234 |
# File 'lib/typeprof/core/env/module_entity.rb', line 231 def remove_extend_decl(genv, node) @extend_decls.delete(node) || raise genv.add_static_eval_queue(:parent_modules_changed, self) end |
#remove_extend_def(genv, node) ⇒ Object
241 242 243 244 |
# File 'lib/typeprof/core/env/module_entity.rb', line 241 def remove_extend_def(genv, node) @extend_defs.delete(node) || raise genv.add_static_eval_queue(:parent_modules_changed, self) end |
#remove_include_decl(genv, node) ⇒ Object
211 212 213 214 |
# File 'lib/typeprof/core/env/module_entity.rb', line 211 def remove_include_decl(genv, node) @include_decls.delete(node) || raise genv.add_static_eval_queue(:parent_modules_changed, self) end |
#remove_include_def(genv, node) ⇒ Object
221 222 223 224 |
# File 'lib/typeprof/core/env/module_entity.rb', line 221 def remove_include_def(genv, node) @include_defs.delete(node) || raise genv.add_static_eval_queue(:parent_modules_changed, self) end |
#remove_ivar_decl(genv, singleton, name, decl) ⇒ Object
531 532 533 534 535 |
# File 'lib/typeprof/core/env/module_entity.rb', line 531 def remove_ivar_decl(genv, singleton, name, decl) ive = get_ivar(singleton, name) ive.remove_decl(decl) ive.on_decl_changed(genv) end |
#remove_module_decl(genv, decl) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/typeprof/core/env/module_entity.rb', line 144 def remove_module_decl(genv, decl) @outer_module.get_const(get_cname).remove_decl(decl) @module_decls.delete(decl) || raise update_type_params if decl.is_a?(AST::SigClassNode) && @superclass_type_args == decl.superclass_args @superclass_type_args = nil @module_decls.each do |decl| if decl.superclass_args @superclass_type_args = decl.superclass_args break end end end on_module_removed(genv) end |
#remove_module_def(genv, node) ⇒ Object
184 185 186 187 188 |
# File 'lib/typeprof/core/env/module_entity.rb', line 184 def remove_module_def(genv, node) @outer_module.get_const(get_cname).remove_def(node) @module_defs.delete(node) || raise on_module_removed(genv) end |
#remove_prepend_decl(genv, node) ⇒ Object
251 252 253 254 |
# File 'lib/typeprof/core/env/module_entity.rb', line 251 def remove_prepend_decl(genv, node) @prepend_decls.delete(node) || raise genv.add_static_eval_queue(:parent_modules_changed, self) end |
#remove_prepend_def(genv, node) ⇒ Object
261 262 263 264 |
# File 'lib/typeprof/core/env/module_entity.rb', line 261 def remove_prepend_def(genv, node) @prepend_defs.delete(node) || raise genv.add_static_eval_queue(:parent_modules_changed, self) end |
#show_cpath ⇒ Object
555 556 557 |
# File 'lib/typeprof/core/env/module_entity.rb', line 555 def show_cpath @cpath.empty? ? "Object" : @cpath.join("::" ) end |
#update_parent(genv, origin, old_parent, new_parent_cpath) ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/typeprof/core/env/module_entity.rb', line 266 def update_parent(genv, origin, old_parent, new_parent_cpath) new_parent = new_parent_cpath ? genv.resolve_cpath(new_parent_cpath) : nil if old_parent != new_parent # check circular inheritance mod = new_parent while mod if mod == self # TODO: report an "circular inheritance" error new_parent = nil break end mod = mod.superclass end if old_parent != new_parent if old_parent set = old_parent.child_modules[self] set.delete(origin) old_parent.child_modules.delete(self) if set.empty? end if new_parent set = new_parent.child_modules[self] ||= Set.empty set << origin end return [new_parent, true] end end return [new_parent, false] end |
#update_type_params ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/typeprof/core/env/module_entity.rb', line 162 def update_type_params @type_params = nil @module_decls.each do |decl| params = decl.params next unless params if !@type_params || @type_params.size < params.size @type_params = {} params.zip(decl.params_default_types) {|name, default_type| @type_params[name] = default_type } end end @type_params ||= {} # TODO: report an error if there are multiple inconsistent declarations end |