Class: TypeProf::Core::LocalEnv

Inherits:
Object
  • Object
show all
Defined in:
lib/typeprof/core/env.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_context, cref, locals, return_boxes, forward_args = nil, sig_type_params: nil) ⇒ LocalEnv

Returns a new instance of LocalEnv.



367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/typeprof/core/env.rb', line 367

def initialize(file_context, cref, locals, return_boxes, forward_args = nil, sig_type_params: nil)
  @file_context = file_context
  @cref = cref
  @locals = locals
  @return_boxes = return_boxes
  @break_vtx = nil
  @next_boxes = []
  @ivar_narrowings = {}
  @strict_const_scope = false
  @forward_args = forward_args
  # [cpath, names] of the type parameters of the enclosing RBS declaration
  @sig_type_params = sig_type_params
end

Instance Attribute Details

#break_vtxObject (readonly)

Returns the value of attribute break_vtx.



381
382
383
# File 'lib/typeprof/core/env.rb', line 381

def break_vtx
  @break_vtx
end

#crefObject (readonly)

Returns the value of attribute cref.



381
382
383
# File 'lib/typeprof/core/env.rb', line 381

def cref
  @cref
end

#file_contextObject (readonly)

Returns the value of attribute file_context.



381
382
383
# File 'lib/typeprof/core/env.rb', line 381

def file_context
  @file_context
end

#forward_argsObject

Returns the value of attribute forward_args.



382
383
384
# File 'lib/typeprof/core/env.rb', line 382

def forward_args
  @forward_args
end

#localsObject (readonly)

Returns the value of attribute locals.



381
382
383
# File 'lib/typeprof/core/env.rb', line 381

def locals
  @locals
end

#module_functionObject

Returns the value of attribute module_function.



382
383
384
# File 'lib/typeprof/core/env.rb', line 382

def module_function
  @module_function
end

#next_boxesObject (readonly)

Returns the value of attribute next_boxes.



381
382
383
# File 'lib/typeprof/core/env.rb', line 381

def next_boxes
  @next_boxes
end

#return_boxesObject (readonly)

Returns the value of attribute return_boxes.



381
382
383
# File 'lib/typeprof/core/env.rb', line 381

def return_boxes
  @return_boxes
end

#sig_type_paramsObject (readonly)

Returns the value of attribute sig_type_params.



381
382
383
# File 'lib/typeprof/core/env.rb', line 381

def sig_type_params
  @sig_type_params
end

#strict_const_scopeObject (readonly)

Returns the value of attribute strict_const_scope.



381
382
383
# File 'lib/typeprof/core/env.rb', line 381

def strict_const_scope
  @strict_const_scope
end

Instance Method Details

#add_next_box(box) ⇒ Object



409
410
411
# File 'lib/typeprof/core/env.rb', line 409

def add_next_box(box)
  @next_boxes << box
end

#add_return_box(box) ⇒ Object



405
406
407
# File 'lib/typeprof/core/env.rb', line 405

def add_return_box(box)
  @return_boxes << box
end

#apply_ivar_narrowing(genv, node, name, vtx) ⇒ Object



426
427
428
429
430
431
432
433
434
435
# File 'lib/typeprof/core/env.rb', line 426

def apply_ivar_narrowing(genv, node, name, vtx)
  if @ivar_narrowings[name] && !@ivar_narrowings[name].empty?
    # Apply all accumulated narrowings in order
    @ivar_narrowings[name].each do |narrowing|
      vtx = narrowing.narrow(genv, node, vtx)
    end
    return vtx
  end
  vtx
end

#code_range_from_node(node) ⇒ Object



385
386
387
# File 'lib/typeprof/core/env.rb', line 385

def code_range_from_node(node)
  TypeProf::CodeRange.from_node(node, @file_context)
end

#exist_var?(name) ⇒ Boolean

Returns:



401
402
403
# File 'lib/typeprof/core/env.rb', line 401

def exist_var?(name)
  !!@locals[name]
end

#get_break_vtxObject



413
414
415
# File 'lib/typeprof/core/env.rb', line 413

def get_break_vtx
  @break_vtx ||= Vertex.new(:break_vtx)
end

#get_var(name) ⇒ Object



397
398
399
# File 'lib/typeprof/core/env.rb', line 397

def get_var(name)
  @locals[name] || raise("#{ name }")
end

#new_var(name, node) ⇒ Object



389
390
391
# File 'lib/typeprof/core/env.rb', line 389

def new_var(name, node)
  @locals[name] = Vertex.new(node)
end

#pathObject



384
# File 'lib/typeprof/core/env.rb', line 384

def path = @file_context&.path

#pop_ivar_narrowing(name) ⇒ Object



422
423
424
# File 'lib/typeprof/core/env.rb', line 422

def pop_ivar_narrowing(name)
  (@ivar_narrowings[name] ||= []).pop
end

#push_ivar_narrowing(name, narrowing) ⇒ Object



417
418
419
420
# File 'lib/typeprof/core/env.rb', line 417

def push_ivar_narrowing(name, narrowing)
  raise unless narrowing.is_a?(Narrowing::Constraint)
  (@ivar_narrowings[name] ||= []) << narrowing
end

#set_var(name, vtx) ⇒ Object



393
394
395
# File 'lib/typeprof/core/env.rb', line 393

def set_var(name, vtx)
  @locals[name] = vtx
end

#use_strict_const_scopeObject



437
438
439
440
441
442
# File 'lib/typeprof/core/env.rb', line 437

def use_strict_const_scope
  @strict_const_scope = true
  yield
ensure
  @strict_const_scope = false
end