class TypeProf::Core::Type::Instance
Attributes
args[R]
mod[R]
Public Class Methods
new(genv, mod, args)
click to toggle source
: (GlobalEnv
, ModuleEntity
, ::Array[Vertex]) -> void
# File typeprof-0.30.1/lib/typeprof/core/type.rb, line 78 def initialize(genv, mod, args) raise mod.class.to_s unless mod.is_a?(ModuleEntity) @mod = mod @args = args raise unless @args.is_a?(::Array) end
Public Instance Methods
base_type(_)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/type.rb, line 87 def base_type(_) self end
check_match(genv, changes, vtx)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/type.rb, line 91 def check_match(genv, changes, vtx) vtx.each_type do |other_ty| case other_ty when Instance ty = self while ty if ty.mod == other_ty.mod args_all_match = true ty.args.zip(other_ty.args) do |arg, other_arg| unless arg.check_match(genv, changes, other_arg) args_all_match = false break end end return true if args_all_match end changes.add_depended_superclass(ty.mod) if other_ty.mod.module? return true if check_match_included_modules(genv, changes, ty, other_ty) end ty = genv.get_superclass_type(ty, changes, {}) end end end return false end
check_match_included_modules(genv, changes, ty, other_ty)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/type.rb, line 120 def check_match_included_modules(genv, changes, ty, other_ty) ty.mod.included_modules.each do |inc_decl, inc_mod| if inc_decl.is_a?(AST::SigIncludeNode) && inc_mod.type_params inc_ty = genv.get_instance_type(inc_mod, inc_decl.args, changes, {}, ty) else type_params = inc_mod.type_params.map {|ty_param| Source.new() } # TODO: better support inc_ty = Type::Instance.new(genv, inc_mod, type_params) end if inc_ty.mod == other_ty.mod args_all_match = true inc_ty.args.zip(other_ty.args) do |arg, other_arg| if other_arg && !arg.check_match(genv, changes, other_arg) args_all_match = false break end end return true if args_all_match end changes.add_depended_superclass(inc_ty.mod) return true if check_match_included_modules(genv, changes, inc_ty, other_ty) end return false end
show()
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/type.rb, line 145 def show case @mod.cpath when [:NilClass] then "nil" when [:TrueClass] then "true" when [:FalseClass] then "false" else "#{ @mod.show_cpath }#{ @args.empty? ? "" : "[#{ @args.map {|arg| Type.strip_parens(arg.show) }.join(", ") }]" }" end end