class Archruby::Ruby::TypeInference::Ruby::LocalScope

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

add_formal_parameter(name, type) click to toggle source
# 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_scope() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_scope() click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

check_from_collection(collection, name) click to toggle source
# File lib/archruby/ruby/type_inference/ruby/parser_for_typeinference.rb, line 524
def check_from_collection(collection, name)
  collection.each do |var_info|
    if var_info[0].to_s == name.to_s
      return true
    end
  end
  return false
end