class TypeProf::Env
Attributes
locals[R]
stack[R]
static_env[R]
type_params[R]
Public Class Methods
new(static_env, locals, stack, type_params)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 159 def initialize(static_env, locals, stack, type_params) @static_env = static_env @locals = locals @stack = stack @type_params = type_params end
Public Instance Methods
deploy_type(id, elems)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 241 def deploy_type(id, elems) type_params = Utils::HashWrapper.new(@type_params.internal_hash.merge({ id => elems })) Env.new(@static_env, @locals, @stack, type_params) end
enable_module_function()
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 246 def enable_module_function senv = StaticEnv.new(@static_env.recv_ty, @static_env.blk_ty, true, @static_env.pub_meth) Env.new(senv, @locals, @stack, @type_params) end
get_container_elem_types(id)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 237 def get_container_elem_types(id) @type_params.internal_hash[id] end
get_local(idx)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 229 def get_local(idx) @locals[idx] end
inspect()
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 266 def inspect "Env[#{ @static_env.inspect }, locals:#{ @locals.inspect }, stack:#{ @stack.inspect }, type_params:#{ (@type_params&.internal_hash).inspect }]" end
local_update(idx, ty)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 233 def local_update(idx, ty) Env.new(@static_env, Utils.array_update(@locals, idx, ty), @stack, @type_params) end
merge(other)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 168 def merge(other) raise if @locals.size != other.locals.size raise if @stack.size != other.stack.size static_env = @static_env.merge(other.static_env) locals = [] @locals.zip(other.locals) {|ty1, ty2| locals << ty1.union(ty2) } stack = [] @stack.zip(other.stack) {|ty1, ty2| stack << ty1.union(ty2) } if @type_params raise if !other.type_params if @type_params == other.type_params type_params = @type_params else type_params = @type_params.internal_hash.dup other.type_params.internal_hash.each do |id, elems| elems2 = type_params[id] if elems2 if elems != elems2 type_params[id] = elems.union(elems2) end else type_params[id] = elems end end type_params = Utils::HashWrapper.new(type_params) end else raise if other.type_params end Env.new(static_env, locals, stack, type_params) end
method_public_set(flag)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 251 def method_public_set(flag) senv = StaticEnv.new(@static_env.recv_ty, @static_env.blk_ty, @static_env.mod_func, flag) Env.new(senv, @locals, @stack, @type_params) end
pop(n)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 213 def pop(n) stack = @stack.dup tys = stack.pop(n) nenv = Env.new(@static_env, @locals, stack, @type_params) return nenv, tys end
push(*tys)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 200 def push(*tys) tys.each do |ty| raise "nil cannot be pushed to the stack" if ty.nil? ty.each_child do |ty| raise if ty.is_a?(Type::Var) #raise if ty.is_a?(Type::Instance) && ty.klass.type_params.size > 1 raise "Array cannot be pushed to the stack" if ty.is_a?(Type::Array) raise "Hash cannot be pushed to the stack" if ty.is_a?(Type::Hash) end end Env.new(@static_env, @locals, @stack + tys, @type_params) end
replace_blk_ty(ty)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 261 def replace_blk_ty(ty) senv = StaticEnv.new(@static_env.recv_ty, ty, @static_env.mod_func, @static_env.pub_meth) Env.new(senv, @locals, @stack, @type_params) end
replace_recv_ty(ty)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 256 def replace_recv_ty(ty) senv = StaticEnv.new(ty, @static_env.blk_ty, @static_env.mod_func, @static_env.pub_meth) Env.new(senv, @locals, @stack, @type_params) end
setn(i, ty)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 220 def setn(i, ty) stack = Utils.array_update(@stack, -i, ty) Env.new(@static_env, @locals, stack, @type_params) end
topn(i)
click to toggle source
# File typeprof-0.21.2/lib/typeprof/analyzer.rb, line 225 def topn(i) push(@stack[-i - 1]) end