class TypeProf::Core::AST::SigFuncType::SigTyAliasNode::SigTyUnionNode::SigTySingletonNode::SigTyInstanceNode
Attributes
args[R]
cpath[R]
toplevel[R]
Public Class Methods
new(raw_decl, lenv)
click to toggle source
Calls superclass method
TypeProf::Core::AST::Node::new
# File typeprof-0.30.1/lib/typeprof/core/ast/sig_type.rb, line 391 def initialize(raw_decl, lenv) super(raw_decl, lenv) name = raw_decl.name @cpath = name.namespace.path + [name.name] @toplevel = name.namespace.absolute? # "::Foo" or "Foo" @args = raw_decl.args.map {|arg| AST.create_rbs_type(arg, lenv) } end
Public Instance Methods
attrs(= { cpath:, toplevel: })
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/ast/sig_type.rb, line 401 def attrs = { cpath:, toplevel: } def define0(genv) @args.each {|arg| arg.define(genv) } const_reads = [] const_read = BaseConstRead.new(genv, @cpath.first, @toplevel ? CRef::Toplevel : @lenv.cref) const_reads << const_read unless @cpath.empty? @cpath[1..].each do |cname| const_read = ScopedConstRead.new(cname, const_read) const_reads << const_read end end const_reads end def undefine0(genv) @static_ret.each do |const_read| const_read.destroy(genv) end @args.each {|arg| arg.undefine(genv) } end def covariant_vertex0(genv, changes, vtx, subst) changes.add_depended_static_read(@static_ret.last) cpath = @static_ret.last.cpath return unless cpath mod = genv.resolve_cpath(cpath) args = @args.map {|arg| arg.covariant_vertex(genv, changes, subst) } changes.add_edge(genv, Source.new(Type::Instance.new(genv, mod, args)), vtx) end def contravariant_vertex0(genv, changes, vtx, subst) changes.add_depended_static_read(@static_ret.last) cpath = @static_ret.last.cpath return unless cpath mod = genv.resolve_cpath(cpath) args = @args.map {|arg| arg.contravariant_vertex(genv, changes, subst) } changes.add_edge(genv, Source.new(Type::Instance.new(genv, mod, args)), vtx) end def show s = "::#{ @cpath.join("::") }" if !@args.empty? s << "[...]" end s end end
contravariant_vertex0(genv, changes, vtx, subst)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/ast/sig_type.rb, line 433 def contravariant_vertex0(genv, changes, vtx, subst) changes.add_depended_static_read(@static_ret.last) cpath = @static_ret.last.cpath return unless cpath mod = genv.resolve_cpath(cpath) args = @args.map {|arg| arg.contravariant_vertex(genv, changes, subst) } changes.add_edge(genv, Source.new(Type::Instance.new(genv, mod, args)), vtx) end
covariant_vertex0(genv, changes, vtx, subst)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/ast/sig_type.rb, line 424 def covariant_vertex0(genv, changes, vtx, subst) changes.add_depended_static_read(@static_ret.last) cpath = @static_ret.last.cpath return unless cpath mod = genv.resolve_cpath(cpath) args = @args.map {|arg| arg.covariant_vertex(genv, changes, subst) } changes.add_edge(genv, Source.new(Type::Instance.new(genv, mod, args)), vtx) end
define0(genv)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/ast/sig_type.rb, line 403 def define0(genv) @args.each {|arg| arg.define(genv) } const_reads = [] const_read = BaseConstRead.new(genv, @cpath.first, @toplevel ? CRef::Toplevel : @lenv.cref) const_reads << const_read unless @cpath.empty? @cpath[1..].each do |cname| const_read = ScopedConstRead.new(cname, const_read) const_reads << const_read end end const_reads end
show()
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/ast/sig_type.rb, line 442 def show s = "::#{ @cpath.join("::") }" if !@args.empty? s << "[...]" end s end
subnodes(= { args: })
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/ast/sig_type.rb, line 400 def subnodes = { args: } def attrs = { cpath:, toplevel: } def define0(genv) @args.each {|arg| arg.define(genv) } const_reads = [] const_read = BaseConstRead.new(genv, @cpath.first, @toplevel ? CRef::Toplevel : @lenv.cref) const_reads << const_read unless @cpath.empty? @cpath[1..].each do |cname| const_read = ScopedConstRead.new(cname, const_read) const_reads << const_read end end const_reads end def undefine0(genv) @static_ret.each do |const_read| const_read.destroy(genv) end @args.each {|arg| arg.undefine(genv) } end def covariant_vertex0(genv, changes, vtx, subst) changes.add_depended_static_read(@static_ret.last) cpath = @static_ret.last.cpath return unless cpath mod = genv.resolve_cpath(cpath) args = @args.map {|arg| arg.covariant_vertex(genv, changes, subst) } changes.add_edge(genv, Source.new(Type::Instance.new(genv, mod, args)), vtx) end def contravariant_vertex0(genv, changes, vtx, subst) changes.add_depended_static_read(@static_ret.last) cpath = @static_ret.last.cpath return unless cpath mod = genv.resolve_cpath(cpath) args = @args.map {|arg| arg.contravariant_vertex(genv, changes, subst) } changes.add_edge(genv, Source.new(Type::Instance.new(genv, mod, args)), vtx) end def show s = "::#{ @cpath.join("::") }" if !@args.empty? s << "[...]" end s end end class SigTyTupleNode < SigTyNode def initialize(raw_decl, lenv) super(raw_decl, lenv) @types = raw_decl.types.map {|type| AST.create_rbs_type(type, lenv) } end attr_reader :types def subnodes = { types: } def covariant_vertex0(genv, changes, vtx, subst) unified_elem = changes.new_covariant_vertex(genv, [self, :Elem]) # TODO elems = @types.map do |type| nvtx = type.covariant_vertex(genv, changes, subst) changes.add_edge(genv, nvtx, unified_elem) nvtx end changes.add_edge(genv, Source.new(Type::Array.new(genv, elems, genv.gen_ary_type(unified_elem))), vtx) end def contravariant_vertex0(genv, changes, vtx, subst) unified_elem = changes.new_contravariant_vertex(genv, [self, :Elem]) # TODO elems = @types.map do |type| nvtx = type.contravariant_vertex(genv, changes, subst) changes.add_edge(genv, nvtx, unified_elem) nvtx end changes.add_edge(genv, Source.new(Type::Array.new(genv, elems, genv.gen_ary_type(unified_elem))), vtx) end def show "[#{ @types.map {|ty| ty.show }.join(", ") }]" end end class SigTyRecordNode < SigTyNode def covariant_vertex0(genv, changes, vtx, subst) raise NotImplementedError end def contravariant_vertex0(genv, changes, vtx, subst) raise NotImplementedError end def show "(...record...)" end end class SigTyVarNode < SigTyNode def initialize(raw_decl, lenv) super(raw_decl, lenv) @var = raw_decl.name end attr_reader :var def attrs = { var: } def covariant_vertex0(genv, changes, vtx, subst) raise "unknown type variable: #{ @var }" unless subst[@var] changes.add_edge(genv, subst[@var], vtx) end def contravariant_vertex0(genv, changes, vtx, subst) raise "unknown type variable: #{ @var }" unless subst[@var] changes.add_edge(genv, Source.new(Type::Var.new(genv, @var, subst[@var])), vtx) end def show "#{ @var }" end end class SigTyOptionalNode < SigTyNode def initialize(raw_decl, lenv) super(raw_decl, lenv) @type = AST.create_rbs_type(raw_decl.type, lenv) end attr_reader :type def subnodes = { type: } def covariant_vertex0(genv, changes, vtx, subst) @type.covariant_vertex0(genv, changes, vtx, subst) changes.add_edge(genv, Source.new(genv.nil_type), vtx) end def contravariant_vertex0(genv, changes, vtx, subst) @type.contravariant_vertex0(genv, changes, vtx, subst) changes.add_edge(genv, Source.new(genv.nil_type), vtx) end def show s = @type.show if @type.is_a?(SigTyIntersectionNode) || @type.is_a?(SigTyUnionNode) s = "(#{ s })" end s + "?" end end class SigTyLiteralNode < SigTyNode def initialize(raw_decl, lenv) super(raw_decl, lenv) @lit = raw_decl.literal end attr_reader :lit def attrs = { lit: } def get_type(genv) case @lit when ::Symbol Type::Symbol.new(genv, @lit) when ::Integer then genv.int_type when ::String then genv.str_type when ::TrueClass then genv.true_type when ::FalseClass then genv.false_type else raise "unknown RBS literal: #{ @lit.inspect }" end end def covariant_vertex0(genv, changes, vtx, subst) changes.add_edge(genv, Source.new(get_type(genv)), vtx) end def contravariant_vertex0(genv, changes, vtx, subst) changes.add_edge(genv, Source.new(get_type(genv)), vtx) end def show @lit.inspect end end class SigTyProcNode < SigTyNode def covariant_vertex0(genv, changes, vtx, subst) raise NotImplementedError end def contravariant_vertex0(genv, changes, vtx, subst) Source.new() end def show "(...proc...)" end end class SigTyInterfaceNode < SigTyNode def initialize(raw_decl, lenv) super(raw_decl, lenv) name = raw_decl.name @cpath = name.namespace.path + [name.name] @toplevel = name.namespace.absolute? # "::Foo" or "Foo" @args = raw_decl.args.map {|arg| AST.create_rbs_type(arg, lenv) } end attr_reader :cpath, :toplevel, :args def subnodes = { args: } def attrs = { cpath:, toplevel: } def define0(genv) @args.each {|arg| arg.define(genv) } const_reads = [] const_read = BaseConstRead.new(genv, @cpath.first, @toplevel ? CRef::Toplevel : @lenv.cref) const_reads << const_read unless @cpath.empty? @cpath[1..].each do |cname| const_read = ScopedConstRead.new(cname, const_read) const_reads << const_read end end const_reads end def undefine0(genv) @static_ret.each do |const_read| const_read.destroy(genv) end @args.each {|arg| arg.undefine(genv) } end def covariant_vertex0(genv, changes, vtx, subst) changes.add_depended_static_read(@static_ret.last) cpath = @static_ret.last.cpath return unless cpath mod = genv.resolve_cpath(cpath) args = @args.map {|arg| arg.covariant_vertex(genv, changes, subst) } changes.add_edge(genv, Source.new(Type::Instance.new(genv, mod, args)), vtx) end def contravariant_vertex0(genv, changes, vtx, subst) changes.add_depended_static_read(@static_ret.last) cpath = @static_ret.last.cpath return unless cpath mod = genv.resolve_cpath(cpath) args = @args.map {|arg| arg.contravariant_vertex(genv, changes, subst) } changes.add_edge(genv, Source.new(Type::Instance.new(genv, mod, args)), vtx) end def show s = "::#{ @cpath.join("::") }" if !@args.empty? s << "[...]" end s
undefine0(genv)
click to toggle source
# File typeprof-0.30.1/lib/typeprof/core/ast/sig_type.rb, line 417 def undefine0(genv) @static_ret.each do |const_read| const_read.destroy(genv) end @args.each {|arg| arg.undefine(genv) } end