class Rubocop::Cop::VariableInspector::VariableTable

variable visibility of the current scope.
variables to current scope and find local variables by considering
This holds scopes as stack structure, and provides a way to add local
in a program.
A VariableTable manages the lifetime of all scopes and local variables

def add_variable_entry(variable_declaration_node, name = nil)

def add_variable_entry(variable_declaration_node, name = nil)
  entry = VariableEntry.new(variable_declaration_node, name)
  invoke_hook(:before_declaring_variable, entry)
  current_scope.variable_entries[entry.name] = entry
  invoke_hook(:after_declaring_variable, entry)
  entry
end

def current_scope

def current_scope
  scope_stack.last
end

def current_scope_level

def current_scope_level
  scope_stack.count
end

def find_variable_entry(variable_name)

def find_variable_entry(variable_name)
  scope_stack.reverse_each do |scope|
    entry = scope.variable_entries[variable_name]
    return entry if entry
    # Only block scope allows referencing outer scope variables.
    return nil unless scope.node.type == :block
  end
  nil
end

def initialize(hook_receiver = nil)

def initialize(hook_receiver = nil)
  @hook_receiver = hook_receiver
end

def invoke_hook(hook_name, *args)

def invoke_hook(hook_name, *args)
  @hook_receiver.send(hook_name, *args) if @hook_receiver
end

def pop_scope

def pop_scope
  scope = current_scope
  invoke_hook(:before_leaving_scope, scope)
  scope_stack.pop
  invoke_hook(:after_leaving_scope, scope)
  scope
end

def push_scope(scope_node)

def push_scope(scope_node)
  scope = Scope.new(scope_node)
  invoke_hook(:before_entering_scope, scope)
  scope_stack.push(scope)
  invoke_hook(:after_entering_scope, scope)
  scope
end

def scope_stack

def scope_stack
  @scope_stack ||= []
end