Class: Archruby::Ruby::TypeInference::Ruby::LocalScope

Inherits:
Object
  • Object
show all
Defined in:
lib/archruby/ruby/type_inference/ruby/parser_for_typeinference.rb

Instance Method Summary collapse

Constructor Details

#initializeLocalScope

Returns a new instance of LocalScope.



476
477
478
479
480
481
# File 'lib/archruby/ruby/type_inference/ruby/parser_for_typeinference.rb', line 476

def initialize
  @scopes = [Set.new]
  @formal_parameters = [Set.new]
  @current_scope = @scopes.last
  @current_formal_parameters = @formal_parameters.last
end

Instance Method Details

#add_formal_parameter(name, type) ⇒ Object



487
488
489
# File 'lib/archruby/ruby/type_inference/ruby/parser_for_typeinference.rb', line 487

def add_formal_parameter(name, type)
  @current_formal_parameters.add([name, type])
end

#add_new_scopeObject



508
509
510
511
512
513
# File 'lib/archruby/ruby/type_inference/ruby/parser_for_typeinference.rb', line 508

def add_new_scope
  @scopes << Set.new
  @current_scope = @scopes.last
  @formal_parameters << Set.new
  @current_formal_parameters = @formal_parameters.last
end

#add_variable(name, type) ⇒ Object



483
484
485
# File 'lib/archruby/ruby/type_inference/ruby/parser_for_typeinference.rb', line 483

def add_variable(name, type)
  @current_scope.add([name, type])
end

#has_formal_parameter(name) ⇒ Object



500
501
502
# File 'lib/archruby/ruby/type_inference/ruby/parser_for_typeinference.rb', line 500

def has_formal_parameter(name)
  check_from_collection(@current_formal_parameters, name)
end

#has_local_params(name) ⇒ Object



504
505
506
# File 'lib/archruby/ruby/type_inference/ruby/parser_for_typeinference.rb', line 504

def has_local_params(name)
  check_from_collection(@current_scope, name)
end

#remove_scopeObject



515
516
517
518
519
520
# File 'lib/archruby/ruby/type_inference/ruby/parser_for_typeinference.rb', line 515

def remove_scope
  @scopes.pop
  @current_scope = @scopes.last
  @formal_parameters.pop
  @current_formal_parameters = @formal_parameters.last
end

#var_type(name) ⇒ Object



491
492
493
494
495
496
497
498
# File 'lib/archruby/ruby/type_inference/ruby/parser_for_typeinference.rb', line 491

def var_type(name)
  @current_scope.each do |var_info|
    if var_info[0].to_s == name.to_s
      return var_info[1]
    end
  end
  return nil
end