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



295
296
297
298
299
300
301
302
303
304
# File 'lib/typeprof/core/env.rb', line 295

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.



306
307
308
# File 'lib/typeprof/core/env.rb', line 306

def break_vtx
  @break_vtx
end

#crefObject (readonly)

Returns the value of attribute cref.



306
307
308
# File 'lib/typeprof/core/env.rb', line 306

def cref
  @cref
end

#localsObject (readonly)

Returns the value of attribute locals.



306
307
308
# File 'lib/typeprof/core/env.rb', line 306

def locals
  @locals
end

#next_boxesObject (readonly)

Returns the value of attribute next_boxes.



306
307
308
# File 'lib/typeprof/core/env.rb', line 306

def next_boxes
  @next_boxes
end

#pathObject (readonly)

Returns the value of attribute path.



306
307
308
# File 'lib/typeprof/core/env.rb', line 306

def path
  @path
end

#return_boxesObject (readonly)

Returns the value of attribute return_boxes.



306
307
308
# File 'lib/typeprof/core/env.rb', line 306

def return_boxes
  @return_boxes
end

#strict_const_scopeObject (readonly)

Returns the value of attribute strict_const_scope.



306
307
308
# File 'lib/typeprof/core/env.rb', line 306

def strict_const_scope
  @strict_const_scope
end

Instance Method Details

#add_next_box(box) ⇒ Object



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

def add_next_box(box)
  @next_boxes << box
end

#add_return_box(box) ⇒ Object



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

def add_return_box(box)
  @return_boxes << box
end

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



346
347
348
349
350
351
352
353
354
355
# File 'lib/typeprof/core/env.rb', line 346

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



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

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

#get_break_vtxObject



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

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

#get_var(name) ⇒ Object



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

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

#new_var(name, node) ⇒ Object



308
309
310
# File 'lib/typeprof/core/env.rb', line 308

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

#pop_ivar_narrowing(name) ⇒ Object



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

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

#push_ivar_narrowing(name, narrowing) ⇒ Object



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

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

#set_var(name, vtx) ⇒ Object



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

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

#use_strict_const_scopeObject



357
358
359
360
361
362
# File 'lib/typeprof/core/env.rb', line 357

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