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(path, cref, locals, return_boxes) ⇒ LocalEnv

Returns a new instance of LocalEnv.



299
300
301
302
303
304
305
306
307
308
# File 'lib/typeprof/core/env.rb', line 299

def initialize(path, cref, locals, return_boxes)
  @path = path
  @cref = cref
  @locals = locals
  @return_boxes = return_boxes
  @break_vtx = nil
  @next_boxes = []
  @ivar_narrowings = {}
  @strict_const_scope = false
end

Instance Attribute Details

#break_vtxObject (readonly)

Returns the value of attribute break_vtx.



310
311
312
# File 'lib/typeprof/core/env.rb', line 310

def break_vtx
  @break_vtx
end

#crefObject (readonly)

Returns the value of attribute cref.



310
311
312
# File 'lib/typeprof/core/env.rb', line 310

def cref
  @cref
end

#localsObject (readonly)

Returns the value of attribute locals.



310
311
312
# File 'lib/typeprof/core/env.rb', line 310

def locals
  @locals
end

#next_boxesObject (readonly)

Returns the value of attribute next_boxes.



310
311
312
# File 'lib/typeprof/core/env.rb', line 310

def next_boxes
  @next_boxes
end

#pathObject (readonly)

Returns the value of attribute path.



310
311
312
# File 'lib/typeprof/core/env.rb', line 310

def path
  @path
end

#return_boxesObject (readonly)

Returns the value of attribute return_boxes.



310
311
312
# File 'lib/typeprof/core/env.rb', line 310

def return_boxes
  @return_boxes
end

#strict_const_scopeObject (readonly)

Returns the value of attribute strict_const_scope.



310
311
312
# File 'lib/typeprof/core/env.rb', line 310

def strict_const_scope
  @strict_const_scope
end

Instance Method Details

#add_next_box(box) ⇒ Object



332
333
334
# File 'lib/typeprof/core/env.rb', line 332

def add_next_box(box)
  @next_boxes << box
end

#add_return_box(box) ⇒ Object



328
329
330
# File 'lib/typeprof/core/env.rb', line 328

def add_return_box(box)
  @return_boxes << box
end

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



350
351
352
353
354
355
356
357
358
359
# File 'lib/typeprof/core/env.rb', line 350

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

#exist_var?(name) ⇒ Boolean

Returns:

  • (Boolean)


324
325
326
# File 'lib/typeprof/core/env.rb', line 324

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

#get_break_vtxObject



336
337
338
# File 'lib/typeprof/core/env.rb', line 336

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

#get_var(name) ⇒ Object



320
321
322
# File 'lib/typeprof/core/env.rb', line 320

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

#new_var(name, node) ⇒ Object



312
313
314
# File 'lib/typeprof/core/env.rb', line 312

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

#pop_ivar_narrowing(name) ⇒ Object



346
347
348
# File 'lib/typeprof/core/env.rb', line 346

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

#push_ivar_narrowing(name, narrowing) ⇒ Object



341
342
343
344
# File 'lib/typeprof/core/env.rb', line 341

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

#set_var(name, vtx) ⇒ Object



316
317
318
# File 'lib/typeprof/core/env.rb', line 316

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

#use_strict_const_scopeObject



361
362
363
364
365
366
# File 'lib/typeprof/core/env.rb', line 361

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